smb_rename.c revision b1352070d318187b41b088da3533692976f3f225
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <smbsrv/smb_incl.h>
#include <smbsrv/smb_fsops.h>
/*
* NT_RENAME InformationLevels:
*
* SMB_NT_RENAME_MOVE_CLUSTER_INFO Server returns invalid parameter.
* SMB_NT_RENAME_SET_LINK_INFO Create a hard link to a file.
* SMB_NT_RENAME_RENAME_FILE In-place rename of a file.
* SMB_NT_RENAME_MOVE_FILE Move (rename) a file.
*/
#define SMB_NT_RENAME_MOVE_CLUSTER_INFO 0x0102
#define SMB_NT_RENAME_SET_LINK_INFO 0x0103
#define SMB_NT_RENAME_RENAME_FILE 0x0104
#define SMB_NT_RENAME_MOVE_FILE 0x0105
static void smb_rename_set_error(smb_request_t *, int);
/*
* smb_com_rename
*
* Rename a file. Files OldFileName must exist and NewFileName must not.
* Both pathnames must be relative to the Tid specified in the request.
* Open files may be renamed.
*
* Multiple files may be renamed in response to a single request as Rename
* File supports wildcards in the file name (last component of the path).
* NOTE: we don't support rename with wildcards.
*
* SearchAttributes indicates the attributes that the target file(s) must
* have. If SearchAttributes is zero then only normal files are renamed.
* If the system file or hidden attributes are specified then the rename
* is inclusive - both the specified type(s) of files and normal files are
* renamed. The encoding of SearchAttributes is described in section 3.10
* - File Attribute Encoding.
*/
{
int rc;
}
}
void
{
}
{
int rc;
return (SDRC_ERROR);
}
if (rc != 0) {
return (SDRC_ERROR);
}
}
/*
* smb_do_rename
*
* Common code for renaming a file.
*
* If the source and destination are identical, we go through all
* the checks but we don't actually do the rename. If the source
* and destination files differ only in case, we do a case-sensitive
* rename. Otherwise, we do a full case-insensitive rename.
*
* Returns errno values.
*/
static int
{
char *dstname;
int rc;
int count;
return (rc);
goto rename_cleanup_nodes;
/*
* Break the oplock before access checks. If a client
* has a file open, this will force a flush or close,
* which may affect the outcome of any share checking.
*/
if (count) {
}
if (status != NT_STATUS_SHARING_VIOLATION)
break;
}
if (status == NT_STATUS_SHARING_VIOLATION) {
goto rename_cleanup_nodes;
}
if (status != NT_STATUS_SUCCESS) {
goto rename_cleanup_nodes;
}
goto rename_cleanup_nodes;
}
/*
* Because the fqm parameter to smbd_fs_query() was 0,
* dst_fqi->fq_fnode may be NULL.
*/
if (rc == 0) {
goto rename_cleanup_nodes;
}
if (rc == 0)
goto rename_cleanup_nodes;
}
if (rc != 0) {
goto rename_cleanup_nodes;
}
/*
* On success of FQM_PATH_MUST_NOT_EXIST only dst_fqi->fq_dnode
* is valid (dst_fqi->fq_fnode is NULL).
*/
/*
* If the source name is mangled but the source and destination
* on-disk names are identical, we'll use the on-disk name.
*/
} else {
}
if (rc == 0)
return (rc);
}
/*
* smb_com_nt_rename
*
* Rename a file. Files OldFileName must exist and NewFileName must not.
* Both pathnames must be relative to the Tid specified in the request.
* Open files may be renamed.
*
* Multiple files may be renamed in response to a single request as Rename
* File supports wildcards in the file name (last component of the path).
* NOTE: we don't support rename with wildcards.
*
* SearchAttributes indicates the attributes that the target file(s) must
* have. If SearchAttributes is zero then only normal files are renamed.
* If the system file or hidden attributes are specified then the rename
* is inclusive - both the specified type(s) of files and normal files are
* renamed. The encoding of SearchAttributes is described in section 3.10
* - File Attribute Encoding.
*
* Client Request Description
* ================================= ==================================
* UCHAR WordCount; Count of parameter words = 4
* USHORT SearchAttributes;
* USHORT InformationLevel; 0x0103 Create a hard link
* 0x0104 In-place rename
* 0x0105 Move (rename) a file
* ULONG ClusterCount Servers should ignore this value
* USHORT ByteCount; Count of data bytes; min = 4
* UCHAR Buffer[]; Buffer containing:
* UCHAR BufferFormat1 0x04
* UCHAR OldFileName[] OldFileName
* UCHAR BufferFormat1 0x04
* UCHAR OldFileName[] NewFileName
*
* Server Response Description
* ================================= ==================================
* UCHAR WordCount; Count of parameter words = 0
* UCHAR ByteCount; Count of data bytes = 0
*/
{
int rc;
if (rc == 0) {
}
}
void
{
}
{
int rc;
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
break;
case SMB_NT_RENAME_MOVE_FILE:
break;
break;
default:
break;
}
if (rc != 0) {
return (SDRC_ERROR);
}
}
/*
* smb_make_link
*
* Common code for creating a hard link (adding an additional name
* for a file.
*
* If the source and destination are identical, we go through all
* the checks but we don't create a link.
*
* Returns errno values.
*/
static int
{
int rc;
int count;
return (rc);
goto link_cleanup_nodes;
/*
* Break the oplock before access checks. If a client
* has a file open, this will force a flush or close,
* which may affect the outcome of any share checking.
*/
if (count) {
}
if (status != NT_STATUS_SHARING_VIOLATION)
break;
}
if (status == NT_STATUS_SHARING_VIOLATION) {
goto link_cleanup_nodes;
}
if (status != NT_STATUS_SUCCESS) {
goto link_cleanup_nodes;
}
rc = 0;
goto link_cleanup_nodes;
}
if (rc != 0) {
goto link_cleanup_nodes;
}
/*
* On success of FQM_PATH_MUST_NOT_EXIST only dst_fqi->fq_dnode
* is valid (dst_fqi->fq_fnode is NULL).
*/
if (rc == 0)
return (rc);
}
static int
{
return (ESRCH);
return (ESRCH);
return (0);
}
/*
* The following values are based on observed WFWG, Windows 9x, Windows NT
* and Windows 2000 behaviour.
*
* ERROR_FILE_EXISTS doesn't work for Windows 98 clients.
*
* Windows 95 clients don't see the problem because the target is deleted
* before the rename request.
*/
static void
{
static struct {
int errnum;
} rc_map[] = {
};
int i;
if (errnum == 0)
return;
return;
}
}
}