pavao-sys 0.3.1

ffi bindings for libsmbclient. Use Pavao to access Samba shares from Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
#![warn(missing_docs)]

//! Raw Rust bindings to Samba's `libsmbclient` library.
//!
//! This crate mirrors the native C types and functions. Most callers should use the safe
//! [`pavao`](https://docs.rs/pavao) crate instead.
//!
//! # Safety
//!
//! The bindings do not validate pointers, lifetimes, buffer lengths, context state, or native
//! return values. Callers must uphold the corresponding `libsmbclient` C API contracts.
//! `libsmbclient` also shares process-wide parameter state, so separate contexts are not sufficient
//! for thread safety. Callers must serialize all raw native activity with one process-wide lock.
//! These bindings do not coordinate with Pavão's safe-wrapper lock; raw calls must never race a
//! Pavão operation or any other raw `libsmbclient` call.
//!
//! # Callback contracts
//!
//! Unless an alias says otherwise, callbacks require a live, initialized context; every file or
//! directory handle must be live and belong to that context; C strings must be NUL-terminated and
//! readable for the call; and buffers must be valid for the supplied size. File and directory
//! operation callbacks generally return `-1` or null with `errno` set on failure. Server-cache
//! callbacks instead return one on failure and do not promise an `errno` value. Callback
//! implementations must not unwind across the C ABI boundary.
//!
//! Directory-entry pointers are borrowed from `libsmbclient`. They may be invalidated by the next
//! read on the same directory or when the directory is closed, so callers must copy needed data.
//!
//! # Feature flags
//!
//! | name       | description                                         | default |
//! |------------|-----------------------------------------------------|---------|
//! | `abi-0-6`  | Require libsmbclient ABI 0.6 or newer.             |         |
//! | `abi-0-8`  | Require libsmbclient ABI 0.8 or newer.             |         |
//! | `vendored` | Build the bundled Samba source instead of using the system library. |         |
//!

#![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)]
/// A directory entry returned by `libsmbclient`.
pub struct smbc_dirent {
    /// Native entry type discriminator.
    ///
    /// Values 1 through 9 represent workgroups, servers, file shares, printer shares,
    /// communications shares, IPC shares, directories, files, and links, respectively.
    pub smbc_type: c_uint,
    /// Total size of this directory-entry structure in bytes.
    pub dirlen: c_uint,
    /// Length of `comment` in bytes, excluding its terminating NUL byte.
    pub commentlen: c_uint,
    /// Pointer to the NUL-terminated entry comment.
    pub comment: *mut c_char,
    /// Length of `name` in bytes, excluding its terminating NUL byte.
    pub namelen: c_uint,
    /// Flexible trailing storage containing the NUL-terminated entry name.
    pub name: [c_char; 1usize],
}
#[repr(C)]
#[derive(Copy)]
/// Extended directory-entry metadata returned by `libsmbclient`.
pub struct libsmb_file_info {
    /// File size in bytes.
    pub size: u64,
    /// DOS attribute bitmask.
    pub attrs: c_ushort,
    /// Owning user identifier.
    pub uid: c_uint,
    /// Owning group identifier.
    pub gid: c_uint,
    /// Creation time, or zero when unsupported by the server.
    pub btime_ts: timespec,
    /// Last content-modification time.
    pub mtime_ts: timespec,
    /// Last access time.
    pub atime_ts: timespec,
    /// Last metadata-change time.
    pub ctime_ts: timespec,
    /// Pointer to the NUL-terminated entry name.
    pub name: *mut c_char,
    /// Pointer to the NUL-terminated DOS-compatible short name.
    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() }
    }
}

/// Native value for the `open_share_mode` option.
pub type smbc_share_mode = c_uint;

/// Native value for the SMB transport encryption policy.
pub type smbc_smb_encrypt_level = c_int;

/// Native Boolean represented as a C integer.
pub type smbc_bool = c_int;

/// Bitmask describing filesystem capabilities reported by `libsmbclient`.
pub type smbc_vfs_feature = c_uint;

/// Directory-entry type for an SMB workgroup.
pub const SMBC_WORKGROUP: c_uint = 1;
/// Directory-entry type for an SMB server.
pub const SMBC_SERVER: c_uint = 2;
/// Directory-entry type for an SMB file share.
pub const SMBC_FILE_SHARE: c_uint = 3;
/// Directory-entry type for an SMB printer share.
pub const SMBC_PRINTER_SHARE: c_uint = 4;
/// Directory-entry type for an SMB communications share.
pub const SMBC_COMMS_SHARE: c_uint = 5;
/// Directory-entry type for an SMB IPC share.
pub const SMBC_IPC_SHARE: c_uint = 6;
/// Directory-entry type for an SMB directory.
pub const SMBC_DIR: c_uint = 7;
/// Directory-entry type for an SMB file.
pub const SMBC_FILE: c_uint = 8;
/// Directory-entry type for an SMB symbolic link.
pub const SMBC_LINK: c_uint = 9;
/// Smallest file descriptor returned by `libsmbclient`.
pub const SMBC_BASE_FD: c_int = 10_000;

