14bff34e3Sthurlow /* 24bff34e3Sthurlow * Copyright (c) 2000-2001 Boris Popov 34bff34e3Sthurlow * All rights reserved. 44bff34e3Sthurlow * 54bff34e3Sthurlow * Redistribution and use in source and binary forms, with or without 64bff34e3Sthurlow * modification, are permitted provided that the following conditions 74bff34e3Sthurlow * are met: 84bff34e3Sthurlow * 1. Redistributions of source code must retain the above copyright 94bff34e3Sthurlow * notice, this list of conditions and the following disclaimer. 104bff34e3Sthurlow * 2. Redistributions in binary form must reproduce the above copyright 114bff34e3Sthurlow * notice, this list of conditions and the following disclaimer in the 124bff34e3Sthurlow * documentation and/or other materials provided with the distribution. 134bff34e3Sthurlow * 3. All advertising materials mentioning features or use of this software 144bff34e3Sthurlow * must display the following acknowledgement: 154bff34e3Sthurlow * This product includes software developed by Boris Popov. 164bff34e3Sthurlow * 4. Neither the name of the author nor the names of any co-contributors 174bff34e3Sthurlow * may be used to endorse or promote products derived from this software 184bff34e3Sthurlow * without specific prior written permission. 194bff34e3Sthurlow * 204bff34e3Sthurlow * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 214bff34e3Sthurlow * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 224bff34e3Sthurlow * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 234bff34e3Sthurlow * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 244bff34e3Sthurlow * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 254bff34e3Sthurlow * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 264bff34e3Sthurlow * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 274bff34e3Sthurlow * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 284bff34e3Sthurlow * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 294bff34e3Sthurlow * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 304bff34e3Sthurlow * SUCH DAMAGE. 314bff34e3Sthurlow * 324bff34e3Sthurlow * $Id: smb_lib.h,v 1.21.82.2 2005/06/02 00:55:39 lindak Exp $ 334bff34e3Sthurlow */ 344bff34e3Sthurlow 359c9af259SGordon Ross /* 36a547be5dSGordon Ross * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 37*85e6b674SGordon Ross * Copyright 2013 Nexenta Systems, Inc. All rights reserved. 389c9af259SGordon Ross */ 399c9af259SGordon Ross 404bff34e3Sthurlow #ifndef _NETSMB_SMB_LIB_H_ 414bff34e3Sthurlow #define _NETSMB_SMB_LIB_H_ 424bff34e3Sthurlow 43613a2f6bSGordon Ross /* 44613a2f6bSGordon Ross * Internal interface exported to our commands in: 45613a2f6bSGordon Ross * usr/src/cmd/fs.d/smbclnt/ 46613a2f6bSGordon Ross */ 47613a2f6bSGordon Ross 484bff34e3Sthurlow #include <sys/types.h> 494bff34e3Sthurlow #include <sys/socket.h> 504bff34e3Sthurlow #include <netinet/in.h> 514bff34e3Sthurlow #include <arpa/inet.h> 524bff34e3Sthurlow #include <sys/byteorder.h> 534bff34e3Sthurlow 54613a2f6bSGordon Ross #include <netsmb/smbfs_api.h> 554bff34e3Sthurlow #include <netsmb/smb_dev.h> 564bff34e3Sthurlow 57613a2f6bSGordon Ross extern const char smbutil_std_opts[]; 58613a2f6bSGordon Ross #define STDPARAM_OPT smbutil_std_opts 594bff34e3Sthurlow 604bff34e3Sthurlow /* 614bff34e3Sthurlow * bits to indicate the source of error 624bff34e3Sthurlow */ 634bff34e3Sthurlow #define SMB_ERRTYPE_MASK 0xf0000 644bff34e3Sthurlow #define SMB_SYS_ERROR 0x00000 654bff34e3Sthurlow #define SMB_RAP_ERROR 0x10000 664bff34e3Sthurlow #define SMB_NB_ERROR 0x20000 674bff34e3Sthurlow 684bff34e3Sthurlow /* 69613a2f6bSGordon Ross * Size of all LM/NTLM hashes (16 bytes). 70613a2f6bSGordon Ross * The driver needs to know this, so it's 71613a2f6bSGordon Ross * defined by smb_dev.h 72613a2f6bSGordon Ross */ 73613a2f6bSGordon Ross #define NTLM_HASH_SZ SMBIOC_HASH_SZ 74613a2f6bSGordon Ross #define NTLM_CHAL_SZ 8 /* challenge size */ 75613a2f6bSGordon Ross 76613a2f6bSGordon Ross /* 77613a2f6bSGordon Ross * This is what goes across the door call to the IOD 78613a2f6bSGordon Ross * when asking for a new connection. 79613a2f6bSGordon Ross */ 80613a2f6bSGordon Ross struct smb_iod_ssn { 81613a2f6bSGordon Ross struct smbioc_ossn iod_ossn; 82613a2f6bSGordon Ross int iod_authflags; /* SMB_AT_x */ 83613a2f6bSGordon Ross uchar_t iod_nthash[NTLM_HASH_SZ]; 84613a2f6bSGordon Ross uchar_t iod_lmhash[NTLM_HASH_SZ]; 85613a2f6bSGordon Ross /* Kerberos cred. cache res. name? */ 86613a2f6bSGordon Ross }; 87613a2f6bSGordon Ross typedef struct smb_iod_ssn smb_iod_ssn_t; 88613a2f6bSGordon Ross 89613a2f6bSGordon Ross 90613a2f6bSGordon Ross /* 914bff34e3Sthurlow * SMB work context. Used to store all values which are necessary 924bff34e3Sthurlow * to establish connection to an SMB server. 934bff34e3Sthurlow */ 944bff34e3Sthurlow struct smb_ctx { 954bff34e3Sthurlow int ct_flags; /* SMBCF_ */ 96613a2f6bSGordon Ross int ct_dev_fd; /* device handle */ 976b2bcd8eSGordon Ross int ct_door_fd; /* to smbiod */ 984bff34e3Sthurlow int ct_parsedlevel; 994bff34e3Sthurlow int ct_minlevel; 1004bff34e3Sthurlow int ct_maxlevel; 101613a2f6bSGordon Ross char *ct_fullserver; /* orig. server name from cmd line */ 102613a2f6bSGordon Ross char *ct_srvaddr_s; /* hostname or IP address of server */ 103613a2f6bSGordon Ross struct addrinfo *ct_addrinfo; /* IP addresses of the server */ 104613a2f6bSGordon Ross struct nb_ctx *ct_nb; /* NetBIOS info. */ 105613a2f6bSGordon Ross char *ct_locname; /* local (machine) name */ 106613a2f6bSGordon Ross smb_iod_ssn_t ct_iod_ssn; 107613a2f6bSGordon Ross /* smbioc_oshare_t ct_sh; XXX */ 108613a2f6bSGordon Ross int ct_minauth; 109613a2f6bSGordon Ross int ct_shtype_req; /* share type wanted */ 1104bff34e3Sthurlow char *ct_origshare; 1114bff34e3Sthurlow char *ct_home; 112430b4c46SGordon Ross char *ct_rpath; /* remote file name */ 1134bff34e3Sthurlow 114613a2f6bSGordon Ross /* Connection setup SMB stuff. */ 115613a2f6bSGordon Ross /* Strings from the SMB negotiate response. */ 116613a2f6bSGordon Ross char *ct_srv_OS; 117613a2f6bSGordon Ross char *ct_srv_LM; 118*85e6b674SGordon Ross uint32_t ct_clnt_caps; 119613a2f6bSGordon Ross 120613a2f6bSGordon Ross /* NTLM auth. stuff */ 121613a2f6bSGordon Ross uchar_t ct_clnonce[NTLM_CHAL_SZ]; 122*85e6b674SGordon Ross uchar_t ct_srv_chal[NTLM_CHAL_SZ]; 123613a2f6bSGordon Ross char ct_password[SMBIOC_MAX_NAME]; 124613a2f6bSGordon Ross 125613a2f6bSGordon Ross /* See ssp.c */ 126613a2f6bSGordon Ross void *ct_ssp_ctx; 127613a2f6bSGordon Ross smbioc_ssn_work_t ct_work; 128613a2f6bSGordon Ross }; 129613a2f6bSGordon Ross 130613a2f6bSGordon Ross 131613a2f6bSGordon Ross /* 132613a2f6bSGordon Ross * Short-hand for some of the substruct fields above 133613a2f6bSGordon Ross */ 134613a2f6bSGordon Ross #define ct_ssn ct_iod_ssn.iod_ossn 135613a2f6bSGordon Ross #define ct_vopt ct_iod_ssn.iod_ossn.ssn_vopt 136613a2f6bSGordon Ross #define ct_owner ct_iod_ssn.iod_ossn.ssn_owner 137613a2f6bSGordon Ross #define ct_srvaddr ct_iod_ssn.iod_ossn.ssn_srvaddr 138613a2f6bSGordon Ross #define ct_domain ct_iod_ssn.iod_ossn.ssn_domain 139613a2f6bSGordon Ross #define ct_user ct_iod_ssn.iod_ossn.ssn_user 140613a2f6bSGordon Ross #define ct_srvname ct_iod_ssn.iod_ossn.ssn_srvname 141613a2f6bSGordon Ross #define ct_authflags ct_iod_ssn.iod_authflags 142613a2f6bSGordon Ross #define ct_nthash ct_iod_ssn.iod_nthash 143613a2f6bSGordon Ross #define ct_lmhash ct_iod_ssn.iod_lmhash 144613a2f6bSGordon Ross 145613a2f6bSGordon Ross #define ct_sopt ct_work.wk_sopt 146613a2f6bSGordon Ross #define ct_iods ct_work.wk_iods 147613a2f6bSGordon Ross #define ct_tran_fd ct_work.wk_iods.is_tran_fd 148613a2f6bSGordon Ross #define ct_hflags ct_work.wk_iods.is_hflags 149613a2f6bSGordon Ross #define ct_hflags2 ct_work.wk_iods.is_hflags2 150613a2f6bSGordon Ross #define ct_vcflags ct_work.wk_iods.is_vcflags 151613a2f6bSGordon Ross #define ct_ssn_key ct_work.wk_iods.is_ssn_key 152613a2f6bSGordon Ross #define ct_mac_seqno ct_work.wk_iods.is_next_seq 153613a2f6bSGordon Ross #define ct_mackeylen ct_work.wk_iods.is_u_maclen 154613a2f6bSGordon Ross #define ct_mackey ct_work.wk_iods.is_u_mackey.lp_ptr 155613a2f6bSGordon Ross 156613a2f6bSGordon Ross 157613a2f6bSGordon Ross /* 158613a2f6bSGordon Ross * Bits in smb_ctx_t.ct_flags 159613a2f6bSGordon Ross */ 1604bff34e3Sthurlow #define SMBCF_NOPWD 0x0001 /* don't ask for a password */ 1614bff34e3Sthurlow #define SMBCF_SRIGHTS 0x0002 /* share access rights supplied */ 1624bff34e3Sthurlow #define SMBCF_LOCALE 0x0004 /* use current locale */ 1634bff34e3Sthurlow #define SMBCF_CMD_DOM 0x0010 /* CMD specified domain */ 1644bff34e3Sthurlow #define SMBCF_CMD_USR 0x0020 /* CMD specified user */ 1654bff34e3Sthurlow #define SMBCF_CMD_PW 0x0040 /* CMD specified password */ 1664bff34e3Sthurlow #define SMBCF_RESOLVED 0x8000 /* structure has been verified */ 1674bff34e3Sthurlow #define SMBCF_KCBAD 0x00080000 /* keychain password failed */ 1684bff34e3Sthurlow #define SMBCF_KCFOUND 0x00100000 /* password is from keychain */ 1694bff34e3Sthurlow #define SMBCF_BROWSEOK 0x00200000 /* browser dialogue may be used */ 1704bff34e3Sthurlow #define SMBCF_AUTHREQ 0x00400000 /* auth. dialog requested */ 1714bff34e3Sthurlow #define SMBCF_KCSAVE 0x00800000 /* add to keychain requested */ 1724bff34e3Sthurlow #define SMBCF_XXX 0x01000000 /* mount-all, a very bad thing */ 1734bff34e3Sthurlow #define SMBCF_SSNACTIVE 0x02000000 /* session setup succeeded */ 1744bff34e3Sthurlow #define SMBCF_KCDOMAIN 0x04000000 /* use domain in KC lookup */ 1754bff34e3Sthurlow 1764bff34e3Sthurlow 1774bff34e3Sthurlow /* 1784bff34e3Sthurlow * Context management 1794bff34e3Sthurlow */ 180613a2f6bSGordon Ross 181613a2f6bSGordon Ross int smb_ctx_init(struct smb_ctx *); 1824bff34e3Sthurlow void smb_ctx_done(struct smb_ctx *); 183613a2f6bSGordon Ross int smb_open_driver(void); 1844bff34e3Sthurlow 185613a2f6bSGordon Ross int smb_ctx_gethandle(struct smb_ctx *); 186613a2f6bSGordon Ross int smb_ctx_findvc(struct smb_ctx *); 187613a2f6bSGordon Ross int smb_ctx_newvc(struct smb_ctx *); 1884bff34e3Sthurlow 189613a2f6bSGordon Ross /* 190613a2f6bSGordon Ross * I/O daemon stuff 191613a2f6bSGordon Ross */ 1924bff34e3Sthurlow 193a547be5dSGordon Ross #define SMBIOD_RUNDIR "/var/run/smbiod" 194a547be5dSGordon Ross #define SMBIOD_SVC_DOOR SMBIOD_RUNDIR "/.svc" 195a547be5dSGordon Ross #define SMBIOD_USR_DOOR SMBIOD_RUNDIR "/%d" 196a547be5dSGordon Ross #define SMBIOD_START 1 197a547be5dSGordon Ross 198613a2f6bSGordon Ross int smb_iod_cl_newvc(smb_ctx_t *ctx); 199613a2f6bSGordon Ross char *smb_iod_door_path(void); 200613a2f6bSGordon Ross int smb_iod_open_door(int *); 201613a2f6bSGordon Ross int smb_iod_connect(struct smb_ctx *); 202613a2f6bSGordon Ross int smb_iod_work(struct smb_ctx *); 203613a2f6bSGordon Ross 204613a2f6bSGordon Ross /* 205613a2f6bSGordon Ross * Other stuff 206613a2f6bSGordon Ross */ 207613a2f6bSGordon Ross 208613a2f6bSGordon Ross int smb_open_rcfile(char *); 209613a2f6bSGordon Ross void smb_close_rcfile(void); 2104bff34e3Sthurlow 2114bff34e3Sthurlow void smb_simplecrypt(char *dst, const char *src); 2124bff34e3Sthurlow int smb_simpledecrypt(char *dst, const char *src); 2134bff34e3Sthurlow 2144bff34e3Sthurlow int nls_setrecode(const char *, const char *); 2154bff34e3Sthurlow int nls_setlocale(const char *); 2164bff34e3Sthurlow char *nls_str_toext(char *, const char *); 2174bff34e3Sthurlow char *nls_str_toloc(char *, const char *); 2184bff34e3Sthurlow void *nls_mem_toext(void *, const void *, int); 2194bff34e3Sthurlow void *nls_mem_toloc(void *, const void *, int); 2204bff34e3Sthurlow char *nls_str_upper(char *, const char *); 2214bff34e3Sthurlow char *nls_str_lower(char *, const char *); 2224bff34e3Sthurlow 2234bff34e3Sthurlow char *smb_getprogname(); 2244bff34e3Sthurlow #define __progname smb_getprogname() 2254bff34e3Sthurlow 2264bff34e3Sthurlow #endif /* _NETSMB_SMB_LIB_H_ */ 227