Support setuid mode
This commit is contained in:
parent
c3a4ece084
commit
8f7bc18837
|
@ -26,6 +26,12 @@ version = "1.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "0.1.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "2.33.0"
|
version = "2.33.0"
|
||||||
|
@ -46,12 +52,12 @@ name = "forgebuild"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"glob",
|
"glob",
|
||||||
"home",
|
|
||||||
"hostname",
|
"hostname",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"structopt",
|
"structopt",
|
||||||
|
"users",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -78,15 +84,6 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "home"
|
|
||||||
version = "0.5.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2456aef2e6b6a9784192ae780c0f15bc57df0e918585282325e8c8ac27737654"
|
|
||||||
dependencies = [
|
|
||||||
"winapi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hostname"
|
name = "hostname"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
|
@ -116,6 +113,15 @@ version = "0.2.69"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005"
|
checksum = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "log"
|
||||||
|
version = "0.4.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "match_cfg"
|
name = "match_cfg"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -282,6 +288,16 @@ version = "0.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
|
checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "users"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"log",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vec_map"
|
name = "vec_map"
|
||||||
version = "0.8.1"
|
version = "0.8.1"
|
||||||
|
|
|
@ -16,5 +16,5 @@ serde_json = "1.0"
|
||||||
structopt = "0.3"
|
structopt = "0.3"
|
||||||
# Debug Context for translations
|
# Debug Context for translations
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
# Detect home folder
|
# Users information
|
||||||
home = "0.5.3"
|
users = "0.11"
|
||||||
|
|
10
src/cli.rs
10
src/cli.rs
|
@ -1,7 +1,11 @@
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
use home::home_dir;
|
|
||||||
|
// To get effective user id (EUID) so that setuid works
|
||||||
|
use users::{get_effective_uid,get_user_by_uid};
|
||||||
|
// For home directory
|
||||||
|
use users::os::unix::UserExt;
|
||||||
|
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
#[structopt(
|
#[structopt(
|
||||||
|
@ -27,7 +31,9 @@ impl Cli {
|
||||||
// Returns an error when the path doesn't exist
|
// Returns an error when the path doesn't exist
|
||||||
PathBuf::from(basedir)
|
PathBuf::from(basedir)
|
||||||
} else {
|
} else {
|
||||||
let mut home_path = home_dir().expect("No HOME folder found.");
|
let owner = get_effective_uid();
|
||||||
|
let mut home_path = get_user_by_uid(owner).expect("Failed owner profile")
|
||||||
|
.home_dir().to_path_buf();
|
||||||
home_path.push(".forgebuild");
|
home_path.push(".forgebuild");
|
||||||
home_path
|
home_path
|
||||||
}
|
}
|
||||||
|
|
14
src/log.rs
14
src/log.rs
|
@ -2,7 +2,11 @@ use std::collections::HashMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use home::home_dir;
|
|
||||||
|
// To get effective user id (EUID) so that setuid works
|
||||||
|
use users::{get_effective_uid,get_user_by_uid};
|
||||||
|
// For home directory
|
||||||
|
use users::os::unix::UserExt;
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
|
@ -58,9 +62,13 @@ fn find_translations() -> PathBuf {
|
||||||
match env::var("FORGEBUILDI18N") {
|
match env::var("FORGEBUILDI18N") {
|
||||||
Ok(dir) => PathBuf::from(dir),
|
Ok(dir) => PathBuf::from(dir),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let home = home_dir().expect("$HOME folder not found");
|
//let mut path = home_dir().expect("$HOME folder not found");
|
||||||
let mut path = PathBuf::from(home);
|
let owner = get_effective_uid();
|
||||||
|
let mut path = get_user_by_uid(owner).expect("Failed owner profile")
|
||||||
|
.home_dir().to_path_buf();
|
||||||
|
|
||||||
path.push(".local/share/forgebuild/i18n");
|
path.push(".local/share/forgebuild/i18n");
|
||||||
|
println!("{}", path.to_str().unwrap());
|
||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
path
|
path
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue