fix: add systemd-homed reported uids to user filter
This commit is contained in:
parent
0b0d2925ff
commit
63c2812959
4 changed files with 37 additions and 14 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
|
@ -1406,6 +1406,7 @@ dependencies = [
|
||||||
"whitespace-conf",
|
"whitespace-conf",
|
||||||
"xdg",
|
"xdg",
|
||||||
"zbus",
|
"zbus",
|
||||||
|
"zbus_systemd",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -8787,6 +8788,16 @@ dependencies = [
|
||||||
"zvariant",
|
"zvariant",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zbus_systemd"
|
||||||
|
version = "0.26000.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "40c8310483ff4a77492d04a90bef30f40938059b4a4b4f7e456dda335d816cb6"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"zbus",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zbus_xml"
|
name = "zbus_xml"
|
||||||
version = "5.2.1"
|
version = "5.2.1"
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ whitespace-conf = "1"
|
||||||
#TODO: reduce features
|
#TODO: reduce features
|
||||||
tokio = { workspace = true, features = ["full"] }
|
tokio = { workspace = true, features = ["full"] }
|
||||||
xdg = "3.0"
|
xdg = "3.0"
|
||||||
|
zbus_systemd = { version = "0.26000.0", features = ["home1"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["systemd"]
|
default = ["systemd"]
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
use cosmic_comp_config::output::randr;
|
use cosmic_comp_config::output::randr;
|
||||||
use cosmic_config::CosmicConfigEntry;
|
use cosmic_config::CosmicConfigEntry;
|
||||||
use kdl::KdlDocument;
|
use kdl::KdlDocument;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::{BTreeMap, BTreeSet};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::os::unix::fs::OpenOptionsExt;
|
use std::os::unix::fs::OpenOptionsExt;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use zbus::Connection;
|
||||||
|
use zbus_systemd::home1::ManagerProxy;
|
||||||
|
|
||||||
pub use cosmic_applets_config::time::TimeAppletConfig;
|
pub use cosmic_applets_config::time::TimeAppletConfig;
|
||||||
pub use cosmic_bg_config::state::State as BgState;
|
pub use cosmic_bg_config::state::State as BgState;
|
||||||
|
|
@ -16,13 +18,25 @@ pub use cosmic_theme::{Theme, ThemeBuilder};
|
||||||
pub struct UserFilter {
|
pub struct UserFilter {
|
||||||
uid_min: u32,
|
uid_min: u32,
|
||||||
uid_max: u32,
|
uid_max: u32,
|
||||||
|
homed_uids: BTreeSet<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for UserFilter {
|
impl UserFilter {
|
||||||
fn default() -> Self {
|
pub async fn new() -> Result<Self, zbus::Error> {
|
||||||
let login_defs_data = fs::read_to_string("/etc/login.defs").unwrap_or_default();
|
let login_defs_data = fs::read_to_string("/etc/login.defs").unwrap_or_default();
|
||||||
let login_defs = whitespace_conf::parse(&login_defs_data);
|
let login_defs = whitespace_conf::parse(&login_defs_data);
|
||||||
Self {
|
|
||||||
|
let connection = Connection::system().await?;
|
||||||
|
let homed = ManagerProxy::new(&connection).await?;
|
||||||
|
|
||||||
|
let homed_uids = homed
|
||||||
|
.list_homes()
|
||||||
|
.await?
|
||||||
|
.iter()
|
||||||
|
.map(|(_, uid, ..)| *uid)
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
uid_min: login_defs
|
uid_min: login_defs
|
||||||
.get("UID_MIN")
|
.get("UID_MIN")
|
||||||
.and_then(|x| x.parse::<u32>().ok())
|
.and_then(|x| x.parse::<u32>().ok())
|
||||||
|
|
@ -31,17 +45,14 @@ impl Default for UserFilter {
|
||||||
.get("UID_MAX")
|
.get("UID_MAX")
|
||||||
.and_then(|x| x.parse::<u32>().ok())
|
.and_then(|x| x.parse::<u32>().ok())
|
||||||
.unwrap_or(65000),
|
.unwrap_or(65000),
|
||||||
}
|
homed_uids,
|
||||||
}
|
})
|
||||||
}
|
|
||||||
|
|
||||||
impl UserFilter {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self::default()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn filter(&self, user: &pwd::Passwd) -> bool {
|
pub fn filter(&self, user: &pwd::Passwd) -> bool {
|
||||||
if user.uid < self.uid_min || user.uid > self.uid_max {
|
if (user.uid < self.uid_min || user.uid > self.uid_max)
|
||||||
|
&& !self.homed_uids.contains(&user.uid)
|
||||||
|
{
|
||||||
// Skip system accounts
|
// Skip system accounts
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,8 +70,8 @@ struct GreeterProxy;
|
||||||
|
|
||||||
#[zbus::interface(name = "com.system76.CosmicGreeter")]
|
#[zbus::interface(name = "com.system76.CosmicGreeter")]
|
||||||
impl GreeterProxy {
|
impl GreeterProxy {
|
||||||
fn get_user_data(&mut self) -> Result<String, GreeterError> {
|
async fn get_user_data(&mut self) -> Result<String, GreeterError> {
|
||||||
let user_filter = UserFilter::new();
|
let user_filter = UserFilter::new().await?;
|
||||||
|
|
||||||
// The pwd::Passwd method is unsafe (but not labelled as such) due to using global state (libc pwent functions).
|
// The pwd::Passwd method is unsafe (but not labelled as such) due to using global state (libc pwent functions).
|
||||||
// To prevent issues, this should only be called once in the entire process space at a time
|
// To prevent issues, this should only be called once in the entire process space at a time
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue