e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * CDDL HEADER START
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * The contents of this file are subject to the terms of the
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * Common Development and Distribution License (the "License").
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * You may not use this file except in compliance with the License.
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * See the License for the specific language governing permissions
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * and limitations under the License.
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * When distributing Covered Code, include this CDDL HEADER in each
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * If applicable, add the following below this CDDL HEADER, with the
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * fields enclosed by brackets "[]" replaced with your own identifying
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * information: Portions Copyright [yyyy] [name of copyright owner]
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * CDDL HEADER END
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
5496c1178a1a48006226450b13c2df195831794cAlek Pinchuk * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * Trans2 Set File/Path Information Levels:
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * SMB_INFO_STANDARD
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * SMB_INFO_SET_EAS
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * SMB_SET_FILE_BASIC_INFO
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * SMB_SET_FILE_DISPOSITION_INFO
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * SMB_SET_FILE_END_OF_FILE_INFO
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * SMB_SET_FILE_ALLOCATION_INFO
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown * Handled Passthrough levels:
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * SMB_FILE_BASIC_INFORMATION
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown * SMB_FILE_RENAME_INFORMATION
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown * SMB_FILE_LINK_INFORMATION
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * SMB_FILE_DISPOSITION_INFORMATION
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * SMB_FILE_END_OF_FILE_INFORMATION
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * SMB_FILE_ALLOCATION_INFORMATION
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * Internal levels representing non trans2 requests
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * SMB_SET_INFORMATION
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * SMB_SET_INFORMATION2
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * Setting timestamps:
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * The behaviour when the time field is set to -1 is not documented
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * but is generally treated like 0, meaning that that server file
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * system assigned value need not be changed.
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * Setting attributes - FILE_ATTRIBUTE_NORMAL:
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * SMB_SET_INFORMATION -
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * - if the specified attributes have ONLY FILE_ATTRIBUTE_NORMAL set
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * do NOT change the file's attributes.
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * SMB_SET_BASIC_INFO -
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * - if the specified attributes have ONLY FILE_ATTRIBUTE_NORMAL set
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * clear (0) the file's attributes.
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * - if the specified attributes are 0 do NOT change the file's
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * attributes.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rossstatic int smb_set_by_fid(smb_request_t *, smb_xa_t *, uint16_t);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rossstatic int smb_set_by_path(smb_request_t *, smb_xa_t *, uint16_t);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * These functions all return and NT status code.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rossstatic uint32_t smb_set_fileinfo(smb_request_t *, smb_setinfo_t *, int);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rossstatic uint32_t smb_set_information(smb_request_t *, smb_setinfo_t *);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rossstatic uint32_t smb_set_information2(smb_request_t *, smb_setinfo_t *);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rossstatic uint32_t smb_set_standard_info(smb_request_t *, smb_setinfo_t *);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rossstatic uint32_t smb_set_rename_info(smb_request_t *sr, smb_setinfo_t *);
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * smb_com_trans2_set_file_information
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desaismb_com_trans2_set_file_information(smb_request_t *sr, smb_xa_t *xa)
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * smb_com_trans2_set_path_information
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desaismb_com_trans2_set_path_information(smb_request_t *sr, smb_xa_t *xa)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States uint16_t infolev;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_fqi_t *fqi = &sr->arg.dirop.fqi;
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai smbsr_error(sr, NT_STATUS_INVALID_DEVICE_REQUEST,
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States sr, &infolev, &fqi->fq_path.pn_path) != 0)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smb_set_by_path(sr, xa, infolev) != 0)
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * smb_com_set_information (aka setattr)
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai DTRACE_SMB_1(op__SetInformation__start, smb_request_t *, sr);
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai DTRACE_SMB_1(op__SetInformation__done, smb_request_t *, sr);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States uint16_t infolev = SMB_SET_INFORMATION;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_fqi_t *fqi = &sr->arg.dirop.fqi;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smbsr_decode_data(sr, "%S", sr, &fqi->fq_path.pn_path) != 0)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smb_set_by_path(sr, NULL, infolev) != 0)
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * smb_com_set_information2 (aka setattre)
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai DTRACE_SMB_1(op__SetInformation2__start, smb_request_t *, sr);
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai DTRACE_SMB_1(op__SetInformation2__done, smb_request_t *, sr);
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai if (smbsr_decode_vwv(sr, "w", &sr->smb_fid) != 0)
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * smb_set_by_fid
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * Common code for setting file information by open file id.
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * Use the id to identify the node object and invoke smb_set_fileinfo
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * for that node.
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * Setting attributes on a named pipe by id is handled by simply
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * returning success.
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desaismb_set_by_fid(smb_request_t *sr, smb_xa_t *xa, uint16_t infolev)
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai return (-1);
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRbadfid);
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai return (-1);
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai if (!SMB_FTYPE_IS_DISK(sr->fid_ofile->f_ftype)) {
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * smb_set_by_path
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * Common code for setting file information by file name.
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * Use the file name to identify the node object and invoke
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * smb_set_fileinfo for that node.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * Path should be set in sr->arg.dirop.fqi.fq_path prior to
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * calling smb_set_by_path.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States *
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * Setting attributes on a named pipe by name is an error and
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * is handled in the calling functions so that they can return
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * the appropriate error status code (which differs by caller).
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statessmb_set_by_path(smb_request_t *sr, smb_xa_t *xa, uint16_t infolev)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_pathname_t *pn;
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai return (-1);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States pn = &sr->arg.dirop.fqi.fq_path;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_pathname_init(sr, pn, pn->pn_path);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (!smb_pathname_validate(sr, pn))
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (-1);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States rc = smb_pathname_reduce(sr, sr->user_cr, pn->pn_path,
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai sr->tid_tree->t_snode, sr->tid_tree->t_snode, &dnode, name);
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai rc = smb_fsop_lookup_name(sr, sr->user_cr, SMB_FOLLOW_LINKS,
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown smbsr_error(sr, NT_STATUS_OBJECT_NAME_NOT_FOUND,
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai return (-1);
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * smb_set_fileinfo
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown * For compatibility with windows servers, SMB_FILE_LINK_INFORMATION
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown * is handled by returning NT_STATUS_NOT_SUPPORTED.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rosssmb_set_fileinfo(smb_request_t *sr, smb_setinfo_t *sinfo, int infolev)
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai /* EAs not supported */
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * smb_set_information
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * It is not valid to set FILE_ATTRIBUTE_DIRECTORY if the
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * target is not a directory.
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * For compatibility with Windows Servers, if the specified
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * attributes have ONLY FILE_ATTRIBUTE_NORMAL set do NOT change
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * the file's attributes.
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desaismb_set_information(smb_request_t *sr, smb_setinfo_t *sinfo)
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai if (smbsr_decode_vwv(sr, "wl10.", &attributes, &mtime) != 0)
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai rc = smb_node_setattr(sr, node, sr->user_cr, NULL, &attr);
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * smb_set_information2
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desaismb_set_information2(smb_request_t *sr, smb_setinfo_t *sinfo)
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai if (smbsr_decode_vwv(sr, "yyy", &crtime, &atime, &mtime) != 0)
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai attr.sa_crtime.tv_sec = smb_time_local_to_gmt(sr, crtime);
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai rc = smb_node_setattr(sr, sinfo->si_node, sr->user_cr,
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * smb_set_standard_info
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * Sets standard file/path information.
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desaismb_set_standard_info(smb_request_t *sr, smb_setinfo_t *sinfo)
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai attr.sa_crtime.tv_sec = smb_time_local_to_gmt(sr, crtime);
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai rc = smb_node_setattr(sr, node, sr->user_cr, sr->fid_ofile, &attr);
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown * smb_set_rename_info
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * This call only allows a rename in the same directory, and the
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * directory name is not part of the new name provided.
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * Explicitly specified parameter validation rules:
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown * - If rootdir is not NULL respond with NT_STATUS_INVALID_PARAMETER.
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown * - If the filename contains a separator character respond with
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown * NT_STATUS_INVALID_PARAMETER.
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * Oplock break:
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * Some Windows servers break BATCH oplocks prior to the rename.
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * W2K3 does not. We behave as W2K3; we do not send an oplock break.
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brownsmb_set_rename_info(smb_request_t *sr, smb_setinfo_t *sinfo)
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown if ((rootdir != 0) || (namelen == 0) || (namelen >= MAXNAMELEN)) {
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Construct the full dst. path relative to the share root.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Allocated path is free'd in smb_request_free.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross /* Got here via: smb_set_by_path */
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross /* Got here via: smb_set_by_fid */
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross rc = smb_node_getshrpath(sinfo->si_node->n_dnode,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * The common rename code can slightly optimize a
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * rename in the same directory when we set the
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * dst_fqi->fq_dnode, dst_fqi->fq_last_comp
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross (void) strlcpy(dst_fqi->fq_last_comp, fname, MAXNAMELEN);