smb_trans2_set_information.c revision 2c1b14e51525da2c09064641416fc4aed457c72f
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Common Development and Distribution License (the "License").
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * You may not use this file except in compliance with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * fields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Use is subject to license terms.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This file contains the common code used by
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Trans2SetFileInfo and Trans2SetPathInfo SMBs.
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic DWORD smb_set_standard_info(struct smb_request *sr,
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic DWORD smb_set_basic_info(struct smb_request *sr,
44cd46cadd9aab751dae6a4023c1cb5bf316d274billmstatic DWORD smb_set_disposition_info(struct smb_request *sr,
44cd46cadd9aab751dae6a4023c1cb5bf316d274billmstatic DWORD smb_set_alloc_info(struct smb_request *sr,
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*LINTED E_STATIC_UNUSED*/
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm/*LINTED E_STATIC_UNUSED*/
44cd46cadd9aab751dae6a4023c1cb5bf316d274billmstatic DWORD smb_set_mac_addappl(struct smb_request *sr,
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*LINTED E_STATIC_UNUSED*/
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic DWORD smb_set_mac_rmvappl(struct smb_request *sr,
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm/*LINTED E_STATIC_UNUSED*/
44cd46cadd9aab751dae6a4023c1cb5bf316d274billmstatic DWORD smb_set_mac_addicon(struct smb_request *sr,
44cd46cadd9aab751dae6a4023c1cb5bf316d274billmstatic unsigned short smb_info_passthru(unsigned short infolevel);
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * smb_trans2_set_information
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * This is a common function called by both Trans2SetFileInfo
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * and Trans2SetPathInfo.
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm /* EAs not supported */
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * smb_info_passthru
fa9e4066f08beec538e775443c5be79dd423fcabahrens * SMB_INFO_PASSTHROUGH
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If the server supports information level request passing through,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the client may add the information level with SMB_INFO_PASSTHROUGH
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and submit the file information in NT data format instead of SMB
fa9e4066f08beec538e775443c5be79dd423fcabahrens * data format. Please refer to MSDN for related NT file information
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * data structure.
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * SMB_INFO_PASSTHROUGH (1000) is defined in win32/cifs.h and the file
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information class values are defined in win32/ntifs.h. we have
fa9e4066f08beec538e775443c5be79dd423fcabahrens * observed:
fa9e4066f08beec538e775443c5be79dd423fcabahrens * 0x3EC = SMB_INFO_PASSTHROUGH + FileBasicInformation (4)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * 0x3F5 = SMB_INFO_PASSTHROUGH + FileDispositionInformation (13)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * 0x3FC = SMB_INFO_PASSTHROUGH + FileEndOfFileInformation (20)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Based on network traces between two Win2K systems:
fa9e4066f08beec538e775443c5be79dd423fcabahrens * FileBasicInformation <=> SMB_SET_FILE_BASIC_INFO
fa9e4066f08beec538e775443c5be79dd423fcabahrens * FileDispositionInformation <=> SMB_SET_FILE_DISPOSITION_INFO
fa9e4066f08beec538e775443c5be79dd423fcabahrens * FileEndOfFileInformation <=> SMB_SET_FILE_END_OF_FILE_INFO
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic unsigned short
fa9e4066f08beec538e775443c5be79dd423fcabahrens * smb_set_standard_info
fa9e4066f08beec538e775443c5be79dd423fcabahrens * SMB_INFO_STANDARD
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Data Block Encoding Description
fa9e4066f08beec538e775443c5be79dd423fcabahrens * ================================== =================================
fa9e4066f08beec538e775443c5be79dd423fcabahrens * SMB_DATE CreationDate; Date when file was created
fa9e4066f08beec538e775443c5be79dd423fcabahrens * SMB_TIME CreationTime; Time when file was created
fa9e4066f08beec538e775443c5be79dd423fcabahrens * SMB_DATE LastAccessDate; Date of last file access
fa9e4066f08beec538e775443c5be79dd423fcabahrens * SMB_TIME LastAccessTime; Time of last file access
fa9e4066f08beec538e775443c5be79dd423fcabahrens * SMB_DATE LastWriteDate; Date of last write to the file
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * SMB_TIME LastWriteTime; Time of last write to the file
fa9e4066f08beec538e775443c5be79dd423fcabahrens * ULONG DataSize; File Size
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * ULONG AllocationSize; Size of filesystem allocation unit
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * USHORT Attributes; File Attributes
fa9e4066f08beec538e775443c5be79dd423fcabahrens * For exact compatibility with Windows (NT and later), the whole
fa9e4066f08beec538e775443c5be79dd423fcabahrens * request is decoded (to ensure that all 22 bytes are present),
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and the DataSize, AllocationSize and Attributes values are
fa9e4066f08beec538e775443c5be79dd423fcabahrens uint32_t Creation, LastAccess, LastWrite; /* times */
fa9e4066f08beec538e775443c5be79dd423fcabahrens unsigned short Attributes;
fa9e4066f08beec538e775443c5be79dd423fcabahrens unsigned int what = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (smb_mbc_decodef(&info->ts_xa->req_data_mb, "yyyllw",
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The behaviour when the time field is set to -1
fa9e4066f08beec538e775443c5be79dd423fcabahrens * is not documented but is generally treated like 0,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * meaning that that server file system assigned value
fa9e4066f08beec538e775443c5be79dd423fcabahrens * need not be changed.
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm smb_node_set_time(node, &crtime, &mtime, &atime, 0, what);
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * smb_set_basic_info
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Sets basic file/path information.
fa9e4066f08beec538e775443c5be79dd423fcabahrens uint64_t NT_Creation, NT_LastAccess, NT_LastWrite, NT_Change;
fa9e4066f08beec538e775443c5be79dd423fcabahrens unsigned short Attributes;
fa9e4066f08beec538e775443c5be79dd423fcabahrens unsigned int what = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (smb_mbc_decodef(&info->ts_xa->req_data_mb, "qqqqw",
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The behaviour when the time field is set to -1
fa9e4066f08beec538e775443c5be79dd423fcabahrens * is not documented but is generally treated like 0,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * meaning that that server file system assigned value
fa9e4066f08beec538e775443c5be79dd423fcabahrens * need not be changed.
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (NT_Creation != 0 && NT_Creation != (uint64_t)-1) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (NT_LastWrite != 0 && NT_LastWrite != (uint64_t)-1) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (NT_LastAccess != 0 && NT_LastAccess != (uint64_t)-1) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If Attributes are 0 this means that the file's attributes
fa9e4066f08beec538e775443c5be79dd423fcabahrens * should be left unchanged. If the client wanted to 0 (clear)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * all of the attributes Attributes would be FILE_ATTRIBUTE_NORMAL.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Note - this is different from SMBsetatr (SMBSetInformation).
fa9e4066f08beec538e775443c5be79dd423fcabahrens * It is not valid to set FILE_ATTRIBUTE_DIRECTORY if the
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * target is not a directory.
fa9e4066f08beec538e775443c5be79dd423fcabahrens smb_node_set_time(node, &crtime, &mtime, &atime, &ctime, what);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * smb_set_alloc_info
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * Sets file allocation/end_of_file info
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (smb_mbc_decodef(&info->ts_xa->req_data_mb, "q", &DataSize) != 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Ensure that the FS is consistent with the node cache
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * because the size flag can get cleared by subsequent
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * write requests without the inode ever being updated.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * smb_set_disposition_info
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Set/Clear DELETE_ON_CLOSE flag for an open file.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * File should have been opened with DELETE access otherwise
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the operation is not permitted.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * NOTE: The node should be marked delete-on-close upon the receipt
fa9e4066f08beec538e775443c5be79dd423fcabahrens * of the Trans2SetFileInfo(SetDispositionInfo) if mark_delete is set.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * It is different than both SmbNtCreateAndX and SmbNtTransact, which
fa9e4066f08beec538e775443c5be79dd423fcabahrens * set delete-on-close on the ofile and defer setting the flag on the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * node until the file is closed.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Observation of Windows 2000 indicates the following:
fa9e4066f08beec538e775443c5be79dd423fcabahrens * 1) If a file is not opened with delete-on-close create options and
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * the delete-on-close is set via Trans2SetFileInfo(SetDispositionInfo)
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * using that open file handle, any subsequent open requests will fail
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * with DELETE_PENDING.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * 2) If a file is opened with delete-on-close create options and the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * client attempts to unset delete-on-close via Trans2SetFileInfo
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * (SetDispositionInfo) prior to the file close, any subsequent open
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * requests will still fail with DELETE_PENDING after the file is closed.
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * 3) If a file is opened with delete-on-close create options and that
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file handle (not the last open handle and the only file handle
fa9e4066f08beec538e775443c5be79dd423fcabahrens * with delete-on-close set) is closed. Any subsequent open requests
fa9e4066f08beec538e775443c5be79dd423fcabahrens * will fail with DELETE_PENDING. Unsetting delete-on-close via
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Trans2SetFileInfo(SetDispositionInfo) at this time will unset the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * node delete-on-close flag, which will result in the file not being
fa9e4066f08beec538e775443c5be79dd423fcabahrens * removed even after the last file handle is closed.
ecc2d604e885a75cc75e647b5641af99d5a6f4a6bonwick unsigned char mark_delete;
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (smb_mbc_decodef(&info->ts_xa->req_data_mb, "b", &mark_delete) != 0)