Skip to content

Commit c2d35ea

Browse files
committed
Use std::ffi instead of libc in generated PAM bindings
1 parent 4d26312 commit c2d35ea

File tree

3 files changed

+61
-58
lines changed

3 files changed

+61
-58
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PAM_SRC_DIR = src/pam
22

3-
BINDGEN_CMD = bindgen --allowlist-function '^pam_.*$$' --allowlist-var '^PAM_.*$$' --opaque-type pam_handle_t --blocklist-function pam_vsyslog --blocklist-function pam_vprompt --blocklist-function pam_vinfo --blocklist-function pam_verror --blocklist-type '.*va_list.*' --ctypes-prefix libc --no-layout-tests --sort-semantically
3+
BINDGEN_CMD = bindgen --allowlist-function '^pam_.*$$' --allowlist-var '^PAM_.*$$' --opaque-type pam_handle_t --blocklist-function pam_vsyslog --blocklist-function pam_vprompt --blocklist-function pam_vinfo --blocklist-function pam_verror --blocklist-type '.*va_list.*' --ctypes-prefix std::ffi --no-layout-tests --sort-semantically
44

55
PAM_VARIANT = $$(./get-pam-variant.bash)
66

src/pam/sys_linuxpam.rs

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@ pub type pam_handle_t = u8;
44
#[repr(C)]
55
#[derive(Debug, Copy, Clone)]
66
pub struct pam_message {
7-
pub msg_style: libc::c_int,
8-
pub msg: *const libc::c_char,
7+
pub msg_style: std::ffi::c_int,
8+
pub msg: *const std::ffi::c_char,
99
}
1010
#[repr(C)]
1111
#[derive(Debug, Copy, Clone)]
1212
pub struct pam_response {
13-
pub resp: *mut libc::c_char,
14-
pub resp_retcode: libc::c_int,
13+
pub resp: *mut std::ffi::c_char,
14+
pub resp_retcode: std::ffi::c_int,
1515
}
1616
#[repr(C)]
1717
#[derive(Debug, Copy, Clone)]
1818
pub struct pam_conv {
1919
pub conv: ::std::option::Option<
2020
unsafe extern "C" fn(
21-
num_msg: libc::c_int,
21+
num_msg: std::ffi::c_int,
2222
msg: *mut *const pam_message,
2323
resp: *mut *mut pam_response,
24-
appdata_ptr: *mut libc::c_void,
25-
) -> libc::c_int,
24+
appdata_ptr: *mut std::ffi::c_void,
25+
) -> std::ffi::c_int,
2626
>,
27-
pub appdata_ptr: *mut libc::c_void,
27+
pub appdata_ptr: *mut std::ffi::c_void,
2828
}
2929
pub const PAM_SUCCESS: u32 = 0;
3030
pub const PAM_OPEN_ERR: u32 = 1;
@@ -72,49 +72,52 @@ pub const PAM_MAX_RESP_SIZE: u32 = 512;
7272
extern "C" {
7373
pub fn pam_set_item(
7474
pamh: *mut pam_handle_t,
75-
item_type: libc::c_int,
76-
item: *const libc::c_void,
77-
) -> libc::c_int;
75+
item_type: std::ffi::c_int,
76+
item: *const std::ffi::c_void,
77+
) -> std::ffi::c_int;
7878
}
7979
extern "C" {
8080
pub fn pam_get_item(
8181
pamh: *const pam_handle_t,
82-
item_type: libc::c_int,
83-
item: *mut *const libc::c_void,
84-
) -> libc::c_int;
82+
item_type: std::ffi::c_int,
83+
item: *mut *const std::ffi::c_void,
84+
) -> std::ffi::c_int;
8585
}
8686
extern "C" {
87-
pub fn pam_strerror(pamh: *mut pam_handle_t, errnum: libc::c_int) -> *const libc::c_char;
87+
pub fn pam_strerror(
88+
pamh: *mut pam_handle_t,
89+
errnum: std::ffi::c_int,
90+
) -> *const std::ffi::c_char;
8891
}
8992
extern "C" {
90-
pub fn pam_getenvlist(pamh: *mut pam_handle_t) -> *mut *mut libc::c_char;
93+
pub fn pam_getenvlist(pamh: *mut pam_handle_t) -> *mut *mut std::ffi::c_char;
9194
}
9295
extern "C" {
9396
pub fn pam_start(
94-
service_name: *const libc::c_char,
95-
user: *const libc::c_char,
97+
service_name: *const std::ffi::c_char,
98+
user: *const std::ffi::c_char,
9699
pam_conversation: *const pam_conv,
97100
pamh: *mut *mut pam_handle_t,
98-
) -> libc::c_int;
101+
) -> std::ffi::c_int;
99102
}
100103
extern "C" {
101-
pub fn pam_end(pamh: *mut pam_handle_t, pam_status: libc::c_int) -> libc::c_int;
104+
pub fn pam_end(pamh: *mut pam_handle_t, pam_status: std::ffi::c_int) -> std::ffi::c_int;
102105
}
103106
extern "C" {
104-
pub fn pam_authenticate(pamh: *mut pam_handle_t, flags: libc::c_int) -> libc::c_int;
107+
pub fn pam_authenticate(pamh: *mut pam_handle_t, flags: std::ffi::c_int) -> std::ffi::c_int;
105108
}
106109
extern "C" {
107-
pub fn pam_setcred(pamh: *mut pam_handle_t, flags: libc::c_int) -> libc::c_int;
110+
pub fn pam_setcred(pamh: *mut pam_handle_t, flags: std::ffi::c_int) -> std::ffi::c_int;
108111
}
109112
extern "C" {
110-
pub fn pam_acct_mgmt(pamh: *mut pam_handle_t, flags: libc::c_int) -> libc::c_int;
113+
pub fn pam_acct_mgmt(pamh: *mut pam_handle_t, flags: std::ffi::c_int) -> std::ffi::c_int;
111114
}
112115
extern "C" {
113-
pub fn pam_open_session(pamh: *mut pam_handle_t, flags: libc::c_int) -> libc::c_int;
116+
pub fn pam_open_session(pamh: *mut pam_handle_t, flags: std::ffi::c_int) -> std::ffi::c_int;
114117
}
115118
extern "C" {
116-
pub fn pam_close_session(pamh: *mut pam_handle_t, flags: libc::c_int) -> libc::c_int;
119+
pub fn pam_close_session(pamh: *mut pam_handle_t, flags: std::ffi::c_int) -> std::ffi::c_int;
117120
}
118121
extern "C" {
119-
pub fn pam_chauthtok(pamh: *mut pam_handle_t, flags: libc::c_int) -> libc::c_int;
122+
pub fn pam_chauthtok(pamh: *mut pam_handle_t, flags: std::ffi::c_int) -> std::ffi::c_int;
120123
}

