changeset 8:a83c56216e21

Ran everything through rustfmt.
author Marc Brinkmann <git@marcbrinkmann.de>
date Sun, 26 Feb 2017 11:29:31 +0100
parents 9380392b9a60
children 2abd89f31a13
files src/constants.rs src/conv.rs src/module.rs
diffstat 3 files changed, 102 insertions(+), 97 deletions(-) [+]
line wrap: on
line diff
--- a/src/constants.rs	Fri Apr 03 23:33:20 2015 -0700
+++ b/src/constants.rs	Sun Feb 26 11:29:31 2017 +0100
@@ -2,78 +2,78 @@
 
 // TODO: Import constants from C header file at compile time.
 
-pub type PamFlag         = c_uint;
-pub type PamItemType     = c_int;
+pub type PamFlag = c_uint;
+pub type PamItemType = c_int;
 pub type PamMessageStyle = c_int;
-pub type PamResultCode   = c_int;
-pub type AlwaysZero      = c_int;
+pub type PamResultCode = c_int;
+pub type AlwaysZero = c_int;
 
 // The Linux-PAM flags
 // see /usr/include/security/_pam_types.h
-pub const PAM_SILENT:                 PamFlag = 0x8000;
-pub const PAM_DISALLOW_NULL_AUTHTOK:  PamFlag = 0x0001;
-pub const PAM_ESTABLISH_CRED:         PamFlag = 0x0002;
-pub const PAM_DELETE_CRED:            PamFlag = 0x0004;
-pub const PAM_REINITIALIZE_CRED:      PamFlag = 0x0008;
-pub const PAM_REFRESH_CRED:           PamFlag = 0x0010;
+pub const PAM_SILENT: PamFlag = 0x8000;
+pub const PAM_DISALLOW_NULL_AUTHTOK: PamFlag = 0x0001;
+pub const PAM_ESTABLISH_CRED: PamFlag = 0x0002;
+pub const PAM_DELETE_CRED: PamFlag = 0x0004;
+pub const PAM_REINITIALIZE_CRED: PamFlag = 0x0008;
+pub const PAM_REFRESH_CRED: PamFlag = 0x0010;
 pub const PAM_CHANGE_EXPIRED_AUTHTOK: PamFlag = 0x0020;
 
 // The Linux-PAM item types
 // see /usr/include/security/_pam_types.h
-pub const PAM_SERVICE:      PamItemType =  1;   /* The service name */
-pub const PAM_USER:         PamItemType =  2;   /* The user name */
-pub const PAM_TTY:          PamItemType =  3;   /* The tty name */
-pub const PAM_RHOST:        PamItemType =  4;   /* The remote host name */
-pub const PAM_CONV:         PamItemType =  5;   /* The pam_conv structure */
-pub const PAM_AUTHTOK:      PamItemType =  6;   /* The authentication token (password) */
-pub const PAM_OLDAUTHTOK:   PamItemType =  7;   /* The old authentication token */
-pub const PAM_RUSER:        PamItemType =  8;   /* The remote user name */
-pub const PAM_USER_PROMPT:  PamItemType =  9;   /* the prompt for getting a username */
+pub const PAM_SERVICE: PamItemType = 1; /* The service name */
+pub const PAM_USER: PamItemType = 2; /* The user name */
+pub const PAM_TTY: PamItemType = 3; /* The tty name */
+pub const PAM_RHOST: PamItemType = 4; /* The remote host name */
+pub const PAM_CONV: PamItemType = 5; /* The pam_conv structure */
+pub const PAM_AUTHTOK: PamItemType = 6; /* The authentication token (password) */
+pub const PAM_OLDAUTHTOK: PamItemType = 7; /* The old authentication token */
+pub const PAM_RUSER: PamItemType = 8; /* The remote user name */
+pub const PAM_USER_PROMPT: PamItemType = 9; /* the prompt for getting a username */
 /* Linux-PAM :extensionsPamItemType = */
