xref: /titanic_51/usr/src/uts/common/fs/smbsrv/smb_delete.c (revision a90cf9f29973990687fa61de9f1f6ea22e924e40)
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 
27b819cea2SGordon Ross #include <sys/sunddi.h>
28b819cea2SGordon Ross #include <sys/nbmlock.h>
29b819cea2SGordon 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
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
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
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
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
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 {
285e3f2c991SKeyur Desai 	char namebuf[MAXNAMELEN];
286*a90cf9f2SGordon Ross 	smb_fqi_t *fqi;
287*a90cf9f2SGordon Ross 	smb_odir_t *od;
288*a90cf9f2SGordon Ross 	uint32_t status;
289*a90cf9f2SGordon Ross 	int rc, deleted = 0;
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 	 */
297*a90cf9f2SGordon Ross 	status = smb_odir_openpath(sr, fqi->fq_path.pn_path,
298*a90cf9f2SGordon Ross 	    SMB_SEARCH_ATTRIBUTES, 0, &od);
299*a90cf9f2SGordon Ross 	if (status != 0) {
300*a90cf9f2SGordon Ross 		err->status = status;
3017f667e74Sjose borrego 		return (-1);
302*a90cf9f2SGordon Ross 	}
3037f667e74Sjose borrego 
304b89a8333Snatalie li - Sun Microsystems - Irvine United States 	for (;;) {
305e3f2c991SKeyur Desai 		rc = smb_delete_find_fname(sr, od, namebuf, MAXNAMELEN);
306b89a8333Snatalie li - Sun Microsystems - Irvine United States 		if (rc != 0)
307b89a8333Snatalie li - Sun Microsystems - Irvine United States 			break;
308b89a8333Snatalie li - Sun Microsystems - Irvine United States 
309148c5f43SAlan Wright 		rc = smb_fsop_lookup_name(sr, sr->user_cr, SMB_CASE_SENSITIVE,
310eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 		    sr->tid_tree->t_snode, fqi->fq_dnode,
311e3f2c991SKeyur Desai 		    namebuf, &fqi->fq_fnode);
312b89a8333Snatalie li - Sun Microsystems - Irvine United States 		if (rc != 0)
313b89a8333Snatalie li - Sun Microsystems - Irvine United States 			break;
314b89a8333Snatalie li - Sun Microsystems - Irvine United States 
315037cac00Sjoyce mcintosh 		if (smb_delete_check_dosattr(sr, err) != 0) {
316eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 			smb_node_release(fqi->fq_fnode);
317b89a8333Snatalie li - Sun Microsystems - Irvine United States 			if (err->status == NT_STATUS_CANNOT_DELETE) {
3187f667e74Sjose borrego 				smb_odir_close(od);
319a1511e6bSjoyce mcintosh 				smb_odir_release(od);
320b89a8333Snatalie li - Sun Microsystems - Irvine United States 				return (-1);
321b89a8333Snatalie li - Sun Microsystems - Irvine United States 			}
322b89a8333Snatalie li - Sun Microsystems - Irvine United States 			if ((err->status == NT_STATUS_FILE_IS_A_DIRECTORY) &&
323eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 			    (SMB_SEARCH_DIRECTORY(fqi->fq_sattr) != 0))
324b89a8333Snatalie li - Sun Microsystems - Irvine United States 				break;
325c8ec8eeaSjose borrego 			continue;
326c8ec8eeaSjose borrego 		}
327b89a8333Snatalie li - Sun Microsystems - Irvine United States 
328b89a8333Snatalie li - Sun Microsystems - Irvine United States 		if (smb_delete_remove_file(sr, err) == 0) {
329b89a8333Snatalie li - Sun Microsystems - Irvine United States 			++deleted;
330eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 			smb_node_release(fqi->fq_fnode);
331b89a8333Snatalie li - Sun Microsystems - Irvine United States 			continue;
332b89a8333Snatalie li - Sun Microsystems - Irvine United States 		}
333b89a8333Snatalie li - Sun Microsystems - Irvine United States 		if (err->status == NT_STATUS_OBJECT_NAME_NOT_FOUND) {
334eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 			smb_node_release(fqi->fq_fnode);
335b89a8333Snatalie li - Sun Microsystems - Irvine United States 			continue;
336b89a8333Snatalie li - Sun Microsystems - Irvine United States 		}
337b89a8333Snatalie li - Sun Microsystems - Irvine United States 
3387f667e74Sjose borrego 		smb_odir_close(od);
339a1511e6bSjoyce mcintosh 		smb_odir_release(od);
340eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 		smb_node_release(fqi->fq_fnode);
341b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
342b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
343b89a8333Snatalie li - Sun Microsystems - Irvine United States 
3447f667e74Sjose borrego 	smb_odir_close(od);
345a1511e6bSjoyce mcintosh 	smb_odir_release(od);
346b89a8333Snatalie li - Sun Microsystems - Irvine United States 
347b89a8333Snatalie li - Sun Microsystems - Irvine United States 	if ((rc != 0) && (rc != ENOENT)) {
348b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smbsr_map_errno(rc, err);
349b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
350b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
351b89a8333Snatalie li - Sun Microsystems - Irvine United States 
352b89a8333Snatalie li - Sun Microsystems - Irvine United States 	if (deleted == 0) {
353b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smb_delete_error(err, NT_STATUS_NO_SUCH_FILE,
354b89a8333Snatalie li - Sun Microsystems - Irvine United States 		    ERRDOS, ERROR_FILE_NOT_FOUND);
355b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
356b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
357b89a8333Snatalie li - Sun Microsystems - Irvine United States 
358b89a8333Snatalie li - Sun Microsystems - Irvine United States 	return (0);
359b89a8333Snatalie li - Sun Microsystems - Irvine United States }
360b89a8333Snatalie li - Sun Microsystems - Irvine United States 
361b89a8333Snatalie li - Sun Microsystems - Irvine United States /*
362b89a8333Snatalie li - Sun Microsystems - Irvine United States  * smb_delete_find_fname
363b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
364e3f2c991SKeyur Desai  * Find next filename that matches search pattern and return it
365e3f2c991SKeyur Desai  * in namebuf.
366b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
367b89a8333Snatalie li - Sun Microsystems - Irvine United States  * Returns: 0 - success
368b89a8333Snatalie li - Sun Microsystems - Irvine United States  *          errno
369b89a8333Snatalie li - Sun Microsystems - Irvine United States  */
370b89a8333Snatalie li - Sun Microsystems - Irvine United States static int
371e3f2c991SKeyur Desai smb_delete_find_fname(smb_request_t *sr, smb_odir_t *od, char *namebuf, int len)
372b89a8333Snatalie li - Sun Microsystems - Irvine United States {
3737f667e74Sjose borrego 	int		rc;
3747f667e74Sjose borrego 	smb_odirent_t	*odirent;
3757f667e74Sjose borrego 	boolean_t	eos;
376b89a8333Snatalie li - Sun Microsystems - Irvine United States 
3777f667e74Sjose borrego 	odirent = kmem_alloc(sizeof (smb_odirent_t), KM_SLEEP);
378b89a8333Snatalie li - Sun Microsystems - Irvine United States 
3797f667e74Sjose borrego 	rc = smb_odir_read(sr, od, odirent, &eos);
380148c5f43SAlan Wright 	if (rc == 0) {
381148c5f43SAlan Wright 		(void) strlcpy(namebuf, odirent->od_name, len);
382148c5f43SAlan Wright 	}
3837f667e74Sjose borrego 	kmem_free(odirent, sizeof (smb_odirent_t));
384b89a8333Snatalie li - Sun Microsystems - Irvine United States 	return (rc);
385b89a8333Snatalie li - Sun Microsystems - Irvine United States }
386dc20a302Sas200622 
387dc20a302Sas200622 /*
388037cac00Sjoyce mcintosh  * smb_delete_check_dosattr
389b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
390b89a8333Snatalie li - Sun Microsystems - Irvine United States  * Check file's dos atributes to ensure that
391b89a8333Snatalie li - Sun Microsystems - Irvine United States  * 1. the file is not a directory - NT_STATUS_FILE_IS_A_DIRECTORY
392b89a8333Snatalie li - Sun Microsystems - Irvine United States  * 2. the file is not readonly - NT_STATUS_CANNOT_DELETE
393b89a8333Snatalie li - Sun Microsystems - Irvine United States  * 3. the file's dos attributes comply with the specified search attributes
394b89a8333Snatalie li - Sun Microsystems - Irvine United States  *     If the file is either hidden or system and those attributes
395b89a8333Snatalie li - Sun Microsystems - Irvine United States  *     are not specified in the search attributes - NT_STATUS_NO_SUCH_FILE
396b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
397b89a8333Snatalie li - Sun Microsystems - Irvine United States  * Returns: 0 - file's attributes pass all checks
398b89a8333Snatalie li - Sun Microsystems - Irvine United States  *         -1 - err populated with error details
399dc20a302Sas200622  */
400b89a8333Snatalie li - Sun Microsystems - Irvine United States static int
401037cac00Sjoyce mcintosh smb_delete_check_dosattr(smb_request_t *sr, smb_error_t *err)
402b89a8333Snatalie li - Sun Microsystems - Irvine United States {
403b89a8333Snatalie li - Sun Microsystems - Irvine United States 	smb_fqi_t *fqi;
404b89a8333Snatalie li - Sun Microsystems - Irvine United States 	smb_node_t *node;
405037cac00Sjoyce mcintosh 	smb_attr_t attr;
406037cac00Sjoyce mcintosh 	uint16_t sattr;
407b89a8333Snatalie li - Sun Microsystems - Irvine United States 
408b89a8333Snatalie li - Sun Microsystems - Irvine United States 	fqi = &sr->arg.dirop.fqi;
409eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	sattr = fqi->fq_sattr;
410eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	node = fqi->fq_fnode;
411b89a8333Snatalie li - Sun Microsystems - Irvine United States 
4125fd03bc0SGordon Ross 	bzero(&attr, sizeof (attr));
4135fd03bc0SGordon Ross 	attr.sa_mask = SMB_AT_DOSATTR;
4148622ec45SGordon Ross 	if (smb_node_getattr(sr, node, zone_kcred(), NULL, &attr) != 0) {
415037cac00Sjoyce mcintosh 		smb_delete_error(err, NT_STATUS_INTERNAL_ERROR,
416037cac00Sjoyce mcintosh 		    ERRDOS, ERROR_INTERNAL_ERROR);
417037cac00Sjoyce mcintosh 		return (-1);
418037cac00Sjoyce mcintosh 	}
419037cac00Sjoyce mcintosh 
420037cac00Sjoyce mcintosh 	if (attr.sa_dosattr & FILE_ATTRIBUTE_DIRECTORY) {
421b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smb_delete_error(err, NT_STATUS_FILE_IS_A_DIRECTORY,
422b89a8333Snatalie li - Sun Microsystems - Irvine United States 		    ERRDOS, ERROR_ACCESS_DENIED);
423b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
424b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
425b89a8333Snatalie li - Sun Microsystems - Irvine United States 
426b89a8333Snatalie li - Sun Microsystems - Irvine United States 	if (SMB_PATHFILE_IS_READONLY(sr, node)) {
427b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smb_delete_error(err, NT_STATUS_CANNOT_DELETE,
428b89a8333Snatalie li - Sun Microsystems - Irvine United States 		    ERRDOS, ERROR_ACCESS_DENIED);
429b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
430b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
431b89a8333Snatalie li - Sun Microsystems - Irvine United States 
432037cac00Sjoyce mcintosh 	if ((attr.sa_dosattr & FILE_ATTRIBUTE_HIDDEN) &&
433037cac00Sjoyce mcintosh 	    !(SMB_SEARCH_HIDDEN(sattr))) {
434b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smb_delete_error(err, NT_STATUS_NO_SUCH_FILE,
435b89a8333Snatalie li - Sun Microsystems - Irvine United States 		    ERRDOS, ERROR_FILE_NOT_FOUND);
436b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
437b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
438b89a8333Snatalie li - Sun Microsystems - Irvine United States 
439037cac00Sjoyce mcintosh 	if ((attr.sa_dosattr & FILE_ATTRIBUTE_SYSTEM) &&
440037cac00Sjoyce mcintosh 	    !(SMB_SEARCH_SYSTEM(sattr))) {
441b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smb_delete_error(err, NT_STATUS_NO_SUCH_FILE,
442b89a8333Snatalie li - Sun Microsystems - Irvine United States 		    ERRDOS, ERROR_FILE_NOT_FOUND);
443b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
444b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
445b89a8333Snatalie li - Sun Microsystems - Irvine United States 
446b89a8333Snatalie li - Sun Microsystems - Irvine United States 	return (0);
447b89a8333Snatalie li - Sun Microsystems - Irvine United States }
448b89a8333Snatalie li - Sun Microsystems - Irvine United States 
449b89a8333Snatalie li - Sun Microsystems - Irvine United States /*
450b89a8333Snatalie li - Sun Microsystems - Irvine United States  * smb_delete_remove_file
451b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
452b89a8333Snatalie li - Sun Microsystems - Irvine United States  * For consistency with Windows 2000, the range check should be done
453b89a8333Snatalie li - Sun Microsystems - Irvine United States  * after checking for sharing violations.  Attempting to delete a
454b89a8333Snatalie li - Sun Microsystems - Irvine United States  * locked file will result in sharing violation, which is the same
455b89a8333Snatalie li - Sun Microsystems - Irvine United States  * thing that will happen if you try to delete a non-locked open file.
456b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
457b89a8333Snatalie li - Sun Microsystems - Irvine United States  * Note that windows 2000 rejects lock requests on open files that
458b89a8333Snatalie li - Sun Microsystems - Irvine United States  * have been opened with metadata open modes.  The error is
459b89a8333Snatalie li - Sun Microsystems - Irvine United States  * STATUS_ACCESS_DENIED.
460b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
461b89a8333Snatalie li - Sun Microsystems - Irvine United States  * NT does not always close a file immediately, which can cause the
462b89a8333Snatalie li - Sun Microsystems - Irvine United States  * share and access checking to fail (the node refcnt is greater
463b89a8333Snatalie li - Sun Microsystems - Irvine United States  * than one), and the file doesn't get deleted. Breaking the oplock
464bc7c423fSGordon Ross  * before share and lock checking gives the client a chance to
465b89a8333Snatalie li - Sun Microsystems - Irvine United States  * close the file.
466b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
467b89a8333Snatalie li - Sun Microsystems - Irvine United States  * Returns: 0 - success
468b89a8333Snatalie li - Sun Microsystems - Irvine United States  *         -1 - error, err populated with error details
469b89a8333Snatalie li - Sun Microsystems - Irvine United States  */
470b89a8333Snatalie li - Sun Microsystems - Irvine United States static int
471b89a8333Snatalie li - Sun Microsystems - Irvine United States smb_delete_remove_file(smb_request_t *sr, smb_error_t *err)
472b89a8333Snatalie li - Sun Microsystems - Irvine United States {
473bc7c423fSGordon Ross 	int rc, count;
474b89a8333Snatalie li - Sun Microsystems - Irvine United States 	uint32_t status;
475b89a8333Snatalie li - Sun Microsystems - Irvine United States 	smb_fqi_t *fqi;
476b89a8333Snatalie li - Sun Microsystems - Irvine United States 	smb_node_t *node;
4778b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	uint32_t flags = 0;
478b89a8333Snatalie li - Sun Microsystems - Irvine United States 
479b89a8333Snatalie li - Sun Microsystems - Irvine United States 	fqi = &sr->arg.dirop.fqi;
480eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	node = fqi->fq_fnode;
481dc20a302Sas200622 
482bc7c423fSGordon Ross 	/*
483bc7c423fSGordon Ross 	 * Break BATCH oplock before ofile checks. If a client
484bc7c423fSGordon Ross 	 * has a file open, this will force a flush or close,
485bc7c423fSGordon Ross 	 * which may affect the outcome of any share checking.
486bc7c423fSGordon Ross 	 */
487cb174861Sjoyce mcintosh 	(void) smb_oplock_break(sr, node,
488cb174861Sjoyce mcintosh 	    SMB_OPLOCK_BREAK_TO_LEVEL_II | SMB_OPLOCK_BREAK_BATCH);
489dc20a302Sas200622 
490bc7c423fSGordon Ross 	/*
491bc7c423fSGordon Ross 	 * Wait (a little) for the oplock break to be
492bc7c423fSGordon Ross 	 * responded to by clients closing handles.
493bc7c423fSGordon Ross 	 * Hold node->n_lock as reader to keep new
494bc7c423fSGordon Ross 	 * ofiles from showing up after we check.
495bc7c423fSGordon Ross 	 */
496bc7c423fSGordon Ross 	smb_node_rdlock(node);
497bc7c423fSGordon Ross 	for (count = 0; count <= 12; count++) {
498b89a8333Snatalie li - Sun Microsystems - Irvine United States 		status = smb_node_delete_check(node);
499bc7c423fSGordon Ross 		if (status != NT_STATUS_SHARING_VIOLATION)
500bc7c423fSGordon Ross 			break;
501bc7c423fSGordon Ross 		smb_node_unlock(node);
502bc7c423fSGordon Ross 		delay(MSEC_TO_TICK(100));
503bc7c423fSGordon Ross 		smb_node_rdlock(node);
504bc7c423fSGordon Ross 	}
505b89a8333Snatalie li - Sun Microsystems - Irvine United States 	if (status != NT_STATUS_SUCCESS) {
506b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smb_delete_error(err, NT_STATUS_SHARING_VIOLATION,
507b89a8333Snatalie li - Sun Microsystems - Irvine United States 		    ERRDOS, ERROR_SHARING_VIOLATION);
508bc7c423fSGordon Ross 		smb_node_unlock(node);
509b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
510dc20a302Sas200622 	}
511da6c28aaSamw 
512bc7c423fSGordon Ross 	/*
513bc7c423fSGordon Ross 	 * Note, the combination of these two:
514bc7c423fSGordon Ross 	 *	smb_node_rdlock(node);
515bc7c423fSGordon Ross 	 *	nbl_start_crit(node->vp, RW_READER);
516bc7c423fSGordon Ross 	 * is equivalent to this call:
517bc7c423fSGordon Ross 	 *	smb_node_start_crit(node, RW_READER)
518bc7c423fSGordon Ross 	 *
519bc7c423fSGordon Ross 	 * Cleanup after this point should use:
520bc7c423fSGordon Ross 	 *	smb_node_end_crit(node)
521bc7c423fSGordon Ross 	 */
522bc7c423fSGordon Ross 	nbl_start_crit(node->vp, RW_READER);
523bc7c423fSGordon Ross 
524bc7c423fSGordon Ross 	/*
525bc7c423fSGordon Ross 	 * This checks nbl_share_conflict, nbl_lock_conflict
526bc7c423fSGordon Ross 	 */
527bc7c423fSGordon Ross 	status = smb_nbl_conflict(node, 0, UINT64_MAX, NBL_REMOVE);
528bc7c423fSGordon Ross 	if (status == NT_STATUS_SHARING_VIOLATION) {
529bc7c423fSGordon Ross 		smb_node_end_crit(node);
530bc7c423fSGordon Ross 		smb_delete_error(err, NT_STATUS_SHARING_VIOLATION,
531bc7c423fSGordon Ross 		    ERRDOS, ERROR_SHARING_VIOLATION);
532bc7c423fSGordon Ross 		return (-1);
533bc7c423fSGordon Ross 	}
534b89a8333Snatalie li - Sun Microsystems - Irvine United States 	if (status != NT_STATUS_SUCCESS) {
535bc7c423fSGordon Ross 		smb_node_end_crit(node);
536b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smb_delete_error(err, NT_STATUS_ACCESS_DENIED,
537b89a8333Snatalie li - Sun Microsystems - Irvine United States 		    ERRDOS, ERROR_ACCESS_DENIED);
538b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
539b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
540b89a8333Snatalie li - Sun Microsystems - Irvine United States 
5418b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	if (SMB_TREE_SUPPORTS_CATIA(sr))
5428b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 		flags |= SMB_CATIA;
5438b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 
5441fcced4cSJordan Brown 	rc = smb_fsop_remove(sr, sr->user_cr, node->n_dnode,
5458b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	    node->od_name, flags);
546da6c28aaSamw 	if (rc != 0) {
547b89a8333Snatalie li - Sun Microsystems - Irvine United States 		if (rc == ENOENT)
548b89a8333Snatalie li - Sun Microsystems - Irvine United States 			smb_delete_error(err, NT_STATUS_OBJECT_NAME_NOT_FOUND,
549faa1795aSjb150015 			    ERRDOS, ERROR_FILE_NOT_FOUND);
550faa1795aSjb150015 		else
551b89a8333Snatalie li - Sun Microsystems - Irvine United States 			smbsr_map_errno(rc, err);
552b89a8333Snatalie li - Sun Microsystems - Irvine United States 
553b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smb_node_end_crit(node);
554b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
555da6c28aaSamw 	}
556da6c28aaSamw 
557b89a8333Snatalie li - Sun Microsystems - Irvine United States 	smb_node_end_crit(node);
558b89a8333Snatalie li - Sun Microsystems - Irvine United States 	return (0);
559da6c28aaSamw }
560da6c28aaSamw 
561b89a8333Snatalie li - Sun Microsystems - Irvine United States 
562da6c28aaSamw /*
563c8ec8eeaSjose borrego  * smb_delete_check_path
564c8ec8eeaSjose borrego  *
565fe1c642dSBill Krier  * smb_pathname_validate() should already have been used to
566fe1c642dSBill Krier  * perform initial validation on the pathname. Additional
567fe1c642dSBill Krier  * request specific validation of the filename is performed
568fe1c642dSBill Krier  * here.
569c8ec8eeaSjose borrego  *
570fe1c642dSBill Krier  * - pn->pn_fname is NULL should result in NT_STATUS_FILE_IS_A_DIRECTORY
571c8ec8eeaSjose borrego  *
572fe1c642dSBill Krier  * - Any wildcard filename that resolves to '.' should result in
573b89a8333Snatalie li - Sun Microsystems - Irvine United States  *   NT_STATUS_OBJECT_NAME_INVALID if the search attributes include
574b89a8333Snatalie li - Sun Microsystems - Irvine United States  *   FILE_ATTRIBUTE_DIRECTORY
575c8ec8eeaSjose borrego  *
576c8ec8eeaSjose borrego  * Returns:
577fe1c642dSBill Krier  *   0: path is valid.
578b89a8333Snatalie li - Sun Microsystems - Irvine United States  *  -1: path is invalid. Sets error information in sr.
579c8ec8eeaSjose borrego  */
580b89a8333Snatalie li - Sun Microsystems - Irvine United States static int
581fe1c642dSBill Krier smb_delete_check_path(smb_request_t *sr)
582c8ec8eeaSjose borrego {
583b89a8333Snatalie li - Sun Microsystems - Irvine United States 	smb_fqi_t *fqi = &sr->arg.dirop.fqi;
584eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	smb_pathname_t *pn = &fqi->fq_path;
585c8ec8eeaSjose borrego 
586fe1c642dSBill Krier 	if (pn->pn_fname == NULL) {
587fe1c642dSBill Krier 		smbsr_error(sr, NT_STATUS_FILE_IS_A_DIRECTORY,
588fe1c642dSBill Krier 		    ERRDOS, ERROR_ACCESS_DENIED);
589b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
590c8ec8eeaSjose borrego 	}
591c8ec8eeaSjose borrego 
592fe1c642dSBill Krier 	/* fname component is, or resolves to, '.' (dot) */
593fe1c642dSBill Krier 	if ((strcmp(pn->pn_fname, ".") == 0) ||
594eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	    (SMB_SEARCH_DIRECTORY(fqi->fq_sattr) &&
595c13be35aSGordon Ross 	    (smb_match(pn->pn_fname, ".", B_FALSE)))) {
596c8ec8eeaSjose borrego 		smbsr_error(sr, NT_STATUS_OBJECT_NAME_INVALID,
597c8ec8eeaSjose borrego 		    ERRDOS, ERROR_INVALID_NAME);
598b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
599c8ec8eeaSjose borrego 	}
600c8ec8eeaSjose borrego 
601b89a8333Snatalie li - Sun Microsystems - Irvine United States 	return (0);
602c8ec8eeaSjose borrego }
603c8ec8eeaSjose borrego 
604c8ec8eeaSjose borrego /*
605b89a8333Snatalie li - Sun Microsystems - Irvine United States  * smb_delete_error
606da6c28aaSamw  */
607b89a8333Snatalie li - Sun Microsystems - Irvine United States static void
608b89a8333Snatalie li - Sun Microsystems - Irvine United States smb_delete_error(smb_error_t *err,
609b89a8333Snatalie li - Sun Microsystems - Irvine United States     uint32_t status, uint16_t errcls, uint16_t errcode)
610faa1795aSjb150015 {
611b89a8333Snatalie li - Sun Microsystems - Irvine United States 	err->status = status;
612b89a8333Snatalie li - Sun Microsystems - Irvine United States 	err->errcls = errcls;
613b89a8333Snatalie li - Sun Microsystems - Irvine United States 	err->errcode = errcode;
614da6c28aaSamw }
615