smb_rename.c revision dc20a3024900c47dd2ee44b9707e6df38f7d62a5
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
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use is subject to license terms.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#pragma ident "%Z%%M% %I% %E% SMI"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_com_rename
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Rename a file. Files OldFileName must exist and NewFileName must not.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Both pathnames must be relative to the Tid specified in the request.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Open files may be renamed.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Multiple files may be renamed in response to a single request as Rename
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * File supports wildcards in the file name (last component of the path).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 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.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* NOTREACHED */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (smbsr_decode_vwv(sr, "w", &src_fqi->srch_attr) != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* NOTREACHED */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = smbsr_decode_data(sr, "%SS", sr, &src_fqi->path, &dst_fqi->path);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* NOTREACHED */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ERROR_FILE_EXISTS doesn't work for Windows98 clients.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Windows95 clients don't see this problem because the target
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is deleted before the rename request.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The following values are based on observed WFWG, Win9x,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * NT and W2K client behaviour.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* NOTREACHED */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* NOTREACHED */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* NOTREACHED */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_do_rename
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 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
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * source and destination are identical, we don't actually do a rename, we
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 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
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * are not released in this routine but in smb_com_rename().
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((rc = smbd_fs_query(sr, src_fqi, FQM_PATH_MUST_EXIST)) != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Break the oplock before access checks. If a client
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * has a file open, this will force a flush or close,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * which may affect the outcome of any share checking.
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as status = smb_range_check(sr, sr->user_cr, src_node, 0, UINT64_MAX,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (utf8_strcasecmp(src_fqi->path, dst_fqi->path) == 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Because the fqm parameter to smbd_fs_query() was 0,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * a successful return value means that dst_fqi->last_snode
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * may be NULL.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc == 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = smbd_fs_query(sr, dst_fqi, FQM_PATH_MUST_NOT_EXIST);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Because of FQM_PATH_MUST_NOT_EXIST and the successful return
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * value, only dst_fqi->dir_snode is valid (dst_fqi->last_snode
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is NULL).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use the unmangled form of the destination name if the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * source and destination names are the same and the source
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * name is mangled. (We are taking a chance here, assuming
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * that this is what the user wants.)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (strcmp(src_fqi->last_comp, dst_fqi->last_comp) == 0)) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc != 0) {