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 * $FreeBSD: head/sys/netsmb/smb_conn.h 78208 2001-06-14 11:05:01Z bp $
|
32 * $FreeBSD: head/sys/netsmb/smb_conn.h 87192 2001-12-02 08:47:29Z bp $ |
33 */ 34 35/* 36 * Two levels of connection hierarchy 37 */ 38#define SMBL_SM 0 39#define SMBL_VC 1 40#define SMBL_SHARE 2 41#define SMBL_NUM 3 42#define SMBL_NONE (-1) 43 44#define SMB_CS_NONE 0x0000 45#define SMB_CS_UPPER 0x0001 /* convert passed string to upper case */ 46#define SMB_CS_LOWER 0x0002 /* convert passed string to lower case */ 47 48/* 49 * Common object flags 50 */ 51#define SMBO_GONE 0x1000000 52 53/* 54 * access modes 55 */ 56#define SMBM_READ 0400 /* read conn attrs.(like list shares) */ 57#define SMBM_WRITE 0200 /* modify conn attrs */ 58#define SMBM_EXEC 0100 /* can send SMB requests */ 59#define SMBM_READGRP 0040 60#define SMBM_WRITEGRP 0020 61#define SMBM_EXECGRP 0010 62#define SMBM_READOTH 0004 63#define SMBM_WRITEOTH 0002 64#define SMBM_EXECOTH 0001 65#define SMBM_MASK 0777 66#define SMBM_EXACT 010000 /* check for specified mode exactly */ 67#define SMBM_ALL (SMBM_READ | SMBM_WRITE | SMBM_EXEC) 68#define SMBM_DEFAULT (SMBM_READ | SMBM_WRITE | SMBM_EXEC) 69#define SMBM_ANY_OWNER ((uid_t)-1) 70#define SMBM_ANY_GROUP ((gid_t)-1) 71 72/* 73 * VC flags 74 */ 75#define SMBV_PERMANENT 0x0002 76#define SMBV_LONGNAMES 0x0004 /* connection is configured to use long names */ 77#define SMBV_ENCRYPT 0x0008 /* server asked for encrypted password */ 78#define SMBV_WIN95 0x0010 /* used to apply bugfixes for this OS */ 79#define SMBV_PRIVATE 0x0020 /* connection can be used only by creator */ 80#define SMBV_RECONNECTING 0x0040 /* conn is in the process of reconnection */ 81#define SMBV_SINGLESHARE 0x0080 /* only one share connectin should be allowed */ 82#define SMBV_CREATE 0x0100 /* lookup for create opeartion */ 83/*#define SMBV_FAILED 0x0200*/ /* last reconnect attempt has failed */ 84 85 86/* 87 * smb_share flags 88 */ 89#define SMBS_PERMANENT 0x0001 90#define SMBS_RECONNECTING 0x0002 91#define SMBS_CONNECTED 0x0004 92 93/* 94 * share types 95 */ 96#define SMB_ST_DISK 0x0 /* A: */ 97#define SMB_ST_PRINTER 0x1 /* LPT: */ 98#define SMB_ST_PIPE 0x2 /* IPC */ 99#define SMB_ST_COMM 0x3 /* COMM */ 100#define SMB_ST_ANY 0x4 101#define SMB_ST_MAX 0x4 102#define SMB_ST_NONE 0xff /* not a part of protocol */ 103 104/* 105 * Negotiated protocol parameters 106 */ 107struct smb_sopt { 108 int sv_proto; 109 int16_t sv_tz; /* offset in min relative to UTC */ 110 u_int32_t sv_maxtx; /* maximum transmit buf size */ 111 u_char sv_sm; /* security mode */ 112 u_int16_t sv_maxmux; /* max number of outstanding rq's */ 113 u_int16_t sv_maxvcs; /* max number of VCs */ 114 u_int16_t sv_rawmode; 115 u_int32_t sv_maxraw; /* maximum raw-buffer size */ 116 u_int32_t sv_skey; /* session key */ 117 u_int32_t sv_caps; /* capabilites SMB_CAP_ */ 118}; 119 120/* 121 * network IO daemon states 122 */ 123enum smbiod_state { 124 SMBIOD_ST_NOTCONN, /* no connect request was made */ 125 SMBIOD_ST_RECONNECT, /* a [re]connect attempt is in progress */ 126 SMBIOD_ST_TRANACTIVE, /* transport level is up */ 127 SMBIOD_ST_VCACTIVE, /* session established */ 128 SMBIOD_ST_DEAD /* connection broken, transport is down */ 129}; 130 131 132/* 133 * Info structures 134 */ 135#define SMB_INFO_NONE 0 136#define SMB_INFO_VC 2 137#define SMB_INFO_SHARE 3 138 139struct smb_vc_info { 140 int itype; 141 int usecount; 142 uid_t uid; /* user id of connection */ 143 gid_t gid; /* group of connection */ 144 mode_t mode; /* access mode */ 145 int flags; 146 enum smbiod_state iodstate; 147 struct smb_sopt sopt; 148 char srvname[SMB_MAXSRVNAMELEN]; 149 char vcname[128]; 150}; 151 152struct smb_share_info { 153 int itype; 154 int usecount; 155 u_short tid; /* TID */ 156 int type; /* share type */ 157 uid_t uid; /* user id of connection */ 158 gid_t gid; /* group of connection */ 159 mode_t mode; /* access mode */ 160 int flags; 161 char sname[128]; 162}; 163 164#ifdef _KERNEL 165 166#include <sys/lock.h> 167#include <netsmb/smb_subr.h> 168 169#define CONNADDREQ(a1,a2) ((a1)->sa_len == (a2)->sa_len && \ 170 bcmp(a1, a2, (a1)->sa_len) == 0) 171 172struct smb_vc; 173struct smb_share; 174struct smb_cred; 175struct smb_rq; 176struct mbdata; 177struct smbioc_oshare; 178struct smbioc_ossn; 179struct uio; 180 181TAILQ_HEAD(smb_rqhead, smb_rq); 182 183#define SMB_DEFRQTIMO 5 184 185#define SMB_DIALECT(vcp) ((vcp)->vc_sopt.sv_proto) 186 187struct smb_tran_desc; 188 189/* 190 * Connection object 191 */ 192struct smb_connobj; 193 194typedef void smb_co_gone_t (struct smb_connobj *cp, struct smb_cred *scred); 195typedef 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 200struct 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 233struct 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 u_int vc_timo; /* default request timeout */ 243 int vc_maxvcs; /* maximum number of VC per connection */ 244 245 void * vc_tolower; /* local charset */ 246 void * vc_toupper; /* local charset */ 247 void * vc_toserver; /* local charset to server one */ 248 void * vc_tolocal; /* server charset to local one */ 249 int vc_number; /* number of this VC from the client side */ 250 int vc_genid; 251 uid_t vc_uid; /* user id of connection */ 252 gid_t vc_grp; /* group of connection */ 253 mode_t vc_mode; /* access mode */ 254 struct tnode * vc_tnode; /* backing object */ 255 u_short vc_smbuid; /* unique vc id assigned by server */ 256 257 u_char vc_hflags; /* or'ed with flags in the smb header */ 258 u_short vc_hflags2; /* or'ed with flags in the smb header */ 259 void * vc_tdata; /* transport control block */ 260 struct smb_tran_desc *vc_tdesc; 261 int vc_chlen; /* actual challenge length */ 262 u_char vc_ch[SMB_MAXCHALLENGELEN]; 263 u_short vc_mid; /* multiplex id */ 264 struct smb_sopt vc_sopt; /* server options */
|
265 struct smb_cred*vc_scred; /* used in reconnect procedure */
|
265 int vc_txmax; /* max tx/rx packet size */ 266 struct smbiod * vc_iod; 267 struct smb_slock vc_stlock; 268}; 269 270#define vc_maxmux vc_sopt.sv_maxmux 271#define vc_flags obj.co_flags 272 273 274/* 275 * smb_share structure describes connection to the given SMB share (tree). 276 * Connection to share is always built on top of the VC. 277 */ 278 279/* 280 * This lock protects ss_flags 281 */ 282#define SMBS_ST_LOCK(ssp) smb_sl_lock(&(ssp)->ss_stlock) 283#define SMBS_ST_LOCKPTR(ssp) (&(ssp)->ss_stlock) 284#define SMBS_ST_UNLOCK(ssp) smb_sl_unlock(&(ssp)->ss_stlock) 285 286struct smb_share { 287 struct smb_connobj obj; 288 char * ss_name; 289 u_short ss_tid; /* TID */ 290 int ss_type; /* share type */ 291 uid_t ss_uid; /* user id of connection */ 292 gid_t ss_grp; /* group of connection */ 293 mode_t ss_mode; /* access mode */ 294 int ss_vcgenid; 295 char * ss_pass; /* password to a share, can be null */ 296 struct smb_slock ss_stlock;
|
298 struct smb_cred *ss_cred; /* used in reconnect procedure */
|
297}; 298 299#define ss_flags obj.co_flags 300 301#define CPTOVC(cp) ((struct smb_vc*)(cp)) 302#define VCTOCP(vcp) (&(vcp)->obj) 303#define CPTOSS(cp) ((struct smb_share*)(cp)) 304#define SSTOVC(ssp) CPTOVC(((ssp)->obj.co_parent)) 305#define SSTOCP(ssp) (&(ssp)->obj) 306 307struct smb_vcspec { 308 char * srvname; 309 struct sockaddr*sap; 310 struct sockaddr*lap; 311 int flags; 312 char * username; 313 char * pass; 314 char * domain; 315 mode_t mode; 316 mode_t rights; 317 uid_t owner; 318 gid_t group; 319 char * localcs; 320 char * servercs; 321 struct smb_sharespec *shspec; 322 struct smb_share *ssp; /* returned */ 323 /* 324 * The rest is an internal data 325 */ 326 struct smb_cred *scred; 327}; 328 329struct smb_sharespec { 330 char * name; 331 char * pass; 332 mode_t mode; 333 mode_t rights; 334 uid_t owner; 335 gid_t group; 336 int stype; 337 /* 338 * The rest is an internal data 339 */ 340 struct smb_cred *scred; 341}; 342 343/* 344 * Session level functions 345 */ 346int smb_sm_init(void); 347int smb_sm_done(void); 348int smb_sm_lookup(struct smb_vcspec *vcspec, 349 struct smb_sharespec *shspec, struct smb_cred *scred, 350 struct smb_vc **vcpp); 351 352/* 353 * Connection object 354 */
|
357void smb_co_ref(struct smb_connobj *cp, struct proc *p);
|
355void smb_co_ref(struct smb_connobj *cp); |
356void smb_co_rele(struct smb_connobj *cp, struct smb_cred *scred); 357int smb_co_get(struct smb_connobj *cp, int flags, struct smb_cred *scred); 358void smb_co_put(struct smb_connobj *cp, struct smb_cred *scred);
|
361int smb_co_lock(struct smb_connobj *cp, int flags, struct proc *p);
362void smb_co_unlock(struct smb_connobj *cp, int flags, struct proc *p);
|
359int smb_co_lock(struct smb_connobj *cp, int flags, struct thread *td); 360void smb_co_unlock(struct smb_connobj *cp, int flags, struct thread *td); |
361 362/* 363 * session level functions 364 */ 365int smb_vc_create(struct smb_vcspec *vcspec, 366 struct smb_cred *scred, struct smb_vc **vcpp); 367int smb_vc_connect(struct smb_vc *vcp, struct smb_cred *scred); 368int smb_vc_access(struct smb_vc *vcp, struct smb_cred *scred, mode_t mode); 369int smb_vc_get(struct smb_vc *vcp, int flags, struct smb_cred *scred); 370void smb_vc_put(struct smb_vc *vcp, struct smb_cred *scred);
|
373void smb_vc_ref(struct smb_vc *vcp, struct proc *p);
|
371void smb_vc_ref(struct smb_vc *vcp); |
372void smb_vc_rele(struct smb_vc *vcp, struct smb_cred *scred);
|
375int smb_vc_lock(struct smb_vc *vcp, int flags, struct proc *p);
376void smb_vc_unlock(struct smb_vc *vcp, int flags, struct proc *p);
|
373int smb_vc_lock(struct smb_vc *vcp, int flags, struct thread *td); 374void smb_vc_unlock(struct smb_vc *vcp, int flags, struct thread *td); |
375int smb_vc_lookupshare(struct smb_vc *vcp, struct smb_sharespec *shspec, 376 struct smb_cred *scred, struct smb_share **sspp); 377const char * smb_vc_getpass(struct smb_vc *vcp); 378u_short smb_vc_nextmid(struct smb_vc *vcp); 379 380/* 381 * share level functions 382 */ 383int smb_share_create(struct smb_vc *vcp, struct smb_sharespec *shspec, 384 struct smb_cred *scred, struct smb_share **sspp); 385int smb_share_access(struct smb_share *ssp, struct smb_cred *scred, mode_t mode);
|
388void smb_share_ref(struct smb_share *ssp, struct proc *p);
|
386void smb_share_ref(struct smb_share *ssp); |
387void smb_share_rele(struct smb_share *ssp, struct smb_cred *scred); 388int smb_share_get(struct smb_share *ssp, int flags, struct smb_cred *scred); 389void smb_share_put(struct smb_share *ssp, struct smb_cred *scred);
|
392int smb_share_lock(struct smb_share *ssp, int flags, struct proc *p);
393void smb_share_unlock(struct smb_share *ssp, int flags, struct proc *p);
|
390int smb_share_lock(struct smb_share *ssp, int flags, struct thread *td); 391void smb_share_unlock(struct smb_share *ssp, int flags, struct thread *td); |
392void smb_share_invalidate(struct smb_share *ssp); 393int smb_share_valid(struct smb_share *ssp); 394const char * smb_share_getpass(struct smb_share *ssp); 395 396/* 397 * SMB protocol level functions 398 */ 399int smb_smb_negotiate(struct smb_vc *vcp, struct smb_cred *scred); 400int smb_smb_ssnsetup(struct smb_vc *vcp, struct smb_cred *scred); 401int smb_smb_ssnclose(struct smb_vc *vcp, struct smb_cred *scred); 402int smb_smb_treeconnect(struct smb_share *ssp, struct smb_cred *scred); 403int smb_smb_treedisconnect(struct smb_share *ssp, struct smb_cred *scred); 404int smb_read(struct smb_share *ssp, u_int16_t fid, struct uio *uio, 405 struct smb_cred *scred); 406int smb_write(struct smb_share *ssp, u_int16_t fid, struct uio *uio, 407 struct smb_cred *scred); 408int smb_smb_echo(struct smb_vc *vcp, struct smb_cred *scred); 409 410/* 411 * smbiod thread 412 */ 413 414#define SMBIOD_EV_NEWRQ 0x0001 415#define SMBIOD_EV_SHUTDOWN 0x0002 416#define SMBIOD_EV_CONNECT 0x0003 417#define SMBIOD_EV_DISCONNECT 0x0004 418#define SMBIOD_EV_TREECONNECT 0x0005 419#define SMBIOD_EV_MASK 0x00ff 420#define SMBIOD_EV_SYNC 0x0100 421#define SMBIOD_EV_PROCESSING 0x0200 422 423struct smbiod_event { 424 int ev_type; 425 int ev_error; 426 void * ev_ident; 427 STAILQ_ENTRY(smbiod_event) ev_link; 428}; 429 430#define SMBIOD_SHUTDOWN 0x0001 431 432struct smbiod { 433 int iod_id; 434 int iod_flags; 435 enum smbiod_state iod_state; 436 int iod_muxcnt; /* number of active outstanding requests */ 437 int iod_sleeptimo; 438 struct smb_vc * iod_vc; 439 struct smb_slock iod_rqlock; /* iod_rqlist, iod_muxwant */ 440 struct smb_rqhead iod_rqlist; /* list of outstanding requests */ 441 int iod_muxwant; 442 struct proc * iod_p;
|
443 struct thread * iod_td; |
444 struct smb_cred iod_scred; 445 struct smb_slock iod_evlock; /* iod_evlist */ 446 STAILQ_HEAD(,smbiod_event) iod_evlist; 447 struct timespec iod_lastrqsent; 448 struct timespec iod_pingtimo; 449}; 450 451int smb_iod_init(void); 452int smb_iod_done(void); 453int smb_iod_create(struct smb_vc *vcp); 454int smb_iod_destroy(struct smbiod *iod); 455int smb_iod_request(struct smbiod *iod, int event, void *ident); 456int smb_iod_addrq(struct smb_rq *rqp); 457int smb_iod_waitrq(struct smb_rq *rqp); 458int smb_iod_removerq(struct smb_rq *rqp); 459 460#endif /* _KERNEL */
|