xref: /freebsd/sys/netsmb/smb_conn.h (revision 41f1dccceb3c3950da343297dc6e7c85086dffbf)
1c398230bSWarner Losh /*-
2681a5bbeSBoris Popov  * Copyright (c) 2000-2001 Boris Popov
3681a5bbeSBoris Popov  * All rights reserved.
4681a5bbeSBoris Popov  *
5681a5bbeSBoris Popov  * Redistribution and use in source and binary forms, with or without
6681a5bbeSBoris Popov  * modification, are permitted provided that the following conditions
7681a5bbeSBoris Popov  * are met:
8681a5bbeSBoris Popov  * 1. Redistributions of source code must retain the above copyright
9681a5bbeSBoris Popov  *    notice, this list of conditions and the following disclaimer.
10681a5bbeSBoris Popov  * 2. Redistributions in binary form must reproduce the above copyright
11681a5bbeSBoris Popov  *    notice, this list of conditions and the following disclaimer in the
12681a5bbeSBoris Popov  *    documentation and/or other materials provided with the distribution.
13681a5bbeSBoris Popov  *
14681a5bbeSBoris Popov  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15681a5bbeSBoris Popov  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16681a5bbeSBoris Popov  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17681a5bbeSBoris Popov  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18681a5bbeSBoris Popov  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19681a5bbeSBoris Popov  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20681a5bbeSBoris Popov  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21681a5bbeSBoris Popov  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22681a5bbeSBoris Popov  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23681a5bbeSBoris Popov  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24681a5bbeSBoris Popov  * SUCH DAMAGE.
25681a5bbeSBoris Popov  *
26681a5bbeSBoris Popov  * $FreeBSD$
27681a5bbeSBoris Popov  */
28681a5bbeSBoris Popov 
29681a5bbeSBoris Popov /*
30681a5bbeSBoris Popov  * Two levels of connection hierarchy
31681a5bbeSBoris Popov  */
32681a5bbeSBoris Popov #define	SMBL_SM		0
33681a5bbeSBoris Popov #define SMBL_VC		1
34681a5bbeSBoris Popov #define SMBL_SHARE	2
35681a5bbeSBoris Popov #define SMBL_NUM	3
36681a5bbeSBoris Popov #define SMBL_NONE	(-1)
37681a5bbeSBoris Popov 
38681a5bbeSBoris Popov #define	SMB_CS_NONE	0x0000
39681a5bbeSBoris Popov #define	SMB_CS_UPPER	0x0001		/* convert passed string to upper case */
40681a5bbeSBoris Popov #define	SMB_CS_LOWER	0x0002		/* convert passed string to lower case */
41681a5bbeSBoris Popov 
42681a5bbeSBoris Popov /*
43681a5bbeSBoris Popov  * Common object flags
44681a5bbeSBoris Popov  */
45681a5bbeSBoris Popov #define SMBO_GONE		0x1000000
46681a5bbeSBoris Popov 
47681a5bbeSBoris Popov /*
48681a5bbeSBoris Popov  * access modes
49681a5bbeSBoris Popov  */
50681a5bbeSBoris Popov #define	SMBM_READ		0400	/* read conn attrs.(like list shares) */
51681a5bbeSBoris Popov #define	SMBM_WRITE		0200	/* modify conn attrs */
52681a5bbeSBoris Popov #define	SMBM_EXEC		0100	/* can send SMB requests */
53681a5bbeSBoris Popov #define	SMBM_READGRP		0040
54681a5bbeSBoris Popov #define	SMBM_WRITEGRP		0020
55681a5bbeSBoris Popov #define	SMBM_EXECGRP		0010
56681a5bbeSBoris Popov #define	SMBM_READOTH		0004
57681a5bbeSBoris Popov #define	SMBM_WRITEOTH		0002
58681a5bbeSBoris Popov #define	SMBM_EXECOTH		0001
59681a5bbeSBoris Popov #define	SMBM_MASK		0777
60681a5bbeSBoris Popov #define	SMBM_EXACT		010000	/* check for specified mode exactly */
61681a5bbeSBoris Popov #define	SMBM_ALL		(SMBM_READ | SMBM_WRITE | SMBM_EXEC)
62681a5bbeSBoris Popov #define	SMBM_DEFAULT		(SMBM_READ | SMBM_WRITE | SMBM_EXEC)
63681a5bbeSBoris Popov #define	SMBM_ANY_OWNER		((uid_t)-1)
64681a5bbeSBoris Popov #define	SMBM_ANY_GROUP		((gid_t)-1)
65681a5bbeSBoris Popov 
66681a5bbeSBoris Popov /*
67681a5bbeSBoris Popov  * VC flags
68681a5bbeSBoris Popov  */
69681a5bbeSBoris Popov #define SMBV_PERMANENT		0x0002
70681a5bbeSBoris Popov #define SMBV_LONGNAMES		0x0004	/* connection is configured to use long names */
71681a5bbeSBoris Popov #define	SMBV_ENCRYPT		0x0008	/* server asked for encrypted password */
72681a5bbeSBoris Popov #define	SMBV_WIN95		0x0010	/* used to apply bugfixes for this OS */
73681a5bbeSBoris Popov #define	SMBV_PRIVATE		0x0020	/* connection can be used only by creator */
74681a5bbeSBoris Popov #define	SMBV_RECONNECTING	0x0040	/* conn is in the process of reconnection */
75fc75194cSBoris Popov #define SMBV_SINGLESHARE	0x0080	/* only one share connecting should be allowed */
76fc75194cSBoris Popov #define SMBV_CREATE		0x0100	/* lookup for create operation */
77681a5bbeSBoris Popov /*#define SMBV_FAILED		0x0200*/	/* last reconnect attempt has failed */
78daa35dedSBoris Popov #define SMBV_UNICODE		0x0400	/* connection is configured to use Unicode */
79681a5bbeSBoris Popov 
80681a5bbeSBoris Popov 
81681a5bbeSBoris Popov /*
82681a5bbeSBoris Popov  * smb_share flags
83681a5bbeSBoris Popov  */
84681a5bbeSBoris Popov #define SMBS_PERMANENT		0x0001
85681a5bbeSBoris Popov #define SMBS_RECONNECTING	0x0002
86681a5bbeSBoris Popov #define SMBS_CONNECTED		0x0004
87681a5bbeSBoris Popov 
88681a5bbeSBoris Popov /*
89681a5bbeSBoris Popov  * share types
90681a5bbeSBoris Popov  */
91681a5bbeSBoris Popov #define	SMB_ST_DISK		0x0	/* A: */
92681a5bbeSBoris Popov #define	SMB_ST_PRINTER		0x1	/* LPT: */
93681a5bbeSBoris Popov #define	SMB_ST_PIPE		0x2	/* IPC */
94681a5bbeSBoris Popov #define	SMB_ST_COMM		0x3	/* COMM */
95681a5bbeSBoris Popov #define	SMB_ST_ANY		0x4
96681a5bbeSBoris Popov #define	SMB_ST_MAX		0x4
97681a5bbeSBoris Popov #define SMB_ST_NONE		0xff	/* not a part of protocol */
98681a5bbeSBoris Popov 
99681a5bbeSBoris Popov /*
100681a5bbeSBoris Popov  * Negotiated protocol parameters
101681a5bbeSBoris Popov  */
102681a5bbeSBoris Popov struct smb_sopt {
103681a5bbeSBoris Popov 	int		sv_proto;
104681a5bbeSBoris Popov 	int16_t		sv_tz;		/* offset in min relative to UTC */
105681a5bbeSBoris Popov 	u_int32_t	sv_maxtx;	/* maximum transmit buf size */
106681a5bbeSBoris Popov 	u_char		sv_sm;		/* security mode */
107681a5bbeSBoris Popov 	u_int16_t	sv_maxmux;	/* max number of outstanding rq's */
108681a5bbeSBoris Popov 	u_int16_t 	sv_maxvcs;	/* max number of VCs */
109681a5bbeSBoris Popov 	u_int16_t	sv_rawmode;
110681a5bbeSBoris Popov 	u_int32_t	sv_maxraw;	/* maximum raw-buffer size */
111681a5bbeSBoris Popov 	u_int32_t	sv_skey;	/* session key */
112fc75194cSBoris Popov 	u_int32_t	sv_caps;	/* capabilities SMB_CAP_ */
113681a5bbeSBoris Popov };
114681a5bbeSBoris Popov 
115681a5bbeSBoris Popov /*
116681a5bbeSBoris Popov  * network IO daemon states
117681a5bbeSBoris Popov  */
118681a5bbeSBoris Popov enum smbiod_state {
119681a5bbeSBoris Popov 	SMBIOD_ST_NOTCONN,	/* no connect request was made */
120681a5bbeSBoris Popov 	SMBIOD_ST_RECONNECT,	/* a [re]connect attempt is in progress */
121681a5bbeSBoris Popov 	SMBIOD_ST_TRANACTIVE,	/* transport level is up */
122681a5bbeSBoris Popov 	SMBIOD_ST_VCACTIVE,	/* session established */
123681a5bbeSBoris Popov 	SMBIOD_ST_DEAD		/* connection broken, transport is down */
124681a5bbeSBoris Popov };
125681a5bbeSBoris Popov 
126681a5bbeSBoris Popov 
127681a5bbeSBoris Popov /*
128681a5bbeSBoris Popov  * Info structures
129681a5bbeSBoris Popov  */
130681a5bbeSBoris Popov #define	SMB_INFO_NONE		0
131681a5bbeSBoris Popov #define	SMB_INFO_VC		2
132681a5bbeSBoris Popov #define	SMB_INFO_SHARE		3
133681a5bbeSBoris Popov 
134681a5bbeSBoris Popov struct smb_vc_info {
135681a5bbeSBoris Popov 	int		itype;
136681a5bbeSBoris Popov 	int		usecount;
137681a5bbeSBoris Popov 	uid_t		uid;		/* user id of connection */
138681a5bbeSBoris Popov 	gid_t		gid;		/* group of connection */
139681a5bbeSBoris Popov 	mode_t		mode;		/* access mode */
140681a5bbeSBoris Popov 	int		flags;
141681a5bbeSBoris Popov 	enum smbiod_state iodstate;
142681a5bbeSBoris Popov 	struct smb_sopt	sopt;
14393e3ed5aSTim J. Robbins 	char		srvname[SMB_MAXSRVNAMELEN + 1];
144681a5bbeSBoris Popov 	char		vcname[128];
145681a5bbeSBoris Popov };
146681a5bbeSBoris Popov 
147681a5bbeSBoris Popov struct smb_share_info {
148681a5bbeSBoris Popov 	int		itype;
149681a5bbeSBoris Popov 	int		usecount;
150681a5bbeSBoris Popov 	u_short		tid;		/* TID */
151681a5bbeSBoris Popov 	int		type;		/* share type */
152681a5bbeSBoris Popov 	uid_t		uid;		/* user id of connection */
153681a5bbeSBoris Popov 	gid_t		gid;		/* group of connection */
154681a5bbeSBoris Popov 	mode_t		mode;		/* access mode */
155681a5bbeSBoris Popov 	int		flags;
156681a5bbeSBoris Popov 	char		sname[128];
157681a5bbeSBoris Popov };
158681a5bbeSBoris Popov 
159681a5bbeSBoris Popov #ifdef _KERNEL
160681a5bbeSBoris Popov 
1617fbfba7bSAttilio Rao #include <sys/lock.h>
1622c55fd74SBruce Evans #include <sys/lockmgr.h>
163681a5bbeSBoris Popov #include <netsmb/smb_subr.h>
164681a5bbeSBoris Popov 
165681a5bbeSBoris Popov #define CONNADDREQ(a1,a2)	((a1)->sa_len == (a2)->sa_len && \
166681a5bbeSBoris Popov 				 bcmp(a1, a2, (a1)->sa_len) == 0)
167681a5bbeSBoris Popov 
168681a5bbeSBoris Popov struct smb_vc;
169681a5bbeSBoris Popov struct smb_share;
170681a5bbeSBoris Popov struct smb_cred;
171681a5bbeSBoris Popov struct smb_rq;
172681a5bbeSBoris Popov struct mbdata;
173681a5bbeSBoris Popov struct smbioc_oshare;
174681a5bbeSBoris Popov struct smbioc_ossn;
175681a5bbeSBoris Popov struct uio;
176681a5bbeSBoris Popov 
177681a5bbeSBoris Popov TAILQ_HEAD(smb_rqhead, smb_rq);
178681a5bbeSBoris Popov 
179681a5bbeSBoris Popov #define SMB_DEFRQTIMO	5
180681a5bbeSBoris Popov 
181681a5bbeSBoris Popov #define SMB_DIALECT(vcp)	((vcp)->vc_sopt.sv_proto)
182681a5bbeSBoris Popov 
183681a5bbeSBoris Popov struct smb_tran_desc;
184681a5bbeSBoris Popov 
185681a5bbeSBoris Popov /*
186681a5bbeSBoris Popov  * Connection object
187681a5bbeSBoris Popov  */
188681a5bbeSBoris Popov struct smb_connobj;
189681a5bbeSBoris Popov 
190681a5bbeSBoris Popov typedef void smb_co_gone_t (struct smb_connobj *cp, struct smb_cred *scred);
191681a5bbeSBoris Popov typedef void smb_co_free_t (struct smb_connobj *cp);
192681a5bbeSBoris Popov 
193681a5bbeSBoris Popov #define	SMB_CO_LOCK(cp)		smb_sl_lock(&(cp)->co_interlock)
194681a5bbeSBoris Popov #define	SMB_CO_UNLOCK(cp)	smb_sl_unlock(&(cp)->co_interlock)
195681a5bbeSBoris Popov 
196681a5bbeSBoris Popov struct smb_connobj {
197681a5bbeSBoris Popov 	int			co_level;	/* SMBL_ */
198681a5bbeSBoris Popov 	int			co_flags;
199681a5bbeSBoris Popov 	struct lock		co_lock;
200681a5bbeSBoris Popov 	struct smb_slock	co_interlock;
201681a5bbeSBoris Popov 	int			co_usecount;
202681a5bbeSBoris Popov 	struct smb_connobj *	co_parent;
203681a5bbeSBoris Popov 	SLIST_HEAD(,smb_connobj)co_children;
204681a5bbeSBoris Popov 	SLIST_ENTRY(smb_connobj)co_next;
205681a5bbeSBoris Popov 	smb_co_gone_t *		co_gone;
206681a5bbeSBoris Popov 	smb_co_free_t *		co_free;
207681a5bbeSBoris Popov };
208681a5bbeSBoris Popov 
209681a5bbeSBoris Popov #define	SMBCO_FOREACH(var, cp)	SLIST_FOREACH((var), &(cp)->co_children, co_next)
210681a5bbeSBoris Popov 
211681a5bbeSBoris Popov /*
212681a5bbeSBoris Popov  * Virtual Circuit (session) to a server.
213681a5bbeSBoris Popov  * This is the most (over)complicated part of SMB protocol.
214681a5bbeSBoris Popov  * For the user security level (usl), each session with different remote
215681a5bbeSBoris Popov  * user name has its own VC.
216681a5bbeSBoris Popov  * It is unclear however, should share security level (ssl) allow additional
217681a5bbeSBoris Popov  * VCs, because user name is not used and can be the same. On other hand,
218681a5bbeSBoris Popov  * multiple VCs allows us to create separate sessions to server on a per
219681a5bbeSBoris Popov  * user basis.
220681a5bbeSBoris Popov  */
221681a5bbeSBoris Popov 
222681a5bbeSBoris Popov /*
223681a5bbeSBoris Popov  * This lock protects vc_flags
224681a5bbeSBoris Popov  */
225681a5bbeSBoris Popov #define	SMBC_ST_LOCK(vcp)	smb_sl_lock(&(vcp)->vc_stlock)
226681a5bbeSBoris Popov #define	SMBC_ST_UNLOCK(vcp)	smb_sl_unlock(&(vcp)->vc_stlock)
227681a5bbeSBoris Popov 
228681a5bbeSBoris Popov 
229681a5bbeSBoris Popov struct smb_vc {
230681a5bbeSBoris Popov 	struct smb_connobj obj;
231681a5bbeSBoris Popov 	char *		vc_srvname;
232681a5bbeSBoris Popov 	struct sockaddr*vc_paddr;	/* server addr */
233681a5bbeSBoris Popov 	struct sockaddr*vc_laddr;	/* local addr, if any */
234681a5bbeSBoris Popov 	char *		vc_username;
235681a5bbeSBoris Popov 	char *		vc_pass;	/* password for usl case */
236681a5bbeSBoris Popov 	char *		vc_domain;	/* workgroup/primary domain */
237681a5bbeSBoris Popov 
238681a5bbeSBoris Popov 	u_int		vc_timo;	/* default request timeout */
239681a5bbeSBoris Popov 	int		vc_maxvcs;	/* maximum number of VC per connection */
240681a5bbeSBoris Popov 
241681a5bbeSBoris Popov 	void *		vc_tolower;	/* local charset */
242681a5bbeSBoris Popov 	void *		vc_toupper;	/* local charset */
243681a5bbeSBoris Popov 	void *		vc_toserver;	/* local charset to server one */
244681a5bbeSBoris Popov 	void *		vc_tolocal;	/* server charset to local one */
245*41f1dcccSKevin Lo 	void *		vc_cp_toserver;	/* local charset to server one (using CodePage) */
246*41f1dcccSKevin Lo 	void *		vc_cp_tolocal;	/* server charset to local one (using CodePage) */
247*41f1dcccSKevin Lo 	void *		vc_ucs_toserver; /* local charset to server one (using UCS-2) */
248*41f1dcccSKevin Lo 	void *		vc_ucs_tolocal;	/* server charset to local one (using UCS-2) */
249681a5bbeSBoris Popov 	int		vc_number;	/* number of this VC from the client side */
250681a5bbeSBoris Popov 	int		vc_genid;
251681a5bbeSBoris Popov 	uid_t		vc_uid;		/* user id of connection */
252681a5bbeSBoris Popov 	gid_t		vc_grp;		/* group of connection */
253681a5bbeSBoris Popov 	mode_t		vc_mode;	/* access mode */
254681a5bbeSBoris Popov 	u_short		vc_smbuid;	/* unique vc id assigned by server */
255681a5bbeSBoris Popov 
256681a5bbeSBoris Popov 	u_char		vc_hflags;	/* or'ed with flags in the smb header */
257681a5bbeSBoris Popov 	u_short		vc_hflags2;	/* or'ed with flags in the smb header */
258681a5bbeSBoris Popov 	void *		vc_tdata;	/* transport control block */
259681a5bbeSBoris Popov 	struct smb_tran_desc *vc_tdesc;
260681a5bbeSBoris Popov 	int		vc_chlen;	/* actual challenge length */
261681a5bbeSBoris Popov 	u_char 		vc_ch[SMB_MAXCHALLENGELEN];
262681a5bbeSBoris Popov 	u_short		vc_mid;		/* multiplex id */
263681a5bbeSBoris Popov 	struct smb_sopt	vc_sopt;	/* server options */
264681a5bbeSBoris Popov 	int		vc_txmax;	/* max tx/rx packet size */
265e2a70cffSBoris Popov 	int		vc_rxmax;	/* max readx data size */
266e2a70cffSBoris Popov 	int		vc_wxmax;	/* max writex data size */
267681a5bbeSBoris Popov 	struct smbiod *	vc_iod;
268681a5bbeSBoris Popov 	struct smb_slock vc_stlock;
269190b2c4fSTim J. Robbins 	u_int32_t	vc_seqno;	/* my next sequence number */
270190b2c4fSTim J. Robbins 	u_int8_t	*vc_mackey;	/* MAC key */
271190b2c4fSTim J. Robbins 	int		vc_mackeylen;	/* length of MAC key */
272681a5bbeSBoris Popov };
273681a5bbeSBoris Popov 
274681a5bbeSBoris Popov #define vc_maxmux	vc_sopt.sv_maxmux
275681a5bbeSBoris Popov #define	vc_flags	obj.co_flags
276681a5bbeSBoris Popov 
27770f9b9d9SBoris Popov #define SMB_UNICODE_STRINGS(vcp)	((vcp)->vc_hflags2 & SMB_FLAGS2_UNICODE)
278681a5bbeSBoris Popov 
279*41f1dcccSKevin Lo #define	SMB_UNICODE_NAME	"UCS-2LE"
280*41f1dcccSKevin Lo 
281681a5bbeSBoris Popov /*
282681a5bbeSBoris Popov  * smb_share structure describes connection to the given SMB share (tree).
283681a5bbeSBoris Popov  * Connection to share is always built on top of the VC.
284681a5bbeSBoris Popov  */
285681a5bbeSBoris Popov 
286681a5bbeSBoris Popov /*
287681a5bbeSBoris Popov  * This lock protects ss_flags
288681a5bbeSBoris Popov  */
289681a5bbeSBoris Popov #define	SMBS_ST_LOCK(ssp)	smb_sl_lock(&(ssp)->ss_stlock)
290681a5bbeSBoris Popov #define	SMBS_ST_LOCKPTR(ssp)	(&(ssp)->ss_stlock)
291681a5bbeSBoris Popov #define	SMBS_ST_UNLOCK(ssp)	smb_sl_unlock(&(ssp)->ss_stlock)
292681a5bbeSBoris Popov 
293681a5bbeSBoris Popov struct smb_share {
294681a5bbeSBoris Popov 	struct smb_connobj obj;
295681a5bbeSBoris Popov 	char *		ss_name;
296681a5bbeSBoris Popov 	u_short		ss_tid;		/* TID */
297681a5bbeSBoris Popov 	int		ss_type;	/* share type */
298681a5bbeSBoris Popov 	uid_t		ss_uid;		/* user id of connection */
299681a5bbeSBoris Popov 	gid_t		ss_grp;		/* group of connection */
300681a5bbeSBoris Popov 	mode_t		ss_mode;	/* access mode */
301681a5bbeSBoris Popov 	int		ss_vcgenid;
302681a5bbeSBoris Popov 	char *		ss_pass;	/* password to a share, can be null */
303681a5bbeSBoris Popov 	struct smb_slock ss_stlock;
304681a5bbeSBoris Popov };
305681a5bbeSBoris Popov 
306681a5bbeSBoris Popov #define	ss_flags	obj.co_flags
307681a5bbeSBoris Popov 
308681a5bbeSBoris Popov #define CPTOVC(cp)	((struct smb_vc*)(cp))
309681a5bbeSBoris Popov #define VCTOCP(vcp)	(&(vcp)->obj)
310681a5bbeSBoris Popov #define CPTOSS(cp)	((struct smb_share*)(cp))
311681a5bbeSBoris Popov #define	SSTOVC(ssp)	CPTOVC(((ssp)->obj.co_parent))
312681a5bbeSBoris Popov #define SSTOCP(ssp)	(&(ssp)->obj)
313681a5bbeSBoris Popov 
314681a5bbeSBoris Popov struct smb_vcspec {
315681a5bbeSBoris Popov 	char *		srvname;
316681a5bbeSBoris Popov 	struct sockaddr*sap;
317681a5bbeSBoris Popov 	struct sockaddr*lap;
318681a5bbeSBoris Popov 	int		flags;
319681a5bbeSBoris Popov 	char *		username;
320681a5bbeSBoris Popov 	char *		pass;
321681a5bbeSBoris Popov 	char *		domain;
322681a5bbeSBoris Popov 	mode_t		mode;
323681a5bbeSBoris Popov 	mode_t		rights;
324681a5bbeSBoris Popov 	uid_t		owner;
325681a5bbeSBoris Popov 	gid_t		group;
326681a5bbeSBoris Popov 	char *		localcs;
327681a5bbeSBoris Popov 	char *		servercs;
328681a5bbeSBoris Popov 	struct smb_sharespec *shspec;
329681a5bbeSBoris Popov 	struct smb_share *ssp;		/* returned */
330681a5bbeSBoris Popov 	/*
331681a5bbeSBoris Popov 	 * The rest is an internal data
332681a5bbeSBoris Popov 	 */
333681a5bbeSBoris Popov 	struct smb_cred *scred;
334681a5bbeSBoris Popov };
335681a5bbeSBoris Popov 
336681a5bbeSBoris Popov struct smb_sharespec {
337681a5bbeSBoris Popov 	char *		name;
338681a5bbeSBoris Popov 	char *		pass;
339681a5bbeSBoris Popov 	mode_t		mode;
340681a5bbeSBoris Popov 	mode_t		rights;
341681a5bbeSBoris Popov 	uid_t		owner;
342681a5bbeSBoris Popov 	gid_t		group;
343681a5bbeSBoris Popov 	int		stype;
344681a5bbeSBoris Popov 	/*
345681a5bbeSBoris Popov 	 * The rest is an internal data
346681a5bbeSBoris Popov 	 */
347681a5bbeSBoris Popov 	struct smb_cred *scred;
348681a5bbeSBoris Popov };
349681a5bbeSBoris Popov 
350681a5bbeSBoris Popov /*
351681a5bbeSBoris Popov  * Session level functions
352681a5bbeSBoris Popov  */
353681a5bbeSBoris Popov int  smb_sm_init(void);
354681a5bbeSBoris Popov int  smb_sm_done(void);
355681a5bbeSBoris Popov int  smb_sm_lookup(struct smb_vcspec *vcspec,
356681a5bbeSBoris Popov 	struct smb_sharespec *shspec, struct smb_cred *scred,
357681a5bbeSBoris Popov 	struct smb_vc **vcpp);
358681a5bbeSBoris Popov 
359681a5bbeSBoris Popov /*
360681a5bbeSBoris Popov  * Connection object
361681a5bbeSBoris Popov  */
362fce6fbfaSBoris Popov void smb_co_ref(struct smb_connobj *cp);
363681a5bbeSBoris Popov void smb_co_rele(struct smb_connobj *cp, struct smb_cred *scred);
364681a5bbeSBoris Popov int  smb_co_get(struct smb_connobj *cp, int flags, struct smb_cred *scred);
365681a5bbeSBoris Popov void smb_co_put(struct smb_connobj *cp, struct smb_cred *scred);
366e3b3762bSRobert Watson int  smb_co_lock(struct smb_connobj *cp, int flags);
367e3b3762bSRobert Watson void smb_co_unlock(struct smb_connobj *cp, int flags);
368681a5bbeSBoris Popov 
369681a5bbeSBoris Popov /*
370681a5bbeSBoris Popov  * session level functions
371681a5bbeSBoris Popov  */
372681a5bbeSBoris Popov int  smb_vc_create(struct smb_vcspec *vcspec,
373681a5bbeSBoris Popov 	struct smb_cred *scred, struct smb_vc **vcpp);
374681a5bbeSBoris Popov int  smb_vc_connect(struct smb_vc *vcp, struct smb_cred *scred);
375681a5bbeSBoris Popov int  smb_vc_access(struct smb_vc *vcp, struct smb_cred *scred, mode_t mode);
376681a5bbeSBoris Popov int  smb_vc_get(struct smb_vc *vcp, int flags, struct smb_cred *scred);
377681a5bbeSBoris Popov void smb_vc_put(struct smb_vc *vcp, struct smb_cred *scred);
378fce6fbfaSBoris Popov void smb_vc_ref(struct smb_vc *vcp);
379681a5bbeSBoris Popov void smb_vc_rele(struct smb_vc *vcp, struct smb_cred *scred);
380e3b3762bSRobert Watson int  smb_vc_lock(struct smb_vc *vcp, int flags);
381e3b3762bSRobert Watson void smb_vc_unlock(struct smb_vc *vcp, int flags);
382681a5bbeSBoris Popov int  smb_vc_lookupshare(struct smb_vc *vcp, struct smb_sharespec *shspec,
383681a5bbeSBoris Popov 	struct smb_cred *scred, struct smb_share **sspp);
384681a5bbeSBoris Popov const char * smb_vc_getpass(struct smb_vc *vcp);
385681a5bbeSBoris Popov u_short smb_vc_nextmid(struct smb_vc *vcp);
386681a5bbeSBoris Popov 
387681a5bbeSBoris Popov /*
388681a5bbeSBoris Popov  * share level functions
389681a5bbeSBoris Popov  */
390681a5bbeSBoris Popov int  smb_share_create(struct smb_vc *vcp, struct smb_sharespec *shspec,
391681a5bbeSBoris Popov 	struct smb_cred *scred, struct smb_share **sspp);
392681a5bbeSBoris Popov int  smb_share_access(struct smb_share *ssp, struct smb_cred *scred, mode_t mode);
393fce6fbfaSBoris Popov void smb_share_ref(struct smb_share *ssp);
394681a5bbeSBoris Popov void smb_share_rele(struct smb_share *ssp, struct smb_cred *scred);
395681a5bbeSBoris Popov int  smb_share_get(struct smb_share *ssp, int flags, struct smb_cred *scred);
396681a5bbeSBoris Popov void smb_share_put(struct smb_share *ssp, struct smb_cred *scred);
397e3b3762bSRobert Watson int  smb_share_lock(struct smb_share *ssp, int flags);
398e3b3762bSRobert Watson void smb_share_unlock(struct smb_share *ssp, int flags);
399681a5bbeSBoris Popov void smb_share_invalidate(struct smb_share *ssp);
400681a5bbeSBoris Popov int  smb_share_valid(struct smb_share *ssp);
401681a5bbeSBoris Popov const char * smb_share_getpass(struct smb_share *ssp);
402681a5bbeSBoris Popov 
403681a5bbeSBoris Popov /*
404681a5bbeSBoris Popov  * SMB protocol level functions
405681a5bbeSBoris Popov  */
406681a5bbeSBoris Popov int  smb_smb_negotiate(struct smb_vc *vcp, struct smb_cred *scred);
407681a5bbeSBoris Popov int  smb_smb_ssnsetup(struct smb_vc *vcp, struct smb_cred *scred);
408681a5bbeSBoris Popov int  smb_smb_ssnclose(struct smb_vc *vcp, struct smb_cred *scred);
409681a5bbeSBoris Popov int  smb_smb_treeconnect(struct smb_share *ssp, struct smb_cred *scred);
410681a5bbeSBoris Popov int  smb_smb_treedisconnect(struct smb_share *ssp, struct smb_cred *scred);
411681a5bbeSBoris Popov int  smb_read(struct smb_share *ssp, u_int16_t fid, struct uio *uio,
412681a5bbeSBoris Popov 	struct smb_cred *scred);
413681a5bbeSBoris Popov int  smb_write(struct smb_share *ssp, u_int16_t fid, struct uio *uio,
414681a5bbeSBoris Popov 	struct smb_cred *scred);
415681a5bbeSBoris Popov int  smb_smb_echo(struct smb_vc *vcp, struct smb_cred *scred);
416681a5bbeSBoris Popov 
417681a5bbeSBoris Popov /*
418681a5bbeSBoris Popov  * smbiod thread
419681a5bbeSBoris Popov  */
420681a5bbeSBoris Popov 
421681a5bbeSBoris Popov #define	SMBIOD_EV_NEWRQ		0x0001
422681a5bbeSBoris Popov #define	SMBIOD_EV_SHUTDOWN	0x0002
423681a5bbeSBoris Popov #define	SMBIOD_EV_CONNECT	0x0003
424681a5bbeSBoris Popov #define	SMBIOD_EV_DISCONNECT	0x0004
425681a5bbeSBoris Popov #define	SMBIOD_EV_TREECONNECT	0x0005
426681a5bbeSBoris Popov #define	SMBIOD_EV_MASK		0x00ff
427681a5bbeSBoris Popov #define	SMBIOD_EV_SYNC		0x0100
428681a5bbeSBoris Popov #define	SMBIOD_EV_PROCESSING	0x0200
429681a5bbeSBoris Popov 
430681a5bbeSBoris Popov struct smbiod_event {
431681a5bbeSBoris Popov 	int	ev_type;
432681a5bbeSBoris Popov 	int	ev_error;
433681a5bbeSBoris Popov 	void *	ev_ident;
434681a5bbeSBoris Popov 	STAILQ_ENTRY(smbiod_event)	ev_link;
435681a5bbeSBoris Popov };
436681a5bbeSBoris Popov 
437681a5bbeSBoris Popov #define	SMBIOD_SHUTDOWN		0x0001
438681a5bbeSBoris Popov 
439681a5bbeSBoris Popov struct smbiod {
440681a5bbeSBoris Popov 	int			iod_id;
441681a5bbeSBoris Popov 	int			iod_flags;
442681a5bbeSBoris Popov 	enum smbiod_state	iod_state;
443681a5bbeSBoris Popov 	int			iod_muxcnt;	/* number of active outstanding requests */
444681a5bbeSBoris Popov 	int			iod_sleeptimo;
445681a5bbeSBoris Popov 	struct smb_vc *		iod_vc;
446681a5bbeSBoris Popov 	struct smb_slock	iod_rqlock;	/* iod_rqlist, iod_muxwant */
447681a5bbeSBoris Popov 	struct smb_rqhead	iod_rqlist;	/* list of outstanding requests */
448681a5bbeSBoris Popov 	int			iod_muxwant;
449681a5bbeSBoris Popov 	struct proc *		iod_p;
450fce6fbfaSBoris Popov 	struct thread *		iod_td;
451681a5bbeSBoris Popov 	struct smb_cred		iod_scred;
452681a5bbeSBoris Popov 	struct smb_slock	iod_evlock;	/* iod_evlist */
453681a5bbeSBoris Popov 	STAILQ_HEAD(,smbiod_event) iod_evlist;
454681a5bbeSBoris Popov 	struct timespec 	iod_lastrqsent;
455681a5bbeSBoris Popov 	struct timespec 	iod_pingtimo;
456681a5bbeSBoris Popov };
457681a5bbeSBoris Popov 
458681a5bbeSBoris Popov int  smb_iod_init(void);
459681a5bbeSBoris Popov int  smb_iod_done(void);
460681a5bbeSBoris Popov int  smb_iod_create(struct smb_vc *vcp);
461681a5bbeSBoris Popov int  smb_iod_destroy(struct smbiod *iod);
462681a5bbeSBoris Popov int  smb_iod_request(struct smbiod *iod, int event, void *ident);
463681a5bbeSBoris Popov int  smb_iod_addrq(struct smb_rq *rqp);
464681a5bbeSBoris Popov int  smb_iod_waitrq(struct smb_rq *rqp);
465681a5bbeSBoris Popov int  smb_iod_removerq(struct smb_rq *rqp);
466681a5bbeSBoris Popov 
467681a5bbeSBoris Popov #endif /* _KERNEL */
468