Home | History | Annotate | Download | only in netsmb
      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 
     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 #include <sys/types.h>
     63 #include <sys/socket_impl.h>
     64 #include <netinet/in.h>
     65 
     66 #define	NSMB_NAME		"nsmb"
     67 
     68 /*
     69  * Update NSMB_VER* if any of the ioctl codes and/or
     70  * associated structures change in ways that would
     71  * make them incompatible with an old driver.
     72  */
     73 #define	NSMB_VERMAJ	1
     74 #define	NSMB_VERMIN	3900
     75 #define	NSMB_VERSION	(NSMB_VERMAJ * 100000 + NSMB_VERMIN)
     76 
     77 /*
     78  * Some errno values we need to expose to the library.
     79  * NB: these are also defined in the library smbfs_api.h
     80  * to avoid exposing all of this stuff in that API.
     81  *
     82  * EBADRPC is used for message decoding errors.
     83  * EAUTH is used for CIFS authentication errors.
     84  */
     85 #ifndef EBADRPC
     86 #define	EBADRPC 	113
     87 #endif
     88 #ifndef EAUTH
     89 #define	EAUTH		114
     90 #endif
     91 
     92 /*
     93  * Upper/lower case options
     94  */
     95 #define	SMB_CS_NONE	0x0000
     96 #define	SMB_CS_UPPER	0x0001	/* convert passed string to upper case */
     97 #define	SMB_CS_LOWER	0x0002	/* convert passed string to lower case */
     98 
     99 /*
    100  * access mode stuff (see also smb_lib.h)
    101  */
    102 #define	SMBM_ANY_OWNER		((uid_t)-1)
    103 #define	SMBM_ANY_GROUP		((gid_t)-1)
    104 
    105 /*
    106  * Option flags in smbioc_ossn.ioc_opt
    107  * and vcspec.optflags
    108  */
    109 #define	SMBVOPT_CREATE		0x0001	/* create object if necessary */
    110 #define	SMBVOPT_PRIVATE		0x0002	/* connection should be private */
    111 #define	SMBVOPT_SINGLESHARE	0x0004	/* keep only one share at this VC */
    112 #define	SMBVOPT_PERMANENT	0x0010	/* object will keep last reference */
    113 #define	SMBVOPT_EXT_SEC		0x0020	/* extended security negotiation */
    114 #define	SMBVOPT_USE_KEYCHAIN	0x0040	/* get p/w from keychain */
    115 #define	SMBVOPT_KC_DOMAIN	0x0080	/* keychain lookup uses domain */
    116 
    117 #define	SMBVOPT_SIGNING_ENABLED		0x0100	/* sign if server agrees */
    118 #define	SMBVOPT_SIGNING_REQUIRED	0x0200	/* signing required */
    119 #define	SMBVOPT_SIGNING_MASK		0x0300	/* all signing bits */
    120 
    121 /*
    122  * Option flags in smbioc_oshare.ioc_opt
    123  * and sharespec.optflags
    124  */
    125 #define	SMBSOPT_CREATE		SMBVOPT_CREATE
    126 #define	SMBSOPT_PERMANENT	SMBVOPT_PERMANENT
    127 
    128 /* All user and machine names. */
    129 #define	SMBIOC_MAX_NAME		256
    130 
    131 /*
    132  * Size of storage for p/w hashes.
    133  * Also for SMBIOC_GETSSNKEY.
    134  */
    135 #define	SMBIOC_HASH_SZ	16
    136 
    137 /*
    138  * network IO daemon states
    139  * really connection states.
    140  */
    141 enum smbiod_state {
    142 	SMBIOD_ST_IDLE = 0,	/* no user requests enqueued yet */
    143 	SMBIOD_ST_RECONNECT,	/* a [re]connect attempt is in progress */
    144 	SMBIOD_ST_RCFAILED,	/* a reconnect attempt has failed */
    145 	SMBIOD_ST_VCACTIVE,	/* session established */
    146 	SMBIOD_ST_DEAD		/* connection gone, no IOD */
    147 };
    148 
    149 
    150 /*
    151  * We're now using structures that are invariant
    152  * across 32-bit vs 64-bit compilers for all
    153  * member sizes and offsets.  Scalar members
    154  * simply have to use fixed-size types.
    155  * Pointers are a little harder...
    156  * We use this union for all pointers that
    157  * must pass between user and kernel.
    158  */
    159 typedef union lptr {
    160 	uint64_t lp_ll;
    161 #ifdef _LP64
    162 	void	*lp_ptr;
    163 #endif
    164 #ifdef _ILP32
    165 	void	*_lp_p2[2];
    166 #ifdef _LITTLE_ENDIAN
    167 #define	lp_ptr	_lp_p2[0]
    168 #define	lp_pad	_lp_p2[1]
    169 #else /* _ENDIAN */
    170 #define	lp_pad	_lp_p2[0]
    171 #define	lp_ptr	_lp_p2[1]
    172 #endif /* _ENDIAN */
    173 #endif /* _ILP32 */
    174 } lptr_t;
    175 
    176 /*
    177  * Handy union of sockaddr types we use.
    178  * Type discriminator is sa_family
    179  */
    180 union smbioc_sockaddr {
    181 	struct sockaddr sa;	/* generic */
    182 	struct sockaddr_in sin;
    183 	struct sockaddr_in6 sin6;
    184 };
    185 typedef union smbioc_sockaddr smbioc_sockaddr_t;
    186 
    187 /*
    188  * This is what identifies a session.
    189  */
    190 struct smbioc_ssn_ident {
    191 	smbioc_sockaddr_t id_srvaddr;
    192 	char		id_domain[SMBIOC_MAX_NAME];
    193 	char		id_user[SMBIOC_MAX_NAME];
    194 };
    195 typedef struct smbioc_ssn_ident smbioc_ssn_ident_t;
    196 
    197 /*
    198  * Flags for smbioc_ossn.ssn_opt
    199  */
    200 #define	SMBLK_CREATE		SMBVOPT_CREATE
    201 
    202 /*
    203  * Structure used with SMBIOC_SSN_FIND, _CREATE
    204  */
    205 struct smbioc_ossn {
    206 	uint32_t		ssn_vopt;	/* i.e. SMBVOPT_CREATE */
    207 	uint32_t		ssn_owner;	/* Unix owner (UID) */
    208 	smbioc_ssn_ident_t	ssn_id;
    209 	char			ssn_srvname[SMBIOC_MAX_NAME];
    210 };
    211 typedef struct smbioc_ossn smbioc_ossn_t;
    212 /* Convenience names for members under ssn_id */
    213 #define	ssn_srvaddr	ssn_id.id_srvaddr
    214 #define	ssn_domain	ssn_id.id_domain
    215 #define	ssn_user	ssn_id.id_user
    216 
    217 /*
    218  * Structure used with SMBIOC_TREE_FIND, _CONNECT
    219  */
    220 #define	SMBIOC_STYPE_LEN	8
    221 struct smbioc_oshare {
    222 	uint32_t	sh_pwlen;
    223 	char		sh_name[SMBIOC_MAX_NAME];
    224 	char		sh_pass[SMBIOC_MAX_NAME];
    225 	/* share types, in ASCII form, i.e. "A:", "IPC", ... */
    226 	char		sh_type_req[SMBIOC_STYPE_LEN];	/* requested */
    227 	char		sh_type_ret[SMBIOC_STYPE_LEN];	/* returned */
    228 };
    229 typedef struct smbioc_oshare smbioc_oshare_t;
    230 
    231 typedef struct smbioc_tcon {
    232 	int32_t		tc_flags;
    233 	int32_t		tc_opt;
    234 	smbioc_oshare_t	tc_sh;
    235 } smbioc_tcon_t;
    236 
    237 
    238 /*
    239  * Negotiated protocol parameters
    240  */
    241 struct smb_sopt {
    242 	int16_t		sv_proto;	/* protocol dialect */
    243 	uchar_t		sv_sm;		/* security mode */
    244 	int16_t		sv_tz;		/* offset in min relative to UTC */
    245 	uint16_t	sv_maxmux;	/* max number of outstanding rq's */
    246 	uint16_t 	sv_maxvcs;	/* max number of VCs */
    247 	uint16_t	sv_rawmode;
    248 	uint32_t	sv_maxtx;	/* maximum transmit buf size */
    249 	uint32_t	sv_maxraw;	/* maximum raw-buffer size */
    250 	uint32_t	sv_skey;	/* session key */
    251 	uint32_t	sv_caps;	/* capabilites SMB_CAP_ */
    252 };
    253 typedef struct smb_sopt smb_sopt_t;
    254 
    255 /*
    256  * State carried in/out of the driver by the IOD thread.
    257  * Inside the driver, these are members of the "VC" object.
    258  */
    259 struct smb_iods {
    260 	int32_t		is_tran_fd;	/* transport FD */
    261 	uint32_t	is_vcflags;	/* SMBV_... */
    262 	uint8_t 	is_hflags;	/* SMB header flags */
    263 	uint16_t	is_hflags2;	/* SMB header flags2 */
    264 	uint16_t	is_smbuid;	/* SMB header UID */
    265 	uint16_t	is_next_mid;	/* SMB header MID */
    266 	uint32_t	is_txmax;	/* max tx/rx packet size */
    267 	uint32_t	is_rwmax;	/* max read/write data size */
    268 	uint32_t	is_rxmax;	/* max readx data size */
    269 	uint32_t	is_wxmax;	/* max writex data size */
    270 	uint8_t		is_ssn_key[SMBIOC_HASH_SZ]; /* session key */
    271 	/* Signing state */
    272 	uint32_t	is_next_seq;	/* my next sequence number */
    273 	uint32_t	is_u_maclen;	/* MAC key length */
    274 	lptr_t		is_u_mackey;	/* user-space ptr! */
    275 };
    276 typedef struct smb_iods smb_iods_t;
    277 
    278 /*
    279  * This is the operational state information passed
    280  * in and out of the driver for SMBIOC_SSN_WORK
    281  */
    282 struct smbioc_ssn_work {
    283 	smb_iods_t	wk_iods;
    284 	smb_sopt_t	wk_sopt;
    285 	int		wk_out_state;
    286 };
    287 typedef struct smbioc_ssn_work smbioc_ssn_work_t;
    288 
    289 /*
    290  * User-level SMB requests
    291  */
    292 
    293 /*
    294  * SMBIOC_REQUEST (simple SMB request)
    295  */
    296 typedef struct smbioc_rq {
    297 	uchar_t		ioc_cmd;
    298 	uint8_t 	ioc_errclass;
    299 	uint16_t	ioc_serror;
    300 	uint32_t	ioc_error;
    301 	uint32_t	ioc_tbufsz;	/* transmit */
    302 	uint32_t	ioc_rbufsz;	/* receive */
    303 	lptr_t		_ioc_tbuf;
    304 	lptr_t		_ioc_rbuf;
    305 } smbioc_rq_t;
    306 #define	ioc_tbuf	_ioc_tbuf.lp_ptr
    307 #define	ioc_rbuf	_ioc_rbuf.lp_ptr
    308 
    309 
    310 #define	SMBIOC_T2RQ_MAXSETUP	4
    311 #define	SMBIOC_T2RQ_MAXNAME	128
    312 
    313 typedef struct smbioc_t2rq {
    314 	uint16_t	ioc_setup[SMBIOC_T2RQ_MAXSETUP];
    315 	int32_t		ioc_setupcnt;
    316 	char		ioc_name[SMBIOC_T2RQ_MAXNAME];
    317 	ushort_t	ioc_tparamcnt;
    318 	ushort_t	ioc_tdatacnt;
    319 	ushort_t	ioc_rparamcnt;
    320 	ushort_t	ioc_rdatacnt;
    321 	uint8_t 	ioc__pad1;
    322 	uint8_t 	ioc_errclass;
    323 	uint16_t	ioc_serror;
    324 	uint32_t	ioc_error;
    325 	uint16_t	ioc_rpflags2;
    326 	uint16_t	ioc__pad2;
    327 	lptr_t		_ioc_tparam;
    328 	lptr_t		_ioc_tdata;
    329 	lptr_t		_ioc_rparam;
    330 	lptr_t		_ioc_rdata;
    331 } smbioc_t2rq_t;
    332 #define	ioc_tparam	_ioc_tparam.lp_ptr
    333 #define	ioc_tdata	_ioc_tdata.lp_ptr
    334 #define	ioc_rparam	_ioc_rparam.lp_ptr
    335 #define	ioc_rdata	_ioc_rdata.lp_ptr
    336 
    337 
    338 typedef struct smbioc_flags {
    339 	int32_t		ioc_level;	/* 0 - session, 1 - share */
    340 	int32_t		ioc_flags;
    341 	int32_t		ioc_mask;
    342 } smbioc_flags_t;
    343 
    344 typedef struct smbioc_rw {
    345 	uint32_t	ioc_fh;
    346 	uint32_t	ioc_cnt;
    347 	lloff_t	_ioc_offset;
    348 	lptr_t	_ioc_base;
    349 } smbioc_rw_t;
    350 #define	ioc_offset	_ioc_offset._f
    351 #define	ioc_base	_ioc_base.lp_ptr
    352 
    353 /* Password Keychain (PK) support. */
    354 typedef struct smbioc_pk {
    355 	uid_t	pk_uid;				/* UID for PAM use */
    356 	char pk_dom[SMBIOC_MAX_NAME];		/* CIFS domain name */
    357 	char pk_usr[SMBIOC_MAX_NAME];		/* CIFS user name */
    358 	uchar_t pk_lmhash[SMBIOC_HASH_SZ];	/* LanMan p/w hash */
    359 	uchar_t pk_nthash[SMBIOC_HASH_SZ];	/* NTLM p/w hash */
    360 } smbioc_pk_t;
    361 
    362 
    363 /*
    364  * Device IOCTLs
    365  *
    366  * Define ioctl codes the way ZFS does.
    367  * The "base" value is arbitrary, and can
    368  * occupy the high word if we like, because
    369  * our driver does its own copyin/copyout.
    370  * Keep GETVERS first and use it to verify
    371  * driver compatibility with the library.
    372  */
    373 #define	SMBIOC_BASE 	((('n' << 8) | 's') << 8)
    374 typedef enum nsmb_ioc {
    375 	SMBIOC_GETVERS = SMBIOC_BASE,	/* keep first */
    376 	SMBIOC_FLAGS2,		/* get hflags2 */
    377 	SMBIOC_GETSSNKEY,	/* get SMB session key */
    378 
    379 	SMBIOC_REQUEST,		/* simple request */
    380 	SMBIOC_T2RQ,		/* trans2 request */
    381 	SMBIOC_READ,		/* read (pipe) */
    382 	SMBIOC_WRITE,		/* write (pipe) */
    383 
    384 	SMBIOC_SSN_CREATE,
    385 	SMBIOC_SSN_FIND,
    386 	SMBIOC_SSN_KILL,	/* force disconnect */
    387 	SMBIOC_SSN_RELE,	/* drop our reference */
    388 
    389 	SMBIOC_TREE_CONNECT,	/* create and connect */
    390 	SMBIOC_TREE_FIND,
    391 	SMBIOC_TREE_KILL,
    392 	SMBIOC_TREE_RELE,
    393 
    394 	SMBIOC_IOD_WORK,	/* work on session requests */
    395 	SMBIOC_IOD_IDLE,	/* wait for requests on this session */
    396 	SMBIOC_IOD_RCFAIL,	/* notify that reconnect failed */
    397 
    398 	/* Password Keychain (PK) support. */
    399 	SMBIOC_PK_ADD,    /* Add/Modify a password entry */
    400 	SMBIOC_PK_CHK,    /* Check for a password entry */
    401 	SMBIOC_PK_DEL,    /* Delete specified password entry */
    402 	SMBIOC_PK_DEL_OWNER,	/* all owned by the caller */
    403 	SMBIOC_PK_DEL_EVERYONE	/* all owned by everyone */
    404 } nsmb_ioc_t;
    405 
    406 #endif /* _NETSMB_DEV_H_ */
    407