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.
24*525641e8SGordon Ross  * Copyright 2020 Tintri by DDN, 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  */
967b59d02dSjb smb_sdrc_t
smb_pre_delete(smb_request_t * sr)97faa1795aSjb smb_pre_delete(smb_request_t *sr)
98da6c28aaSamw {
99faa1795aSjb 	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;
103faa1795aSjb 
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);
106faa1795aSjb 
10793bc28dbSGordon Ross 	DTRACE_SMB_START(op__Delete, smb_request_t *, sr); /* arg.dirop */
108faa1795aSjb 
109faa1795aSjb 	return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
110faa1795aSjb }
111faa1795aSjb 
112faa1795aSjb void
smb_post_delete(smb_request_t * sr)113faa1795aSjb smb_post_delete(smb_request_t *sr)
114faa1795aSjb {
11593bc28dbSGordon Ross 	DTRACE_SMB_DONE(op__Delete, smb_request_t *, sr);
116faa1795aSjb }
117faa1795aSjb 
118c8ec8eeaSjose borrego /*
119c8ec8eeaSjose borrego  * smb_com_delete
120c8ec8eeaSjose borrego  *
121fe1c642dSBill Krier  * 1. intialize, pre-process and validate pathname
122b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
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.
132b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
133b89a8333Snatalie li - Sun Microsystems - Irvine United States  * 3. check access permissions
134b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
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
139b89a8333Snatalie li - Sun Microsystems - Irvine United States  *
140b89a8333Snatalie li - Sun Microsystems - Irvine United States  * Returns: SDRC_SUCCESS or SDRC_ERROR
141c8ec8eeaSjose borrego  */
142faa1795aSjb smb_sdrc_t
smb_com_delete(smb_request_t * sr)143faa1795aSjb smb_com_delete(smb_request_t *sr)
144faa1795aSjb {
145c8ec8eeaSjose borrego 	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))
157faa1795aSjb 		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;
170b89a8333Snatalie li - Sun Microsystems - Irvine United States 		}
171b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
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;
176b89a8333Snatalie li - Sun Microsystems - Irvine United States 			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);
179b89a8333Snatalie li - Sun Microsystems - Irvine United States 		} else {
180b89a8333Snatalie li - Sun Microsystems - Irvine United States 			smbsr_errno(sr, rc);
181c8ec8eeaSjose borrego 		}
182c8ec8eeaSjose borrego 
183c8ec8eeaSjose borrego 		return (SDRC_ERROR);
184c8ec8eeaSjose borrego 	}
185c8ec8eeaSjose borrego 
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 	}
193da6c28aaSamw 
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 	}
202dc20a302Sas 
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);
214c8ec8eeaSjose borrego 
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;
232dc20a302Sas 
233b89a8333Snatalie li - Sun Microsystems - Irvine United States 	fqi = &sr->arg.dirop.fqi;
234fe1c642dSBill Krier 	pn = &fqi->fq_path;
235dc20a302Sas 
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 	}
249dc20a302Sas 
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 	}
254da6c28aaSamw 
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 	}
259da6c28aaSamw 
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 }
263dc20a302Sas 
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 {
285a90cf9f2SGordon Ross 	char namebuf[MAXNAMELEN];
286b89a8333Snatalie li - Sun Microsystems - Irvine United States 	smb_fqi_t *fqi;
2877f667e74Sjose borrego 	smb_odir_t *od;
288a90cf9f2SGordon Ross 	uint32_t status;
289a90cf9f2SGordon 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 	 */
297a90cf9f2SGordon Ross 	status = smb_odir_openpath(sr, fqi->fq_path.pn_path,
298a90cf9f2SGordon Ross 	    SMB_SEARCH_ATTRIBUTES, 0, &od);
299a90cf9f2SGordon Ross 	if (status != 0) {
300a90cf9f2SGordon Ross 		err->status = status;
3017f667e74Sjose borrego 		return (-1);
302a90cf9f2SGordon 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);
321faa1795aSjb 			}
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;
325b89a8333Snatalie li - Sun Microsystems - Irvine United States 			continue;
326b89a8333Snatalie li - Sun Microsystems - Irvine United States 		}
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;
332da6c28aaSamw 		}
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);
342da6c28aaSamw 	}
343da6c28aaSamw 
3447f667e74Sjose borrego 	smb_odir_close(od);
345a1511e6bSjoyce mcintosh 	smb_odir_release(od);
346b89a8333Snatalie li - Sun Microsystems - Irvine United States 
347da6c28aaSamw 	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);
350da6c28aaSamw 	}
351da6c28aaSamw 
352da6c28aaSamw 	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);
356da6c28aaSamw 	}
357da6c28aaSamw 
358b89a8333Snatalie li - Sun Microsystems - Irvine United States 	return (0);
359b89a8333Snatalie li - Sun Microsystems - Irvine United States }
360da6c28aaSamw 
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
smb_delete_find_fname(smb_request_t * sr,smb_odir_t * od,char * namebuf,int len)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) {
381a90cf9f2SGordon Ross 		(void) strlcpy(namebuf, odirent->od_name, len);
382b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
3837f667e74Sjose borrego 	kmem_free(odirent, sizeof (smb_odirent_t));
384148c5f43SAlan Wright 	return (rc);
385da6c28aaSamw }
386da6c28aaSamw 
387b89a8333Snatalie li - Sun Microsystems - Irvine United States /*
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
399b89a8333Snatalie li - Sun Microsystems - Irvine United States  */
400b89a8333Snatalie li - Sun Microsystems - Irvine United States static int
smb_delete_check_dosattr(smb_request_t * sr,smb_error_t * err)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
smb_delete_remove_file(smb_request_t * sr,smb_error_t * err)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 {
47394047d49SGordon Ross 	int rc;
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;
481b89a8333Snatalie li - Sun Microsystems - Irvine United States 
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 	 */
48794047d49SGordon Ross 	status = smb_oplock_break_DELETE(node, NULL);
48894047d49SGordon Ross 	if (status == NT_STATUS_OPLOCK_BREAK_IN_PROGRESS) {
489*525641e8SGordon Ross 		(void) smb_oplock_wait_break(sr, node, 0);
49094047d49SGordon Ross 		status = 0;
49194047d49SGordon Ross 	}
49294047d49SGordon Ross 	if (status != 0) {
49394047d49SGordon Ross 		err->status = status;
49494047d49SGordon Ross 		return (-1);
49594047d49SGordon Ross 	}
496b89a8333Snatalie li - Sun Microsystems - Irvine United States 
497bc7c423fSGordon Ross 	smb_node_rdlock(node);
49894047d49SGordon Ross 	status = smb_node_delete_check(node);
499b89a8333Snatalie li - Sun Microsystems - Irvine United States 	if (status != NT_STATUS_SUCCESS) {
50094047d49SGordon Ross 		smb_node_unlock(node);
501b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smb_delete_error(err, NT_STATUS_SHARING_VIOLATION,
502b89a8333Snatalie li - Sun Microsystems - Irvine United States 		    ERRDOS, ERROR_SHARING_VIOLATION);
503b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
504b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
505b89a8333Snatalie li - Sun Microsystems - Irvine United States 
506bc7c423fSGordon Ross 	/*
507bc7c423fSGordon Ross 	 * Note, the combination of these two:
508bc7c423fSGordon Ross 	 *	smb_node_rdlock(node);
509bc7c423fSGordon Ross 	 *	nbl_start_crit(node->vp, RW_READER);
510bc7c423fSGordon Ross 	 * is equivalent to this call:
511bc7c423fSGordon Ross 	 *	smb_node_start_crit(node, RW_READER)
512bc7c423fSGordon Ross 	 *
513bc7c423fSGordon Ross 	 * Cleanup after this point should use:
514bc7c423fSGordon Ross 	 *	smb_node_end_crit(node)
515bc7c423fSGordon Ross 	 */
516bc7c423fSGordon Ross 	nbl_start_crit(node->vp, RW_READER);
517bc7c423fSGordon Ross 
518bc7c423fSGordon Ross 	/*
519bc7c423fSGordon Ross 	 * This checks nbl_share_conflict, nbl_lock_conflict
520bc7c423fSGordon Ross 	 */
521bc7c423fSGordon Ross 	status = smb_nbl_conflict(node, 0, UINT64_MAX, NBL_REMOVE);
522bc7c423fSGordon Ross 	if (status == NT_STATUS_SHARING_VIOLATION) {
523bc7c423fSGordon Ross 		smb_node_end_crit(node);
524bc7c423fSGordon Ross 		smb_delete_error(err, NT_STATUS_SHARING_VIOLATION,
525bc7c423fSGordon Ross 		    ERRDOS, ERROR_SHARING_VIOLATION);
526bc7c423fSGordon Ross 		return (-1);
527bc7c423fSGordon Ross 	}
528b89a8333Snatalie li - Sun Microsystems - Irvine United States 	if (status != NT_STATUS_SUCCESS) {
529bc7c423fSGordon Ross 		smb_node_end_crit(node);
530b89a8333Snatalie li - Sun Microsystems - Irvine United States 		smb_delete_error(err, NT_STATUS_ACCESS_DENIED,
531b89a8333Snatalie li - Sun Microsystems - Irvine United States 		    ERRDOS, ERROR_ACCESS_DENIED);
532b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
533b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
534b89a8333Snatalie li - Sun Microsystems - Irvine United States 
5358b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	if (SMB_TREE_SUPPORTS_CATIA(sr))
5368b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 		flags |= SMB_CATIA;
5378b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 
5381fcced4cSJordan Brown 	rc = smb_fsop_remove(sr, sr->user_cr, node->n_dnode,
5398b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	    node->od_name, flags);
540b89a8333Snatalie li - Sun Microsystems - Irvine United States 	if (rc != 0) {
541d2488fe8SGordon Ross 		smbsr_map_errno(rc, err);
542d2488fe8SGordon Ross 		rc = -1;
543b89a8333Snatalie li - Sun Microsystems - Irvine United States 	}
544b89a8333Snatalie li - Sun Microsystems - Irvine United States 
545b89a8333Snatalie li - Sun Microsystems - Irvine United States 	smb_node_end_crit(node);
546d2488fe8SGordon Ross 	return (rc);
547b89a8333Snatalie li - Sun Microsystems - Irvine United States }
548b89a8333Snatalie li - Sun Microsystems - Irvine United States 
549b89a8333Snatalie li - Sun Microsystems - Irvine United States 
550c8ec8eeaSjose borrego /*
551c8ec8eeaSjose borrego  * smb_delete_check_path
552c8ec8eeaSjose borrego  *
553fe1c642dSBill Krier  * smb_pathname_validate() should already have been used to
554fe1c642dSBill Krier  * perform initial validation on the pathname. Additional
555fe1c642dSBill Krier  * request specific validation of the filename is performed
556fe1c642dSBill Krier  * here.
557fe1c642dSBill Krier  *
558fe1c642dSBill Krier  * - pn->pn_fname is NULL should result in NT_STATUS_FILE_IS_A_DIRECTORY
559fe1c642dSBill Krier  *
560fe1c642dSBill Krier  * - Any wildcard filename that resolves to '.' should result in
561fe1c642dSBill Krier  *   NT_STATUS_OBJECT_NAME_INVALID if the search attributes include
562fe1c642dSBill Krier  *   FILE_ATTRIBUTE_DIRECTORY
563c8ec8eeaSjose borrego  *
564c8ec8eeaSjose borrego  * Returns:
565fe1c642dSBill Krier  *   0: path is valid.
566b89a8333Snatalie li - Sun Microsystems - Irvine United States  *  -1: path is invalid. Sets error information in sr.
567c8ec8eeaSjose borrego  */
568b89a8333Snatalie li - Sun Microsystems - Irvine United States static int
smb_delete_check_path(smb_request_t * sr)569fe1c642dSBill Krier smb_delete_check_path(smb_request_t *sr)
570c8ec8eeaSjose borrego {
571b89a8333Snatalie li - Sun Microsystems - Irvine United States 	smb_fqi_t *fqi = &sr->arg.dirop.fqi;
572eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	smb_pathname_t *pn = &fqi->fq_path;
573c8ec8eeaSjose borrego 
574fe1c642dSBill Krier 	if (pn->pn_fname == NULL) {
575fe1c642dSBill Krier 		smbsr_error(sr, NT_STATUS_FILE_IS_A_DIRECTORY,
576fe1c642dSBill Krier 		    ERRDOS, ERROR_ACCESS_DENIED);
577fe1c642dSBill Krier 		return (-1);
578c8ec8eeaSjose borrego 	}
579c8ec8eeaSjose borrego 
580fe1c642dSBill Krier 	/* fname component is, or resolves to, '.' (dot) */
581fe1c642dSBill Krier 	if ((strcmp(pn->pn_fname, ".") == 0) ||
582eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	    (SMB_SEARCH_DIRECTORY(fqi->fq_sattr) &&
583c13be35aSGordon Ross 	    (smb_match(pn->pn_fname, ".", B_FALSE)))) {
584c8ec8eeaSjose borrego 		smbsr_error(sr, NT_STATUS_OBJECT_NAME_INVALID,
585c8ec8eeaSjose borrego 		    ERRDOS, ERROR_INVALID_NAME);
586b89a8333Snatalie li - Sun Microsystems - Irvine United States 		return (-1);
587c8ec8eeaSjose borrego 	}
588c8ec8eeaSjose borrego 
589b89a8333Snatalie li - Sun Microsystems - Irvine United States 	return (0);
590c8ec8eeaSjose borrego }
591c8ec8eeaSjose borrego 
592faa1795aSjb /*
593b89a8333Snatalie li - Sun Microsystems - Irvine United States  * smb_delete_error
594faa1795aSjb  */
595b89a8333Snatalie li - Sun Microsystems - Irvine United States static void
smb_delete_error(smb_error_t * err,uint32_t status,uint16_t errcls,uint16_t errcode)596b89a8333Snatalie li - Sun Microsystems - Irvine United States smb_delete_error(smb_error_t *err,
597b89a8333Snatalie li - Sun Microsystems - Irvine United States     uint32_t status, uint16_t errcls, uint16_t errcode)
598da6c28aaSamw {
599b89a8333Snatalie li - Sun Microsystems - Irvine United States 	err->status = status;
600b89a8333Snatalie li - Sun Microsystems - Irvine United States 	err->errcls = errcls;
601b89a8333Snatalie li - Sun Microsystems - Irvine United States 	err->errcode = errcode;
602da6c28aaSamw }
603