1681a5bbeSBoris Popov /* 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 */ 84681a5bbeSBoris Popov 85681a5bbeSBoris Popov 86681a5bbeSBoris Popov /* 87681a5bbeSBoris Popov * smb_share flags 88681a5bbeSBoris Popov */ 89681a5bbeSBoris Popov #define SMBS_PERMANENT 0x0001 90681a5bbeSBoris Popov #define SMBS_RECONNECTING 0x0002 91681a5bbeSBoris Popov #define SMBS_CONNECTED 0x0004 92681a5bbeSBoris Popov 93681a5bbeSBoris Popov /* 94681a5bbeSBoris Popov * share types 95681a5bbeSBoris Popov */ 96681a5bbeSBoris Popov #define SMB_ST_DISK 0x0 /* A: */ 97681a5bbeSBoris Popov #define SMB_ST_PRINTER 0x1 /* LPT: */ 98681a5bbeSBoris Popov #define SMB_ST_PIPE 0x2 /* IPC */ 99681a5bbeSBoris Popov #define SMB_ST_COMM 0x3 /* COMM */ 100681a5bbeSBoris Popov #define SMB_ST_ANY 0x4 101681a5bbeSBoris Popov #define SMB_ST_MAX 0x4 102681a5bbeSBoris Popov #define SMB_ST_NONE 0xff /* not a part of protocol */ 103681a5bbeSBoris Popov 104681a5bbeSBoris Popov /* 105681a5bbeSBoris Popov * Negotiated protocol parameters 106681a5bbeSBoris Popov */ 107681a5bbeSBoris Popov struct smb_sopt { 108681a5bbeSBoris Popov int sv_proto; 109681a5bbeSBoris Popov int16_t sv_tz; /* offset in min relative to UTC */ 110681a5bbeSBoris Popov u_int32_t sv_maxtx; /* maximum transmit buf size */ 111681a5bbeSBoris Popov u_char sv_sm; /* security mode */ 112681a5bbeSBoris Popov u_int16_t sv_maxmux; /* max number of outstanding rq's */ 113681a5bbeSBoris Popov u_int16_t sv_maxvcs; /* max number of VCs */ 114681a5bbeSBoris Popov u_int16_t sv_rawmode; 115681a5bbeSBoris Popov u_int32_t sv_maxraw; /* maximum raw-buffer size */ 116681a5bbeSBoris Popov u_int32_t sv_skey; /* session key */ 117fc75194cSBoris Popov u_int32_t sv_caps; /* capabilities SMB_CAP_ */ 118681a5bbeSBoris Popov }; 119681a5bbeSBoris Popov 120681a5bbeSBoris Popov /* 121681a5bbeSBoris Popov * network IO daemon states 122681a5bbeSBoris Popov */ 123681a5bbeSBoris Popov enum smbiod_state { 124681a5bbeSBoris Popov SMBIOD_ST_NOTCONN, /* no connect request was made */ 125681a5bbeSBoris Popov SMBIOD_ST_RECONNECT, /* a [re]connect attempt is in progress */ 126681a5bbeSBoris Popov SMBIOD_ST_TRANACTIVE, /* transport level is up */ 127681a5bbeSBoris Popov SMBIOD_ST_VCACTIVE, /* session established */ 128681a5bbeSBoris Popov SMBIOD_ST_DEAD /* connection broken, transport is down */ 129681a5bbeSBoris Popov }; 130681a5bbeSBoris Popov 131681a5bbeSBoris Popov 132681a5bbeSBoris Popov /* 133681a5bbeSBoris Popov * Info structures 134681a5bbeSBoris Popov */ 135681a5bbeSBoris Popov #define SMB_INFO_NONE 0 136681a5bbeSBoris Popov #define SMB_INFO_VC 2 137681a5bbeSBoris Popov #define SMB_INFO_SHARE 3 138681a5bbeSBoris Popov 139681a5bbeSBoris Popov struct smb_vc_info { 140681a5bbeSBoris Popov int itype; 141681a5bbeSBoris Popov int usecount; 142681a5bbeSBoris Popov uid_t uid; /* user id of connection */ 143681a5bbeSBoris Popov gid_t gid; /* group of connection */ 144681a5bbeSBoris Popov mode_t mode; /* access mode */ 145681a5bbeSBoris Popov int flags; 146681a5bbeSBoris Popov enum smbiod_state iodstate; 147681a5bbeSBoris Popov struct smb_sopt sopt; 148681a5bbeSBoris Popov char srvname[SMB_MAXSRVNAMELEN]; 149681a5bbeSBoris Popov char vcname[128]; 150681a5bbeSBoris Popov }; 151681a5bbeSBoris Popov 152681a5bbeSBoris Popov struct smb_share_info { 153681a5bbeSBoris Popov int itype; 154681a5bbeSBoris Popov int usecount; 155681a5bbeSBoris Popov u_short tid; /* TID */ 156681a5bbeSBoris Popov int type; /* share type */ 157681a5bbeSBoris Popov uid_t uid; /* user id of connection */ 158681a5bbeSBoris Popov gid_t gid; /* group of connection */ 159681a5bbeSBoris Popov mode_t mode; /* access mode */ 160681a5bbeSBoris Popov int flags; 161681a5bbeSBoris Popov char sname[128]; 162681a5bbeSBoris Popov }; 163681a5bbeSBoris Popov 164681a5bbeSBoris Popov #ifdef _KERNEL 165681a5bbeSBoris Popov 166681a5bbeSBoris Popov #include <sys/lock.h> 167681a5bbeSBoris Popov #include <netsmb/smb_subr.h> 168681a5bbeSBoris Popov 169681a5bbeSBoris Popov #define CONNADDREQ(a1,a2) ((a1)->sa_len == (a2)->sa_len && \ 170681a5bbeSBoris Popov bcmp(a1, a2, (a1)->sa_len) == 0) 171681a5bbeSBoris Popov 172681a5bbeSBoris Popov struct smb_vc; 173681a5bbeSBoris Popov struct smb_share; 174681a5bbeSBoris Popov struct smb_cred; 175681a5bbeSBoris Popov struct smb_rq; 176681a5bbeSBoris Popov struct mbdata; 177681a5bbeSBoris Popov struct smbioc_oshare; 178681a5bbeSBoris Popov struct smbioc_ossn; 179681a5bbeSBoris Popov struct uio; 180681a5bbeSBoris Popov 181681a5bbeSBoris Popov TAILQ_HEAD(smb_rqhead, smb_rq); 182681a5bbeSBoris Popov 183681a5bbeSBoris Popov #define SMB_DEFRQTIMO 5 184681a5bbeSBoris Popov 185681a5bbeSBoris Popov #define SMB_DIALECT(vcp) ((vcp)->vc_sopt.sv_proto) 186681a5bbeSBoris Popov 187681a5bbeSBoris Popov struct smb_tran_desc; 188681a5bbeSBoris Popov 189681a5bbeSBoris Popov /* 190681a5bbeSBoris Popov * Connection object 191681a5bbeSBoris Popov */ 192681a5bbeSBoris Popov struct smb_connobj; 193681a5bbeSBoris Popov 194681a5bbeSBoris Popov typedef void smb_co_gone_t (struct smb_connobj *cp, struct smb_cred *scred); 195681a5bbeSBoris Popov typedef void smb_co_free_t (struct smb_connobj *cp); 196681a5bbeSBoris Popov 197681a5bbeSBoris Popov #define SMB_CO_LOCK(cp) smb_sl_lock(&(cp)->co_interlock) 198681a5bbeSBoris Popov #define SMB_CO_UNLOCK(cp) smb_sl_unlock(&(cp)->co_interlock) 199681a5bbeSBoris Popov 200681a5bbeSBoris Popov struct smb_connobj { 201681a5bbeSBoris Popov int co_level; /* SMBL_ */ 202681a5bbeSBoris Popov int co_flags; 203681a5bbeSBoris Popov struct lock co_lock; 204681a5bbeSBoris Popov struct smb_slock co_interlock; 205681a5bbeSBoris Popov int co_usecount; 206681a5bbeSBoris Popov struct smb_connobj * co_parent; 207681a5bbeSBoris Popov SLIST_HEAD(,smb_connobj)co_children; 208681a5bbeSBoris Popov SLIST_ENTRY(smb_connobj)co_next; 209681a5bbeSBoris Popov smb_co_gone_t * co_gone; 210681a5bbeSBoris Popov smb_co_free_t * co_free; 211681a5bbeSBoris Popov }; 212681a5bbeSBoris Popov 213681a5bbeSBoris Popov #define SMBCO_FOREACH(var, cp) SLIST_FOREACH((var), &(cp)->co_children, co_next) 214681a5bbeSBoris Popov 215681a5bbeSBoris Popov /* 216681a5bbeSBoris Popov * Virtual Circuit (session) to a server. 217681a5bbeSBoris Popov * This is the most (over)complicated part of SMB protocol. 218681a5bbeSBoris Popov * For the user security level (usl), each session with different remote 219681a5bbeSBoris Popov * user name has its own VC. 220681a5bbeSBoris Popov * It is unclear however, should share security level (ssl) allow additional 221681a5bbeSBoris Popov * VCs, because user name is not used and can be the same. On other hand, 222681a5bbeSBoris Popov * multiple VCs allows us to create separate sessions to server on a per 223681a5bbeSBoris Popov * user basis. 224681a5bbeSBoris Popov */ 225681a5bbeSBoris Popov 226681a5bbeSBoris Popov /* 227681a5bbeSBoris Popov * This lock protects vc_flags 228681a5bbeSBoris Popov */ 229681a5bbeSBoris Popov #define SMBC_ST_LOCK(vcp) smb_sl_lock(&(vcp)->vc_stlock) 230681a5bbeSBoris Popov #define SMBC_ST_UNLOCK(vcp) smb_sl_unlock(&(vcp)->vc_stlock) 231681a5bbeSBoris Popov 232681a5bbeSBoris Popov 233681a5bbeSBoris Popov struct smb_vc { 234681a5bbeSBoris Popov struct smb_connobj obj; 235681a5bbeSBoris Popov char * vc_srvname; 236681a5bbeSBoris Popov struct sockaddr*vc_paddr; /* server addr */ 237681a5bbeSBoris Popov struct sockaddr*vc_laddr; /* local addr, if any */ 238681a5bbeSBoris Popov char * vc_username; 239681a5bbeSBoris Popov char * vc_pass; /* password for usl case */ 240681a5bbeSBoris Popov char * vc_domain; /* workgroup/primary domain */ 241681a5bbeSBoris Popov 242681a5bbeSBoris Popov u_int vc_timo; /* default request timeout */ 243681a5bbeSBoris Popov int vc_maxvcs; /* maximum number of VC per connection */ 244681a5bbeSBoris Popov 245681a5bbeSBoris Popov void * vc_tolower; /* local charset */ 246681a5bbeSBoris Popov void * vc_toupper; /* local charset */ 247681a5bbeSBoris Popov void * vc_toserver; /* local charset to server one */ 248681a5bbeSBoris Popov void * vc_tolocal; /* server charset to local one */ 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 struct tnode * vc_tnode; /* backing object */ 255681a5bbeSBoris Popov u_short vc_smbuid; /* unique vc id assigned by server */ 256681a5bbeSBoris Popov 257681a5bbeSBoris Popov u_char vc_hflags; /* or'ed with flags in the smb header */ 258681a5bbeSBoris Popov u_short vc_hflags2; /* or'ed with flags in the smb header */ 259681a5bbeSBoris Popov void * vc_tdata; /* transport control block */ 260681a5bbeSBoris Popov struct smb_tran_desc *vc_tdesc; 261681a5bbeSBoris Popov int vc_chlen; /* actual challenge length */ 262681a5bbeSBoris Popov u_char vc_ch[SMB_MAXCHALLENGELEN]; 263681a5bbeSBoris Popov u_short vc_mid; /* multiplex id */ 264681a5bbeSBoris Popov struct smb_sopt vc_sopt; /* server options */ 265681a5bbeSBoris Popov int vc_txmax; /* max tx/rx packet size */ 266681a5bbeSBoris Popov struct smbiod * vc_iod; 267681a5bbeSBoris Popov struct smb_slock vc_stlock; 268681a5bbeSBoris Popov }; 269681a5bbeSBoris Popov 270681a5bbeSBoris Popov #define vc_maxmux vc_sopt.sv_maxmux 271681a5bbeSBoris Popov #define vc_flags obj.co_flags 272681a5bbeSBoris Popov 273681a5bbeSBoris Popov 274681a5bbeSBoris Popov /* 275681a5bbeSBoris Popov * smb_share structure describes connection to the given SMB share (tree). 276681a5bbeSBoris Popov * Connection to share is always built on top of the VC. 277681a5bbeSBoris Popov */ 278681a5bbeSBoris Popov 279681a5bbeSBoris Popov /* 280681a5bbeSBoris Popov * This lock protects ss_flags 281681a5bbeSBoris Popov */ 282681a5bbeSBoris Popov #define SMBS_ST_LOCK(ssp) smb_sl_lock(&(ssp)->ss_stlock) 283681a5bbeSBoris Popov #define SMBS_ST_LOCKPTR(ssp) (&(ssp)->ss_stlock) 284681a5bbeSBoris Popov #define SMBS_ST_UNLOCK(ssp) smb_sl_unlock(&(ssp)->ss_stlock) 285681a5bbeSBoris Popov 286681a5bbeSBoris Popov struct smb_share { 287681a5bbeSBoris Popov struct smb_connobj obj; 288681a5bbeSBoris Popov char * ss_name; 289681a5bbeSBoris Popov u_short ss_tid; /* TID */ 290681a5bbeSBoris Popov int ss_type; /* share type */ 291681a5bbeSBoris Popov uid_t ss_uid; /* user id of connection */ 292681a5bbeSBoris Popov gid_t ss_grp; /* group of connection */ 293681a5bbeSBoris Popov mode_t ss_mode; /* access mode */ 294681a5bbeSBoris Popov int ss_vcgenid; 295681a5bbeSBoris Popov char * ss_pass; /* password to a share, can be null */ 296681a5bbeSBoris Popov struct smb_slock ss_stlock; 297681a5bbeSBoris Popov }; 298681a5bbeSBoris Popov 299681a5bbeSBoris Popov #define ss_flags obj.co_flags 300681a5bbeSBoris Popov 301681a5bbeSBoris Popov #define CPTOVC(cp) ((struct smb_vc*)(cp)) 302681a5bbeSBoris Popov #define VCTOCP(vcp) (&(vcp)->obj) 303681a5bbeSBoris Popov #define CPTOSS(cp) ((struct smb_share*)(cp)) 304681a5bbeSBoris Popov #define SSTOVC(ssp) CPTOVC(((ssp)->obj.co_parent)) 305681a5bbeSBoris Popov #define SSTOCP(ssp) (&(ssp)->obj) 306681a5bbeSBoris Popov 307681a5bbeSBoris Popov struct smb_vcspec { 308681a5bbeSBoris Popov char * srvname; 309681a5bbeSBoris Popov struct sockaddr*sap; 310681a5bbeSBoris Popov struct sockaddr*lap; 311681a5bbeSBoris Popov int flags; 312681a5bbeSBoris Popov char * username; 313681a5bbeSBoris Popov char * pass; 314681a5bbeSBoris Popov char * domain; 315681a5bbeSBoris Popov mode_t mode; 316681a5bbeSBoris Popov mode_t rights; 317681a5bbeSBoris Popov uid_t owner; 318681a5bbeSBoris Popov gid_t group; 319681a5bbeSBoris Popov char * localcs; 320681a5bbeSBoris Popov char * servercs; 321681a5bbeSBoris Popov struct smb_sharespec *shspec; 322681a5bbeSBoris Popov struct smb_share *ssp; /* returned */ 323681a5bbeSBoris Popov /* 324681a5bbeSBoris Popov * The rest is an internal data 325681a5bbeSBoris Popov */ 326681a5bbeSBoris Popov struct smb_cred *scred; 327681a5bbeSBoris Popov }; 328681a5bbeSBoris Popov 329681a5bbeSBoris Popov struct smb_sharespec { 330681a5bbeSBoris Popov char * name; 331681a5bbeSBoris Popov char * pass; 332681a5bbeSBoris Popov mode_t mode; 333681a5bbeSBoris Popov mode_t rights; 334681a5bbeSBoris Popov uid_t owner; 335681a5bbeSBoris Popov gid_t group; 336681a5bbeSBoris Popov int stype; 337681a5bbeSBoris Popov /* 338681a5bbeSBoris Popov * The rest is an internal data 339681a5bbeSBoris Popov */ 340681a5bbeSBoris Popov struct smb_cred *scred; 341681a5bbeSBoris Popov }; 342681a5bbeSBoris Popov 343681a5bbeSBoris Popov /* 344681a5bbeSBoris Popov * Session level functions 345681a5bbeSBoris Popov */ 346681a5bbeSBoris Popov int smb_sm_init(void); 347681a5bbeSBoris Popov int smb_sm_done(void); 348681a5bbeSBoris Popov int smb_sm_lookup(struct smb_vcspec *vcspec, 349681a5bbeSBoris Popov struct smb_sharespec *shspec, struct smb_cred *scred, 350681a5bbeSBoris Popov struct smb_vc **vcpp); 351681a5bbeSBoris Popov 352681a5bbeSBoris Popov /* 353681a5bbeSBoris Popov * Connection object 354681a5bbeSBoris Popov */ 355fce6fbfaSBoris Popov void smb_co_ref(struct smb_connobj *cp); 356681a5bbeSBoris Popov void smb_co_rele(struct smb_connobj *cp, struct smb_cred *scred); 357681a5bbeSBoris Popov int smb_co_get(struct smb_connobj *cp, int flags, struct smb_cred *scred); 358681a5bbeSBoris Popov void smb_co_put(struct smb_connobj *cp, struct smb_cred *scred); 359fce6fbfaSBoris Popov int smb_co_lock(struct smb_connobj *cp, int flags, struct thread *td); 360fce6fbfaSBoris Popov void smb_co_unlock(struct smb_connobj *cp, int flags, struct thread *td); 361681a5bbeSBoris Popov 362681a5bbeSBoris Popov /* 363681a5bbeSBoris Popov * session level functions 364681a5bbeSBoris Popov */ 365681a5bbeSBoris Popov int smb_vc_create(struct smb_vcspec *vcspec, 366681a5bbeSBoris Popov struct smb_cred *scred, struct smb_vc **vcpp); 367681a5bbeSBoris Popov int smb_vc_connect(struct smb_vc *vcp, struct smb_cred *scred); 368681a5bbeSBoris Popov int smb_vc_access(struct smb_vc *vcp, struct smb_cred *scred, mode_t mode); 369681a5bbeSBoris Popov int smb_vc_get(struct smb_vc *vcp, int flags, struct smb_cred *scred); 370681a5bbeSBoris Popov void smb_vc_put(struct smb_vc *vcp, struct smb_cred *scred); 371fce6fbfaSBoris Popov void smb_vc_ref(struct smb_vc *vcp); 372681a5bbeSBoris Popov void smb_vc_rele(struct smb_vc *vcp, struct smb_cred *scred); 373fce6fbfaSBoris Popov int smb_vc_lock(struct smb_vc *vcp, int flags, struct thread *td); 374fce6fbfaSBoris Popov void smb_vc_unlock(struct smb_vc *vcp, int flags, struct thread *td); 375681a5bbeSBoris Popov int smb_vc_lookupshare(struct smb_vc *vcp, struct smb_sharespec *shspec, 376681a5bbeSBoris Popov struct smb_cred *scred, struct smb_share **sspp); 377681a5bbeSBoris Popov const char * smb_vc_getpass(struct smb_vc *vcp); 378681a5bbeSBoris Popov u_short smb_vc_nextmid(struct smb_vc *vcp); 379681a5bbeSBoris Popov 380681a5bbeSBoris Popov /* 381681a5bbeSBoris Popov * share level functions 382681a5bbeSBoris Popov */ 383681a5bbeSBoris Popov int smb_share_create(struct smb_vc *vcp, struct smb_sharespec *shspec, 384681a5bbeSBoris Popov struct smb_cred *scred, struct smb_share **sspp); 385681a5bbeSBoris Popov int smb_share_access(struct smb_share *ssp, struct smb_cred *scred, mode_t mode); 386fce6fbfaSBoris Popov void smb_share_ref(struct smb_share *ssp); 387681a5bbeSBoris Popov void smb_share_rele(struct smb_share *ssp, struct smb_cred *scred); 388681a5bbeSBoris Popov int smb_share_get(struct smb_share *ssp, int flags, struct smb_cred *scred); 389681a5bbeSBoris Popov void smb_share_put(struct smb_share *ssp, struct smb_cred *scred); 390fce6fbfaSBoris Popov int smb_share_lock(struct smb_share *ssp, int flags, struct thread *td); 391fce6fbfaSBoris Popov void smb_share_unlock(struct smb_share *ssp, int flags, struct thread *td); 392681a5bbeSBoris Popov void smb_share_invalidate(struct smb_share *ssp); 393681a5bbeSBoris Popov int smb_share_valid(struct smb_share *ssp); 394681a5bbeSBoris Popov const char * smb_share_getpass(struct smb_share *ssp); 395681a5bbeSBoris Popov 396681a5bbeSBoris Popov /* 397681a5bbeSBoris Popov * SMB protocol level functions 398681a5bbeSBoris Popov */ 399681a5bbeSBoris Popov int smb_smb_negotiate(struct smb_vc *vcp, struct smb_cred *scred); 400681a5bbeSBoris Popov int smb_smb_ssnsetup(struct smb_vc *vcp, struct smb_cred *scred); 401681a5bbeSBoris Popov int smb_smb_ssnclose(struct smb_vc *vcp, struct smb_cred *scred); 402681a5bbeSBoris Popov int smb_smb_treeconnect(struct smb_share *ssp, struct smb_cred *scred); 403681a5bbeSBoris Popov int smb_smb_treedisconnect(struct smb_share *ssp, struct smb_cred *scred); 404681a5bbeSBoris Popov int smb_read(struct smb_share *ssp, u_int16_t fid, struct uio *uio, 405681a5bbeSBoris Popov struct smb_cred *scred); 406681a5bbeSBoris Popov int smb_write(struct smb_share *ssp, u_int16_t fid, struct uio *uio, 407681a5bbeSBoris Popov struct smb_cred *scred); 408681a5bbeSBoris Popov int smb_smb_echo(struct smb_vc *vcp, struct smb_cred *scred); 409681a5bbeSBoris Popov 410681a5bbeSBoris Popov /* 411681a5bbeSBoris Popov * smbiod thread 412681a5bbeSBoris Popov */ 413681a5bbeSBoris Popov 414681a5bbeSBoris Popov #define SMBIOD_EV_NEWRQ 0x0001 415681a5bbeSBoris Popov #define SMBIOD_EV_SHUTDOWN 0x0002 416681a5bbeSBoris Popov #define SMBIOD_EV_CONNECT 0x0003 417681a5bbeSBoris Popov #define SMBIOD_EV_DISCONNECT 0x0004 418681a5bbeSBoris Popov #define SMBIOD_EV_TREECONNECT 0x0005 419681a5bbeSBoris Popov #define SMBIOD_EV_MASK 0x00ff 420681a5bbeSBoris Popov #define SMBIOD_EV_SYNC 0x0100 421681a5bbeSBoris Popov #define SMBIOD_EV_PROCESSING 0x0200 422681a5bbeSBoris Popov 423681a5bbeSBoris Popov struct smbiod_event { 424681a5bbeSBoris Popov int ev_type; 425681a5bbeSBoris Popov int ev_error; 426681a5bbeSBoris Popov void * ev_ident; 427681a5bbeSBoris Popov STAILQ_ENTRY(smbiod_event) ev_link; 428681a5bbeSBoris Popov }; 429681a5bbeSBoris Popov 430681a5bbeSBoris Popov #define SMBIOD_SHUTDOWN 0x0001 431681a5bbeSBoris Popov 432681a5bbeSBoris Popov struct smbiod { 433681a5bbeSBoris Popov int iod_id; 434681a5bbeSBoris Popov int iod_flags; 435681a5bbeSBoris Popov enum smbiod_state iod_state; 436681a5bbeSBoris Popov int iod_muxcnt; /* number of active outstanding requests */ 437681a5bbeSBoris Popov int iod_sleeptimo; 438681a5bbeSBoris Popov struct smb_vc * iod_vc; 439681a5bbeSBoris Popov struct smb_slock iod_rqlock; /* iod_rqlist, iod_muxwant */ 440681a5bbeSBoris Popov struct smb_rqhead iod_rqlist; /* list of outstanding requests */ 441681a5bbeSBoris Popov int iod_muxwant; 442681a5bbeSBoris Popov struct proc * iod_p; 443fce6fbfaSBoris Popov struct thread * iod_td; 444681a5bbeSBoris Popov struct smb_cred iod_scred; 445681a5bbeSBoris Popov struct smb_slock iod_evlock; /* iod_evlist */ 446681a5bbeSBoris Popov STAILQ_HEAD(,smbiod_event) iod_evlist; 447681a5bbeSBoris Popov struct timespec iod_lastrqsent; 448681a5bbeSBoris Popov struct timespec iod_pingtimo; 449681a5bbeSBoris Popov }; 450681a5bbeSBoris Popov 451681a5bbeSBoris Popov int smb_iod_init(void); 452681a5bbeSBoris Popov int smb_iod_done(void); 453681a5bbeSBoris Popov int smb_iod_create(struct smb_vc *vcp); 454681a5bbeSBoris Popov int smb_iod_destroy(struct smbiod *iod); 455681a5bbeSBoris Popov int smb_iod_request(struct smbiod *iod, int event, void *ident); 456681a5bbeSBoris Popov int smb_iod_addrq(struct smb_rq *rqp); 457681a5bbeSBoris Popov int smb_iod_waitrq(struct smb_rq *rqp); 458681a5bbeSBoris Popov int smb_iod_removerq(struct smb_rq *rqp); 459681a5bbeSBoris Popov 460681a5bbeSBoris Popov #endif /* _KERNEL */ 461