19c9af259SGordon Ross /* 29c9af259SGordon Ross * Copyright (c) 2000-2001 Boris Popov 39c9af259SGordon Ross * All rights reserved. 49c9af259SGordon Ross * 59c9af259SGordon Ross * Redistribution and use in source and binary forms, with or without 69c9af259SGordon Ross * modification, are permitted provided that the following conditions 79c9af259SGordon Ross * are met: 89c9af259SGordon Ross * 1. Redistributions of source code must retain the above copyright 99c9af259SGordon Ross * notice, this list of conditions and the following disclaimer. 109c9af259SGordon Ross * 2. Redistributions in binary form must reproduce the above copyright 119c9af259SGordon Ross * notice, this list of conditions and the following disclaimer in the 129c9af259SGordon Ross * documentation and/or other materials provided with the distribution. 139c9af259SGordon Ross * 3. All advertising materials mentioning features or use of this software 149c9af259SGordon Ross * must display the following acknowledgement: 159c9af259SGordon Ross * This product includes software developed by Boris Popov. 169c9af259SGordon Ross * 4. Neither the name of the author nor the names of any co-contributors 179c9af259SGordon Ross * may be used to endorse or promote products derived from this software 189c9af259SGordon Ross * without specific prior written permission. 199c9af259SGordon Ross * 209c9af259SGordon Ross * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 219c9af259SGordon Ross * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 229c9af259SGordon Ross * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 239c9af259SGordon Ross * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 249c9af259SGordon Ross * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 259c9af259SGordon Ross * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 269c9af259SGordon Ross * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 279c9af259SGordon Ross * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 289c9af259SGordon Ross * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 299c9af259SGordon Ross * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 309c9af259SGordon Ross * SUCH DAMAGE. 319c9af259SGordon Ross */ 329c9af259SGordon Ross 339c9af259SGordon Ross /* 34613a2f6bSGordon Ross * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 359c9af259SGordon Ross * Use is subject to license terms. 369c9af259SGordon Ross */ 379c9af259SGordon Ross 389c9af259SGordon Ross #ifndef _PRIVATE_H 399c9af259SGordon Ross #define _PRIVATE_H 409c9af259SGordon Ross 419c9af259SGordon Ross /* 429c9af259SGordon Ross * Private declarations for this library. 439c9af259SGordon Ross * Moved from smb_lib.h 449c9af259SGordon Ross */ 459c9af259SGordon Ross 469c9af259SGordon Ross #include <inttypes.h> 47613a2f6bSGordon Ross #include <sys/byteorder.h> 48613a2f6bSGordon Ross #include <sys/ccompile.h> 49613a2f6bSGordon Ross 50*02d09e03SGordon Ross #include <netsmb/mchain.h> 51613a2f6bSGordon Ross #include <netsmb/netbios.h> 52613a2f6bSGordon Ross 53613a2f6bSGordon Ross extern void dprint(const char *, const char *, ...) 54613a2f6bSGordon Ross __PRINTFLIKE(2); 55613a2f6bSGordon Ross 56613a2f6bSGordon Ross #if defined(DEBUG) || defined(__lint) 57613a2f6bSGordon Ross #define DPRINT(...) dprint(__func__, __VA_ARGS__) 58613a2f6bSGordon Ross #else 59613a2f6bSGordon Ross #define DPRINT(...) ((void)0) 60613a2f6bSGordon Ross #endif 61613a2f6bSGordon Ross 62613a2f6bSGordon Ross /* 63613a2f6bSGordon Ross * Flags bits in ct_vcflags (copied from smb_conn.h) 64613a2f6bSGordon Ross * Pass these to the driver? 65613a2f6bSGordon Ross */ 66613a2f6bSGordon Ross #define SMBV_RECONNECTING 0x0002 /* conn in process of reconnection */ 67613a2f6bSGordon Ross #define SMBV_LONGNAMES 0x0004 /* conn configured to use long names */ 68613a2f6bSGordon Ross #define SMBV_ENCRYPT 0x0008 /* server demands encrypted password */ 69613a2f6bSGordon Ross #define SMBV_WIN95 0x0010 /* used to apply bugfixes for this OS */ 70613a2f6bSGordon Ross #define SMBV_NT4 0x0020 /* used when NT4 issues invalid resp */ 71613a2f6bSGordon Ross #define SMBV_UNICODE 0x0040 /* conn configured to use Unicode */ 72613a2f6bSGordon Ross #define SMBV_EXT_SEC 0x0080 /* conn to use extended security */ 73613a2f6bSGordon Ross #define SMBV_WILL_SIGN 0x0100 /* negotiated signing */ 74613a2f6bSGordon Ross 759c9af259SGordon Ross /* 769c9af259SGordon Ross * request handling structures 779c9af259SGordon Ross */ 789c9af259SGordon Ross struct smb_rq { 79613a2f6bSGordon Ross struct smb_ctx *rq_ctx; 809c9af259SGordon Ross struct mbdata rq_rq; 819c9af259SGordon Ross struct mbdata rq_rp; 82613a2f6bSGordon Ross int rq_rpbufsz; 83613a2f6bSGordon Ross uint8_t rq_cmd; 84613a2f6bSGordon Ross uint8_t rq_hflags; 85613a2f6bSGordon Ross uint16_t rq_hflags2; 86613a2f6bSGordon Ross uint32_t rq_status; 87613a2f6bSGordon Ross uint16_t rq_uid; 88613a2f6bSGordon Ross uint16_t rq_tid; 89613a2f6bSGordon Ross uint16_t rq_mid; 90613a2f6bSGordon Ross uint32_t rq_seqno; 91613a2f6bSGordon Ross /* See rq_[bw]{start,end} functions */ 92613a2f6bSGordon Ross char *rq_wcntp; 93613a2f6bSGordon Ross int rq_wcbase; 94613a2f6bSGordon Ross char *rq_bcntp; 95613a2f6bSGordon Ross int rq_bcbase; 969c9af259SGordon Ross }; 979c9af259SGordon Ross typedef struct smb_rq smb_rq_t; 989c9af259SGordon Ross 999c9af259SGordon Ross #define smb_rq_getrequest(rqp) (&(rqp)->rq_rq) 1009c9af259SGordon Ross #define smb_rq_getreply(rqp) (&(rqp)->rq_rp) 1019c9af259SGordon Ross 102613a2f6bSGordon Ross int smb_rq_init(struct smb_ctx *, uchar_t, struct smb_rq **); 1039c9af259SGordon Ross void smb_rq_done(struct smb_rq *); 104613a2f6bSGordon Ross void smb_rq_bstart(struct smb_rq *); 105613a2f6bSGordon Ross void smb_rq_bend(struct smb_rq *); 106613a2f6bSGordon Ross void smb_rq_wstart(struct smb_rq *); 1079c9af259SGordon Ross void smb_rq_wend(struct smb_rq *); 1089c9af259SGordon Ross int smb_rq_simple(struct smb_rq *); 1099c9af259SGordon Ross int smb_rq_dmem(struct mbdata *, const char *, size_t); 110613a2f6bSGordon Ross int smb_rq_internal(struct smb_ctx *, struct smb_rq *); 111*02d09e03SGordon Ross void smb_rq_sign(struct smb_rq *); 112613a2f6bSGordon Ross int smb_rq_verify(struct smb_rq *); 1139c9af259SGordon Ross 1149c9af259SGordon Ross /* 115*02d09e03SGordon Ross * This library extends the mchain.h function set a little. 1169c9af259SGordon Ross */ 117*02d09e03SGordon Ross int m_getm(struct mbuf *, int, struct mbuf **); 1189c9af259SGordon Ross int m_lineup(struct mbuf *, struct mbuf **); 119613a2f6bSGordon Ross size_t m_totlen(struct mbuf *); 120613a2f6bSGordon Ross 121*02d09e03SGordon Ross int mb_init_sz(struct mbdata *, int); 122*02d09e03SGordon Ross int mb_fit(struct mbdata *mbp, int size, char **pp); 123*02d09e03SGordon Ross 124*02d09e03SGordon Ross int mb_put_string(struct mbdata *mbp, const char *s, int); 125613a2f6bSGordon Ross int mb_put_astring(struct mbdata *mbp, const char *s); 126613a2f6bSGordon Ross int mb_put_ustring(struct mbdata *mbp, const char *s); 1279c9af259SGordon Ross 128*02d09e03SGordon Ross int md_get_string(struct mbdata *, char **, int); 129*02d09e03SGordon Ross int md_get_astring(struct mbdata *, char **); 130*02d09e03SGordon Ross int md_get_ustring(struct mbdata *, char **); 1319c9af259SGordon Ross 1329c9af259SGordon Ross /* 1339c9af259SGordon Ross * Network stuff (NetBIOS and otherwise) 1349c9af259SGordon Ross */ 135613a2f6bSGordon Ross struct nb_name; 136613a2f6bSGordon Ross struct sockaddr_nb; 137613a2f6bSGordon Ross 138613a2f6bSGordon Ross extern int smb_recv_timeout; /* seconds */ 139613a2f6bSGordon Ross 140613a2f6bSGordon Ross void dump_ctx(char *, struct smb_ctx *); 141613a2f6bSGordon Ross void dump_addrinfo(struct addrinfo *); 142613a2f6bSGordon Ross void dump_sockaddr(struct sockaddr *); 143613a2f6bSGordon Ross int nb_ssn_request(struct smb_ctx *, char *); 1449c9af259SGordon Ross 1459c9af259SGordon Ross int nb_name_len(struct nb_name *); 146613a2f6bSGordon Ross int nb_name_encode(struct mbdata *, struct nb_name *); 1479c9af259SGordon Ross int nb_encname_len(const uchar_t *); 1489c9af259SGordon Ross 149613a2f6bSGordon Ross int nb_snballoc(struct sockaddr_nb **); 1509c9af259SGordon Ross void nb_snbfree(struct sockaddr *); 1519c9af259SGordon Ross int nb_sockaddr(struct sockaddr *, struct nb_name *, struct sockaddr_nb **); 1529c9af259SGordon Ross 153613a2f6bSGordon Ross int nbns_getaddrinfo(const char *name, struct nb_ctx *nbc, 154613a2f6bSGordon Ross struct addrinfo **res); 1559c9af259SGordon Ross int nbns_resolvename(const char *, struct nb_ctx *, struct sockaddr **); 156613a2f6bSGordon Ross int get_xti_err(int); 1579c9af259SGordon Ross 158613a2f6bSGordon Ross 159613a2f6bSGordon Ross /* 160613a2f6bSGordon Ross * Private SMB stuff 161613a2f6bSGordon Ross */ 162613a2f6bSGordon Ross 163613a2f6bSGordon Ross struct smb_bitname { 164613a2f6bSGordon Ross uint_t bn_bit; 165613a2f6bSGordon Ross char *bn_name; 166613a2f6bSGordon Ross }; 167613a2f6bSGordon Ross typedef struct smb_bitname smb_bitname_t; 168613a2f6bSGordon Ross char *smb_printb(char *, int, const struct smb_bitname *); 169613a2f6bSGordon Ross 170613a2f6bSGordon Ross int smb_ctx_getaddr(struct smb_ctx *ctx); 171613a2f6bSGordon Ross int smb_ctx_gethandle(struct smb_ctx *ctx); 172613a2f6bSGordon Ross 173613a2f6bSGordon Ross int smb_ssn_send(struct smb_ctx *, struct mbdata *); 174613a2f6bSGordon Ross int smb_ssn_recv(struct smb_ctx *, struct mbdata *); 175613a2f6bSGordon Ross 176613a2f6bSGordon Ross int smb_negprot(struct smb_ctx *, struct mbdata *); 177613a2f6bSGordon Ross 178613a2f6bSGordon Ross int smb_ssnsetup_null(struct smb_ctx *); 179613a2f6bSGordon Ross int smb_ssnsetup_ntlm1(struct smb_ctx *); 180613a2f6bSGordon Ross int smb_ssnsetup_ntlm2(struct smb_ctx *); 181613a2f6bSGordon Ross int smb_ssnsetup_spnego(struct smb_ctx *, struct mbdata *); 182613a2f6bSGordon Ross 183613a2f6bSGordon Ross void smb_time_local2server(struct timeval *, int, long *); 184613a2f6bSGordon Ross void smb_time_server2local(ulong_t, int, struct timeval *); 185613a2f6bSGordon Ross void smb_time_NT2local(uint64_t, int, struct timeval *); 186613a2f6bSGordon Ross void smb_time_local2NT(struct timeval *, int, uint64_t *); 187613a2f6bSGordon Ross 188613a2f6bSGordon Ross int smb_getlocalname(char **); 189613a2f6bSGordon Ross int smb_get_authentication(struct smb_ctx *); 190613a2f6bSGordon Ross int smb_get_keychain(struct smb_ctx *ctx); 191613a2f6bSGordon Ross void smb_hexdump(const void *buf, int len); 192613a2f6bSGordon Ross 193613a2f6bSGordon Ross /* See ssp.c */ 194613a2f6bSGordon Ross int ssp_ctx_create_client(struct smb_ctx *, struct mbdata *); 195613a2f6bSGordon Ross int ssp_ctx_next_token(struct smb_ctx *, struct mbdata *, struct mbdata *); 196613a2f6bSGordon Ross void ssp_ctx_destroy(struct smb_ctx *); 197613a2f6bSGordon Ross 198613a2f6bSGordon Ross #ifdef KICONV_SUPPORT 199613a2f6bSGordon Ross /* See nls.c (get rid of this?) */ 2009c9af259SGordon Ross extern uchar_t nls_lower[256], nls_upper[256]; 201613a2f6bSGordon Ross #endif /* KICONV_SUPPORT */ 2029c9af259SGordon Ross 2039c9af259SGordon Ross #endif /* _PRIVATE_H */ 204