-pub const PAM_FAIL_DELAY:   PamItemType = 10;   /* app supplied function to override failure delays */
-pub const PAM_XDISPLAY:     PamItemType = 11;   /* X :display name */
-pub const PAM_XAUTHDATA:    PamItemType = 12;   /* X :server authentication data */
-pub const PAM_AUTHTOK_TYPE: PamItemType = 13;   /* The type for pam_get_authtok */
+pub const PAM_FAIL_DELAY: PamItemType = 10; /* app supplied function to override failure delays */
+pub const PAM_XDISPLAY: PamItemType = 11; /* X :display name */
+pub const PAM_XAUTHDATA: PamItemType = 12; /* X :server authentication data */
+pub const PAM_AUTHTOK_TYPE: PamItemType = 13; /* The type for pam_get_authtok */
 
 // Message styles
 pub const PAM_PROMPT_ECHO_OFF: PamMessageStyle = 1;
-pub const PAM_PROMPT_ECHO_ON:  PamMessageStyle = 2;
-pub const PAM_ERROR_MSG:       PamMessageStyle = 3;
-pub const PAM_TEXT_INFO:       PamMessageStyle = 4;
-pub const PAM_RADIO_TYPE:      PamMessageStyle = 5;        /* yes/no/maybe conditionals */
-pub const PAM_BINARY_PROMPT:   PamMessageStyle = 7;
+pub const PAM_PROMPT_ECHO_ON: PamMessageStyle = 2;
+pub const PAM_ERROR_MSG: PamMessageStyle = 3;
+pub const PAM_TEXT_INFO: PamMessageStyle = 4;
+pub const PAM_RADIO_TYPE: PamMessageStyle = 5; /* yes/no/maybe conditionals */
+pub const PAM_BINARY_PROMPT: PamMessageStyle = 7;
 
 // The Linux-PAM return values
 // see /usr/include/security/_pam_types.h
-pub const PAM_SUCCESS:               PamResultCode =  0;
-pub const PAM_OPEN_ERR:              PamResultCode =  1;
-pub const PAM_SYMBOL_ERR:            PamResultCode =  2;
-pub const PAM_SERVICE_ERR:           PamResultCode =  3;
-pub const PAM_SYSTEM_ERR:            PamResultCode =  4;
-pub const PAM_BUF_ERR:               PamResultCode =  5;
-pub const PAM_PERM_DENIED:           PamResultCode =  6;
-pub const PAM_AUTH_ERR:              PamResultCode =  7;
-pub const PAM_CRED_INSUFFICIENT:     PamResultCode =  8;
-pub const PAM_AUTHINFO_UNAVAIL:      PamResultCode =  9;
-pub const PAM_USER_UNKNOWN:          PamResultCode = 10;
-pub const PAM_MAXTRIES:              PamResultCode = 11;
-pub const PAM_NEW_AUTHTOK_REQD:      PamResultCode = 12;
-pub const PAM_ACCT_EXPIRED:          PamResultCode = 13;
-pub const PAM_SESSION_ERR:           PamResultCode = 14;
-pub const PAM_CRED_UNAVAIL:          PamResultCode = 15;
-pub const PAM_CRED_EXPIRED:          PamResultCode = 16;
-pub const PAM_CRED_ERR:              PamResultCode = 17;
-pub const PAM_NO_MODULE_DATA:        PamResultCode = 18;
-pub const PAM_CONV_ERR:              PamResultCode = 19;
-pub const PAM_AUTHTOK_ERR:           PamResultCode = 20;
-pub const PAM_AUTHTOK_RECOVERY_ERR:  PamResultCode = 21;
-pub const PAM_AUTHTOK_LOCK_BUSY:     PamResultCode = 22;
+pub const PAM_SUCCESS: PamResultCode = 0;
+pub const PAM_OPEN_ERR: PamResultCode = 1;
+pub const PAM_SYMBOL_ERR: PamResultCode = 2;
+pub const PAM_SERVICE_ERR: PamResultCode = 3;
+pub const PAM_SYSTEM_ERR: PamResultCode = 4;
+pub const PAM_BUF_ERR: PamResultCode = 5;
+pub const PAM_PERM_DENIED: PamResultCode = 6;
+pub const PAM_AUTH_ERR: PamResultCode = 7;
+pub const PAM_CRED_INSUFFICIENT: PamResultCode = 8;
+pub const PAM_AUTHINFO_UNAVAIL: PamResultCode = 9;
+pub const PAM_USER_UNKNOWN: PamResultCode = 10;
+pub const PAM_MAXTRIES: PamResultCode = 11;
+pub const PAM_NEW_AUTHTOK_REQD: PamResultCode = 12;
+pub const PAM_ACCT_EXPIRED: PamResultCode = 13;
+pub const PAM_SESSION_ERR: PamResultCode = 14;
+pub const PAM_CRED_UNAVAIL: PamResultCode = 15;
+pub const PAM_CRED_EXPIRED: PamResultCode = 16;
+pub const PAM_CRED_ERR: PamResultCode = 17;
+pub const PAM_NO_MODULE_DATA: PamResultCode = 18;
+pub const PAM_CONV_ERR: PamResultCode = 19;
+pub const PAM_AUTHTOK_ERR: PamResultCode = 20;
+pub const PAM_AUTHTOK_RECOVERY_ERR: PamResultCode = 21;
+pub const PAM_AUTHTOK_LOCK_BUSY: PamResultCode = 22;
 pub const PAM_AUTHTOK_DISABLE_AGING: PamResultCode = 23;
