comparison src/module.rs @ 10:74b53b921b23

Added set_item_str.
author Marc Brinkmann <git@marcbrinkmann.de>
date Sun, 26 Feb 2017 11:50:19 +0100
parents a83c56216e21
children 30831c70e5c0
comparison
equal deleted inserted replaced
9:2abd89f31a13 10:74b53b921b23
131 } else { 131 } else {
132 Err(res) 132 Err(res)
133 } 133 }
134 } 134 }
135 135
136 /// Sets a value in the pam context. The value can be retrieved using
137 /// `get_item`.
138 ///
139 /// Note that all items are strings, except `PAM_CONV` and `PAM_FAIL_DELAY`.
140 ///
141 /// See `pam_set_item` in
142 /// http://www.linux-pam.org/Linux-PAM-html/mwg-expected-by-module-item.html
143 pub fn set_item_str<'a, P: PamItem>(pamh: &'a mut PamHandleT, item: &str) -> PamResult<()> {
144 let c_item = CString::new(item).unwrap().as_ptr();
145
146 let res = unsafe {
147 pam_set_item(pamh,
148 PamItem::item_type(PhantomData::<P>),
149
150 // unwrapping is okay here, as c_item will not be a NULL
151 // pointer
152 (c_item as *const PamItemT).as_ref().unwrap())
153 };
154 if constants::PAM_SUCCESS == res {
155 Ok(())
156 } else {
157 Err(res)
158 }
159 }
160
136 /// Retrieves the name of the user who is authenticating or logging in. 161 /// Retrieves the name of the user who is authenticating or logging in.
137 /// 162 ///
138 /// This is really a specialization of `get_item`. 163 /// This is really a specialization of `get_item`.
139 /// 164 ///
140 /// See `pam_get_user` in 165 /// See `pam_get_user` in