/// Share mode that denies DOS compatibility access.
pub const SMBC_SHAREMODE_DENY_DOS: smbc_share_mode = 0;
/// Share mode that denies all access sharing.
pub const SMBC_SHAREMODE_DENY_ALL: smbc_share_mode = 1;
/// Share mode that denies write sharing.
pub const SMBC_SHAREMODE_DENY_WRITE: smbc_share_mode = 2;
/// Share mode that denies read sharing.
pub const SMBC_SHAREMODE_DENY_READ: smbc_share_mode = 3;
/// Share mode that allows all sharing.
pub const SMBC_SHAREMODE_DENY_NONE: smbc_share_mode = 4;
/// Share mode that denies file-control-block sharing.
pub const SMBC_SHAREMODE_DENY_FCB: smbc_share_mode = 7;

/// Default SMB encryption policy.
pub const SMBC_ENCRYPTLEVEL_DEFAULT: smbc_smb_encrypt_level = -1;
/// SMB encryption is disabled.
pub const SMBC_ENCRYPTLEVEL_NONE: smbc_smb_encrypt_level = 0;
/// SMB encryption is requested when available.
pub const SMBC_ENCRYPTLEVEL_REQUEST: smbc_smb_encrypt_level = 1;
/// SMB encryption is required.
pub const SMBC_ENCRYPTLEVEL_REQUIRE: smbc_smb_encrypt_level = 2;

/// Extended-attribute flag that requires a new attribute.
pub const SMBC_XATTR_FLAG_CREATE: c_int = 0x1;
/// Extended-attribute flag that requires an existing attribute.
pub const SMBC_XATTR_FLAG_REPLACE: c_int = 0x2;

/// DOS attribute bit for read-only files.
pub const SMBC_DOS_MODE_READONLY: c_int = 0x01;
/// DOS attribute bit for hidden files.
pub const SMBC_DOS_MODE_HIDDEN: c_int = 0x02;
/// DOS attribute bit for system files.
pub const SMBC_DOS_MODE_SYSTEM: c_int = 0x04;
/// DOS attribute bit for volume identifiers.
pub const SMBC_DOS_MODE_VOLUME_ID: c_int = 0x08;
/// DOS attribute bit for directories.
pub const SMBC_DOS_MODE_DIRECTORY: c_int = 0x10;
/// DOS attribute bit for archived files.
pub const SMBC_DOS_MODE_ARCHIVE: c_int = 0x20;

/// VFS feature indicating a read-only filesystem.
pub const SMBC_VFS_FEATURE_RDONLY: smbc_vfs_feature = 1 << 0;
/// VFS feature indicating DFS support.
pub const SMBC_VFS_FEATURE_DFS: smbc_vfs_feature = 1 << 28;
/// VFS feature indicating case-insensitive path handling.
pub const SMBC_VFS_FEATURE_CASE_INSENSITIVE: smbc_vfs_feature = 1 << 29;
/// VFS feature indicating the absence of Unix CIFS extensions.
pub const SMBC_VFS_FEATURE_NO_UNIXCIFS: smbc_vfs_feature = 1 << 30;

/// Notification filter for file-name changes.
pub const SMBC_NOTIFY_CHANGE_FILE_NAME: c_uint = 0x001;
/// Notification filter for directory-name changes.
pub const SMBC_NOTIFY_CHANGE_DIR_NAME: c_uint = 0x002;
/// Notification filter for attribute changes.
pub const SMBC_NOTIFY_CHANGE_ATTRIBUTES: c_uint = 0x004;
/// Notification filter for size changes.
pub const SMBC_NOTIFY_CHANGE_SIZE: c_uint = 0x008;
/// Notification filter for last-write changes.
pub const SMBC_NOTIFY_CHANGE_LAST_WRITE: c_uint = 0x010;
/// Notification filter for last-access changes.
pub const SMBC_NOTIFY_CHANGE_LAST_ACCESS: c_uint = 0x020;
/// Notification filter for creation-time changes.
pub const SMBC_NOTIFY_CHANGE_CREATION: c_uint = 0x040;
/// Notification filter for extended-attribute changes.
pub const SMBC_NOTIFY_CHANGE_EA: c_uint = 0x080;
/// Notification filter for security changes.
pub const SMBC_NOTIFY_CHANGE_SECURITY: c_uint = 0x100;
/// Notification filter for stream-name changes.
pub const SMBC_NOTIFY_CHANGE_STREAM_NAME: c_uint = 0x200;
/// Notification filter for stream-size changes.
pub const SMBC_NOTIFY_CHANGE_STREAM_SIZE: c_uint = 0x400;
/// Notification filter for stream-write changes.
pub const SMBC_NOTIFY_CHANGE_STREAM_WRITE: c_uint = 0x800;

/// Notification action for an added entry.
pub const SMBC_NOTIFY_ACTION_ADDED: c_uint = 1;
/// Notification action for a removed entry.
pub const SMBC_NOTIFY_ACTION_REMOVED: c_uint = 2;
/// Notification action for a modified entry.
pub const SMBC_NOTIFY_ACTION_MODIFIED: c_uint = 3;
/// Notification action for an old entry name.
pub const SMBC_NOTIFY_ACTION_OLD_NAME: c_uint = 4;
/// Notification action for a new entry name.
pub const SMBC_NOTIFY_ACTION_NEW_NAME: c_uint = 5;
/// Notification action for an added stream.
pub const SMBC_NOTIFY_ACTION_ADDED_STREAM: c_uint = 6;
/// Notification action for a removed stream.
pub const SMBC_NOTIFY_ACTION_REMOVED_STREAM: c_uint = 7;
/// Notification action for a modified stream.
pub const SMBC_NOTIFY_ACTION_MODIFIED_STREAM: c_uint = 8;

