#ifndef _NETSMB_DEV_H_
#define _NETSMB_DEV_H_
#ifndef _KERNEL
#include <sys/types.h>
#endif
#include <sys/ioccom.h>
#include <netsmb/smb.h>
#define NSMB_NAME "nsmb"
#define KERBEROS_REALM_DELIMITER '@'
#define WIN2008_SPN_PLEASE_IGNORE_REALM "cifs/not_defined_in_RFC4178@please_ignore"
#define SMB_IOC_STRUCT_VERSION 160
#define SMB_MAX_IOC_SIZE 4 * 1024
#define TRY_BOTH_PORTS 1
#define USE_THIS_PORT_ONLY 2
#define SMB_SHARING_VC 4
struct smbioc_ossn {
u_int32_t ioc_opt;
u_int32_t ioc_reconnect_wait_time;
uid_t ioc_owner;
char ioc_localcs[16] __attribute((aligned(8)));
char ioc_srvname[SMB_MAX_DNS_SRVNAMELEN+1] __attribute((aligned(8)));
char ioc_localname[SMB_MAXNetBIOSNAMELEN+1] __attribute((aligned(8)));
char ioc_kuser[SMB_MAXUSERNAMELEN + 1] __attribute((aligned(8)));
char ioc_kspn_hint[SMB_MAX_KERB_PN+1] __attribute((aligned(8)));
};
struct smbioc_negotiate {
u_int32_t ioc_version;
u_int32_t ioc_extra_flags;
u_int32_t ioc_ret_caps;
u_int32_t ioc_ret_vc_flags;
int32_t ioc_saddr_len;
int32_t ioc_laddr_len;
union {
user_addr_t ioc_kern_saddr __attribute((aligned(8)));
struct sockaddr *ioc_saddr __attribute((aligned(8)));
};
union {
user_addr_t ioc_kern_laddr __attribute((aligned(8)));
struct sockaddr *ioc_laddr __attribute((aligned(8)));
};
struct smbioc_ossn ioc_ssn __attribute((aligned(8)));
char ioc_user[SMB_MAXUSERNAMELEN + 1] __attribute((aligned(8)));
u_int64_t ioc_reserved __attribute((aligned(8)));
};
struct smbioc_setup {
u_int32_t ioc_version;
int32_t ioc_vcflags;
char ioc_user[SMB_MAXUSERNAMELEN + 1] __attribute((aligned(8)));
char ioc_uppercase_user[SMB_MAXUSERNAMELEN + 1] __attribute((aligned(8)));
char ioc_password[SMB_MAXPASSWORDLEN + 1] __attribute((aligned(8)));
char ioc_domain[SMB_MAXNetBIOSNAMELEN + 1] __attribute((aligned(8)));
char ioc_kclientpn[SMB_MAX_KERB_PN+1] __attribute((aligned(8)));
char ioc_kservicepn[SMB_MAX_KERB_PN+1] __attribute((aligned(8)));
u_int64_t ioc_reserved __attribute((aligned(8)));
};
struct smbioc_share {
u_int32_t ioc_version;
int32_t ioc_stype;
char ioc_share[SMB_MAXSHARENAMELEN + 1] __attribute((aligned(8)));
u_int64_t ioc_reserved __attribute((aligned(8)));
};
struct dos_error {
u_int8_t errclass;
u_int8_t err_reserved;
u_int16_t error;
};
struct smbioc_rq {
u_int32_t ioc_version;
u_int8_t ioc_cmd;
u_int8_t ioc_twc;
u_int16_t ioc_tbc;
int32_t ioc_rpbufsz;
u_int16_t ioc_rbc;
u_int16_t ioc_srflags2;
u_int8_t ioc_rwc;
u_int8_t ioc_pad[3];
struct dos_error ioc_dos_error;
u_int32_t ioc_nt_error;
union {
user_addr_t ioc_kern_twords __attribute((aligned(8)));
void * ioc_twords __attribute((aligned(8)));
};
union {
user_addr_t ioc_kern_tbytes __attribute((aligned(8)));
void * ioc_tbytes __attribute((aligned(8)));
};
union {
user_addr_t ioc_kern_rpbuf __attribute((aligned(8)));
char * ioc_rpbuf __attribute((aligned(8)));
};
u_int64_t ioc_reserved __attribute((aligned(8)));
};
struct smbioc_t2rq {
u_int32_t ioc_version;
u_int32_t ioc_name_len;
u_int16_t ioc_setupcnt;
u_int16_t ioc_tparamcnt;
u_int16_t ioc_tdatacnt;
u_int16_t ioc_rparamcnt;
u_int16_t ioc_rdatacnt;
u_int16_t ioc_srflags2;
u_int16_t ioc_setup[SMB_MAXSETUPWORDS];
struct dos_error ioc_dos_error __attribute((aligned(8)));
u_int32_t ioc_nt_error __attribute((aligned(8)));
union {
user_addr_t ioc_kern_name __attribute((aligned(8)));
const char *ioc_name __attribute((aligned(8)));
};
union {
user_addr_t ioc_kern_tparam __attribute((aligned(8)));
void * ioc_tparam __attribute((aligned(8)));
};
union {
user_addr_t ioc_kern_tdata __attribute((aligned(8)));
void * ioc_tdata __attribute((aligned(8)));
};
union {
user_addr_t ioc_kern_rparam __attribute((aligned(8)));
void * ioc_rparam __attribute((aligned(8)));
};
union {
user_addr_t ioc_kern_rdata __attribute((aligned(8)));
void * ioc_rdata __attribute((aligned(8)));
};
u_int64_t ioc_reserved __attribute((aligned(8)));
};
struct smbioc_rw {
u_int32_t ioc_version;
u_int32_t ioc_cnt;
off_t ioc_offset;
smbfh ioc_fh;
union {
user_addr_t ioc_kern_base __attribute((aligned(8)));
void *ioc_base __attribute((aligned(8)));
};
u_int64_t ioc_reserved __attribute((aligned(8)));
};
struct smbioc_os_lanman {
char NativeOS[SMB_MAX_NATIVE_OS_STRING];
char NativeLANManager[SMB_MAX_NATIVE_LANMAN_STRING];
};
#ifdef SMB_ROSETTA
#define MIN_SMBIOC_COMMAND 102
#define MAX_SMBIOC_COMMAND 117
#define SMBIOC_COMMAND_COUNT MAX_SMBIOC_COMMAND - MIN_SMBIOC_COMMAND + 1
#define SMBIOC_UNUSED_104 104 - MIN_SMBIOC_COMMAND
#define SMBIOC_UNUSED_105 105 - MIN_SMBIOC_COMMAND
#define SMBIOC_UNUSED_106 106 - MIN_SMBIOC_COMMAND
#define SMBIOC_UNUSED_108 108 - MIN_SMBIOC_COMMAND
#endif // SMB_ROSETTA
#define SMBIOC_REQUEST _IOWR('n', 102, struct smbioc_rq)
#define SMBIOC_T2RQ _IOWR('n', 103, struct smbioc_t2rq)
#define SMBIOC_READ _IOWR('n', 107, struct smbioc_rw)
#define SMBIOC_WRITE _IOWR('n', 108, struct smbioc_rw)
#define SMBIOC_NEGOTIATE _IOWR('n', 109, struct smbioc_negotiate)
#define SMBIOC_SSNSETUP _IOW('n', 110, struct smbioc_setup)
#define SMBIOC_TCON _IOW('n', 111, struct smbioc_share)
#define SMBIOC_TDIS _IOW('n', 112, struct smbioc_share)
#define SMBIOC_GET_VC_FLAGS2 _IOR('n', 113, u_int16_t)
#define SMBIOC_SESSSTATE _IOR('n', 114, u_int16_t)
#define SMBIOC_CANCEL_SESSION _IOR('n', 115, u_int16_t)
#define SMBIOC_GET_VC_FLAGS _IOR('n', 116, u_int32_t)
#define SMBIOC_GET_OS_LANMAN _IOR('n', 117, struct smbioc_os_lanman)
#define SMB_ENETFSACCOUNTRESTRICTED -5042
#define SMB_ENETFSPWDNEEDSCHANGE -5045
#define SMB_ENETFSPWDPOLICY -5046
#ifdef _KERNEL
STAILQ_HEAD(smbrqh, smb_rq);
struct smb_dev {
struct smb_vc * sd_vc;
struct smb_share *sd_share;
u_int32_t sd_flags;
void * sd_devfs;
};
int smb_usr_negotiate(struct smbioc_negotiate *dp, vfs_context_t context, struct smb_dev *sdp);
int smb_usr_simplerequest(struct smb_share *ssp, struct smbioc_rq *data, vfs_context_t context);
int smb_usr_t2request(struct smb_share *ssp, struct smbioc_t2rq *data, vfs_context_t context);
int smb_dev2share(int fd, struct smb_share **sspp);
#else
int smb_ioctl_call(int , unsigned long , void *);
#endif
#endif