xref: /illumos-gate/usr/src/uts/common/smbsrv/smb_ioctl.h (revision fd23e79e54fa036de2121522ebfe7f566a9ad56a)
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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
24  * Copyright 2017 Joyent, Inc.
25  * Copyright 2022 RackTop Systems, Inc.
26  */
27 
28 #ifndef _SMB_IOCTL_H_
29 #define	_SMB_IOCTL_H_
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <smbsrv/smbinfo.h>
38 
39 #define	SMB_IOC_VERSION		0x534D4201	/* SMB1 */
40 
41 #define	SMB_IOC_BASE		(('S' << 16) | ('B' << 8))
42 
43 #define	SMB_IOC_CONFIG		_IOW(SMB_IOC_BASE, 1, int)
44 #define	SMB_IOC_START		_IOW(SMB_IOC_BASE, 2, int)
45 #define	SMB_IOC_GMTOFF		_IOW(SMB_IOC_BASE, 3, int)
46 #define	SMB_IOC_SHARE		_IOW(SMB_IOC_BASE, 4, int)
47 #define	SMB_IOC_UNSHARE		_IOW(SMB_IOC_BASE, 5, int)
48 #define	SMB_IOC_NUMOPEN		_IOW(SMB_IOC_BASE, 6, int)
49 #define	SMB_IOC_SVCENUM		_IOW(SMB_IOC_BASE, 7, int)
50 #define	SMB_IOC_FILE_CLOSE	_IOW(SMB_IOC_BASE, 8, int)
51 #define	SMB_IOC_SESSION_CLOSE	_IOW(SMB_IOC_BASE, 9, int)
52 #define	SMB_IOC_STOP		_IOW(SMB_IOC_BASE, 10, int)
53 #define	SMB_IOC_EVENT		_IOW(SMB_IOC_BASE, 11, int)
54 #define	SMB_IOC_SHAREINFO	_IOW(SMB_IOC_BASE, 12, int)
55 #define	SMB_IOC_SHAREACCESS	_IOW(SMB_IOC_BASE, 13, int)
56 #define	SMB_IOC_SPOOLDOC	_IOW(SMB_IOC_BASE, 14, int)
57 
58 typedef struct smb_ioc_header {
59 	uint32_t	version;
60 	uint32_t	crc;
61 	uint32_t	len;
62 	int		cmd;
63 } smb_ioc_header_t;
64 
65 typedef	struct smb_ioc_spooldoc {
66 	smb_ioc_header_t hdr;
67 	smb_inaddr_t	ipaddr;
68 	uint32_t	spool_num;
69 	char		username[MAXNAMELEN];
70 	char		path[MAXPATHLEN];
71 } smb_ioc_spooldoc_t;
72 
73 typedef	struct {
74 	smb_ioc_header_t hdr;
75 	int32_t		offset;
76 } smb_ioc_gmt_t;
77 
78 typedef struct smb_ioc_share {
79 	smb_ioc_header_t hdr;
80 	uint32_t	shrlen;
81 	char		shr[1];
82 } smb_ioc_share_t;
83 
84 typedef struct smb_ioc_shareinfo {
85 	smb_ioc_header_t hdr;
86 	char		shrname[MAXNAMELEN];
87 	uint32_t	shortnames;
88 } smb_ioc_shareinfo_t;
89 
90 typedef struct smb_ioc_shareaccess {
91 	smb_ioc_header_t hdr;
92 	uint64_t	session_id;
93 	uint64_t	user_id;
94 	char		shrname[MAXNAMELEN];
95 } smb_ioc_shareaccess_t;
96 
97 typedef	struct smb_ioc_start {
98 	smb_ioc_header_t hdr;
99 	int		opipe;
100 	int		lmshrd;
101 	int		udoor;
102 	/* These are used only by libfksmbsrv */
103 	void		*opipe_func;
104 	void		*lmshr_func;
105 	void		*udoor_func;
106 } smb_ioc_start_t;
107 
108 typedef	struct smb_ioc_event {
109 	smb_ioc_header_t hdr;
110 	uint32_t	txid;
111 } smb_ioc_event_t;
112 
113 typedef	struct smb_ioc_opennum {
114 	smb_ioc_header_t hdr;
115 	uint32_t	open_users;
116 	uint32_t	open_trees;
117 	uint32_t	open_files;
118 	uint32_t	qualtype;
119 	char		qualifier[MAXNAMELEN];
120 } smb_ioc_opennum_t;
121 
122 /*
123  * For enumeration, user and session are synonymous, as are
124  * connection and tree.
125  */
126 #define	SMB_SVCENUM_TYPE_USER	0x55534552	/* 'USER' */
127 #define	SMB_SVCENUM_TYPE_TREE	0x54524545	/* 'TREE' */
128 #define	SMB_SVCENUM_TYPE_FILE	0x46494C45	/* 'FILE' */
129 #define	SMB_SVCENUM_TYPE_SHARE	0x53484152	/* 'SHAR' */
130 
131 /* Maximum size of payload data an smbsrv ioctl may use. */
132 #define	SMB_IOC_DATA_SIZE		(256 * 1024)
133 
134 typedef struct smb_svcenum {
135 	uint32_t	se_type;	/* object type to enumerate */
136 	uint32_t	se_level;	/* level of detail being requested */
137 	uint32_t	se_prefmaxlen;	/* client max size buffer preference */
138 					/* (ignored by kernel) */
139 	uint32_t	se_resume;	/* client resume handle */
140 	uint32_t	se_bavail;	/* remaining buffer space in bytes */
141 	uint32_t	se_bused;	/* consumed buffer space in bytes */
142 	uint32_t	se_ntotal;	/* total number of objects */
143 	uint32_t	se_nlimit;	/* max number of objects to return */
144 	uint32_t	se_nitems;	/* number of objects in buf */
145 	uint32_t	se_nskip;	/* number of objects to skip */
146 	uint32_t	se_status;	/* enumeration status */
147 	uint32_t	se_buflen;	/* length of the buffer in bytes */
148 	uint8_t		se_buf[1];	/* buffer to hold enumeration data */
149 } smb_svcenum_t;
150 
151 typedef	struct smb_ioc_svcenum {
152 	smb_ioc_header_t hdr;
153 	smb_svcenum_t	svcenum;
154 } smb_ioc_svcenum_t;
155 
156 typedef struct smb_ioc_session {
157 	smb_ioc_header_t hdr;
158 	char		client[MAXNAMELEN];
159 	char		username[MAXNAMELEN];
160 } smb_ioc_session_t;
161 
162 typedef	struct smb_ioc_fileid {
163 	smb_ioc_header_t hdr;
164 	uint32_t	uniqid;
165 } smb_ioc_fileid_t;
166 
167 /* See also: smb_kmod_cfg_t */
168 typedef struct smb_ioc_cfg {
169 	smb_ioc_header_t hdr;
170 	uint32_t	maxworkers;
171 	uint32_t	maxconnections;
172 	uint32_t	keepalive;
173 	int32_t		restrict_anon;
174 	int32_t		signing_enable;
175 	int32_t		signing_required;
176 	int32_t		oplock_enable;
177 	int32_t		sync_enable;
178 	int32_t		secmode;
179 	int32_t		netbios_enable;
180 	int32_t		ipv6_enable;
181 	int32_t		print_enable;
182 	int32_t		traverse_mounts;
183 	int32_t		short_names;
184 	uint32_t	max_protocol;
185 	uint32_t	min_protocol;
186 	uint32_t	encrypt;
187 	uint32_t	encrypt_ciphers;
188 	uint32_t	exec_flags;
189 	uint32_t	negtok_len;
190 	uint32_t	max_opens;	/* per client */
191 	smb_version_t	version;
192 	uint16_t	initial_credits;
193 	uint16_t	maximum_credits;
194 	/* SMB negotiate protocol response. */
195 	uuid_t		machine_uuid;
196 	uchar_t		negtok[SMB_PI_MAX_NEGTOK];
197 	char		native_os[SMB_PI_MAX_NATIVE_OS];
198 	char		native_lm[SMB_PI_MAX_LANMAN];
199 	char		nbdomain[NETBIOS_NAME_SZ];
200 	char		fqdn[SMB_PI_MAX_DOMAIN];
201 	char		hostname[SMB_PI_MAX_HOST];
202 	char		system_comment[SMB_PI_MAX_COMMENT];
203 } smb_ioc_cfg_t;
204 
205 typedef union smb_ioc {
206 	smb_ioc_header_t	ioc_hdr;
207 	smb_ioc_gmt_t		ioc_gmt;
208 	smb_ioc_cfg_t		ioc_cfg;
209 	smb_ioc_start_t		ioc_start;
210 	smb_ioc_event_t		ioc_event;
211 	smb_ioc_opennum_t	ioc_opennum;
212 	smb_ioc_svcenum_t	ioc_svcenum;
213 	smb_ioc_session_t	ioc_session;
214 	smb_ioc_fileid_t	ioc_fileid;
215 	smb_ioc_share_t		ioc_share;
216 	smb_ioc_shareaccess_t	ioc_shareaccess;
217 	smb_ioc_shareinfo_t	ioc_shareinfo;
218 	smb_ioc_spooldoc_t	ioc_spooldoc;
219 } smb_ioc_t;
220 
221 uint32_t smb_crc_gen(uint8_t *, size_t);
222 
223 /* fksmbd (init,open,close,ioctl) calls into libfksmbsrv */
224 int fksmbsrv_drv_open(void);
225 int fksmbsrv_drv_close(void);
226 int fksmbsrv_drv_ioctl(int cmd, void *arg);
227 void fksmbsrv_drv_load(void);
228 
229 #ifdef __cplusplus
230 }
231 #endif
232 
233 #endif /* _SMB_IOCTL_H_ */
234