-pub const PAM_TRY_AGAIN:             PamResultCode = 24;
-pub const PAM_IGNORE:                PamResultCode = 25;
-pub const PAM_ABORT:                 PamResultCode = 26;
-pub const PAM_AUTHTOK_EXPIRED:       PamResultCode = 27;
-pub const PAM_MODULE_UNKNOWN:        PamResultCode = 28;
-pub const PAM_BAD_ITEM:              PamResultCode = 29;
-pub const PAM_CONV_AGAIN:            PamResultCode = 30;
-pub const PAM_INCOMPLETE:            PamResultCode = 31;
+pub const PAM_TRY_AGAIN: PamResultCode = 24;
+pub const PAM_IGNORE: PamResultCode = 25;
+pub const PAM_ABORT: PamResultCode = 26;
+pub const PAM_AUTHTOK_EXPIRED: PamResultCode = 27;
+pub const PAM_MODULE_UNKNOWN: PamResultCode = 28;
+pub const PAM_BAD_ITEM: PamResultCode = 29;
+pub const PAM_CONV_AGAIN: PamResultCode = 30;
+pub const PAM_INCOMPLETE: PamResultCode = 31;
--- a/src/conv.rs	Fri Apr 03 23:33:20 2015 -0700
+++ b/src/conv.rs	Sun Feb 26 11:29:31 2017 +0100
@@ -1,7 +1,7 @@
 use libc::{c_char, c_int};
-use std::{ptr};
+use std::ptr;
 use std::ffi::{CStr, CString};
-use std::marker::{PhantomData};
+use std::marker::PhantomData;
 
 use constants;
 use constants::*;
@@ -13,7 +13,7 @@
 #[repr(C)]
 struct PamMessage {
     msg_style: PamMessageStyle,
-    msg:       *const c_char,
+    msg: *const c_char,
 }
 
 #[repr(C)]
@@ -29,11 +29,11 @@
 /// will be relayed back.
 #[repr(C)]
 pub struct PamConv {
-    conv: extern fn(num_msg: c_int,
-                    pam_message: &&PamMessage,
-                    pam_response: &mut *const PamResponse,
-                    appdata_ptr: *const AppDataPtr
-                   ) -> PamResultCode,
+    conv: extern "C" fn(num_msg: c_int,
+                        pam_message: &&PamMessage,
+                        pam_response: &mut *const PamResponse,
+                        appdata_ptr: *const AppDataPtr)
+                        -> PamResultCode,
     appdata_ptr: *const AppDataPtr,
 }
 
@@ -65,8 +65,7 @@
         if constants::PAM_SUCCESS == ret {
             if resp_ptr.is_null() {
                 Ok(None)
-            }
-            else {
+            } else {
                 let bytes = unsafe { CStr::from_ptr((*resp_ptr).resp).to_bytes() };
                 Ok(String::from_utf8(bytes.to_vec()).ok())
             }
@@ -77,5 +76,7 @@
 }
 
 impl PamItem for PamConv {
-    fn item_type(_: PhantomData<Self>) -> PamItemType { PAM_CONV }
+    fn item_type(_: PhantomData<Self>) -> PamItemType {
+        PAM_CONV
+    }
 }
--- a/src/module.rs	Fri Apr 03 23:33:20 2015 -0700
+++ b/src/module.rs	Sun Feb 26 11:29:31 2017 +0100
@@ -1,9 +1,9 @@
 //! Functions for use in pam modules.
 
