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 /*
22bbf6f00cSJordan Brown  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23da6c28aaSamw  * Use is subject to license terms.
24*93bc28dbSGordon Ross  *
25*93bc28dbSGordon Ross  * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
26da6c28aaSamw  */
27da6c28aaSamw 
28bbf6f00cSJordan Brown #include <smbsrv/smb_kproto.h>
29da6c28aaSamw 
30da6c28aaSamw 
31da6c28aaSamw /*
32da6c28aaSamw  * smb_com_logoff_andx
33da6c28aaSamw  *
34da6c28aaSamw  * This SMB is the inverse of SMB_COM_SESSION_SETUP_ANDX.
35da6c28aaSamw  *
36da6c28aaSamw  * Client Request                     Description
37da6c28aaSamw  * ================================== =================================
38da6c28aaSamw  *
39da6c28aaSamw  * UCHAR WordCount;                   Count of parameter words = 2
40da6c28aaSamw  * UCHAR AndXCommand;                 Secondary (X) command;  0xFF = none
41da6c28aaSamw  * UCHAR AndXReserved;                Reserved (must be 0)
42da6c28aaSamw  * USHORT AndXOffset;                 Offset to next command WordCount
43da6c28aaSamw  * USHORT ByteCount;                  Count of data bytes = 0
44da6c28aaSamw  *
45da6c28aaSamw  * Server Response                    Description
46da6c28aaSamw  * ================================== =================================
47da6c28aaSamw  *
48da6c28aaSamw  * UCHAR WordCount;                   Count of parameter words = 2
49da6c28aaSamw  * UCHAR AndXCommand;                 Secondary (X) command;  0xFF = none
50da6c28aaSamw  * UCHAR AndXReserved;                Reserved (must be 0)
51da6c28aaSamw  * USHORT AndXOffset;                 Offset to next command WordCount
52da6c28aaSamw  * USHORT ByteCount;                  Count of data bytes = 0
53da6c28aaSamw  *
54da6c28aaSamw  * The user represented by Uid in the SMB header is logged off.  The server
55da6c28aaSamw  * closes all files currently open by this user, and invalidates any
56da6c28aaSamw  * outstanding requests with this Uid.
57da6c28aaSamw  *
58da6c28aaSamw  * SMB_COM_SESSION_SETUP_ANDX is the only valid AndX command for this SMB.
59da6c28aaSamw  *
60da6c28aaSamw  * 4.1.3.1   Errors
61da6c28aaSamw  *
62da6c28aaSamw  * ERRSRV/invnid  - TID was invalid
63da6c28aaSamw  * ERRSRV/baduid  - UID was invalid
64da6c28aaSamw  */
657b59d02dSjb smb_sdrc_t
smb_pre_logoff_andx(smb_request_t * sr)66faa1795aSjb smb_pre_logoff_andx(smb_request_t *sr)
67faa1795aSjb {
68*93bc28dbSGordon Ross 	DTRACE_SMB_START(op__LogoffX, smb_request_t *, sr);
69faa1795aSjb 	return (SDRC_SUCCESS);
70faa1795aSjb }
71faa1795aSjb 
72faa1795aSjb void
smb_post_logoff_andx(smb_request_t * sr)73faa1795aSjb smb_post_logoff_andx(smb_request_t *sr)
74faa1795aSjb {
75*93bc28dbSGordon Ross 	DTRACE_SMB_DONE(op__LogoffX, smb_request_t *, sr);
76faa1795aSjb }
77faa1795aSjb 
78faa1795aSjb smb_sdrc_t
smb_com_logoff_andx(smb_request_t * sr)79faa1795aSjb smb_com_logoff_andx(smb_request_t *sr)
80da6c28aaSamw {
81da6c28aaSamw 	if (sr->uid_user == NULL) {
82dc20a302Sas 		smbsr_error(sr, 0, ERRSRV, ERRbaduid);
83faa1795aSjb 		return (SDRC_ERROR);
84da6c28aaSamw 	}
85da6c28aaSamw 
86da6c28aaSamw 	smb_user_logoff(sr->uid_user);
87da6c28aaSamw 
887b59d02dSjb 	if (smbsr_encode_result(sr, 2, 0, "bb.ww", 2, sr->andx_com, -1, 0))
89faa1795aSjb 		return (SDRC_ERROR);
90faa1795aSjb 	return (SDRC_SUCCESS);
91da6c28aaSamw }
92