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