#define SMBL_SM 0
#define SMBL_VC 1
#define SMBL_SHARE 2
#define SMBL_NUM 3
#define SMBL_NONE (-1)
#define SMB_CS_NONE 0x0000
#define SMB_CS_UPPER 0x0001
#define SMB_CS_LOWER 0x0002
#define SMBO_GONE 0x1000000
#define SMBM_READ 0400
#define SMBM_WRITE 0200
#define SMBM_EXEC 0100
#define SMBM_READGRP 0040
#define SMBM_WRITEGRP 0020
#define SMBM_EXECGRP 0010
#define SMBM_READOTH 0004
#define SMBM_WRITEOTH 0002
#define SMBM_EXECOTH 0001
#define SMBM_MASK 0777
#define SMBM_EXACT 010000
#define SMBM_ALL (SMBM_READ | SMBM_WRITE | SMBM_EXEC)
#define SMBM_DEFAULT (SMBM_READ | SMBM_WRITE | SMBM_EXEC)
#define SMBM_ANY_OWNER ((uid_t)-1)
#define SMBM_ANY_GROUP ((gid_t)-1)
#define SMBV_PERMANENT 0x0002
#define SMBV_LONGNAMES 0x0004
#define SMBV_ENCRYPT 0x0008
#define SMBV_WIN95 0x0010
#define SMBV_PRIVATE 0x0020
#define SMBV_RECONNECTING 0x0040
#define SMBV_SINGLESHARE 0x0080
#define SMBV_CREATE 0x0100
#define SMBV_UNICODE 0x0400
#define SMBS_PERMANENT 0x0001
#define SMBS_RECONNECTING 0x0002
#define SMBS_CONNECTED 0x0004
#define SMB_ST_DISK 0x0
#define SMB_ST_PRINTER 0x1
#define SMB_ST_PIPE 0x2
#define SMB_ST_COMM 0x3
#define SMB_ST_ANY 0x4
#define SMB_ST_MAX 0x4
#define SMB_ST_NONE 0xff
struct smb_sopt {
int sv_proto;
int16_t sv_tz;
u_int32_t sv_maxtx;
u_char sv_sm;
u_int16_t sv_maxmux;
u_int16_t sv_maxvcs;
u_int16_t sv_rawmode;
u_int32_t sv_maxraw;
u_int32_t sv_skey;
u_int32_t sv_caps;
};
enum smbiod_state {
SMBIOD_ST_NOTCONN,
SMBIOD_ST_RECONNECT,
SMBIOD_ST_TRANACTIVE,
SMBIOD_ST_VCACTIVE,
SMBIOD_ST_DEAD
};
#define SMB_INFO_NONE 0
#define SMB_INFO_VC 2
#define SMB_INFO_SHARE 3
struct smb_vc_info {
int itype;
int usecount;
uid_t uid;
gid_t gid;
mode_t mode;
int flags;
enum smbiod_state iodstate;
struct smb_sopt sopt;
char srvname[SMB_MAXSRVNAMELEN + 1];
char vcname[128];
};
struct smb_share_info {
int itype;
int usecount;
u_short tid;
int type;
uid_t uid;
gid_t gid;
mode_t mode;
int flags;
char sname[128];
};
#ifdef _KERNEL
#include <netsmb/smb_subr.h>
#include <sys/param.h>
#include <sys/lock.h>
#include <sys/condvar.h>
#include <sys/sx.h>
#define CONNADDREQ(a1,a2) ((a1)->sa_len == (a2)->sa_len && \
bcmp(a1, a2, (a1)->sa_len) == 0)
struct smb_vc;
struct smb_share;
struct smb_cred;
struct smb_rq;
struct mbdata;
struct smbioc_oshare;
struct smbioc_ossn;
struct uio;
TAILQ_HEAD(smb_rqhead, smb_rq);
#define SMB_DEFRQTIMO 5
#define SMB_DIALECT(vcp) ((vcp)->vc_sopt.sv_proto)
struct smb_tran_desc;
struct smb_connobj;
typedef void smb_co_gone_t (struct smb_connobj *cp, struct smb_cred *scred);
typedef void smb_co_free_t (struct smb_connobj *cp);
struct smb_connobj {
struct cv co_lock;
struct thread *co_locker;
struct sx co_interlock;
int co_lockcnt;
int co_level;
int co_flags;
int co_usecount;
struct smb_connobj * co_parent;
SLIST_HEAD(,smb_connobj)co_children;
SLIST_ENTRY(smb_connobj)co_next;
smb_co_gone_t * co_gone;
smb_co_free_t * co_free;
};
#define SMBCO_FOREACH(var, cp) SLIST_FOREACH((var), &(cp)->co_children, co_next)
#define SMBC_ST_LOCK(vcp) smb_sl_lock(&(vcp)->vc_stlock)
#define SMBC_ST_UNLOCK(vcp) smb_sl_unlock(&(vcp)->vc_stlock)
struct smb_vc {
struct smb_connobj obj;
char * vc_srvname;
struct sockaddr*vc_paddr;
struct sockaddr*vc_laddr;
char * vc_username;
char * vc_pass;
char * vc_domain;
u_int vc_timo;
int vc_maxvcs;
void * vc_tolower;
void * vc_toupper;
void * vc_toserver;
void * vc_tolocal;
void * vc_cp_toserver;
void * vc_cp_tolocal;
void * vc_ucs_toserver;
void * vc_ucs_tolocal;
int vc_number;
int vc_genid;
uid_t vc_uid;
gid_t vc_grp;
mode_t vc_mode;
u_short vc_smbuid;
u_char vc_hflags;
u_short vc_hflags2;
void * vc_tdata;
struct smb_tran_desc *vc_tdesc;
int vc_chlen;
u_char vc_ch[SMB_MAXCHALLENGELEN];
u_short vc_mid;
struct smb_sopt vc_sopt;
int vc_txmax;
int vc_rxmax;
int vc_wxmax;
struct smbiod * vc_iod;
struct smb_slock vc_stlock;
u_int32_t vc_seqno;
u_int8_t *vc_mackey;
int vc_mackeylen;
};
#define vc_maxmux vc_sopt.sv_maxmux
#define vc_flags obj.co_flags
#define SMB_UNICODE_STRINGS(vcp) ((vcp)->vc_hflags2 & SMB_FLAGS2_UNICODE)
#define SMB_UNICODE_NAME "UCS-2LE"
#define SMBS_ST_LOCK(ssp) smb_sl_lock(&(ssp)->ss_stlock)
#define SMBS_ST_LOCKPTR(ssp) (&(ssp)->ss_stlock)
#define SMBS_ST_UNLOCK(ssp) smb_sl_unlock(&(ssp)->ss_stlock)
struct smb_share {
struct smb_connobj obj;
char * ss_name;
u_short ss_tid;
int ss_type;
uid_t ss_uid;
gid_t ss_grp;
mode_t ss_mode;
int ss_vcgenid;
char * ss_pass;
struct smb_slock ss_stlock;
};
#define ss_flags obj.co_flags
#define CPTOVC(cp) ((struct smb_vc*)(cp))
#define VCTOCP(vcp) (&(vcp)->obj)
#define CPTOSS(cp) ((struct smb_share*)(cp))
#define SSTOVC(ssp) CPTOVC(((ssp)->obj.co_parent))
#define SSTOCP(ssp) (&(ssp)->obj)
struct smb_vcspec {
char * srvname;
struct sockaddr*sap;
struct sockaddr*lap;
int flags;
char * username;
char * pass;
char * domain;
mode_t mode;
mode_t rights;
uid_t owner;
gid_t group;
char * localcs;
char * servercs;
struct smb_sharespec *shspec;
struct smb_share *ssp;
struct smb_cred *scred;
};
struct smb_sharespec {
char * name;
char * pass;
mode_t mode;
mode_t rights;
uid_t owner;
gid_t group;
int stype;
struct smb_cred *scred;
};
int smb_sm_init(void);
int smb_sm_done(void);
int smb_sm_lookup(struct smb_vcspec *vcspec,
struct smb_sharespec *shspec, struct smb_cred *scred,
struct smb_vc **vcpp);
void smb_co_ref(struct smb_connobj *cp);
void smb_co_rele(struct smb_connobj *cp, struct smb_cred *scred);
int smb_co_get(struct smb_connobj *cp, struct smb_cred *scred);
void smb_co_put(struct smb_connobj *cp, struct smb_cred *scred);
int smb_co_lock(struct smb_connobj *cp);
void smb_co_unlock(struct smb_connobj *cp);
int smb_vc_create(struct smb_vcspec *vcspec,
struct smb_cred *scred, struct smb_vc **vcpp);
int smb_vc_connect(struct smb_vc *vcp, struct smb_cred *scred);
int smb_vc_access(struct smb_vc *vcp, struct smb_cred *scred, mode_t mode);
int smb_vc_get(struct smb_vc *vcp, struct smb_cred *scred);
void smb_vc_put(struct smb_vc *vcp, struct smb_cred *scred);
void smb_vc_ref(struct smb_vc *vcp);
void smb_vc_rele(struct smb_vc *vcp, struct smb_cred *scred);
int smb_vc_lock(struct smb_vc *vcp);
void smb_vc_unlock(struct smb_vc *vcp);
int smb_vc_lookupshare(struct smb_vc *vcp, struct smb_sharespec *shspec,
struct smb_cred *scred, struct smb_share **sspp);
const char * smb_vc_getpass(struct smb_vc *vcp);
u_short smb_vc_nextmid(struct smb_vc *vcp);
int smb_share_create(struct smb_vc *vcp, struct smb_sharespec *shspec,
struct smb_cred *scred, struct smb_share **sspp);
int smb_share_access(struct smb_share *ssp, struct smb_cred *scred, mode_t mode);
void smb_share_ref(struct smb_share *ssp);
void smb_share_rele(struct smb_share *ssp, struct smb_cred *scred);
int smb_share_get(struct smb_share *ssp, struct smb_cred *scred);
void smb_share_put(struct smb_share *ssp, struct smb_cred *scred);
int smb_share_lock(struct smb_share *ssp);
void smb_share_unlock(struct smb_share *ssp);
void smb_share_invalidate(struct smb_share *ssp);
int smb_share_valid(struct smb_share *ssp);
const char * smb_share_getpass(struct smb_share *ssp);
int smb_smb_negotiate(struct smb_vc *vcp, struct smb_cred *scred);
int smb_smb_ssnsetup(struct smb_vc *vcp, struct smb_cred *scred);
int smb_smb_ssnclose(struct smb_vc *vcp, struct smb_cred *scred);
int smb_smb_treeconnect(struct smb_share *ssp, struct smb_cred *scred);
int smb_smb_treedisconnect(struct smb_share *ssp, struct smb_cred *scred);
int smb_read(struct smb_share *ssp, u_int16_t fid, struct uio *uio,
struct smb_cred *scred);
int smb_write(struct smb_share *ssp, u_int16_t fid, struct uio *uio,
struct smb_cred *scred);
int smb_smb_echo(struct smb_vc *vcp, struct smb_cred *scred);
#define SMBIOD_EV_NEWRQ 0x0001
#define SMBIOD_EV_SHUTDOWN 0x0002
#define SMBIOD_EV_CONNECT 0x0003
#define SMBIOD_EV_DISCONNECT 0x0004
#define SMBIOD_EV_TREECONNECT 0x0005
#define SMBIOD_EV_MASK 0x00ff
#define SMBIOD_EV_SYNC 0x0100
#define SMBIOD_EV_PROCESSING 0x0200
struct smbiod_event {
int ev_type;
int ev_error;
void * ev_ident;
STAILQ_ENTRY(smbiod_event) ev_link;
};
#define SMBIOD_SHUTDOWN 0x0001
struct smbiod {
int iod_id;
int iod_flags;
enum smbiod_state iod_state;
int iod_muxcnt;
int iod_sleeptimo;
struct smb_vc * iod_vc;
struct smb_slock iod_rqlock;
struct smb_rqhead iod_rqlist;
int iod_muxwant;
struct proc * iod_p;
struct thread * iod_td;
struct smb_cred iod_scred;
struct smb_slock iod_evlock;
STAILQ_HEAD(,smbiod_event) iod_evlist;
struct timespec iod_lastrqsent;
struct timespec iod_pingtimo;
};
int smb_iod_init(void);
int smb_iod_done(void);
int smb_iod_create(struct smb_vc *vcp);
int smb_iod_destroy(struct smbiod *iod);
int smb_iod_request(struct smbiod *iod, int event, void *ident);
int smb_iod_addrq(struct smb_rq *rqp);
int smb_iod_waitrq(struct smb_rq *rqp);
int smb_iod_removerq(struct smb_rq *rqp);
#endif