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 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 * 25 * Copyright 2017 Nexenta Systems, Inc. All rights reserved. 26 */ 27 28 #include <smbsrv/smb_kproto.h> 29 30 /* 31 * Close a file by fid. All locks or other resources held by the 32 * requesting process on the file should be released by the server. 33 * The requesting process can no longer use the fid for further 34 * file access requests. 35 * 36 * If LastWriteTime is non-zero, it should be used to set the file 37 * timestamp. Otherwise, file system should set the timestamp. 38 * Failure to set the timestamp, even if requested by the client, 39 * should not result in an error response from the server. 40 */ 41 smb_sdrc_t 42 smb_pre_close(smb_request_t *sr) 43 { 44 int rc; 45 46 rc = smbsr_decode_vwv(sr, "wl", &sr->smb_fid, &sr->arg.timestamp); 47 48 DTRACE_SMB_START(op__Close, smb_request_t *, sr); 49 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR); 50 } 51 52 void 53 smb_post_close(smb_request_t *sr) 54 { 55 DTRACE_SMB_DONE(op__Close, smb_request_t *, sr); 56 } 57 58 smb_sdrc_t 59 smb_com_close(smb_request_t *sr) 60 { 61 int32_t mtime; 62 63 smbsr_lookup_file(sr); 64 if (sr->fid_ofile == NULL) { 65 smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRbadfid); 66 return (SDRC_ERROR); 67 } 68 69 mtime = smb_time_local_to_gmt(sr, sr->arg.timestamp); 70 smb_ofile_close(sr->fid_ofile, mtime); 71 72 if (smbsr_encode_empty_result(sr) != 0) 73 return (SDRC_ERROR); 74 75 return (SDRC_SUCCESS); 76 } 77 78 /* 79 * Close the file represented by fid and then disconnect the 80 * associated tree. 81 */ 82 smb_sdrc_t 83 smb_pre_close_and_tree_disconnect(smb_request_t *sr) 84 { 85 int rc; 86 87 rc = smbsr_decode_vwv(sr, "wl", &sr->smb_fid, &sr->arg.timestamp); 88 89 DTRACE_SMB_START(op__CloseAndTreeDisconnect, smb_request_t *, sr); 90 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR); 91 } 92 93 void 94 smb_post_close_and_tree_disconnect(smb_request_t *sr) 95 { 96 DTRACE_SMB_DONE(op__CloseAndTreeDisconnect, smb_request_t *, sr); 97 } 98 99 smb_sdrc_t 100 smb_com_close_and_tree_disconnect(smb_request_t *sr) 101 { 102 int32_t mtime; 103 104 smbsr_lookup_file(sr); 105 if (sr->fid_ofile == NULL) { 106 smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRbadfid); 107 return (SDRC_ERROR); 108 } 109 110 mtime = smb_time_local_to_gmt(sr, sr->arg.timestamp); 111 smb_ofile_close(sr->fid_ofile, mtime); 112 113 smb_tree_disconnect(sr->tid_tree, B_TRUE); 114 smb_session_cancel_requests(sr->session, sr->tid_tree, sr); 115 116 if (smbsr_encode_empty_result(sr) != 0) 117 return (SDRC_ERROR); 118 119 return (SDRC_SUCCESS); 120 } 121