pavao_sys/
lib.rs

1//! # Pavão-sys
2//!
3//! [Pavão=sys](https://github.com/veeso/pavao) exposes the C bindings for the **libsmbclient** library to rust.
4//!
5//! If you're looking for the Rust SMB library checkout pavao.
6//!
7
8#![doc(html_playground_url = "https://play.rust-lang.org")]
9#![doc(
10    html_favicon_url = "https://raw.githubusercontent.com/veeso/pavao/main/docs/images/pavao.png"
11)]
12#![doc(html_logo_url = "https://raw.githubusercontent.com/veeso/pavao/main/docs/images/pavao.png")]
13#![allow(non_camel_case_types)]
14#![allow(clippy::upper_case_acronyms)]
15use std::{clone, default, mem, option};
16
17use libc::{
18    c_char, c_int, c_uint, c_ulong, c_ushort, c_void, mode_t, off_t, size_t, ssize_t, stat,
19    statvfs, time_t, timespec, timeval,
20};
21
22#[repr(C)]
23#[derive(Copy)]
24pub struct smbc_dirent {
25    /** Type of entity.
26    SMBC_WORKGROUP=1,
27    SMBC_SERVER=2,
28    SMBC_FILE_SHARE=3,
29    SMBC_PRINTER_SHARE=4,
30    SMBC_COMMS_SHARE=5,
31    SMBC_IPC_SHARE=6,
32    SMBC_DIR=7,
33    SMBC_FILE=8,
34    SMBC_LINK=9,*/
35    pub smbc_type: c_uint,
36
37    /** Length of this smbc_dirent in bytes
38     */
39    pub dirlen: c_uint,
40    /** The length of the comment string in bytes (does not include
41     *  null terminator)
42     */
43    pub commentlen: c_uint,
44    /** Points to the null terminated comment string
45     */
46    pub comment: *mut c_char,
47    /** The length of the name string in bytes (does not include
48     *  null terminator)
49     */
50    pub namelen: c_uint,
51    /** Points to the null terminated name string
52     */
53    pub name: [c_char; 1024usize],
54}
55
56impl clone::Clone for smbc_dirent {
57    fn clone(&self) -> Self {
58        *self
59    }
60}
61
62impl default::Default for smbc_dirent {
63    fn default() -> Self {
64        unsafe { mem::zeroed() }
65    }
66}
67#[repr(C)]
68#[derive(Copy)]
69/// Structure that represents all attributes of a directory entry.
70/// libsmb_file_info as implemented in libsmbclient.h
71pub struct libsmb_file_info {
72    /// Size of file
73    pub size: c_ulong,
74    /// DOS attributes of file
75    pub attrs: c_ushort,
76    /// User ID of file
77    pub uid: c_uint,
78    /// Group ID of file
79    pub gid: c_uint,
80    /// Birth/Create time of file (if supported by system)
81    ///Otherwise the value will be 0
82    pub btime_ts: timespec,
83    /// Modified time for the file
84    pub mtime_ts: timespec,
85    /// Access time for the file
86    pub atime_ts: timespec,
87    /// Change time for the file
88    pub ctime_ts: timespec,
89    /// Name of file
90    pub name: *mut c_char,
91    /// Short name of file
92    pub short_name: *mut c_char,
93}
94
95impl clone::Clone for libsmb_file_info {
96    fn clone(&self) -> Self {
97        *self
98    }
99}
100
101impl default::Default for libsmb_file_info {
102    fn default() -> Self {
103        unsafe { mem::zeroed() }
104    }
105}
106
107/*
108 * Valid values for the option "open_share_mode", when calling
109 * smbc_setOptionOpenShareMode()
110 */
111pub type smbc_share_mode = c_uint;
112
113/**
114 * Values for option SMB Encryption Level, as set and retrieved with
115 * smbc_setOptionSmbEncryptionLevel() and smbc_getOptionSmbEncryptionLevel()
116 */
117pub type smbc_smb_encrypt_level = c_uint;
118
119pub type smbc_bool = c_int;
120
121#[repr(C)]
122#[derive(Copy)]
123pub struct print_job_info {
124    /** numeric ID of the print job
125     */
126    pub id: c_ushort,
127
128    /** represents print job priority (lower numbers mean higher priority)
129     */
130    pub priority: c_ushort,
131
132    /** Size of the print job
133     */
134    pub size: size_t,
135
136    /** Name of the user that owns the print job
137     */
138    pub user: [c_char; 128usize],
139
140    /** Name of the print job. This will have no name if an anonymous print
141     *  file was opened. Ie smb://server/printer
142     */
143    pub name: [c_char; 128usize],
144
145    /** Time the print job was spooled
146     */
147    pub t: time_t,
148}
149
150impl clone::Clone for print_job_info {
151    fn clone(&self) -> Self {
152        *self
153    }
154}
155
156impl default::Default for print_job_info {
157    fn default() -> Self {
158        unsafe { mem::zeroed() }
159    }
160}
161
162pub enum _SMBCSRV {}
163pub type SMBCSRV = _SMBCSRV;
164pub enum _SMBCFILE {}
165pub type SMBCFILE = _SMBCFILE;
166pub type SMBCCTX = _SMBCCTX;
167
168pub type smbc_get_auth_data_fn = option::Option<
169    extern "C" fn(
170        srv: *const c_char,
171        shr: *const c_char,
172        wg: *mut c_char,
173        wglen: c_int,
174        un: *mut c_char,
175        unlen: c_int,
176        pw: *mut c_char,
177        pwlen: c_int,
178    ),
179>;
180pub type smbc_get_auth_data_with_context_fn = Option<
181    extern "C" fn(
182        c: *mut SMBCCTX,
183        srv: *const c_char,
184        shr: *const c_char,
185        wg: *mut c_char,
186        wglen: c_int,
187        un: *mut c_char,
188        unlen: c_int,
189        pw: *mut c_char,
190        pwlen: c_int,
191    ),
192>;
193pub type smbc_list_print_job_fn = option::Option<extern "C" fn(i: *mut print_job_info)>;
194pub type smbc_check_server_fn =
195    option::Option<extern "C" fn(c: *mut SMBCCTX, srv: *mut SMBCSRV) -> c_int>;
196pub type smbc_remove_unused_server_fn =
197    option::Option<extern "C" fn(c: *mut SMBCCTX, srv: *mut SMBCSRV) -> c_int>;
198pub type smbc_add_cached_srv_fn = option::Option<
199    extern "C" fn(
200        c: *mut SMBCCTX,
201        srv: *mut SMBCSRV,
202        server: *const c_char,
203        share: *const c_char,
204        workgroup: *const c_char,
205        username: *const c_char,
206    ) -> c_int,
207>;
208pub type smbc_get_cached_srv_fn = option::Option<
209    extern "C" fn(
210        c: *mut SMBCCTX,
211        server: *const c_char,
212        share: *const c_char,
213        workgroup: *const c_char,
214        username: *const c_char,
215    ) -> *mut SMBCSRV,
216>;
217pub type smbc_remove_cached_srv_fn =
218    option::Option<extern "C" fn(c: *mut SMBCCTX, srv: *mut SMBCSRV) -> c_int>;
219pub type smbc_purge_cached_fn = option::Option<extern "C" fn(c: *mut SMBCCTX) -> c_int>;
220
221pub type smbc_open_fn = option::Option<
222    extern "C" fn(
223        c: *mut SMBCCTX,
224        fname: *const c_char,
225        flags: c_int,
226        mode: mode_t,
227    ) -> *mut SMBCFILE,
228>;
229pub type smbc_creat_fn = option::Option<
230    extern "C" fn(c: *mut SMBCCTX, path: *const c_char, mode: mode_t) -> *mut SMBCFILE,
231>;
232pub type smbc_read_fn = option::Option<
233    extern "C" fn(c: *mut SMBCCTX, file: *mut SMBCFILE, buf: *mut c_void, count: size_t) -> ssize_t,
234>;
235pub type smbc_write_fn = option::Option<
236    extern "C" fn(
237        c: *mut SMBCCTX,
238        file: *mut SMBCFILE,
239        buf: *const c_void,
240        count: size_t,
241    ) -> ssize_t,
242>;
243pub type smbc_unlink_fn =
244    option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char) -> c_int>;
245pub type smbc_rename_fn = option::Option<
246    extern "C" fn(
247        ocontext: *mut SMBCCTX,
248        oname: *const c_char,
249        ncontext: *mut SMBCCTX,
250        nname: *const c_char,
251    ) -> c_int,
252>;
253pub type smbc_lseek_fn = option::Option<
254    extern "C" fn(c: *mut SMBCCTX, file: *mut SMBCFILE, offset: off_t, whence: c_int) -> off_t,
255>;
256pub type smbc_stat_fn =
257    option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char, st: *mut stat) -> c_int>;
258pub type smbc_statvfs_fn =
259    option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char, st: *mut statvfs) -> c_int>;
260pub type smbc_fstat_fn =
261    option::Option<extern "C" fn(c: *mut SMBCCTX, file: *mut SMBCFILE, st: *mut stat) -> c_int>;
262pub type smbc_close_fn =
263    option::Option<extern "C" fn(c: *mut SMBCCTX, file: *mut SMBCFILE) -> c_int>;
264pub type smbc_opendir_fn =
265    option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char) -> *mut SMBCFILE>;
266pub type smbc_closedir_fn =
267    option::Option<extern "C" fn(c: *mut SMBCCTX, dir: *mut SMBCFILE) -> c_int>;
268pub type smbc_readdir_fn =
269    option::Option<extern "C" fn(c: *mut SMBCCTX, dir: *mut SMBCFILE) -> *mut smbc_dirent>;
270pub type smbc_readdirplus_fn =
271    option::Option<extern "C" fn(c: *mut SMBCCTX, dir: *mut SMBCFILE) -> *mut libsmb_file_info>;
272pub type smbc_getdents_fn = option::Option<
273    extern "C" fn(
274        c: *mut SMBCCTX,
275        dir: *mut SMBCFILE,
276        dirp: *mut smbc_dirent,
277        count: c_int,
278    ) -> c_int,
279>;
280pub type smbc_mkdir_fn =
281    option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char, mode: mode_t) -> c_int>;
282pub type smbc_rmdir_fn =
283    option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char) -> c_int>;
284pub type smbc_telldir_fn =
285    option::Option<extern "C" fn(c: *mut SMBCCTX, dir: *mut SMBCFILE) -> off_t>;
286pub type smbc_lseekdir_fn =
287    option::Option<extern "C" fn(c: *mut SMBCCTX, dir: *mut SMBCFILE, offset: off_t) -> c_int>;
288pub type smbc_fstatdir_fn =
289    option::Option<extern "C" fn(c: *mut SMBCCTX, dir: *mut SMBCFILE, st: *mut stat) -> c_int>;
290pub type smbc_chmod_fn =
291    option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char, mode: mode_t) -> c_int>;
292pub type smbc_utimes_fn = option::Option<
293    extern "C" fn(c: *mut SMBCCTX, fname: *const c_char, tbuf: *mut timeval) -> c_int,
294>;
295pub type smbc_setxattr_fn = option::Option<
296    extern "C" fn(
297        context: *mut SMBCCTX,
298        fname: *const c_char,
299        name: *const c_char,
300        value: *const c_void,
301        size: size_t,
302        flags: c_int,
303    ) -> c_int,
304>;
305pub type smbc_getxattr_fn = option::Option<
306    extern "C" fn(
307        context: *mut SMBCCTX,
308        fname: *const c_char,
309        name: *const c_char,
310        value: *const c_void,
311        size: size_t,
312    ) -> c_int,
313>;
314pub type smbc_removexattr_fn = option::Option<
315    extern "C" fn(context: *mut SMBCCTX, fname: *const c_char, name: *const c_char) -> c_int,
316>;
317pub type smbc_listxattr_fn = option::Option<
318    extern "C" fn(
319        context: *mut SMBCCTX,
320        fname: *const c_char,
321        list: *mut c_char,
322        size: size_t,
323    ) -> c_int,
324>;
325pub type smbc_print_file_fn = option::Option<
326    extern "C" fn(
327        c_file: *mut SMBCCTX,
328        fname: *const c_char,
329        c_print: *mut SMBCCTX,
330        printq: *const c_char,
331    ) -> c_int,
332>;
333pub type smbc_open_print_job_fn =
334    option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char) -> *mut SMBCFILE>;
335pub type smbc_list_print_jobs_fn = option::Option<
336    extern "C" fn(c: *mut SMBCCTX, fname: *const c_char, _fn: smbc_list_print_job_fn) -> c_int,
337>;
338pub type smbc_unlink_print_job_fn =
339    option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char, id: c_int) -> c_int>;
340
341pub enum SMBC_internal_data {}
342#[repr(C)]
343#[derive(Copy)]
344pub struct _SMBCCTX {
345    pub debug: c_int,
346    pub netbios_name: *mut c_char,
347    pub workgroup: *mut c_char,
348    pub user: *mut c_char,
349    pub timeout: c_int,
350    pub open: smbc_open_fn,
351    pub creat: smbc_creat_fn,
352    pub read: smbc_read_fn,
353    pub write: smbc_write_fn,
354    pub unlink: smbc_unlink_fn,
355    pub rename: smbc_rename_fn,
356    pub lseek: smbc_lseek_fn,
357    pub stat: smbc_stat_fn,
358    pub fstat: smbc_fstat_fn,
359    pub close_fn: smbc_close_fn,
360    pub opendir: smbc_opendir_fn,
361    pub closedir: smbc_closedir_fn,
362    pub readdir: smbc_readdir_fn,
363    pub getdents: smbc_getdents_fn,
364    pub mkdir: smbc_mkdir_fn,
365    pub rmdir: smbc_rmdir_fn,
366    pub telldir: smbc_telldir_fn,
367    pub lseekdir: smbc_lseekdir_fn,
368    pub fstatdir: smbc_fstatdir_fn,
369    pub chmod: smbc_chmod_fn,
370    pub utimes: smbc_utimes_fn,
371    pub setxattr: smbc_setxattr_fn,
372    pub getxattr: smbc_getxattr_fn,
373    pub removexattr: smbc_removexattr_fn,
374    pub listxattr: smbc_listxattr_fn,
375    pub print_file: smbc_print_file_fn,
376    pub open_print_job: smbc_open_print_job_fn,
377    pub list_print_jobs: smbc_list_print_jobs_fn,
378    pub unlink_print_job: smbc_unlink_print_job_fn,
379    pub callbacks: _smbc_callbacks,
380    pub reserved: *mut c_void,
381    pub flags: c_int,
382    pub options: _smbc_options,
383    pub internal: *mut SMBC_internal_data,
384}
385
386impl clone::Clone for _SMBCCTX {
387    fn clone(&self) -> Self {
388        *self
389    }
390}
391
392impl default::Default for _SMBCCTX {
393    fn default() -> Self {
394        unsafe { mem::zeroed() }
395    }
396}
397
398#[repr(C)]
399#[derive(Copy)]
400pub struct _smbc_callbacks {
401    pub auth_fn: smbc_get_auth_data_fn,
402    pub check_server_fn: smbc_check_server_fn,
403    pub remove_unused_server_fn: smbc_remove_unused_server_fn,
404    pub add_cached_srv_fn: smbc_add_cached_srv_fn,
405    pub get_cached_srv_fn: smbc_get_cached_srv_fn,
406    pub remove_cached_srv_fn: smbc_remove_cached_srv_fn,
407    pub purge_cached_fn: smbc_purge_cached_fn,
408}
409
410impl clone::Clone for _smbc_callbacks {
411    fn clone(&self) -> Self {
412        *self
413    }
414}
415
416impl default::Default for _smbc_callbacks {
417    fn default() -> Self {
418        unsafe { mem::zeroed() }
419    }
420}
421
422#[repr(C)]
423#[derive(Copy)]
424pub struct _smbc_options {
425    pub browse_max_lmb_count: c_int,
426    pub urlencode_readdir_entries: c_int,
427    pub one_share_per_server: c_int,
428}
429impl clone::Clone for _smbc_options {
430    fn clone(&self) -> Self {
431        *self
432    }
433}
434impl default::Default for _smbc_options {
435    fn default() -> Self {
436        unsafe { mem::zeroed() }
437    }
438}
439
440#[link(name = "smbclient")]
441extern "C" {
442    pub fn smbc_setDebug(c: *mut SMBCCTX, debug: c_int);
443    pub fn smbc_getNetbiosName(c: *mut SMBCCTX) -> *mut c_char;
444    pub fn smbc_setNetbiosName(c: *mut SMBCCTX, netbios_name: *mut c_char);
445    pub fn smbc_getWorkgroup(c: *mut SMBCCTX) -> *mut c_char;
446    pub fn smbc_setWorkgroup(c: *mut SMBCCTX, workgroup: *mut c_char);
447    pub fn smbc_getUser(c: *mut SMBCCTX) -> *mut c_char;
448    pub fn smbc_setUser(c: *mut SMBCCTX, user: *mut c_char);
449    pub fn smbc_getTimeout(c: *mut SMBCCTX) -> c_int;
450    pub fn smbc_setTimeout(c: *mut SMBCCTX, timeout: c_int);
451    pub fn smbc_setOptionDebugToStderr(c: *mut SMBCCTX, b: smbc_bool);
452    pub fn smbc_setOptionOpenShareMode(c: *mut SMBCCTX, share_mode: smbc_share_mode);
453    pub fn smbc_setOptionSmbEncryptionLevel(c: *mut SMBCCTX, level: smbc_smb_encrypt_level);
454    pub fn smbc_setOptionCaseSensitive(c: *mut SMBCCTX, b: smbc_bool);
455    pub fn smbc_setOptionBrowseMaxLmbCount(c: *mut SMBCCTX, count: c_int);
456    pub fn smbc_setOptionUrlEncodeReaddirEntries(c: *mut SMBCCTX, b: smbc_bool);
457    pub fn smbc_setOptionOneSharePerServer(c: *mut SMBCCTX, b: smbc_bool);
458    pub fn smbc_setOptionUseKerberos(c: *mut SMBCCTX, b: smbc_bool);
459    pub fn smbc_setOptionFallbackAfterKerberos(c: *mut SMBCCTX, b: smbc_bool);
460    pub fn smbc_setOptionNoAutoAnonymousLogin(c: *mut SMBCCTX, b: smbc_bool);
461    pub fn smbc_setOptionUseCCache(c: *mut SMBCCTX, b: smbc_bool);
462    pub fn smbc_setFunctionAuthDataWithContext(
463        c: *mut SMBCCTX,
464        _fn: smbc_get_auth_data_with_context_fn,
465    );
466    pub fn smbc_getFunctionOpen(c: *mut SMBCCTX) -> smbc_open_fn;
467    pub fn smbc_getFunctionRead(c: *mut SMBCCTX) -> smbc_read_fn;
468    pub fn smbc_getFunctionWrite(c: *mut SMBCCTX) -> smbc_write_fn;
469    pub fn smbc_getFunctionUnlink(c: *mut SMBCCTX) -> smbc_unlink_fn;
470    pub fn smbc_getFunctionRename(c: *mut SMBCCTX) -> smbc_rename_fn;
471    pub fn smbc_getFunctionLseek(c: *mut SMBCCTX) -> smbc_lseek_fn;
472    pub fn smbc_getFunctionStat(c: *mut SMBCCTX) -> smbc_stat_fn;
473    pub fn smbc_getFunctionStatVFS(c: *mut SMBCCTX) -> smbc_statvfs_fn;
474    pub fn smbc_getFunctionClose(c: *mut SMBCCTX) -> smbc_close_fn;
475    pub fn smbc_getFunctionOpendir(c: *mut SMBCCTX) -> smbc_opendir_fn;
476    pub fn smbc_getFunctionClosedir(c: *mut SMBCCTX) -> smbc_closedir_fn;
477    pub fn smbc_getFunctionReaddir(c: *mut SMBCCTX) -> smbc_readdir_fn;
478    pub fn smbc_getFunctionReaddirPlus(c: *mut SMBCCTX) -> smbc_readdirplus_fn;
479    pub fn smbc_getFunctionMkdir(c: *mut SMBCCTX) -> smbc_mkdir_fn;
480    pub fn smbc_getFunctionRmdir(c: *mut SMBCCTX) -> smbc_rmdir_fn;
481    pub fn smbc_getFunctionChmod(c: *mut SMBCCTX) -> smbc_chmod_fn;
482    pub fn smbc_getFunctionPrintFile(c: *mut SMBCCTX) -> smbc_print_file_fn;
483    pub fn smbc_new_context() -> *mut SMBCCTX;
484    pub fn smbc_free_context(context: *mut SMBCCTX, shutdown_ctx: c_int) -> c_int;
485    pub fn smbc_init_context(context: *mut SMBCCTX) -> *mut SMBCCTX;
486    pub fn smbc_version() -> *const c_char;
487}