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