xref: /titanic_51/usr/src/lib/libsmbfs/smb/private.h (revision a799b1e741b6f59012a469e6b57c40cb8061127b)
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 
33 /*
34  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
35  * Use is subject to license terms.
36  */
37 
38 #ifndef _PRIVATE_H
39 #define	_PRIVATE_H
40 
41 /*
42  * Private declarations for this library.
43  * Moved from smb_lib.h
44  */
45 
46 #include <inttypes.h>
47 #include <sys/byteorder.h>
48 #include <sys/ccompile.h>
49 
50 #include <netsmb/netbios.h>
51 
52 extern void dprint(const char *, const char *, ...)
53 	__PRINTFLIKE(2);
54 
55 #if defined(DEBUG) || defined(__lint)
56 #define	DPRINT(...) dprint(__func__, __VA_ARGS__)
57 #else
58 #define	DPRINT(...) ((void)0)
59 #endif
60 
61 /*
62  * Flags bits in ct_vcflags (copied from smb_conn.h)
63  * Pass these to the driver?
64  */
65 #define	SMBV_RECONNECTING	0x0002	/* conn in process of reconnection */
66 #define	SMBV_LONGNAMES		0x0004	/* conn configured to use long names */
67 #define	SMBV_ENCRYPT		0x0008	/* server demands encrypted password */
68 #define	SMBV_WIN95		0x0010	/* used to apply bugfixes for this OS */
69 #define	SMBV_NT4		0x0020	/* used when NT4 issues invalid resp */
70 #define	SMBV_UNICODE		0x0040	/* conn configured to use Unicode */
71 #define	SMBV_EXT_SEC		0x0080	/* conn to use extended security */
72 #define	SMBV_WILL_SIGN		0x0100	/* negotiated signing */
73 
74 
75 /*
76  * BSD-style mbuf simulation
77  */
78 struct mbuf {
79 	int		m_len;
80 	int		m_maxlen;
81 	char		*m_data;
82 	struct mbuf	*m_next;
83 };
84 typedef struct mbuf mbuf_t;
85 
86 struct mbdata {
87 	struct mbuf	*mb_top;
88 	struct mbuf	*mb_cur;
89 	char		*mb_pos;
90 	int		mb_count;
91 };
92 typedef struct mbdata mbdata_t;
93 
94 /*
95  * Note: Leaving a little space (8 bytes) between the
96  * mbuf header and the start of the data so we can
97  * prepend a NetBIOS header in that space.
98  */
99 #define	M_ALIGNFACTOR	(sizeof (long))
100 #define	M_ALIGN(len)	(((len) + M_ALIGNFACTOR - 1) & ~(M_ALIGNFACTOR - 1))
101 #define	M_BASESIZE	(sizeof (struct mbuf) + 8)
102 #define	M_MINSIZE	(1024 - M_BASESIZE)
103 #define	M_TOP(m)	((char *)(m) + M_BASESIZE)
104 #define	M_TRAILINGSPACE(m) ((m)->m_maxlen - (m)->m_len)
105 #define	mtod(m, t)	((t)(m)->m_data)
106 
107 /*
108  * request handling structures
109  */
110 struct smb_rq {
111 	struct smb_ctx *rq_ctx;
112 	struct mbdata	rq_rq;
113 	struct mbdata	rq_rp;
114 	int		rq_rpbufsz;
115 	uint8_t		rq_cmd;
116 	uint8_t		rq_hflags;
117 	uint16_t	rq_hflags2;
118 	uint32_t	rq_status;
119 	uint16_t	rq_uid;
120 	uint16_t	rq_tid;
121 	uint16_t	rq_mid;
122 	uint32_t	rq_seqno;
123 	/* See rq_[bw]{start,end} functions */
124 	char		*rq_wcntp;
125 	int		rq_wcbase;
126 	char		*rq_bcntp;
127 	int		rq_bcbase;
128 };
129 typedef struct smb_rq smb_rq_t;
130 
131 #define	smb_rq_getrequest(rqp)	(&(rqp)->rq_rq)
132 #define	smb_rq_getreply(rqp)	(&(rqp)->rq_rp)
133 
134 int  smb_rq_init(struct smb_ctx *, uchar_t, struct smb_rq **);
135 void smb_rq_done(struct smb_rq *);
136 void smb_rq_bstart(struct smb_rq *);
137 void smb_rq_bend(struct smb_rq *);
138 void smb_rq_wstart(struct smb_rq *);
139 void smb_rq_wend(struct smb_rq *);
140 int  smb_rq_simple(struct smb_rq *);
141 int  smb_rq_dmem(struct mbdata *, const char *, size_t);
142 int  smb_rq_internal(struct smb_ctx *, struct smb_rq *);
143 int  smb_rq_sign(struct smb_rq *);
144 int  smb_rq_verify(struct smb_rq *);
145 
146 
147 /*
148  * Message compose/parse
149  */
150 
151 void m_freem(struct mbuf *);
152 int  m_getm(struct mbuf *, size_t, struct mbuf **);
153 int  m_lineup(struct mbuf *, struct mbuf **);
154 size_t m_totlen(struct mbuf *);
155 
156 int  mb_init(struct mbdata *, size_t);
157 int  mb_initm(struct mbdata *, struct mbuf *);
158 int  mb_done(struct mbdata *);
159 int  mb_fit(struct mbdata *mbp, size_t size, char **pp);
160 int  mb_put_uint8(struct mbdata *, uint8_t);
161 int  mb_put_uint16be(struct mbdata *, uint16_t);
162 int  mb_put_uint16le(struct mbdata *, uint16_t);
163 int  mb_put_uint32be(struct mbdata *, uint32_t);
164 int  mb_put_uint32le(struct mbdata *, uint32_t);
165 int  mb_put_uint64be(struct mbdata *, uint64_t);
166 int  mb_put_uint64le(struct mbdata *, uint64_t);
167 int  mb_put_mem(struct mbdata *, const void *, size_t);
168 int  mb_put_mbuf(struct mbdata *, struct mbuf *);
169 int  mb_put_astring(struct mbdata *mbp, const char *s);
170 int  mb_put_dstring(struct mbdata *mbp, const char *s, int);
171 int  mb_put_ustring(struct mbdata *mbp, const char *s);
172 
173 int  mb_get_uint8(struct mbdata *, uint8_t *);
174 int  mb_get_uint16(struct mbdata *, uint16_t *);
175 int  mb_get_uint16le(struct mbdata *, uint16_t *);
176 int  mb_get_uint16be(struct mbdata *, uint16_t *);
177 int  mb_get_uint32(struct mbdata *, uint32_t *);
178 int  mb_get_uint32be(struct mbdata *, uint32_t *);
179 int  mb_get_uint32le(struct mbdata *, uint32_t *);
180 int  mb_get_uint64(struct mbdata *, uint64_t *);
181 int  mb_get_uint64be(struct mbdata *, uint64_t *);
182 int  mb_get_uint64le(struct mbdata *, uint64_t *);
183 int  mb_get_mem(struct mbdata *, void *, size_t);
184 int  mb_get_mbuf(struct mbdata *, int, struct mbuf **);
185 int  mb_get_string(struct mbdata *, char **, int);
186 int  mb_get_astring(struct mbdata *, char **);
187 int  mb_get_ustring(struct mbdata *, char **);
188 
189 
190 /*
191  * Network stuff (NetBIOS and otherwise)
192  */
193 struct nb_name;
194 struct sockaddr_nb;
195 
196 extern int smb_recv_timeout; /* seconds */
197 
198 void dump_ctx(char *, struct smb_ctx *);
199 void dump_addrinfo(struct addrinfo *);
200 void dump_sockaddr(struct sockaddr *);
201 int nb_ssn_request(struct smb_ctx *, char *);
202 
203 int nb_name_len(struct nb_name *);
204 int nb_name_encode(struct mbdata *, struct nb_name *);
205 int nb_encname_len(const uchar_t *);
206 
207 int  nb_snballoc(struct sockaddr_nb **);
208 void nb_snbfree(struct sockaddr *);
209 int  nb_sockaddr(struct sockaddr *, struct nb_name *, struct sockaddr_nb **);
210 
211 int nbns_getaddrinfo(const char *name, struct nb_ctx *nbc,
212 	struct addrinfo **res);
213 int  nbns_resolvename(const char *, struct nb_ctx *, struct sockaddr **);
214 int  get_xti_err(int);
215 
216 
217 /*
218  * Private SMB stuff
219  */
220 
221 struct smb_bitname {
222 	uint_t	bn_bit;
223 	char	*bn_name;
224 };
225 typedef struct smb_bitname smb_bitname_t;
226 char *smb_printb(char *, int, const struct smb_bitname *);
227 
228 int smb_ctx_getaddr(struct smb_ctx *ctx);
229 int smb_ctx_gethandle(struct smb_ctx *ctx);
230 
231 int smb_ssn_send(struct smb_ctx *, struct mbdata *);
232 int smb_ssn_recv(struct smb_ctx *, struct mbdata *);
233 
234 int smb_negprot(struct smb_ctx *, struct mbdata *);
235 
236 int smb_ssnsetup_null(struct smb_ctx *);
237 int smb_ssnsetup_ntlm1(struct smb_ctx *);
238 int smb_ssnsetup_ntlm2(struct smb_ctx *);
239 int smb_ssnsetup_spnego(struct smb_ctx *, struct mbdata *);
240 
241 void smb_time_local2server(struct timeval *, int, long *);
242 void smb_time_server2local(ulong_t, int, struct timeval *);
243 void smb_time_NT2local(uint64_t, int, struct timeval *);
244 void smb_time_local2NT(struct timeval *, int, uint64_t *);
245 
246 int smb_getlocalname(char **);
247 int smb_get_authentication(struct smb_ctx *);
248 int smb_get_keychain(struct smb_ctx *ctx);
249 void smb_hexdump(const void *buf, int len);
250 
251 /* See ssp.c */
252 int ssp_ctx_create_client(struct smb_ctx *, struct mbdata *);
253 int ssp_ctx_next_token(struct smb_ctx *, struct mbdata *, struct mbdata *);
254 void ssp_ctx_destroy(struct smb_ctx *);
255 
256 #ifdef KICONV_SUPPORT
257 /* See nls.c (get rid of this?) */
258 extern uchar_t nls_lower[256], nls_upper[256];
259 #endif	/* KICONV_SUPPORT */
260 
261 #endif /* _PRIVATE_H */
262