pam_sys/raw.rs
1// Copyright (C) 2015-2017 Florian Wilkens
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
4// associated documentation files (the "Software"), to deal in the Software without restriction,
5// including without limitation the rights to use, copy, modify, merge, publish, distribute,
6// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
7// furnished to do so, subject to the following conditions:
8//
9// The above copyright notice and this permission notice shall be included in all copies or substantial
10// portions of the Software.
11//
12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
13// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
15// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
16// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
18//! Raw FFI bindings to Linux-PAM
19//!
20//! This modules contains the raw and unchangeg FFI bindings to libpam.so.
21//! All C-types are mapped to their responding types from `libc` and functions
22//! names are exactly as exported by `libpam.so`
23//!
24//! Note: If possible the wrapped versions of these functions should be preferred,
25//! since they offer some additional typesafety through the use of the enums defined
26//! in the [`types`](../types/index.html) module.
27
28use libc::{c_char, c_int, c_void};
29
30use types::*;
31
32extern "C" {
33 /* ------------------------ pam_appl.h -------------------------- */
34 /* -------------- The Linux-PAM Framework layer API ------------- */
35 pub fn pam_start(service_name: *const c_char,
36 user: *const c_char,
37 pam_conversation: *const PamConversation,
38 pamh: *mut *const PamHandle)
39 -> c_int;
40
41 pub fn pam_end(pamh: *mut PamHandle, pam_status: c_int) -> c_int;
42
43 /* Authentication APIs */
44 pub fn pam_authenticate(pamh: *mut PamHandle, flags: c_int) -> c_int;
45
46 pub fn pam_setcred(pamh: *mut PamHandle, flags: c_int) -> c_int;
47
48 /* Account Management APIs */
49 pub fn pam_acct_mgmt(pamh: *mut PamHandle, flags: c_int) -> c_int;
50
51 /* Session Management APIs */
52 pub fn pam_open_session(pamh: *mut PamHandle, flags: c_int) -> c_int;
53
54 pub fn pam_close_session(pamh: *mut PamHandle, flags: c_int) -> c_int;
55
56 /* Password Management APIs */
57 pub fn pam_chauthtok(pamh: *mut PamHandle, flags: c_int) -> c_int;
58 /* ------------------------ pam_appl.h -------------------------- */
59
60 /* ----------------------- _pam_types.h ------------------------- */
61 /* ---------- Common Linux-PAM application/module PI ------------ */
62 pub fn pam_set_item(pamh: *mut PamHandle, item_type: c_int, item: *const c_void) -> c_int;
63
64 pub fn pam_get_item(pamh: *const PamHandle,
65 item_type: c_int,
66 item: *mut *const c_void)
67 -> c_int;
68
69 pub fn pam_strerror(pamh: *mut PamHandle, errnum: c_int) -> *const c_char;
70
71 pub fn pam_putenv(pamh: *mut PamHandle, name_value: *const c_char) -> c_int;
72
73 pub fn pam_getenv(pamh: *mut PamHandle, name: *const c_char) -> *const c_char;
74
75 pub fn pam_getenvlist(pamh: *mut PamHandle) -> *const *const c_char;
76 /* ----------------------- _pam_types.h ------------------------- */
77
78 /* ----------------------- pam_misc.h --------------------------- */
79 #[cfg(target_os = "linux")]
80 pub fn pam_misc_paste_env(pamh: *mut PamHandle,
81 user_env: *const *const c_char)
82 -> c_int;
83
84 #[cfg(target_os = "linux")]
85 pub fn pam_misc_drop_env(env: *mut *mut c_char) -> c_int;
86
87 #[cfg(target_os = "linux")]
88 pub fn pam_misc_setenv(pamh: *mut PamHandle,
89 name: *const c_char,
90 value: *const c_char,
91 readonly: c_int)
92 -> c_int;
93 /* ----------------------- pam_misc.h --------------------------- */
94
95 /* ----------------------- pam_modules.h ------------------------ */
96 /* -------------------- The Linux-PAM Module PI ----------------- */
97 pub fn pam_set_data(pamh: *mut PamHandle,
98 module_data_name: *const c_char,
99 data: *mut c_void,
100 cleanup: Option<extern "C" fn(*mut PamHandle, *mut c_void, c_int)>)
101 -> c_int;
102
103 pub fn pam_get_data(pamh: *const PamHandle,
104 module_data_name: *const c_char,
105 data: *mut *const c_void)
106 -> c_int;
107
108 pub fn pam_get_user(pamh: *const PamHandle,
109 user: *mut *const c_char,
110 prompt: *const c_char)
111 -> c_int;
112 /* ----------------------- pam_modules.h ------------------------ */
113}