xref: /titanic_50/usr/src/uts/common/netsmb/smb_dev.h (revision 45179f4335d029f1129eb7283f8087740f0395f1)
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 2008 Sun Microsystems, Inc.  All rights reserved.
37  * Use is subject to license terms.
38  */
39 
40 #ifndef _NETSMB_DEV_H_
41 #define	_NETSMB_DEV_H_
42 
43 /*
44  * This file defines an internal ABI for the "nsmb" driver,
45  * particularly the various data structures passed to ioctl.
46  * In order to avoid some messy 32-bit to 64-bit conversions
47  * in the driver, we take pains to define all data structures
48  * that pass across the user/kernel boundary in a way that
49  * makes them invariant across 32-bit and 64-bit ABIs.
50  * This invariance is checked during the driver build
51  * using a mechanism similar to genassym.h builds.
52  *
53  * If you change any of the ioctl data structures in
54  * this file, YOU MUST ALSO edit this file:
55  *   uts/common/fs/smbclnt/netsmb/offsets.in
56  * and then verify the invariance describe above.
57  *
58  * Also, remember to "bump" NSMB_VER below when
59  * any part of this user/kernel I/F changes.
60  */
61 
62 #ifndef _KERNEL
63 #include <sys/types.h>
64 #endif
65 
66 #include <sys/socket_impl.h>
67 #include <netsmb/smb.h>
68 #include <netsmb/netbios.h>
69 
70 #define	NSMB_NAME		"nsmb"
71 
72 /*
73  * Update NSMB_VER* if any of the ioctl codes and/or
74  * associated structures change in ways that would
75  * make them incompatible with an old driver.
76  */
77 #define	NSMB_VERMAJ	1
78 #define	NSMB_VERMIN	3600
79 #define	NSMB_VERSION	(NSMB_VERMAJ * 100000 + NSMB_VERMIN)
80 #define	NSMB_VER_STR "1.36"
81 
82 #define	NSMBFL_OPEN		0x0001
83 #define	NSMBFL_NEWVC		0x0002
84 
85 /*
86  * Hack-ish errno values we need to expose to the library.
87  * EBADRPC is used for message decoding errors.
88  * EAUTH is used for CIFS authentication errors.
89  */
90 #ifndef EBADRPC
91 #define	EBADRPC 	113 /* XXX */
92 #endif
93 #ifndef EAUTH
94 #define	EAUTH		114 /* XXX */
95 #endif
96 
97 /*
98  * "Level" in the connection object hierarchy
99  */
100 #define	SMBL_SM		0
101 #define	SMBL_VC		1
102 #define	SMBL_SHARE	2
103 #define	SMBL_NUM	3
104 #define	SMBL_NONE	(-1)
105 
106 /*
107  * Upper/lower case options
108  */
109 #define	SMB_CS_NONE	0x0000
110 #define	SMB_CS_UPPER	0x0001	/* convert passed string to upper case */
111 #define	SMB_CS_LOWER	0x0002	/* convert passed string to lower case */
112 
113 /*
114  * access mode stuff (see also smb_lib.h)
115  */
116 #define	SMBM_ANY_OWNER		((uid_t)-1)
117 #define	SMBM_ANY_GROUP		((gid_t)-1)
118 #define	SMBM_MASK		0777
119 #define	SMBM_EXACT		010000	/* check for specified mode exactly */
120 #ifdef _KERNEL
121 /* In-kernel, we prefer the vnode.h names. */
122 #define	SMBM_READ	VREAD	/* (S_IRUSR) read conn attrs. */
123 #define	SMBM_WRITE	VWRITE	/* (S_IWUSR) modify conn attrs */
124 #define	SMBM_EXEC	VEXEC	/* (S_IXUSR) can send SMB requests */
125 #endif
126 
127 /*
128  * Option flags in smbioc_ossn.ioc_opt
129  * and vcspec.optflags
130  */
131 #define	SMBVOPT_CREATE		0x0001	/* create object if necessary */
132 #define	SMBVOPT_PRIVATE		0x0002	/* connection should be private */
133 #define	SMBVOPT_SINGLESHARE	0x0004	/* keep only one share at this VC */
134 #define	SMBVOPT_PERMANENT	0x0010	/* object will keep last reference */
135 #define	SMBVOPT_EXT_SEC		0x0020	/* extended security negotiation */
136 #define	SMBVOPT_USE_KEYCHAIN	0x0040	/* get p/w from keychain */
137 #define	SMBVOPT_KC_DOMAIN	0x0080	/* keychain lookup uses domain */
138 
139 #define	SMBVOPT_SIGNING_ENABLED		0x0100	/* sign if server agrees */
140 #define	SMBVOPT_SIGNING_REQUIRED	0x0200	/* signing required */
141 #define	SMBVOPT_SIGNING_MASK		0x0300	/* all signing bits */
142 
143 /* XXX: How about a separate field for these? */
144 #define	SMBVOPT_MINAUTH			0x7000	/* min. auth. level (mask) */
145 #define	SMBVOPT_MINAUTH_NONE		0x0000	/* any authentication OK */
146 #define	SMBVOPT_MINAUTH_LM		0x1000	/* no plaintext passwords */
147 #define	SMBVOPT_MINAUTH_NTLM		0x2000	/* don't send LM reply */
148 #define	SMBVOPT_MINAUTH_NTLMV2		0x3000	/* don't fall back to NTLMv1 */
149 #define	SMBVOPT_MINAUTH_KERBEROS	0x4000	/* don't do NTLMv1 or v2 */
150 
151 /*
152  * Option flags in smbioc_oshare.ioc_opt
153  * and sharespec.optflags
154  */
155 #define	SMBSOPT_CREATE		SMBVOPT_CREATE
156 #define	SMBSOPT_PERMANENT	SMBVOPT_PERMANENT
157 
158 #define	MAX_STR_LEN	8	/* Maxilum length of the minor device name */
159 
160 /*
161  * We're now using structures that are invariant
162  * across 32-bit vs 64-bit compilers for all
163  * member sizes and offsets.  Scalar members
164  * simply have to use fixed-size types.
165  * Pointers are a little harder...
166  * We use this union for all pointers that
167  * must pass between user and kernel.
168  */
169 typedef union lptr {
170 	uint64_t lp_ll;
171 #ifdef _LP64
172 	void	*lp_ptr;
173 #endif
174 #ifdef _ILP32
175 	void	*_lp_p2[2];
176 #ifdef _LITTLE_ENDIAN
177 #define	lp_ptr	_lp_p2[0]
178 #define	lp_pad	_lp_p2[1]
179 #else /* _ENDIAN */
180 #define	lp_pad	_lp_p2[0]
181 #define	lp_ptr	_lp_p2[1]
182 #endif /* _ENDIAN */
183 #endif /* _ILP32 */
184 } lptr_t;
185 
186 /*
187  * Handy union of sockaddr types we use.
188  * Type discriminator is sa_family
189  */
190 union sockaddr_any {
191 	struct sockaddr sa;
192 	struct sockaddr_in in;
193 	struct sockaddr_nb nb;
194 };
195 
196 
197 /*
198  * SMBIOC_LOOKUP flags
199  */
200 #define	SMBLK_CREATE		SMBVOPT_CREATE
201 
202 #define	DEF_SEC_TOKEN_LEN 2048
203 
204 struct smbioc_ossn {
205 	union sockaddr_any		ioc_server;
206 	union sockaddr_any		ioc_local;
207 	char		ioc_localcs[16];	/* local charset */
208 	char		ioc_servercs[16];	/* server charset */
209 	char		ioc_srvname[SMB_MAXSRVNAMELEN + 1];
210 	char		ioc_user[SMB_MAXUSERNAMELEN + 1];
211 	char		ioc_workgroup[SMB_MAXUSERNAMELEN + 1];
212 	char		ioc_password[SMB_MAXPASSWORDLEN + 1];
213 	int32_t		ioc_opt;
214 	int32_t		ioc_timeout;    /* ignored?! XXX */
215 	int32_t		ioc_retrycount; /* number of retries before giveup */
216 	uid_t		ioc_owner;	/* proposed owner */
217 	gid_t		ioc_group;	/* proposed group */
218 	mode_t		ioc_mode;	/* desired access mode */
219 	mode_t		ioc_rights;	/* SMBM_* */
220 	int32_t		ioc_intoklen;
221 	int32_t		ioc_outtoklen;
222 	/* copyout ends at this offset */
223 	lptr_t		_ioc_intok;
224 	lptr_t		_ioc_outtok;
225 };
226 typedef struct smbioc_ossn smbioc_ossn_t;
227 #define	ioc_intok	_ioc_intok.lp_ptr
228 #define	ioc_outtok	_ioc_outtok.lp_ptr
229 
230 
231 struct smbioc_oshare {
232 	char		ioc_share[SMB_MAXSHARENAMELEN + 1];
233 	char		ioc_password[SMB_MAXPASSWORDLEN + 1];
234 	int32_t		ioc_opt;
235 	int32_t		ioc_stype;	/* share type */
236 	uid_t		ioc_owner;	/* proposed owner of share */
237 	gid_t		ioc_group;	/* proposed group of share */
238 	mode_t		ioc_mode;	/* desired access mode to share */
239 	mode_t		ioc_rights;	/* SMBM_* */
240 	/*
241 	 * Hack: need the size of this to be 8-byte aligned
242 	 * so that the ioc_ossn following it in smbioc_lookup
243 	 * is correctly aligned...
244 	 */
245 	int32_t		ioc__pad;
246 };
247 typedef struct smbioc_oshare smbioc_oshare_t;
248 
249 typedef struct smbioc_rq {
250 	uchar_t		ioc_cmd;
251 	uchar_t		ioc_twc; /* _twords */
252 	ushort_t	ioc_tbc; /* _tbytes */
253 	int32_t		ioc_rpbufsz; /* _rpbuf */
254 	uchar_t		ioc__pad1;
255 	uchar_t		ioc_rwc;
256 	ushort_t	ioc_rbc;
257 	uchar_t		ioc__pad2;
258 	uint8_t 	ioc_errclass;
259 	uint16_t	ioc_serror;
260 	uint32_t	ioc_error;
261 	uint32_t	ioc__pad3;
262 	/*
263 	 * Copyout all but the pointers, which
264 	 * we may have set to kernel memory.
265 	 * See ..._COPYOUT_SIZE
266 	 */
267 	lptr_t		_ioc_twords;
268 	lptr_t		_ioc_tbytes;
269 	lptr_t		_ioc_rpbuf;
270 } smbioc_rq_t;
271 #define	ioc_twords	_ioc_twords.lp_ptr
272 #define	ioc_tbytes	_ioc_tbytes.lp_ptr
273 #define	ioc_rpbuf	_ioc_rpbuf.lp_ptr
274 #define	SMBIOC_RQ_COPYOUT_SIZE \
275 	(offsetof(smbioc_rq_t, _ioc_twords))
276 
277 
278 #define	SMBIOC_T2RQ_MAXNAME 128
279 
280 typedef struct smbioc_t2rq {
281 	uint16_t	ioc_setup[SMB_MAXSETUPWORDS];
282 	int32_t		ioc_setupcnt;
283 	char		ioc_name[SMBIOC_T2RQ_MAXNAME];
284 	ushort_t	ioc_tparamcnt;
285 	ushort_t	ioc_tdatacnt;
286 	ushort_t	ioc_rparamcnt;
287 	ushort_t	ioc_rdatacnt;
288 	uint8_t 	ioc__pad1;
289 	uint8_t 	ioc_errclass;
290 	uint16_t	ioc_serror;
291 	uint32_t	ioc_error;
292 	uint16_t	ioc_rpflags2;
293 	uint16_t	ioc__pad2;
294 	/*
295 	 * Copyout all but the pointers, which
296 	 * we may have set to kernel memory.
297 	 * See ..._COPYOUT_SIZE
298 	 */
299 	lptr_t		_ioc_tparam;
300 	lptr_t		_ioc_tdata;
301 	lptr_t		_ioc_rparam;
302 	lptr_t		_ioc_rdata;
303 } smbioc_t2rq_t;
304 #define	ioc_tparam	_ioc_tparam.lp_ptr
305 #define	ioc_tdata	_ioc_tdata.lp_ptr
306 #define	ioc_rparam	_ioc_rparam.lp_ptr
307 #define	ioc_rdata	_ioc_rdata.lp_ptr
308 #define	SMBIOC_T2RQ_COPYOUT_SIZE \
309 	(offsetof(smbioc_t2rq_t, _ioc_tparam))
310 
311 
312 typedef struct smbioc_flags {
313 	int32_t		ioc_level;	/* 0 - session, 1 - share */
314 	int32_t		ioc_mask;
315 	int32_t		ioc_flags;
316 } smbioc_flags_t;
317 
318 typedef struct smbioc_lookup {
319 	int32_t		ioc_level;
320 	int32_t		ioc_flags;
321 	struct smbioc_oshare	ioc_sh;
322 	struct smbioc_ossn	ioc_ssn;
323 } smbioc_lookup_t;
324 #define	SMBIOC_LOOK_COPYOUT_SIZE \
325 	(offsetof(smbioc_lookup_t, ioc_ssn._ioc_intok))
326 
327 typedef struct smbioc_rw {
328 	uint16_t	ioc_fh;
329 	uint32_t	ioc_cnt;
330 	lloff_t	_ioc_offset;
331 	lptr_t	_ioc_base;
332 } smbioc_rw_t;
333 #define	ioc_offset	_ioc_offset._f
334 #define	ioc_base	_ioc_base.lp_ptr
335 #define	SMBIOC_RW_COPYOUT_SIZE \
336 	(offsetof(smbioc_rw_t, _ioc_base))
337 
338 /* Password Keychain (PK) support. */
339 #define	SMBIOC_PK_MAXLEN 255
340 typedef struct smbioc_pk {
341 	uid_t	pk_uid;				/* UID for PAM use */
342 	char pk_dom[SMBIOC_PK_MAXLEN+1];	/* CIFS domain name */
343 	char pk_usr[SMBIOC_PK_MAXLEN+1];	/* CIFS user name */
344 	char pk_pass[SMBIOC_PK_MAXLEN+1];	/* CIFS password */
345 } smbioc_pk_t;
346 
347 
348 /*
349  * Device IOCTLs
350  *
351  * Define ioctl codes the way ZFS does.
352  * The "base" value is arbitrary, and can
353  * occupy the high word if we like, because
354  * our driver does its own copyin/copyout.
355  * Keep GETVERS first and use it to verify
356  * driver compatibility with the library.
357  */
358 #define	SMBIOC_BASE 	((('n' << 8) | 's') << 8)
359 typedef enum nsmb_ioc {
360 	SMBIOC_GETVERS = SMBIOC_BASE,
361 	SMBIOC_REQUEST,
362 	SMBIOC_T2RQ,
363 	SMBIOC_LOOKUP,
364 	SMBIOC_READ,
365 	SMBIOC_WRITE,
366 	SMBIOC_FINDVC,
367 	SMBIOC_NEGOTIATE,
368 	SMBIOC_SSNSETUP,
369 	SMBIOC_TCON,
370 	SMBIOC_TDIS,
371 	SMBIOC_FLAGS2,
372 	/* Password Keychain (PK) support. */
373 	SMBIOC_PK_ADD,    /* Add/Modify a password entry */
374 	SMBIOC_PK_CHK,    /* Check for a password entry */
375 	SMBIOC_PK_DEL,    /* Delete specified password entry */
376 	SMBIOC_PK_DEL_OWNER,	/* all owned by the caller */
377 	SMBIOC_PK_DEL_EVERYONE	/* all owned by everyone */
378 } nsmb_ioc_t;
379 
380 #ifdef _KERNEL
381 #include <sys/dditypes.h>	/* for dev_info_t */
382 
383 #define	SMBST_CONNECTED	1
384 
385 /* Size of storage for p/w hashes. */
386 #define	SMB_PWH_MAX	24
387 
388 extern const uint32_t nsmb_version;
389 
390 struct smb_cred;
391 struct smb_share;
392 struct smb_vc;
393 
394 typedef struct smb_dev {
395 	int		sd_opened;	/* Opened or not */
396 	int		sd_level;	/* Future use */
397 	struct smb_vc	*sd_vc;		/* Reference to VC */
398 	struct smb_share *sd_share;	/* Reference to share if any */
399 	int		sd_poll;	/* Future use */
400 	int		sd_seq;		/* Kind of minor number/instance no */
401 	int		sd_flags;	/* State of connection */
402 	zoneid_t	zoneid;		/* Zone id */
403 	dev_info_t	*smb_dip;	/* ptr to dev_info node */
404 	void		*sd_devfs;	/* Dont know how to use this. but */
405 	struct cred	*smb_cred;	/* per dev credentails. Future use */
406 } smb_dev_t;
407 
408 /*
409  * Compound user interface
410  */
411 int smb_usr_findvc(struct smbioc_lookup *dp, struct smb_cred *scred,
412 	struct smb_vc **vcpp);
413 int  smb_usr_negotiate(struct smbioc_lookup *dp, struct smb_cred *scred,
414 	struct smb_vc **vcpp);
415 int  smb_usr_ssnsetup(struct smbioc_lookup *dp, struct smb_cred *scred,
416 	struct smb_vc *vcp);
417 int  smb_usr_tcon(struct smbioc_lookup *dp, struct smb_cred *scred,
418 	struct smb_vc *vcp, struct smb_share **sspp);
419 int  smb_usr_simplerequest(struct smb_share *ssp, struct smbioc_rq *data,
420 	struct smb_cred *scred);
421 int  smb_usr_t2request(struct smb_share *ssp, struct smbioc_t2rq *data,
422 	struct smb_cred *scred);
423 int  smb_usr_rw(struct smb_share *ssp, smbioc_rw_t *dp,
424 	int cmd, struct smb_cred *scred);
425 int  smb_dev2share(int fd, struct smb_share **sspp);
426 
427 #endif /* _KERNEL */
428 #endif /* _NETSMB_DEV_H_ */
429