FreeBSD/Linux Kernel Cross Reference
sys/netsmb/smb_conn.h
1 /* $NetBSD: smb_conn.h,v 1.14 2003/06/29 22:32:09 fvdl Exp $ */
2
3 /*
4 * Copyright (c) 2000-2001 Boris Popov
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Boris Popov.
18 * 4. Neither the name of the author nor the names of any co-contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * FreeBSD: src/sys/netsmb/smb_conn.h,v 1.8 2002/09/16 10:50:38 bp Exp
35 */
36
37 /*
38 * Two levels of connection hierarchy
39 */
40 #define SMBL_SM 0
41 #define SMBL_VC 1
42 #define SMBL_SHARE 2
43 #define SMBL_NUM 3
44 #define SMBL_NONE (-1)
45
46 #define SMB_CS_NONE 0x0000
47 #define SMB_CS_UPPER 0x0001 /* convert passed string to upper case */
48 #define SMB_CS_LOWER 0x0002 /* convert passed string to lower case */
49
50 /*
51 * Common object flags
52 */
53 #define SMBO_GONE 0x1000000
54
55 /*
56 * access modes
57 */
58 #define SMBM_READ 0400 /* read conn attrs.(like list shares) */
59 #define SMBM_WRITE 0200 /* modify conn attrs */
60 #define SMBM_EXEC 0100 /* can send SMB requests */
61 #define SMBM_READGRP 0040
62 #define SMBM_WRITEGRP 0020
63 #define SMBM_EXECGRP 0010
64 #define SMBM_READOTH 0004
65 #define SMBM_WRITEOTH 0002
66 #define SMBM_EXECOTH 0001
67 #define SMBM_MASK 0777
68 #define SMBM_EXACT 010000 /* check for specified mode exactly */
69 #define SMBM_ALL (SMBM_READ | SMBM_WRITE | SMBM_EXEC)
70 #define SMBM_DEFAULT (SMBM_READ | SMBM_WRITE | SMBM_EXEC)
71 #define SMBM_ANY_OWNER ((uid_t)-1)
72 #define SMBM_ANY_GROUP ((gid_t)-1)
73
74 /*
75 * VC flags
76 */
77 #define SMBV_PERMANENT 0x0002
78 #define SMBV_LONGNAMES 0x0004 /* connection is configured to use long names */
79 #define SMBV_ENCRYPT 0x0008 /* server asked for encrypted password */
80 #define SMBV_WIN95 0x0010 /* used to apply bugfixes for this OS */
81 #define SMBV_PRIVATE 0x0020 /* connection can be used only by creator */
82 #define SMBV_RECONNECTING 0x0040 /* conn is in the process of reconnection */
83 #define SMBV_SINGLESHARE 0x0080 /* only one share connecting should be allowed */
84 #define SMBV_CREATE 0x0100 /* lookup for create operation */
85 /*#define SMBV_FAILED 0x0200*/ /* last reconnect attempt has failed */
86 #define SMBV_UNICODE 0x0400 /* connection is configured to use Unicode */
87
88
89 /*
90 * smb_share flags
91 */
92 #define SMBS_PERMANENT 0x0001
93 #define SMBS_RECONNECTING 0x0002
94 #define SMBS_CONNECTED 0x0004
95
96 /*
97 * share types
98 */
99 #define SMB_ST_DISK 0x0 /* A: */
100 #define SMB_ST_PRINTER 0x1 /* LPT: */
101 #define SMB_ST_PIPE 0x2 /* IPC */
102 #define SMB_ST_COMM 0x3 /* COMM */
103 #define SMB_ST_ANY 0x4
104 #define SMB_ST_MAX 0x4
105 #define SMB_ST_NONE 0xff /* not a part of protocol */
106
107 /*
108 * Negotiated protocol parameters
109 */
110 struct smb_sopt {
111 int sv_proto;
112 int16_t sv_tz; /* offset in min relative to UTC */
113 u_int32_t sv_maxtx; /* maximum transmit buf size */
114 u_int16_t sv_sm; /* security mode */
115 u_int16_t sv_maxmux; /* max number of outstanding rq's */
116 u_int16_t sv_maxvcs; /* max number of VCs */
117 u_int16_t sv_rawmode;
118 u_int32_t sv_maxraw; /* maximum raw-buffer size */
119 u_int32_t sv_skey; /* session key */
120 u_int32_t sv_caps; /* capabilities SMB_CAP_ */
121 };
122
123 /*
124 * network IO daemon states
125 */
126 enum smbiod_state {
127 SMBIOD_ST_NOTCONN, /* no connect request was made */
128 SMBIOD_ST_RECONNECT, /* a [re]connect attempt is in progress */
129 SMBIOD_ST_TRANACTIVE, /* transport level is up */
130 SMBIOD_ST_VCACTIVE, /* session established */
131 SMBIOD_ST_DEAD /* connection broken, transport is down */
132 };
133
134
135 /*
136 * Info structures
137 */
138 #define SMB_INFO_NONE 0
139 #define SMB_INFO_VC 2
140 #define SMB_INFO_SHARE 3
141
142 struct smb_vc_info {
143 int itype;
144 int usecount;
145 uid_t uid; /* user id of connection */
146 gid_t gid; /* group of connection */
147 mode_t mode; /* access mode */
148 int flags;
149 enum smbiod_state iodstate;
150 struct smb_sopt sopt;
151 char srvname[SMB_MAXSRVNAMELEN];
152 char vcname[128];
153 };
154
155 struct smb_share_info {
156 int itype;
157 int usecount;
158 u_short tid; /* TID */
159 int type; /* share type */
160 uid_t uid; /* user id of connection */
161 gid_t gid; /* group of connection */
162 mode_t mode; /* access mode */
163 int flags;
164 char sname[128];
165 };
166
167 #ifdef _KERNEL
168
169 #include <sys/lock.h>
170 #include <netsmb/smb_subr.h>
171
172 #define CONNADDREQ(a1,a2) ((a1)->sa_len == (a2)->sa_len && \
173 bcmp(a1, a2, (a1)->sa_len) == 0)
174
175 struct smb_vc;
176 struct smb_share;
177 struct smb_cred;
178 struct smb_rq;
179 struct mbdata;
180 struct smbioc_oshare;
181 struct smbioc_ossn;
182 struct uio;
183
184 #define SMB_DIALECT(vcp) ((vcp)->vc_sopt.sv_proto)
185 #define SMB_CAPS(vcp) ((vcp)->vc_sopt.sv_caps)
186
187 struct smb_tran_desc;
188
189 /*
190 * Connection object
191 */
192 struct smb_connobj;
193
194 typedef void smb_co_gone_t (struct smb_connobj *cp, struct smb_cred *scred);
195 typedef void smb_co_free_t (struct smb_connobj *cp);
196
197 #define SMB_CO_LOCK(cp) smb_sl_lock(&(cp)->co_interlock)
198 #define SMB_CO_UNLOCK(cp) smb_sl_unlock(&(cp)->co_interlock)
199
200 struct smb_connobj {
201 int co_level; /* SMBL_ */
202 int co_flags;
203 struct lock co_lock;
204 struct smb_slock co_interlock;
205 int co_usecount;
206 struct smb_connobj * co_parent;
207 SLIST_HEAD(,smb_connobj)co_children;
208 SLIST_ENTRY(smb_connobj)co_next;
209 smb_co_gone_t * co_gone;
210 smb_co_free_t * co_free;
211 };
212
213 #define SMBCO_FOREACH(var, cp) SLIST_FOREACH((var), &(cp)->co_children, co_next)
214
215 /*
216 * Virtual Circuit (session) to a server.
217 * This is the most (over)complicated part of SMB protocol.
218 * For the user security level (usl), each session with different remote
219 * user name has its own VC.
220 * It is unclear however, should share security level (ssl) allow additional
221 * VCs, because user name is not used and can be the same. On other hand,
222 * multiple VCs allows us to create separate sessions to server on a per
223 * user basis.
224 */
225
226 /*
227 * This lock protects vc_flags
228 */
229 #define SMBC_ST_LOCK(vcp) smb_sl_lock(&(vcp)->vc_stlock)
230 #define SMBC_ST_UNLOCK(vcp) smb_sl_unlock(&(vcp)->vc_stlock)
231
232
233 struct smb_vc {
234 struct smb_connobj obj;
235 char * vc_srvname;
236 struct sockaddr*vc_paddr; /* server addr */
237 struct sockaddr*vc_laddr; /* local addr, if any */
238 char * vc_username;
239 char * vc_pass; /* password for usl case */
240 char * vc_domain; /* workgroup/primary domain */
241
242 int vc_maxvcs; /* maximum number of VC per connection */
243
244 void * vc_tolower; /* local charset */
245 void * vc_toupper; /* local charset */
246 void * vc_toserver; /* local charset to server one */
247 void * vc_tolocal; /* server charset to local one */
248 int vc_number; /* number of this VC from the client side */
249 int vc_genid;
250 uid_t vc_uid; /* user id of connection */
251 gid_t vc_grp; /* group of connection */
252 mode_t vc_mode; /* access mode */
253 struct tnode * vc_tnode; /* backing object */
254 u_short vc_smbuid; /* unique vc id assigned by server */
255
256 u_char vc_hflags; /* or'ed with flags in the smb header */
257 u_short vc_hflags2; /* or'ed with flags in the smb header */
258 void * vc_tdata; /* transport control block */
259 struct smb_tran_desc *vc_tdesc;
260 int vc_chlen; /* actual challenge length */
261 u_char vc_ch[SMB_MAXCHALLENGELEN];
262 u_short vc_mid; /* multiplex id */
263 struct smb_sopt vc_sopt; /* server options */
264 size_t vc_txmax; /* max tx/rx packet size */
265 size_t vc_rxmax; /* max readx data size */
266 size_t vc_wxmax; /* max writex data size */
267 struct smbiod * vc_iod;
268 struct smb_slock vc_stlock;
269 };
270
271 #define vc_maxmux vc_sopt.sv_maxmux
272 #define vc_flags obj.co_flags
273
274 #define SMB_UNICODE_STRINGS(vcp) ((vcp)->vc_hflags2 & SMB_FLAGS2_UNICODE)
275
276 /*
277 * smb_share structure describes connection to the given SMB share (tree).
278 * Connection to share is always built on top of the VC.
279 */
280
281 /*
282 * This lock protects ss_flags
283 */
284 #define SMBS_ST_LOCK(ssp) smb_sl_lock(&(ssp)->ss_stlock)
285 #define SMBS_ST_LOCKPTR(ssp) (&(ssp)->ss_stlock)
286 #define SMBS_ST_UNLOCK(ssp) smb_sl_unlock(&(ssp)->ss_stlock)
287
288 struct smb_share {
289 struct smb_connobj obj;
290 char * ss_name;
291 u_short ss_tid; /* TID */
292 int ss_type; /* share type */
293 uid_t ss_uid; /* user id of connection */
294 gid_t ss_grp; /* group of connection */
295 mode_t ss_mode; /* access mode */
296 int ss_vcgenid;
297 char * ss_pass; /* password to a share, can be null */
298 struct smb_slock ss_stlock;
299 };
300
301 #define ss_flags obj.co_flags
302
303 #define CPTOVC(cp) ((struct smb_vc*)(cp))
304 #define VCTOCP(vcp) (&(vcp)->obj)
305 #define CPTOSS(cp) ((struct smb_share*)(cp))
306 #define SSTOVC(ssp) CPTOVC(((ssp)->obj.co_parent))
307 #define SSTOCP(ssp) (&(ssp)->obj)
308
309 struct smb_vcspec {
310 char * srvname;
311 struct sockaddr*sap;
312 struct sockaddr*lap;
313 int flags;
314 char * username;
315 char * pass;
316 char * domain;
317 mode_t mode;
318 mode_t rights;
319 uid_t owner;
320 gid_t group;
321 char * localcs;
322 char * servercs;
323 struct smb_sharespec *shspec;
324 struct smb_share *ssp; /* returned */
325 /*
326 * The rest is an internal data
327 */
328 struct smb_cred *scred;
329 };
330
331 struct smb_sharespec {
332 char * name;
333 char * pass;
334 mode_t mode;
335 mode_t rights;
336 uid_t owner;
337 gid_t group;
338 int stype;
339 /*
340 * The rest is an internal data
341 */
342 struct smb_cred *scred;
343 };
344
345 /*
346 * Session level functions
347 */
348 int smb_sm_init(void);
349 int smb_sm_done(void);
350 int smb_sm_lookup(struct smb_vcspec *vcspec,
351 struct smb_sharespec *shspec, struct smb_cred *scred,
352 struct smb_vc **vcpp);
353
354 /*
355 * Connection object
356 */
357 void smb_co_ref(struct smb_connobj *cp);
358 void smb_co_rele(struct smb_connobj *cp, struct smb_cred *scred);
359 int smb_co_get(struct smb_connobj *cp, int flags, struct smb_cred *scred);
360 void smb_co_put(struct smb_connobj *cp, struct smb_cred *scred);
361 int smb_co_lock(struct smb_connobj *cp, int flags);
362 void smb_co_unlock(struct smb_connobj *cp, int flags);
363
364 /*
365 * session level functions
366 */
367 int smb_vc_create(struct smb_vcspec *vcspec,
368 struct smb_cred *scred, struct smb_vc **vcpp);
369 int smb_vc_connect(struct smb_vc *vcp, struct smb_cred *scred);
370 int smb_vc_access(struct smb_vc *vcp, struct smb_cred *scred, mode_t mode);
371 int smb_vc_get(struct smb_vc *vcp, int flags, struct smb_cred *scred);
372 void smb_vc_put(struct smb_vc *vcp, struct smb_cred *scred);
373 void smb_vc_ref(struct smb_vc *vcp);
374 void smb_vc_rele(struct smb_vc *vcp, struct smb_cred *scred);
375 int smb_vc_lock(struct smb_vc *vcp, int flags);
376 void smb_vc_unlock(struct smb_vc *vcp, int flags);
377 int smb_vc_lookupshare(struct smb_vc *vcp, struct smb_sharespec *shspec,
378 struct smb_cred *scred, struct smb_share **sspp);
379 const char * smb_vc_getpass(struct smb_vc *vcp);
380 u_short smb_vc_nextmid(struct smb_vc *vcp);
381
382 /*
383 * share level functions
384 */
385 int smb_share_create(struct smb_vc *vcp, struct smb_sharespec *shspec,
386 struct smb_cred *scred, struct smb_share **sspp);
387 int smb_share_access(struct smb_share *ssp, struct smb_cred *scred, mode_t mode);
388 void smb_share_ref(struct smb_share *ssp);
389 void smb_share_rele(struct smb_share *ssp, struct smb_cred *scred);
390 int smb_share_get(struct smb_share *ssp, int flags, struct smb_cred *scred);
391 void smb_share_put(struct smb_share *ssp, struct smb_cred *scred);
392 int smb_share_lock(struct smb_share *ssp, int flags);
393 void smb_share_unlock(struct smb_share *ssp, int flags);
394 int smb_share_valid(struct smb_share *ssp);
395 const char * smb_share_getpass(struct smb_share *ssp);
396
397 /*
398 * SMB protocol level functions
399 */
400 int smb_smb_negotiate(struct smb_vc *vcp, struct smb_cred *scred);
401 int smb_smb_ssnsetup(struct smb_vc *vcp, struct smb_cred *scred);
402 int smb_smb_ssnclose(struct smb_vc *vcp, struct smb_cred *scred);
403 int smb_smb_treeconnect(struct smb_share *ssp, struct smb_cred *scred);
404 int smb_smb_treedisconnect(struct smb_share *ssp, struct smb_cred *scred);
405 int smb_read(struct smb_share *ssp, u_int16_t fid, struct uio *uio,
406 struct smb_cred *scred);
407 int smb_write(struct smb_share *ssp, u_int16_t fid, struct uio *uio,
408 struct smb_cred *scred);
409 #if 0
410 int smb_smb_echo(struct smb_vc *vcp, struct smb_cred *scred);
411 #endif
412
413 /*
414 * smbiod thread
415 */
416
417 #define SMBIOD_EV_NEWRQ 0x0001
418 #define SMBIOD_EV_SHUTDOWN 0x0002
419 #define SMBIOD_EV_CONNECT 0x0003
420 #define SMBIOD_EV_DISCONNECT 0x0004
421 #define SMBIOD_EV_TREECONNECT 0x0005
422 #define SMBIOD_EV_MASK 0x00ff
423 #define SMBIOD_EV_SYNC 0x0100
424 #define SMBIOD_EV_PROCESSING 0x0200
425
426 struct smbiod_event {
427 int ev_type;
428 int ev_error;
429 void * ev_ident;
430 SIMPLEQ_ENTRY(smbiod_event) ev_link;
431 };
432
433 #define SMBIOD_SHUTDOWN 0x0001
434
435 struct smbiod {
436 int iod_id;
437 int iod_flags;
438 enum smbiod_state iod_state;
439 int iod_muxcnt; /* number of active outstanding requests */
440 struct smb_vc * iod_vc;
441 struct smb_slock iod_rqlock; /* iod_rqlist, iod_muxwant */
442 SIMPLEQ_HEAD(, smb_rq)
443 iod_rqlist; /* list of outstanding requests */
444 int iod_muxwant;
445 struct proc * iod_p;
446 #ifndef __NetBSD__
447 struct thread * iod_td;
448 #endif
449 struct smb_cred iod_scred;
450 struct smb_slock iod_evlock; /* iod_evlist */
451 SIMPLEQ_HEAD(,smbiod_event) iod_evlist;
452 #if 0
453 int iod_sleeptimo;
454 struct timeval iod_lastrqsent;
455 struct timeval iod_pingtimo;
456 #endif
457 };
458
459 int smb_iod_init(void);
460 int smb_iod_done(void);
461 int smb_iod_create(struct smb_vc *vcp);
462 int smb_iod_destroy(struct smbiod *iod);
463 int smb_iod_request(struct smbiod *iod, int event, void *ident);
464 int smb_iod_addrq(struct smb_rq *rqp);
465 int smb_iod_waitrq(struct smb_rq *rqp);
466 int smb_iod_removerq(struct smb_rq *rqp);
467
468 #endif /* _KERNEL */
Cache object: d84bee90daf49934e47b0045d31bddde
|