Implemented groupadd, fix for passwd compile

This commit is contained in:
MggMuggins
2017-11-26 16:53:37 -06:00
parent 6b951a8bdc
commit 8fffeb1e57
5 changed files with 120 additions and 11 deletions
Generated
+20 -6
View File
@@ -8,10 +8,18 @@ name = "argon2rs"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"blake2-rfc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
"blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"scoped_threadpool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "arrayvec"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "0.7.0"
@@ -19,9 +27,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "blake2-rfc"
version = "0.2.17"
version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"arrayvec 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -65,6 +74,11 @@ dependencies = [
"unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "nodrop"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rand"
version = "0.3.18"
@@ -90,7 +104,6 @@ dependencies = [
[[package]]
name = "redox_users"
version = "0.1.0"
source = "git+https://github.com/redox-os/users.git#77ce04ba3c2a1e4731e75eb58984598fa8937880"
dependencies = [
"argon2rs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"extra 0.1.0 (git+https://github.com/redox-os/libextra.git)",
@@ -128,25 +141,26 @@ dependencies = [
"rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_users 0.1.0 (git+https://github.com/redox-os/users.git)",
"redox_users 0.1.0",
"termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[metadata]
"checksum arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)" = "<none>"
"checksum argon2rs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3f67b0b6a86dae6e67ff4ca2b6201396074996379fba2b92ff649126f37cb392"
"checksum arrayvec 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2f0ef4a9820019a0c91d918918c93dc71d469f581a49b47ddc1d285d4270bbe2"
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
"checksum blake2-rfc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "0c6a476f32fef3402f1161f89d0d39822809627754a126f8441ff2a9d45e2d59"
"checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400"
"checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e"
"checksum extra 0.1.0 (git+https://github.com/redox-os/libextra.git)" = "<none>"
"checksum fuchsia-zircon 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f6c0581a4e363262e52b87f59ee2afe3415361c6ec35e665924eb08afe8ff159"
"checksum fuchsia-zircon-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "43f3795b4bae048dc6123a6b972cadde2e676f9ded08aef6bb77f5f157684a82"
"checksum libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "5ba3df4dcb460b9dfbd070d41c94c19209620c191b0340b929ce748a2bcd42d2"
"checksum liner 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f9e406164c25b420480023985bdf65cef366855666ad4cb12cd3eaee82dcb399"
"checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2"
"checksum rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)" = "6475140dfd8655aeb72e1fd4b7a1cc1c202be65d71669476e392fe62532b9edd"
"checksum redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "8dde11f18c108289bef24469638a04dce49da56084f2d50618b226e47eb04509"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum redox_users 0.1.0 (git+https://github.com/redox-os/users.git)" = "<none>"
"checksum scoped_threadpool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "4ea459fe3ceff01e09534847c49860891d3ff1c12b4eb7731b67f2778fb60190"
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
"checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f"
+6 -2
View File
@@ -2,13 +2,17 @@
name = "userutils"
version = "0.1.0"
[[bin]]
name = "id"
path = "src/bin/id.rs"
[[bin]]
name = "getty"
path = "src/bin/getty.rs"
[[bin]]
name = "id"
path = "src/bin/id.rs"
name = "groupadd"
path = "src/bin/groupadd.rs"
[[bin]]
name = "login"
+2 -1
View File
@@ -16,4 +16,5 @@ inspiration by BSD systems. They are indeed small, by choice.
- `passwd`: Allows users to modify their passwords.
- `su`: Allows users to substitute identity.
- `sudo`: Enables users to execute a command as another user.
- `whoami`: Display effective user ID.
- `groupadd`: Add a user group
- `whoami`: Display effective user ID.
+90
View File
@@ -0,0 +1,90 @@
#[deny(dead_code)]
extern crate arg_parser;
extern crate extra;
extern crate redox_users;
use extra::option::OptionalExt;
use std::{io, env};
use std::io::Write;
use std::process::exit;
use arg_parser::ArgParser;
use redox_users::{add_group, get_uid, get_unique_group_id};
const MAN_PAGE: &'static str = /* @MANSTART{groupadd} */ r#"
NAME
groupadd - add a user group
SYNOPSIS
groupadd [ -f | --force ] group
groupadd [ -h | --help ]
DESCRIPTION
The groupadd utility adds a new user group using values
passed on the command line and system defaults.
OPTIONS
-f, --force
Simply forces the exit status of the program to 0
even if the group already exists. A message is still
printed to stdout.
-h, --help
Display this help and exit.
AUTHOR
Written by Wesley Hershberger.
"#; /* @MANEND */
fn main() {
let stdout = io::stdout();
let mut stdout = stdout.lock();
let mut stderr = io::stderr();
let mut parser = ArgParser::new(1)
.add_flag(&["h", "help"])
.add_flag(&["f", "force"]);
parser.parse(env::args());
// Shows the help
if parser.found("help") {
stdout.write_all(MAN_PAGE.as_bytes()).try(&mut stderr);
stdout.flush().try(&mut stderr);
exit(0);
}
if get_uid() != 0 {
eprintln!("groupadd: privelege elevation required");
exit(1);
}
let groupname = if parser.args.is_empty() {
eprintln!("groupadd: no group name specified");
exit(1);
} else {
&parser.args[0]
};
let gid = match get_unique_group_id() {
Some(gid) => gid,
None => {
eprintln!("groupadd: no available gid");
exit(1);
}
};
match add_group(groupname, gid, &[""]) {
Ok(_) => {},
Err(err) => {
eprintln!("groupadd: {}: {}", err, groupname);
if parser.found("force") {
exit(0);
} else {
exit(1);
}
}
}
}
+2 -2
View File
@@ -1,4 +1,4 @@
#![deny(warnings)]
#![deny(dead_code)]
extern crate arg_parser;
extern crate extra;
@@ -136,4 +136,4 @@ fn main() {
eprintln!("passwd: you do not have permission to set the password of '{}'", user.user);
exit(1);
}
}
}