a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * CDDL HEADER START
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * The contents of this file are subject to the terms of the
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Common Development and Distribution License (the "License").
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * You may not use this file except in compliance with the License.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * See the License for the specific language governing permissions
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * and limitations under the License.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * When distributing Covered Code, include this CDDL HEADER in each
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * If applicable, add the following below this CDDL HEADER, with the
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * fields enclosed by brackets "[]" replaced with your own identifying
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * information: Portions Copyright [yyyy] [name of copyright owner]
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * CDDL HEADER END
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Common functions supporting both:
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * SMB1 Trans2 Set File/Path Info,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * SMB2 Set File Info
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * smb_set_basic_info
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * [MS-FSCC] 2.4.7
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * FileBasicInformation
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * SMB_SET_FILE_BASIC_INFO
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * SMB_FILE_BASIC_INFORMATION
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Sets basic file/path information.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * It is not valid to set FILE_ATTRIBUTE_DIRECTORY if the
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * target is not a directory.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * For compatibility with windows servers:
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * - if the specified attributes have ONLY FILE_ATTRIBUTE_NORMAL set
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * clear (0) the file's attributes.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * - if the specified attributes are 0 do NOT change the file's attributes.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rosssmb_set_basic_info(smb_request_t *sr, smb_setinfo_t *si)
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross &crtime, &atime, &mtime, &ctime, &attributes) != 0)
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross smb_time_nt_to_unix(atime, &attr->sa_vattr.va_atime);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross smb_time_nt_to_unix(mtime, &attr->sa_vattr.va_mtime);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross smb_time_nt_to_unix(ctime, &attr->sa_vattr.va_ctime);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross rc = smb_node_setattr(sr, node, sr->user_cr, sr->fid_ofile, attr);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * smb_set_eof_info
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * FileEndOfFileInformation
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * SMB_SET_FILE_END_OF_FILE_INFO
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * SMB_FILE_END_OF_FILE_INFORMATION
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rosssmb_set_eof_info(smb_request_t *sr, smb_setinfo_t *si)
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross if (smb_mbc_decodef(&si->si_data, "q", &eof) != 0)
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross /* If opened by path, break exclusive oplock */
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross SMB_OPLOCK_BREAK_EXCLUSIVE | SMB_OPLOCK_BREAK_TO_NONE);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross rc = smb_node_setattr(sr, node, sr->user_cr, sr->fid_ofile, attr);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * smb_set_alloc_info
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * FileAllocationInformation
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * SMB_SET_FILE_ALLOCATION_INFO
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * SMB_FILE_ALLOCATION_INFORMATION
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rosssmb_set_alloc_info(smb_request_t *sr, smb_setinfo_t *si)
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross if (smb_mbc_decodef(&si->si_data, "q", &allocsz) != 0)
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross /* If opened by path, break exclusive oplock */
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross SMB_OPLOCK_BREAK_EXCLUSIVE | SMB_OPLOCK_BREAK_TO_NONE);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross rc = smb_node_setattr(sr, node, sr->user_cr, sr->fid_ofile, attr);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * smb_set_disposition_info
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * FileDispositionInformation
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * SMB_SET_FILE_DISPOSITION_INFO
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * SMB_FILE_DISPOSITION_INFORMATION
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Set/Clear DELETE_ON_CLOSE flag for an open file.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * File should have been opened with DELETE access otherwise
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * the operation is not permitted.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * NOTE: The node should be marked delete-on-close upon the receipt
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * of the Trans2SetFileInfo(SetDispositionInfo) if mark_delete is set.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * It is different than both SmbNtCreateAndX and SmbNtTransact, which
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * set delete-on-close on the ofile and defer setting the flag on the
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * node until the file is closed.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Observation of Windows 2000 indicates the following:
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * 1) If a file is not opened with delete-on-close create options and
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * the delete-on-close is set via Trans2SetFileInfo(SetDispositionInfo)
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * using that open file handle, any subsequent open requests will fail
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * with DELETE_PENDING.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * 2) If a file is opened with delete-on-close create options and the
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * client attempts to unset delete-on-close via Trans2SetFileInfo
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * (SetDispositionInfo) prior to the file close, any subsequent open
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * requests will still fail with DELETE_PENDING after the file is closed.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * 3) If a file is opened with delete-on-close create options and that
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * file handle (not the last open handle and the only file handle
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * with delete-on-close set) is closed. Any subsequent open requests
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * will fail with DELETE_PENDING. Unsetting delete-on-close via
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Trans2SetFileInfo(SetDispositionInfo) at this time will unset the
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * node delete-on-close flag, which will result in the file not being
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * removed even after the last file handle is closed.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rosssmb_set_disposition_info(smb_request_t *sr, smb_setinfo_t *si)
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross if (smb_mbc_decodef(&si->si_data, "b", &mark_delete) != 0)
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross if ((of == NULL) || !(smb_ofile_granted_access(of) & DELETE))