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 2009 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26/*
27 * SMB: trans2_create_directory
28 *
29 * This requests the server to create a directory relative to Tid in the
30 * SMB header, optionally assigning extended attributes to it.
31 *
32 *  Client Request             Value
33 *  ========================== =========================================
34 *
35 *  WordCount                  15
36 *  MaxSetupCount              0
37 *  SetupCount                 1
38 *  Setup[0]                   TRANS2_CREATE_DIRECTORY
39 *
40 *  Parameter Block Encoding   Description
41 *  ========================== =========================================
42 *
43 *  ULONG Reserved;            Reserved--must be zero
44 *  STRING Name[];             Directory name to create
45 *  UCHAR Data[];              Optional FEAList for the new directory
46 *
47 *  Response Parameter Block   Description
48 *  ========================== =========================================
49 *
50 *  USHORT EaErrorOffset       Offset into FEAList of first error which
51 *                             occurred while setting EAs
52 */
53
54#include <smbsrv/smb_kproto.h>
55
56
57/*
58 * smb_com_trans2_create_directory
59 */
60smb_sdrc_t
61smb_com_trans2_create_directory(struct smb_request *sr, struct smb_xa *xa)
62{
63	int	rc;
64	smb_pathname_t *pn = &sr->arg.dirop.fqi.fq_path;
65
66	if (!STYPE_ISDSK(sr->tid_tree->t_res_type)) {
67		smbsr_error(sr, NT_STATUS_ACCESS_DENIED,
68		    ERRDOS, ERROR_ACCESS_DENIED);
69		return (SDRC_ERROR);
70	}
71
72	if (smb_mbc_decodef(&xa->req_param_mb, "%4.u", sr, &pn->pn_path) != 0)
73		return (SDRC_ERROR);
74
75	smb_pathname_init(sr, pn, pn->pn_path);
76	if (!smb_pathname_validate(sr, pn) ||
77	    !smb_validate_dirname(sr, pn)) {
78		return (SDRC_ERROR);
79	}
80
81	if ((rc = smb_common_create_directory(sr)) != 0) {
82		smbsr_errno(sr, rc);
83		return (SDRC_ERROR);
84	}
85
86	if (smb_mbc_encodef(&xa->rep_param_mb, "w", 0) < 0)
87		return (SDRC_ERROR);
88
89	return (SDRC_SUCCESS);
90}
91