#[repr(C)]
#[derive(Copy)]
/// Information about a queued SMB print job.
pub struct print_job_info {
    /// Numeric print-job identifier.
    pub id: c_ushort,
    /// Print priority, where lower values indicate higher priority.
    pub priority: c_ushort,
    /// Print-job size in bytes.
    pub size: size_t,
    /// NUL-terminated name of the user that owns the job.
    pub user: [c_char; 128usize],
    /// NUL-terminated job name, empty for an anonymous printer file.
    pub name: [c_char; 128usize],
    /// Time at which the job was spooled.
    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() }
    }
}

/// Opaque native SMB server handle.
pub enum _SMBCSRV {}
/// Native SMB server handle.
pub type SMBCSRV = _SMBCSRV;
/// Opaque native SMB file or directory handle.
pub enum _SMBCFILE {}
/// Native SMB file or directory handle.
pub type SMBCFILE = _SMBCFILE;
/// Opaque native SMB client context.
pub enum _SMBCCTX {}
/// Native `libsmbclient` context.
pub type SMBCCTX = _SMBCCTX;

/// Optional callback that supplies authentication strings.
///
/// `srv` and `shr` are borrowed NUL-terminated strings. The callback must write NUL-terminated
/// workgroup, username, and password values without exceeding `wglen`, `unlen`, and `pwlen`.
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,
    ),
>;
/// Optional context-aware callback that supplies authentication strings.
///
/// `c` must be live, `srv` and `shr` are borrowed NUL-terminated strings, and each output buffer
/// must receive a NUL-terminated value without exceeding its corresponding length.
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,
    ),
>;
/// Optional callback that receives native `libsmbclient` diagnostics.
pub type smbc_debug_callback_fn =
    option::Option<extern "C" fn(private_ptr: *mut c_void, level: c_int, message: *const c_char)>;
/// Optional callback invoked for each print job in a queue.
///
/// `i` is borrowed for the callback invocation and must not be retained or freed.
pub type smbc_list_print_job_fn = option::Option<extern "C" fn(i: *mut print_job_info)>;
/// Optional callback that checks whether a cached server is still available.
///
/// `srv` must be a live server handle associated with `c`. Returns zero on success or one on
/// failure.
pub type smbc_check_server_fn =
    option::Option<extern "C" fn(c: *mut SMBCCTX, srv: *mut SMBCSRV) -> c_int>;
/// Optional callback that removes an unused cached server.
///
/// `srv` must be a live server handle associated with `c`. Returns zero on success or one on
/// failure.
pub type smbc_remove_unused_server_fn =
    option::Option<extern "C" fn(c: *mut SMBCCTX, srv: *mut SMBCSRV) -> c_int>;
/// Optional callback that inserts a server into the connection cache.
///
/// `srv` must be live, and all name pointers must reference NUL-terminated strings for the call.
/// Returns zero on success or one on failure.
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,
>;
/// Optional callback that looks up a server in the connection cache.
///
/// All name pointers must reference NUL-terminated strings for the call. A non-null result is a
/// borrowed cache entry owned by `c`; null indicates no match or failure.
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,
>;
/// Optional callback that removes a server from the connection cache.
///
/// `srv` must be a live server handle associated with `c`. Returns zero on success or one on
/// failure.
pub type smbc_remove_cached_srv_fn =
    option::Option<extern "C" fn(c: *mut SMBCCTX, srv: *mut SMBCSRV) -> c_int>;
/// Optional callback that purges the connection cache.
///
/// Returns zero on success or one when cached servers remain in use.
pub type smbc_purge_cached_fn = option::Option<extern "C" fn(c: *mut SMBCCTX) -> c_int>;

/// Optional callback that opens a remote file.
///
/// `fname` must be a NUL-terminated SMB URL and `flags` must be valid native open flags. Returns a
/// live file handle owned by `c`, or null with `errno` set on failure.
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,
>;
/// Optional callback that creates a remote file.
///
/// `path` must be a NUL-terminated SMB URL. Returns a live file handle owned by `c`, or null with
/// `errno` set on failure.
pub type smbc_creat_fn = option::Option<
    extern "C" fn(c: *mut SMBCCTX, path: *const c_char, mode: mode_t) -> *mut SMBCFILE,
>;
/// Optional callback that reads bytes from an open remote file.
///
/// `file` must be live and belong to `c`; `buf` must be writable for `count` bytes. Returns the
/// number of bytes read, zero at end of file, or `-1` with `errno` set on failure.
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,
>;
/// Optional callback that writes bytes to an open remote file.
///
/// `file` must be live and belong to `c`; `buf` must be readable for `count` bytes. Returns the
/// number of bytes written, or `-1` with `errno` set on failure.
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,
>;
/// Callback invoked while `libsmbclient` splices data between two open files.
pub type smbc_splice_callback_fn =
    option::Option<extern "C" fn(n: off_t, priv_: *mut c_void) -> c_int>;
