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