#![warn(missing_docs)]
#![doc(html_playground_url = "https://play.rust-lang.org")]
#![doc(
html_favicon_url = "https://raw.githubusercontent.com/veeso/pavao/main/docs/images/pavao.png"
)]
#![doc(html_logo_url = "https://raw.githubusercontent.com/veeso/pavao/main/docs/images/pavao.png")]
#![allow(non_camel_case_types)]
#![allow(clippy::upper_case_acronyms)]
use std::{clone, default, mem, option};
use libc::{
c_char, c_int, c_uint, c_ushort, c_void, mode_t, off_t, size_t, ssize_t, stat, statvfs, time_t,
timespec, timeval,
};
#[repr(C)]
pub struct smbc_dirent {
pub smbc_type: c_uint,
pub dirlen: c_uint,
pub commentlen: c_uint,
pub comment: *mut c_char,
pub namelen: c_uint,
pub name: [c_char; 1usize],
}
#[repr(C)]
#[derive(Copy)]
pub struct libsmb_file_info {
pub size: u64,
pub attrs: c_ushort,
pub uid: c_uint,
pub gid: c_uint,
pub btime_ts: timespec,
pub mtime_ts: timespec,
pub atime_ts: timespec,
pub ctime_ts: timespec,
pub name: *mut c_char,
pub short_name: *mut c_char,
}
impl clone::Clone for libsmb_file_info {
fn clone(&self) -> Self {
*self
}
}
impl default::Default for libsmb_file_info {
fn default() -> Self {
unsafe { mem::zeroed() }
}
}
pub type smbc_share_mode = c_uint;
pub type smbc_smb_encrypt_level = c_int;
pub type smbc_bool = c_int;
pub type smbc_vfs_feature = c_uint;
pub const SMBC_WORKGROUP: c_uint = 1;
pub const SMBC_SERVER: c_uint = 2;
pub const SMBC_FILE_SHARE: c_uint = 3;
pub const SMBC_PRINTER_SHARE: c_uint = 4;
pub const SMBC_COMMS_SHARE: c_uint = 5;
pub const SMBC_IPC_SHARE: c_uint = 6;
pub const SMBC_DIR: c_uint = 7;
pub const SMBC_FILE: c_uint = 8;
pub const SMBC_LINK: c_uint = 9;
pub const SMBC_BASE_FD: c_int = 10_000;
pub const SMBC_SHAREMODE_DENY_DOS: smbc_share_mode = 0;
pub const SMBC_SHAREMODE_DENY_ALL: smbc_share_mode = 1;
pub const SMBC_SHAREMODE_DENY_WRITE: smbc_share_mode = 2;
pub const SMBC_SHAREMODE_DENY_READ: smbc_share_mode = 3;
pub const SMBC_SHAREMODE_DENY_NONE: smbc_share_mode = 4;
pub const SMBC_SHAREMODE_DENY_FCB: smbc_share_mode = 7;
pub const SMBC_ENCRYPTLEVEL_DEFAULT: smbc_smb_encrypt_level = -1;
pub const SMBC_ENCRYPTLEVEL_NONE: smbc_smb_encrypt_level = 0;
pub const SMBC_ENCRYPTLEVEL_REQUEST: smbc_smb_encrypt_level = 1;
pub const SMBC_ENCRYPTLEVEL_REQUIRE: smbc_smb_encrypt_level = 2;
pub const SMBC_XATTR_FLAG_CREATE: c_int = 0x1;
pub const SMBC_XATTR_FLAG_REPLACE: c_int = 0x2;
pub const SMBC_DOS_MODE_READONLY: c_int = 0x01;
pub const SMBC_DOS_MODE_HIDDEN: c_int = 0x02;
pub const SMBC_DOS_MODE_SYSTEM: c_int = 0x04;
pub const SMBC_DOS_MODE_VOLUME_ID: c_int = 0x08;
pub const SMBC_DOS_MODE_DIRECTORY: c_int = 0x10;
pub const SMBC_DOS_MODE_ARCHIVE: c_int = 0x20;
pub const SMBC_VFS_FEATURE_RDONLY: smbc_vfs_feature = 1 << 0;
pub const SMBC_VFS_FEATURE_DFS: smbc_vfs_feature = 1 << 28;
pub const SMBC_VFS_FEATURE_CASE_INSENSITIVE: smbc_vfs_feature = 1 << 29;
pub const SMBC_VFS_FEATURE_NO_UNIXCIFS: smbc_vfs_feature = 1 << 30;
pub const SMBC_NOTIFY_CHANGE_FILE_NAME: c_uint = 0x001;
pub const SMBC_NOTIFY_CHANGE_DIR_NAME: c_uint = 0x002;
pub const SMBC_NOTIFY_CHANGE_ATTRIBUTES: c_uint = 0x004;
pub const SMBC_NOTIFY_CHANGE_SIZE: c_uint = 0x008;
pub const SMBC_NOTIFY_CHANGE_LAST_WRITE: c_uint = 0x010;
pub const SMBC_NOTIFY_CHANGE_LAST_ACCESS: c_uint = 0x020;
pub const SMBC_NOTIFY_CHANGE_CREATION: c_uint = 0x040;
pub const SMBC_NOTIFY_CHANGE_EA: c_uint = 0x080;
pub const SMBC_NOTIFY_CHANGE_SECURITY: c_uint = 0x100;
pub const SMBC_NOTIFY_CHANGE_STREAM_NAME: c_uint = 0x200;
pub const SMBC_NOTIFY_CHANGE_STREAM_SIZE: c_uint = 0x400;
pub const SMBC_NOTIFY_CHANGE_STREAM_WRITE: c_uint = 0x800;
pub const SMBC_NOTIFY_ACTION_ADDED: c_uint = 1;
pub const SMBC_NOTIFY_ACTION_REMOVED: c_uint = 2;
pub const SMBC_NOTIFY_ACTION_MODIFIED: c_uint = 3;
pub const SMBC_NOTIFY_ACTION_OLD_NAME: c_uint = 4;
pub const SMBC_NOTIFY_ACTION_NEW_NAME: c_uint = 5;
pub const SMBC_NOTIFY_ACTION_ADDED_STREAM: c_uint = 6;
pub const SMBC_NOTIFY_ACTION_REMOVED_STREAM: c_uint = 7;
pub const SMBC_NOTIFY_ACTION_MODIFIED_STREAM: c_uint = 8;
#[repr(C)]
#[derive(Copy)]
pub struct print_job_info {
pub id: c_ushort,
pub priority: c_ushort,
pub size: size_t,
pub user: [c_char; 128usize],
pub name: [c_char; 128usize],
pub t: time_t,
}
impl clone::Clone for print_job_info {
fn clone(&self) -> Self {
*self
}
}
impl default::Default for print_job_info {
fn default() -> Self {
unsafe { mem::zeroed() }
}
}
pub enum _SMBCSRV {}
pub type SMBCSRV = _SMBCSRV;
pub enum _SMBCFILE {}
pub type SMBCFILE = _SMBCFILE;
pub enum _SMBCCTX {}
pub type SMBCCTX = _SMBCCTX;
pub type smbc_get_auth_data_fn = option::Option<
extern "C" fn(
srv: *const c_char,
shr: *const c_char,
wg: *mut c_char,
wglen: c_int,
un: *mut c_char,
unlen: c_int,
pw: *mut c_char,
pwlen: c_int,
),
>;
pub type smbc_get_auth_data_with_context_fn = Option<
extern "C" fn(
c: *mut SMBCCTX,
srv: *const c_char,
shr: *const c_char,
wg: *mut c_char,
wglen: c_int,
un: *mut c_char,
unlen: c_int,
pw: *mut c_char,
pwlen: c_int,
),
>;
pub type smbc_debug_callback_fn =
option::Option<extern "C" fn(private_ptr: *mut c_void, level: c_int, message: *const c_char)>;
pub type smbc_list_print_job_fn = option::Option<extern "C" fn(i: *mut print_job_info)>;
pub type smbc_check_server_fn =
option::Option<extern "C" fn(c: *mut SMBCCTX, srv: *mut SMBCSRV) -> c_int>;
pub type smbc_remove_unused_server_fn =
option::Option<extern "C" fn(c: *mut SMBCCTX, srv: *mut SMBCSRV) -> c_int>;
pub type smbc_add_cached_srv_fn = option::Option<
extern "C" fn(
c: *mut SMBCCTX,
srv: *mut SMBCSRV,
server: *const c_char,
share: *const c_char,
workgroup: *const c_char,
username: *const c_char,
) -> c_int,
>;
pub type smbc_get_cached_srv_fn = option::Option<
extern "C" fn(
c: *mut SMBCCTX,
server: *const c_char,
share: *const c_char,
workgroup: *const c_char,
username: *const c_char,
) -> *mut SMBCSRV,
>;
pub type smbc_remove_cached_srv_fn =
option::Option<extern "C" fn(c: *mut SMBCCTX, srv: *mut SMBCSRV) -> c_int>;
pub type smbc_purge_cached_fn = option::Option<extern "C" fn(c: *mut SMBCCTX) -> c_int>;
pub type smbc_open_fn = option::Option<
extern "C" fn(
c: *mut SMBCCTX,
fname: *const c_char,
flags: c_int,
mode: mode_t,
) -> *mut SMBCFILE,
>;
pub type smbc_creat_fn = option::Option<
extern "C" fn(c: *mut SMBCCTX, path: *const c_char, mode: mode_t) -> *mut SMBCFILE,
>;
pub type smbc_read_fn = option::Option<
extern "C" fn(c: *mut SMBCCTX, file: *mut SMBCFILE, buf: *mut c_void, count: size_t) -> ssize_t,
>;
pub type smbc_write_fn = option::Option<
extern "C" fn(
c: *mut SMBCCTX,
file: *mut SMBCFILE,
buf: *const c_void,
count: size_t,
) -> ssize_t,
>;
pub type smbc_splice_callback_fn =
option::Option<extern "C" fn(n: off_t, priv_: *mut c_void) -> c_int>;
pub type smbc_splice_fn = option::Option<
extern "C" fn(
c: *mut SMBCCTX,
srcfile: *mut SMBCFILE,
dstfile: *mut SMBCFILE,
count: off_t,
splice_cb: smbc_splice_callback_fn,
priv_: *mut c_void,
) -> off_t,
>;
pub type smbc_unlink_fn =
option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char) -> c_int>;
pub type smbc_rename_fn = option::Option<
extern "C" fn(
ocontext: *mut SMBCCTX,
oname: *const c_char,
ncontext: *mut SMBCCTX,
nname: *const c_char,
) -> c_int,
>;
pub type smbc_lseek_fn = option::Option<
extern "C" fn(c: *mut SMBCCTX, file: *mut SMBCFILE, offset: off_t, whence: c_int) -> off_t,
>;
pub type smbc_stat_fn =
option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char, st: *mut stat) -> c_int>;
pub type smbc_statvfs_fn =
option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char, st: *mut statvfs) -> c_int>;
pub type smbc_fstatvfs_fn =
option::Option<extern "C" fn(c: *mut SMBCCTX, file: *mut SMBCFILE, st: *mut statvfs) -> c_int>;
pub type smbc_ftruncate_fn =
option::Option<extern "C" fn(c: *mut SMBCCTX, file: *mut SMBCFILE, size: off_t) -> c_int>;
pub type smbc_fstat_fn =
option::Option<extern "C" fn(c: *mut SMBCCTX, file: *mut SMBCFILE, st: *mut stat) -> c_int>;
pub type smbc_close_fn =
option::Option<extern "C" fn(c: *mut SMBCCTX, file: *mut SMBCFILE) -> c_int>;
pub type smbc_opendir_fn =
option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char) -> *mut SMBCFILE>;
pub type smbc_closedir_fn =
option::Option<extern "C" fn(c: *mut SMBCCTX, dir: *mut SMBCFILE) -> c_int>;
pub type smbc_readdir_fn =
option::Option<extern "C" fn(c: *mut SMBCCTX, dir: *mut SMBCFILE) -> *mut smbc_dirent>;
pub type smbc_readdirplus_fn =
option::Option<extern "C" fn(c: *mut SMBCCTX, dir: *mut SMBCFILE) -> *mut libsmb_file_info>;
#[cfg(feature = "abi-0-6")]
pub type smbc_readdirplus2_fn = option::Option<
extern "C" fn(c: *mut SMBCCTX, dir: *mut SMBCFILE, st: *mut stat) -> *const libsmb_file_info,
>;
pub type smbc_getdents_fn = option::Option<
extern "C" fn(
c: *mut SMBCCTX,
dir: *mut SMBCFILE,
dirp: *mut smbc_dirent,
count: c_int,
) -> c_int,
>;
pub type smbc_mkdir_fn =
option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char, mode: mode_t) -> c_int>;
pub type smbc_rmdir_fn =
option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char) -> c_int>;
pub type smbc_telldir_fn =
option::Option<extern "C" fn(c: *mut SMBCCTX, dir: *mut SMBCFILE) -> off_t>;
pub type smbc_lseekdir_fn =
option::Option<extern "C" fn(c: *mut SMBCCTX, dir: *mut SMBCFILE, offset: off_t) -> c_int>;
pub type smbc_fstatdir_fn =
option::Option<extern "C" fn(c: *mut SMBCCTX, dir: *mut SMBCFILE, st: *mut stat) -> c_int>;
#[repr(C)]
pub struct smbc_notify_callback_action {
pub action: u32,
pub filename: *const c_char,
}
pub type smbc_notify_callback_fn = option::Option<
extern "C" fn(
actions: *const smbc_notify_callback_action,
num_actions: size_t,
private_data: *mut c_void,
) -> c_int,
>;
pub type smbc_notify_fn = option::Option<
extern "C" fn(
c: *mut SMBCCTX,
dir: *mut SMBCFILE,
recursive: smbc_bool,
completion_filter: u32,
callback_timeout_ms: c_uint,
cb: smbc_notify_callback_fn,
private_data: *mut c_void,
) -> c_int,
>;
pub type smbc_chmod_fn =
option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char, mode: mode_t) -> c_int>;
pub type smbc_utimes_fn = option::Option<
extern "C" fn(c: *mut SMBCCTX, fname: *const c_char, tbuf: *mut timeval) -> c_int,
>;
pub type smbc_setxattr_fn = option::Option<
extern "C" fn(
context: *mut SMBCCTX,
fname: *const c_char,
name: *const c_char,
value: *const c_void,
size: size_t,
flags: c_int,
) -> c_int,
>;
pub type smbc_getxattr_fn = option::Option<
extern "C" fn(
context: *mut SMBCCTX,
fname: *const c_char,
name: *const c_char,
value: *const c_void,
size: size_t,
) -> c_int,
>;
pub type smbc_removexattr_fn = option::Option<
extern "C" fn(context: *mut SMBCCTX, fname: *const c_char, name: *const c_char) -> c_int,
>;
pub type smbc_listxattr_fn = option::Option<
extern "C" fn(
context: *mut SMBCCTX,
fname: *const c_char,
list: *mut c_char,
size: size_t,
) -> c_int,
>;
pub type smbc_print_file_fn = option::Option<
extern "C" fn(
c_file: *mut SMBCCTX,
fname: *const c_char,
c_print: *mut SMBCCTX,
printq: *const c_char,
) -> c_int,
>;
pub type smbc_open_print_job_fn =
option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char) -> *mut SMBCFILE>;
pub type smbc_list_print_jobs_fn = option::Option<
extern "C" fn(c: *mut SMBCCTX, fname: *const c_char, _fn: smbc_list_print_job_fn) -> c_int,
>;
pub type smbc_unlink_print_job_fn =
option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char, id: c_int) -> c_int>;
#[link(name = "smbclient")]
unsafe extern "C" {
pub fn smbc_getDebug(c: *mut SMBCCTX) -> c_int;
pub fn smbc_setDebug(c: *mut SMBCCTX, debug: c_int);
pub fn smbc_setConfiguration(c: *mut SMBCCTX, file: *const c_char) -> c_int;
pub fn smbc_setLogCallback(
c: *mut SMBCCTX,
private_ptr: *mut c_void,
callback: smbc_debug_callback_fn,
);
pub fn smbc_getNetbiosName(c: *mut SMBCCTX) -> *const c_char;
pub fn smbc_setNetbiosName(c: *mut SMBCCTX, netbios_name: *const c_char);
pub fn smbc_getWorkgroup(c: *mut SMBCCTX) -> *const c_char;
pub fn smbc_setWorkgroup(c: *mut SMBCCTX, workgroup: *const c_char);
pub fn smbc_getUser(c: *mut SMBCCTX) -> *const c_char;
pub fn smbc_setUser(c: *mut SMBCCTX, user: *const c_char);
pub fn smbc_getTimeout(c: *mut SMBCCTX) -> c_int;
pub fn smbc_setTimeout(c: *mut SMBCCTX, timeout: c_int);
pub fn smbc_getPort(c: *mut SMBCCTX) -> u16;
pub fn smbc_setPort(c: *mut SMBCCTX, port: u16);
pub fn smbc_getOptionFullTimeNames(c: *mut SMBCCTX) -> smbc_bool;
pub fn smbc_setOptionFullTimeNames(c: *mut SMBCCTX, b: smbc_bool);
pub fn smbc_getOptionUserData(c: *mut SMBCCTX) -> *mut c_void;
pub fn smbc_setOptionUserData(c: *mut SMBCCTX, user_data: *mut c_void);
pub fn smbc_getOptionUseNTHash(c: *mut SMBCCTX) -> smbc_bool;
pub fn smbc_setOptionUseNTHash(c: *mut SMBCCTX, b: smbc_bool);
pub fn smbc_getOptionDebugToStderr(c: *mut SMBCCTX) -> smbc_bool;
pub fn smbc_setOptionDebugToStderr(c: *mut SMBCCTX, b: smbc_bool);
pub fn smbc_getOptionOpenShareMode(c: *mut SMBCCTX) -> smbc_share_mode;
pub fn smbc_setOptionOpenShareMode(c: *mut SMBCCTX, share_mode: smbc_share_mode);
pub fn smbc_getOptionSmbEncryptionLevel(c: *mut SMBCCTX) -> smbc_smb_encrypt_level;
pub fn smbc_setOptionSmbEncryptionLevel(c: *mut SMBCCTX, level: smbc_smb_encrypt_level);
pub fn smbc_getOptionCaseSensitive(c: *mut SMBCCTX) -> smbc_bool;
pub fn smbc_setOptionCaseSensitive(c: *mut SMBCCTX, b: smbc_bool);
pub fn smbc_getOptionBrowseMaxLmbCount(c: *mut SMBCCTX) -> c_int;
pub fn smbc_setOptionBrowseMaxLmbCount(c: *mut SMBCCTX, count: c_int);
pub fn smbc_getOptionUrlEncodeReaddirEntries(c: *mut SMBCCTX) -> smbc_bool;
pub fn smbc_setOptionUrlEncodeReaddirEntries(c: *mut SMBCCTX, b: smbc_bool);
pub fn smbc_getOptionOneSharePerServer(c: *mut SMBCCTX) -> smbc_bool;
pub fn smbc_setOptionOneSharePerServer(c: *mut SMBCCTX, b: smbc_bool);
pub fn smbc_getOptionUseKerberos(c: *mut SMBCCTX) -> smbc_bool;
pub fn smbc_setOptionUseKerberos(c: *mut SMBCCTX, b: smbc_bool);
pub fn smbc_getOptionFallbackAfterKerberos(c: *mut SMBCCTX) -> smbc_bool;
pub fn smbc_setOptionFallbackAfterKerberos(c: *mut SMBCCTX, b: smbc_bool);
pub fn smbc_getOptionNoAutoAnonymousLogin(c: *mut SMBCCTX) -> smbc_bool;
pub fn smbc_setOptionNoAutoAnonymousLogin(c: *mut SMBCCTX, b: smbc_bool);
pub fn smbc_getOptionUseCCache(c: *mut SMBCCTX) -> smbc_bool;
pub fn smbc_setOptionUseCCache(c: *mut SMBCCTX, b: smbc_bool);
#[cfg(feature = "abi-0-8")]
pub fn smbc_getOptionPosixExtensions(c: *mut SMBCCTX) -> smbc_bool;
#[cfg(feature = "abi-0-8")]
pub fn smbc_setOptionPosixExtensions(c: *mut SMBCCTX, b: smbc_bool);
pub fn smbc_setOptionProtocols(
c: *mut SMBCCTX,
min_protocol: *const c_char,
max_protocol: *const c_char,
) -> smbc_bool;
pub fn smbc_setFunctionAuthDataWithContext(
c: *mut SMBCCTX,
_fn: smbc_get_auth_data_with_context_fn,
);
pub fn smbc_getFunctionOpen(c: *mut SMBCCTX) -> smbc_open_fn;
pub fn smbc_getFunctionCreat(c: *mut SMBCCTX) -> smbc_creat_fn;
pub fn smbc_getFunctionRead(c: *mut SMBCCTX) -> smbc_read_fn;
pub fn smbc_getFunctionWrite(c: *mut SMBCCTX) -> smbc_write_fn;
pub fn smbc_getFunctionSplice(c: *mut SMBCCTX) -> smbc_splice_fn;
pub fn smbc_getFunctionUnlink(c: *mut SMBCCTX) -> smbc_unlink_fn;
pub fn smbc_getFunctionRename(c: *mut SMBCCTX) -> smbc_rename_fn;
pub fn smbc_getFunctionLseek(c: *mut SMBCCTX) -> smbc_lseek_fn;
pub fn smbc_getFunctionStat(c: *mut SMBCCTX) -> smbc_stat_fn;
pub fn smbc_getFunctionFstat(c: *mut SMBCCTX) -> smbc_fstat_fn;
pub fn smbc_getFunctionFtruncate(c: *mut SMBCCTX) -> smbc_ftruncate_fn;
pub fn smbc_getFunctionStatVFS(c: *mut SMBCCTX) -> smbc_statvfs_fn;
pub fn smbc_getFunctionFstatVFS(c: *mut SMBCCTX) -> smbc_fstatvfs_fn;
pub fn smbc_getFunctionClose(c: *mut SMBCCTX) -> smbc_close_fn;
pub fn smbc_getFunctionOpendir(c: *mut SMBCCTX) -> smbc_opendir_fn;
pub fn smbc_getFunctionClosedir(c: *mut SMBCCTX) -> smbc_closedir_fn;
pub fn smbc_getFunctionReaddir(c: *mut SMBCCTX) -> smbc_readdir_fn;
pub fn smbc_getFunctionReaddirPlus(c: *mut SMBCCTX) -> smbc_readdirplus_fn;
#[cfg(feature = "abi-0-6")]
pub fn smbc_getFunctionReaddirPlus2(c: *mut SMBCCTX) -> smbc_readdirplus2_fn;
pub fn smbc_getFunctionGetdents(c: *mut SMBCCTX) -> smbc_getdents_fn;
pub fn smbc_getFunctionMkdir(c: *mut SMBCCTX) -> smbc_mkdir_fn;
pub fn smbc_getFunctionRmdir(c: *mut SMBCCTX) -> smbc_rmdir_fn;
pub fn smbc_getFunctionTelldir(c: *mut SMBCCTX) -> smbc_telldir_fn;
pub fn smbc_getFunctionLseekdir(c: *mut SMBCCTX) -> smbc_lseekdir_fn;
pub fn smbc_getFunctionFstatdir(c: *mut SMBCCTX) -> smbc_fstatdir_fn;
pub fn smbc_getFunctionNotify(c: *mut SMBCCTX) -> smbc_notify_fn;
pub fn smbc_getFunctionChmod(c: *mut SMBCCTX) -> smbc_chmod_fn;
pub fn smbc_getFunctionUtimes(c: *mut SMBCCTX) -> smbc_utimes_fn;
pub fn smbc_getFunctionSetxattr(c: *mut SMBCCTX) -> smbc_setxattr_fn;
pub fn smbc_getFunctionGetxattr(c: *mut SMBCCTX) -> smbc_getxattr_fn;
pub fn smbc_getFunctionRemovexattr(c: *mut SMBCCTX) -> smbc_removexattr_fn;
pub fn smbc_getFunctionListxattr(c: *mut SMBCCTX) -> smbc_listxattr_fn;
pub fn smbc_getFunctionPrintFile(c: *mut SMBCCTX) -> smbc_print_file_fn;
pub fn smbc_getFunctionOpenPrintJob(c: *mut SMBCCTX) -> smbc_open_print_job_fn;
pub fn smbc_getFunctionListPrintJobs(c: *mut SMBCCTX) -> smbc_list_print_jobs_fn;
pub fn smbc_getFunctionUnlinkPrintJob(c: *mut SMBCCTX) -> smbc_unlink_print_job_fn;
pub fn smbc_new_context() -> *mut SMBCCTX;
pub fn smbc_free_context(context: *mut SMBCCTX, shutdown_ctx: c_int) -> c_int;
pub fn smbc_set_credentials_with_fallback(
c: *mut SMBCCTX,
workgroup: *const c_char,
user: *const c_char,
password: *const c_char,
);
pub fn smbc_init_context(context: *mut SMBCCTX) -> *mut SMBCCTX;
pub fn smbc_version() -> *const c_char;
}
#[cfg(test)]
mod tests {
use std::sync::atomic::{AtomicBool, Ordering};
use libc::{c_char, c_int, c_void};
use serial_test::serial;
use super::*;
fn with_context(test: impl FnOnce(*mut SMBCCTX)) {
unsafe {
let context = smbc_new_context();
assert!(!context.is_null());
test(context);
assert_eq!(smbc_free_context(context, 1), 0);
}
}
extern "C" fn record_log(private_ptr: *mut c_void, _level: c_int, _message: *const c_char) {
unsafe { (&*private_ptr.cast::<AtomicBool>()).store(true, Ordering::SeqCst) };
}
#[test]
#[serial]
fn treats_smbc_context_as_opaque() {
with_context(|context| assert!(!context.is_null()));
}
#[test]
fn uses_fixed_width_file_info_size() {
let info = libsmb_file_info {
size: u64::MAX,
..Default::default()
};
assert_eq!(info.size, u64::MAX);
assert_eq!(std::mem::size_of_val(&info.size), 8);
}
#[test]
fn uses_signed_encryption_level() {
let level: smbc_smb_encrypt_level = -1;
assert_eq!(level, -1);
}
#[test]
fn uses_const_context_string_pointers() {
let _: unsafe extern "C" fn(*mut SMBCCTX) -> *const c_char = smbc_getNetbiosName;
let _: unsafe extern "C" fn(*mut SMBCCTX, *const c_char) = smbc_setNetbiosName;
let _: unsafe extern "C" fn(*mut SMBCCTX) -> *const c_char = smbc_getWorkgroup;
let _: unsafe extern "C" fn(*mut SMBCCTX, *const c_char) = smbc_setWorkgroup;
let _: unsafe extern "C" fn(*mut SMBCCTX) -> *const c_char = smbc_getUser;
let _: unsafe extern "C" fn(*mut SMBCCTX, *const c_char) = smbc_setUser;
}
#[test]
fn exposes_directory_entry_constants() {
assert_eq!(SMBC_WORKGROUP, 1);
assert_eq!(SMBC_SERVER, 2);
assert_eq!(SMBC_FILE_SHARE, 3);
assert_eq!(SMBC_PRINTER_SHARE, 4);
assert_eq!(SMBC_COMMS_SHARE, 5);
assert_eq!(SMBC_IPC_SHARE, 6);
assert_eq!(SMBC_DIR, 7);
assert_eq!(SMBC_FILE, 8);
assert_eq!(SMBC_LINK, 9);
assert_eq!(SMBC_BASE_FD, 10000);
}
#[test]
fn exposes_share_and_encryption_constants() {
assert_eq!(SMBC_SHAREMODE_DENY_DOS, 0);
assert_eq!(SMBC_SHAREMODE_DENY_ALL, 1);
assert_eq!(SMBC_SHAREMODE_DENY_WRITE, 2);
assert_eq!(SMBC_SHAREMODE_DENY_READ, 3);
assert_eq!(SMBC_SHAREMODE_DENY_NONE, 4);
assert_eq!(SMBC_SHAREMODE_DENY_FCB, 7);
assert_eq!(SMBC_ENCRYPTLEVEL_DEFAULT, -1);
assert_eq!(SMBC_ENCRYPTLEVEL_NONE, 0);
assert_eq!(SMBC_ENCRYPTLEVEL_REQUEST, 1);
assert_eq!(SMBC_ENCRYPTLEVEL_REQUIRE, 2);
}
#[test]
fn exposes_extended_attribute_constants() {
assert_eq!(SMBC_XATTR_FLAG_CREATE, 0x1);
assert_eq!(SMBC_XATTR_FLAG_REPLACE, 0x2);
assert_eq!(SMBC_DOS_MODE_READONLY, 0x01);
assert_eq!(SMBC_DOS_MODE_HIDDEN, 0x02);
assert_eq!(SMBC_DOS_MODE_SYSTEM, 0x04);
assert_eq!(SMBC_DOS_MODE_VOLUME_ID, 0x08);
assert_eq!(SMBC_DOS_MODE_DIRECTORY, 0x10);
assert_eq!(SMBC_DOS_MODE_ARCHIVE, 0x20);
}
#[test]
fn exposes_vfs_feature_constants() {
assert_eq!(SMBC_VFS_FEATURE_RDONLY, 1 << 0);
assert_eq!(SMBC_VFS_FEATURE_DFS, 1 << 28);
assert_eq!(SMBC_VFS_FEATURE_CASE_INSENSITIVE, 1 << 29);
assert_eq!(SMBC_VFS_FEATURE_NO_UNIXCIFS, 1 << 30);
}
#[test]
fn exposes_notification_constants() {
assert_eq!(SMBC_NOTIFY_CHANGE_FILE_NAME, 0x001);
assert_eq!(SMBC_NOTIFY_CHANGE_DIR_NAME, 0x002);
assert_eq!(SMBC_NOTIFY_CHANGE_ATTRIBUTES, 0x004);
assert_eq!(SMBC_NOTIFY_CHANGE_SIZE, 0x008);
assert_eq!(SMBC_NOTIFY_CHANGE_LAST_WRITE, 0x010);
assert_eq!(SMBC_NOTIFY_CHANGE_LAST_ACCESS, 0x020);
assert_eq!(SMBC_NOTIFY_CHANGE_CREATION, 0x040);
assert_eq!(SMBC_NOTIFY_CHANGE_EA, 0x080);
assert_eq!(SMBC_NOTIFY_CHANGE_SECURITY, 0x100);
assert_eq!(SMBC_NOTIFY_CHANGE_STREAM_NAME, 0x200);
assert_eq!(SMBC_NOTIFY_CHANGE_STREAM_SIZE, 0x400);
assert_eq!(SMBC_NOTIFY_CHANGE_STREAM_WRITE, 0x800);
assert_eq!(SMBC_NOTIFY_ACTION_ADDED, 1);
assert_eq!(SMBC_NOTIFY_ACTION_REMOVED, 2);
assert_eq!(SMBC_NOTIFY_ACTION_MODIFIED, 3);
assert_eq!(SMBC_NOTIFY_ACTION_OLD_NAME, 4);
assert_eq!(SMBC_NOTIFY_ACTION_NEW_NAME, 5);
assert_eq!(SMBC_NOTIFY_ACTION_ADDED_STREAM, 6);
assert_eq!(SMBC_NOTIFY_ACTION_REMOVED_STREAM, 7);
assert_eq!(SMBC_NOTIFY_ACTION_MODIFIED_STREAM, 8);
}
#[test]
#[serial]
fn gets_debug_level() {
with_context(|context| unsafe {
smbc_setDebug(context, 7);
assert_eq!(smbc_getDebug(context), 7);
});
}
#[test]
#[serial]
fn rejects_missing_configuration() {
with_context(|context| unsafe {
assert_eq!(
smbc_setConfiguration(context, c"/definitely/missing/pavao.conf".as_ptr()),
-1
);
});
}
#[test]
#[serial]
fn sets_log_callback() {
with_context(|context| unsafe {
let called = AtomicBool::new(false);
let private_ptr = std::ptr::from_ref(&called).cast_mut().cast::<c_void>();
smbc_setDebug(context, 1);
smbc_setLogCallback(context, private_ptr, Some(record_log));
assert_eq!(
smbc_setConfiguration(context, c"/definitely/missing/pavao.conf".as_ptr()),
-1
);
smbc_setLogCallback(context, std::ptr::null_mut(), None);
assert!(called.load(Ordering::SeqCst));
});
}
#[test]
#[serial]
fn gets_default_port() {
with_context(|context| unsafe {
assert_eq!(smbc_getPort(context), 0);
});
}
#[test]
#[serial]
fn sets_port() {
with_context(|context| unsafe {
smbc_setPort(context, 445);
assert_eq!(smbc_getPort(context), 445);
});
}
#[test]
#[serial]
fn gets_full_time_names_option() {
with_context(|context| unsafe {
assert_eq!(smbc_getOptionFullTimeNames(context), 0);
});
}
#[test]
#[serial]
fn sets_full_time_names_option() {
with_context(|context| unsafe {
smbc_setOptionFullTimeNames(context, 1);
assert_eq!(smbc_getOptionFullTimeNames(context), 1);
});
}
#[test]
#[serial]
fn gets_empty_user_data() {
with_context(|context| unsafe {
assert!(smbc_getOptionUserData(context).is_null());
});
}
#[test]
#[serial]
fn sets_user_data() {
with_context(|context| unsafe {
let mut value = 42;
let user_data = std::ptr::from_mut(&mut value).cast::<c_void>();
smbc_setOptionUserData(context, user_data);
assert_eq!(smbc_getOptionUserData(context), user_data);
smbc_setOptionUserData(context, std::ptr::null_mut());
});
}
#[test]
#[serial]
fn gets_nt_hash_option() {
with_context(|context| unsafe {
assert_eq!(smbc_getOptionUseNTHash(context), 0);
});
}
#[test]
#[serial]
fn sets_nt_hash_option() {
with_context(|context| unsafe {
smbc_setOptionUseNTHash(context, 1);
assert_eq!(smbc_getOptionUseNTHash(context), 1);
});
}
#[test]
#[serial]
fn sets_fallback_credentials() {
with_context(|context| unsafe {
smbc_setUser(context, c"user".as_ptr());
smbc_set_credentials_with_fallback(
context,
c"WORKGROUP".as_ptr(),
c"user".as_ptr(),
c"password".as_ptr(),
);
assert_eq!(std::ffi::CStr::from_ptr(smbc_getUser(context)), c"user");
});
}
#[test]
#[serial]
fn gets_debug_to_stderr_option() {
with_context(|context| unsafe {
smbc_setOptionDebugToStderr(context, 1);
assert_eq!(smbc_getOptionDebugToStderr(context), 1);
});
}
#[test]
#[serial]
fn gets_open_share_mode_option() {
with_context(|context| unsafe {
smbc_setOptionOpenShareMode(context, SMBC_SHAREMODE_DENY_ALL);
assert_eq!(
smbc_getOptionOpenShareMode(context),
SMBC_SHAREMODE_DENY_ALL
);
});
}
#[test]
#[serial]
fn gets_encryption_level_option() {
with_context(|context| unsafe {
smbc_setOptionSmbEncryptionLevel(context, SMBC_ENCRYPTLEVEL_REQUIRE);
assert_eq!(
smbc_getOptionSmbEncryptionLevel(context),
SMBC_ENCRYPTLEVEL_REQUIRE
);
});
}
#[test]
#[serial]
fn gets_case_sensitive_option() {
with_context(|context| unsafe {
smbc_setOptionCaseSensitive(context, 1);
assert_eq!(smbc_getOptionCaseSensitive(context), 1);
});
}
#[test]
#[serial]
fn gets_browse_max_lmb_count_option() {
with_context(|context| unsafe {
smbc_setOptionBrowseMaxLmbCount(context, 9);
assert_eq!(smbc_getOptionBrowseMaxLmbCount(context), 9);
});
}
#[test]
#[serial]
fn gets_url_encode_readdir_option() {
with_context(|context| unsafe {
smbc_setOptionUrlEncodeReaddirEntries(context, 1);
assert_eq!(smbc_getOptionUrlEncodeReaddirEntries(context), 1);
});
}
#[test]
#[serial]
fn gets_one_share_per_server_option() {
with_context(|context| unsafe {
smbc_setOptionOneSharePerServer(context, 1);
assert_eq!(smbc_getOptionOneSharePerServer(context), 1);
});
}
#[test]
#[serial]
fn gets_use_kerberos_option() {
with_context(|context| unsafe {
smbc_setOptionUseKerberos(context, 1);
assert_eq!(smbc_getOptionUseKerberos(context), 1);
});
}
#[test]
#[serial]
fn gets_kerberos_fallback_option() {
with_context(|context| unsafe {
smbc_setOptionFallbackAfterKerberos(context, 1);
assert_eq!(smbc_getOptionFallbackAfterKerberos(context), 1);
});
}
#[test]
#[serial]
fn gets_no_auto_anonymous_option() {
with_context(|context| unsafe {
smbc_setOptionNoAutoAnonymousLogin(context, 1);
assert_eq!(smbc_getOptionNoAutoAnonymousLogin(context), 1);
});
}
#[test]
#[serial]
fn gets_use_ccache_option() {
with_context(|context| unsafe {
smbc_setOptionUseCCache(context, 1);
assert_eq!(smbc_getOptionUseCCache(context), 1);
});
}
#[test]
#[serial]
fn binds_smbc_get_function_creat() {
with_context(|context| unsafe {
assert!(smbc_getFunctionCreat(context).is_some());
});
}
#[test]
#[serial]
fn binds_smbc_get_function_splice() {
with_context(|context| unsafe {
assert!(smbc_getFunctionSplice(context).is_some());
});
}
#[test]
#[serial]
fn binds_smbc_get_function_fstat() {
with_context(|context| unsafe {
assert!(smbc_getFunctionFstat(context).is_some());
});
}
#[test]
#[serial]
fn binds_smbc_get_function_fstatvfs() {
with_context(|context| unsafe {
assert!(smbc_getFunctionFstatVFS(context).is_some());
});
}
#[test]
#[serial]
fn binds_smbc_get_function_ftruncate() {
with_context(|context| unsafe {
assert!(smbc_getFunctionFtruncate(context).is_some());
});
}
#[test]
#[serial]
fn binds_smbc_get_function_getdents() {
with_context(|context| unsafe {
assert!(smbc_getFunctionGetdents(context).is_some());
});
}
#[test]
#[serial]
fn binds_smbc_get_function_telldir() {
with_context(|context| unsafe {
assert!(smbc_getFunctionTelldir(context).is_some());
});
}
#[test]
#[serial]
fn binds_smbc_get_function_lseekdir() {
with_context(|context| unsafe {
assert!(smbc_getFunctionLseekdir(context).is_some());
});
}
#[test]
#[serial]
fn binds_smbc_get_function_fstatdir() {
with_context(|context| unsafe {
assert!(smbc_getFunctionFstatdir(context).is_some());
});
}
#[test]
#[serial]
fn binds_smbc_get_function_notify() {
with_context(|context| unsafe {
assert!(smbc_getFunctionNotify(context).is_some());
});
}
#[cfg(feature = "abi-0-6")]
#[test]
#[serial]
fn binds_smbc_get_function_readdir_plus_2() {
with_context(|context| unsafe {
assert!(smbc_getFunctionReaddirPlus2(context).is_some());
});
}
#[test]
#[serial]
fn binds_smbc_get_function_utimes() {
with_context(|context| unsafe {
assert!(smbc_getFunctionUtimes(context).is_some());
});
}
#[test]
#[serial]
fn binds_smbc_get_function_setxattr() {
with_context(|context| unsafe {
assert!(smbc_getFunctionSetxattr(context).is_some());
});
}
#[test]
#[serial]
fn binds_smbc_get_function_getxattr() {
with_context(|context| unsafe {
assert!(smbc_getFunctionGetxattr(context).is_some());
});
}
#[test]
#[serial]
fn binds_smbc_get_function_removexattr() {
with_context(|context| unsafe {
assert!(smbc_getFunctionRemovexattr(context).is_some());
});
}
#[test]
#[serial]
fn binds_smbc_get_function_listxattr() {
with_context(|context| unsafe {
assert!(smbc_getFunctionListxattr(context).is_some());
});
}
#[test]
#[serial]
fn binds_smbc_get_function_open_print_job() {
with_context(|context| unsafe {
assert!(smbc_getFunctionOpenPrintJob(context).is_some());
});
}
#[test]
#[serial]
fn binds_smbc_get_function_list_print_jobs() {
with_context(|context| unsafe {
assert!(smbc_getFunctionListPrintJobs(context).is_some());
});
}
#[test]
#[serial]
fn binds_smbc_get_function_unlink_print_job() {
with_context(|context| unsafe {
assert!(smbc_getFunctionUnlinkPrintJob(context).is_some());
});
}
#[cfg(feature = "abi-0-8")]
#[test]
#[serial]
fn gets_posix_extensions_option() {
with_context(|context| unsafe {
let value = smbc_getOptionPosixExtensions(context);
assert!(value == 0 || value == 1);
});
}
#[cfg(feature = "abi-0-8")]
#[test]
#[serial]
fn sets_posix_extensions_option() {
with_context(|context| unsafe {
smbc_setOptionPosixExtensions(context, 1);
assert_eq!(smbc_getOptionPosixExtensions(context), 1);
});
}
}