/// Optional callback that splices data between two open remote files.
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,
>;
/// Optional callback that removes a remote file.
///
/// `fname` must be a NUL-terminated SMB URL. Returns zero on success or `-1` with `errno` set.
pub type smbc_unlink_fn =
    option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char) -> c_int>;
/// Optional callback that renames or moves a remote entry.
///
/// Both contexts must be live and both name pointers must be NUL-terminated SMB URLs. Returns zero
/// on success or `-1` with `errno` set on failure.
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,
>;
/// Optional callback that changes an open file's offset.
///
/// `file` must be live and belong to `c`; `whence` must be a valid `SEEK_*` value. Returns the new
/// offset or `-1` with `errno` set on failure.
pub type smbc_lseek_fn = option::Option<
    extern "C" fn(c: *mut SMBCCTX, file: *mut SMBCFILE, offset: off_t, whence: c_int) -> off_t,
>;
/// Optional callback that reads metadata for a remote path.
///
/// `fname` must be a NUL-terminated SMB URL and `st` must be writable for one `stat`. Returns zero
/// on success or `-1` with `errno` set on failure.
pub type smbc_stat_fn =
    option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char, st: *mut stat) -> c_int>;
/// Optional callback that reads filesystem statistics for a remote path.
///
/// `fname` must be a NUL-terminated SMB URL and `st` must be writable for one `statvfs`. Returns
/// zero on success or `-1` with `errno` set on failure.
pub type smbc_statvfs_fn =
    option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char, st: *mut statvfs) -> c_int>;
/// Optional callback that reads filesystem statistics from an open file handle.
pub type smbc_fstatvfs_fn =
    option::Option<extern "C" fn(c: *mut SMBCCTX, file: *mut SMBCFILE, st: *mut statvfs) -> c_int>;
/// Optional callback that changes the length of an open remote file.
pub type smbc_ftruncate_fn =
    option::Option<extern "C" fn(c: *mut SMBCCTX, file: *mut SMBCFILE, size: off_t) -> c_int>;
/// Optional callback that reads metadata from an open file handle.
///
/// `file` must be live and belong to `c`; `st` must be writable for one `stat`. Returns zero on
/// success or `-1` with `errno` set on failure.
pub type smbc_fstat_fn =
    option::Option<extern "C" fn(c: *mut SMBCCTX, file: *mut SMBCFILE, st: *mut stat) -> c_int>;
/// Optional callback that closes an open file handle.
///
/// `file` must be live and belong to `c`. A successful zero return invalidates the handle; `-1`
/// indicates failure with `errno` set.
pub type smbc_close_fn =
    option::Option<extern "C" fn(c: *mut SMBCCTX, file: *mut SMBCFILE) -> c_int>;
/// Optional callback that opens a remote directory.
///
/// `fname` must be a NUL-terminated SMB URL. Returns a live directory handle owned by `c`, or null
/// with `errno` set on failure.
pub type smbc_opendir_fn =
    option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char) -> *mut SMBCFILE>;
/// Optional callback that closes an open directory handle.
///
/// `dir` must be live and belong to `c`. A successful zero return invalidates the handle; `-1`
/// indicates failure with `errno` set.
pub type smbc_closedir_fn =
    option::Option<extern "C" fn(c: *mut SMBCCTX, dir: *mut SMBCFILE) -> c_int>;
/// Optional callback that reads the next directory entry.
///
/// `dir` must be live and belong to `c`. The returned entry is borrowed until the next read or
/// directory close. Null means end-of-directory or failure; inspect `errno` to distinguish them.
pub type smbc_readdir_fn =
    option::Option<extern "C" fn(c: *mut SMBCCTX, dir: *mut SMBCFILE) -> *mut smbc_dirent>;
/// Optional callback that reads the next directory entry with metadata.
///
/// `dir` must be live and belong to `c`. The returned metadata is read-only and borrowed until the
/// next read or directory close. Null means end-of-directory or failure.
pub type smbc_readdirplus_fn =
    option::Option<extern "C" fn(c: *mut SMBCCTX, dir: *mut SMBCFILE) -> *mut libsmb_file_info>;
/// Optional callback that reads the next directory entry and metadata into `st`.
#[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,
>;
/// Optional callback that reads multiple directory entries into a buffer.
///
/// `dir` must be live and `dirp` must be writable for `count` bytes. Returns bytes written, zero at
/// end-of-directory, or `-1` with `errno` set on failure.
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,
>;
/// Optional callback that creates a remote directory.
///
/// `fname` must be a NUL-terminated SMB URL. Returns zero on success or `-1` with `errno` set.
pub type smbc_mkdir_fn =
    option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char, mode: mode_t) -> c_int>;
/// Optional callback that removes a remote directory.
///
/// `fname` must be a NUL-terminated SMB URL. Returns zero on success or `-1` with `errno` set.
pub type smbc_rmdir_fn =
    option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char) -> c_int>;
/// Optional callback that returns the current directory-stream offset.
///
/// `dir` must be live and belong to `c`. Returns the current offset or `-1` with `errno` set.
pub type smbc_telldir_fn =
    option::Option<extern "C" fn(c: *mut SMBCCTX, dir: *mut SMBCFILE) -> off_t>;
