xref: /freebsd/sys/netsmb/smb_conn.h (revision c398230b64aea809cb7c5cea8db580af7097920c)
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  * 3. All advertising materials mentioning features or use of this software
14681a5bbeSBoris Popov  *    must display the following acknowledgement:
15681a5bbeSBoris Popov  *    This product includes software developed by Boris Popov.
16681a5bbeSBoris Popov  * 4. Neither the name of the author nor the names of any co-contributors
17681a5bbeSBoris Popov  *    may be used to endorse or promote products derived from this software
18681a5bbeSBoris Popov  *    without specific prior written permission.
19681a5bbeSBoris Popov  *
20681a5bbeSBoris Popov  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21681a5bbeSBoris Popov  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22681a5bbeSBoris Popov  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23681a5bbeSBoris Popov  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24681a5bbeSBoris Popov  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25681a5bbeSBoris Popov  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26681a5bbeSBoris Popov  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27681a5bbeSBoris Popov  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28681a5bbeSBoris Popov  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29681a5bbeSBoris Popov  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30681a5bbeSBoris Popov  * SUCH DAMAGE.
31681a5bbeSBoris Popov  *
32681a5bbeSBoris Popov  * $FreeBSD$
33681a5bbeSBoris Popov  */
34681a5bbeSBoris Popov 
35681a5bbeSBoris Popov /*
36681a5bbeSBoris Popov  * Two levels of connection hierarchy
37681a5bbeSBoris Popov  */
38681a5bbeSBoris Popov #define	SMBL_SM		0
39681a5bbeSBoris Popov #define SMBL_VC		1
40681a5bbeSBoris Popov #define SMBL_SHARE	2
41681a5bbeSBoris Popov #define SMBL_NUM	3
42681a5bbeSBoris Popov #define SMBL_NONE	(-1)
43681a5bbeSBoris Popov 
44681a5bbeSBoris Popov #define	SMB_CS_NONE	0x0000
45681a5bbeSBoris Popov #define	SMB_CS_UPPER	0x0001		/* convert passed string to upper case */
46681a5bbeSBoris Popov #define	SMB_CS_LOWER	0x0002		/* convert passed string to lower case */
47681a5bbeSBoris Popov 
48681a5bbeSBoris Popov /*
49681a5bbeSBoris Popov  * Common object flags
50681a5bbeSBoris Popov  */
51681a5bbeSBoris Popov #define SMBO_GONE		0x1000000
52681a5bbeSBoris Popov 
53681a5bbeSBoris Popov /*
54681a5bbeSBoris Popov  * access modes
55681a5bbeSBoris Popov  */
56681a5bbeSBoris Popov #define	SMBM_READ		0400	/* read conn attrs.(like list shares) */
57681a5bbeSBoris Popov #define	SMBM_WRITE		0200	/* modify conn attrs */
58681a5bbeSBoris Popov #define	SMBM_EXEC		0100	/* can send SMB requests */
59681a5bbeSBoris Popov #define	SMBM_READGRP		0040
60681a5bbeSBoris Popov #define	SMBM_WRITEGRP		0020
61681a5bbeSBoris Popov #define	SMBM_EXECGRP		0010
62681a5bbeSBoris Popov #define	SMBM_READOTH		0004
63681a5bbeSBoris Popov #define	SMBM_WRITEOTH		0002
64681a5bbeSBoris Popov #define	SMBM_EXECOTH		0001
65681a5bbeSBoris Popov #define	SMBM_MASK		0777
66681a5bbeSBoris Popov #define	SMBM_EXACT		010000	/* check for specified mode exactly */
67681a5bbeSBoris Popov #define	SMBM_ALL		(SMBM_READ | SMBM_WRITE | SMBM_EXEC)
68681a5bbeSBoris Popov #define	SMBM_DEFAULT		(SMBM_READ | SMBM_WRITE | SMBM_EXEC)
69681a5bbeSBoris Popov #define	SMBM_ANY_OWNER		((uid_t)-1)
70681a5bbeSBoris Popov #define	SMBM_ANY_GROUP		((gid_t)-1)
71681a5bbeSBoris Popov 
72681a5bbeSBoris Popov /*
73681a5bbeSBoris Popov  * VC flags
74681a5bbeSBoris Popov  */
75681a5bbeSBoris Popov #define SMBV_PERMANENT		0x0002
76681a5bbeSBoris Popov #define SMBV_LONGNAMES		0x0004	/* connection is configured to use long names */
77681a5bbeSBoris Popov #define	SMBV_ENCRYPT		0x0008	/* server asked for encrypted password */
78681a5bbeSBoris Popov #define	SMBV_WIN95		0x0010	/* used to apply bugfixes for this OS */
79681a5bbeSBoris Popov #define	SMBV_PRIVATE		0x0020	/* connection can be used only by creator */
80681a5bbeSBoris Popov #define	SMBV_RECONNECTING	0x0040	/* conn is in the process of reconnection */
81fc75194cSBoris Popov #define SMBV_SINGLESHARE	0x0080	/* only one share connecting should be allowed */
82fc75194cSBoris Popov #define SMBV_CREATE		0x0100	/* lookup for create operation */
83681a5bbeSBoris Popov /*#define SMBV_FAILED		0x0200*/	/* last reconnect attempt has failed */
84daa35dedSBoris Popov #define SMBV_UNICODE		0x0400	/* connection is configured to use Unicode */
85681a5bbeSBoris Popov 
86681a5bbeSBoris Popov 
87681a5bbeSBoris Popov /*
88681a5bbeSBoris Popov  * smb_share flags
89681a5bbeSBoris Popov  */
90681a5bbeSBoris Popov #define SMBS_PERMANENT		0x0001
91681a5bbeSBoris Popov #define SMBS_RECONNECTING	0x0002
92681a5bbeSBoris Popov #define SMBS_CONNECTED		0x0004
93681a5bbeSBoris Popov 
94681a5bbeSBoris Popov /*
95681a5bbeSBoris Popov  * share types
96681a5bbeSBoris Popov  */
97681a5bbeSBoris Popov #define	SMB_ST_DISK		0x0	/* A: */
98681a5bbeSBoris Popov #define	SMB_ST_PRINTER		0x1	/* LPT: */
99681a5bbeSBoris Popov #define	SMB_ST_PIPE		0x2	/* IPC */
100681a5bbeSBoris Popov #define	SMB_ST_COMM		0x3	/* COMM */
101681a5bbeSBoris Popov #define	SMB_ST_ANY		0x4
102681a5bbeSBoris Popov #define	SMB_ST_MAX		0x4
103681a5bbeSBoris Popov #define SMB_ST_NONE		0xff	/* not a part of protocol */
104681a5bbeSBoris Popov 
105681a5bbeSBoris Popov /*
106681a5bbeSBoris Popov  * Negotiated protocol parameters
107681a5bbeSBoris Popov  */
108681a5bbeSBoris Popov struct smb_sopt {
109681a5bbeSBoris Popov 	int		sv_proto;
110681a5bbeSBoris Popov 	int16_t		sv_tz;		/* offset in min relative to UTC */
111681a5bbeSBoris Popov 	u_int32_t	sv_maxtx;	/* maximum transmit buf size */
112681a5bbeSBoris Popov 	u_char		sv_sm;		/* security mode */
113681a5bbeSBoris Popov 	u_int16_t	sv_maxmux;	/* max number of outstanding rq's */
114681a5bbeSBoris Popov 	u_int16_t 	sv_maxvcs;	/* max number of VCs */
115681a5bbeSBoris Popov 	u_int16_t	sv_rawmode;
116681a5bbeSBoris Popov 	u_int32_t	sv_maxraw;	/* maximum raw-buffer size */
117681a5bbeSBoris Popov 	u_int32_t	sv_skey;	/* session key */
118fc75194cSBoris Popov 	u_int32_t	sv_caps;	/* capabilities SMB_CAP_ */
119681a5bbeSBoris Popov };
120681a5bbeSBoris Popov 
121681a5bbeSBoris Popov /*
122681a5bbeSBoris Popov  * network IO daemon states
123681a5bbeSBoris Popov  */
124681a5bbeSBoris Popov enum smbiod_state {
125681a5bbeSBoris Popov 	SMBIOD_ST_NOTCONN,	/* no connect request was made */
126681a5bbeSBoris Popov 	SMBIOD_ST_RECONNECT,	/* a [re]connect attempt is in progress */
127681a5bbeSBoris Popov 	SMBIOD_ST_TRANACTIVE,	/* transport level is up */
128681a5bbeSBoris Popov 	SMBIOD_ST_VCACTIVE,	/* session established */
129681a5bbeSBoris Popov 	SMBIOD_ST_DEAD		/* connection broken, transport is down */
130681a5bbeSBoris Popov };
131681a5bbeSBoris Popov 
132681a5bbeSBoris Popov 
133681a5bbeSBoris Popov /*
134681a5bbeSBoris Popov  * Info structures
135681a5bbeSBoris Popov  */
136681a5bbeSBoris Popov #define	SMB_INFO_NONE		0
137681a5bbeSBoris Popov #define	SMB_INFO_VC		2
138681a5bbeSBoris Popov #define	SMB_INFO_SHARE		3
139681a5bbeSBoris Popov 
140681a5bbeSBoris Popov struct smb_vc_info {
141681a5bbeSBoris Popov 	int		itype;
142681a5bbeSBoris Popov 	int		usecount;
143681a5bbeSBoris Popov 	uid_t		uid;		/* user id of connection */
144681a5bbeSBoris Popov 	gid_t		gid;		/* group of connection */
145681a5bbeSBoris Popov 	mode_t		mode;		/* access mode */
146681a5bbeSBoris Popov 	int		flags;
147681a5bbeSBoris Popov 	enum smbiod_state iodstate;
148681a5bbeSBoris Popov 	struct smb_sopt	sopt;
14993e3ed5aSTim J. Robbins 	char		srvname[SMB_MAXSRVNAMELEN + 1];
150681a5bbeSBoris Popov 	char		vcname[128];
151681a5bbeSBoris Popov };
152681a5bbeSBoris Popov 
153681a5bbeSBoris Popov struct smb_share_info {
154681a5bbeSBoris Popov 	int		itype;
155681a5bbeSBoris Popov 	int		usecount;
156681a5bbeSBoris Popov 	u_short		tid;		/* TID */
157681a5bbeSBoris Popov 	int		type;		/* share type */
158681a5bbeSBoris Popov 	uid_t		uid;		/* user id of connection */
159681a5bbeSBoris Popov 	gid_t		gid;		/* group of connection */
160681a5bbeSBoris Popov 	mode_t		mode;		/* access mode */
161681a5bbeSBoris Popov 	int		flags;
162681a5bbeSBoris Popov 	char		sname[128];
163681a5bbeSBoris Popov };
164681a5bbeSBoris Popov 
165681a5bbeSBoris Popov #ifdef _KERNEL
166681a5bbeSBoris Popov 
1672c55fd74SBruce Evans #include <sys/lockmgr.h>
168681a5bbeSBoris Popov #include <netsmb/smb_subr.h>
169681a5bbeSBoris Popov 
170681a5bbeSBoris Popov #define CONNADDREQ(a1,a2)	((a1)->sa_len == (a2)->sa_len && \
171681a5bbeSBoris Popov 				 bcmp(a1, a2, (a1)->sa_len) == 0)
172681a5bbeSBoris Popov 
173681a5bbeSBoris Popov struct smb_vc;
174681a5bbeSBoris Popov struct smb_share;
175681a5bbeSBoris Popov struct smb_cred;
176681a5bbeSBoris Popov struct smb_rq;
177681a5bbeSBoris Popov struct mbdata;
178681a5bbeSBoris Popov struct smbioc_oshare;
179681a5bbeSBoris Popov struct smbioc_ossn;
180681a5bbeSBoris Popov struct uio;
181681a5bbeSBoris Popov 
182681a5bbeSBoris Popov TAILQ_HEAD(smb_rqhead, smb_rq);
183681a5bbeSBoris Popov 
184681a5bbeSBoris Popov #define SMB_DEFRQTIMO	5
185681a5bbeSBoris Popov 
186681a5bbeSBoris Popov #define SMB_DIALECT(vcp)	((vcp)->vc_sopt.sv_proto)
187681a5bbeSBoris Popov 
188681a5bbeSBoris Popov struct smb_tran_desc;
189681a5bbeSBoris Popov 
190681a5bbeSBoris Popov /*
191681a5bbeSBoris Popov  * Connection object
192681a5bbeSBoris Popov  */
193681a5bbeSBoris Popov struct smb_connobj;
194681a5bbeSBoris Popov 
195681a5bbeSBoris Popov typedef void smb_co_gone_t (struct smb_connobj *cp, struct smb_cred *scred);
196681a5bbeSBoris Popov typedef void smb_co_free_t (struct smb_connobj *cp);
197681a5bbeSBoris Popov 
198681a5bbeSBoris Popov #define	SMB_CO_LOCK(cp)		smb_sl_lock(&(cp)->co_interlock)
199681a5bbeSBoris Popov #define	SMB_CO_UNLOCK(cp)	smb_sl_unlock(&(cp)->co_interlock)
200681a5bbeSBoris Popov 
201681a5bbeSBoris Popov struct smb_connobj {
202681a5bbeSBoris Popov 	int			co_level;	/* SMBL_ */
203681a5bbeSBoris Popov 	int			co_flags;
204681a5bbeSBoris Popov 	struct lock		co_lock;
205681a5bbeSBoris Popov 	struct smb_slock	co_interlock;
206681a5bbeSBoris Popov 	int			co_usecount;
207681a5bbeSBoris Popov 	struct smb_connobj *	co_parent;
208681a5bbeSBoris Popov 	SLIST_HEAD(,smb_connobj)co_children;
209681a5bbeSBoris Popov 	SLIST_ENTRY(smb_connobj)co_next;
210681a5bbeSBoris Popov 	smb_co_gone_t *		co_gone;
211681a5bbeSBoris Popov 	smb_co_free_t *		co_free;
212681a5bbeSBoris Popov };
213681a5bbeSBoris Popov 
214681a5bbeSBoris Popov #define	SMBCO_FOREACH(var, cp)	SLIST_FOREACH((var), &(cp)->co_children, co_next)
215681a5bbeSBoris Popov 
216681a5bbeSBoris Popov /*
217681a5bbeSBoris Popov  * Virtual Circuit (session) to a server.
218681a5bbeSBoris Popov  * This is the most (over)complicated part of SMB protocol.
219681a5bbeSBoris Popov  * For the user security level (usl), each session with different remote
220681a5bbeSBoris Popov  * user name has its own VC.
221681a5bbeSBoris Popov  * It is unclear however, should share security level (ssl) allow additional
222681a5bbeSBoris Popov  * VCs, because user name is not used and can be the same. On other hand,
223681a5bbeSBoris Popov  * multiple VCs allows us to create separate sessions to server on a per
224681a5bbeSBoris Popov  * user basis.
225681a5bbeSBoris Popov  */
226681a5bbeSBoris Popov 
227681a5bbeSBoris Popov /*
228681a5bbeSBoris Popov  * This lock protects vc_flags
229681a5bbeSBoris Popov  */
230681a5bbeSBoris Popov #define	SMBC_ST_LOCK(vcp)	smb_sl_lock(&(vcp)->vc_stlock)
231681a5bbeSBoris Popov #define	SMBC_ST_UNLOCK(vcp)	smb_sl_unlock(&(vcp)->vc_stlock)
232681a5bbeSBoris Popov 
233681a5bbeSBoris Popov 
234681a5bbeSBoris Popov struct smb_vc {
235681a5bbeSBoris Popov 	struct smb_connobj obj;
236681a5bbeSBoris Popov 	char *		vc_srvname;
237681a5bbeSBoris Popov 	struct sockaddr*vc_paddr;	/* server addr */
238681a5bbeSBoris Popov 	struct sockaddr*vc_laddr;	/* local addr, if any */
239681a5bbeSBoris Popov 	char *		vc_username;
240681a5bbeSBoris Popov 	char *		vc_pass;	/* password for usl case */
241681a5bbeSBoris Popov 	char *		vc_domain;	/* workgroup/primary domain */
242681a5bbeSBoris Popov 
243681a5bbeSBoris Popov 	u_int		vc_timo;	/* default request timeout */
244681a5bbeSBoris Popov 	int		vc_maxvcs;	/* maximum number of VC per connection */
245681a5bbeSBoris Popov 
246681a5bbeSBoris Popov 	void *		vc_tolower;	/* local charset */
247681a5bbeSBoris Popov 	void *		vc_toupper;	/* local charset */
248681a5bbeSBoris Popov 	void *		vc_toserver;	/* local charset to server one */
249681a5bbeSBoris Popov 	void *		vc_tolocal;	/* server charset to local one */
250681a5bbeSBoris Popov 	int		vc_number;	/* number of this VC from the client side */
251681a5bbeSBoris Popov 	int		vc_genid;
252681a5bbeSBoris Popov 	uid_t		vc_uid;		/* user id of connection */
253681a5bbeSBoris Popov 	gid_t		vc_grp;		/* group of connection */
254681a5bbeSBoris Popov 	mode_t		vc_mode;	/* access mode */
255681a5bbeSBoris Popov 	struct tnode *	vc_tnode;	/* backing object */
256681a5bbeSBoris Popov 	u_short		vc_smbuid;	/* unique vc id assigned by server */
257681a5bbeSBoris Popov 
258681a5bbeSBoris Popov 	u_char		vc_hflags;	/* or'ed with flags in the smb header */
259681a5bbeSBoris Popov 	u_short		vc_hflags2;	/* or'ed with flags in the smb header */
260681a5bbeSBoris Popov 	void *		vc_tdata;	/* transport control block */
261681a5bbeSBoris Popov 	struct smb_tran_desc *vc_tdesc;
262681a5bbeSBoris Popov 	int		vc_chlen;	/* actual challenge length */
263681a5bbeSBoris Popov 	u_char 		vc_ch[SMB_MAXCHALLENGELEN];
264681a5bbeSBoris Popov 	u_short		vc_mid;		/* multiplex id */
265681a5bbeSBoris Popov 	struct smb_sopt	vc_sopt;	/* server options */
266681a5bbeSBoris Popov 	int		vc_txmax;	/* max tx/rx packet size */
267e2a70cffSBoris Popov 	int		vc_rxmax;	/* max readx data size */
268e2a70cffSBoris Popov 	int		vc_wxmax;	/* max writex data size */
269681a5bbeSBoris Popov 	struct smbiod *	vc_iod;
270681a5bbeSBoris Popov 	struct smb_slock vc_stlock;
271190b2c4fSTim J. Robbins 	u_int32_t	vc_seqno;	/* my next sequence number */
272190b2c4fSTim J. Robbins 	u_int8_t	*vc_mackey;	/* MAC key */
273190b2c4fSTim J. Robbins 	int		vc_mackeylen;	/* length of MAC key */
274681a5bbeSBoris Popov };
275681a5bbeSBoris Popov 
276681a5bbeSBoris Popov #define vc_maxmux	vc_sopt.sv_maxmux
277681a5bbeSBoris Popov #define	vc_flags	obj.co_flags
278681a5bbeSBoris Popov 
27970f9b9d9SBoris Popov #define SMB_UNICODE_STRINGS(vcp)	((vcp)->vc_hflags2 & SMB_FLAGS2_UNICODE)
280681a5bbeSBoris Popov 
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);
366fce6fbfaSBoris Popov int  smb_co_lock(struct smb_connobj *cp, int flags, struct thread *td);
367fce6fbfaSBoris Popov void smb_co_unlock(struct smb_connobj *cp, int flags, struct thread *td);
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);
380fce6fbfaSBoris Popov int  smb_vc_lock(struct smb_vc *vcp, int flags, struct thread *td);
381fce6fbfaSBoris Popov void smb_vc_unlock(struct smb_vc *vcp, int flags, struct thread *td);
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);
397fce6fbfaSBoris Popov int  smb_share_lock(struct smb_share *ssp, int flags, struct thread *td);
398fce6fbfaSBoris Popov void smb_share_unlock(struct smb_share *ssp, int flags, struct thread *td);
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