xref: /illumos-gate/usr/src/uts/common/fs/smbsrv/smb_nt_transact_ioctl.c (revision f998c95e3b7029fe5f7542e115f7474ddb8024d7)
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 #include <smbsrv/smb_incl.h>
29 #include <smbsrv/winioctl.h>
30 #include <smbsrv/ntstatus.h>
31 
32 
33 /*
34  * This table defines the list of IOCTL/FSCTL values for which we'll
35  * return a specific NT status code.
36  */
37 static struct {
38 	uint32_t fcode;
39 	DWORD status;
40 } ioctl_ret_tbl[] = {
41 	{ FSCTL_GET_OBJECT_ID,		NT_STATUS_INVALID_PARAMETER },
42 	{ FSCTL_QUERY_ALLOCATED_RANGES,	NT_STATUS_INVALID_PARAMETER }
43 };
44 
45 
46 /*
47  * smb_nt_transact_ioctl
48  *
49  * This command allows device and file system control functions to be
50  * transferred transparently from client to server. This is currently
51  * a stub to work out whether or not we need to return an NT status
52  * code.
53  *
54  * Setup Words Encoding        Description
55  * =========================== =========================================
56  * ULONG FunctionCode;         NT device or file system control code
57  * USHORT Fid;                 Handle for io or fs control. Unless BIT0
58  *                             of ISFLAGS is set.
59  * BOOLEAN IsFsctl;            Indicates whether the command is a device
60  *                             control (FALSE) or a file system control
61  *                             (TRUE).
62  * UCHAR   IsFlags;            BIT0 - command is to be applied to share
63  *                             root handle. Share must be a DFS share.
64  *
65  * Data Block Encoding         Description
66  * =========================== =========================================
67  * Data[ TotalDataCount ]      Passed to the Fsctl or Ioctl
68  *
69  * Server Response             Description
70  * =========================== ==================================
71  * SetupCount                  1
72  * Setup[0]                    Length of information returned by
73  *                             io or fs control.
74  * DataCount                   Length of information returned by
75  *                             io or fs control.
76  * Data[ DataCount ]           The results of the io or fs control.
77  */
78 smb_sdrc_t
79 smb_nt_transact_ioctl(struct smb_request *sr, struct smb_xa *xa)
80 {
81 	DWORD status = NT_STATUS_SUCCESS;
82 	uint32_t fcode;
83 	unsigned short fid;
84 	unsigned char is_fsctl;
85 	unsigned char is_flags;
86 	int i;
87 
88 	if (smb_decode_mbc(&xa->req_setup_mb, "lwbb",
89 	    &fcode, &fid, &is_fsctl, &is_flags) != 0) {
90 		smbsr_error(sr, NT_STATUS_INVALID_PARAMETER, 0, 0);
91 		return (SDRC_ERROR);
92 	}
93 
94 	for (i = 0; i < sizeof (ioctl_ret_tbl) / sizeof (ioctl_ret_tbl[0]);
95 	    i++) {
96 		if (ioctl_ret_tbl[i].fcode == fcode) {
97 			status = ioctl_ret_tbl[i].status;
98 			break;
99 		}
100 	}
101 
102 	if (status != NT_STATUS_SUCCESS) {
103 		smbsr_error(sr, status, 0, 0);
104 		return (SDRC_ERROR);
105 	}
106 
107 	(void) smb_encode_mbc(&xa->rep_param_mb, "l", 0);
108 	return (SDRC_SUCCESS);
109 }
110