xref: /illumos-gate/usr/src/uts/common/fs/smbsrv/smb_tree_connect.c (revision f998c95e3b7029fe5f7542e115f7474ddb8024d7)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 /*
29  * SMB: tree_connect
30  *
31  * When a client connects to a server resource, an SMB_COM_TREE_CONNECT
32  * message is generated to the server. This command is almost exactly like
33  * SMB_COM_TREE_CONNECT_ANDX, except that no AndX command may follow; see
34  * section 4.1.4.
35  *
36  * Client Request                     Description
37  * ================================== =================================
38  *
39  * UCHAR WordCount;                   Count of parameter words = 0
40  * USHORT ByteCount;                  Count of data bytes;    min = 4
41  * UCHAR BufferFormat1;               0x04
42  * STRING Path[];                     Server name and share name
43  * UCHAR BufferFormat2;               0x04
44  * STRING Password[];                 Password
45  * UCHAR BufferFormat3;               0x04
46  * STRING Service[];                  Service name
47  *
48  * The CIFS server responds with:
49  *
50  * Server Response                  Description
51  * ================================ =================================
52  *
53  * UCHAR WordCount;                 Count of parameter words = 2
54  * USHORT MaxBufferSize;            Max size message the server handles
55  * USHORT Tid;                      Tree ID
56  * USHORT ByteCount;                Count of data bytes = 0
57  *
58  * If the negotiated dialect is MICROSOFT NETWORKS 1.03 or earlier,
59  * MaxBufferSize in the response message indicates the maximum size message
60  * that the server can handle.  The client should not generate messages,
61  * nor expect to receive responses, larger than this.  This must be
62  * constant for a given server.  For newer dialects, this field is ignored.
63  *
64  * Tid should be included in any future SMBs referencing this tree
65  * connection.
66  */
67 
68 #include <smbsrv/smb_incl.h>
69 
70 /*
71  * If the negotiated dialect is MICROSOFT NETWORKS 1.03 or earlier,
72  * MaxBufferSize in the response message indicates the maximum size
73  * message that the server can handle.  The client should not generate
74  * messages, nor expect to receive responses, larger than this.  This
75  * must be constant for a given server. For newer dialects, this field
76  * is ignored.
77  */
78 smb_sdrc_t
79 smb_pre_tree_connect(smb_request_t *sr)
80 {
81 	int rc;
82 
83 	/*
84 	 * Perhaps this should be "%A.sA" now that unicode is enabled.
85 	 */
86 	rc = smbsr_decode_data(sr, "%AAA", sr, &sr->arg.tcon.path,
87 	    &sr->arg.tcon.password, &sr->arg.tcon.service);
88 
89 	sr->arg.tcon.flags = 0;
90 
91 	DTRACE_SMB_2(op__TreeConnect__start, smb_request_t *, sr,
92 	    struct tcon *, &sr->arg.tcon);
93 
94 	return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
95 }
96 
97 void
98 smb_post_tree_connect(smb_request_t *sr)
99 {
100 	DTRACE_SMB_1(op__TreeConnect__done, smb_request_t *, sr);
101 }
102 
103 smb_sdrc_t
104 smb_com_tree_connect(smb_request_t *sr)
105 {
106 	int rc;
107 
108 	if (smbsr_connect_tree(sr) != 0)
109 		return (SDRC_ERROR);
110 
111 	rc = smbsr_encode_result(sr, 2, 0, "bwww",
112 	    2,				/* wct */
113 	    (WORD)smb_maxbufsize,	/* MaxBufferSize */
114 	    sr->smb_tid,		/* TID */
115 	    0);				/* bcc */
116 
117 	return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
118 }
119