-
Notifications
You must be signed in to change notification settings - Fork 74
Add first user into wheel group #3030
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
Merged
+26
−47
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b629dc1
Cleared several warnings on unused code
mchf 49f40f0
Automatically add first user into wheel group
mchf 9cbf204
Formatting
mchf a41bfec
Moved implementation of logic from ModelAdapter into Model
mchf 021537a
Set addidional user groups in time of user creation
mchf 66e4dec
Formatting
mchf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -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"); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why those empty lines? ;-)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well just my way of formatting .. kind of separates things into logical blocks |
||
| 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(()) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good idea. Thinking about it, and having into account that there is some repetitive code when running the commands, perhaps we could even think about having our own struct.
Something like:
And you could do:
It is just an idea. WDYT? We could even reuse it in other parts of Agama.