/*
* 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 2013 Nexenta Systems, Inc. All rights reserved.
*/
#include <smbsrv/smb_kproto.h>
#include <smbsrv/smb_fsops.h>
static int smb_delete_check_path(smb_request_t *);
/*
* 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
{
}
/*
* smb_com_delete
*
* 1. intialize, pre-process and validate pathname
*
* 2. process the path to get directory node & last_comp,
* store these in fqi
* - If smb_pathname_reduce cannot find the specified path,
* the error (ENOTDIR) is translated to NT_STATUS_OBJECT_PATH_NOT_FOUND
* if the target is a single file (no wildcards). If there are
* wildcards in the last_comp, NT_STATUS_OBJECT_NAME_NOT_FOUND is
* used instead.
* - If the directory node is the mount point and the last component
* is ".." NT_STATUS_OBJECT_PATH_SYNTAX_BAD is returned.
*
* 3. check access permissions
*
* 4. invoke the appropriate deletion routine to find and remove
* the specified file(s).
* - if target is a single file (no wildcards) - smb_delete_single_file
* - if the target contains wildcards - smb_delete_multiple_files
*
* Returns: SDRC_SUCCESS or SDRC_ERROR
*/
{
int rc;
return (SDRC_ERROR);
if (smb_delete_check_path(sr) != 0)
return (SDRC_ERROR);
if (rc == 0) {
}
}
if (rc != 0) {
if (wildcards)
else
} else {
}
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
if (rc != 0) {
return (SDRC_ERROR);
}
if (wildcards)
else
if (rc != 0)
else
}
/*
* smb_delete_single_file
*
* Find the specified file and, if its attributes match the search
* criteria, delete it.
*
* Returns 0 - success (file deleted)
* -1 - error, err is populated with error details
*/
static int
{
/* pn already initialized and validated */
return (-1);
}
return (-1);
}
return (-1);
}
return (-1);
}
return (0);
}
/*
* smb_delete_multiple_files
*
* For each matching file found by smb_delete_find_fname:
* 1. lookup file
* 2. check the file's attributes
* - The search ends with an error if a readonly file
* (NT_STATUS_CANNOT_DELETE) is matched.
* - The search ends (but not an error) if a directory is
* matched and the request's search did not include
* directories.
* - Otherwise, if smb_delete_check_dosattr fails the file
* is skipped and the search continues (at step 1)
* 3. delete the file
*
* Returns 0 - success
* -1 - error, err is populated with error details
*/
static int
{
/*
* Specify all search attributes (SMB_SEARCH_ATTRIBUTES) so that
* delete-specific checking can be done (smb_delete_check_dosattr).
*/
SMB_SEARCH_ATTRIBUTES, 0, &od);
if (status != 0) {
return (-1);
}
for (;;) {
if (rc != 0)
break;
if (rc != 0)
break;
return (-1);
}
break;
continue;
}
++deleted;
continue;
}
continue;
}
return (-1);
}
return (-1);
}
if (deleted == 0) {
return (-1);
}
return (0);
}
/*
* smb_delete_find_fname
*
* Find next filename that matches search pattern and return it
* in namebuf.
*
* Returns: 0 - success
* errno
*/
static int
{
int rc;
if (rc == 0) {
}
return (rc);
}
/*
* smb_delete_check_dosattr
*
* Check file's dos atributes to ensure that
* 1. the file is not a directory - NT_STATUS_FILE_IS_A_DIRECTORY
* 2. the file is not readonly - NT_STATUS_CANNOT_DELETE
* 3. the file's dos attributes comply with the specified search attributes
* If the file is either hidden or system and those attributes
* are not specified in the search attributes - NT_STATUS_NO_SUCH_FILE
*
* Returns: 0 - file's attributes pass all checks
* -1 - err populated with error details
*/
static int
{
return (-1);
}
return (-1);
}
return (-1);
}
!(SMB_SEARCH_HIDDEN(sattr))) {
return (-1);
}
!(SMB_SEARCH_SYSTEM(sattr))) {
return (-1);
}
return (0);
}
/*
* smb_delete_remove_file
*
* 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.
*
* 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 lock checking gives the client a chance to
* close the file.
*
* Returns: 0 - success
* -1 - error, err populated with error details
*/
static int
{
/*
* Break BATCH oplock before ofile checks. If a client
* has a file open, this will force a flush or close,
* which may affect the outcome of any share checking.
*/
/*
* Wait (a little) for the oplock break to be
* responded to by clients closing handles.
* Hold node->n_lock as reader to keep new
* ofiles from showing up after we check.
*/
if (status != NT_STATUS_SHARING_VIOLATION)
break;
}
if (status != NT_STATUS_SUCCESS) {
return (-1);
}
/*
* Note, the combination of these two:
* smb_node_rdlock(node);
* nbl_start_crit(node->vp, RW_READER);
* is equivalent to this call:
* smb_node_start_crit(node, RW_READER)
*
* Cleanup after this point should use:
* smb_node_end_crit(node)
*/
/*
* This checks nbl_share_conflict, nbl_lock_conflict
*/
if (status == NT_STATUS_SHARING_VIOLATION) {
return (-1);
}
if (status != NT_STATUS_SUCCESS) {
return (-1);
}
if (SMB_TREE_SUPPORTS_CATIA(sr))
if (rc != 0) {
else
return (-1);
}
return (0);
}
/*
* smb_delete_check_path
*
* smb_pathname_validate() should already have been used to
* perform initial validation on the pathname. Additional
* request specific validation of the filename is performed
* here.
*
* - pn->pn_fname is NULL should result in NT_STATUS_FILE_IS_A_DIRECTORY
*
* - Any wildcard filename that resolves to '.' should result in
* NT_STATUS_OBJECT_NAME_INVALID if the search attributes include
* FILE_ATTRIBUTE_DIRECTORY
*
* Returns:
* 0: path is valid.
* -1: path is invalid. Sets error information in sr.
*/
static int
{
return (-1);
}
/* fname component is, or resolves to, '.' (dot) */
return (-1);
}
return (0);
}
/*
* smb_delete_error
*/
static void
{
}