1da6c28aaSamw /*
2da6c28aaSamw * CDDL HEADER START
3da6c28aaSamw *
4da6c28aaSamw * The contents of this file are subject to the terms of the
5da6c28aaSamw * Common Development and Distribution License (the "License").
6da6c28aaSamw * You may not use this file except in compliance with the License.
7da6c28aaSamw *
8da6c28aaSamw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9da6c28aaSamw * or http://www.opensolaris.org/os/licensing.
10da6c28aaSamw * See the License for the specific language governing permissions
11da6c28aaSamw * and limitations under the License.
12da6c28aaSamw *
13da6c28aaSamw * When distributing Covered Code, include this CDDL HEADER in each
14da6c28aaSamw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15da6c28aaSamw * If applicable, add the following below this CDDL HEADER, with the
16da6c28aaSamw * fields enclosed by brackets "[]" replaced with your own identifying
17da6c28aaSamw * information: Portions Copyright [yyyy] [name of copyright owner]
18da6c28aaSamw *
19da6c28aaSamw * CDDL HEADER END
20da6c28aaSamw */
21da6c28aaSamw /*
22148c5f43SAlan Wright * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23*27f3c5a8SGordon Ross * Copyright 2019 Nexenta by DDN, Inc. All rights reserved.
24da6c28aaSamw */
25da6c28aaSamw
26bbf6f00cSJordan Brown #include <smbsrv/smb_kproto.h>
27cb174861Sjoyce mcintosh #include <smbsrv/smb_share.h>
28da6c28aaSamw
29a90cf9f2SGordon Ross static void
smb_tcon_puterror(smb_request_t * sr,uint32_t status)30a90cf9f2SGordon Ross smb_tcon_puterror(smb_request_t *sr, uint32_t status)
31a90cf9f2SGordon Ross {
32a90cf9f2SGordon Ross
33a90cf9f2SGordon Ross switch (status) {
34a90cf9f2SGordon Ross
35a90cf9f2SGordon Ross case NT_STATUS_BAD_NETWORK_NAME:
36a90cf9f2SGordon Ross /* Intentional status=0 */
37a90cf9f2SGordon Ross smbsr_error(sr, 0, ERRSRV, ERRinvnetname);
38a90cf9f2SGordon Ross break;
39a90cf9f2SGordon Ross
40a90cf9f2SGordon Ross case NT_STATUS_ACCESS_DENIED:
41a90cf9f2SGordon Ross smbsr_error(sr, status, ERRSRV, ERRaccess);
42a90cf9f2SGordon Ross break;
43a90cf9f2SGordon Ross
44a90cf9f2SGordon Ross case NT_STATUS_BAD_DEVICE_TYPE:
45a90cf9f2SGordon Ross smbsr_error(sr, status, ERRDOS, ERROR_BAD_DEV_TYPE);
46a90cf9f2SGordon Ross break;
47a90cf9f2SGordon Ross
48a90cf9f2SGordon Ross default:
49a90cf9f2SGordon Ross case NT_STATUS_INTERNAL_ERROR:
50a90cf9f2SGordon Ross /* Intentional status=0 */
51a90cf9f2SGordon Ross smbsr_error(sr, 0, ERRSRV, ERRsrverror);
52a90cf9f2SGordon Ross break;
53a90cf9f2SGordon Ross }
54a90cf9f2SGordon Ross }
55a90cf9f2SGordon Ross
56da6c28aaSamw /*
57c8ec8eeaSjose borrego * SmbTreeConnect: Map a share to a tree and obtain a tree-id (TID).
58da6c28aaSamw *
59da6c28aaSamw * Client Request Description
60da6c28aaSamw * ================================== =================================
61da6c28aaSamw *
62da6c28aaSamw * UCHAR WordCount; Count of parameter words = 0
63da6c28aaSamw * USHORT ByteCount; Count of data bytes; min = 4
64da6c28aaSamw * UCHAR BufferFormat1; 0x04
65da6c28aaSamw * STRING Path[]; Server name and share name
66da6c28aaSamw * UCHAR BufferFormat2; 0x04
67da6c28aaSamw * STRING Password[]; Password
68da6c28aaSamw * UCHAR BufferFormat3; 0x04
69da6c28aaSamw * STRING Service[]; Service name
70da6c28aaSamw *
71da6c28aaSamw * The CIFS server responds with:
72da6c28aaSamw *
73da6c28aaSamw * Server Response Description
74da6c28aaSamw * ================================ =================================
75da6c28aaSamw *
76da6c28aaSamw * UCHAR WordCount; Count of parameter words = 2
77da6c28aaSamw * USHORT MaxBufferSize; Max size message the server handles
78da6c28aaSamw * USHORT Tid; Tree ID
79da6c28aaSamw * USHORT ByteCount; Count of data bytes = 0
80da6c28aaSamw *
817b59d02dSjb * If the negotiated dialect is MICROSOFT NETWORKS 1.03 or earlier,
827b59d02dSjb * MaxBufferSize in the response message indicates the maximum size
837b59d02dSjb * message that the server can handle. The client should not generate
847b59d02dSjb * messages, nor expect to receive responses, larger than this. This
857b59d02dSjb * must be constant for a given server. For newer dialects, this field
867b59d02dSjb * is ignored.
877b59d02dSjb */
887b59d02dSjb smb_sdrc_t
smb_pre_tree_connect(smb_request_t * sr)89faa1795aSjb smb_pre_tree_connect(smb_request_t *sr)
90da6c28aaSamw {
91148c5f43SAlan Wright smb_arg_tcon_t *tcon = &sr->sr_tcon;
92148c5f43SAlan Wright int rc;
937b59d02dSjb
94da6c28aaSamw /*
957b59d02dSjb * Perhaps this should be "%A.sA" now that unicode is enabled.
96da6c28aaSamw */
97148c5f43SAlan Wright rc = smbsr_decode_data(sr, "%AAA", sr, &tcon->path,
98148c5f43SAlan Wright &tcon->password, &tcon->service);
99da6c28aaSamw
100148c5f43SAlan Wright tcon->flags = 0;
101148c5f43SAlan Wright tcon->optional_support = 0;
102da6c28aaSamw
10393bc28dbSGordon Ross DTRACE_SMB_START(op__TreeConnect, smb_request_t *, sr);
104faa1795aSjb
105faa1795aSjb return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
106faa1795aSjb }
107faa1795aSjb
108faa1795aSjb void
smb_post_tree_connect(smb_request_t * sr)109faa1795aSjb smb_post_tree_connect(smb_request_t *sr)
110faa1795aSjb {
11193bc28dbSGordon Ross DTRACE_SMB_DONE(op__TreeConnect, smb_request_t *, sr);
112faa1795aSjb }
113faa1795aSjb
114faa1795aSjb smb_sdrc_t
smb_com_tree_connect(smb_request_t * sr)115faa1795aSjb smb_com_tree_connect(smb_request_t *sr)
116faa1795aSjb {
117a90cf9f2SGordon Ross uint32_t status;
118faa1795aSjb int rc;
119faa1795aSjb
120a90cf9f2SGordon Ross status = smb_tree_connect(sr);
121a90cf9f2SGordon Ross if (status) {
122a90cf9f2SGordon Ross smb_tcon_puterror(sr, status);
123faa1795aSjb return (SDRC_ERROR);
124a90cf9f2SGordon Ross }
125c8ec8eeaSjose borrego
1267b59d02dSjb rc = smbsr_encode_result(sr, 2, 0, "bwww",
127da6c28aaSamw 2, /* wct */
128da6c28aaSamw (WORD)smb_maxbufsize, /* MaxBufferSize */
129da6c28aaSamw sr->smb_tid, /* TID */
130da6c28aaSamw 0); /* bcc */
131da6c28aaSamw
132faa1795aSjb return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
133da6c28aaSamw }
134c8ec8eeaSjose borrego
135c8ec8eeaSjose borrego /*
136c8ec8eeaSjose borrego * SmbTreeConnectX: Map a share to a tree and obtain a tree-id (TID).
137c8ec8eeaSjose borrego *
138c8ec8eeaSjose borrego * Client Request Description
139c8ec8eeaSjose borrego * ================================= =================================
140c8ec8eeaSjose borrego *
141c8ec8eeaSjose borrego * UCHAR WordCount; Count of parameter words = 4
142c8ec8eeaSjose borrego * UCHAR AndXCommand; Secondary (X) command; 0xFF = none
143c8ec8eeaSjose borrego * UCHAR AndXReserved; Reserved (must be 0)
144c8ec8eeaSjose borrego * USHORT AndXOffset; Offset to next command WordCount
145c8ec8eeaSjose borrego * USHORT Flags; Additional information
146c8ec8eeaSjose borrego * bit 0 set = disconnect Tid
147c8ec8eeaSjose borrego * USHORT PasswordLength; Length of Password[]
148c8ec8eeaSjose borrego * USHORT ByteCount; Count of data bytes; min = 3
149c8ec8eeaSjose borrego * UCHAR Password[]; Password
150c8ec8eeaSjose borrego * STRING Path[]; Server name and share name
151c8ec8eeaSjose borrego * STRING Service[]; Service name
152c8ec8eeaSjose borrego *
153c8ec8eeaSjose borrego * If the negotiated dialect is LANMAN1.0 or later, then it is a protocol
154c8ec8eeaSjose borrego * violation for the client to send this message prior to a successful
155c8ec8eeaSjose borrego * SMB_COM_SESSION_SETUP_ANDX, and the server ignores Password.
156c8ec8eeaSjose borrego *
157c8ec8eeaSjose borrego * If the negotiated dialect is prior to LANMAN1.0 and the client has not
158c8ec8eeaSjose borrego * sent a successful SMB_COM_SESSION_SETUP_ANDX request when the tree
159c8ec8eeaSjose borrego * connect arrives, a user level security mode server must nevertheless
160c8ec8eeaSjose borrego * validate the client's credentials.
161c8ec8eeaSjose borrego *
1628d7e4166Sjose borrego * Flags (prefix with TREE_CONNECT_ANDX_):
1638d7e4166Sjose borrego * ========================== ========================================
1648d7e4166Sjose borrego * 0x0001 DISCONECT_TID The tree specified by TID in the SMB header
1658d7e4166Sjose borrego * should be disconnected - disconnect errors
1668d7e4166Sjose borrego * should be ignored.
1678d7e4166Sjose borrego *
1688d7e4166Sjose borrego * 0x0004 EXTENDED_SIGNATURES Client request for signing key protection.
1698d7e4166Sjose borrego *
1708d7e4166Sjose borrego * 0x0008 EXTENDED_RESPONSE Client request for extended information.
1718d7e4166Sjose borrego *
1728d7e4166Sjose borrego * Path follows UNC style syntax (\\server\share) and indicates the name
1738d7e4166Sjose borrego * of the resource to which the client wishes to connect.
174c8ec8eeaSjose borrego *
175c8ec8eeaSjose borrego * Because Password may be an authentication response, it is a variable
176c8ec8eeaSjose borrego * length field with the length specified by PasswordLength. If
177c8ec8eeaSjose borrego * authentication is not being used, Password should be a null terminated
178c8ec8eeaSjose borrego * ASCII string with PasswordLength set to the string size including the
179c8ec8eeaSjose borrego * terminating null.
180c8ec8eeaSjose borrego *
181c8ec8eeaSjose borrego * The server can enforce whatever policy it desires to govern share
182c8ec8eeaSjose borrego * access. Administrative privilege is required for administrative
183c8ec8eeaSjose borrego * shares (C$, etc.).
184c8ec8eeaSjose borrego *
185c8ec8eeaSjose borrego * The Service component indicates the type of resource the client
186c8ec8eeaSjose borrego * intends to access. Valid values are:
187c8ec8eeaSjose borrego *
188c8ec8eeaSjose borrego * Service Description Earliest Dialect Allowed
189c8ec8eeaSjose borrego * ======== ======================== ================================
190c8ec8eeaSjose borrego *
191c8ec8eeaSjose borrego * A: disk share PC NETWORK PROGRAM 1.0
192c8ec8eeaSjose borrego * LPT1: printer PC NETWORK PROGRAM 1.0
193c8ec8eeaSjose borrego * IPC named pipe MICROSOFT NETWORKS 3.0
194c8ec8eeaSjose borrego * COMM communications device MICROSOFT NETWORKS 3.0
195c8ec8eeaSjose borrego * ????? any type of device MICROSOFT NETWORKS 3.0
196c8ec8eeaSjose borrego *
197c8ec8eeaSjose borrego * If the negotiated dialect is earlier than DOS LANMAN2.1, the response to
198c8ec8eeaSjose borrego * this SMB is:
199c8ec8eeaSjose borrego *
200c8ec8eeaSjose borrego * Server Response Description
201c8ec8eeaSjose borrego * ================================ ===================================
202c8ec8eeaSjose borrego *
203c8ec8eeaSjose borrego * UCHAR WordCount; Count of parameter words = 2
204c8ec8eeaSjose borrego * UCHAR AndXCommand; Secondary (X) command; 0xFF = none
205c8ec8eeaSjose borrego * UCHAR AndXReserved; Reserved (must be 0)
206c8ec8eeaSjose borrego * USHORT AndXOffset; Offset to next command WordCount
207c8ec8eeaSjose borrego * USHORT ByteCount; Count of data bytes; min = 3
208c8ec8eeaSjose borrego *
209c8ec8eeaSjose borrego * If the negotiated is DOS LANMAN2.1 or later, the response to this SMB
210c8ec8eeaSjose borrego * is:
211c8ec8eeaSjose borrego *
212c8ec8eeaSjose borrego * Server Response Description
213c8ec8eeaSjose borrego * ================================ ===================================
214c8ec8eeaSjose borrego *
215c8ec8eeaSjose borrego * UCHAR WordCount; Count of parameter words = 3
216c8ec8eeaSjose borrego * UCHAR AndXCommand; Secondary (X) command; 0xFF = none
217c8ec8eeaSjose borrego * UCHAR AndXReserved; Reserved (must be 0)
218c8ec8eeaSjose borrego * USHORT AndXOffset; Offset to next command WordCount
219c8ec8eeaSjose borrego * USHORT OptionalSupport; Optional support bits
220c8ec8eeaSjose borrego * USHORT ByteCount; Count of data bytes; min = 3
221c8ec8eeaSjose borrego * UCHAR Service[]; Service type connected to. Always
222c8ec8eeaSjose borrego * ANSII.
223c8ec8eeaSjose borrego * STRING NativeFileSystem[]; Native file system for this tree
224c8ec8eeaSjose borrego *
225c8ec8eeaSjose borrego * NativeFileSystem is the name of the filesystem; values to be expected
226c8ec8eeaSjose borrego * include FAT, NTFS, etc.
227c8ec8eeaSjose borrego *
2288d7e4166Sjose borrego * OptionalSupport:
2298d7e4166Sjose borrego * ============================== ==========================
2308d7e4166Sjose borrego * 0x0001 SMB_SUPPORT_SEARCH_BITS The server supports the use of Search
2318d7e4166Sjose borrego * Attributes in client requests.
2328d7e4166Sjose borrego * 0x0002 SMB_SHARE_IS_IN_DFS The share is managed by DFS.
2338d7e4166Sjose borrego * 0x000C SMB_CSC_MASK Offline-caching mask - see CSC flags.
2348d7e4166Sjose borrego * 0x0010 SMB_UNIQUE_FILE_NAME The server uses long names and does not
2358d7e4166Sjose borrego * support short names. Indicator for
2368d7e4166Sjose borrego * clients directory/name-space caching.
2378d7e4166Sjose borrego * 0x0020 SMB_EXTENDED_SIGNATURES The server will use signing key protection.
2388d7e4166Sjose borrego *
2398d7e4166Sjose borrego * Client-side caching (offline files):
2408d7e4166Sjose borrego * ============================== ==========================
2418d7e4166Sjose borrego * 0x0000 SMB_CSC_CACHE_MANUAL_REINT Clients may cache files for offline use
2428d7e4166Sjose borrego * but automatic file-by-file reintegration
2438d7e4166Sjose borrego * is not allowed.
2448d7e4166Sjose borrego * 0x0004 SMB_CSC_CACHE_AUTO_REINT Automatic file-by-file reintegration is
2458d7e4166Sjose borrego * allowed.
2468d7e4166Sjose borrego * 0x0008 SMB_CSC_CACHE_VDO File opens do not need to be flowed.
2478d7e4166Sjose borrego * 0x000C SMB_CSC_CACHE_NONE CSC is disabled for this share.
248c8ec8eeaSjose borrego *
249c8ec8eeaSjose borrego * Some servers negotiate "DOS LANMAN2.1" dialect or later and still send
250c8ec8eeaSjose borrego * the "downlevel" (i.e. wordcount==2) response. Valid AndX following
251c8ec8eeaSjose borrego * commands are
252c8ec8eeaSjose borrego *
253c8ec8eeaSjose borrego * SMB_COM_OPEN SMB_COM_OPEN_ANDX SMB_COM_CREATE
254c8ec8eeaSjose borrego * SMB_COM_CREATE_NEW SMB_COM_CREATE_DIRECTORY SMB_COM_DELETE
255c8ec8eeaSjose borrego * SMB_COM_DELETE_DIRECTORY SMB_COM_FIND SMB_COM_COPY
256c8ec8eeaSjose borrego * SMB_COM_FIND_UNIQUE SMB_COM_RENAME
257c8ec8eeaSjose borrego * SMB_COM_CHECK_DIRECTORY SMB_COM_QUERY_INFORMATION
258c8ec8eeaSjose borrego * SMB_COM_GET_PRINT_QUEUE SMB_COM_OPEN_PRINT_FILE
259c8ec8eeaSjose borrego * SMB_COM_TRANSACTION SMB_COM_NO_ANDX_CMD
260c8ec8eeaSjose borrego * SMB_COM_SET_INFORMATION SMB_COM_NT_RENAME
261c8ec8eeaSjose borrego *
262c8ec8eeaSjose borrego * Errors:
263c8ec8eeaSjose borrego * ERRDOS/ERRnomem
264c8ec8eeaSjose borrego * ERRDOS/ERRbadpath
265c8ec8eeaSjose borrego * ERRDOS/ERRinvdevice
266c8ec8eeaSjose borrego * ERRSRV/ERRaccess
267c8ec8eeaSjose borrego * ERRSRV/ERRbadpw
268c8ec8eeaSjose borrego * ERRSRV/ERRinvnetname
269c8ec8eeaSjose borrego */
270c8ec8eeaSjose borrego smb_sdrc_t
smb_pre_tree_connect_andx(smb_request_t * sr)271c8ec8eeaSjose borrego smb_pre_tree_connect_andx(smb_request_t *sr)
272c8ec8eeaSjose borrego {
273148c5f43SAlan Wright smb_arg_tcon_t *tcon = &sr->sr_tcon;
274148c5f43SAlan Wright uint8_t *pwbuf = NULL;
275148c5f43SAlan Wright uint16_t pwlen = 0;
276148c5f43SAlan Wright int rc;
277c8ec8eeaSjose borrego
278c8ec8eeaSjose borrego rc = smbsr_decode_vwv(sr, "b.www", &sr->andx_com, &sr->andx_off,
279148c5f43SAlan Wright &tcon->flags, &pwlen);
280c8ec8eeaSjose borrego if (rc == 0) {
2819fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (pwlen != 0)
2829fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States pwbuf = smb_srm_zalloc(sr, pwlen);
283c8ec8eeaSjose borrego
284c8ec8eeaSjose borrego rc = smbsr_decode_data(sr, "%#cus", sr, pwlen, pwbuf,
285148c5f43SAlan Wright &tcon->path, &tcon->service);
286c8ec8eeaSjose borrego
287148c5f43SAlan Wright tcon->pwdlen = pwlen;
288148c5f43SAlan Wright tcon->password = (char *)pwbuf;
289c8ec8eeaSjose borrego }
290c8ec8eeaSjose borrego
291148c5f43SAlan Wright tcon->optional_support = 0;
2928d7e4166Sjose borrego
29393bc28dbSGordon Ross DTRACE_SMB_START(op__TreeConnectX, smb_request_t *, sr);
294c8ec8eeaSjose borrego
295c8ec8eeaSjose borrego return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
296c8ec8eeaSjose borrego }
297c8ec8eeaSjose borrego
298c8ec8eeaSjose borrego void
smb_post_tree_connect_andx(smb_request_t * sr)299c8ec8eeaSjose borrego smb_post_tree_connect_andx(smb_request_t *sr)
300c8ec8eeaSjose borrego {
30193bc28dbSGordon Ross DTRACE_SMB_DONE(op__TreeConnectX, smb_request_t *, sr);
302c8ec8eeaSjose borrego }
303c8ec8eeaSjose borrego
304c8ec8eeaSjose borrego smb_sdrc_t
smb_com_tree_connect_andx(smb_request_t * sr)305c8ec8eeaSjose borrego smb_com_tree_connect_andx(smb_request_t *sr)
306c8ec8eeaSjose borrego {
307148c5f43SAlan Wright smb_arg_tcon_t *tcon = &sr->sr_tcon;
308593e4726SGordon Ross smb_tree_t *tree;
309148c5f43SAlan Wright char *service;
310a90cf9f2SGordon Ross uint32_t status;
311148c5f43SAlan Wright int rc;
312c8ec8eeaSjose borrego
313593e4726SGordon Ross if (tcon->flags & SMB_TCONX_DISCONECT_TID) {
314593e4726SGordon Ross tree = smb_session_lookup_tree(sr->session, sr->smb_tid);
315593e4726SGordon Ross if (tree != NULL) {
316593e4726SGordon Ross smb_tree_disconnect(tree, B_TRUE);
3170897f7fbSGordon Ross smb_session_cancel_requests(sr->session, tree, sr);
318*27f3c5a8SGordon Ross smb_tree_release(tree);
319593e4726SGordon Ross }
320593e4726SGordon Ross }
321593e4726SGordon Ross
322a90cf9f2SGordon Ross status = smb_tree_connect(sr);
323a90cf9f2SGordon Ross if (status) {
324a90cf9f2SGordon Ross smb_tcon_puterror(sr, status);
325c8ec8eeaSjose borrego return (SDRC_ERROR);
326a90cf9f2SGordon Ross }
327593e4726SGordon Ross tree = sr->tid_tree;
328c8ec8eeaSjose borrego
329593e4726SGordon Ross switch (tree->t_res_type & STYPE_MASK) {
330148c5f43SAlan Wright case STYPE_IPC:
331c8ec8eeaSjose borrego service = "IPC";
332148c5f43SAlan Wright break;
333148c5f43SAlan Wright case STYPE_PRINTQ:
334148c5f43SAlan Wright service = "LPT1:";
335148c5f43SAlan Wright break;
336148c5f43SAlan Wright case STYPE_DISKTREE:
337148c5f43SAlan Wright default:
338c8ec8eeaSjose borrego service = "A:";
339148c5f43SAlan Wright }
340c8ec8eeaSjose borrego
341c8ec8eeaSjose borrego if (sr->session->dialect < NT_LM_0_12) {
342593e4726SGordon Ross rc = smbsr_encode_result(sr, 2, VAR_BCC, "bb.ww%ss",
343c8ec8eeaSjose borrego (char)2, /* wct */
344c8ec8eeaSjose borrego sr->andx_com,
345c8ec8eeaSjose borrego VAR_BCC,
346c8ec8eeaSjose borrego VAR_BCC,
347593e4726SGordon Ross sr,
348c8ec8eeaSjose borrego service,
349593e4726SGordon Ross tree->t_typename);
350593e4726SGordon Ross } else if ((tcon->flags & SMB_TCONX_EXTENDED_RESPONSE) == 0) {
351593e4726SGordon Ross rc = smbsr_encode_result(sr, 3, VAR_BCC, "bb.www%su",
352c8ec8eeaSjose borrego (char)3, /* wct */
353c8ec8eeaSjose borrego sr->andx_com,
354c8ec8eeaSjose borrego (short)64,
355148c5f43SAlan Wright tcon->optional_support,
356c8ec8eeaSjose borrego VAR_BCC,
357c8ec8eeaSjose borrego sr,
358593e4726SGordon Ross service,
359593e4726SGordon Ross tree->t_typename);
360593e4726SGordon Ross
361593e4726SGordon Ross } else {
362593e4726SGordon Ross rc = smbsr_encode_result(sr, 7, VAR_BCC, "bb.wwllw%su",
363593e4726SGordon Ross (char)7, /* wct (b) */
364593e4726SGordon Ross sr->andx_com, /* AndXcmd (b) */
365593e4726SGordon Ross (short)72, /* AndXoff (w) */
366593e4726SGordon Ross tcon->optional_support, /* (w) */
367593e4726SGordon Ross tree->t_access, /* (l) */
368593e4726SGordon Ross 0, /* guest_access (l) */
369593e4726SGordon Ross VAR_BCC, /* (w) */
370593e4726SGordon Ross sr, /* (%) */
371593e4726SGordon Ross service, /* (s) */
372593e4726SGordon Ross tree->t_typename); /* (u) */
373c8ec8eeaSjose borrego }
374c8ec8eeaSjose borrego
375c8ec8eeaSjose borrego return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
376c8ec8eeaSjose borrego }
377c8ec8eeaSjose borrego
378c8ec8eeaSjose borrego /*
379c8ec8eeaSjose borrego * SmbTreeDisconnect: Disconnect a tree.
380c8ec8eeaSjose borrego *
381c8ec8eeaSjose borrego * Note: SDDF_SUPPRESS_UID is set for this operation, which means the sr
382c8ec8eeaSjose borrego * uid_user field will not be valid on entry to these functions. Do not
383c8ec8eeaSjose borrego * use it until it is set up in smb_com_tree_disconnect() or the system
384c8ec8eeaSjose borrego * will panic.
385c8ec8eeaSjose borrego *
386c8ec8eeaSjose borrego * Note: there are scenarios in which the client does not send a tree
387c8ec8eeaSjose borrego * disconnect request, for example, when ERRbaduid is returned from
388c8ec8eeaSjose borrego * SmbReadX after a user has logged off. Any open files will remain
389c8ec8eeaSjose borrego * around until the session is destroyed.
390c8ec8eeaSjose borrego *
391c8ec8eeaSjose borrego * Client Request Description
392c8ec8eeaSjose borrego * ================================== =================================
393c8ec8eeaSjose borrego *
394c8ec8eeaSjose borrego * UCHAR WordCount; Count of parameter words = 0
395c8ec8eeaSjose borrego * USHORT ByteCount; Count of data bytes = 0
396c8ec8eeaSjose borrego *
397c8ec8eeaSjose borrego * The resource sharing connection identified by Tid in the SMB header is
398c8ec8eeaSjose borrego * logically disconnected from the server. Tid is invalidated; it will not
399c8ec8eeaSjose borrego * be recognized if used by the client for subsequent requests. All locks,
400c8ec8eeaSjose borrego * open files, etc. created on behalf of Tid are released.
401c8ec8eeaSjose borrego *
402c8ec8eeaSjose borrego * Server Response Description
403c8ec8eeaSjose borrego * ================================== =================================
404c8ec8eeaSjose borrego *
405c8ec8eeaSjose borrego * UCHAR WordCount; Count of parameter words = 0
406c8ec8eeaSjose borrego * USHORT ByteCount; Count of data bytes = 0
407c8ec8eeaSjose borrego *
408c8ec8eeaSjose borrego * Errors:
409c8ec8eeaSjose borrego * ERRSRV/ERRinvnid
410c8ec8eeaSjose borrego * ERRSRV/ERRbaduid
411c8ec8eeaSjose borrego */
412c8ec8eeaSjose borrego smb_sdrc_t
smb_pre_tree_disconnect(smb_request_t * sr)413c8ec8eeaSjose borrego smb_pre_tree_disconnect(smb_request_t *sr)
414c8ec8eeaSjose borrego {
415148c5f43SAlan Wright sr->uid_user = smb_session_lookup_uid(sr->session, sr->smb_uid);
4163b13a1efSThomas Keiser sr->tid_tree = smb_session_lookup_tree(sr->session, sr->smb_tid);
417148c5f43SAlan Wright
41893bc28dbSGordon Ross DTRACE_SMB_START(op__TreeDisconnect, smb_request_t *, sr);
419c8ec8eeaSjose borrego return (SDRC_SUCCESS);
420c8ec8eeaSjose borrego }
421c8ec8eeaSjose borrego
422c8ec8eeaSjose borrego void
smb_post_tree_disconnect(smb_request_t * sr)423c8ec8eeaSjose borrego smb_post_tree_disconnect(smb_request_t *sr)
424c8ec8eeaSjose borrego {
42593bc28dbSGordon Ross DTRACE_SMB_DONE(op__TreeDisconnect, smb_request_t *, sr);
426c8ec8eeaSjose borrego }
427c8ec8eeaSjose borrego
428c8ec8eeaSjose borrego /*
429c8ec8eeaSjose borrego * SmbTreeDisconnect requires a valid UID as well as a valid TID. Some
430c8ec8eeaSjose borrego * clients logoff a user and then try to disconnect the trees connected
431c8ec8eeaSjose borrego * by the user who has just been logged off, which would normally fail
432c8ec8eeaSjose borrego * in the dispatch code with ERRbaduid but, unfortunately, ERRbaduid
433c8ec8eeaSjose borrego * causes a problem for some of those clients. Windows returns ERRinvnid.
434c8ec8eeaSjose borrego *
435c8ec8eeaSjose borrego * To prevent ERRbaduid being returned, the UID and TID are looked up here
436c8ec8eeaSjose borrego * rather than prior to dispatching SmbTreeDisconnect requests. If either
437c8ec8eeaSjose borrego * the UID or the TID is invalid, ERRinvnid is returned.
438c8ec8eeaSjose borrego */
439c8ec8eeaSjose borrego smb_sdrc_t
smb_com_tree_disconnect(smb_request_t * sr)440c8ec8eeaSjose borrego smb_com_tree_disconnect(smb_request_t *sr)
441c8ec8eeaSjose borrego {
442c8ec8eeaSjose borrego if (sr->uid_user == NULL || sr->tid_tree == NULL) {
443c8ec8eeaSjose borrego smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRinvnid);
444c8ec8eeaSjose borrego return (SDRC_ERROR);
445c8ec8eeaSjose borrego }
446c8ec8eeaSjose borrego
447b89a8333Snatalie li - Sun Microsystems - Irvine United States sr->user_cr = smb_user_getcred(sr->uid_user);
448b89a8333Snatalie li - Sun Microsystems - Irvine United States
44929bd2886SAlan Wright smb_tree_disconnect(sr->tid_tree, B_TRUE);
4500897f7fbSGordon Ross smb_session_cancel_requests(sr->session, sr->tid_tree, sr);
451c8ec8eeaSjose borrego
452c8ec8eeaSjose borrego if (smbsr_encode_empty_result(sr))
453c8ec8eeaSjose borrego return (SDRC_ERROR);
454c8ec8eeaSjose borrego
455c8ec8eeaSjose borrego return (SDRC_SUCCESS);
456c8ec8eeaSjose borrego }
457