Unverified Commit 235be05c authored by Jeremy Soller's avatar Jeremy Soller Committed by GitHub

Merge pull request #32 from MggMuggins/master

Remove ArgParser dep, whoami
parents a190dd55 69838054
......@@ -3,11 +3,6 @@ name = "ansi_term"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "arg_parser"
version = "0.1.0"
source = "git+https://github.com/redox-os/arg-parser.git#7503531821b0c111f9fac77a5d2536ea221105fe"
[[package]]
name = "argon2rs"
version = "0.2.5"
......@@ -270,7 +265,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "userutils"
version = "0.1.0"
dependencies = [
"arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)",
"clap 2.29.4 (registry+https://github.com/rust-lang/crates.io-index)",
"extra 0.1.0 (git+https://github.com/redox-os/libextra.git)",
"liner 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -306,7 +300,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6b3568b48b7cefa6b8ce125f9bb4989e52fbcc29ebea88df04cc7c5f12f70455"
"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.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef"
"checksum atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8352656fd42c30a0c3c89d26dea01e3b77c0ab2af18230835c15e2e13cd51859"
......
......@@ -50,12 +50,7 @@ path = "src/bin/userdel.rs"
name = "usermod"
path = "src/bin/usermod.rs"
[[bin]]
name = "whoami"
path = "src/bin/whoami.rs"
[dependencies]
arg_parser = { git = "https://github.com/redox-os/arg-parser.git" }
clap = "~2.29.4"
extra = { git = "https://github.com/redox-os/libextra.git" }
liner = "0.1"
......
......@@ -17,5 +17,8 @@ inspiration by BSD systems. They are indeed small, by choice.
- `su`: Allows users to substitute identity.
- `sudo`: Enables users to execute a command as another user.
- `useradd`: Add a user
- `usermod`: Modify user information
- `userdel`: Delete a user
- `groupadd`: Add a user group
- `whoami`: Display effective user ID.
- `groupmod`: Modify group information
- `groupdel`: Remove a user group
......@@ -5,6 +5,7 @@ extern crate clap;
extern crate extra;
extern crate redox_users;
use std::env::args;
use std::process::exit;
use extra::option::OptionalExt;
......@@ -53,7 +54,7 @@ AUTHOR
"#; /* @MANEND */
pub fn main() {
let args = clap_app!(id =>
let app = clap_app!(id =>
(author: "Jose Narvaez")
(about: "Get user and group information about the current user")
(@arg IGNORE: -a "Ignored for compatibility with other impls of id")
......@@ -66,7 +67,12 @@ pub fn main() {
(@arg NAME: -n --name requires[selector] "Display names of groups/users instead of ids (use with -g or -u)")
(@arg REAL: -r --real requires[selector] "Display real id's instead of effective ids (use with -g and -u)")
)
).get_matches();
);
let args = match &*args().nth(0).unwrap_or(String::new()) {
"whoami" => app.get_matches_from(["id", "-un"].iter()),
_ => app.get_matches()
};
// Display the different group IDs (effective and real)
// as white-space separated numbers, in no particular order.
......@@ -78,19 +84,10 @@ pub fn main() {
println!("{} {}", egid, gid);
exit(0);
}
/*
// Check if people passed both -g -u which are mutually exclusive
if parser.found(&'u') && parser.found(&'g') {
let msg = "id: specify either -u or -g but not both\n";
print_msg(msg, &mut stdout, &mut stderr);
print_msg(HELP_INFO, &mut stdout, &mut stderr);
exit(1);
}*/
// Display effective/real process user ID UNIX user name
if args.is_present("USER") && args.is_present("NAME") {
// Did they pass -r? F so, we show the real
// Did they pass -r? If so, we show the real
let uid = if args.is_present("REAL") {
get_uid()
} else {
......
#![deny(warnings)]
extern crate arg_parser;
#[macro_use]
extern crate clap;
extern crate extra;
extern crate liner;
extern crate termion;
......@@ -9,17 +10,14 @@ extern crate userutils;
use std::fs::File;
use std::io::{self, Write};
use std::process::exit;
use std::env;
use std::str;
use extra::option::OptionalExt;
use arg_parser::ArgParser;
use termion::input::TermRead;
use redox_users::{AllUsers};
use userutils::spawn_shell;
const MAN_PAGE: &'static str = /* @MANSTART{login} */ r#"
const _MAN_PAGE: &'static str = /* @MANSTART{login} */ r#"
NAME
login - log into the computer
......@@ -31,9 +29,8 @@ DESCRIPTION
OPTIONS
-h
--help
Display this help and exit.
-h --help
Display help info and exit.
AUTHOR
Written by Jeremy Soller, Jose Narvaez.
......@@ -46,16 +43,10 @@ pub fn main() {
let mut stdout = io::stdout();
let mut stderr = io::stderr();
let mut parser = ArgParser::new(1)
.add_flag(&["h", "help"]);
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);
}
let _args = clap_app!(login =>
(author: "Jeremy Soller, Jose Narvaez")
(about: "Login as a user")
).get_matches();
if let Ok(mut issue) = File::open(ISSUE_FILE) {
io::copy(&mut issue, &mut stdout).try(&mut stderr);
......
#![deny(warnings)]
extern crate arg_parser;
extern crate extra;
extern crate syscall;
extern crate termion;
......@@ -11,13 +10,12 @@ use std::io::{self, Write};
use std::os::unix::process::CommandExt;
use std::process::{Command, exit};
use arg_parser::ArgParser;
use extra::option::OptionalExt;
use termion::input::TermRead;
use redox_users::{get_uid, AllUsers, AllGroups};
const MAX_ATTEMPTS: u16 = 3;
const MAN_PAGE: &'static str = /* @MANSTART{sudo} */ r#"
const _MAN_PAGE: &'static str = /* @MANSTART{sudo} */ r#"
NAME
sudo - execute a command as another user
......@@ -29,12 +27,6 @@ DESCRIPTION
The sudo utility allows a permitted user to execute a command as the
superuser or another user, as specified by the security policy.
OPTIONS
-h
--help
Display this help and exit.
EXIT STATUS
Upon successful execution of a command, the exit status from sudo will
be the exit status of the program that was executed. In case of error
......@@ -50,17 +42,6 @@ pub fn main() {
let stdout = io::stdout();
let mut stdout = stdout.lock();
let mut parser = ArgParser::new(1)
.add_flag(&["h", "help"]);
parser.parse(env::args());
// Shows the help
if parser.found("help") {
let _ = stdout.write_all(MAN_PAGE.as_bytes());
let _ = stdout.flush();
exit(0);
}
let mut args = env::args().skip(1);
let cmd = args.next().unwrap_or_else(|| {
eprintln!("sudo: no command provided");
......
#![deny(warnings)]
extern crate arg_parser;
extern crate extra;
extern crate redox_users;
use std::io::{self, Write};
use std::process::exit;
use std::env;
use arg_parser::ArgParser;
use extra::option::OptionalExt;
use redox_users::{get_euid, AllUsers};
const MAN_PAGE: &'static str = /* @MANSTART{whoami} */ r#"
NAME
whoami - display effective user id
SYNOPSIS
whoami [ -h | --help ]
DESCRIPTION
The whoami utility displays your effective user ID as a name.
OPTIONS
-h
--help
Display this help and exit.
EXIT STATUS
The whoami utility exits 0 on success, and >0 if an error occurs.
AUTHOR
Written by Jose Narvaez.
"#; /* @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"]);
parser.parse(env::args());
if parser.found("help") {
stdout.write_all(MAN_PAGE.as_bytes()).try(&mut stderr);
stdout.flush().try(&mut stderr);
exit(0);
}
let euid = get_euid().unwrap_or_exit(1);
let users = AllUsers::new().unwrap_or_exit(1);
let user = users.get_by_id(euid).unwrap_or_exit(1);
println!("{}", user.user);
exit(0);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment