Improved id and whoami.
Details - New implementation of `id` inspired by BSD's one. - Refactoring on `whoami`. - Added few utility functions in `userutils` for getting processes user and group real/effective ID and names. Added docs do `getty`, `login`, `passwd`, `su`, and `sudo`. Details - The docs are from BSD's ones. - Also added `ArgParser` to all of them and added a -h/--help flag to all of them. - This is the start of a revision of all of those commands.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
extern crate arg_parser;
|
||||
extern crate extra;
|
||||
extern crate syscall;
|
||||
extern crate termion;
|
||||
extern crate userutils;
|
||||
@@ -8,9 +10,37 @@ use std::io::{self, Read, Write};
|
||||
use std::os::unix::process::CommandExt;
|
||||
use std::process::{self, Command};
|
||||
|
||||
use arg_parser::ArgParser;
|
||||
use termion::input::TermRead;
|
||||
use userutils::{Passwd, Group};
|
||||
|
||||
const MAN_PAGE: &'static str = /* @MANSTART{sudo} */ r#"
|
||||
NAME
|
||||
sudo - execute a command as another user
|
||||
|
||||
SYNOPSIS
|
||||
sudo command
|
||||
sudo [ -h | --help ]
|
||||
|
||||
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
|
||||
the exit status will be >0.
|
||||
|
||||
AUTHOR
|
||||
Written by Jeremy Soller.
|
||||
"#;
|
||||
|
||||
pub fn main() {
|
||||
let stdin = io::stdin();
|
||||
let mut stdin = stdin.lock();
|
||||
@@ -19,6 +49,17 @@ pub fn main() {
|
||||
let stderr = io::stderr();
|
||||
let mut stderr = stderr.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();
|
||||
process::exit(0);
|
||||
}
|
||||
|
||||
let mut args = env::args().skip(1);
|
||||
match args.next() {
|
||||
None => {
|
||||
|
||||
Reference in New Issue
Block a user