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