smb_delete.c revision 8c10a8659ac31335ed870a1711c0182623f72fd6
/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <smbsrv/smb_incl.h>
#include <smbsrv/smb_fsops.h>
/*
* smb_com_delete
*
* The delete file message is sent to delete a data file. The appropriate
* Tid and additional pathname are passed. Read only files may not be
* deleted, the read-only attribute must be reset prior to file deletion.
*
* NT supports a hidden permission known as File Delete Child (FDC). If
* the user has FullControl access to a directory, the user is permitted
* to delete any object in the directory regardless of the permissions
* on the object.
*
* Client Request Description
* ================================== =================================
* UCHAR WordCount; Count of parameter words = 1
* USHORT SearchAttributes;
* USHORT ByteCount; Count of data bytes; min = 2
* UCHAR BufferFormat; 0x04
* STRING FileName[]; File name
*
* Multiple files may be deleted in response to a single request as
* SMB_COM_DELETE supports wildcards
*
* SearchAttributes indicates the attributes that the target file(s) must
* have. If the attribute is zero then only normal files are deleted. If
* the system file or hidden attributes are specified then the delete is
* inclusive -both the specified type(s) of files and normal files are
* deleted. Attributes are described in the "Attribute Encoding" section
* of this document.
*
* If bit0 of the Flags2 field of the SMB header is set, a pattern is
* passed in, and the file has a long name, then the passed pattern much
* match the long file name for the delete to succeed. If bit0 is clear, a
* pattern is passed in, and the file has a long name, then the passed
* pattern must match the file's short name for the deletion to succeed.
*
* Server Response Description
* ================================== =================================
* UCHAR WordCount; Count of parameter words = 0
* USHORT ByteCount; Count of data bytes = 0
*
* 4.2.10.1 Errors
*
* ERRDOS/ERRbadshare # returned by NT for files that are already open
*/
{
int rc;
}
void
{
}
{
int rc;
int od = 0;
int deleted = 0;
char *name;
char *fname;
char *sname;
char *fullname;
int is_stream;
return (SDRC_ERROR);
/*
* This while loop is meant to deal with wildcards.
* It is not expected that wildcards will exist for
* streams. For the streams case, it is expected
* that the below loop will be executed only once.
*/
goto delete_error;
}
goto delete_error;
}
/*
* NT does not always close a file immediately, which
* can cause the share and access checking to fail
* (the node refcnt is greater than one), and the file
* doesn't get deleted. Breaking the oplock before
* share and access checking gives the client a chance
* to close the file.
*/
goto delete_error;
}
if (is_stream) {
/*
* It is assumed that fname does not contain
* any wildcards .
* smb_fsop_remove() requires filename+streamname
*/
fullname, 0);
} else {
/*
* name (i.e. pc->dc_name) is the on-disk name
* unless there is a case collision, in which
* case readdir will have returned a mangled name.
*/
if (smb_maybe_mangled_name(name) == 0)
od = 1;
}
if (rc != 0) {
goto delete_error;
}
} else {
deleted++;
}
}
goto delete_error;
}
if (deleted == 0) {
else
goto delete_error;
}
return (SDRC_ERROR);
}
/*
* For consistency with Windows 2000, the range check should be done
* after checking for sharing violations. Attempting to delete a
* locked file will result in sharing violation, which is the same
* thing that will happen if you try to delete a non-locked open file.
*
* Note that windows 2000 rejects lock requests on open files that
* have been opened with metadata open modes. The error is
* STATUS_ACCESS_DENIED.
*/
static uint32_t
{
if (status == NT_STATUS_SHARING_VIOLATION) {
return (status);
}
if (status != NT_STATUS_SUCCESS) {
}
return (status);
}