/// Optional callback that changes a directory-stream offset.
///
/// `dir` must be live and belong to `c`, and `offset` must come from the same stream. Returns zero
/// on success or `-1` with `errno` set on failure.
pub type smbc_lseekdir_fn =
    option::Option<extern "C" fn(c: *mut SMBCCTX, dir: *mut SMBCFILE, offset: off_t) -> c_int>;
/// Optional callback that reads metadata from an open directory handle.
///
/// `dir` must be live and belong to `c`; `st` must be writable for one `stat`. Returns zero on
/// success or `-1` with `errno` set on failure.
pub type smbc_fstatdir_fn =
    option::Option<extern "C" fn(c: *mut SMBCCTX, dir: *mut SMBCFILE, st: *mut stat) -> c_int>;
/// A single directory notification action reported by `libsmbclient`.
#[repr(C)]
pub struct smbc_notify_callback_action {
    /// Notification action discriminator.
    pub action: u32,
    /// NUL-terminated path associated with the action.
    pub filename: *const c_char,
}
/// Callback invoked with directory notification actions.
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,
>;
/// Optional callback that watches a directory for changes.
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,
>;
/// Optional callback that changes a remote entry's POSIX mode.
///
/// `fname` must be a NUL-terminated SMB URL. Returns zero on success or `-1` with `errno` set.
pub type smbc_chmod_fn =
    option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char, mode: mode_t) -> c_int>;
/// Optional callback that changes a remote entry's access and modification times.
///
/// `fname` must be a NUL-terminated SMB URL and `tbuf` must reference two valid `timeval` values.
/// Returns zero on success or `-1` with `errno` set on failure.
pub type smbc_utimes_fn = option::Option<
    extern "C" fn(c: *mut SMBCCTX, fname: *const c_char, tbuf: *mut timeval) -> c_int,
>;
/// Optional callback that writes a remote entry's extended attribute.
///
/// `fname` and `name` must be NUL-terminated; `value` must be readable for `size` bytes. Returns
/// zero on success or `-1` with `errno` set on failure.
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,
>;
/// Optional callback that reads a remote entry's extended attribute.
///
/// `fname` and `name` must be NUL-terminated. When `size` is nonzero, `value` must reference a
/// writable buffer of that size; a zero size queries the required length. Returns the value size
/// or `-1` with `errno` set on failure.
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,
>;
/// Optional callback that removes a remote entry's extended attribute.
///
/// `fname` and `name` must be NUL-terminated. Returns zero on success or `-1` with `errno` set.
pub type smbc_removexattr_fn = option::Option<
    extern "C" fn(context: *mut SMBCCTX, fname: *const c_char, name: *const c_char) -> c_int,
>;
/// Optional callback that lists a remote entry's extended attributes.
///
/// `fname` must be NUL-terminated. When `size` is nonzero, `list` must be writable for that many
/// bytes; a zero size queries the required length. Returns the list size or `-1` on failure.
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,
>;
/// Optional callback that submits a remote file to a print queue.
///
/// Both contexts must be live and both string pointers must be NUL-terminated SMB URLs. Returns
/// zero on success or `-1` with `errno` set on failure.
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,
>;
/// Optional callback that opens a new print job.
///
/// `fname` must be a NUL-terminated print-queue URL. Returns a live print handle owned by `c`, or
/// null with `errno` set on failure.
pub type smbc_open_print_job_fn =
    option::Option<extern "C" fn(c: *mut SMBCCTX, fname: *const c_char) -> *mut SMBCFILE>;
