-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 00a31d1
Showing
8 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/target | ||
*.tar.gz | ||
*.tar.zst | ||
*.out* | ||
pkg | ||
completions | ||
.vscode/settings.json |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "pam_pwdfile_rs" | ||
version = "0.1.0" | ||
authors = ["Supernovatux <[email protected]>"] | ||
|
||
[dependencies] | ||
pamsm = {version = "*" ,features = ["libpam"] } | ||
sha2 = "0.10.6" | ||
|
||
[lib] | ||
name = "pam_pwdfile_rs" | ||
crate-type = ["cdylib"] | ||
|
||
[profile.release] | ||
debug = false | ||
opt-level = 3 | ||
lto = true | ||
codegen-units = 1 | ||
panic = "abort" | ||
overflow-checks = false | ||
strip = "symbols" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Supernovatux | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Maintainer: Supernovatux <[email protected]> | ||
|
||
pkgname=libpam-pwdfile-rs | ||
pkgver=0.1.0 | ||
pkgrel=1 | ||
pkgdesc="A simple PAM module to authenticate users against a password file" | ||
url="https://github.com/Supernovatux/libpam-pwdfile-rs" | ||
license=("MIT") | ||
arch=("x86_64") | ||
provides=("libpam-pwdfile-rs") | ||
conflicts=("libpam-pwdfile-rs") | ||
source=("https://github.com/Supernovatux/auto_backlight/releases/download/v$pkgver/auto-backlight-$pkgver-x86_64.tar.gz") | ||
sha512sums=("3e961b01592ec79b2cbd56f1c79c23e166c3701bce6d7b965eede873450e9a2cd81e09200b9ecbef9e37e32fc5f80a7af9f5f9672782e1f34bc23ed080d21b0a") | ||
|
||
package() { | ||
install -Dm755 target/release/auto-backlight -t "$pkgdir/usr/bin" | ||
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/zsh | ||
pkgname=libpam-pwdfile-rs | ||
cargo +nightly build -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target x86_64-unknown-linux-gnu --release | ||
version=$(cat Cargo.toml | grep -m1 version | awk '{print $3}' | tr -d '"') | ||
tar -cvf $pkgname-$version-x86_64.tar.gz target/x86_64-unknown-linux-gnu/release/libpam_pwdfile_rs.so LICENSE -I "gzip --best" | ||
shasum=$(sha512sum ./$pkgname-$version-x86_64.tar.gz | awk '{print $1}') | ||
sed -i "s/sha512sums=.*/sha512sums=(\"$shasum\")/" PKGBUILD | ||
sed -i "s/pkgver=.*/pkgver=$version/" PKGBUILD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# libpam-pwdfile-rs | ||
|
||
This is a rust port of [libpam-pwdfile](https://git.tiwe.de/libpam-pwdfile.git). It is a PAM module that allows you to authenticate against a password file. Password are hashed with sha512 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#[macro_use] | ||
extern crate pamsm; | ||
extern crate sha2; | ||
use pamsm::{Pam, PamError, PamFlags, PamLibExt, PamServiceModule}; | ||
use sha2::{Digest, Sha512}; | ||
use std::{ffi::CStr, io::BufRead}; | ||
macro_rules! try_or_ret { | ||
($expr:expr, $err:expr) => { | ||
match $expr { | ||
Ok(val) => val, | ||
Err(_) => return $err, | ||
} | ||
}; | ||
($expr:expr) => { | ||
match $expr { | ||
Ok(exp) => exp, | ||
Err(e) => return e, | ||
} | ||
}; | ||
} | ||
struct PamPwdfile; | ||
fn get_string(pam_string: Result<Option<&CStr>, PamError>) -> Result<String, PamError> { | ||
match pam_string { | ||
Ok(Some(p)) => Ok(p.to_str().map_err(|_| PamError::AUTH_ERR)?.to_string()), | ||
_ => Err(PamError::AUTH_ERR), | ||
} | ||
} | ||
impl PamServiceModule for PamPwdfile { | ||
fn authenticate(pamh: Pam, _flags: PamFlags, args: Vec<String>) -> PamError { | ||
let mut sha512 = Sha512::new(); | ||
let username: String = try_or_ret!(get_string(pamh.get_cached_user())); | ||
let password: String = try_or_ret!(get_string(pamh.get_authtok(None))); | ||
sha512.update(password.as_bytes()); | ||
let hash = format!("{:x}", sha512.finalize()); | ||
let path_to_file = if let Some(index) = args.iter().position(|x| x == "pwdfile") { | ||
if let Some(pwdfile) = args.get(index + 1) { | ||
pwdfile | ||
} else { | ||
return PamError::AUTH_ERR; | ||
} | ||
} else { | ||
return PamError::AUTH_ERR; | ||
}; | ||
let file = try_or_ret!( | ||
std::fs::File::open(path_to_file), | ||
PamError::AUTHINFO_UNAVAIL | ||
); | ||
let reader = std::io::BufReader::new(file); | ||
for i in reader.lines() { | ||
let line = try_or_ret!(i, PamError::AUTHINFO_UNAVAIL); | ||
let new = line.split_once(':').map(|(user, pass)| { | ||
if user.trim() == username && pass.trim() == hash { | ||
PamError::SUCCESS | ||
} else { | ||
PamError::AUTH_ERR | ||
} | ||
}); | ||
if let Some(PamError::SUCCESS) = new { | ||
return PamError::SUCCESS; | ||
} | ||
} | ||
PamError::AUTH_ERR | ||
} | ||
} | ||
|
||
pam_module!(PamPwdfile); |