Drop unmaintained users crate

Its functionality is provided by the `nix` crate which is already a
dependency anyway.

See: https://rustsec.org/advisories/RUSTSEC-2023-0040.html
This commit is contained in:
Hugo Osvaldo Barrera
2023-06-07 14:50:43 +02:00
committed by Kenny Levinsen
parent 7d0f74dfbe
commit 7ebc50ea7a
4 changed files with 13 additions and 36 deletions

11
Cargo.lock generated
View File

@@ -93,7 +93,6 @@ dependencies = [
"serde_json", "serde_json",
"thiserror", "thiserror",
"tokio", "tokio",
"users",
] ]
[[package]] [[package]]
@@ -356,16 +355,6 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
[[package]]
name = "users"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032"
dependencies = [
"libc",
"log",
]
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.11.0+wasi-snapshot-preview1" version = "0.11.0+wasi-snapshot-preview1"

View File

@@ -13,7 +13,6 @@ debug = []
[dependencies] [dependencies]
nix = "0.26" nix = "0.26"
pam-sys = "0.5.6" pam-sys = "0.5.6"
users = "0.11.0"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
greetd_ipc = { path = "../greetd_ipc", features = ["tokio-codec"] } greetd_ipc = { path = "../greetd_ipc", features = ["tokio-codec"] }

View File

@@ -221,15 +221,12 @@ pub async fn main(config: Config) -> Result<(), Error> {
service service
}; };
let u = users::get_user_by_name(&config.file.default_session.user).ok_or(format!( let u = nix::unistd::User::from_name(&config.file.default_session.user)?.ok_or(format!(
"configured default session user '{}' not found", "configured default session user '{}' not found",
&config.file.default_session.user &config.file.default_session.user
))?; ))?;
let uid = Uid::from_raw(u.uid()); let (listener_path, listener) = Listener::create(u.uid, u.gid)?;
let gid = Gid::from_raw(u.primary_group_id());
let (listener_path, listener) = Listener::create(uid, gid)?;
let term_mode = get_tty(&config)?; let term_mode = get_tty(&config)?;

View File

@@ -2,11 +2,10 @@ use std::{env, ffi::CString, os::unix::net::UnixDatagram};
use nix::{ use nix::{
sys::wait::waitpid, sys::wait::waitpid,
unistd::{execve, fork, initgroups, setgid, setsid, setuid, ForkResult, Gid, Uid}, unistd::{execve, fork, initgroups, setgid, setsid, setuid, ForkResult},
}; };
use pam_sys::{PamFlag, PamItemType}; use pam_sys::{PamFlag, PamItemType};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use users::os::unix::UserExt;
use super::{ use super::{
conv::SessionConv, conv::SessionConv,
@@ -162,7 +161,7 @@ fn worker(sock: &UnixDatagram) -> Result<(), Error> {
let pam_username = pam.get_user()?; let pam_username = pam.get_user()?;
let user = users::get_user_by_name(&pam_username).ok_or("unable to get user info")?; let user = nix::unistd::User::from_name(&pam_username)?.ok_or("unable to get user info")?;
// Make this process a session leader. // Make this process a session leader.
setsid().map_err(|e| format!("unable to become session leader: {}", e))?; setsid().map_err(|e| format!("unable to become session leader: {}", e))?;
@@ -198,13 +197,6 @@ fn worker(sock: &UnixDatagram) -> Result<(), Error> {
} }
} }
// Prepare some values from the user struct we gathered earlier.
let username = user.name().to_str().unwrap_or("");
let home = user.home_dir().to_str().unwrap_or("");
let shell = user.shell().to_str().unwrap_or("");
let uid = Uid::from_raw(user.uid());
let gid = Gid::from_raw(user.primary_group_id());
// PAM has to be provided a bunch of environment variables before // PAM has to be provided a bunch of environment variables before
// open_session. We pass any environment variables from our greeter // open_session. We pass any environment variables from our greeter
// through here as well. This allows them to affect PAM (more // through here as well. This allows them to affect PAM (more
@@ -213,10 +205,10 @@ fn worker(sock: &UnixDatagram) -> Result<(), Error> {
let prepared_env = [ let prepared_env = [
"XDG_SEAT=seat0".to_string(), "XDG_SEAT=seat0".to_string(),
format!("XDG_SESSION_CLASS={}", class.as_str()), format!("XDG_SESSION_CLASS={}", class.as_str()),
format!("USER={}", username), format!("USER={}", user.name),
format!("LOGNAME={}", username), format!("LOGNAME={}", user.name),
format!("HOME={}", home), format!("HOME={}", user.dir.to_string_lossy()),
format!("SHELL={}", shell), format!("SHELL={}", user.shell.to_string_lossy()),
format!( format!(
"TERM={}", "TERM={}",
env::var("TERM").unwrap_or_else(|_| "linux".to_string()) env::var("TERM").unwrap_or_else(|_| "linux".to_string())
@@ -236,7 +228,7 @@ fn worker(sock: &UnixDatagram) -> Result<(), Error> {
} }
// Prepare some strings in C format that we'll need. // Prepare some strings in C format that we'll need.
let cusername = CString::new(username)?; let cusername = CString::new(user.name)?;
let command = if source_profile { let command = if source_profile {
format!( format!(
"[ -f /etc/profile ] && . /etc/profile; [ -f $HOME/.profile ] && . $HOME/.profile; exec {}", "[ -f /etc/profile ] && . /etc/profile; [ -f $HOME/.profile ] && . $HOME/.profile; exec {}",
@@ -261,16 +253,16 @@ fn worker(sock: &UnixDatagram) -> Result<(), Error> {
// this match arm. // this match arm.
// Drop privileges to target user // Drop privileges to target user
initgroups(&cusername, gid).expect("unable to init groups"); initgroups(&cusername, user.gid).expect("unable to init groups");
setgid(gid).expect("unable to set GID"); setgid(user.gid).expect("unable to set GID");
setuid(uid).expect("unable to set UID"); setuid(user.uid).expect("unable to set UID");
// Set our parent death signal. setuid/setgid above resets the // Set our parent death signal. setuid/setgid above resets the
// death signal, which is why we do this here. // death signal, which is why we do this here.
prctl(PrctlOption::SET_PDEATHSIG(libc::SIGTERM)).expect("unable to set death signal"); prctl(PrctlOption::SET_PDEATHSIG(libc::SIGTERM)).expect("unable to set death signal");
// Change working directory // Change working directory
if let Err(e) = env::set_current_dir(home) { if let Err(e) = env::set_current_dir(user.dir) {
eprintln!("unable to set working directory: {}", e); eprintln!("unable to set working directory: {}", e);
} }