/// Optional callback that enumerates jobs in a print queue.
///
/// `fname` must be a NUL-terminated queue URL and `_fn` must remain callable throughout the
/// operation. Returns zero on success or `-1` with `errno` set on failure.
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,
>;
/// Optional callback that removes a job from a print queue.
///
/// `fname` must be a NUL-terminated queue URL. Returns zero on success or `-1` with `errno` set.
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" {
    /// Returns the native debug verbosity configured for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    pub fn smbc_getDebug(c: *mut SMBCCTX) -> c_int;
    /// Sets the native debug verbosity for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    pub fn smbc_setDebug(c: *mut SMBCCTX, debug: c_int);
    /// Sets the global `libsmbclient` configuration file used by `c`.
    ///
    /// Returns zero on success or `-1` when the file cannot be loaded.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer, and `file` must point to a valid
    /// NUL-terminated path.
    pub fn smbc_setConfiguration(c: *mut SMBCCTX, file: *const c_char) -> c_int;
    /// Installs the callback used for native diagnostic messages.
    ///
    /// The callback is process-global despite being selected through `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer. If `callback` is `Some`, its function and
    /// `private_ptr` must remain valid whenever `libsmbclient` invokes it, and the callback must
    /// not unwind across the C ABI boundary.
    pub fn smbc_setLogCallback(
        c: *mut SMBCCTX,
        private_ptr: *mut c_void,
        callback: smbc_debug_callback_fn,
    );
    /// Returns the NetBIOS name configured for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be valid. The returned pointer must not be modified or freed and is invalidated by
    /// changing the name or destroying `c`.
    pub fn smbc_getNetbiosName(c: *mut SMBCCTX) -> *const c_char;
    /// Sets the NetBIOS name configured for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be valid and `netbios_name` must point to a valid NUL-terminated string.
    pub fn smbc_setNetbiosName(c: *mut SMBCCTX, netbios_name: *const c_char);
    /// Returns the workgroup configured for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be valid. The returned pointer must not be modified or freed and is invalidated by
    /// changing the workgroup or destroying `c`.
    pub fn smbc_getWorkgroup(c: *mut SMBCCTX) -> *const c_char;
    /// Sets the workgroup configured for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be valid and `workgroup` must point to a valid NUL-terminated string.
    pub fn smbc_setWorkgroup(c: *mut SMBCCTX, workgroup: *const c_char);
    /// Returns the username configured for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be valid. The returned pointer must not be modified or freed and is invalidated by
    /// changing the username or destroying `c`.
    pub fn smbc_getUser(c: *mut SMBCCTX) -> *const c_char;
    /// Sets the username configured for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be valid and `user` must point to a valid NUL-terminated string.
    pub fn smbc_setUser(c: *mut SMBCCTX, user: *const c_char);
    /// Returns the timeout configured for `c` in milliseconds.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    pub fn smbc_getTimeout(c: *mut SMBCCTX) -> c_int;
    /// Sets the timeout for `c` in milliseconds.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    pub fn smbc_setTimeout(c: *mut SMBCCTX, timeout: c_int);
    /// Returns the TCP port configured for `c`, or zero for the native default.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    pub fn smbc_getPort(c: *mut SMBCCTX) -> u16;
    /// Sets the TCP port used by `c`, where zero selects the native default.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    pub fn smbc_setPort(c: *mut SMBCCTX, port: u16);
    /// Returns whether full SMB time attribute names are enabled for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    pub fn smbc_getOptionFullTimeNames(c: *mut SMBCCTX) -> smbc_bool;
    /// Enables or disables full SMB time attribute names for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    pub fn smbc_setOptionFullTimeNames(c: *mut SMBCCTX, b: smbc_bool);
    /// Returns the user data pointer stored in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    pub fn smbc_getOptionUserData(c: *mut SMBCCTX) -> *mut c_void;
    /// Stores an opaque user data pointer in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer. The caller must ensure the pointed-to data
    /// remains valid for any native code that retrieves or uses it.
    pub fn smbc_setOptionUserData(c: *mut SMBCCTX, user_data: *mut c_void);
    /// Returns whether the password configured for `c` is an NT hash.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    pub fn smbc_getOptionUseNTHash(c: *mut SMBCCTX) -> smbc_bool;
    /// Marks the password configured for `c` as an NT hash when enabled.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    pub fn smbc_setOptionUseNTHash(c: *mut SMBCCTX, b: smbc_bool);
    /// Returns whether native debug output is written to standard error for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    pub fn smbc_getOptionDebugToStderr(c: *mut SMBCCTX) -> smbc_bool;
    /// Controls whether native debug output is written to standard error.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, uninitialized native context pointer.
    pub fn smbc_setOptionDebugToStderr(c: *mut SMBCCTX, b: smbc_bool);
    /// Returns the file-open sharing mode configured for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    pub fn smbc_getOptionOpenShareMode(c: *mut SMBCCTX) -> smbc_share_mode;
    /// Sets the file-open sharing mode for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, uninitialized context and `share_mode` must be supported.
    pub fn smbc_setOptionOpenShareMode(c: *mut SMBCCTX, share_mode: smbc_share_mode);
    /// Returns the SMB encryption policy configured for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    pub fn smbc_getOptionSmbEncryptionLevel(c: *mut SMBCCTX) -> smbc_smb_encrypt_level;
    /// Sets the SMB encryption policy for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, uninitialized context and `level` must be supported.
    pub fn smbc_setOptionSmbEncryptionLevel(c: *mut SMBCCTX, level: smbc_smb_encrypt_level);
    /// Returns whether path matching is case-sensitive for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    pub fn smbc_getOptionCaseSensitive(c: *mut SMBCCTX) -> smbc_bool;
    /// Controls case-sensitive path matching for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, uninitialized native context pointer.
    pub fn smbc_setOptionCaseSensitive(c: *mut SMBCCTX, b: smbc_bool);
    /// Returns the maximum local master browser query count configured for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    pub fn smbc_getOptionBrowseMaxLmbCount(c: *mut SMBCCTX) -> c_int;
    /// Sets the maximum local master browser query count for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, uninitialized native context pointer.
    pub fn smbc_setOptionBrowseMaxLmbCount(c: *mut SMBCCTX, count: c_int);
    /// Returns whether URL encoding is enabled for directory-entry names in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    pub fn smbc_getOptionUrlEncodeReaddirEntries(c: *mut SMBCCTX) -> smbc_bool;
    /// Controls URL encoding of directory-entry names for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, uninitialized native context pointer.
    pub fn smbc_setOptionUrlEncodeReaddirEntries(c: *mut SMBCCTX, b: smbc_bool);
    /// Returns whether each server connection is restricted to one share.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    pub fn smbc_getOptionOneSharePerServer(c: *mut SMBCCTX) -> smbc_bool;
    /// Restricts each server connection to one share when enabled.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, uninitialized native context pointer.
    pub fn smbc_setOptionOneSharePerServer(c: *mut SMBCCTX, b: smbc_bool);
    /// Returns whether Kerberos authentication is enabled for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    pub fn smbc_getOptionUseKerberos(c: *mut SMBCCTX) -> smbc_bool;
    /// Controls whether Kerberos authentication is attempted for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, uninitialized native context pointer.
    pub fn smbc_setOptionUseKerberos(c: *mut SMBCCTX, b: smbc_bool);
    /// Returns whether authentication falls back after Kerberos fails.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    pub fn smbc_getOptionFallbackAfterKerberos(c: *mut SMBCCTX) -> smbc_bool;
    /// Controls fallback after Kerberos authentication fails.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, uninitialized native context pointer.
    pub fn smbc_setOptionFallbackAfterKerberos(c: *mut SMBCCTX, b: smbc_bool);
    /// Returns whether automatic anonymous authentication is disabled.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    pub fn smbc_getOptionNoAutoAnonymousLogin(c: *mut SMBCCTX) -> smbc_bool;
    /// Prevents automatic anonymous authentication when enabled.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, uninitialized native context pointer.
    pub fn smbc_setOptionNoAutoAnonymousLogin(c: *mut SMBCCTX, b: smbc_bool);
    /// Returns whether Kerberos uses the credential cache.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    pub fn smbc_getOptionUseCCache(c: *mut SMBCCTX) -> smbc_bool;
    /// Controls whether Kerberos uses the credential cache.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, uninitialized native context pointer.
    pub fn smbc_setOptionUseCCache(c: *mut SMBCCTX, b: smbc_bool);
    /// Returns whether POSIX extensions are enabled for `c`.
    ///
    /// Available when the `abi-0-8` feature is enabled.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer.
    #[cfg(feature = "abi-0-8")]
    pub fn smbc_getOptionPosixExtensions(c: *mut SMBCCTX) -> smbc_bool;
    /// Enables or disables POSIX extensions for `c`.
    ///
    /// Available when the `abi-0-8` feature is enabled.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, uninitialized native context pointer.
    #[cfg(feature = "abi-0-8")]
    pub fn smbc_setOptionPosixExtensions(c: *mut SMBCCTX, b: smbc_bool);
    /// Sets the minimum and maximum SMB dialects offered during protocol negotiation.
    ///
    /// Each protocol name must be a NUL-terminated Samba dialect string such as `NT1`,
    /// `SMB2_02`, or `SMB3_11`. A null pointer keeps the corresponding `smb.conf` value.
    /// Returns a non-zero value on success and `0` when a protocol name is not recognized.
    ///
    /// Available since Samba 4.10 (libsmbclient ABI 0.5). The call takes effect only when it
    /// is issued before [`smbc_init_context`].
    ///
    /// # Safety
    ///
    /// `c` must be a valid, uninitialized [`SMBCCTX`]. Each non-null protocol pointer must point
    /// to a NUL-terminated, valid Samba dialect string. This call must be issued before
    /// [`smbc_init_context`].
    pub fn smbc_setOptionProtocols(
        c: *mut SMBCCTX,
        min_protocol: *const c_char,
        max_protocol: *const c_char,
    ) -> smbc_bool;
    /// Installs the context-aware authentication callback for `c`.
    ///
    /// # Safety
    ///
    /// `c` must be valid and uninitialized. The callback must uphold the native callback contract.
    pub fn smbc_setFunctionAuthDataWithContext(
        c: *mut SMBCCTX,
        _fn: smbc_get_auth_data_with_context_fn,
    );
    /// Returns the file-open callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionOpen(c: *mut SMBCCTX) -> smbc_open_fn;
    /// Returns the file-creation callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionCreat(c: *mut SMBCCTX) -> smbc_creat_fn;
    /// Returns the file-read callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionRead(c: *mut SMBCCTX) -> smbc_read_fn;
    /// Returns the file-write callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionWrite(c: *mut SMBCCTX) -> smbc_write_fn;
    /// Returns the file-splicing callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionSplice(c: *mut SMBCCTX) -> smbc_splice_fn;
    /// Returns the file-removal callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionUnlink(c: *mut SMBCCTX) -> smbc_unlink_fn;
    /// Returns the entry-rename callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionRename(c: *mut SMBCCTX) -> smbc_rename_fn;
    /// Returns the file-seek callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionLseek(c: *mut SMBCCTX) -> smbc_lseek_fn;
    /// Returns the path-metadata callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionStat(c: *mut SMBCCTX) -> smbc_stat_fn;
    /// Returns the open-file metadata callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionFstat(c: *mut SMBCCTX) -> smbc_fstat_fn;
    /// Returns the file-truncation callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionFtruncate(c: *mut SMBCCTX) -> smbc_ftruncate_fn;
    /// Returns the filesystem-statistics callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionStatVFS(c: *mut SMBCCTX) -> smbc_statvfs_fn;
    /// Returns the open-file filesystem-statistics callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionFstatVFS(c: *mut SMBCCTX) -> smbc_fstatvfs_fn;
    /// Returns the file-close callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionClose(c: *mut SMBCCTX) -> smbc_close_fn;
    /// Returns the directory-open callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionOpendir(c: *mut SMBCCTX) -> smbc_opendir_fn;
    /// Returns the directory-close callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionClosedir(c: *mut SMBCCTX) -> smbc_closedir_fn;
    /// Returns the directory-read callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionReaddir(c: *mut SMBCCTX) -> smbc_readdir_fn;
    /// Returns the extended directory-read callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionReaddirPlus(c: *mut SMBCCTX) -> smbc_readdirplus_fn;
    /// Returns the extended directory-read callback that also accepts a `stat` buffer.
    ///
    /// Available when the `abi-0-6` feature is enabled.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    #[cfg(feature = "abi-0-6")]
    pub fn smbc_getFunctionReaddirPlus2(c: *mut SMBCCTX) -> smbc_readdirplus2_fn;
    /// Returns the multiple-directory-entry callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionGetdents(c: *mut SMBCCTX) -> smbc_getdents_fn;
    /// Returns the directory-creation callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionMkdir(c: *mut SMBCCTX) -> smbc_mkdir_fn;
    /// Returns the directory-removal callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionRmdir(c: *mut SMBCCTX) -> smbc_rmdir_fn;
    /// Returns the directory-position callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionTelldir(c: *mut SMBCCTX) -> smbc_telldir_fn;
    /// Returns the directory-seek callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionLseekdir(c: *mut SMBCCTX) -> smbc_lseekdir_fn;
    /// Returns the directory-metadata callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionFstatdir(c: *mut SMBCCTX) -> smbc_fstatdir_fn;
    /// Returns the directory-notification callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionNotify(c: *mut SMBCCTX) -> smbc_notify_fn;
    /// Returns the mode-change callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionChmod(c: *mut SMBCCTX) -> smbc_chmod_fn;
    /// Returns the timestamp-update callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionUtimes(c: *mut SMBCCTX) -> smbc_utimes_fn;
    /// Returns the extended-attribute write callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionSetxattr(c: *mut SMBCCTX) -> smbc_setxattr_fn;
    /// Returns the extended-attribute read callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionGetxattr(c: *mut SMBCCTX) -> smbc_getxattr_fn;
    /// Returns the extended-attribute removal callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionRemovexattr(c: *mut SMBCCTX) -> smbc_removexattr_fn;
    /// Returns the extended-attribute listing callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionListxattr(c: *mut SMBCCTX) -> smbc_listxattr_fn;
    /// Returns the file-printing callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionPrintFile(c: *mut SMBCCTX) -> smbc_print_file_fn;
    /// Returns the print-job opening callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionOpenPrintJob(c: *mut SMBCCTX) -> smbc_open_print_job_fn;
    /// Returns the print-job listing callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionListPrintJobs(c: *mut SMBCCTX) -> smbc_list_print_jobs_fn;
    /// Returns the print-job removal callback installed in `c`.
    ///
    /// # Safety
    ///
    /// `c` must be a valid, initialized native context pointer.
    pub fn smbc_getFunctionUnlinkPrintJob(c: *mut SMBCCTX) -> smbc_unlink_print_job_fn;
    /// Allocates a new, uninitialized native SMB context.
    ///
    /// Returns null and sets `errno` to `ENOMEM` when allocation fails.
    ///
    /// # Safety
    ///
    /// A non-null pointer must be passed to [`smbc_init_context`] before use and eventually passed
    /// exactly once to [`smbc_free_context`].
    pub fn smbc_new_context() -> *mut SMBCCTX;
    /// Attempts to free `context` and optionally shuts down its connections.
    ///
    /// Returns zero on success. Returns one and sets `errno` to `EBUSY` if resources remain in use
    /// when `shutdown_ctx` is zero, or to `EBADF` if `context` is null.
    ///
    /// # Safety
    ///
    /// `context` must be a live pointer allocated by [`smbc_new_context`] and not previously freed.
    /// It remains owned by the caller when this function returns one.
    pub fn smbc_free_context(context: *mut SMBCCTX, shutdown_ctx: c_int) -> c_int;
    /// Sets fallback credentials used by `libsmbclient` for DFS referrals.
    ///
    /// # Safety
    ///
    /// `c` must be a valid native context pointer. Each non-null credential pointer must refer to
    /// a valid NUL-terminated string for the duration of the call.
    pub fn smbc_set_credentials_with_fallback(
        c: *mut SMBCCTX,
        workgroup: *const c_char,
        user: *const c_char,
        password: *const c_char,
    );
    /// Initializes a newly allocated native SMB context.
    ///
    /// Returns `context` on success. Returns null and sets `errno` to `EBADF`, `ENOMEM`, or `ENOENT`
    /// for a null context, allocation failure, or an unreadable Samba configuration, respectively.
    ///
    /// # Safety
    ///
    /// `context` must be a live, uninitialized pointer returned by [`smbc_new_context`]. On failure,
    /// the caller still owns it and must pass it to [`smbc_free_context`].
    pub fn smbc_init_context(context: *mut SMBCCTX) -> *mut SMBCCTX;
    /// Returns the linked `libsmbclient` version string.
    ///
    /// # Safety
    ///
    /// The returned pointer is borrowed static storage and must not be modified or freed.
    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);
        });
    }
}