/*
* 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.
*/
/*
* Copyright 2013 Nexenta Systems, Inc. All rights reserved.
*/
/*
* SMB Negotiate Protocol, and related.
*/
#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 "charsets.h"
#include "smb_crypt.h"
#include "private.h"
/*
* SMB dialects that we know about.
*/
struct smb_dialect {
int d_id;
const char *d_name;
};
{SMB_DIALECT_CORE, "PC NETWORK PROGRAM 1.0"},
{SMB_DIALECT_LANMAN1_0, "LANMAN1.0"},
{SMB_DIALECT_LANMAN2_0, "LM1.2X002"},
{SMB_DIALECT_LANMAN2_1, "LANMAN2.1"},
{SMB_DIALECT_NTLM0_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
{
int will_sign = 0;
/*
* Initialize: vc_hflags and vc_hflags2.
* Note: ctx->ct_hflags* are copied into the
* (per request) rqp->rq_hflags* by smb_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.
*/
ctx->ct_hflags2 =
/* SMB_FLAGS2_IS_LONG_NAME |? */
/* EXT_SEC (see below) */
/*
* 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;
/* BEGIN CSTYLED */
/*
* Will we do SMB signing? Or block the connection?
* The table below describes this logic. References:
* [Windows Server Protocols: MS-SMB, sec. 3.2.4.2.3]
*
* ------------+----------+------------+-------------+-----------
* Required | Signed | Signed | Signed | Blocked [1]
* ------------+----------+------------+-------------+-----------
* Enabled | Signed | Signed | Not Signed | Not Signed
* ------------+----------+------------+-------------+-----------
* If Required | Signed | Not Signed | Not Signed | Not Signed
* ------------+----------+------------+-------------+-----------
* Disabled | Blocked | Not Signed | Not Signed | Not Signed
*
* [1] Like Windows 2003 and later, we don't really implement
* the "Disabled" setting. Instead we implement "If Required",
* so we always sign if the server requires signing.
*/
/* END CSTYLED */
/*
* Server requires signing. We will sign,
* even if local setting is "disabled".
*/
will_sign = 1;
/*
* Server enables signing (client's option).
* If enabled locally, do signing.
*/
will_sign = 1;
/* else not signing. */
} else {
/*
* Server does not support signing.
* If we "require" it, bail now.
*/
DPRINT("Client requires signing "
"but server has it disabled.");
goto errout;
}
}
if (will_sign) {
}
/* See comment above re. FLAGS2_UNICODE */
else
/*
* They don't do NT error codes.
*
* If we send requests with
* SMB_FLAGS2_ERR_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;
} 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. */
/*
* Most of the "capability" bits we offer in session setup
* are just copied from those offered by the server.
*/
/* Get the client nonce. */
return (0);
if (err == 0)
return (err);
}