-use libc::{c_char};
+use libc::c_char;
 use std::{mem, ptr};
 use std::ffi::{CStr, CString};
-use std::marker::{PhantomData};
+use std::marker::PhantomData;
 
 use constants;
 use constants::*;
@@ -23,35 +23,34 @@
 pub enum PamDataT {}
 
 #[link(name = "pam")]
-extern {
+extern "C" {
     fn pam_get_data(pamh: *const PamHandleT,
                     module_data_name: *const c_char,
-                    data: &mut *const PamDataT,
-                    ) -> PamResultCode;
+                    data: &mut *const PamDataT)
+                    -> PamResultCode;
 
     fn pam_set_data(pamh: *const PamHandleT,
                     module_data_name: *const c_char,
                     data: Box<PamDataT>,
-                    cleanup: extern fn (pamh: *const PamHandleT,
-                                        data: Box<PamDataT>,
-                                        error_status: PamResultCode
-                                        ),
-                    ) -> PamResultCode;
+                    cleanup: extern "C" fn(pamh: *const PamHandleT,
+                                           data: Box<PamDataT>,
+                                           error_status: PamResultCode))
+                    -> PamResultCode;
 
     fn pam_get_item(pamh: *const PamHandleT,
                     item_type: PamItemType,
-                    item: &mut *const PamItemT,
-                    ) -> PamResultCode;
+                    item: &mut *const PamItemT)
+                    -> PamResultCode;
 
     fn pam_set_item(pamh: *mut PamHandleT,
                     item_type: PamItemType,
-                    item: &PamItemT,
-                    ) -> PamResultCode;
+                    item: &PamItemT)
+                    -> PamResultCode;
 
     fn pam_get_user(pamh: *const PamHandleT,
-                    user: & *mut c_char,
-                    prompt: *const c_char,
-                    ) -> PamResultCode;
+                    user: &*mut c_char,
+                    prompt: *const c_char)
+                    -> PamResultCode;
 }
 
 pub type PamResult<T> = Result<T, PamResultCode>;
@@ -83,8 +82,7 @@
         let typed_ptr: *const T = mem::transmute(ptr);
         let data: &T = &*typed_ptr;
         Ok(data)
-    }
-    else {
+    } else {
         Err(res)
     }
 }
@@ -100,11 +98,15 @@
         let c_data: Box<PamDataT> = mem::transmute(data);
         pam_set_data(pamh, c_key, c_data, cleanup::<T>)
     };
-    if constants::PAM_SUCCESS == res { Ok(()) } else { Err(res) }
+    if constants::PAM_SUCCESS == res {
+        Ok(())
+    } else {
+        Err(res)
+    }
 }
 
 #[no_mangle]
-pub extern fn cleanup<T>(_: *const PamHandleT, c_data: Box<PamDataT>, _: PamResultCode) {
+pub extern "C" fn cleanup<T>(_: *const PamHandleT, c_data: Box<PamDataT>, _: PamResultCode) {
     unsafe {
         let data: Box<T> = mem::transmute(c_data);
         mem::drop(data);
@@ -124,7 +126,11 @@
         let t: &T = &*typed_ptr;
         (r, t)
     };
-    if constants::PAM_SUCCESS == res { Ok(item) } else { Err(res) }
+    if constants::PAM_SUCCESS == res {
+        Ok(item)
+    } else {
+        Err(res)
+    }
 }
 
 /// Retrieves the name of the user who is authenticating or logging in.
@@ -137,16 +143,14 @@
     let ptr: *mut c_char = ptr::null_mut();
     let c_prompt = match prompt {
         Some(p) => CString::new(p).unwrap().as_ptr(),
-        None    => ptr::null(),
+        None => ptr::null(),
     };
     let res = unsafe { pam_get_user(pamh, &ptr, c_prompt) };
     if constants::PAM_SUCCESS == res && !ptr.is_null() {
         let const_ptr = ptr as *const c_char;
         let bytes = unsafe { CStr::from_ptr(const_ptr).to_bytes() };
-        String::from_utf8(bytes.to_vec())
-            .map_err(|_| PAM_CONV_ERR)
-    }
-    else {
+        String::from_utf8(bytes.to_vec()).map_err(|_| PAM_CONV_ERR)
+    } else {
         Err(res)
     }
 }