15331Samw /* 25331Samw * CDDL HEADER START 35331Samw * 45331Samw * The contents of this file are subject to the terms of the 55331Samw * Common Development and Distribution License (the "License"). 65331Samw * You may not use this file except in compliance with the License. 75331Samw * 85331Samw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 95331Samw * or http://www.opensolaris.org/os/licensing. 105331Samw * See the License for the specific language governing permissions 115331Samw * and limitations under the License. 125331Samw * 135331Samw * When distributing Covered Code, include this CDDL HEADER in each 145331Samw * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 155331Samw * If applicable, add the following below this CDDL HEADER, with the 165331Samw * fields enclosed by brackets "[]" replaced with your own identifying 175331Samw * information: Portions Copyright [yyyy] [name of copyright owner] 185331Samw * 195331Samw * CDDL HEADER END 205331Samw */ 215331Samw /* 22*5772Sas200622 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 235331Samw * Use is subject to license terms. 245331Samw */ 255331Samw 265331Samw #pragma ident "%Z%%M% %I% %E% SMI" 275331Samw 285331Samw #include <smbsrv/smb_incl.h> 295331Samw 305331Samw 315331Samw /* 325331Samw * Close a file by fid. All locks or other resources held by the 335331Samw * requesting process on the file should be released by the server. 345331Samw * The requesting process can no longer use the fid for further 355331Samw * file access requests. 365331Samw * 375331Samw * If LastWriteTime is non-zero, it should be used to set the file 385331Samw * timestamp. Otherwise, file system should set the timestamp. 395331Samw * Failure to set the timestamp, even if requested by the client, 405331Samw * should not result in an error response from the server. 415331Samw */ 425331Samw int 435331Samw smb_com_close(struct smb_request *sr) 445331Samw { 455331Samw uint32_t last_wtime; 465331Samw int rc = 0; 475331Samw 485331Samw rc = smbsr_decode_vwv(sr, "wl", &sr->smb_fid, &last_wtime); 495331Samw if (rc != 0) { 505331Samw smbsr_decode_error(sr); 515331Samw /* NOTREACHED */ 525331Samw } 535331Samw 545331Samw sr->fid_ofile = smb_ofile_lookup_by_fid(sr->tid_tree, sr->smb_fid); 555331Samw if (sr->fid_ofile == NULL) { 56*5772Sas200622 smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRbadfid); 575331Samw /* NOTREACHED */ 585331Samw } 595331Samw 605331Samw rc = smb_common_close(sr, last_wtime); 615331Samw if (rc) { 62*5772Sas200622 smbsr_errno(sr, rc); 635331Samw /* NOTREACHED */ 645331Samw } 655331Samw 665331Samw smbsr_encode_empty_result(sr); 675331Samw return (SDRC_NORMAL_REPLY); 685331Samw } 695331Samw 705331Samw /* 715331Samw * Close the file represented by fid and then disconnect the 725331Samw * associated tree. 735331Samw */ 745331Samw int 755331Samw smb_com_close_and_tree_disconnect(struct smb_request *sr) 765331Samw { 775331Samw uint32_t last_wtime; 785331Samw int rc = 0; 795331Samw 805331Samw rc = smbsr_decode_vwv(sr, "wl", &sr->smb_fid, &last_wtime); 815331Samw if (rc != 0) { 825331Samw smbsr_decode_error(sr); 835331Samw /* NOTREACHED */ 845331Samw } 855331Samw 865331Samw sr->fid_ofile = smb_ofile_lookup_by_fid(sr->tid_tree, sr->smb_fid); 875331Samw if (sr->fid_ofile == NULL) { 88*5772Sas200622 smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRbadfid); 895331Samw /* NOTREACHED */ 905331Samw } 915331Samw 925331Samw rc = smb_common_close(sr, last_wtime); 935331Samw smbsr_rq_notify(sr, sr->session, sr->tid_tree); 945331Samw smb_tree_disconnect(sr->tid_tree); 955331Samw 965331Samw if (rc) { 97*5772Sas200622 smbsr_errno(sr, rc); 985331Samw /* NOTREACHED */ 995331Samw } 1005331Samw 1015331Samw smbsr_encode_empty_result(sr); 1025331Samw return (SDRC_NORMAL_REPLY); 1035331Samw } 1045331Samw 1055331Samw /* 1065331Samw * smb_common_close 1075331Samw * 1085331Samw * Common close function called by SmbClose, SmbWriteAndClose, 1095331Samw * and SMBCloseAndTreeDisconnect. 1105331Samw */ 1115331Samw int 1125331Samw smb_common_close(struct smb_request *sr, uint32_t last_wtime) 1135331Samw { 1145331Samw return (smb_ofile_close(sr->fid_ofile, last_wtime)); 1155331Samw } 1165331Samw 1175331Samw /* 1185331Samw * smb_commit_delete_on_close() 1195331Samw * 1205331Samw * Check for the DeleteOnClose flag on the smb file and set it on the 1215331Samw * smb node if it is not already set. This will inhibit subsequent 1225331Samw * open requests. The delete-on-close credentials should be set to the 1235331Samw * user credentials of the current open file instance. 1245331Samw * 1255331Samw * When DeleteOnClose is set on an smb_node, the common open code will 1265331Samw * reject subsequent open requests for the file. Observation of Windows 1275331Samw * 2000 indicates that subsequent opens should be allowed (assuming 1285331Samw * there would be no sharing violation) until the file is closed using 1295331Samw * the fid on which the DeleteOnClose was requested. 1305331Samw * 1315331Samw * If there are multiple opens with delete-on-close create options, 1325331Samw * whichever the first file handle is closed will trigger the node to be 1335331Samw * marked as delete-on-close. The credentials of that ofile will be used 1345331Samw * as the delete-on-close credentials of the node. 1355331Samw */ 1365331Samw void 1375331Samw smb_commit_delete_on_close(struct smb_ofile *ofile) 1385331Samw { 1395331Samw struct smb_node *node = ofile->f_node; 1405331Samw 1415331Samw if (!(node->flags & NODE_FLAGS_DELETE_ON_CLOSE) && 1425331Samw (ofile->f_flags & SMB_OFLAGS_SET_DELETE_ON_CLOSE)) { 1435331Samw node->flags |= NODE_FLAGS_DELETE_ON_CLOSE; 1445331Samw crhold(node->delete_on_close_cred = ofile->f_cr); 1455331Samw } 1465331Samw } 147