xref: /titanic_52/usr/src/lib/libsmbfs/smb/private.h (revision 430b4c467020edf2445feb0c21db01c88b86243a)
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 /*
34*430b4c46SGordon Ross  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
35613a2f6bSGordon Ross  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
369c9af259SGordon Ross  * Use is subject to license terms.
379c9af259SGordon Ross  */
389c9af259SGordon Ross 
399c9af259SGordon Ross #ifndef _PRIVATE_H
409c9af259SGordon Ross #define	_PRIVATE_H
419c9af259SGordon Ross 
429c9af259SGordon Ross /*
439c9af259SGordon Ross  * Private declarations for this library.
449c9af259SGordon Ross  * Moved from smb_lib.h
459c9af259SGordon Ross  */
469c9af259SGordon Ross 
479c9af259SGordon Ross #include <inttypes.h>
48613a2f6bSGordon Ross #include <sys/byteorder.h>
49613a2f6bSGordon Ross #include <sys/ccompile.h>
50613a2f6bSGordon Ross 
5102d09e03SGordon Ross #include <netsmb/mchain.h>
52613a2f6bSGordon Ross #include <netsmb/netbios.h>
53613a2f6bSGordon Ross 
54613a2f6bSGordon Ross extern void dprint(const char *, const char *, ...)
55613a2f6bSGordon Ross 	__PRINTFLIKE(2);
56613a2f6bSGordon Ross 
57613a2f6bSGordon Ross #if defined(DEBUG) || defined(__lint)
58613a2f6bSGordon Ross #define	DPRINT(...) dprint(__func__, __VA_ARGS__)
59613a2f6bSGordon Ross #else
60613a2f6bSGordon Ross #define	DPRINT(...) ((void)0)
61613a2f6bSGordon Ross #endif
62613a2f6bSGordon Ross 
63613a2f6bSGordon Ross /*
64613a2f6bSGordon Ross  * Flags bits in ct_vcflags (copied from smb_conn.h)
65613a2f6bSGordon Ross  * Pass these to the driver?
66613a2f6bSGordon Ross  */
67613a2f6bSGordon Ross #define	SMBV_RECONNECTING	0x0002	/* conn in process of reconnection */
68613a2f6bSGordon Ross #define	SMBV_LONGNAMES		0x0004	/* conn configured to use long names */
69613a2f6bSGordon Ross #define	SMBV_ENCRYPT		0x0008	/* server demands encrypted password */
70613a2f6bSGordon Ross #define	SMBV_WIN95		0x0010	/* used to apply bugfixes for this OS */
71613a2f6bSGordon Ross #define	SMBV_NT4		0x0020	/* used when NT4 issues invalid resp */
72613a2f6bSGordon Ross #define	SMBV_UNICODE		0x0040	/* conn configured to use Unicode */
73613a2f6bSGordon Ross #define	SMBV_EXT_SEC		0x0080	/* conn to use extended security */
74613a2f6bSGordon Ross #define	SMBV_WILL_SIGN		0x0100	/* negotiated signing */
75613a2f6bSGordon Ross 
769c9af259SGordon Ross /*
779c9af259SGordon Ross  * request handling structures
789c9af259SGordon Ross  */
799c9af259SGordon Ross struct smb_rq {
80613a2f6bSGordon Ross 	struct smb_ctx *rq_ctx;
819c9af259SGordon Ross 	struct mbdata	rq_rq;
829c9af259SGordon Ross 	struct mbdata	rq_rp;
83613a2f6bSGordon Ross 	int		rq_rpbufsz;
84613a2f6bSGordon Ross 	uint8_t		rq_cmd;
85613a2f6bSGordon Ross 	uint8_t		rq_hflags;
86613a2f6bSGordon Ross 	uint16_t	rq_hflags2;
87613a2f6bSGordon Ross 	uint32_t	rq_status;
88613a2f6bSGordon Ross 	uint16_t	rq_uid;
89613a2f6bSGordon Ross 	uint16_t	rq_tid;
90613a2f6bSGordon Ross 	uint16_t	rq_mid;
91613a2f6bSGordon Ross 	uint32_t	rq_seqno;
92613a2f6bSGordon Ross 	/* See rq_[bw]{start,end} functions */
93613a2f6bSGordon Ross 	char		*rq_wcntp;
94613a2f6bSGordon Ross 	int		rq_wcbase;
95613a2f6bSGordon Ross 	char		*rq_bcntp;
96613a2f6bSGordon Ross 	int		rq_bcbase;
979c9af259SGordon Ross };
989c9af259SGordon Ross typedef struct smb_rq smb_rq_t;
999c9af259SGordon Ross 
1009c9af259SGordon Ross #define	smb_rq_getrequest(rqp)	(&(rqp)->rq_rq)
1019c9af259SGordon Ross #define	smb_rq_getreply(rqp)	(&(rqp)->rq_rp)
1029c9af259SGordon Ross 
103613a2f6bSGordon Ross int  smb_rq_init(struct smb_ctx *, uchar_t, struct smb_rq **);
1049c9af259SGordon Ross void smb_rq_done(struct smb_rq *);
105613a2f6bSGordon Ross void smb_rq_bstart(struct smb_rq *);
106613a2f6bSGordon Ross void smb_rq_bend(struct smb_rq *);
107613a2f6bSGordon Ross void smb_rq_wstart(struct smb_rq *);
1089c9af259SGordon Ross void smb_rq_wend(struct smb_rq *);
1099c9af259SGordon Ross int  smb_rq_simple(struct smb_rq *);
1109c9af259SGordon Ross int  smb_rq_dmem(struct mbdata *, const char *, size_t);
111613a2f6bSGordon Ross int  smb_rq_internal(struct smb_ctx *, struct smb_rq *);
11202d09e03SGordon Ross void smb_rq_sign(struct smb_rq *);
113613a2f6bSGordon Ross int  smb_rq_verify(struct smb_rq *);
114*430b4c46SGordon Ross int  smb_t2_request(int, int, uint16_t *, const char *,
115*430b4c46SGordon Ross 	int, void *, int, void *, int *, void *, int *, void *, int *);
1169c9af259SGordon Ross 
1179c9af259SGordon Ross /*
11802d09e03SGordon Ross  * This library extends the mchain.h function set a little.
1199c9af259SGordon Ross  */
12002d09e03SGordon Ross int  m_getm(struct mbuf *, int, struct mbuf **);
1219c9af259SGordon Ross int  m_lineup(struct mbuf *, struct mbuf **);
122613a2f6bSGordon Ross size_t m_totlen(struct mbuf *);
123613a2f6bSGordon Ross 
12402d09e03SGordon Ross int  mb_init_sz(struct mbdata *, int);
12502d09e03SGordon Ross int  mb_fit(struct mbdata *mbp, int size, char **pp);
12602d09e03SGordon Ross 
12702d09e03SGordon Ross int  mb_put_string(struct mbdata *mbp, const char *s, int);
128613a2f6bSGordon Ross int  mb_put_astring(struct mbdata *mbp, const char *s);
129613a2f6bSGordon Ross int  mb_put_ustring(struct mbdata *mbp, const char *s);
1309c9af259SGordon Ross 
13102d09e03SGordon Ross int  md_get_string(struct mbdata *, char **, int);
13202d09e03SGordon Ross int  md_get_astring(struct mbdata *, char **);
13302d09e03SGordon Ross int  md_get_ustring(struct mbdata *, char **);
1349c9af259SGordon Ross 
1359c9af259SGordon Ross /*
1369c9af259SGordon Ross  * Network stuff (NetBIOS and otherwise)
1379c9af259SGordon Ross  */
138613a2f6bSGordon Ross struct nb_name;
139613a2f6bSGordon Ross struct sockaddr_nb;
140613a2f6bSGordon Ross 
141613a2f6bSGordon Ross extern int smb_recv_timeout; /* seconds */
142613a2f6bSGordon Ross 
143613a2f6bSGordon Ross void dump_ctx(char *, struct smb_ctx *);
144613a2f6bSGordon Ross void dump_addrinfo(struct addrinfo *);
145613a2f6bSGordon Ross void dump_sockaddr(struct sockaddr *);
146613a2f6bSGordon Ross int nb_ssn_request(struct smb_ctx *, char *);
1479c9af259SGordon Ross 
1489c9af259SGordon Ross int nb_name_len(struct nb_name *);
149613a2f6bSGordon Ross int nb_name_encode(struct mbdata *, struct nb_name *);
1509c9af259SGordon Ross int nb_encname_len(const uchar_t *);
1519c9af259SGordon Ross 
152613a2f6bSGordon Ross int  nb_snballoc(struct sockaddr_nb **);
1539c9af259SGordon Ross void nb_snbfree(struct sockaddr *);
1549c9af259SGordon Ross int  nb_sockaddr(struct sockaddr *, struct nb_name *, struct sockaddr_nb **);
1559c9af259SGordon Ross 
156613a2f6bSGordon Ross int nbns_getaddrinfo(const char *name, struct nb_ctx *nbc,
157613a2f6bSGordon Ross 	struct addrinfo **res);
1589c9af259SGordon Ross int  nbns_resolvename(const char *, struct nb_ctx *, struct sockaddr **);
159613a2f6bSGordon Ross int  get_xti_err(int);
1609c9af259SGordon Ross 
161613a2f6bSGordon Ross 
162613a2f6bSGordon Ross /*
163613a2f6bSGordon Ross  * Private SMB stuff
164613a2f6bSGordon Ross  */
165613a2f6bSGordon Ross 
166613a2f6bSGordon Ross struct smb_bitname {
167613a2f6bSGordon Ross 	uint_t	bn_bit;
168613a2f6bSGordon Ross 	char	*bn_name;
169613a2f6bSGordon Ross };
170613a2f6bSGordon Ross typedef struct smb_bitname smb_bitname_t;
171613a2f6bSGordon Ross char *smb_printb(char *, int, const struct smb_bitname *);
172613a2f6bSGordon Ross 
173613a2f6bSGordon Ross int smb_ctx_getaddr(struct smb_ctx *ctx);
174613a2f6bSGordon Ross int smb_ctx_gethandle(struct smb_ctx *ctx);
175613a2f6bSGordon Ross 
176*430b4c46SGordon Ross int  smb_iod_start(struct smb_ctx *);
177*430b4c46SGordon Ross 
178613a2f6bSGordon Ross int smb_ssn_send(struct smb_ctx *, struct mbdata *);
179613a2f6bSGordon Ross int smb_ssn_recv(struct smb_ctx *, struct mbdata *);
180613a2f6bSGordon Ross 
181613a2f6bSGordon Ross int smb_negprot(struct smb_ctx *, struct mbdata *);
182613a2f6bSGordon Ross 
183613a2f6bSGordon Ross int smb_ssnsetup_null(struct smb_ctx *);
184613a2f6bSGordon Ross int smb_ssnsetup_ntlm1(struct smb_ctx *);
185613a2f6bSGordon Ross int smb_ssnsetup_ntlm2(struct smb_ctx *);
186613a2f6bSGordon Ross int smb_ssnsetup_spnego(struct smb_ctx *, struct mbdata *);
187613a2f6bSGordon Ross 
188613a2f6bSGordon Ross void smb_time_local2server(struct timeval *, int, long *);
189613a2f6bSGordon Ross void smb_time_server2local(ulong_t, int, struct timeval *);
190613a2f6bSGordon Ross void smb_time_NT2local(uint64_t, int, struct timeval *);
191613a2f6bSGordon Ross void smb_time_local2NT(struct timeval *, int, uint64_t *);
192613a2f6bSGordon Ross 
193613a2f6bSGordon Ross int smb_getlocalname(char **);
194613a2f6bSGordon Ross int smb_get_authentication(struct smb_ctx *);
195613a2f6bSGordon Ross int smb_get_keychain(struct smb_ctx *ctx);
196613a2f6bSGordon Ross void smb_hexdump(const void *buf, int len);
197613a2f6bSGordon Ross 
198613a2f6bSGordon Ross /* See ssp.c */
199613a2f6bSGordon Ross int ssp_ctx_create_client(struct smb_ctx *, struct mbdata *);
200613a2f6bSGordon Ross int ssp_ctx_next_token(struct smb_ctx *, struct mbdata *, struct mbdata *);
201613a2f6bSGordon Ross void ssp_ctx_destroy(struct smb_ctx *);
202613a2f6bSGordon Ross 
203613a2f6bSGordon Ross #ifdef KICONV_SUPPORT
204613a2f6bSGordon Ross /* See nls.c (get rid of this?) */
2059c9af259SGordon Ross extern uchar_t nls_lower[256], nls_upper[256];
206613a2f6bSGordon Ross #endif	/* KICONV_SUPPORT */
2079c9af259SGordon Ross 
2089c9af259SGordon Ross #endif /* _PRIVATE_H */
209