xref: /illumos-gate/usr/src/uts/common/fs/smbsrv/smb_trans2_create_directory.c (revision faa1795a28a5c712eed6d0a3f84d98c368a316c6)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 /*
29  * SMB: trans2_create_directory
30  *
31  * This requests the server to create a directory relative to Tid in the
32  * SMB header, optionally assigning extended attributes to it.
33  *
34  *  Client Request             Value
35  *  ========================== =========================================
36  *
37  *  WordCount                  15
38  *  MaxSetupCount              0
39  *  SetupCount                 1
40  *  Setup[0]                   TRANS2_CREATE_DIRECTORY
41  *
42  *  Parameter Block Encoding   Description
43  *  ========================== =========================================
44  *
45  *  ULONG Reserved;            Reserved--must be zero
46  *  STRING Name[];             Directory name to create
47  *  UCHAR Data[];              Optional FEAList for the new directory
48  *
49  *  Response Parameter Block   Description
50  *  ========================== =========================================
51  *
52  *  USHORT EaErrorOffset       Offset into FEAList of first error which
53  *                             occurred while setting EAs
54  */
55 
56 #include <smbsrv/nterror.h>
57 #include <smbsrv/ntstatus.h>
58 #include <smbsrv/smb_incl.h>
59 
60 
61 /*
62  * smb_com_trans2_create_directory
63  */
64 smb_sdrc_t
65 smb_com_trans2_create_directory(struct smb_request *sr, struct smb_xa *xa)
66 {
67 	int	rc;
68 	DWORD	status;
69 
70 	if (!STYPE_ISDSK(sr->tid_tree->t_res_type)) {
71 		smbsr_error(sr, NT_STATUS_ACCESS_DENIED,
72 		    ERRDOS, ERROR_ACCESS_DENIED);
73 		return (SDRC_ERROR);
74 	}
75 
76 	if (smb_decode_mbc(&xa->req_param_mb, "%4.s",
77 	    sr, &sr->arg.dirop.fqi.path) != 0) {
78 		return (SDRC_ERROR);
79 	}
80 
81 	if ((status = smb_validate_dirname(sr->arg.dirop.fqi.path)) != 0) {
82 		smbsr_error(sr, status, ERRDOS, ERROR_INVALID_NAME);
83 		return (SDRC_ERROR);
84 	}
85 
86 	if ((rc = smb_common_create_directory(sr)) != 0) {
87 		smbsr_errno(sr, rc);
88 		return (SDRC_ERROR);
89 	}
90 
91 	if (smb_encode_mbc(&xa->rep_param_mb, "w", 0) < 0)
92 		return (SDRC_ERROR);
93 
94 	return (SDRC_SUCCESS);
95 }
96