Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portable C binding #822

Merged
merged 5 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pam/converse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl PamMessageStyle {
pub fn from_int(val: libc::c_int) -> Option<PamMessageStyle> {
use PamMessageStyle::*;

match val as libc::c_uint {
match val {
PAM_PROMPT_ECHO_OFF => Some(PromptEchoOff),
PAM_PROMPT_ECHO_ON => Some(PromptEchoOn),
PAM_ERROR_MSG => Some(ErrorMessage),
Expand Down
2 changes: 1 addition & 1 deletion src/pam/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl PamErrorType {
pub(super) fn from_int(errno: libc::c_int) -> PamErrorType {
use PamErrorType::*;

match errno as libc::c_uint {
match errno {
PAM_SUCCESS => Success,
PAM_OPEN_ERR => OpenError,
PAM_SYMBOL_ERR => SymbolError,
Expand Down
32 changes: 8 additions & 24 deletions src/pam/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
/// Get the PAM flag value for the silent flag
fn silent_flag(&self) -> i32 {
if self.silent {
PAM_SILENT as i32
PAM_SILENT

Check warning on line 143 in src/pam/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/pam/mod.rs#L143

Added line #L143 was not covered by tests
} else {
0
}
Expand All @@ -151,7 +151,7 @@
if self.allow_null_auth_token {
0
} else {
PAM_DISALLOW_NULL_AUTHTOK as i32
PAM_DISALLOW_NULL_AUTHTOK

Check warning on line 154 in src/pam/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/pam/mod.rs#L154

Added line #L154 was not covered by tests
}
}

Expand Down Expand Up @@ -196,18 +196,14 @@
pub fn set_user(&mut self, user: &str) -> PamResult<()> {
let c_user = CString::new(user)?;
pam_err(unsafe {
pam_set_item(
self.pamh,
PAM_USER as i32,
c_user.as_ptr() as *const libc::c_void,
)
pam_set_item(self.pamh, PAM_USER, c_user.as_ptr() as *const libc::c_void)

Check warning on line 199 in src/pam/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/pam/mod.rs#L199

Added line #L199 was not covered by tests
})
}

/// Get the user that is currently active in the PAM handle
pub fn get_user(&mut self) -> PamResult<String> {
let mut data = std::ptr::null();
pam_err(unsafe { pam_get_item(self.pamh, PAM_USER as i32, &mut data) })?;
pam_err(unsafe { pam_get_item(self.pamh, PAM_USER, &mut data) })?;

Check warning on line 206 in src/pam/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/pam/mod.rs#L206

Added line #L206 was not covered by tests

// safety check to make sure that we do not ready a null ptr into a cstr
if data.is_null() {
Expand All @@ -223,25 +219,13 @@
/// Set the TTY path for the current TTY that this PAM session started from.
pub fn set_tty<P: AsRef<OsStr>>(&mut self, tty_path: P) -> PamResult<()> {
let data = CString::new(tty_path.as_ref().as_bytes())?;
pam_err(unsafe {
pam_set_item(
self.pamh,
PAM_TTY as i32,
data.as_ptr() as *const libc::c_void,
)
})
pam_err(unsafe { pam_set_item(self.pamh, PAM_TTY, data.as_ptr() as *const libc::c_void) })

Check warning on line 222 in src/pam/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/pam/mod.rs#L222

Added line #L222 was not covered by tests
}

// Set the user that requested the actions in this PAM instance.
pub fn set_requesting_user(&mut self, user: &str) -> PamResult<()> {
let data = CString::new(user.as_bytes())?;
pam_err(unsafe {
pam_set_item(
self.pamh,
PAM_RUSER as i32,
data.as_ptr() as *const libc::c_void,
)
})
pam_err(unsafe { pam_set_item(self.pamh, PAM_RUSER, data.as_ptr() as *const libc::c_void) })

Check warning on line 228 in src/pam/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/pam/mod.rs#L228

Added line #L228 was not covered by tests
}

/// Re-initialize the credentials stored in PAM
Expand All @@ -266,7 +250,7 @@
let mut flags = 0;
flags |= self.silent_flag();
if expired_only {
flags |= PAM_CHANGE_EXPIRED_AUTHTOK as i32;
flags |= PAM_CHANGE_EXPIRED_AUTHTOK;

Check warning on line 253 in src/pam/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/pam/mod.rs#L253

Added line #L253 was not covered by tests
}
pam_err(unsafe { pam_chauthtok(self.pamh, flags) })
}
Expand Down Expand Up @@ -362,7 +346,7 @@
unsafe {
pam_end(
self.pamh,
self.last_pam_status.unwrap_or(PAM_SUCCESS as libc::c_int) | PAM_DATA_SILENT as i32,
self.last_pam_status.unwrap_or(PAM_SUCCESS as libc::c_int) | PAM_DATA_SILENT,

Check warning on line 349 in src/pam/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/pam/mod.rs#L349

Added line #L349 was not covered by tests
)
};
}
Expand Down
Loading
Loading