smb_session_setup_andx.c revision da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER START
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The contents of this file are subject to the terms of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Common Development and Distribution License (the "License").
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You may not use this file except in compliance with the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * or http://www.opensolaris.org/os/licensing.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * See the License for the specific language governing permissions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and limitations under the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * When distributing Covered Code, include this CDDL HEADER in each
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If applicable, add the following below this CDDL HEADER, with the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * fields enclosed by brackets "[]" replaced with your own identifying
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * information: Portions Copyright [yyyy] [name of copyright owner]
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER END
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use is subject to license terms.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#pragma ident "%Z%%M% %I% %E% SMI"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: session_setup_andx
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This SMB is used to further "Set up" the session normally just
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * established via the negotiate protocol.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * One primary function is to perform a "user logon" in the case where the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * server is in user level security mode. The Uid in the SMB header is set
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * by the client to be the userid desired for the AccountName and validated
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * by the AccountPassword.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If the negotiated protocol is prior to NT LM 0.12, the format of
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB_COM_SESSION_SETUP_ANDX is:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Client Request Description
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ============================== =====================================
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR WordCount; Count of parameter words = 10
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR AndXCommand; Secondary (X) command; 0xFF = none
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR AndXReserved; Reserved (must be 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT AndXOffset; Offset to next command WordCount
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT MaxBufferSize; Client maximum buffer size
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT MaxMpxCount; Actual maximum multiplexed pending
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * requests
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT VcNumber; 0 = first (only), nonzero=additional
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * VC number
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ULONG SessionKey; Session key (valid iff VcNumber != 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT PasswordLength; Account password size
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ULONG Reserved; Must be 0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT ByteCount; Count of data bytes; min = 0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR AccountPassword[]; Account Password
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * STRING AccountName[]; Account Name
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * STRING PrimaryDomain[]; Client's primary domain
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * STRING NativeOS[]; Client's native operating system
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * STRING NativeLanMan[]; Client's native LAN Manager type
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and the response is:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Server Response Description
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ================================== =================================
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR WordCount; Count of parameter words = 3
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR AndXCommand; Secondary (X) command; 0xFF =
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * none
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR AndXReserved; Reserved (must be 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT AndXOffset; Offset to next command WordCount
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT Action; Request mode:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * bit0 = logged in as GUEST
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT ByteCount; Count of data bytes
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * STRING NativeOS[]; Server's native operating system
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * STRING NativeLanMan[]; Server's native LAN Manager type
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * STRING PrimaryDomain[]; Server's primary domain
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If the server is in "share level security mode", the account name and
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * passwd should be ignored by the server.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If challenge/response authentication is not being used, AccountPassword
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * should be a null terminated ASCII string with PasswordLength set to the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * string size including the null; the password will case insensitive. If
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * challenge/response authentication is being used (see section 2.10), then
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * AccountPassword will be the response to the server's challenge, and
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * PasswordLength should be set to its length.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The server validates the name and password supplied and if valid, it
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * registers the user identifier on this session as representing the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * specified AccountName. The Uid field in the SMB header will then be
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * used to validate access on subsequent SMB requests. The SMB requests
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * where permission checks are required are those which refer to a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * symbolically named resource such as SMB_COM_OPEN, SMB_COM_RENAME,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB_COM_DELETE, etc.. The value of the Uid is relative to a specific
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * client/server session so it is possible to have the same Uid value
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * represent two different users on two different sessions at the server.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Multiple session setup commands may be sent to register additional users
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * on this session. If the server receives an additional
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB_COM_SESSION_SETUP_ANDX, only the Uid, AccountName and
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * AccountPassword fields need contain valid values (the server MUST ignore
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the other fields).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The client writes the name of its domain in PrimaryDomain if it knows
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * what the domain name is. If the domain name is unknown, the client
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * either encodes it as a NULL string, or as a question mark.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If bit0 of Action is set, this informs the client that although the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * server did not recognize the AccountName, it logged the user in as a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * guest. This is optional behavior by the server, and in any case one
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * would ordinarily expect guest privileges to limited.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Another function of the Session Set Up protocol is to inform the server
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * of the maximum values which will be utilized by this client. Here
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * MaxBufferSize is the maximum message size which the client can receive.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Thus although the server may support 16k buffers (as returned in the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB_COM_NEGOTIATE response), if the client only has 4k buffers, the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * value of MaxBufferSize here would be 4096. The minimum allowable value
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * for MaxBufferSize is 1024. The SMB_COM_NEGOTIATE response includes the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * server buffer size supported. Thus this is the maximum SMB message size
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * which the client can send to the server. This size may be larger than
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the size returned to the server from the client via the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB_COM_SESSION_SETUP_AND X protocol which is the maximum SMB message
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * size which the server may send to the client. Thus if the server's
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * buffer size were 4k and the client's buffer size were only 2K, the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * client could send up to 4k (standard) write requests but must only
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * request up to 2k for (standard) read requests.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The field, MaxMpxCount informs the server of the maximum number of
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * requests which the client will have outstanding to the server
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * simultaneously (see sections 5.13 and 5.25).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The VcNumber field specifies whether the client wants this to be the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * first VC or an additional VC. If the the SMB_COM_SESSION_SETUP_ANDX
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * request contains a VcNumber of 0 and other VCs are still connected to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * that client, they should be aborted to free any resources held by the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * server. This condition could occur if the client was rebooted and
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * reconnected to the server before the transport level had informed the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * server of the previous VC termination. There is more information on
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * VCs in smb_negotiate.c.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The values for MaxBufferSize, MaxMpxCount, and VcNumber must be less
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * than or equal to the maximum values supported by the server as returned
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * in the SMB_COM_NEGOTIATE response.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If the negotiated SMB dialect is "NT LM 0.12" or later, the format of
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the response SMB is unchanged, but the request is:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Client Request Description
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ============================== =====================================
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR WordCount; Count of parameter words = 13
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR AndXCommand; Secondary (X) command; 0xFF = none
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR AndXReserved; Reserved (must be 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT AndXOffset; Offset to next command WordCount
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT MaxBufferSize; Client's maximum buffer size
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT MaxMpxCount; Actual maximum multiplexed pending
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * requests
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT VcNumber; 0 = first (only), nonzero=additional
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * VC number
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ULONG SessionKey; Session key (valid iff VcNumber != 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT Account password size, ANSI
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CaseInsensitivePasswordLength;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT Account password size, Unicode
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CaseSensitivePasswordLength;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ULONG Reserved; must be 0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ULONG Capabilities; Client capabilities
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT ByteCount; Count of data bytes; min = 0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR Account Password, ANSI
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CaseInsensitivePassword[];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR CaseSensitivePassword[]; Account Password, Unicode
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * STRING AccountName[]; Account Name, Unicode
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * STRING PrimaryDomain[]; Client's primary domain, Unicode
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * STRING NativeOS[]; Client's native operating system,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Unicode
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * STRING NativeLanMan[]; Client's native LAN Manager type,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Unicode
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The client expresses its capabilities to the server encoded in the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Capabilities field:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Capability Name Encoding Description
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ======================== ========= ================================
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CAP_UNICODE 0x0004 The client can use UNICODE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * strings
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CAP_LARGE_FILES 0x0008 The client can deal with files
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * having 64 bit offsets
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CAP_NT_SMBS 0x0010 The client understands the SMBs
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * introduced with the NT LM 0.12
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * dialect. Implies CAP_NT_FIND.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CAP_NT_FIND 0x0200
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CAP_STATUS32 0x0040 The client can receive 32 bit
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * errors encoded in Status.Status
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CAP_LEVEL_II_OPLOCKS 0x0080 The client understands Level II
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * oplocks
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The entire message sent and received including the optional ANDX SMB
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * must fit in the negotiated maximum transfer size. The following are the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * only valid SMB commands for AndXCommand for SMB_COM_SESSION_SETUP_ANDX
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB_COM_TREE_CONNECT_ANDX SMB_COM_OPEN
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB_COM_OPEN_ANDX SMB_COM_CREATE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB_COM_CREATE_NEW SMB_COM_CREATE_DIRECTORY
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB_COM_DELETE SMB_COM_DELETE_DIRECTORY
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB_COM_FIND SMB_COM_FIND_UNIQUE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB_COM_COPY SMB_COM_RENAME
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB_COM_NT_RENAME SMB_COM_CHECK_DIRECTORY
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB_COM_QUERY_INFORMATION SMB_COM_SET_INFORMATION
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB_COM_NO_ANDX_COMMAND SMB_COM_OPEN_PRINT_FILE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB_COM_GET_PRINT_QUEUE SMB_COM_TRANSACTION
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 4.1.2.1 Errors
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ERRSRV/ERRerror - no NEG_PROT issued
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ERRSRV/ERRbadpw - password not correct for given user name
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ERRSRV/ERRtoomanyuids - maximum number of users per session exceeded
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ERRSRV/ERRnosupport - chaining of this request to the previous one is
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * not supported
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/types.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/socket.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <netinet/in.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <smbsrv/smb_incl.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <smbsrv/smb_token.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <smbsrv/smb_door_svc.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwint
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_com_session_setup_andx(struct smb_request *sr)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint16_t maxbufsize, maxmpxcount, vcnumber = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint32_t sesskey;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint32_t capabilities = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *account_name = "";
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *primary_domain = "";
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *native_os = "";
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *native_lanman = "";
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *hostname = smb_info.si.skc_hostname;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_token_t *usr_token = NULL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_user_t *user = NULL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int security = smb_info.si.skc_secmode;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint16_t ci_pwlen = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char *ci_password = NULL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint16_t cs_pwlen = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char *cs_password = NULL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw netr_client_t clnt_info;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_session_key_t *session_key = NULL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int rc;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (sr->session->dialect >= NT_LM_0_12) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = smbsr_decode_vwv(sr, "b.wwwwlww4.l", &sr->andx_com,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &sr->andx_off, &maxbufsize, &maxmpxcount, &vcnumber,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &sesskey, &ci_pwlen, &cs_pwlen, &capabilities);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbsr_decode_error(sr);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* NOTREACHED */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ci_password = kmem_alloc(ci_pwlen + 1, KM_SLEEP);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw cs_password = kmem_alloc(cs_pwlen + 1, KM_SLEEP);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The padding between the Native OS and Native LM is a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * bit strange. On NT4.0, there is a 2 byte pad between
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the OS (Windows NT 1381) and LM (Windows NT 4.0).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * On Windows 2000, there is no padding between the OS
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * (Windows 2000 2195) and LM (Windows 2000 5.0).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If the padding is removed from this decode string
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the NT4.0 LM comes out as an empty string.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * So if the client's native OS is Win NT we consider
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the padding otherwise we don't.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = smbsr_decode_data(sr, "%#c#cuuu",
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ci_pwlen, ci_password,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw cs_pwlen, cs_password,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &account_name,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &primary_domain,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &native_os);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw kmem_free(ci_password, ci_pwlen + 1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw kmem_free(cs_password, cs_pwlen + 1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbsr_decode_error(sr);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* NOTREACHED */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ci_password[ci_pwlen] = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw cs_password[cs_pwlen] = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->session->native_os = smbnative_os_value(native_os);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (sr->session->native_os == NATIVE_OS_WINNT)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = smbsr_decode_data(sr, "%,u", sr, &native_lanman);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw else
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = smbsr_decode_data(sr, "%u", sr, &native_lanman);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Native Lanman could be null so we really don't care
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * if above decode fails, but to have a valid value for
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the field we set it to Win NT.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc != 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw native_lanman = "NT LAN Manager 4.0";
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = smbsr_decode_vwv(sr, "b.wwwwlw4.", &sr->andx_com,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &sr->andx_off, &maxbufsize, &maxmpxcount,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &vcnumber, &sesskey, &ci_pwlen);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbsr_decode_error(sr);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* NOTREACHED */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ci_password = kmem_alloc(ci_pwlen + 1, KM_SLEEP);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = smbsr_decode_data(sr, "%#c", sr, ci_pwlen, ci_password);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw kmem_free(ci_password, ci_pwlen + 1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbsr_decode_error(sr);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* NOTREACHED */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ci_password[ci_pwlen] = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Despite the CIFS/1.0 spec, the rest of this message is
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * not always present. We need to try to get the account
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * name and the primary domain but we don't care about the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the native OS or native LanMan fields.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (smbsr_decode_data(sr, "%u", sr, &account_name) != 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw account_name = "";
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (smbsr_decode_data(sr, "%u", sr, &primary_domain) != 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw primary_domain = "";
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->session->native_os = NATIVE_OS_UNKNOWN;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If the vcnumber is zero, we can discard any
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * other connections associated with this client.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->session->vcnumber = vcnumber;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (vcnumber == 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_reconnection_check(sr->session);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->session->smb_msg_size = maxbufsize;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw bzero(&clnt_info, sizeof (netr_client_t));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (*primary_domain == 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw primary_domain = smb_info.si.skc_resource_domain;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((cs_pwlen == 0) &&
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (ci_pwlen == 0 || (ci_pwlen == 1 && *ci_password == 0))) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* anonymous user */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw clnt_info.flags |= NETR_CFLG_ANON;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw account_name = "nobody";
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else if (*account_name == '\0') {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (ci_password)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw kmem_free(ci_password, ci_pwlen + 1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (cs_password)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw kmem_free(cs_password, cs_pwlen + 1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbsr_raise_error(sr, ERRSRV, ERRaccess);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* NOTREACHED */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else if (utf8_strcasecmp(primary_domain, hostname) == 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * When domain name is equal to hostname, it means
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the user is local even if system is running in
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * domain mode, so perform a local logon.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw clnt_info.flags |= NETR_CFLG_LOCAL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else if (security == SMB_SECMODE_DOMAIN) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw clnt_info.flags |= NETR_CFLG_DOMAIN;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else if (security == SMB_SECMODE_WORKGRP) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw clnt_info.flags |= NETR_CFLG_LOCAL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) utf8_strupr(primary_domain);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If this is an additional setup for an existing user
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * on this session, duplicate the authenticated user.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Otherwise authenticate as new user.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw user = smb_user_lookup_by_name(sr->session, primary_domain,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw account_name);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (user) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_user_t *orig_user = user;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw user = smb_user_dup(orig_user);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_user_release(orig_user);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw cred_t *cr;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint32_t privileges;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw clnt_info.logon_level = NETR_NETWORK_LOGON;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw clnt_info.domain = primary_domain;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw clnt_info.username = account_name;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw clnt_info.workstation = sr->session->workstation;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw clnt_info.ipaddr = sr->session->ipaddr;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw clnt_info.local_ipaddr = sr->session->local_ipaddr;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw clnt_info.challenge_key.challenge_key_val =
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->session->challenge_key;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw clnt_info.challenge_key.challenge_key_len =
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->session->challenge_len;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw clnt_info.nt_password.nt_password_val = cs_password;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw clnt_info.nt_password.nt_password_len = cs_pwlen;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw clnt_info.lm_password.lm_password_val = ci_password;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw clnt_info.lm_password.lm_password_len = ci_pwlen;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw clnt_info.native_os = sr->session->native_os;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw clnt_info.native_lm = smbnative_lm_value(native_lanman);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw clnt_info.local_port = sr->session->s_local_port;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw DTRACE_PROBE1(smb__sessionsetup__clntinfo, netr_client_t *,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &clnt_info);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw usr_token = smb_upcall_get_token(&clnt_info);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (usr_token == 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (ci_password)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw kmem_free(ci_password, ci_pwlen + 1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (cs_password)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw kmem_free(cs_password, cs_pwlen + 1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbsr_raise_error(sr, ERRSRV, ERRbadpw);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* NOTREACHED */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (usr_token->tkn_session_key) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw session_key = kmem_alloc(sizeof (smb_session_key_t),
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw KM_SLEEP);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) memcpy(session_key, usr_token->tkn_session_key,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sizeof (smb_session_key_t));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw cr = smb_cred_create(usr_token, &privileges);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (cr != NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw user = smb_user_login(sr->session, cr,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw usr_token->tkn_domain_name,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw usr_token->tkn_account_name,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw usr_token->tkn_flags,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw privileges,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw usr_token->tkn_audit_sid);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_cred_rele(cr);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_token_free(usr_token);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (ci_password)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw kmem_free(ci_password, ci_pwlen + 1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (cs_password)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw kmem_free(cs_password, cs_pwlen + 1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (user == NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (session_key)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw kmem_free(session_key, sizeof (smb_session_key_t));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbsr_raise_error(sr, ERRDOS, ERROR_INVALID_HANDLE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* no return */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->user_cr = user->u_cred;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->smb_uid = user->u_uid;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->uid_user = user;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->session->capabilities = capabilities;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Check to see if SMB signing is enable, but if it is already turned
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * on leave it.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The first authenticated logon provides the MAC key and sequence
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * numbers for signing all further session on the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * same network connection.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!(sr->session->signing.flags & SMB_SIGNING_ENABLED) &&
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (sr->session->secmode & NEGOTIATE_SECURITY_SIGNATURES_ENABLED) &&
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (sr->smb_flg2 & SMB_FLAGS2_SMB_SECURITY_SIGNATURE) &&
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw session_key)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_sign_init(sr, session_key, (char *)cs_password, cs_pwlen);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (session_key)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw kmem_free(session_key, sizeof (smb_session_key_t));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * NT systems use different native OS and native LanMan values
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * dependent on whether they are acting as a client or a server.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * As a server, NT 4.0 responds with the following values:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * NativeOS: Windows NT 4.0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * NativeLM: NT LAN Manager 4.0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * We should probably use the same values as NT but this code has
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * been using the product name and "Windows NT 4.0" for a long time
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and I don't know if a change would cause any problems (see the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * conditional test below).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbsr_encode_result(sr, 3, VAR_BCC, "bb.www%uuu",
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 3,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->andx_com,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw -1, /* andx_off */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ((user->u_flags & SMB_USER_FLAG_GUEST) ? 1 : 0),
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw VAR_BCC,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "Windows NT 4.0",
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "NT LAN Manager 4.0",
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_info.si.skc_resource_domain);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SDRC_NORMAL_REPLY);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}