xref: /titanic_44/usr/src/lib/libsmbfs/smb/private.h (revision 6e91bba0d6c6bdabbba62cefae583715a4a58e2a)
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/mchain.h>
51 #include <netsmb/netbios.h>
52 
53 extern void dprint(const char *, const char *, ...)
54 	__PRINTFLIKE(2);
55 
56 #if defined(DEBUG) || defined(__lint)
57 #define	DPRINT(...) dprint(__func__, __VA_ARGS__)
58 #else
59 #define	DPRINT(...) ((void)0)
60 #endif
61 
62 /*
63  * Flags bits in ct_vcflags (copied from smb_conn.h)
64  * Pass these to the driver?
65  */
66 #define	SMBV_RECONNECTING	0x0002	/* conn in process of reconnection */
67 #define	SMBV_LONGNAMES		0x0004	/* conn configured to use long names */
68 #define	SMBV_ENCRYPT		0x0008	/* server demands encrypted password */
69 #define	SMBV_WIN95		0x0010	/* used to apply bugfixes for this OS */
70 #define	SMBV_NT4		0x0020	/* used when NT4 issues invalid resp */
71 #define	SMBV_UNICODE		0x0040	/* conn configured to use Unicode */
72 #define	SMBV_EXT_SEC		0x0080	/* conn to use extended security */
73 #define	SMBV_WILL_SIGN		0x0100	/* negotiated signing */
74 
75 /*
76  * request handling structures
77  */
78 struct smb_rq {
79 	struct smb_ctx *rq_ctx;
80 	struct mbdata	rq_rq;
81 	struct mbdata	rq_rp;
82 	int		rq_rpbufsz;
83 	uint8_t		rq_cmd;
84 	uint8_t		rq_hflags;
85 	uint16_t	rq_hflags2;
86 	uint32_t	rq_status;
87 	uint16_t	rq_uid;
88 	uint16_t	rq_tid;
89 	uint16_t	rq_mid;
90 	uint32_t	rq_seqno;
91 	/* See rq_[bw]{start,end} functions */
92 	char		*rq_wcntp;
93 	int		rq_wcbase;
94 	char		*rq_bcntp;
95 	int		rq_bcbase;
96 };
97 typedef struct smb_rq smb_rq_t;
98 
99 #define	smb_rq_getrequest(rqp)	(&(rqp)->rq_rq)
100 #define	smb_rq_getreply(rqp)	(&(rqp)->rq_rp)
101 
102 int  smb_rq_init(struct smb_ctx *, uchar_t, struct smb_rq **);
103 void smb_rq_done(struct smb_rq *);
104 void smb_rq_bstart(struct smb_rq *);
105 void smb_rq_bend(struct smb_rq *);
106 void smb_rq_wstart(struct smb_rq *);
107 void smb_rq_wend(struct smb_rq *);
108 int  smb_rq_simple(struct smb_rq *);
109 int  smb_rq_dmem(struct mbdata *, const char *, size_t);
110 int  smb_rq_internal(struct smb_ctx *, struct smb_rq *);
111 void smb_rq_sign(struct smb_rq *);
112 int  smb_rq_verify(struct smb_rq *);
113 
114 /*
115  * This library extends the mchain.h function set a little.
116  */
117 int  m_getm(struct mbuf *, int, struct mbuf **);
118 int  m_lineup(struct mbuf *, struct mbuf **);
119 size_t m_totlen(struct mbuf *);
120 
121 int  mb_init_sz(struct mbdata *, int);
122 int  mb_fit(struct mbdata *mbp, int size, char **pp);
123 
124 int  mb_put_string(struct mbdata *mbp, const char *s, int);
125 int  mb_put_astring(struct mbdata *mbp, const char *s);
126 int  mb_put_ustring(struct mbdata *mbp, const char *s);
127 
128 int  md_get_string(struct mbdata *, char **, int);
129 int  md_get_astring(struct mbdata *, char **);
130 int  md_get_ustring(struct mbdata *, char **);
131 
132 /*
133  * Network stuff (NetBIOS and otherwise)
134  */
135 struct nb_name;
136 struct sockaddr_nb;
137 
138 extern int smb_recv_timeout; /* seconds */
139 
140 void dump_ctx(char *, struct smb_ctx *);
141 void dump_addrinfo(struct addrinfo *);
142 void dump_sockaddr(struct sockaddr *);
143 int nb_ssn_request(struct smb_ctx *, char *);
144 
145 int nb_name_len(struct nb_name *);
146 int nb_name_encode(struct mbdata *, struct nb_name *);
147 int nb_encname_len(const uchar_t *);
148 
149 int  nb_snballoc(struct sockaddr_nb **);
150 void nb_snbfree(struct sockaddr *);
151 int  nb_sockaddr(struct sockaddr *, struct nb_name *, struct sockaddr_nb **);
152 
153 int nbns_getaddrinfo(const char *name, struct nb_ctx *nbc,
154 	struct addrinfo **res);
155 int  nbns_resolvename(const char *, struct nb_ctx *, struct sockaddr **);
156 int  get_xti_err(int);
157 
158 
159 /*
160  * Private SMB stuff
161  */
162 
163 struct smb_bitname {
164 	uint_t	bn_bit;
165 	char	*bn_name;
166 };
167 typedef struct smb_bitname smb_bitname_t;
168 char *smb_printb(char *, int, const struct smb_bitname *);
169 
170 int smb_ctx_getaddr(struct smb_ctx *ctx);
171 int smb_ctx_gethandle(struct smb_ctx *ctx);
172 
173 int smb_ssn_send(struct smb_ctx *, struct mbdata *);
174 int smb_ssn_recv(struct smb_ctx *, struct mbdata *);
175 
176 int smb_negprot(struct smb_ctx *, struct mbdata *);
177 
178 int smb_ssnsetup_null(struct smb_ctx *);
179 int smb_ssnsetup_ntlm1(struct smb_ctx *);
180 int smb_ssnsetup_ntlm2(struct smb_ctx *);
181 int smb_ssnsetup_spnego(struct smb_ctx *, struct mbdata *);
182 
183 void smb_time_local2server(struct timeval *, int, long *);
184 void smb_time_server2local(ulong_t, int, struct timeval *);
185 void smb_time_NT2local(uint64_t, int, struct timeval *);
186 void smb_time_local2NT(struct timeval *, int, uint64_t *);
187 
188 int smb_getlocalname(char **);
189 int smb_get_authentication(struct smb_ctx *);
190 int smb_get_keychain(struct smb_ctx *ctx);
191 void smb_hexdump(const void *buf, int len);
192 
193 /* See ssp.c */
194 int ssp_ctx_create_client(struct smb_ctx *, struct mbdata *);
195 int ssp_ctx_next_token(struct smb_ctx *, struct mbdata *, struct mbdata *);
196 void ssp_ctx_destroy(struct smb_ctx *);
197 
198 #ifdef KICONV_SUPPORT
199 /* See nls.c (get rid of this?) */
200 extern uchar_t nls_lower[256], nls_upper[256];
201 #endif	/* KICONV_SUPPORT */
202 
203 #endif /* _PRIVATE_H */
204