xref: /titanic_44/usr/src/uts/common/fs/smbsrv/smb_delete.c (revision b819cea2f73f98c5662230cc9affc8cc84f77fcf)
1da6c28aaSamw /*
2da6c28aaSamw  * CDDL HEADER START
3da6c28aaSamw  *
4da6c28aaSamw  * The contents of this file are subject to the terms of the
5da6c28aaSamw  * Common Development and Distribution License (the "License").
6da6c28aaSamw  * You may not use this file except in compliance with the License.
7da6c28aaSamw  *
8da6c28aaSamw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9da6c28aaSamw  * or http://www.opensolaris.org/os/licensing.
10da6c28aaSamw  * See the License for the specific language governing permissions
11da6c28aaSamw  * and limitations under the License.
12da6c28aaSamw  *
13da6c28aaSamw  * When distributing Covered Code, include this CDDL HEADER in each
14da6c28aaSamw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15da6c28aaSamw  * If applicable, add the following below this CDDL HEADER, with the
16da6c28aaSamw  * fields enclosed by brackets "[]" replaced with your own identifying
17da6c28aaSamw  * information: Portions Copyright [yyyy] [name of copyright owner]
18da6c28aaSamw  *
19da6c28aaSamw  * CDDL HEADER END
20da6c28aaSamw  */
21148c5f43SAlan Wright 
22da6c28aaSamw /*
23148c5f43SAlan Wright  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
245fd03bc0SGordon Ross  * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
25da6c28aaSamw  */
26da6c28aaSamw 
27*b819cea2SGordon Ross #include <sys/sunddi.h>
28*b819cea2SGordon Ross #include <sys/nbmlock.h>
29*b819cea2SGordon Ross 
30bbf6f00cSJordan Brown #include <smbsrv/smb_kproto.h>
31da6c28aaSamw #include <smbsrv/smb_fsops.h>
32da6c28aaSamw #include <smbsrv/smbinfo.h>
33da6c28aaSamw 
34fe1c642dSBill Krier static int smb_delete_check_path(smb_request_t *);
35b89a8333Snatalie li - Sun Microsystems - Irvine United States static int smb_delete_single_file(smb_request_t *, smb_error_t *);
36b89a8333Snatalie li - Sun Microsystems - Irvine United States static int smb_delete_multiple_files(smb_request_t *, smb_error_t *);
37e3f2c991SKeyur Desai static int smb_delete_find_fname(smb_request_t *, smb_odir_t *, char *, int);
38037cac00Sjoyce mcintosh static int smb_delete_check_dosattr(smb_request_t *, smb_error_t *);
39b89a8333Snatalie li - Sun Microsystems - Irvine United States static int smb_delete_remove_file(smb_request_t *, smb_error_t *);
40b89a8333Snatalie li - Sun Microsystems - Irvine United States 
41b89a8333Snatalie li - Sun Microsystems - Irvine United States static void smb_delete_error(smb_error_t *, uint32_t, uint16_t, uint16_t);
42da6c28aaSamw 
43da6c28aaSamw /*
44da6c28aaSamw  * smb_com_delete
45da6c28aaSamw  *
46da6c28aaSamw  * The delete file message is sent to delete a data file. The appropriate
47da6c28aaSamw  * Tid and additional pathname are passed. Read only files may not be
48da6c28aaSamw  * deleted, the read-only attribute must be reset prior to file deletion.
49da6c28aaSamw  *
50da6c28aaSamw  * NT supports a hidden permission known as File Delete Child (FDC). If
51da6c28aaSamw  * the user has FullControl access to a directory, the user is permitted
52da6c28aaSamw  * to delete any object in the directory regardless of the permissions
53da6c28aaSamw  * on the object.
54da6c28aaSamw  *
55da6c28aaSamw  * Client Request                     Description
56da6c28aaSamw  * ================================== =================================
57da6c28aaSamw  * UCHAR WordCount;                   Count of parameter words = 1
58da6c28aaSamw  * USHORT SearchAttributes;
59da6c28aaSamw  * USHORT ByteCount;                  Count of data bytes; min = 2
60da6c28aaSamw  * UCHAR BufferFormat;                0x04
61da6c28aaSamw  * STRING FileName[];                 File name
62da6c28aaSamw  *
63da6c28aaSamw  * Multiple files may be deleted in response to a single request as
64da6c28aaSamw  * SMB_COM_DELETE supports wildcards
65da6c28aaSamw  *
66da6c28aaSamw  * SearchAttributes indicates the attributes that the target file(s) must
67da6c28aaSamw  * have. If the attribute is zero then only normal files are deleted. If
68da6c28aaSamw  * the system file or hidden attributes are specified then the delete is
69da6c28aaSamw  * inclusive -both the specified type(s) of files and normal files are
70da6c28aaSamw  * deleted. Attributes are described in the "Attribute Encoding" section
71da6c28aaSamw  * of this document.
72da6c28aaSamw  *
73da6c28aaSamw  * If bit0 of the Flags2 field of the SMB header is set, a pattern is
74da6c28aaSamw  * passed in, and the file has a long name, then the passed pattern  much
75da6c28aaSamw  * match the long file name for the delete to succeed. If bit0 is clear, a
76da6c28aaSamw  * pattern is passed in, and the file has a long name, then the passed
77da6c28aaSamw  * pattern must match the file's short name for the deletion to succeed.
78da6c28aaSamw  *
79da6c28aaSamw  * Server Response                    Description
80da6c28aaSamw  * ================================== =================================
81da6c28aaSamw  * UCHAR WordCount;                   Count of parameter words = 0
82da6c28aaSamw  * USHORT ByteCount;                  Count of data bytes = 0
83da6c28aaSamw  *
84da6c28aaSamw  * 4.2.10.1  Errors
85da6c28aaSamw  *
86da6c28aaSamw  * ERRDOS/ERRbadpath
87da6c28aaSamw  * ERRDOS/ERRbadfile
88da6c28aaSamw  * ERRDOS/ERRnoaccess
89da6c28aaSamw  * ERRDOS/ERRbadshare	# returned by NT for files that are already open
90da6c28aaSamw  * ERRHRD/ERRnowrite
91da6c28aaSamw  * ERRSRV/ERRaccess
92da6c28aaSamw  * ERRSRV/ERRinvdevice
93da6c28aaSamw  * ERRSRV/ERRinvid
94da6c28aaSamw  * ERRSRV/ERRbaduid
95da6c28aaSamw  */
967b59d02dSjb150015 smb_sdrc_t
smb_pre_delete(smb_request_t * sr)97faa1795aSjb150015 smb_pre_delete(smb_request_t *sr)
98da6c28aaSamw {
99faa1795aSjb150015 	int rc;
100b89a8333Snatalie li - Sun Microsystems - Irvine United States 	smb_fqi_t *fqi;
101b89a8333Snatalie li - Sun Microsystems - Irvine United States 
102b89a8333Snatalie li - Sun Microsystems - Irvine United States 	fqi = &sr->arg.dirop.fqi;
103faa1795aSjb150015 
104eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	if ((rc = smbsr_decode_vwv(sr, "w", &fqi->fq_sattr)) == 0)
105eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 		rc = smbsr_decode_data(sr, "%S", sr, &fqi->fq_path.pn_path);
106faa1795aSjb150015 
107b89a8333Snatalie li - Sun Microsystems - Irvine United States 	DTRACE_SMB_2(op__Delete__start, smb_request_t *, sr, smb_fqi_t *, fqi);
108faa1795aSjb150015 
109faa1795aSjb150015 	return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
110faa1795aSjb150015 }
111faa1795aSjb150015 
112faa1795aSjb150015 void
smb_post_delete(smb_request_t * sr)113faa1795aSjb150015 smb_post_delete(smb_request_t *sr)
114faa1795aSjb150015 {
115faa1795aSjb150015 	DTRACE_SMB_1(op__Delete__done, smb_request_t *, sr);
116faa1795aSjb150015 }
117faa1795aSjb150015 
118c8ec8eeaSjose borrego /*
119c8ec8eeaSjose borrego  * smb_com_delete
120c8ec8eeaSjose borrego  *
121fe1c642dSBill Krier  * 1. intialize, pre-process and validate pathname
122c8ec8eeaSjose borrego  *
123b89a8333Snatalie li - Sun Microsystems - Irvine United States  * 2. process the path to get directory node & last_comp,
124b89a8333Snatalie li - Sun Microsystems - Irvine United States  *    store these in fqi
125b89a8333Snatalie li - Sun Microsystems - Irvine United States  *    - If smb_pathname_reduce cannot find the specified path,
126b89a8333Snatalie li - Sun Microsystems - Irvine United States  *      the error (ENOTDIR) is translated to NT_STATUS_OBJECT_PATH_NOT_FOUND
127b89a8333Snatalie li - Sun Microsystems - Irvine United States  *      if the target is a single file (no wildcards).  If there are
128b89a8333Snatalie li - Sun Microsystems - Irvine United States  *      wildcards in the last_comp, NT_STATUS_OBJECT_NAME_NOT_FOUND is
129b89a8333Snatalie li - Sun Microsystems - Irvine United States  *      used instead.
130b89a8333Snatalie li - Sun Microsystems - Irvine United States  *    - If the directory node is the mount point and the last component
131b89a8333Snatalie li - Sun Microsystems - Irvine United States  *      is ".." NT_STATUS_OBJECT_PATH_SYNTAX_BAD is returned.
132c8ec8eeaSjose borrego  *
133b89a8333Snatalie li - Sun Microsystems - Irvine United States  * 3. check access permissions
134c8ec8eeaSjose borrego  *
135b89a8333Snatalie li - Sun Microsystems - Irvine United States  * 4. invoke the appropriate deletion routine to find and remove
136b89a8333Snatalie li - Sun Microsystems - Irvine United States  *    the specified file(s).
137b89a8333Snatalie li - Sun Microsystems - Irvine United States  *    - if target is a single file (no wildcards) - smb_delete_single_file
138b89a8333Snatalie li - Sun Microsystems - Irvine United States  *    - if the target contains wildcards - smb_delete_multiple_files
139c8ec8eeaSjose borrego  *
140b89a8333Snatalie li - Sun Microsystems - Irvine United States  * Returns: SDRC_SUCCESS or SDRC_ERROR
141c8ec8eeaSjose borrego  */
142faa1795aSjb150015 smb_sdrc_t
smb_com_delete(smb_request_t * sr)143faa1795aSjb150015 smb_com_delete(smb_request_t *sr)
144faa1795aSjb150015 {
145da6c28aaSamw 	int rc;
146b89a8333Snatalie li - Sun Microsystems - Irvine United States 	smb_error_t err;
147b89a8333Snatalie li - Sun Microsystems - Irvine United States 	uint32_t status;
148fe1c642dSBill Krier 	boolean_t wildcards = B_FALSE;
149b89a8333Snatalie li - Sun Microsystems - Irvine United States 	smb_fqi_t *fqi;
150fe1c642dSBill Krier 	smb_pathname_t *pn;
151da6c28aaSamw 
152b89a8333Snatalie li - Sun Microsystems - Irvine United States 	fqi = &sr->arg.dirop.fqi;
153fe1c642dSBill Krier 	pn = &fqi->fq_path;
154b89a8333Snatalie li - Sun Microsystems - Irvine United States 
155fe1c642dSBill Krier 	smb_pathname_init(sr, pn, pn->pn_path);
156fe1c642dSBill Krier 	if (!smb_pathname_validate(sr, pn))
157faa1795aSjb150015 		return (SDRC_ERROR);
158fe1c642dSBill Krier 	if (smb_delete_check_path(sr) != 0)
159fe1c642dSBill Krier 		return (SDRC_ERROR);
160fe1c642dSBill Krier 
161fe1c642dSBill Krier 	wildcards = smb_contains_wildcards(pn->pn_fname);
162da6c28aaSamw 
163eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	rc = smb_pathname_reduce(sr, sr->user_cr, fqi->fq_path.pn_path,
164b89a8333Snatalie li - Sun Microsystems - Irvine United States 	    sr->tid_tree->t_snode, sr->tid_tree->t_snode,
165eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	    &fqi->fq_dnode, fqi->fq_last_comp);
166b89a8333Snatalie li - Sun Microsystems - Irvine United States 	if (rc == 0) {
1679fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		if (!smb_node_is_dir(fqi->fq_dnode)) {
168eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 			smb_node_release(fqi->fq_dnode);
169b89a8333Snatalie li - Sun Microsystems - Irvine United States 			rc = ENOTDIR;
170c8ec8eeaSjose borrego 		}
171c8ec8eeaSjose borrego 	}
172b89a8333Snatalie li - Sun Microsystems - Irvine United States 	if (rc != 0) {
173b89a8333Snatalie li - Sun Microsystems - Irvine United States 		if (rc == ENOTDIR) {
174b89a8333Snatalie li - Sun Microsystems - Irvine United States 			if (wildcards)
175b89a8333Snatalie li - Sun Microsystems - Irvine United States 				status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
176c8ec8eeaSjose borrego 			else
177b89a8333Snatalie li - Sun Microsystems - Irvine United States 				status = NT_STATUS_OBJECT_PATH_NOT_FOUND;
178b89a8333Snatalie li - Sun Microsystems - Irvine United States 			smbsr_error(sr, status, ERRDOS, ERROR_FILE_NOT_FOUND);
179c8ec8eeaSjose borrego 		} else {
180b89a8333Snatalie li - Sun Microsystems - Irvine United States 			smbsr_errno(sr, rc);
181b89a8333Snatalie li - Sun Microsystems - Irvine United States 		}
182b89a8333Snatalie li - Sun Microsystems - Irvine United States 
183b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (SDRC_ERROR);
184b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
185b89a8333Snatalie li - Sun Microsystems - Irvine United States 
186eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	if ((fqi->fq_dnode == sr->tid_tree->t_snode) &&
187eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	    (strcmp(fqi->fq_last_comp, "..") == 0)) {
188eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 		smb_node_release(fqi->fq_dnode);
189b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smbsr_error(sr, NT_STATUS_OBJECT_PATH_SYNTAX_BAD,
190b89a8333Snatalie li - Sun Microsystems - Irvine United States 		    ERRDOS, ERROR_BAD_PATHNAME);
191b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (SDRC_ERROR);
192b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
193b89a8333Snatalie li - Sun Microsystems - Irvine United States 
194eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	rc = smb_fsop_access(sr, sr->user_cr, fqi->fq_dnode,
195b89a8333Snatalie li - Sun Microsystems - Irvine United States 	    FILE_LIST_DIRECTORY);
196b89a8333Snatalie li - Sun Microsystems - Irvine United States 	if (rc != 0) {
197eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 		smb_node_release(fqi->fq_dnode);
198b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smbsr_error(sr, NT_STATUS_ACCESS_DENIED,
199b89a8333Snatalie li - Sun Microsystems - Irvine United States 		    ERRDOS, ERROR_ACCESS_DENIED);
200b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (SDRC_ERROR);
201b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
202b89a8333Snatalie li - Sun Microsystems - Irvine United States 
203b89a8333Snatalie li - Sun Microsystems - Irvine United States 	if (wildcards)
204b89a8333Snatalie li - Sun Microsystems - Irvine United States 		rc = smb_delete_multiple_files(sr, &err);
205b89a8333Snatalie li - Sun Microsystems - Irvine United States 	else
206b89a8333Snatalie li - Sun Microsystems - Irvine United States 		rc = smb_delete_single_file(sr, &err);
207b89a8333Snatalie li - Sun Microsystems - Irvine United States 
208eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	smb_node_release(fqi->fq_dnode);
209f8a1d300Sjoyce mcintosh 
210b89a8333Snatalie li - Sun Microsystems - Irvine United States 	if (rc != 0)
211b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smbsr_set_error(sr, &err);
212b89a8333Snatalie li - Sun Microsystems - Irvine United States 	else
213b89a8333Snatalie li - Sun Microsystems - Irvine United States 		rc = smbsr_encode_empty_result(sr);
214b89a8333Snatalie li - Sun Microsystems - Irvine United States 
215b89a8333Snatalie li - Sun Microsystems - Irvine United States 	return (rc == 0 ? SDRC_SUCCESS : SDRC_ERROR);
216b89a8333Snatalie li - Sun Microsystems - Irvine United States }
217b89a8333Snatalie li - Sun Microsystems - Irvine United States 
218b89a8333Snatalie li - Sun Microsystems - Irvine United States /*
219b89a8333Snatalie li - Sun Microsystems - Irvine United States  * smb_delete_single_file
220b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
221b89a8333Snatalie li - Sun Microsystems - Irvine United States  * Find the specified file and, if its attributes match the search
222b89a8333Snatalie li - Sun Microsystems - Irvine United States  * criteria, delete it.
223b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
224b89a8333Snatalie li - Sun Microsystems - Irvine United States  * Returns 0 - success (file deleted)
225b89a8333Snatalie li - Sun Microsystems - Irvine United States  *        -1 - error, err is populated with error details
226b89a8333Snatalie li - Sun Microsystems - Irvine United States  */
227b89a8333Snatalie li - Sun Microsystems - Irvine United States static int
smb_delete_single_file(smb_request_t * sr,smb_error_t * err)228b89a8333Snatalie li - Sun Microsystems - Irvine United States smb_delete_single_file(smb_request_t *sr, smb_error_t *err)
229b89a8333Snatalie li - Sun Microsystems - Irvine United States {
230b89a8333Snatalie li - Sun Microsystems - Irvine United States 	smb_fqi_t *fqi;
231fe1c642dSBill Krier 	smb_pathname_t *pn;
232b89a8333Snatalie li - Sun Microsystems - Irvine United States 
233b89a8333Snatalie li - Sun Microsystems - Irvine United States 	fqi = &sr->arg.dirop.fqi;
234fe1c642dSBill Krier 	pn = &fqi->fq_path;
235b89a8333Snatalie li - Sun Microsystems - Irvine United States 
236fe1c642dSBill Krier 	/* pn already initialized and validated */
237fe1c642dSBill Krier 	if (!smb_validate_object_name(sr, pn)) {
238fe1c642dSBill Krier 		smb_delete_error(err, sr->smb_error.status,
239fe1c642dSBill Krier 		    ERRDOS, ERROR_INVALID_NAME);
2408d7e4166Sjose borrego 		return (-1);
2418d7e4166Sjose borrego 	}
2428d7e4166Sjose borrego 
243b89a8333Snatalie li - Sun Microsystems - Irvine United States 	if (smb_fsop_lookup_name(sr, sr->user_cr, 0, sr->tid_tree->t_snode,
244037cac00Sjoyce mcintosh 	    fqi->fq_dnode, fqi->fq_last_comp, &fqi->fq_fnode) != 0) {
245b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smb_delete_error(err, NT_STATUS_OBJECT_NAME_NOT_FOUND,
246b89a8333Snatalie li - Sun Microsystems - Irvine United States 		    ERRDOS, ERROR_FILE_NOT_FOUND);
247b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
248b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
249b89a8333Snatalie li - Sun Microsystems - Irvine United States 
250037cac00Sjoyce mcintosh 	if (smb_delete_check_dosattr(sr, err) != 0) {
251eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 		smb_node_release(fqi->fq_fnode);
252b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
253b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
254b89a8333Snatalie li - Sun Microsystems - Irvine United States 
255b89a8333Snatalie li - Sun Microsystems - Irvine United States 	if (smb_delete_remove_file(sr, err) != 0) {
256eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 		smb_node_release(fqi->fq_fnode);
257b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
258b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
259b89a8333Snatalie li - Sun Microsystems - Irvine United States 
260eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	smb_node_release(fqi->fq_fnode);
261b89a8333Snatalie li - Sun Microsystems - Irvine United States 	return (0);
262b89a8333Snatalie li - Sun Microsystems - Irvine United States }
263b89a8333Snatalie li - Sun Microsystems - Irvine United States 
264b89a8333Snatalie li - Sun Microsystems - Irvine United States /*
265b89a8333Snatalie li - Sun Microsystems - Irvine United States  * smb_delete_multiple_files
266b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
2677f667e74Sjose borrego  * For each matching file found by smb_delete_find_fname:
268b89a8333Snatalie li - Sun Microsystems - Irvine United States  * 1. lookup file
269b89a8333Snatalie li - Sun Microsystems - Irvine United States  * 2. check the file's attributes
270b89a8333Snatalie li - Sun Microsystems - Irvine United States  *    - The search ends with an error if a readonly file
271b89a8333Snatalie li - Sun Microsystems - Irvine United States  *      (NT_STATUS_CANNOT_DELETE) is matched.
272b89a8333Snatalie li - Sun Microsystems - Irvine United States  *    - The search ends (but not an error) if a directory is
273b89a8333Snatalie li - Sun Microsystems - Irvine United States  *      matched and the request's search did not include
274b89a8333Snatalie li - Sun Microsystems - Irvine United States  *      directories.
275037cac00Sjoyce mcintosh  *    - Otherwise, if smb_delete_check_dosattr fails the file
276b89a8333Snatalie li - Sun Microsystems - Irvine United States  *      is skipped and the search continues (at step 1)
277b89a8333Snatalie li - Sun Microsystems - Irvine United States  * 3. delete the file
278b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
279b89a8333Snatalie li - Sun Microsystems - Irvine United States  * Returns 0 - success
280b89a8333Snatalie li - Sun Microsystems - Irvine United States  *        -1 - error, err is populated with error details
281b89a8333Snatalie li - Sun Microsystems - Irvine United States  */
282b89a8333Snatalie li - Sun Microsystems - Irvine United States static int
smb_delete_multiple_files(smb_request_t * sr,smb_error_t * err)283b89a8333Snatalie li - Sun Microsystems - Irvine United States smb_delete_multiple_files(smb_request_t *sr, smb_error_t *err)
284b89a8333Snatalie li - Sun Microsystems - Irvine United States {
285b89a8333Snatalie li - Sun Microsystems - Irvine United States 	int rc, deleted = 0;
286b89a8333Snatalie li - Sun Microsystems - Irvine United States 	smb_fqi_t *fqi;
2877f667e74Sjose borrego 	uint16_t odid;
2887f667e74Sjose borrego 	smb_odir_t *od;
289e3f2c991SKeyur Desai 	char namebuf[MAXNAMELEN];
290b89a8333Snatalie li - Sun Microsystems - Irvine United States 
291b89a8333Snatalie li - Sun Microsystems - Irvine United States 	fqi = &sr->arg.dirop.fqi;
292b89a8333Snatalie li - Sun Microsystems - Irvine United States 
2937f667e74Sjose borrego 	/*
2947f667e74Sjose borrego 	 * Specify all search attributes (SMB_SEARCH_ATTRIBUTES) so that
295037cac00Sjoyce mcintosh 	 * delete-specific checking can be done (smb_delete_check_dosattr).
2967f667e74Sjose borrego 	 */
297eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	odid = smb_odir_open(sr, fqi->fq_path.pn_path,
298eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	    SMB_SEARCH_ATTRIBUTES, 0);
299eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	if (odid == 0)
3007f667e74Sjose borrego 		return (-1);
301eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 
3023b13a1efSThomas Keiser 	if ((od = smb_tree_lookup_odir(sr, odid)) == NULL)
3037f667e74Sjose borrego 		return (-1);
3047f667e74Sjose borrego 
305b89a8333Snatalie li - Sun Microsystems - Irvine United States 	for (;;) {
306e3f2c991SKeyur Desai 		rc = smb_delete_find_fname(sr, od, namebuf, MAXNAMELEN);
307b89a8333Snatalie li - Sun Microsystems - Irvine United States 		if (rc != 0)
308b89a8333Snatalie li - Sun Microsystems - Irvine United States 			break;
309b89a8333Snatalie li - Sun Microsystems - Irvine United States 
310148c5f43SAlan Wright 		rc = smb_fsop_lookup_name(sr, sr->user_cr, SMB_CASE_SENSITIVE,
311eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 		    sr->tid_tree->t_snode, fqi->fq_dnode,
312e3f2c991SKeyur Desai 		    namebuf, &fqi->fq_fnode);
313b89a8333Snatalie li - Sun Microsystems - Irvine United States 		if (rc != 0)
314b89a8333Snatalie li - Sun Microsystems - Irvine United States 			break;
315b89a8333Snatalie li - Sun Microsystems - Irvine United States 
316037cac00Sjoyce mcintosh 		if (smb_delete_check_dosattr(sr, err) != 0) {
317eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 			smb_node_release(fqi->fq_fnode);
318b89a8333Snatalie li - Sun Microsystems - Irvine United States 			if (err->status == NT_STATUS_CANNOT_DELETE) {
3197f667e74Sjose borrego 				smb_odir_close(od);
320a1511e6bSjoyce mcintosh 				smb_odir_release(od);
321b89a8333Snatalie li - Sun Microsystems - Irvine United States 				return (-1);
322b89a8333Snatalie li - Sun Microsystems - Irvine United States 			}
323b89a8333Snatalie li - Sun Microsystems - Irvine United States 			if ((err->status == NT_STATUS_FILE_IS_A_DIRECTORY) &&
324eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 			    (SMB_SEARCH_DIRECTORY(fqi->fq_sattr) != 0))
325b89a8333Snatalie li - Sun Microsystems - Irvine United States 				break;
326c8ec8eeaSjose borrego 			continue;
327c8ec8eeaSjose borrego 		}
328b89a8333Snatalie li - Sun Microsystems - Irvine United States 
329b89a8333Snatalie li - Sun Microsystems - Irvine United States 		if (smb_delete_remove_file(sr, err) == 0) {
330b89a8333Snatalie li - Sun Microsystems - Irvine United States 			++deleted;
331eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 			smb_node_release(fqi->fq_fnode);
332b89a8333Snatalie li - Sun Microsystems - Irvine United States 			continue;
333b89a8333Snatalie li - Sun Microsystems - Irvine United States 		}
334b89a8333Snatalie li - Sun Microsystems - Irvine United States 		if (err->status == NT_STATUS_OBJECT_NAME_NOT_FOUND) {
335eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 			smb_node_release(fqi->fq_fnode);
336b89a8333Snatalie li - Sun Microsystems - Irvine United States 			continue;
337b89a8333Snatalie li - Sun Microsystems - Irvine United States 		}
338b89a8333Snatalie li - Sun Microsystems - Irvine United States 
3397f667e74Sjose borrego 		smb_odir_close(od);
340a1511e6bSjoyce mcintosh 		smb_odir_release(od);
341eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 		smb_node_release(fqi->fq_fnode);
342b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
343b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
344b89a8333Snatalie li - Sun Microsystems - Irvine United States 
3457f667e74Sjose borrego 	smb_odir_close(od);
346a1511e6bSjoyce mcintosh 	smb_odir_release(od);
347b89a8333Snatalie li - Sun Microsystems - Irvine United States 
348b89a8333Snatalie li - Sun Microsystems - Irvine United States 	if ((rc != 0) && (rc != ENOENT)) {
349b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smbsr_map_errno(rc, err);
350b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
351b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
352b89a8333Snatalie li - Sun Microsystems - Irvine United States 
353b89a8333Snatalie li - Sun Microsystems - Irvine United States 	if (deleted == 0) {
354b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smb_delete_error(err, NT_STATUS_NO_SUCH_FILE,
355b89a8333Snatalie li - Sun Microsystems - Irvine United States 		    ERRDOS, ERROR_FILE_NOT_FOUND);
356b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
357b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
358b89a8333Snatalie li - Sun Microsystems - Irvine United States 
359b89a8333Snatalie li - Sun Microsystems - Irvine United States 	return (0);
360b89a8333Snatalie li - Sun Microsystems - Irvine United States }
361b89a8333Snatalie li - Sun Microsystems - Irvine United States 
362b89a8333Snatalie li - Sun Microsystems - Irvine United States /*
363b89a8333Snatalie li - Sun Microsystems - Irvine United States  * smb_delete_find_fname
364b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
365e3f2c991SKeyur Desai  * Find next filename that matches search pattern and return it
366e3f2c991SKeyur Desai  * in namebuf.
367b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
368b89a8333Snatalie li - Sun Microsystems - Irvine United States  * Returns: 0 - success
369b89a8333Snatalie li - Sun Microsystems - Irvine United States  *          errno
370b89a8333Snatalie li - Sun Microsystems - Irvine United States  */
371b89a8333Snatalie li - Sun Microsystems - Irvine United States static int
smb_delete_find_fname(smb_request_t * sr,smb_odir_t * od,char * namebuf,int len)372e3f2c991SKeyur Desai smb_delete_find_fname(smb_request_t *sr, smb_odir_t *od, char *namebuf, int len)
373b89a8333Snatalie li - Sun Microsystems - Irvine United States {
3747f667e74Sjose borrego 	int		rc;
3757f667e74Sjose borrego 	smb_odirent_t	*odirent;
3767f667e74Sjose borrego 	boolean_t	eos;
377b89a8333Snatalie li - Sun Microsystems - Irvine United States 
3787f667e74Sjose borrego 	odirent = kmem_alloc(sizeof (smb_odirent_t), KM_SLEEP);
379b89a8333Snatalie li - Sun Microsystems - Irvine United States 
3807f667e74Sjose borrego 	rc = smb_odir_read(sr, od, odirent, &eos);
381148c5f43SAlan Wright 	if (rc == 0) {
382148c5f43SAlan Wright 		if (eos)
383148c5f43SAlan Wright 			rc = ENOENT;
384148c5f43SAlan Wright 		else
385148c5f43SAlan Wright 			(void) strlcpy(namebuf, odirent->od_name, len);
386148c5f43SAlan Wright 	}
3877f667e74Sjose borrego 	kmem_free(odirent, sizeof (smb_odirent_t));
388b89a8333Snatalie li - Sun Microsystems - Irvine United States 	return (rc);
389b89a8333Snatalie li - Sun Microsystems - Irvine United States }
390dc20a302Sas200622 
391dc20a302Sas200622 /*
392037cac00Sjoyce mcintosh  * smb_delete_check_dosattr
393b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
394b89a8333Snatalie li - Sun Microsystems - Irvine United States  * Check file's dos atributes to ensure that
395b89a8333Snatalie li - Sun Microsystems - Irvine United States  * 1. the file is not a directory - NT_STATUS_FILE_IS_A_DIRECTORY
396b89a8333Snatalie li - Sun Microsystems - Irvine United States  * 2. the file is not readonly - NT_STATUS_CANNOT_DELETE
397b89a8333Snatalie li - Sun Microsystems - Irvine United States  * 3. the file's dos attributes comply with the specified search attributes
398b89a8333Snatalie li - Sun Microsystems - Irvine United States  *     If the file is either hidden or system and those attributes
399b89a8333Snatalie li - Sun Microsystems - Irvine United States  *     are not specified in the search attributes - NT_STATUS_NO_SUCH_FILE
400b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
401b89a8333Snatalie li - Sun Microsystems - Irvine United States  * Returns: 0 - file's attributes pass all checks
402b89a8333Snatalie li - Sun Microsystems - Irvine United States  *         -1 - err populated with error details
403dc20a302Sas200622  */
404b89a8333Snatalie li - Sun Microsystems - Irvine United States static int
smb_delete_check_dosattr(smb_request_t * sr,smb_error_t * err)405037cac00Sjoyce mcintosh smb_delete_check_dosattr(smb_request_t *sr, smb_error_t *err)
406b89a8333Snatalie li - Sun Microsystems - Irvine United States {
407b89a8333Snatalie li - Sun Microsystems - Irvine United States 	smb_fqi_t *fqi;
408b89a8333Snatalie li - Sun Microsystems - Irvine United States 	smb_node_t *node;
409037cac00Sjoyce mcintosh 	smb_attr_t attr;
410037cac00Sjoyce mcintosh 	uint16_t sattr;
411b89a8333Snatalie li - Sun Microsystems - Irvine United States 
412b89a8333Snatalie li - Sun Microsystems - Irvine United States 	fqi = &sr->arg.dirop.fqi;
413eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	sattr = fqi->fq_sattr;
414eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	node = fqi->fq_fnode;
415b89a8333Snatalie li - Sun Microsystems - Irvine United States 
4165fd03bc0SGordon Ross 	bzero(&attr, sizeof (attr));
4175fd03bc0SGordon Ross 	attr.sa_mask = SMB_AT_DOSATTR;
4188622ec45SGordon Ross 	if (smb_node_getattr(sr, node, zone_kcred(), NULL, &attr) != 0) {
419037cac00Sjoyce mcintosh 		smb_delete_error(err, NT_STATUS_INTERNAL_ERROR,
420037cac00Sjoyce mcintosh 		    ERRDOS, ERROR_INTERNAL_ERROR);
421037cac00Sjoyce mcintosh 		return (-1);
422037cac00Sjoyce mcintosh 	}
423037cac00Sjoyce mcintosh 
424037cac00Sjoyce mcintosh 	if (attr.sa_dosattr & FILE_ATTRIBUTE_DIRECTORY) {
425b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smb_delete_error(err, NT_STATUS_FILE_IS_A_DIRECTORY,
426b89a8333Snatalie li - Sun Microsystems - Irvine United States 		    ERRDOS, ERROR_ACCESS_DENIED);
427b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
428b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
429b89a8333Snatalie li - Sun Microsystems - Irvine United States 
430b89a8333Snatalie li - Sun Microsystems - Irvine United States 	if (SMB_PATHFILE_IS_READONLY(sr, node)) {
431b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smb_delete_error(err, NT_STATUS_CANNOT_DELETE,
432b89a8333Snatalie li - Sun Microsystems - Irvine United States 		    ERRDOS, ERROR_ACCESS_DENIED);
433b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
434b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
435b89a8333Snatalie li - Sun Microsystems - Irvine United States 
436037cac00Sjoyce mcintosh 	if ((attr.sa_dosattr & FILE_ATTRIBUTE_HIDDEN) &&
437037cac00Sjoyce mcintosh 	    !(SMB_SEARCH_HIDDEN(sattr))) {
438b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smb_delete_error(err, NT_STATUS_NO_SUCH_FILE,
439b89a8333Snatalie li - Sun Microsystems - Irvine United States 		    ERRDOS, ERROR_FILE_NOT_FOUND);
440b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
441b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
442b89a8333Snatalie li - Sun Microsystems - Irvine United States 
443037cac00Sjoyce mcintosh 	if ((attr.sa_dosattr & FILE_ATTRIBUTE_SYSTEM) &&
444037cac00Sjoyce mcintosh 	    !(SMB_SEARCH_SYSTEM(sattr))) {
445b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smb_delete_error(err, NT_STATUS_NO_SUCH_FILE,
446b89a8333Snatalie li - Sun Microsystems - Irvine United States 		    ERRDOS, ERROR_FILE_NOT_FOUND);
447b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
448b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
449b89a8333Snatalie li - Sun Microsystems - Irvine United States 
450b89a8333Snatalie li - Sun Microsystems - Irvine United States 	return (0);
451b89a8333Snatalie li - Sun Microsystems - Irvine United States }
452b89a8333Snatalie li - Sun Microsystems - Irvine United States 
453b89a8333Snatalie li - Sun Microsystems - Irvine United States /*
454b89a8333Snatalie li - Sun Microsystems - Irvine United States  * smb_delete_remove_file
455b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
456b89a8333Snatalie li - Sun Microsystems - Irvine United States  * For consistency with Windows 2000, the range check should be done
457b89a8333Snatalie li - Sun Microsystems - Irvine United States  * after checking for sharing violations.  Attempting to delete a
458b89a8333Snatalie li - Sun Microsystems - Irvine United States  * locked file will result in sharing violation, which is the same
459b89a8333Snatalie li - Sun Microsystems - Irvine United States  * thing that will happen if you try to delete a non-locked open file.
460b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
461b89a8333Snatalie li - Sun Microsystems - Irvine United States  * Note that windows 2000 rejects lock requests on open files that
462b89a8333Snatalie li - Sun Microsystems - Irvine United States  * have been opened with metadata open modes.  The error is
463b89a8333Snatalie li - Sun Microsystems - Irvine United States  * STATUS_ACCESS_DENIED.
464b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
465b89a8333Snatalie li - Sun Microsystems - Irvine United States  * NT does not always close a file immediately, which can cause the
466b89a8333Snatalie li - Sun Microsystems - Irvine United States  * share and access checking to fail (the node refcnt is greater
467b89a8333Snatalie li - Sun Microsystems - Irvine United States  * than one), and the file doesn't get deleted. Breaking the oplock
468bc7c423fSGordon Ross  * before share and lock checking gives the client a chance to
469b89a8333Snatalie li - Sun Microsystems - Irvine United States  * close the file.
470b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
471b89a8333Snatalie li - Sun Microsystems - Irvine United States  * Returns: 0 - success
472b89a8333Snatalie li - Sun Microsystems - Irvine United States  *         -1 - error, err populated with error details
473b89a8333Snatalie li - Sun Microsystems - Irvine United States  */
474b89a8333Snatalie li - Sun Microsystems - Irvine United States static int
smb_delete_remove_file(smb_request_t * sr,smb_error_t * err)475b89a8333Snatalie li - Sun Microsystems - Irvine United States smb_delete_remove_file(smb_request_t *sr, smb_error_t *err)
476b89a8333Snatalie li - Sun Microsystems - Irvine United States {
477bc7c423fSGordon Ross 	int rc, count;
478b89a8333Snatalie li - Sun Microsystems - Irvine United States 	uint32_t status;
479b89a8333Snatalie li - Sun Microsystems - Irvine United States 	smb_fqi_t *fqi;
480b89a8333Snatalie li - Sun Microsystems - Irvine United States 	smb_node_t *node;
4818b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	uint32_t flags = 0;
482b89a8333Snatalie li - Sun Microsystems - Irvine United States 
483b89a8333Snatalie li - Sun Microsystems - Irvine United States 	fqi = &sr->arg.dirop.fqi;
484eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	node = fqi->fq_fnode;
485dc20a302Sas200622 
486bc7c423fSGordon Ross 	/*
487bc7c423fSGordon Ross 	 * Break BATCH oplock before ofile checks. If a client
488bc7c423fSGordon Ross 	 * has a file open, this will force a flush or close,
489bc7c423fSGordon Ross 	 * which may affect the outcome of any share checking.
490bc7c423fSGordon Ross 	 */
491cb174861Sjoyce mcintosh 	(void) smb_oplock_break(sr, node,
492cb174861Sjoyce mcintosh 	    SMB_OPLOCK_BREAK_TO_LEVEL_II | SMB_OPLOCK_BREAK_BATCH);
493dc20a302Sas200622 
494bc7c423fSGordon Ross 	/*
495bc7c423fSGordon Ross 	 * Wait (a little) for the oplock break to be
496bc7c423fSGordon Ross 	 * responded to by clients closing handles.
497bc7c423fSGordon Ross 	 * Hold node->n_lock as reader to keep new
498bc7c423fSGordon Ross 	 * ofiles from showing up after we check.
499bc7c423fSGordon Ross 	 */
500bc7c423fSGordon Ross 	smb_node_rdlock(node);
501bc7c423fSGordon Ross 	for (count = 0; count <= 12; count++) {
502b89a8333Snatalie li - Sun Microsystems - Irvine United States 		status = smb_node_delete_check(node);
503bc7c423fSGordon Ross 		if (status != NT_STATUS_SHARING_VIOLATION)
504bc7c423fSGordon Ross 			break;
505bc7c423fSGordon Ross 		smb_node_unlock(node);
506bc7c423fSGordon Ross 		delay(MSEC_TO_TICK(100));
507bc7c423fSGordon Ross 		smb_node_rdlock(node);
508bc7c423fSGordon Ross 	}
509b89a8333Snatalie li - Sun Microsystems - Irvine United States 	if (status != NT_STATUS_SUCCESS) {
510b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smb_delete_error(err, NT_STATUS_SHARING_VIOLATION,
511b89a8333Snatalie li - Sun Microsystems - Irvine United States 		    ERRDOS, ERROR_SHARING_VIOLATION);
512bc7c423fSGordon Ross 		smb_node_unlock(node);
513b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
514dc20a302Sas200622 	}
515da6c28aaSamw 
516bc7c423fSGordon Ross 	/*
517bc7c423fSGordon Ross 	 * Note, the combination of these two:
518bc7c423fSGordon Ross 	 *	smb_node_rdlock(node);
519bc7c423fSGordon Ross 	 *	nbl_start_crit(node->vp, RW_READER);
520bc7c423fSGordon Ross 	 * is equivalent to this call:
521bc7c423fSGordon Ross 	 *	smb_node_start_crit(node, RW_READER)
522bc7c423fSGordon Ross 	 *
523bc7c423fSGordon Ross 	 * Cleanup after this point should use:
524bc7c423fSGordon Ross 	 *	smb_node_end_crit(node)
525bc7c423fSGordon Ross 	 */
526bc7c423fSGordon Ross 	nbl_start_crit(node->vp, RW_READER);
527bc7c423fSGordon Ross 
528bc7c423fSGordon Ross 	/*
529bc7c423fSGordon Ross 	 * This checks nbl_share_conflict, nbl_lock_conflict
530bc7c423fSGordon Ross 	 */
531bc7c423fSGordon Ross 	status = smb_nbl_conflict(node, 0, UINT64_MAX, NBL_REMOVE);
532bc7c423fSGordon Ross 	if (status == NT_STATUS_SHARING_VIOLATION) {
533bc7c423fSGordon Ross 		smb_node_end_crit(node);
534bc7c423fSGordon Ross 		smb_delete_error(err, NT_STATUS_SHARING_VIOLATION,
535bc7c423fSGordon Ross 		    ERRDOS, ERROR_SHARING_VIOLATION);
536bc7c423fSGordon Ross 		return (-1);
537bc7c423fSGordon Ross 	}
538b89a8333Snatalie li - Sun Microsystems - Irvine United States 	if (status != NT_STATUS_SUCCESS) {
539bc7c423fSGordon Ross 		smb_node_end_crit(node);
540b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smb_delete_error(err, NT_STATUS_ACCESS_DENIED,
541b89a8333Snatalie li - Sun Microsystems - Irvine United States 		    ERRDOS, ERROR_ACCESS_DENIED);
542b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
543b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
544b89a8333Snatalie li - Sun Microsystems - Irvine United States 
5458b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	if (SMB_TREE_SUPPORTS_CATIA(sr))
5468b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 		flags |= SMB_CATIA;
5478b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 
5481fcced4cSJordan Brown 	rc = smb_fsop_remove(sr, sr->user_cr, node->n_dnode,
5498b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	    node->od_name, flags);
550da6c28aaSamw 	if (rc != 0) {
551b89a8333Snatalie li - Sun Microsystems - Irvine United States 		if (rc == ENOENT)
552b89a8333Snatalie li - Sun Microsystems - Irvine United States 			smb_delete_error(err, NT_STATUS_OBJECT_NAME_NOT_FOUND,
553faa1795aSjb150015 			    ERRDOS, ERROR_FILE_NOT_FOUND);
554faa1795aSjb150015 		else
555b89a8333Snatalie li - Sun Microsystems - Irvine United States 			smbsr_map_errno(rc, err);
556b89a8333Snatalie li - Sun Microsystems - Irvine United States 
557b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smb_node_end_crit(node);
558b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
559da6c28aaSamw 	}
560da6c28aaSamw 
561b89a8333Snatalie li - Sun Microsystems - Irvine United States 	smb_node_end_crit(node);
562b89a8333Snatalie li - Sun Microsystems - Irvine United States 	return (0);
563da6c28aaSamw }
564da6c28aaSamw 
565b89a8333Snatalie li - Sun Microsystems - Irvine United States 
566da6c28aaSamw /*
567c8ec8eeaSjose borrego  * smb_delete_check_path
568c8ec8eeaSjose borrego  *
569fe1c642dSBill Krier  * smb_pathname_validate() should already have been used to
570fe1c642dSBill Krier  * perform initial validation on the pathname. Additional
571fe1c642dSBill Krier  * request specific validation of the filename is performed
572fe1c642dSBill Krier  * here.
573c8ec8eeaSjose borrego  *
574fe1c642dSBill Krier  * - pn->pn_fname is NULL should result in NT_STATUS_FILE_IS_A_DIRECTORY
575c8ec8eeaSjose borrego  *
576fe1c642dSBill Krier  * - Any wildcard filename that resolves to '.' should result in
577b89a8333Snatalie li - Sun Microsystems - Irvine United States  *   NT_STATUS_OBJECT_NAME_INVALID if the search attributes include
578b89a8333Snatalie li - Sun Microsystems - Irvine United States  *   FILE_ATTRIBUTE_DIRECTORY
579c8ec8eeaSjose borrego  *
580c8ec8eeaSjose borrego  * Returns:
581fe1c642dSBill Krier  *   0: path is valid.
582b89a8333Snatalie li - Sun Microsystems - Irvine United States  *  -1: path is invalid. Sets error information in sr.
583c8ec8eeaSjose borrego  */
584b89a8333Snatalie li - Sun Microsystems - Irvine United States static int
smb_delete_check_path(smb_request_t * sr)585fe1c642dSBill Krier smb_delete_check_path(smb_request_t *sr)
586c8ec8eeaSjose borrego {
587b89a8333Snatalie li - Sun Microsystems - Irvine United States 	smb_fqi_t *fqi = &sr->arg.dirop.fqi;
588eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	smb_pathname_t *pn = &fqi->fq_path;
589c8ec8eeaSjose borrego 
590fe1c642dSBill Krier 	if (pn->pn_fname == NULL) {
591fe1c642dSBill Krier 		smbsr_error(sr, NT_STATUS_FILE_IS_A_DIRECTORY,
592fe1c642dSBill Krier 		    ERRDOS, ERROR_ACCESS_DENIED);
593b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
594c8ec8eeaSjose borrego 	}
595c8ec8eeaSjose borrego 
596fe1c642dSBill Krier 	/* fname component is, or resolves to, '.' (dot) */
597fe1c642dSBill Krier 	if ((strcmp(pn->pn_fname, ".") == 0) ||
598eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	    (SMB_SEARCH_DIRECTORY(fqi->fq_sattr) &&
599c13be35aSGordon Ross 	    (smb_match(pn->pn_fname, ".", B_FALSE)))) {
600c8ec8eeaSjose borrego 		smbsr_error(sr, NT_STATUS_OBJECT_NAME_INVALID,
601c8ec8eeaSjose borrego 		    ERRDOS, ERROR_INVALID_NAME);
602b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
603c8ec8eeaSjose borrego 	}
604c8ec8eeaSjose borrego 
605b89a8333Snatalie li - Sun Microsystems - Irvine United States 	return (0);
606c8ec8eeaSjose borrego }
607c8ec8eeaSjose borrego 
608c8ec8eeaSjose borrego /*
609b89a8333Snatalie li - Sun Microsystems - Irvine United States  * smb_delete_error
610da6c28aaSamw  */
611b89a8333Snatalie li - Sun Microsystems - Irvine United States static void
smb_delete_error(smb_error_t * err,uint32_t status,uint16_t errcls,uint16_t errcode)612b89a8333Snatalie li - Sun Microsystems - Irvine United States smb_delete_error(smb_error_t *err,
613b89a8333Snatalie li - Sun Microsystems - Irvine United States     uint32_t status, uint16_t errcls, uint16_t errcode)
614faa1795aSjb150015 {
615b89a8333Snatalie li - Sun Microsystems - Irvine United States 	err->status = status;
616b89a8333Snatalie li - Sun Microsystems - Irvine United States 	err->errcls = errcls;
617b89a8333Snatalie li - Sun Microsystems - Irvine United States 	err->errcode = errcode;
618da6c28aaSamw }
619