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 /*
229fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * Copyright 2010 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 
28da6c28aaSamw /*
29da6c28aaSamw  * SMB: process_exit
30da6c28aaSamw  *
31da6c28aaSamw  * This command informs the server that a client process has terminated.
32da6c28aaSamw  * The server must close all files opened by Pid in the SMB header.  This
33da6c28aaSamw  * must automatically release all locks the process holds.
34da6c28aaSamw  *
35da6c28aaSamw  * Client Request                     Description
36da6c28aaSamw  * ================================== =================================
37da6c28aaSamw  *
38da6c28aaSamw  * UCHAR WordCount;                   Count of parameter words = 0
39da6c28aaSamw  * USHORT ByteCount;                  Count of data bytes = 0
40da6c28aaSamw  *
41da6c28aaSamw  * Server Response                    Description
42da6c28aaSamw  * ================================== =================================
43da6c28aaSamw  *
44da6c28aaSamw  * UCHAR WordCount;                   Count of parameter words = 0
45da6c28aaSamw  *  USHORT ByteCount;                 Count of data bytes = 0
46da6c28aaSamw  *
47da6c28aaSamw  * This SMB should not generate any errors from the server, unless the
48da6c28aaSamw  * server is a user mode server and Uid in the SMB header is invalid.
49da6c28aaSamw  *
50da6c28aaSamw  * Clients are not required to send this SMB, they can do all cleanup
51da6c28aaSamw  * necessary by sending close SMBs to the server to release resources.  In
52da6c28aaSamw  * fact, clients who have negotiated LANMAN 1.0 and later probably do not
53da6c28aaSamw  * send this message at all.
54da6c28aaSamw  */
55da6c28aaSamw 
56bbf6f00cSJordan Brown #include <smbsrv/smb_kproto.h>
57da6c28aaSamw 
587b59d02dSjb smb_sdrc_t
smb_pre_process_exit(smb_request_t * sr)59faa1795aSjb smb_pre_process_exit(smb_request_t *sr)
60faa1795aSjb {
61*93bc28dbSGordon Ross 	DTRACE_SMB_START(op__ProcessExit, smb_request_t *, sr);
62faa1795aSjb 	return (SDRC_SUCCESS);
63faa1795aSjb }
64faa1795aSjb 
65faa1795aSjb void
smb_post_process_exit(smb_request_t * sr)66faa1795aSjb smb_post_process_exit(smb_request_t *sr)
67faa1795aSjb {
68*93bc28dbSGordon Ross 	DTRACE_SMB_DONE(op__ProcessExit, smb_request_t *, sr);
69faa1795aSjb }
70faa1795aSjb 
71faa1795aSjb smb_sdrc_t
smb_com_process_exit(smb_request_t * sr)72faa1795aSjb smb_com_process_exit(smb_request_t *sr)
73da6c28aaSamw {
747b59d02dSjb 	int rc;
757b59d02dSjb 
769fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	sr->uid_user = smb_session_lookup_uid(sr->session, sr->smb_uid);
77da6c28aaSamw 	if (sr->uid_user == NULL) {
787b59d02dSjb 		rc = smbsr_encode_empty_result(sr);
79faa1795aSjb 		return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
80da6c28aaSamw 	}
81da6c28aaSamw 
82b89a8333Snatalie li - Sun Microsystems - Irvine United States 	sr->user_cr = smb_user_getcred(sr->uid_user);
83b89a8333Snatalie li - Sun Microsystems - Irvine United States 
84da6c28aaSamw 	/*
85da6c28aaSamw 	 * If request has a valid tree ID, only look for the PID within
86da6c28aaSamw 	 * that tree.  Otherwise look in all the trees.  smbtorture seems
87da6c28aaSamw 	 * to be the only thing that sends this request these days and
88da6c28aaSamw 	 * it doesn't provide a TID.
89da6c28aaSamw 	 */
903b13a1efSThomas Keiser 	sr->tid_tree = smb_session_lookup_tree(sr->session, sr->smb_tid);
91c8ec8eeaSjose borrego 	if (sr->tid_tree != NULL)
92c8ec8eeaSjose borrego 		smb_tree_close_pid(sr->tid_tree, sr->smb_pid);
93c8ec8eeaSjose borrego 	else
943b13a1efSThomas Keiser 		smb_session_close_pid(sr->session, sr->smb_pid);
95da6c28aaSamw 
967b59d02dSjb 	rc = smbsr_encode_empty_result(sr);
97faa1795aSjb 	return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
98da6c28aaSamw }
99