Mercurial > crates > nonstick
annotate pam/src/module.rs @ 34:ec70822cbdef
Overhaul
author | Andy Caldwell <andrew.caldwell@metaswitch.com> |
---|---|
date | Sun, 24 Apr 2022 03:42:11 +0100 |
parents | 4263c1d83d5b |
children | 50371046c61a |
rev | line source |
---|---|
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
1 //! Functions for use in pam modules. |
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
2 |
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
3 use libc::c_char; |
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
4 use std::ffi::{CStr, CString}; |
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
5 |
34 | 6 use constants::{PamFlag, PamResultCode}; |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
7 |
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
8 /// Opaque type, used as a pointer when making pam API calls. |
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
9 /// |
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
10 /// A module is invoked via an external function such as `pam_sm_authenticate`. |
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
11 /// Such a call provides a pam handle pointer. The same pointer should be given |
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
12 /// as an argument when making API calls. |
34 | 13 #[repr(C)] |
14 pub struct PamHandle { | |
15 _data: [u8; 0], | |
16 } | |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
17 |
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
18 #[link(name = "pam")] |
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
19 extern "C" { |
34 | 20 fn pam_get_data( |
21 pamh: *const PamHandle, | |
22 module_data_name: *const c_char, | |
23 data: &mut *const libc::c_void, | |
24 ) -> PamResultCode; | |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
25 |
34 | 26 fn pam_set_data( |
27 pamh: *const PamHandle, | |
28 module_data_name: *const c_char, | |
29 data: *mut libc::c_void, | |
30 cleanup: extern "C" fn( | |
31 pamh: *const PamHandle, | |
32 data: *mut libc::c_void, | |
33 error_status: PamResultCode, | |
34 ), | |
35 ) -> PamResultCode; | |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
36 |
34 | 37 fn pam_get_item( |
38 pamh: *const PamHandle, | |
39 item_type: crate::items::ItemType, | |
40 item: &mut *const libc::c_void, | |
41 ) -> PamResultCode; | |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
42 |
34 | 43 fn pam_set_item( |
44 pamh: *mut PamHandle, | |
45 item_type: crate::items::ItemType, | |
46 item: *const libc::c_void, | |
47 ) -> PamResultCode; | |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
48 |
34 | 49 fn pam_get_user( |
50 pamh: *const PamHandle, | |
51 user: &*mut c_char, | |
52 prompt: *const c_char, | |
53 ) -> PamResultCode; | |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
54 } |
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
55 |
34 | 56 pub extern "C" fn cleanup<T>(_: *const PamHandle, c_data: *mut libc::c_void, _: PamResultCode) { |
19
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
57 unsafe { |
34 | 58 let _data: Box<T> = Box::from_raw(c_data.cast::<T>()); |
19
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
59 } |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
60 } |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
61 |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
62 pub type PamResult<T> = Result<T, PamResultCode>; |
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
63 |
19
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
64 impl PamHandle { |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
65 /// Gets some value, identified by `key`, that has been set by the module |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
66 /// previously. |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
67 /// |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
68 /// See `pam_get_data` in |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
69 /// http://www.linux-pam.org/Linux-PAM-html/mwg-expected-by-module-item.html |
34 | 70 /// |
71 /// # Errors | |
72 /// | |
73 /// Returns an error if the underlying PAM function call fails. | |
74 /// | |
75 /// # Safety | |
76 /// | |
77 /// The data stored under the provided key must be of type `T` otherwise the | |
78 /// behaviour of this funtion is undefined. | |
19
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
79 pub unsafe fn get_data<'a, T>(&'a self, key: &str) -> PamResult<&'a T> { |
34 | 80 let c_key = CString::new(key).unwrap(); |
81 let mut ptr: *const libc::c_void = std::ptr::null(); | |
82 let res = pam_get_data(self, c_key.as_ptr(), &mut ptr); | |
19
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
83 if PamResultCode::PAM_SUCCESS == res && !ptr.is_null() { |
34 | 84 let typed_ptr = ptr.cast::<T>(); |
19
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
85 let data: &T = &*typed_ptr; |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
86 Ok(data) |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
87 } else { |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
88 Err(res) |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
89 } |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
90 } |
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
91 |
19
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
92 /// Stores a value that can be retrieved later with `get_data`. The value lives |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
93 /// as long as the current pam cycle. |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
94 /// |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
95 /// See `pam_set_data` in |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
96 /// http://www.linux-pam.org/Linux-PAM-html/mwg-expected-by-module-item.html |
34 | 97 /// |
98 /// # Errors | |
99 /// | |
100 /// Returns an error if the underlying PAM function call fails. | |
19
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
101 pub fn set_data<T>(&self, key: &str, data: Box<T>) -> PamResult<()> { |
34 | 102 let c_key = CString::new(key).unwrap(); |
19
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
103 let res = unsafe { |
34 | 104 pam_set_data( |
105 self, | |
106 c_key.as_ptr(), | |
107 Box::into_raw(data).cast::<libc::c_void>(), | |
108 cleanup::<T>, | |
109 ) | |
19
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
110 }; |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
111 if PamResultCode::PAM_SUCCESS == res { |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
112 Ok(()) |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
113 } else { |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
114 Err(res) |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
115 } |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
116 } |
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
117 |
19
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
118 /// Retrieves a value that has been set, possibly by the pam client. This is |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
119 /// particularly useful for getting a `PamConv` reference. |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
120 /// |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
121 /// See `pam_get_item` in |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
122 /// http://www.linux-pam.org/Linux-PAM-html/mwg-expected-by-module-item.html |
34 | 123 /// |
124 /// # Errors | |
125 /// | |
126 /// Returns an error if the underlying PAM function call fails. | |
127 pub fn get_item<T: crate::items::Item>(&self) -> PamResult<Option<T>> { | |
128 let mut ptr: *const libc::c_void = std::ptr::null(); | |
19
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
129 let (res, item) = unsafe { |
34 | 130 let r = pam_get_item(self, T::type_id(), &mut ptr); |
131 let typed_ptr = ptr.cast::<T::Raw>(); | |
132 let t = if typed_ptr.is_null() { | |
133 None | |
134 } else { | |
135 Some(T::from_raw(typed_ptr)) | |
136 }; | |
19
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
137 (r, t) |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
138 }; |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
139 if PamResultCode::PAM_SUCCESS == res { |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
140 Ok(item) |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
141 } else { |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
142 Err(res) |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
143 } |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
144 } |
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
145 |
19
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
146 /// Sets a value in the pam context. The value can be retrieved using |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
147 /// `get_item`. |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
148 /// |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
149 /// Note that all items are strings, except `PAM_CONV` and `PAM_FAIL_DELAY`. |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
150 /// |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
151 /// See `pam_set_item` in |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
152 /// http://www.linux-pam.org/Linux-PAM-html/mwg-expected-by-module-item.html |
34 | 153 /// |
154 /// # Errors | |
155 /// | |
156 /// Returns an error if the underlying PAM function call fails. | |
157 /// | |
158 /// # Panics | |
159 /// | |
160 /// Panics if the provided item key contains a nul byte | |
161 pub fn set_item_str<T: crate::items::Item>(&mut self, item: T) -> PamResult<()> { | |
162 let res = | |
163 unsafe { pam_set_item(self, T::type_id(), item.into_raw().cast::<libc::c_void>())}; | |
19
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
164 if PamResultCode::PAM_SUCCESS == res { |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
165 Ok(()) |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
166 } else { |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
167 Err(res) |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
168 } |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
169 } |
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
170 |
19
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
171 /// Retrieves the name of the user who is authenticating or logging in. |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
172 /// |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
173 /// This is really a specialization of `get_item`. |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
174 /// |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
175 /// See `pam_get_user` in |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
176 /// http://www.linux-pam.org/Linux-PAM-html/mwg-expected-by-module-item.html |
34 | 177 /// |
178 /// # Errors | |
179 /// | |
180 /// Returns an error if the underlying PAM function call fails. | |
181 /// | |
182 /// # Panics | |
183 /// | |
184 /// Panics if the provided prompt string contains a nul byte | |
19
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
185 pub fn get_user(&self, prompt: Option<&str>) -> PamResult<String> { |
34 | 186 let ptr: *mut c_char = std::ptr::null_mut(); |
187 let prompt_string; | |
19
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
188 let c_prompt = match prompt { |
34 | 189 Some(p) => { |
190 prompt_string = CString::new(p).unwrap(); | |
191 prompt_string.as_ptr() | |
192 } | |
193 None => std::ptr::null(), | |
19
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
194 }; |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
195 let res = unsafe { pam_get_user(self, &ptr, c_prompt) }; |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
196 if PamResultCode::PAM_SUCCESS == res && !ptr.is_null() { |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
197 let const_ptr = ptr as *const c_char; |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
198 let bytes = unsafe { CStr::from_ptr(const_ptr).to_bytes() }; |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
199 String::from_utf8(bytes.to_vec()).map_err(|_| PamResultCode::PAM_CONV_ERR) |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
200 } else { |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
201 Err(res) |
d654aa0655e5
Making PamHandle a struct with methods
Anthony Nowell <anthony@algorithmia.com>
parents:
15
diff
changeset
|
202 } |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
203 } |
22
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
204 } |
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
205 |
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
206 /// Provides functions that are invoked by the entrypoints generated by the |
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
207 /// [`pam_hooks!` macro](../macro.pam_hooks.html). |
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
208 /// |
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
209 /// All of hooks are ignored by PAM dispatch by default given the default return value of `PAM_IGNORE`. |
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
210 /// Override any functions that you want to handle with your module. See `man pam(3)`. |
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
211 #[allow(unused_variables)] |
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
212 pub trait PamHooks { |
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
213 /// This function performs the task of establishing whether the user is permitted to gain access at |
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
214 /// this time. It should be understood that the user has previously been validated by an |
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
215 /// authentication module. This function checks for other things. Such things might be: the time of |
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
216 /// day or the date, the terminal line, remote hostname, etc. This function may also determine |
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
217 /// things like the expiration on passwords, and respond that the user change it before continuing. |
34 | 218 fn acct_mgmt(pamh: &mut PamHandle, args: Vec<&CStr>, flags: PamFlag) -> PamResultCode { |
219 PamResultCode::PAM_IGNORE | |
220 } | |
22
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
221 |
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
222 /// This function performs the task of authenticating the user. |
34 | 223 fn sm_authenticate(pamh: &mut PamHandle, args: Vec<&CStr>, flags: PamFlag) -> PamResultCode { |
224 PamResultCode::PAM_IGNORE | |
225 } | |
22
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
226 |
34 | 227 /// This function is used to (re-)set the authentication token of the user. |
228 /// | |
229 /// The PAM library calls this function twice in succession. The first time with | |
230 /// `PAM_PRELIM_CHECK` and then, if the module does not return `PAM_TRY_AGAIN`, subsequently with | |
231 /// `PAM_UPDATE_AUTHTOK`. It is only on the second call that the authorization token is | |
232 /// (possibly) changed. | |
233 fn sm_chauthtok(pamh: &mut PamHandle, args: Vec<&CStr>, flags: PamFlag) -> PamResultCode { | |
234 PamResultCode::PAM_IGNORE | |
235 } | |
22
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
236 |
34 | 237 /// This function is called to terminate a session. |
238 fn sm_close_session(pamh: &mut PamHandle, args: Vec<&CStr>, flags: PamFlag) -> PamResultCode { | |
239 PamResultCode::PAM_IGNORE | |
240 } | |
22
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
241 |
34 | 242 /// This function is called to commence a session. |
243 fn sm_open_session(pamh: &mut PamHandle, args: Vec<&CStr>, flags: PamFlag) -> PamResultCode { | |
244 PamResultCode::PAM_IGNORE | |
245 } | |
22
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
246 |
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
247 /// This function performs the task of altering the credentials of the user with respect to the |
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
248 /// corresponding authorization scheme. Generally, an authentication module may have access to more |
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
249 /// information about a user than their authentication token. This function is used to make such |
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
250 /// information available to the application. It should only be called after the user has been |
4263c1d83d5b
Refactor PamHooks into modules mod
Anthony Nowell <anthony@algorithmia.com>
parents:
19
diff
changeset
|
251 /// authenticated but before a session has been established. |
34 | 252 fn sm_setcred(pamh: &mut PamHandle, args: Vec<&CStr>, flags: PamFlag) -> PamResultCode { |
253 PamResultCode::PAM_IGNORE | |
254 } | |
255 } |