1c398230bSWarner Losh /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3fe267a55SPedro F. Giffuni * 4681a5bbeSBoris Popov * Copyright (c) 2000-2001 Boris Popov 5681a5bbeSBoris Popov * All rights reserved. 6681a5bbeSBoris Popov * 7681a5bbeSBoris Popov * Redistribution and use in source and binary forms, with or without 8681a5bbeSBoris Popov * modification, are permitted provided that the following conditions 9681a5bbeSBoris Popov * are met: 10681a5bbeSBoris Popov * 1. Redistributions of source code must retain the above copyright 11681a5bbeSBoris Popov * notice, this list of conditions and the following disclaimer. 12681a5bbeSBoris Popov * 2. Redistributions in binary form must reproduce the above copyright 13681a5bbeSBoris Popov * notice, this list of conditions and the following disclaimer in the 14681a5bbeSBoris Popov * documentation and/or other materials provided with the distribution. 15681a5bbeSBoris Popov * 16681a5bbeSBoris Popov * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17681a5bbeSBoris Popov * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18681a5bbeSBoris Popov * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19681a5bbeSBoris Popov * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20681a5bbeSBoris Popov * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21681a5bbeSBoris Popov * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22681a5bbeSBoris Popov * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23681a5bbeSBoris Popov * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24681a5bbeSBoris Popov * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25681a5bbeSBoris Popov * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26681a5bbeSBoris Popov * SUCH DAMAGE. 27681a5bbeSBoris Popov */ 28681a5bbeSBoris Popov 29681a5bbeSBoris Popov /* 30681a5bbeSBoris Popov * Two levels of connection hierarchy 31681a5bbeSBoris Popov */ 32681a5bbeSBoris Popov #define SMBL_SM 0 33681a5bbeSBoris Popov #define SMBL_VC 1 34681a5bbeSBoris Popov #define SMBL_SHARE 2 35681a5bbeSBoris Popov #define SMBL_NUM 3 36681a5bbeSBoris Popov #define SMBL_NONE (-1) 37681a5bbeSBoris Popov 38681a5bbeSBoris Popov #define SMB_CS_NONE 0x0000 39681a5bbeSBoris Popov #define SMB_CS_UPPER 0x0001 /* convert passed string to upper case */ 40681a5bbeSBoris Popov #define SMB_CS_LOWER 0x0002 /* convert passed string to lower case */ 41681a5bbeSBoris Popov 42681a5bbeSBoris Popov /* 43681a5bbeSBoris Popov * Common object flags 44681a5bbeSBoris Popov */ 45681a5bbeSBoris Popov #define SMBO_GONE 0x1000000 46681a5bbeSBoris Popov 47681a5bbeSBoris Popov /* 48681a5bbeSBoris Popov * access modes 49681a5bbeSBoris Popov */ 50681a5bbeSBoris Popov #define SMBM_READ 0400 /* read conn attrs.(like list shares) */ 51681a5bbeSBoris Popov #define SMBM_WRITE 0200 /* modify conn attrs */ 52681a5bbeSBoris Popov #define SMBM_EXEC 0100 /* can send SMB requests */ 53681a5bbeSBoris Popov #define SMBM_READGRP 0040 54681a5bbeSBoris Popov #define SMBM_WRITEGRP 0020 55681a5bbeSBoris Popov #define SMBM_EXECGRP 0010 56681a5bbeSBoris Popov #define SMBM_READOTH 0004 57681a5bbeSBoris Popov #define SMBM_WRITEOTH 0002 58681a5bbeSBoris Popov #define SMBM_EXECOTH 0001 59681a5bbeSBoris Popov #define SMBM_MASK 0777 60681a5bbeSBoris Popov #define SMBM_EXACT 010000 /* check for specified mode exactly */ 61681a5bbeSBoris Popov #define SMBM_ALL (SMBM_READ | SMBM_WRITE | SMBM_EXEC) 62681a5bbeSBoris Popov #define SMBM_DEFAULT (SMBM_READ | SMBM_WRITE | SMBM_EXEC) 63681a5bbeSBoris Popov #define SMBM_ANY_OWNER ((uid_t)-1) 64681a5bbeSBoris Popov #define SMBM_ANY_GROUP ((gid_t)-1) 65681a5bbeSBoris Popov 66681a5bbeSBoris Popov /* 67681a5bbeSBoris Popov * VC flags 68681a5bbeSBoris Popov */ 69681a5bbeSBoris Popov #define SMBV_PERMANENT 0x0002 70681a5bbeSBoris Popov #define SMBV_LONGNAMES 0x0004 /* connection is configured to use long names */ 71681a5bbeSBoris Popov #define SMBV_ENCRYPT 0x0008 /* server asked for encrypted password */ 72681a5bbeSBoris Popov #define SMBV_WIN95 0x0010 /* used to apply bugfixes for this OS */ 73681a5bbeSBoris Popov #define SMBV_PRIVATE 0x0020 /* connection can be used only by creator */ 74681a5bbeSBoris Popov #define SMBV_RECONNECTING 0x0040 /* conn is in the process of reconnection */ 75fc75194cSBoris Popov #define SMBV_SINGLESHARE 0x0080 /* only one share connecting should be allowed */ 76fc75194cSBoris Popov #define SMBV_CREATE 0x0100 /* lookup for create operation */ 77681a5bbeSBoris Popov /*#define SMBV_FAILED 0x0200*/ /* last reconnect attempt has failed */ 78daa35dedSBoris Popov #define SMBV_UNICODE 0x0400 /* connection is configured to use Unicode */ 79681a5bbeSBoris Popov 80681a5bbeSBoris Popov /* 81681a5bbeSBoris Popov * smb_share flags 82681a5bbeSBoris Popov */ 83681a5bbeSBoris Popov #define SMBS_PERMANENT 0x0001 84681a5bbeSBoris Popov #define SMBS_RECONNECTING 0x0002 85681a5bbeSBoris Popov #define SMBS_CONNECTED 0x0004 86681a5bbeSBoris Popov 87681a5bbeSBoris Popov /* 88681a5bbeSBoris Popov * share types 89681a5bbeSBoris Popov */ 90681a5bbeSBoris Popov #define SMB_ST_DISK 0x0 /* A: */ 91681a5bbeSBoris Popov #define SMB_ST_PRINTER 0x1 /* LPT: */ 92681a5bbeSBoris Popov #define SMB_ST_PIPE 0x2 /* IPC */ 93681a5bbeSBoris Popov #define SMB_ST_COMM 0x3 /* COMM */ 94681a5bbeSBoris Popov #define SMB_ST_ANY 0x4 95681a5bbeSBoris Popov #define SMB_ST_MAX 0x4 96681a5bbeSBoris Popov #define SMB_ST_NONE 0xff /* not a part of protocol */ 97681a5bbeSBoris Popov 98681a5bbeSBoris Popov /* 99681a5bbeSBoris Popov * Negotiated protocol parameters 100681a5bbeSBoris Popov */ 101681a5bbeSBoris Popov struct smb_sopt { 102681a5bbeSBoris Popov int sv_proto; 103681a5bbeSBoris Popov int16_t sv_tz; /* offset in min relative to UTC */ 104681a5bbeSBoris Popov u_int32_t sv_maxtx; /* maximum transmit buf size */ 105681a5bbeSBoris Popov u_char sv_sm; /* security mode */ 106681a5bbeSBoris Popov u_int16_t sv_maxmux; /* max number of outstanding rq's */ 107681a5bbeSBoris Popov u_int16_t sv_maxvcs; /* max number of VCs */ 108681a5bbeSBoris Popov u_int16_t sv_rawmode; 109681a5bbeSBoris Popov u_int32_t sv_maxraw; /* maximum raw-buffer size */ 110681a5bbeSBoris Popov u_int32_t sv_skey; /* session key */ 111fc75194cSBoris Popov u_int32_t sv_caps; /* capabilities SMB_CAP_ */ 112681a5bbeSBoris Popov }; 113681a5bbeSBoris Popov 114681a5bbeSBoris Popov /* 115681a5bbeSBoris Popov * network IO daemon states 116681a5bbeSBoris Popov */ 117681a5bbeSBoris Popov enum smbiod_state { 118681a5bbeSBoris Popov SMBIOD_ST_NOTCONN, /* no connect request was made */ 119681a5bbeSBoris Popov SMBIOD_ST_RECONNECT, /* a [re]connect attempt is in progress */ 120681a5bbeSBoris Popov SMBIOD_ST_TRANACTIVE, /* transport level is up */ 121681a5bbeSBoris Popov SMBIOD_ST_VCACTIVE, /* session established */ 122681a5bbeSBoris Popov SMBIOD_ST_DEAD /* connection broken, transport is down */ 123681a5bbeSBoris Popov }; 124681a5bbeSBoris Popov 125681a5bbeSBoris Popov /* 126681a5bbeSBoris Popov * Info structures 127681a5bbeSBoris Popov */ 128681a5bbeSBoris Popov #define SMB_INFO_NONE 0 129681a5bbeSBoris Popov #define SMB_INFO_VC 2 130681a5bbeSBoris Popov #define SMB_INFO_SHARE 3 131681a5bbeSBoris Popov 132681a5bbeSBoris Popov struct smb_vc_info { 133681a5bbeSBoris Popov int itype; 134681a5bbeSBoris Popov int usecount; 135681a5bbeSBoris Popov uid_t uid; /* user id of connection */ 136681a5bbeSBoris Popov gid_t gid; /* group of connection */ 137681a5bbeSBoris Popov mode_t mode; /* access mode */ 138681a5bbeSBoris Popov int flags; 139681a5bbeSBoris Popov enum smbiod_state iodstate; 140681a5bbeSBoris Popov struct smb_sopt sopt; 14193e3ed5aSTim J. Robbins char srvname[SMB_MAXSRVNAMELEN + 1]; 142681a5bbeSBoris Popov char vcname[128]; 143681a5bbeSBoris Popov }; 144681a5bbeSBoris Popov 145681a5bbeSBoris Popov struct smb_share_info { 146681a5bbeSBoris Popov int itype; 147681a5bbeSBoris Popov int usecount; 148681a5bbeSBoris Popov u_short tid; /* TID */ 149681a5bbeSBoris Popov int type; /* share type */ 150681a5bbeSBoris Popov uid_t uid; /* user id of connection */ 151681a5bbeSBoris Popov gid_t gid; /* group of connection */ 152681a5bbeSBoris Popov mode_t mode; /* access mode */ 153681a5bbeSBoris Popov int flags; 154681a5bbeSBoris Popov char sname[128]; 155681a5bbeSBoris Popov }; 156681a5bbeSBoris Popov 157681a5bbeSBoris Popov #ifdef _KERNEL 158681a5bbeSBoris Popov 159681a5bbeSBoris Popov #include <netsmb/smb_subr.h> 160a4c05984SDavide Italiano #include <sys/param.h> 161a4c05984SDavide Italiano #include <sys/lock.h> 162a4c05984SDavide Italiano #include <sys/condvar.h> 163a4c05984SDavide Italiano #include <sys/sx.h> 164681a5bbeSBoris Popov 165681a5bbeSBoris Popov #define CONNADDREQ(a1,a2) ((a1)->sa_len == (a2)->sa_len && \ 166681a5bbeSBoris Popov bcmp(a1, a2, (a1)->sa_len) == 0) 167681a5bbeSBoris Popov 168681a5bbeSBoris Popov struct smb_vc; 169681a5bbeSBoris Popov struct smb_share; 170681a5bbeSBoris Popov struct smb_cred; 171681a5bbeSBoris Popov struct smb_rq; 172681a5bbeSBoris Popov struct mbdata; 173681a5bbeSBoris Popov struct smbioc_oshare; 174681a5bbeSBoris Popov struct smbioc_ossn; 175681a5bbeSBoris Popov struct uio; 176681a5bbeSBoris Popov 177681a5bbeSBoris Popov TAILQ_HEAD(smb_rqhead, smb_rq); 178681a5bbeSBoris Popov 179681a5bbeSBoris Popov #define SMB_DEFRQTIMO 5 180681a5bbeSBoris Popov 181681a5bbeSBoris Popov #define SMB_DIALECT(vcp) ((vcp)->vc_sopt.sv_proto) 182681a5bbeSBoris Popov 183681a5bbeSBoris Popov struct smb_tran_desc; 184681a5bbeSBoris Popov 185681a5bbeSBoris Popov /* 186681a5bbeSBoris Popov * Connection object 187681a5bbeSBoris Popov */ 188681a5bbeSBoris Popov struct smb_connobj; 189681a5bbeSBoris Popov 190681a5bbeSBoris Popov typedef void smb_co_gone_t (struct smb_connobj *cp, struct smb_cred *scred); 191681a5bbeSBoris Popov typedef void smb_co_free_t (struct smb_connobj *cp); 192681a5bbeSBoris Popov 193681a5bbeSBoris Popov struct smb_connobj { 194a4c05984SDavide Italiano struct cv co_lock; 195a4c05984SDavide Italiano struct thread *co_locker; 196a4c05984SDavide Italiano struct sx co_interlock; 197a4c05984SDavide Italiano int co_lockcnt; 198681a5bbeSBoris Popov int co_level; /* SMBL_ */ 199681a5bbeSBoris Popov int co_flags; 200681a5bbeSBoris Popov int co_usecount; 201681a5bbeSBoris Popov struct smb_connobj * co_parent; 202681a5bbeSBoris Popov SLIST_HEAD(,smb_connobj)co_children; 203681a5bbeSBoris Popov SLIST_ENTRY(smb_connobj)co_next; 204681a5bbeSBoris Popov smb_co_gone_t * co_gone; 205681a5bbeSBoris Popov smb_co_free_t * co_free; 206681a5bbeSBoris Popov }; 207681a5bbeSBoris Popov 208681a5bbeSBoris Popov #define SMBCO_FOREACH(var, cp) SLIST_FOREACH((var), &(cp)->co_children, co_next) 209681a5bbeSBoris Popov 210681a5bbeSBoris Popov /* 211681a5bbeSBoris Popov * Virtual Circuit (session) to a server. 212681a5bbeSBoris Popov * This is the most (over)complicated part of SMB protocol. 213681a5bbeSBoris Popov * For the user security level (usl), each session with different remote 214681a5bbeSBoris Popov * user name has its own VC. 215681a5bbeSBoris Popov * It is unclear however, should share security level (ssl) allow additional 216681a5bbeSBoris Popov * VCs, because user name is not used and can be the same. On other hand, 217681a5bbeSBoris Popov * multiple VCs allows us to create separate sessions to server on a per 218681a5bbeSBoris Popov * user basis. 219681a5bbeSBoris Popov */ 220681a5bbeSBoris Popov 221681a5bbeSBoris Popov /* 222681a5bbeSBoris Popov * This lock protects vc_flags 223681a5bbeSBoris Popov */ 224681a5bbeSBoris Popov #define SMBC_ST_LOCK(vcp) smb_sl_lock(&(vcp)->vc_stlock) 225681a5bbeSBoris Popov #define SMBC_ST_UNLOCK(vcp) smb_sl_unlock(&(vcp)->vc_stlock) 226681a5bbeSBoris Popov 227681a5bbeSBoris Popov struct smb_vc { 228681a5bbeSBoris Popov struct smb_connobj obj; 229681a5bbeSBoris Popov char * vc_srvname; 230681a5bbeSBoris Popov struct sockaddr*vc_paddr; /* server addr */ 231681a5bbeSBoris Popov struct sockaddr*vc_laddr; /* local addr, if any */ 232681a5bbeSBoris Popov char * vc_username; 233681a5bbeSBoris Popov char * vc_pass; /* password for usl case */ 234681a5bbeSBoris Popov char * vc_domain; /* workgroup/primary domain */ 235681a5bbeSBoris Popov 236681a5bbeSBoris Popov u_int vc_timo; /* default request timeout */ 237681a5bbeSBoris Popov int vc_maxvcs; /* maximum number of VC per connection */ 238681a5bbeSBoris Popov 239681a5bbeSBoris Popov void * vc_tolower; /* local charset */ 240681a5bbeSBoris Popov void * vc_toupper; /* local charset */ 241681a5bbeSBoris Popov void * vc_toserver; /* local charset to server one */ 242681a5bbeSBoris Popov void * vc_tolocal; /* server charset to local one */ 24341f1dcccSKevin Lo void * vc_cp_toserver; /* local charset to server one (using CodePage) */ 24441f1dcccSKevin Lo void * vc_cp_tolocal; /* server charset to local one (using CodePage) */ 24541f1dcccSKevin Lo void * vc_ucs_toserver; /* local charset to server one (using UCS-2) */ 24641f1dcccSKevin Lo void * vc_ucs_tolocal; /* server charset to local one (using UCS-2) */ 247681a5bbeSBoris Popov int vc_number; /* number of this VC from the client side */ 248681a5bbeSBoris Popov int vc_genid; 249681a5bbeSBoris Popov uid_t vc_uid; /* user id of connection */ 250681a5bbeSBoris Popov gid_t vc_grp; /* group of connection */ 251681a5bbeSBoris Popov mode_t vc_mode; /* access mode */ 252681a5bbeSBoris Popov u_short vc_smbuid; /* unique vc id assigned by server */ 253681a5bbeSBoris Popov 254681a5bbeSBoris Popov u_char vc_hflags; /* or'ed with flags in the smb header */ 255681a5bbeSBoris Popov u_short vc_hflags2; /* or'ed with flags in the smb header */ 256681a5bbeSBoris Popov void * vc_tdata; /* transport control block */ 257681a5bbeSBoris Popov struct smb_tran_desc *vc_tdesc; 258681a5bbeSBoris Popov int vc_chlen; /* actual challenge length */ 259681a5bbeSBoris Popov u_char vc_ch[SMB_MAXCHALLENGELEN]; 260681a5bbeSBoris Popov u_short vc_mid; /* multiplex id */ 261681a5bbeSBoris Popov struct smb_sopt vc_sopt; /* server options */ 262681a5bbeSBoris Popov int vc_txmax; /* max tx/rx packet size */ 263e2a70cffSBoris Popov int vc_rxmax; /* max readx data size */ 264e2a70cffSBoris Popov int vc_wxmax; /* max writex data size */ 265681a5bbeSBoris Popov struct smbiod * vc_iod; 266681a5bbeSBoris Popov struct smb_slock vc_stlock; 267190b2c4fSTim J. Robbins u_int32_t vc_seqno; /* my next sequence number */ 268190b2c4fSTim J. Robbins u_int8_t *vc_mackey; /* MAC key */ 269190b2c4fSTim J. Robbins int vc_mackeylen; /* length of MAC key */ 270681a5bbeSBoris Popov }; 271681a5bbeSBoris Popov 272681a5bbeSBoris Popov #define vc_maxmux vc_sopt.sv_maxmux 273681a5bbeSBoris Popov #define vc_flags obj.co_flags 274681a5bbeSBoris Popov 27570f9b9d9SBoris Popov #define SMB_UNICODE_STRINGS(vcp) ((vcp)->vc_hflags2 & SMB_FLAGS2_UNICODE) 276681a5bbeSBoris Popov 27741f1dcccSKevin Lo #define SMB_UNICODE_NAME "UCS-2LE" 27841f1dcccSKevin Lo 279681a5bbeSBoris Popov /* 280681a5bbeSBoris Popov * smb_share structure describes connection to the given SMB share (tree). 281681a5bbeSBoris Popov * Connection to share is always built on top of the VC. 282681a5bbeSBoris Popov */ 283681a5bbeSBoris Popov 284681a5bbeSBoris Popov /* 285681a5bbeSBoris Popov * This lock protects ss_flags 286681a5bbeSBoris Popov */ 287681a5bbeSBoris Popov #define SMBS_ST_LOCK(ssp) smb_sl_lock(&(ssp)->ss_stlock) 288681a5bbeSBoris Popov #define SMBS_ST_LOCKPTR(ssp) (&(ssp)->ss_stlock) 289681a5bbeSBoris Popov #define SMBS_ST_UNLOCK(ssp) smb_sl_unlock(&(ssp)->ss_stlock) 290681a5bbeSBoris Popov 291681a5bbeSBoris Popov struct smb_share { 292681a5bbeSBoris Popov struct smb_connobj obj; 293681a5bbeSBoris Popov char * ss_name; 294681a5bbeSBoris Popov u_short ss_tid; /* TID */ 295681a5bbeSBoris Popov int ss_type; /* share type */ 296681a5bbeSBoris Popov uid_t ss_uid; /* user id of connection */ 297681a5bbeSBoris Popov gid_t ss_grp; /* group of connection */ 298681a5bbeSBoris Popov mode_t ss_mode; /* access mode */ 299681a5bbeSBoris Popov int ss_vcgenid; 300681a5bbeSBoris Popov char * ss_pass; /* password to a share, can be null */ 301681a5bbeSBoris Popov struct smb_slock ss_stlock; 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 */ 360fce6fbfaSBoris Popov void smb_co_ref(struct smb_connobj *cp); 361681a5bbeSBoris Popov void smb_co_rele(struct smb_connobj *cp, struct smb_cred *scred); 362a4c05984SDavide Italiano int smb_co_get(struct smb_connobj *cp, struct smb_cred *scred); 363681a5bbeSBoris Popov void smb_co_put(struct smb_connobj *cp, struct smb_cred *scred); 364a4c05984SDavide Italiano int smb_co_lock(struct smb_connobj *cp); 365a4c05984SDavide Italiano void smb_co_unlock(struct smb_connobj *cp); 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); 374a4c05984SDavide Italiano int smb_vc_get(struct smb_vc *vcp, struct smb_cred *scred); 375681a5bbeSBoris Popov void smb_vc_put(struct smb_vc *vcp, struct smb_cred *scred); 376fce6fbfaSBoris Popov void smb_vc_ref(struct smb_vc *vcp); 377681a5bbeSBoris Popov void smb_vc_rele(struct smb_vc *vcp, struct smb_cred *scred); 378a4c05984SDavide Italiano int smb_vc_lock(struct smb_vc *vcp); 379a4c05984SDavide Italiano void smb_vc_unlock(struct smb_vc *vcp); 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); 391fce6fbfaSBoris Popov void smb_share_ref(struct smb_share *ssp); 392681a5bbeSBoris Popov void smb_share_rele(struct smb_share *ssp, struct smb_cred *scred); 393a4c05984SDavide Italiano int smb_share_get(struct smb_share *ssp, struct smb_cred *scred); 394681a5bbeSBoris Popov void smb_share_put(struct smb_share *ssp, struct smb_cred *scred); 395a4c05984SDavide Italiano int smb_share_lock(struct smb_share *ssp); 396a4c05984SDavide Italiano void smb_share_unlock(struct smb_share *ssp); 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; 448fce6fbfaSBoris Popov struct thread * iod_td; 449681a5bbeSBoris Popov struct smb_cred iod_scred; 450681a5bbeSBoris Popov struct smb_slock iod_evlock; /* iod_evlist */ 451681a5bbeSBoris Popov STAILQ_HEAD(,smbiod_event) iod_evlist; 452681a5bbeSBoris Popov struct timespec iod_lastrqsent; 453681a5bbeSBoris Popov struct timespec iod_pingtimo; 454681a5bbeSBoris Popov }; 455681a5bbeSBoris Popov 456681a5bbeSBoris Popov int smb_iod_init(void); 457681a5bbeSBoris Popov int smb_iod_done(void); 458681a5bbeSBoris Popov int smb_iod_create(struct smb_vc *vcp); 459681a5bbeSBoris Popov int smb_iod_destroy(struct smbiod *iod); 460681a5bbeSBoris Popov int smb_iod_request(struct smbiod *iod, int event, void *ident); 461681a5bbeSBoris Popov int smb_iod_addrq(struct smb_rq *rqp); 462681a5bbeSBoris Popov int smb_iod_waitrq(struct smb_rq *rqp); 463681a5bbeSBoris Popov int smb_iod_removerq(struct smb_rq *rqp); 464681a5bbeSBoris Popov 465681a5bbeSBoris Popov #endif /* _KERNEL */ 466