diff --git a/rust/agama-server/src/users/web.rs b/rust/agama-server/src/users/web.rs index 544485b25e..0c86e1c5c1 100644 --- a/rust/agama-server/src/users/web.rs +++ b/rust/agama-server/src/users/web.rs @@ -27,7 +27,7 @@ use crate::{error::Error, users::password::PasswordChecker}; use agama_lib::{ error::ServiceError, - users::{model::RootPatchSettings, proxies::Users1Proxy, FirstUser, RootUser, UsersClient}, + users::{model::RootPatchSettings, FirstUser, RootUser, UsersClient}, }; use axum::{ extract::State, @@ -37,7 +37,6 @@ use axum::{ Json, Router, }; use serde::Deserialize; -use tokio_stream::{Stream, StreamExt}; use super::password::PasswordCheckResult; @@ -48,9 +47,6 @@ struct UsersState<'a> { /// Sets up and returns the axum service for the users module. pub async fn users_service(dbus: zbus::Connection) -> Result { - const DBUS_SERVICE: &str = "org.opensuse.Agama.Manager1"; - const DBUS_PATH: &str = "/org/opensuse/Agama/Users1"; - let users = UsersClient::new(dbus.clone()).await?; let state = UsersState { users }; // FIXME: use anyhow temporarily until we adapt all these methods to return diff --git a/rust/agama-users/src/model.rs b/rust/agama-users/src/model.rs index 7bf57ef188..81c8b3f321 100644 --- a/rust/agama-users/src/model.rs +++ b/rust/agama-users/src/model.rs @@ -35,30 +35,6 @@ pub trait ModelAdapter: Send + 'static { fn install(&self, _config: &Config) -> Result<(), service::Error> { Ok(()) } - - fn add_first_user(&self, _user: &FirstUserConfig) -> Result<(), service::Error> { - Ok(()) - } - - fn add_root_user(&self, _root: &RootUserConfig) -> Result<(), service::Error> { - Ok(()) - } - - fn set_user_password( - &self, - _user_name: &str, - _user_password: &UserPassword, - ) -> Result<(), service::Error> { - Ok(()) - } - - fn update_authorized_keys(&self, _ssh_key: &str) -> Result<(), service::Error> { - Ok(()) - } - - fn update_user_fullname(&self, _user: &FirstUserConfig) -> Result<(), service::Error> { - Ok(()) - } } /// [ModelAdapter] implementation for systemd-based systems. @@ -72,18 +48,14 @@ impl Model { install_dir: PathBuf::from(install_dir.as_ref()), } } -} -impl ModelAdapter for Model { - fn install(&self, config: &Config) -> Result<(), service::Error> { - if let Some(first_user) = &config.first_user { - self.add_first_user(&first_user)?; - } - if let Some(root_user) = &config.root { - self.add_root_user(&root_user)?; - } + /// Wrapper for creating Command which works in installation chroot + fn chroot_command(&self) -> Command { + let mut cmd = Command::new("chroot"); - Ok(()) + cmd.arg(&self.install_dir); + + cmd } /// Reads first user's data from given config and updates its setup accordingly @@ -95,9 +67,9 @@ impl ModelAdapter for Model { return Err(service::Error::MissingUserData); }; - let useradd = Command::new("chroot") - .arg(&self.install_dir) - .args(["useradd", &user_name]) + let useradd = self + .chroot_command() + .args(["useradd", "-G", "wheel", &user_name]) .output()?; if !useradd.status.success() { @@ -109,7 +81,6 @@ impl ModelAdapter for Model { } self.set_user_password(user_name, user_password)?; - self.update_user_fullname(user) } @@ -140,8 +111,7 @@ impl ModelAdapter for Model { user_name: &str, user_password: &UserPassword, ) -> Result<(), service::Error> { - let mut passwd_cmd = Command::new("chroot"); - passwd_cmd.arg(&self.install_dir); + let mut passwd_cmd = self.chroot_command(); passwd_cmd.arg("chpasswd"); if user_password.hashed_password { @@ -193,8 +163,8 @@ impl ModelAdapter for Model { return Ok(()); }; - let chfn = Command::new("chroot") - .arg(&self.install_dir) + let chfn = self + .chroot_command() .args(["chfn", "-f", &full_name, &user_name]) .output()?; @@ -213,3 +183,16 @@ impl ModelAdapter for Model { Ok(()) } } + +impl ModelAdapter for Model { + fn install(&self, config: &Config) -> Result<(), service::Error> { + if let Some(first_user) = &config.first_user { + self.add_first_user(&first_user)?; + } + if let Some(root_user) = &config.root { + self.add_root_user(&root_user)?; + } + + Ok(()) + } +}