src/pam/sys_openpam.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
/* automatically generated by rust-bindgen 0.70.1, minified by cargo-minify */
22

33
pub type pam_handle_t = u8;
4-
pub type _bindgen_ty_1 = libc::c_uint;
5-
pub type _bindgen_ty_2 = libc::c_uint;
6-
pub type _bindgen_ty_3 = libc::c_int;
7-
pub type _bindgen_ty_4 = libc::c_uint;
4+
pub type _bindgen_ty_1 = std::ffi::c_uint;
5+
pub type _bindgen_ty_2 = std::ffi::c_uint;
6+
pub type _bindgen_ty_3 = std::ffi::c_int;
7+
pub type _bindgen_ty_4 = std::ffi::c_uint;
88
#[repr(C)]
99
#[derive(Debug, Copy, Clone)]
1010
pub struct pam_message {
11-
pub msg_style: libc::c_int,
12-
pub msg: *mut libc::c_char,
11+
pub msg_style: std::ffi::c_int,
12+
pub msg: *mut std::ffi::c_char,
1313
}
1414
#[repr(C)]
1515
#[derive(Debug, Copy, Clone)]
1616
pub struct pam_response {
17-
pub resp: *mut libc::c_char,
18-
pub resp_retcode: libc::c_int,
17+
pub resp: *mut std::ffi::c_char,
18+
pub resp_retcode: std::ffi::c_int,
1919
}
2020
#[repr(C)]
2121
#[derive(Debug, Copy, Clone)]
2222
pub struct pam_conv {
2323
pub conv: ::std::option::Option<
2424
unsafe extern "C" fn(
25-
arg1: libc::c_int,
25+
arg1: std::ffi::c_int,
2626
arg2: *mut *const pam_message,
2727
arg3: *mut *mut pam_response,
28-
arg4: *mut libc::c_void,
29-
) -> libc::c_int,
28+
arg4: *mut std::ffi::c_void,
29+
) -> std::ffi::c_int,
3030
>,
31-
pub appdata_ptr: *mut libc::c_void,
31+
pub appdata_ptr: *mut std::ffi::c_void,
3232
}
3333
pub const PAM_SUCCESS: _bindgen_ty_1 = 0;
3434
pub const PAM_OPEN_ERR: _bindgen_ty_1 = 1;
@@ -73,54 +73,54 @@ pub const PAM_USER: _bindgen_ty_4 = 2;
7373
pub const PAM_TTY: _bindgen_ty_4 = 3;
7474
pub const PAM_RUSER: _bindgen_ty_4 = 8;
7575
extern "C" {
76-
pub fn pam_acct_mgmt(_pamh: *mut pam_handle_t, _flags: libc::c_int) -> libc::c_int;
76+
pub fn pam_acct_mgmt(_pamh: *mut pam_handle_t, _flags: std::ffi::c_int) -> std::ffi::c_int;
7777
}
7878
extern "C" {
79-
pub fn pam_authenticate(_pamh: *mut pam_handle_t, _flags: libc::c_int) -> libc::c_int;
79+
pub fn pam_authenticate(_pamh: *mut pam_handle_t, _flags: std::ffi::c_int) -> std::ffi::c_int;
8080
}
8181
extern "C" {
82-
pub fn pam_chauthtok(_pamh: *mut pam_handle_t, _flags: libc::c_int) -> libc::c_int;
82+
pub fn pam_chauthtok(_pamh: *mut pam_handle_t, _flags: std::ffi::c_int) -> std::ffi::c_int;
8383
}
8484
extern "C" {
85-
pub fn pam_close_session(_pamh: *mut pam_handle_t, _flags: libc::c_int) -> libc::c_int;
85+
pub fn pam_close_session(_pamh: *mut pam_handle_t, _flags: std::ffi::c_int) -> std::ffi::c_int;
8686
}
8787
extern "C" {
88-
pub fn pam_end(_pamh: *mut pam_handle_t, _status: libc::c_int) -> libc::c_int;
88+
pub fn pam_end(_pamh: *mut pam_handle_t, _status: std::ffi::c_int) -> std::ffi::c_int;
8989
}
9090
extern "C" {
9191
pub fn pam_get_item(
9292
_pamh: *const pam_handle_t,
93-
_item_type: libc::c_int,
94-
_item: *mut *const libc::c_void,
95-
) -> libc::c_int;
93+
_item_type: std::ffi::c_int,
94+
_item: *mut *const std::ffi::c_void,
95+
) -> std::ffi::c_int;
9696
}
9797
extern "C" {
98-
pub fn pam_getenvlist(_pamh: *mut pam_handle_t) -> *mut *mut libc::c_char;
98+
pub fn pam_getenvlist(_pamh: *mut pam_handle_t) -> *mut *mut std::ffi::c_char;
9999
}
100100
extern "C" {
101-
pub fn pam_open_session(_pamh: *mut pam_handle_t, _flags: libc::c_int) -> libc::c_int;
101+
pub fn pam_open_session(_pamh: *mut pam_handle_t, _flags: std::ffi::c_int) -> std::ffi::c_int;
102102
}
103103
extern "C" {
104104
pub fn pam_set_item(
105105
_pamh: *mut pam_handle_t,
106-
_item_type: libc::c_int,
107-
_item: *const libc::c_void,
108-
) -> libc::c_int;
106+
_item_type: std::ffi::c_int,
107+
_item: *const std::ffi::c_void,
108+
) -> std::ffi::c_int;
109109
}
110110
extern "C" {
111-
pub fn pam_setcred(_pamh: *mut pam_handle_t, _flags: libc::c_int) -> libc::c_int;
111+
pub fn pam_setcred(_pamh: *mut pam_handle_t, _flags: std::ffi::c_int) -> std::ffi::c_int;
112112
}
113113
extern "C" {
114114
pub fn pam_start(
115-
_service: *const libc::c_char,
116-
_user: *const libc::c_char,
115+
_service: *const std::ffi::c_char,
116+
_user: *const std::ffi::c_char,
117117
_pam_conv: *const pam_conv,
118118
_pamh: *mut *mut pam_handle_t,
119-
) -> libc::c_int;
119+
) -> std::ffi::c_int;
120120
}
121121
extern "C" {
122122
pub fn pam_strerror(
123123
_pamh: *const pam_handle_t,
124-
_error_number: libc::c_int,
125-
) -> *const libc::c_char;
124+
_error_number: std::ffi::c_int,
125+
) -> *const std::ffi::c_char;
126126
}

0 commit comments

Comments
 (0)