Mercurial > crates > nonstick
comparison pam-http/src/ffi.rs @ 15:27730595f1ea
Adding pam-http module
| author | Anthony Nowell <anthony@algorithmia.com> |
|---|---|
| date | Sun, 24 Sep 2017 00:22:29 -0600 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 14:51b097c12d3c | 15:27730595f1ea |
|---|---|
| 1 use pam::module::{PamHandleT}; | |
| 2 use pam::constants::{PamFlag, PamResultCode, PAM_SILENT}; | |
| 3 use std::ffi::CStr; | |
| 4 use std::os::raw::{c_char, c_int}; | |
| 5 | |
| 6 | |
| 7 | |
| 8 fn extract_argv(argc: c_int, argv: *const *const c_char) -> Vec<String> { | |
| 9 (0..argc) | |
| 10 .map(|o| unsafe { | |
| 11 CStr::from_ptr(*argv.offset(o as isize) as *const c_char) | |
| 12 .to_string_lossy() | |
| 13 .into_owned() | |
| 14 }) | |
| 15 .collect() | |
| 16 } | |
| 17 | |
| 18 #[no_mangle] | |
| 19 pub extern "C" fn pam_sm_acct_mgmt( | |
| 20 pamh: &PamHandleT, | |
| 21 flags: PamFlag, | |
| 22 argc: c_int, | |
| 23 argv: *const *const c_char, | |
| 24 ) -> PamResultCode { | |
| 25 let args = extract_argv(argc, argv); | |
| 26 let silent = (flags & PAM_SILENT) != 0; | |
| 27 super::acct_mgmt(pamh, args, silent) | |
| 28 } | |
| 29 | |
| 30 #[no_mangle] | |
| 31 pub extern "C" fn pam_sm_authenticate( | |
| 32 pamh: &PamHandleT, | |
| 33 flags: PamFlag, | |
| 34 argc: c_int, | |
| 35 argv: *const *const c_char, | |
| 36 ) -> PamResultCode { | |
| 37 let args = extract_argv(argc, argv); | |
| 38 let silent = (flags & PAM_SILENT) != 0; | |
| 39 super::sm_authenticate(pamh, args, silent) | |
| 40 } | |
| 41 | |
| 42 #[no_mangle] | |
| 43 pub extern "C" fn pam_sm_chauthtok( | |
| 44 _: &PamHandleT, | |
| 45 _: PamFlag, | |
| 46 _: c_int, | |
| 47 _: *const *const c_char, | |
| 48 ) -> PamResultCode { | |
| 49 PamResultCode::PAM_IGNORE | |
| 50 } | |
| 51 | |
| 52 #[no_mangle] | |
| 53 pub extern "C" fn pam_sm_close_session( | |
| 54 _: &PamHandleT, | |
| 55 _: PamFlag, | |
| 56 _: c_int, | |
| 57 _: *const *const c_char, | |
| 58 ) -> PamResultCode { | |
| 59 PamResultCode::PAM_IGNORE | |
| 60 } | |
| 61 | |
| 62 #[no_mangle] | |
| 63 pub extern "C" fn pam_sm_open_session( | |
| 64 _: &PamHandleT, | |
| 65 _: PamFlag, | |
| 66 _: c_int, | |
| 67 _: *const *const c_char, | |
| 68 ) -> PamResultCode { | |
| 69 PamResultCode::PAM_IGNORE | |
| 70 } | |
| 71 | |
| 72 #[no_mangle] | |
| 73 pub extern "C" fn pam_sm_setcred( | |
| 74 pamh: &PamHandleT, | |
| 75 flags: PamFlag, | |
| 76 argc: c_int, | |
| 77 argv: *const *const c_char, | |
| 78 ) -> PamResultCode { | |
| 79 let args = extract_argv(argc, argv); | |
| 80 let silent = (flags & PAM_SILENT) != 0; | |
| 81 super::sm_setcred(pamh, args, silent) | |
| 82 } |
