/*
* Copyright (c) 2000-2001 Boris Popov
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Boris Popov.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
*/
/*
* SMB Negotiate Protocol, and related.
* Copied from the driver: smb_smb.c
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>
#include <netdb.h>
#include <libintl.h>
#include <xti.h>
#include <assert.h>
#include <sys/byteorder.h>
#include "smbfs_lib.h"
#include "smbfs_nb_lib.h"
#include "smbfs_charsets.h"
#include "smbfs_private.h"
/*
* SMB dialects that we know about.
*/
struct smb_dialect {
int d_id;
const char *d_name;
};
{PC_NETWORK_PROGRAM_1_0, "PC NETWORK PROGRAM 1.0"},
{LANMAN1_0, "LANMAN1.0"},
{LANMAN2_0, "LM1.2X002"},
{LANMAN2_1, "LANMAN2.1"},
{NTLM_0_12, "NT LM 0.12"},
{-1, NULL}
};
#define SMB_DIALECT_MAX \
/*
* SMB Negotiate Protocol
* Based on code from the driver: smb_smb.c
*
* If using Extended Security, oblob (output)
* will hold the initial security "hint".
*/
int
{
/*
* Initialize: vc_hflags and vc_hflags2.
* Note: ctx->ct_hflags* are copied into the
* (per request) rqp->rq_hflags* by smbfs_rq_init.
*
* Like Windows, set FLAGS2_UNICODE in our first request,
* even though technically we don't yet know whether the
* server supports Unicode. Will clear this flag below
* if we find out it doesn't. Need to do this because
* some servers reject all non-Unicode requests.
*/
/*
* Sould we offer extended security?
* We'll turn this back off below if
* the server doesn't support it.
*/
/*
* The initial UID needs to be zero,
* or Windows XP says "bad user".
* The initial TID is all ones, but
* we don't use it or store it here
* because the driver handles that.
*/
/*
* In case we're reconnecting,
* free previous stuff.
*/
ctx->ct_mac_seqno = 0;
ctx->ct_mackeylen = 0;
}
if (err)
return (err);
/*
* Build the SMB request.
*/
}
/*
* This does the OTW call
*/
if (err) {
goto errout;
}
goto errout;
}
/*
* Decode the response
*
* Comments to right show names as described in
* The Microsoft SMB Protocol spec. [MS-SMB]
* section 2.2.3
*/
goto errout;
}
/* XXX: User-visible warning too? */
goto errout;
}
if (wc != 17) {
goto errout;
}
if (err)
goto errout;
/*
* Signing rules:
* - If the server REQUIRES signing smb client will sign.
* - If the client REQUIRES signing smb client will sign.
* - If the server doesn't REQUIRE signing and client_signing_required
* is FALSE, smb client will not sign.
*/
DPRINT("Security signatures: %d\n",
/* See comment above re. FLAGS2_UNICODE */
else
/*
* They don't do NT error codes.
*
* If we send requests with
* SMB_FLAGS2_NT_STATUS set in
* Flags2, Windows 98, at least,
* appears to send replies with that
* bit set even though it sends back
* DOS error codes. (They probably
* just use the request header as
* a template for the reply header,
* and don't bother clearing that bit.)
*
* Therefore, we clear that bit in
* our vc_hflags2 field.
*/
}
DPRINT("Win95 detected");
}
/*
* The rest of the message varies depending on
* whether we've negotiated "extended security".
*
* With extended security, we have:
* Server_GUID (length 16)
* Security_BLOB
* Otherwise we have:
* EncryptionKey (length is eklen)
* PrimaryDomain
*/
struct mbuf *m;
DPRINT("Ext.Security: yes");
/*
* Skip the server GUID.
*/
if (err)
goto errout;
/*
* Remainder is the security blob.
* Note: eklen "must be ignored" [MS-SMB]
*/
if (len < 0)
goto errout;
/*
* Get the (optional) SPNEGO "hint".
*/
if (err)
goto errout;
smbfs_mb_initm(oblob, m);
} else {
DPRINT("Ext.Security: no");
/*
* Save the "Encryption Key" (the challenge).
*
* Sanity check: make sure the sec. blob length
* isn't bigger than the byte count.
*/
goto errout;
}
/*
* Server domain follows (ignored)
* Note: NOT aligned(2) - unusual!
*/
}
/*
* A few sanity checks on what we received,
* becuse we will send these in ssnsetup.
*
* Maximum outstanding requests (we care),
* and Max. VCs (we only use one). Also,
* MaxBufferSize lower limit per spec.
*/
/*
* Maximum transfer size.
* Sanity checks:
*
* Let's be conservative about an upper limit here.
* Win2k uses 16644 (and others) so 32k should be a
* reasonable sanity limit for this value.
*
* with CAP_LARGE_..., which we nearly always use.
*/
/*
* This is just the payload size, so we must
* leave room for the SMB headers, etc.
* This is just the ct_txmax value, but
* reduced and rounded down. Tricky bit:
*
* Servers typically give us a value that's
* some nice "round" number, i.e 0x4000 plus
* some overhead, i.e. Win2k: 16644==0x4104
* Subtract for the SMB header (32) and the
* SMB command word and byte vectors (34?),
* then round down to a 512 byte multiple.
*/
len &= 0xFE00;
/* XXX: Not sure yet which of these to keep. */
return (0);
if (err == 0)
return (err);
}