xref: /illumos-gate/usr/src/uts/common/netsmb/smb_dev.h (revision 686670eacbe137c7a9e6c85fef8763f8627a27b5)
1 /*
2  * Copyright (c) 2000-2001 Boris Popov
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *    This product includes software developed by Boris Popov.
16  * 4. Neither the name of the author nor the names of any co-contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  * $Id: smb_dev.h,v 1.10.178.1 2005/05/27 02:35:29 lindak Exp $
33  */
34 
35 /*
36  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
37  * Use is subject to license terms.
38  *
39  * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
40  */
41 
42 #ifndef _NETSMB_DEV_H_
43 #define	_NETSMB_DEV_H_
44 
45 /*
46  * This file defines an internal ABI for the "nsmb" driver,
47  * particularly the various data structures passed to ioctl.
48  * In order to avoid some messy 32-bit to 64-bit conversions
49  * in the driver, we take pains to define all data structures
50  * that pass across the user/kernel boundary in a way that
51  * makes them invariant across 32-bit and 64-bit ABIs.
52  * This invariance is checked during the driver build
53  * using a mechanism similar to genassym.h builds.
54  *
55  * If you change any of the ioctl data structures in
56  * this file, YOU MUST ALSO edit this file:
57  *   uts/common/fs/smbclnt/netsmb/offsets.in
58  * and then verify the invariance describe above.
59  *
60  * Also, remember to "bump" NSMB_VER below when
61  * any part of this user/kernel I/F changes.
62  */
63 
64 #include <sys/types.h>
65 #include <sys/socket_impl.h>
66 #include <netinet/in.h>
67 
68 #define	NSMB_NAME		"nsmb"
69 
70 /*
71  * Update NSMB_VER* if any of the ioctl codes and/or
72  * associated structures change in ways that would
73  * make them incompatible with an old driver.
74  */
75 #define	NSMB_VERMAJ	2
76 #define	NSMB_VERMIN	0x100
77 #define	NSMB_VERSION	((NSMB_VERMAJ << 16) | NSMB_VERMIN)
78 
79 /*
80  * Some errno values we need to expose to the library.
81  * NB: these are also defined in the library smbfs_api.h
82  * to avoid exposing all of this stuff in that API.
83  *
84  * EBADRPC is used for message decoding errors.
85  * EAUTH is used for CIFS authentication errors.
86  */
87 #ifndef EBADRPC
88 #define	EBADRPC		113
89 #endif
90 #ifndef EAUTH
91 #define	EAUTH		114
92 #endif
93 
94 /*
95  * Upper/lower case options
96  */
97 #define	SMB_CS_NONE	0x0000
98 #define	SMB_CS_UPPER	0x0001	/* convert passed string to upper case */
99 #define	SMB_CS_LOWER	0x0002	/* convert passed string to lower case */
100 
101 /*
102  * access mode stuff (see also smb_lib.h)
103  */
104 #define	SMBM_ANY_OWNER		((uid_t)-1)
105 #define	SMBM_ANY_GROUP		((gid_t)-1)
106 
107 /*
108  * Option flags in smbioc_ossn.ioc_opt
109  * and vcspec.optflags
110  */
111 #define	SMBVOPT_CREATE		0x0001	/* create object if necessary */
112 #define	SMBVOPT_PRIVATE		0x0002	/* connection should be private */
113 #define	SMBVOPT_SINGLESHARE	0x0004	/* keep only one share at this VC */
114 #define	SMBVOPT_PERMANENT	0x0010	/* object will keep last reference */
115 #define	SMBVOPT_ANONYMOUS	0x0020	/* using a NULL session */
116 
117 #define	SMBVOPT_SIGNING_ENABLED		0x10000	/* sign if server agrees */
118 #define	SMBVOPT_SIGNING_REQUIRED	0x20000 /* signing required */
119 #define	SMBVOPT_SIGNING_MASK		0x30000	/* all signing bits */
120 
121 #define	SMB2_DIALECT_BASE	0x0200
122 #define	SMB2_DIALECT_0202	0x0202
123 #define	SMB2_DIALECT_02ff	0x02ff
124 #define	SMB2_DIALECT_0210	0x0210
125 #define	SMB2_DIALECT_0300	0x0300
126 #define	SMB2_DIALECT_0302	0x0302
127 
128 /* Maximum supported dialect (for ssn_maxver) */
129 #define	SMB2_DIALECT_MAX	SMB2_DIALECT_0302
130 
131 /*
132  * Option flags in smbioc_oshare.ioc_opt
133  * and sharespec.optflags
134  */
135 #define	SMBSOPT_CREATE		SMBVOPT_CREATE
136 #define	SMBSOPT_PERMANENT	SMBVOPT_PERMANENT
137 
138 /* All user and machine names. */
139 #define	SMBIOC_MAX_NAME		256
140 
141 /*
142  * Size of storage for p/w hashes.
143  * Also for SMBIOC_GETSSNKEY.
144  */
145 #define	SMBIOC_HASH_SZ	16
146 
147 /*
148  * network IO daemon states
149  */
150 enum smbiod_state {
151 	SMBIOD_ST_UNINIT = 0,	/* uninitialized */
152 	SMBIOD_ST_RECONNECT,	/* a [re]connect attempt requested */
153 	SMBIOD_ST_RCFAILED,	/* a reconnect attempt has failed */
154 	SMBIOD_ST_CONNECTED,	/* Transport (TCP) connected */
155 	SMBIOD_ST_NEGOTIATED,	/* Negotiated SMB/SMB2+ */
156 	SMBIOD_ST_AUTHCONT,	/* Session setup continuing */
157 	SMBIOD_ST_AUTHFAIL,	/* Session setup failed */
158 	SMBIOD_ST_AUTHOK,	/* Session setup success */
159 	SMBIOD_ST_VCACTIVE,	/* iod_work running */
160 	SMBIOD_ST_IDLE,		/* no trees, will go DEAD */
161 	SMBIOD_ST_DEAD		/* connection gone, no IOD */
162 };
163 
164 
165 /*
166  * We're now using structures that are invariant
167  * across 32-bit vs 64-bit compilers for all
168  * member sizes and offsets.  Scalar members
169  * simply have to use fixed-size types.
170  * Pointers are a little harder...
171  * We use this union for all pointers that
172  * must pass between user and kernel.
173  */
174 typedef union lptr {
175 	uint64_t lp_ll;
176 #ifdef _LP64
177 	void	*lp_ptr;
178 #endif
179 #ifdef _ILP32
180 	void	*_lp_p2[2];
181 #ifdef _LITTLE_ENDIAN
182 #define	lp_ptr	_lp_p2[0]
183 #define	lp_pad	_lp_p2[1]
184 #else /* _ENDIAN */
185 #define	lp_pad	_lp_p2[0]
186 #define	lp_ptr	_lp_p2[1]
187 #endif /* _ENDIAN */
188 #endif /* _ILP32 */
189 } lptr_t;
190 
191 /*
192  * Handy union of sockaddr types we use.
193  * Type discriminator is sa_family
194  */
195 union smbioc_sockaddr {
196 	struct sockaddr sa;	/* generic */
197 	struct sockaddr_in sin;
198 	struct sockaddr_in6 sin6;
199 };
200 typedef union smbioc_sockaddr smbioc_sockaddr_t;
201 
202 /*
203  * This is what identifies a session.
204  */
205 struct smbioc_ssn_ident {
206 	smbioc_sockaddr_t id_srvaddr;
207 	char		id_domain[SMBIOC_MAX_NAME];
208 	char		id_user[SMBIOC_MAX_NAME];
209 };
210 typedef struct smbioc_ssn_ident smbioc_ssn_ident_t;
211 
212 /*
213  * Flags for smbioc_ossn.ssn_opt
214  */
215 #define	SMBLK_CREATE		SMBVOPT_CREATE
216 
217 /*
218  * Structure used with SMBIOC_SSN_FIND, _CREATE
219  */
220 struct smbioc_ossn {
221 	uint32_t		ssn_owner;	/* Unix owner (UID) */
222 	uint32_t		ssn_vopt;	/* i.e. SMBVOPT_CREATE */
223 	uint16_t		ssn_minver;	/* Min SMB version. */
224 	uint16_t		ssn_maxver;	/* Max SMB version. */
225 	smbioc_ssn_ident_t	ssn_id;
226 	char			ssn_srvname[SMBIOC_MAX_NAME];
227 };
228 typedef struct smbioc_ossn smbioc_ossn_t;
229 /* Convenience names for members under ssn_id */
230 #define	ssn_srvaddr	ssn_id.id_srvaddr
231 #define	ssn_domain	ssn_id.id_domain
232 #define	ssn_user	ssn_id.id_user
233 
234 /*
235  * Structure used with SMBIOC_TREE_FIND, _CONNECT
236  */
237 struct smbioc_oshare {
238 	uint32_t	sh_use;		/* requested */
239 	uint32_t	sh_type;	/* returned */
240 	char		sh_name[SMBIOC_MAX_NAME];
241 	char		sh_pass[SMBIOC_MAX_NAME];
242 };
243 typedef struct smbioc_oshare smbioc_oshare_t;
244 
245 typedef struct smbioc_tcon {
246 	int32_t		tc_flags;
247 	int32_t		tc_opt;
248 	smbioc_oshare_t	tc_sh;
249 } smbioc_tcon_t;
250 
251 /*
252  * This is the operational state information passed
253  * in and out of the driver for SMBIOC_SSN_WORK
254  */
255 struct smbioc_ssn_work {
256 	uint32_t	wk_out_state;	/* out-only */
257 	uint32_t	wk_u_ssnkey_len; /* ssn key length */
258 	lptr_t		wk_u_ssnkey_buf; /* user-space ptr! */
259 	uint32_t	wk_u_auth_rlen;	/* recv auth tok len */
260 	uint32_t	wk_u_auth_wlen;	/* send auth tok len */
261 	lptr_t		wk_u_auth_rbuf;	/* recv auth tok buf */
262 	lptr_t		wk_u_auth_wbuf;	/* send auth tok buf */
263 	uint8_t		wk_cl_guid[16];	/* client GUID */
264 };
265 typedef struct smbioc_ssn_work smbioc_ssn_work_t;
266 
267 /*
268  * User-level SMB requests
269  */
270 
271 typedef struct smbioc_rw {
272 	uint32_t	ioc_cnt;
273 	uint32_t	ioc_flags;
274 	lloff_t	_ioc_offset;
275 	lptr_t	_ioc_base;
276 } smbioc_rw_t;
277 #define	ioc_offset	_ioc_offset._f
278 #define	ioc_base	_ioc_base.lp_ptr
279 
280 /* Transact on named pipe (send/recv) */
281 typedef struct smbioc_xnp {
282 	uint32_t	ioc_tdlen;	/* transmit len */
283 	uint32_t	ioc_rdlen;	/* recv maxlen */
284 	uint32_t	ioc_more;	/* more data to read */
285 	uint32_t	ioc_pad1;
286 	lptr_t		_ioc_tdata;
287 	lptr_t		_ioc_rdata;
288 } smbioc_xnp_t;
289 #define	ioc_tdata	_ioc_tdata.lp_ptr
290 #define	ioc_rdata	_ioc_rdata.lp_ptr
291 
292 typedef struct smbioc_ntcreate {
293 	uint32_t	ioc_req_acc;
294 	uint32_t	ioc_efattr;
295 	uint32_t	ioc_share_acc;
296 	uint32_t	ioc_open_disp;
297 	uint32_t	ioc_creat_opts;
298 	char		ioc_name[SMBIOC_MAX_NAME];
299 } smbioc_ntcreate_t;
300 
301 typedef struct smbioc_printjob {
302 	uint16_t	ioc_setuplen;
303 	uint16_t	ioc_prmode;
304 	char		ioc_title[SMBIOC_MAX_NAME];
305 } smbioc_printjob_t;
306 
307 /* Password Keychain (PK) support. */
308 typedef struct smbioc_pk {
309 	uid_t	pk_uid;				/* UID for PAM use */
310 	char pk_dom[SMBIOC_MAX_NAME];		/* CIFS domain name */
311 	char pk_usr[SMBIOC_MAX_NAME];		/* CIFS user name */
312 	uchar_t pk_lmhash[SMBIOC_HASH_SZ];	/* LanMan p/w hash */
313 	uchar_t pk_nthash[SMBIOC_HASH_SZ];	/* NTLM p/w hash */
314 } smbioc_pk_t;
315 
316 
317 /*
318  * Device IOCTLs
319  *
320  * Define ioctl codes the way ZFS does.
321  * The "base" value is arbitrary, and can
322  * occupy the high word if we like, because
323  * our driver does its own copyin/copyout.
324  * Keep GETVERS first and use it to verify
325  * driver compatibility with the library.
326  */
327 #define	SMBIOC_BASE	((('n' << 8) | 's') << 8)
328 typedef enum nsmb_ioc {
329 	SMBIOC_GETVERS = SMBIOC_BASE,	/* keep first */
330 	SMBIOC_FLAGS2,		/* obsolete */
331 	SMBIOC_GETSSNKEY,	/* get SMB session key */
332 	SMBIOC_DUP_DEV,		/* duplicate dev handle */
333 
334 	SMBIOC_READ,		/* read (pipe) */
335 	SMBIOC_WRITE,		/* write (pipe) */
336 	SMBIOC_XACTNP,		/* "transact" (pipe) */
337 	SMBIOC_NTCREATE,	/* open or create */
338 	SMBIOC_PRINTJOB,	/* open print job */
339 	SMBIOC_CLOSEFH,		/* from ntcreate or printjob */
340 
341 	SMBIOC_SSN_CREATE,
342 	SMBIOC_SSN_FIND,
343 	SMBIOC_SSN_KILL,	/* force disconnect */
344 	SMBIOC_SSN_RELE,	/* drop our reference */
345 
346 	SMBIOC_TREE_CONNECT,	/* create and connect */
347 	SMBIOC_TREE_FIND,
348 	SMBIOC_TREE_KILL,
349 	SMBIOC_TREE_RELE,
350 
351 	SMBIOC_IOD_CONNECT,	/* Setup connection */
352 	SMBIOC_IOD_NEGOTIATE,	/* SMB/SMB2 negotiate */
353 	SMBIOC_IOD_SSNSETUP,	/* SMB/SMB2 session setup */
354 	SMBIOC_IOD_WORK,	/* work on session requests */
355 	SMBIOC_IOD_IDLE,	/* wait for requests on this session */
356 	SMBIOC_IOD_RCFAIL,	/* tell driver reconnect failed */
357 
358 	/* Password Keychain (PK) support. */
359 	SMBIOC_PK_ADD,    /* Add/Modify a password entry */
360 	SMBIOC_PK_CHK,    /* Check for a password entry */
361 	SMBIOC_PK_DEL,    /* Delete specified password entry */
362 	SMBIOC_PK_DEL_OWNER,	/* all owned by the caller */
363 	SMBIOC_PK_DEL_EVERYONE	/* all owned by everyone */
364 } nsmb_ioc_t;
365 
366 #endif /* _NETSMB_DEV_H_ */
367