smb_rename.c revision da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER START
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The contents of this file are subject to the terms of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Common Development and Distribution License (the "License").
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You may not use this file except in compliance with the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * See the License for the specific language governing permissions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and limitations under the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * When distributing Covered Code, include this CDDL HEADER in each
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If applicable, add the following below this CDDL HEADER, with the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * fields enclosed by brackets "[]" replaced with your own identifying
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * information: Portions Copyright [yyyy] [name of copyright owner]
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER END
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use is subject to license terms.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#pragma ident "%Z%%M% %I% %E% SMI"
b1352070d318187b41b088da3533692976f3f225Alan Wright * smb_com_rename
b1352070d318187b41b088da3533692976f3f225Alan Wright * Rename a file. Files OldFileName must exist and NewFileName must not.
b1352070d318187b41b088da3533692976f3f225Alan Wright * Both pathnames must be relative to the Tid specified in the request.
b1352070d318187b41b088da3533692976f3f225Alan Wright * Open files may be renamed.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * Multiple files may be renamed in response to a single request as Rename
b1352070d318187b41b088da3533692976f3f225Alan Wright * File supports wildcards in the file name (last component of the path).
b1352070d318187b41b088da3533692976f3f225Alan Wright * NOTE: we don't support rename with wildcards.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SearchAttributes indicates the attributes that the target file(s) must
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * have. If SearchAttributes is zero then only normal files are renamed.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If the system file or hidden attributes are specified then the rename
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is inclusive - both the specified type(s) of files and normal files are
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * renamed. The encoding of SearchAttributes is described in section 3.10
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * - File Attribute Encoding.
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /* NOTREACHED */
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States src_fqi = &sr->arg.dirop.fqi;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States dst_fqi = &sr->arg.dirop.dst_fqi;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if (smbsr_decode_vwv(sr, "w", &src_fqi->srch_attr) != 0) {
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States smbsr_decode_error(sr);
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States /* NOTREACHED */
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States }
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States rc = smbsr_decode_data(sr, "%SS", sr, &src_fqi->path, &dst_fqi->path);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if (rc != 0) {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb /* NOTREACHED */
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if (rc != 0) {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * ERROR_FILE_EXISTS doesn't work for Windows98 clients.
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * Windows95 clients don't see this problem because the target
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is deleted before the rename request.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * The following values are based on observed WFWG, Win9x,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * NT and W2K client behaviour.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* NOTREACHED */
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb /* NOTREACHED */
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb /* NOTREACHED */
b1352070d318187b41b088da3533692976f3f225Alan Wright if (dst_node->flags & NODE_FLAGS_NOTIFY_CHANGE) {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States smbsr_encode_empty_result(sr);
b1352070d318187b41b088da3533692976f3f225Alan Wright * smb_rename_share_check
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * An open file can be renamed if
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 1. isn't opened for data writing or deleting
b1352070d318187b41b088da3533692976f3f225Alan Wright * 2. Opened with "Deny Delete" share mode
b1352070d318187b41b088da3533692976f3f225Alan Wright * But not opened for data reading or executing
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * (opened for accessing meta data)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * smb_do_rename
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States *
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States * Backend to smb_com_rename to ensure that the rename operation is atomic.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This function should be called within a mutual exclusion region. If the
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * source and destination are identical, we don't actually do a rename, we
b1352070d318187b41b088da3533692976f3f225Alan Wright * just check that the conditions are right. If the source and destination
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * files differ only in case, we a case-sensitive rename. Otherwise, we do
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * a full case-insensitive rename.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This function should always return errno values.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Upon success, the last_snode's and dir_snode's of both src_fqi and dst_fqi
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States * are not released in this routine but in smb_com_rename().
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States */
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United Statessmb_do_rename(
b1352070d318187b41b088da3533692976f3f225Alan Wright if ((rc = smbd_fs_query(sr, src_fqi, FQM_PATH_MUST_EXIST)) != 0) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * Break the oplock before access checks. If a client
b1352070d318187b41b088da3533692976f3f225Alan Wright * has a file open, this will force a flush or close,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * which may affect the outcome of any share checking.
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States return (EACCES);
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States }
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States }
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States status = smb_lock_range_access(sr, src_node, 0, 0, FILE_WRITE_DATA);
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States }
b1352070d318187b41b088da3533692976f3f225Alan Wright if (utf8_strcasecmp(src_fqi->path, dst_fqi->path) == 0) {
b1352070d318187b41b088da3533692976f3f225Alan Wright if ((rc = smbd_fs_query(sr, dst_fqi, 0)) != 0) {
b1352070d318187b41b088da3533692976f3f225Alan Wright * Because the fqm parameter to smbd_fs_query() was 0,
b1352070d318187b41b088da3533692976f3f225Alan Wright * a successful return value means that dst_fqi->last_snode
b1352070d318187b41b088da3533692976f3f225Alan Wright * may be NULL.
b1352070d318187b41b088da3533692976f3f225Alan Wright rc = strcmp(src_fqi->last_comp_od, dst_fqi->last_comp);
b1352070d318187b41b088da3533692976f3f225Alan Wright rc = smbd_fs_query(sr, dst_fqi, FQM_PATH_MUST_NOT_EXIST);
b1352070d318187b41b088da3533692976f3f225Alan Wright * Because of FQM_PATH_MUST_NOT_EXIST and the successful return
b1352070d318187b41b088da3533692976f3f225Alan Wright * value, only dst_fqi->dir_snode is valid (dst_fqi->last_snode
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * is NULL).
b1352070d318187b41b088da3533692976f3f225Alan Wright * Use the unmangled form of the destination name if the
b1352070d318187b41b088da3533692976f3f225Alan Wright * source and destination names are the same and the source
b1352070d318187b41b088da3533692976f3f225Alan Wright * name is mangled. (We are taking a chance here, assuming
b1352070d318187b41b088da3533692976f3f225Alan Wright * that this is what the user wants.)
b1352070d318187b41b088da3533692976f3f225Alan Wright if ((smb_maybe_mangled_name(src_fqi->last_comp)) &&