15331Samw /*
25331Samw * CDDL HEADER START
35331Samw *
45331Samw * The contents of this file are subject to the terms of the
55331Samw * Common Development and Distribution License (the "License").
65331Samw * You may not use this file except in compliance with the License.
75331Samw *
85331Samw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95331Samw * or http://www.opensolaris.org/os/licensing.
105331Samw * See the License for the specific language governing permissions
115331Samw * and limitations under the License.
125331Samw *
135331Samw * When distributing Covered Code, include this CDDL HEADER in each
145331Samw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155331Samw * If applicable, add the following below this CDDL HEADER, with the
165331Samw * fields enclosed by brackets "[]" replaced with your own identifying
175331Samw * information: Portions Copyright [yyyy] [name of copyright owner]
185331Samw *
195331Samw * CDDL HEADER END
205331Samw */
215331Samw /*
2212508Samw@Sun.COM * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
235331Samw */
245331Samw
255331Samw /*
265331Samw * Notes on the virtual circuit (VC) values in the SMB Negotiate
275331Samw * response and SessionSetupAndx request.
285331Samw *
295331Samw * A virtual circuit (VC) represents a connection between a client and a
305331Samw * server using a reliable, session oriented transport protocol, such as
315331Samw * NetBIOS or TCP/IP. Originally, each SMB session was restricted to a
325331Samw * single underlying transport connection, i.e. a single NetBIOS session,
335331Samw * which limited performance for raw data transfers.
345331Samw *
355331Samw * The intention behind multiple VCs was to improve performance by
365331Samw * allowing parallelism over each NetBIOS session. For example, raw data
375331Samw * could be transmitted using a different VC from other types of SMB
385331Samw * requests to remove the interleaving restriction while a raw transfer
395331Samw * is in progress. So the MaxNumberVcs field was added to the negotiate
405331Samw * response to make the number of VCs configurable and to allow servers
415331Samw * to specify how many they were prepared to support per session
425331Samw * connection. This turned out to be difficult to manage and, with
435331Samw * technology improvements, it has become obsolete.
445331Samw *
455331Samw * Servers should set the MaxNumberVcs value in the Negotiate response
465331Samw * to 1. Clients should probably ignore it. If a server receives a
475331Samw * SessionSetupAndx with a VC value of 0, it should close all other
485331Samw * VCs to that client. If it receives a non-zero VC, it should leave
495331Samw * other VCs in tact.
505331Samw *
515331Samw */
525331Samw
535331Samw /*
545331Samw * SMB: negotiate
555331Samw *
565331Samw * Client Request Description
575331Samw * ============================ =======================================
585331Samw *
595331Samw * UCHAR WordCount; Count of parameter words = 0
605331Samw * USHORT ByteCount; Count of data bytes; min = 2
615331Samw * struct {
625331Samw * UCHAR BufferFormat; 0x02 -- Dialect
635331Samw * UCHAR DialectName[]; ASCII null-terminated string
645331Samw * } Dialects[];
655331Samw *
665331Samw * The Client sends a list of dialects that it can communicate with. The
675331Samw * response is a selection of one of those dialects (numbered 0 through n)
685331Samw * or -1 (hex FFFF) indicating that none of the dialects were acceptable.
695331Samw * The negotiate message is binding on the virtual circuit and must be
705331Samw * sent. One and only one negotiate message may be sent, subsequent
715331Samw * negotiate requests will be rejected with an error response and no action
725331Samw * will be taken.
735331Samw *
745331Samw * The protocol does not impose any particular structure to the dialect
755331Samw * strings. Implementors of particular protocols may choose to include,
765331Samw * for example, version numbers in the string.
775331Samw *
785331Samw * If the server does not understand any of the dialect strings, or if PC
795331Samw * NETWORK PROGRAM 1.0 is the chosen dialect, the response format is
805331Samw *
815331Samw * Server Response Description
825331Samw * ============================ =======================================
835331Samw *
845331Samw * UCHAR WordCount; Count of parameter words = 1
855331Samw * USHORT DialectIndex; Index of selected dialect
865331Samw * USHORT ByteCount; Count of data bytes = 0
875331Samw *
885331Samw * If the chosen dialect is greater than core up to and including
895331Samw * LANMAN2.1, the protocol response format is
905331Samw *
915331Samw * Server Response Description
925331Samw * ============================ =======================================
935331Samw *
945331Samw * UCHAR WordCount; Count of parameter words = 13
955331Samw * USHORT DialectIndex; Index of selected dialect
965331Samw * USHORT SecurityMode; Security mode:
975331Samw * bit 0: 0 = share, 1 = user
985331Samw * bit 1: 1 = use challenge/response
995331Samw * authentication
1005331Samw * USHORT MaxBufferSize; Max transmit buffer size (>= 1024)
1015331Samw * USHORT MaxMpxCount; Max pending multiplexed requests
1025331Samw * USHORT MaxNumberVcs; Max VCs between client and server
1035331Samw * USHORT RawMode; Raw modes supported:
1045331Samw * bit 0: 1 = Read Raw supported
1055331Samw * bit 1: 1 = Write Raw supported
1065331Samw * ULONG SessionKey; Unique token identifying this session
1075331Samw * SMB_TIME ServerTime; Current time at server
1085331Samw * SMB_DATE ServerDate; Current date at server
1095331Samw * USHORT ServerTimeZone; Current time zone at server
1105331Samw * USHORT EncryptionKeyLength; MBZ if this is not LM2.1
1115331Samw * USHORT Reserved; MBZ
1125331Samw * USHORT ByteCount Count of data bytes
1135331Samw * UCHAR EncryptionKey[]; The challenge encryption key
1145331Samw * STRING PrimaryDomain[]; The server's primary domain
1155331Samw *
1165331Samw * MaxBufferSize is the size of the largest message which the client can
1175331Samw * legitimately send to the server
1185331Samw *
1195331Samw * If bit0 of the Flags field is set in the negotiate response, this
1205331Samw * indicates the server supports the SMB_COM_LOCK_AND_READ and
1215331Samw * SMB_COM_WRITE_AND_UNLOCK client requests.
1225331Samw *
1235331Samw * If the SecurityMode field indicates the server is running in user mode,
1245331Samw * the client must send appropriate SMB_COM_SESSION_SETUP_ANDX requests
1255331Samw * before the server will allow the client to access resources. If the
1265331Samw * SecurityMode fields indicates the client should use challenge/response
1275331Samw * authentication, the client should use the authentication mechanism
1285331Samw * specified in section 2.10.
1295331Samw *
1305331Samw * Clients should submit no more than MaxMpxCount distinct unanswered SMBs
1315331Samw * to the server when using multiplexed reads or writes (see sections 5.13
1325331Samw * and 5.25)
1335331Samw *
1345331Samw * Clients using the "MICROSOFT NETWORKS 1.03" dialect use a different
1355331Samw * form of raw reads than documented here, and servers are better off
1365331Samw * setting RawMode in this response to 0 for such sessions.
1375331Samw *
1385331Samw * If the negotiated dialect is "DOS LANMAN2.1" or "LANMAN2.1", then
1395331Samw * PrimaryDomain string should be included in this response.
1405331Samw *
1415331Samw * If the negotiated dialect is NT LM 0.12, the response format is
1425331Samw *
1435331Samw * Server Response Description
1445331Samw * ========================== =========================================
1455331Samw *
1465331Samw * UCHAR WordCount; Count of parameter words = 17
1475331Samw * USHORT DialectIndex; Index of selected dialect
1485331Samw * UCHAR SecurityMode; Security mode:
1495331Samw * bit 0: 0 = share, 1 = user
1505331Samw * bit 1: 1 = encrypt passwords
1515331Samw * USHORT MaxMpxCount; Max pending multiplexed requests
1525331Samw * USHORT MaxNumberVcs; Max VCs between client and server
1535331Samw * ULONG MaxBufferSize; Max transmit buffer size
1545331Samw * ULONG MaxRawSize; Maximum raw buffer size
1555331Samw * ULONG SessionKey; Unique token identifying this session
1565331Samw * ULONG Capabilities; Server capabilities
1575331Samw * ULONG SystemTimeLow; System (UTC) time of the server (low).
1585331Samw * ULONG SystemTimeHigh; System (UTC) time of the server (high).
1595331Samw * USHORT ServerTimeZone; Time zone of server (min from UTC)
1605331Samw * UCHAR EncryptionKeyLength; Length of encryption key.
1615331Samw * USHORT ByteCount; Count of data bytes
1625331Samw * UCHAR EncryptionKey[]; The challenge encryption key
1635331Samw * UCHAR OemDomainName[]; The name of the domain (in OEM chars)
1645331Samw *
1655331Samw * In addition to the definitions above, MaxBufferSize is the size of the
1665331Samw * largest message which the client can legitimately send to the server.
1675331Samw * If the client is using a connectionless protocol, MaxBufferSize must be
1685331Samw * set to the smaller of the server's internal buffer size and the amount
1695331Samw * of data which can be placed in a response packet.
1705331Samw *
1715331Samw * MaxRawSize specifies the maximum message size the server can send or
1725331Samw * receive for SMB_COM_WRITE_RAW or SMB_COM_READ_RAW.
1735331Samw *
1745331Samw * Connectionless clients must set Sid to 0 in the SMB request header.
1755331Samw *
1765331Samw * Capabilities allows the server to tell the client what it supports.
17710966SJordan.Brown@Sun.COM * The bit definitions defined in smb.h. Bit 0x2000 used to be set in
1785331Samw * the negotiate response capabilities but it caused problems with
1795331Samw * Windows 2000. It is probably not valid, it doesn't appear in the
1805331Samw * CIFS spec.
1815331Samw *
1825331Samw * 4.1.1.1 Errors
1835331Samw *
1845331Samw * SUCCESS/SUCCESS
1855331Samw * ERRSRV/ERRerror
1865331Samw */
1875331Samw #include <sys/types.h>
1885331Samw #include <sys/strsubr.h>
1895331Samw #include <sys/socketvar.h>
1905331Samw #include <sys/socket.h>
1915331Samw #include <sys/random.h>
1925331Samw #include <netinet/in.h>
19310966SJordan.Brown@Sun.COM #include <smbsrv/smb_kproto.h>
1945331Samw #include <smbsrv/smbinfo.h>
1955331Samw
19612508Samw@Sun.COM static smb_xlate_t smb_dialect[] = {
19712508Samw@Sun.COM { DIALECT_UNKNOWN, "DIALECT_UNKNOWN" },
19812508Samw@Sun.COM { PC_NETWORK_PROGRAM_1_0, "PC NETWORK PROGRAM 1.0" },
19912508Samw@Sun.COM { PCLAN1_0, "PCLAN1.0" },
20012508Samw@Sun.COM { MICROSOFT_NETWORKS_1_03, "MICROSOFT NETWORKS 1.03" },
20112508Samw@Sun.COM { MICROSOFT_NETWORKS_3_0, "MICROSOFT NETWORKS 3.0" },
20212508Samw@Sun.COM { LANMAN1_0, "LANMAN1.0" },
20312508Samw@Sun.COM { LM1_2X002, "LM1.2X002" },
20412508Samw@Sun.COM { DOS_LM1_2X002, "DOS LM1.2X002" },
20512508Samw@Sun.COM { DOS_LANMAN2_1, "DOS LANMAN2.1" },
20612508Samw@Sun.COM { LANMAN2_1, "LANMAN2.1" },
20712508Samw@Sun.COM { Windows_for_Workgroups_3_1a, "Windows for Workgroups 3.1a" },
20812508Samw@Sun.COM { NT_LM_0_12, "NT LM 0.12" }
20912508Samw@Sun.COM };
21012508Samw@Sun.COM
2115331Samw /*
2125331Samw * Maximum buffer size for DOS: chosen to be the same as NT.
2135331Samw * Do not change this value, DOS is very sensitive to it.
2145331Samw */
2155331Samw #define SMB_DOS_MAXBUF 0x1104
2165331Samw
2175331Samw /*
2185331Samw * The DOS TCP rcvbuf is set to 8700 because DOS 6.1 seems to have problems
2195331Samw * with other values. DOS 6.1 seems to depend on a window value of 8700 to
2205331Samw * send the next set of data. If we return a window value of 40KB, after
2215331Samw * sending 8700 bytes of data, it will start the next set of data from 40KB
2225331Samw * instead of 8.7k. Why 8.7k? We have no idea; it is the value that NT uses.
2235331Samw * September 2000.
2245331Samw *
2255331Samw * IR104720 Increased smb_nt_tcp_rcvbuf from 40KB to just under 1MB to allow
2265331Samw * for a larger TCP window sizei based on observations of Windows 2000 and
2275331Samw * performance testing. March 2003.
2285331Samw */
2296139Sjb150015 static uint32_t smb_dos_tcp_rcvbuf = 8700;
2306139Sjb150015 static uint32_t smb_nt_tcp_rcvbuf = 1048560; /* scale factor of 4 */
2315331Samw
23212508Samw@Sun.COM static void smb_negotiate_genkey(smb_request_t *);
23312508Samw@Sun.COM static int smb_xlate_dialect(const char *);
2345331Samw
23511963SAfshin.Ardakani@Sun.COM int smb_cap_passthru = 1;
23611963SAfshin.Ardakani@Sun.COM
2376139Sjb150015 smb_sdrc_t
smb_pre_negotiate(smb_request_t * sr)2386139Sjb150015 smb_pre_negotiate(smb_request_t *sr)
2396139Sjb150015 {
24012508Samw@Sun.COM smb_arg_negotiate_t *negprot;
24112508Samw@Sun.COM int dialect;
24212508Samw@Sun.COM int pos;
24312508Samw@Sun.COM int rc = 0;
24412508Samw@Sun.COM
24512508Samw@Sun.COM negprot = smb_srm_zalloc(sr, sizeof (smb_arg_negotiate_t));
24612508Samw@Sun.COM negprot->ni_index = -1;
24712508Samw@Sun.COM sr->sr_negprot = negprot;
24812508Samw@Sun.COM
24912508Samw@Sun.COM for (pos = 0; smbsr_decode_data_avail(sr); pos++) {
25012508Samw@Sun.COM if (smbsr_decode_data(sr, "%L", sr, &negprot->ni_name) != 0) {
25112508Samw@Sun.COM smbsr_error(sr, 0, ERRSRV, ERRerror);
25212508Samw@Sun.COM rc = -1;
25312508Samw@Sun.COM break;
25412508Samw@Sun.COM }
25512508Samw@Sun.COM
25612508Samw@Sun.COM if ((dialect = smb_xlate_dialect(negprot->ni_name)) < 0)
25712508Samw@Sun.COM continue;
25812508Samw@Sun.COM
25912508Samw@Sun.COM if (negprot->ni_dialect < dialect) {
26012508Samw@Sun.COM negprot->ni_dialect = dialect;
26112508Samw@Sun.COM negprot->ni_index = pos;
26212508Samw@Sun.COM }
26312508Samw@Sun.COM }
26412508Samw@Sun.COM
26512508Samw@Sun.COM DTRACE_SMB_2(op__Negotiate__start, smb_request_t *, sr,
26612508Samw@Sun.COM smb_arg_negotiate_t, negprot);
2679343SAfshin.Ardakani@Sun.COM smb_rwx_rwenter(&sr->session->s_lock, RW_WRITER);
26812508Samw@Sun.COM return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
2696139Sjb150015 }
2706139Sjb150015
2716139Sjb150015 void
smb_post_negotiate(smb_request_t * sr)2726139Sjb150015 smb_post_negotiate(smb_request_t *sr)
2736139Sjb150015 {
27412508Samw@Sun.COM smb_arg_negotiate_t *negprot = sr->sr_negprot;
27512508Samw@Sun.COM
27612508Samw@Sun.COM DTRACE_SMB_2(op__Negotiate__done, smb_request_t *, sr,
27712508Samw@Sun.COM smb_arg_negotiate_t, negprot);
2789343SAfshin.Ardakani@Sun.COM smb_rwx_rwexit(&sr->session->s_lock);
27912508Samw@Sun.COM
28012508Samw@Sun.COM bzero(negprot, sizeof (smb_arg_negotiate_t));
2816139Sjb150015 }
2825331Samw
2836030Sjb150015 smb_sdrc_t
smb_com_negotiate(smb_request_t * sr)2846139Sjb150015 smb_com_negotiate(smb_request_t *sr)
2855331Samw {
28612508Samw@Sun.COM smb_arg_negotiate_t *negprot = sr->sr_negprot;
28712508Samw@Sun.COM uint16_t secmode;
288*12890SJoyce.McIntosh@Sun.COM uint16_t rawmode = 0;
2895331Samw uint32_t sesskey;
29012508Samw@Sun.COM char ipaddr_buf[INET6_ADDRSTRLEN];
29112508Samw@Sun.COM char *nbdomain;
29212508Samw@Sun.COM uint8_t *wcbuf;
29312508Samw@Sun.COM int wclen;
29412508Samw@Sun.COM smb_msgbuf_t mb;
2956030Sjb150015 int rc;
2965331Samw
2975331Samw if (sr->session->s_state != SMB_SESSION_STATE_ESTABLISHED) {
2985331Samw /* The protocol has already been negotiated. */
2995772Sas200622 smbsr_error(sr, 0, ERRSRV, ERRerror);
3006139Sjb150015 return (SDRC_ERROR);
3015331Samw }
3025331Samw
30312508Samw@Sun.COM sr->session->secmode = NEGOTIATE_SECURITY_CHALLENGE_RESPONSE |
30412508Samw@Sun.COM NEGOTIATE_SECURITY_USER_LEVEL;
30512508Samw@Sun.COM secmode = sr->session->secmode;
3065331Samw
30712508Samw@Sun.COM smb_negotiate_genkey(sr);
30812508Samw@Sun.COM sesskey = sr->session->sesskey;
3095331Samw
31012508Samw@Sun.COM (void) microtime(&negprot->ni_servertime);
31112508Samw@Sun.COM negprot->ni_tzcorrection = sr->sr_gmtoff / 60;
31212508Samw@Sun.COM negprot->ni_maxmpxcount = sr->sr_cfg->skc_maxworkers;
31312508Samw@Sun.COM nbdomain = sr->sr_cfg->skc_nbdomain;
3145331Samw
31512508Samw@Sun.COM /*
31612508Samw@Sun.COM * UNICODE support is required for long share names,
31712508Samw@Sun.COM * long file names and streams.
31812508Samw@Sun.COM */
31912508Samw@Sun.COM negprot->ni_capabilities = CAP_LARGE_FILES
32012508Samw@Sun.COM | CAP_UNICODE
32112508Samw@Sun.COM | CAP_NT_SMBS
32212508Samw@Sun.COM | CAP_STATUS32
32312508Samw@Sun.COM | CAP_NT_FIND
32412508Samw@Sun.COM | CAP_LEVEL_II_OPLOCKS
32512508Samw@Sun.COM | CAP_LOCK_AND_READ
32612508Samw@Sun.COM | CAP_RPC_REMOTE_APIS
32712508Samw@Sun.COM | CAP_LARGE_READX
32812508Samw@Sun.COM | CAP_LARGE_WRITEX
32912508Samw@Sun.COM | CAP_DFS;
3305331Samw
331*12890SJoyce.McIntosh@Sun.COM if (smb_raw_mode) {
332*12890SJoyce.McIntosh@Sun.COM negprot->ni_capabilities |= CAP_RAW_MODE;
333*12890SJoyce.McIntosh@Sun.COM rawmode = 3;
334*12890SJoyce.McIntosh@Sun.COM }
335*12890SJoyce.McIntosh@Sun.COM
33612508Samw@Sun.COM if (smb_cap_passthru)
33712508Samw@Sun.COM negprot->ni_capabilities |= CAP_INFOLEVEL_PASSTHRU;
33812508Samw@Sun.COM else
33912508Samw@Sun.COM cmn_err(CE_NOTE, "smbsrv: cap passthru is %s",
34012508Samw@Sun.COM (negprot->ni_capabilities & CAP_INFOLEVEL_PASSTHRU) ?
34112508Samw@Sun.COM "enabled" : "disabled");
3425331Samw
34312508Samw@Sun.COM (void) smb_inet_ntop(&sr->session->ipaddr, ipaddr_buf,
34412508Samw@Sun.COM SMB_IPSTRLEN(sr->session->ipaddr.a_family));
3455331Samw
34612508Samw@Sun.COM switch (negprot->ni_dialect) {
3475331Samw case PC_NETWORK_PROGRAM_1_0: /* core */
3488348SEric.Yu@Sun.COM (void) ksocket_setsockopt(sr->session->sock, SOL_SOCKET,
3498348SEric.Yu@Sun.COM SO_RCVBUF, (const void *)&smb_dos_tcp_rcvbuf,
3508348SEric.Yu@Sun.COM sizeof (smb_dos_tcp_rcvbuf), CRED());
35112508Samw@Sun.COM rc = smbsr_encode_result(sr, 1, 0, "bww", 1,
35212508Samw@Sun.COM negprot->ni_index, 0);
3535331Samw break;
3545331Samw
3555331Samw case Windows_for_Workgroups_3_1a:
3565331Samw case PCLAN1_0:
3575331Samw case MICROSOFT_NETWORKS_1_03:
3585331Samw case MICROSOFT_NETWORKS_3_0:
3595331Samw case LANMAN1_0:
3605331Samw case LM1_2X002:
3615331Samw case DOS_LM1_2X002:
3628348SEric.Yu@Sun.COM (void) ksocket_setsockopt(sr->session->sock, SOL_SOCKET,
3638348SEric.Yu@Sun.COM SO_RCVBUF, (const void *)&smb_dos_tcp_rcvbuf,
3648348SEric.Yu@Sun.COM sizeof (smb_dos_tcp_rcvbuf), CRED());
3655331Samw sr->smb_flg |= SMB_FLAGS_LOCK_AND_READ_OK;
3666030Sjb150015 rc = smbsr_encode_result(sr, 13, VAR_BCC,
3677052Samw "bwwwwwwlYww2.w#c",
36812508Samw@Sun.COM 13, /* wct */
36912508Samw@Sun.COM negprot->ni_index, /* dialect index */
37012508Samw@Sun.COM secmode, /* security mode */
37112508Samw@Sun.COM SMB_DOS_MAXBUF, /* max buffer size */
37212508Samw@Sun.COM 1, /* max MPX */
37312508Samw@Sun.COM 1, /* max VCs */
374*12890SJoyce.McIntosh@Sun.COM rawmode, /* read/write raw (s/b 3) */
37512508Samw@Sun.COM sesskey, /* session key */
37612508Samw@Sun.COM negprot->ni_servertime.tv_sec, /* server date/time */
37712508Samw@Sun.COM negprot->ni_tzcorrection,
37812508Samw@Sun.COM (uint16_t)negprot->ni_keylen, /* encryption key length */
37912508Samw@Sun.COM /* reserved field handled 2. */
3805331Samw VAR_BCC,
38112508Samw@Sun.COM (int)negprot->ni_keylen,
38212508Samw@Sun.COM negprot->ni_key); /* encryption key */
3835331Samw break;
3845331Samw
3855331Samw case DOS_LANMAN2_1:
3865331Samw case LANMAN2_1:
3878348SEric.Yu@Sun.COM (void) ksocket_setsockopt(sr->session->sock, SOL_SOCKET,
3888348SEric.Yu@Sun.COM SO_RCVBUF, (const void *)&smb_dos_tcp_rcvbuf,
3898348SEric.Yu@Sun.COM sizeof (smb_dos_tcp_rcvbuf), CRED());
3905331Samw sr->smb_flg |= SMB_FLAGS_LOCK_AND_READ_OK;
3916030Sjb150015 rc = smbsr_encode_result(sr, 13, VAR_BCC,
3927052Samw "bwwwwwwlYww2.w#cs",
39312508Samw@Sun.COM 13, /* wct */
39412508Samw@Sun.COM negprot->ni_index, /* dialect index */
39512508Samw@Sun.COM secmode, /* security mode */
39612508Samw@Sun.COM SMB_DOS_MAXBUF, /* max buffer size */
39712508Samw@Sun.COM 1, /* max MPX */
39812508Samw@Sun.COM 1, /* max VCs */
399*12890SJoyce.McIntosh@Sun.COM rawmode, /* read/write raw (s/b 3) */
40012508Samw@Sun.COM sesskey, /* session key */
40112508Samw@Sun.COM negprot->ni_servertime.tv_sec, /* server date/time */
40212508Samw@Sun.COM negprot->ni_tzcorrection,
40312508Samw@Sun.COM (uint16_t)negprot->ni_keylen, /* encryption key length */
40412508Samw@Sun.COM /* reserved field handled 2. */
4055331Samw VAR_BCC,
40612508Samw@Sun.COM (int)negprot->ni_keylen,
40712508Samw@Sun.COM negprot->ni_key, /* encryption key */
40812508Samw@Sun.COM nbdomain);
4095331Samw break;
4105331Samw
4115331Samw case NT_LM_0_12:
4128348SEric.Yu@Sun.COM (void) ksocket_setsockopt(sr->session->sock, SOL_SOCKET,
4138348SEric.Yu@Sun.COM SO_RCVBUF, (const void *)&smb_nt_tcp_rcvbuf,
4148348SEric.Yu@Sun.COM sizeof (smb_nt_tcp_rcvbuf), CRED());
4155331Samw
4165331Samw /*
4175331Samw * Turn off Extended Security Negotiation
4185331Samw */
4195331Samw sr->smb_flg2 &= ~SMB_FLAGS2_EXT_SEC;
4205331Samw
4215331Samw /*
4225331Samw * Allow SMB signatures if security challenge response enabled
4235331Samw */
4245331Samw if ((secmode & NEGOTIATE_SECURITY_CHALLENGE_RESPONSE) &&
4256139Sjb150015 sr->sr_cfg->skc_signing_enable) {
4265331Samw secmode |= NEGOTIATE_SECURITY_SIGNATURES_ENABLED;
4276139Sjb150015 if (sr->sr_cfg->skc_signing_required)
4285331Samw secmode |=
4295331Samw NEGOTIATE_SECURITY_SIGNATURES_REQUIRED;
4305331Samw
4315331Samw sr->session->secmode = secmode;
4325331Samw }
4335331Samw
4347961SNatalie.Li@Sun.COM /*
43512508Samw@Sun.COM * nbdomain is not expected to be aligned.
4367961SNatalie.Li@Sun.COM * Use temporary buffer to avoid alignment padding
4377961SNatalie.Li@Sun.COM */
43812508Samw@Sun.COM wclen = smb_wcequiv_strlen(nbdomain) + sizeof (smb_wchar_t);
43912508Samw@Sun.COM wcbuf = smb_srm_zalloc(sr, wclen);
44012508Samw@Sun.COM smb_msgbuf_init(&mb, wcbuf, wclen, SMB_MSGBUF_UNICODE);
44112508Samw@Sun.COM if (smb_msgbuf_encode(&mb, "U", nbdomain) < 0) {
4427961SNatalie.Li@Sun.COM smb_msgbuf_term(&mb);
4437961SNatalie.Li@Sun.COM smbsr_error(sr, 0, ERRSRV, ERRerror);
4447961SNatalie.Li@Sun.COM return (SDRC_ERROR);
4457961SNatalie.Li@Sun.COM }
4467961SNatalie.Li@Sun.COM
4476030Sjb150015 rc = smbsr_encode_result(sr, 17, VAR_BCC,
4487961SNatalie.Li@Sun.COM "bwbwwllllTwbw#c#c",
44912508Samw@Sun.COM 17, /* wct */
45012508Samw@Sun.COM negprot->ni_index, /* dialect index */
45112508Samw@Sun.COM secmode, /* security mode */
45212508Samw@Sun.COM negprot->ni_maxmpxcount, /* max MPX */
45312508Samw@Sun.COM 1, /* max VCs */
4545331Samw (DWORD)smb_maxbufsize, /* max buffer size */
45512508Samw@Sun.COM 0xFFFF, /* max raw size */
45612508Samw@Sun.COM sesskey, /* session key */
45712508Samw@Sun.COM negprot->ni_capabilities,
45812508Samw@Sun.COM &negprot->ni_servertime, /* system time */
45912508Samw@Sun.COM negprot->ni_tzcorrection,
46012508Samw@Sun.COM negprot->ni_keylen, /* encryption key length */
4615331Samw VAR_BCC,
46212508Samw@Sun.COM (int)negprot->ni_keylen,
46312508Samw@Sun.COM negprot->ni_key, /* encryption key */
46412508Samw@Sun.COM wclen,
46512508Samw@Sun.COM wcbuf); /* nbdomain (unicode) */
4667961SNatalie.Li@Sun.COM
4677961SNatalie.Li@Sun.COM smb_msgbuf_term(&mb);
4685331Samw break;
4695331Samw
4705331Samw default:
47112508Samw@Sun.COM rc = smbsr_encode_result(sr, 1, 0, "bww", 1, -1, 0);
4727961SNatalie.Li@Sun.COM return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
4735331Samw }
4745331Samw
4756030Sjb150015 if (rc != 0)
4766139Sjb150015 return (SDRC_ERROR);
4776030Sjb150015
4785331Samw /*
4795331Samw * Save the agreed dialect. Note that this value is also
4805331Samw * used to detect and reject attempts to re-negotiate.
4815331Samw */
48212508Samw@Sun.COM sr->session->dialect = negprot->ni_dialect;
4835331Samw sr->session->s_state = SMB_SESSION_STATE_NEGOTIATED;
4846139Sjb150015 return (SDRC_SUCCESS);
4855331Samw }
4865331Samw
4875331Samw static void
smb_negotiate_genkey(smb_request_t * sr)48812508Samw@Sun.COM smb_negotiate_genkey(smb_request_t *sr)
4895331Samw {
49012508Samw@Sun.COM smb_arg_negotiate_t *negprot = sr->sr_negprot;
49112508Samw@Sun.COM uint8_t tmp_key[8];
4925331Samw
4935331Samw (void) random_get_pseudo_bytes(tmp_key, 8);
4945331Samw bcopy(tmp_key, &sr->session->challenge_key, 8);
4955331Samw sr->session->challenge_len = 8;
49612508Samw@Sun.COM negprot->ni_keylen = 8;
49712508Samw@Sun.COM bcopy(tmp_key, negprot->ni_key, 8);
4985331Samw
4995331Samw (void) random_get_pseudo_bytes(tmp_key, 4);
5005331Samw sr->session->sesskey = tmp_key[0] | tmp_key[1] << 8 |
5015331Samw tmp_key[2] << 16 | tmp_key[3] << 24;
50212508Samw@Sun.COM }
5035331Samw
50412508Samw@Sun.COM static int
smb_xlate_dialect(const char * dialect)50512508Samw@Sun.COM smb_xlate_dialect(const char *dialect)
50612508Samw@Sun.COM {
50712508Samw@Sun.COM smb_xlate_t *dp;
50812508Samw@Sun.COM int i;
50912508Samw@Sun.COM
51012508Samw@Sun.COM for (i = 0; i < sizeof (smb_dialect) / sizeof (smb_dialect[0]); ++i) {
51112508Samw@Sun.COM dp = &smb_dialect[i];
51212508Samw@Sun.COM
51312508Samw@Sun.COM if (strcmp(dp->str, dialect) == 0)
51412508Samw@Sun.COM return (dp->code);
51512508Samw@Sun.COM }
51612508Samw@Sun.COM
51712508Samw@Sun.COM return (-1);
5185331Samw }
519