Browse Source

Support setuid mode

master
southerntofu 10 months ago
parent
commit
8f7bc18837
  1. 36
      Cargo.lock
  2. 4
      Cargo.toml
  3. 10
      src/cli.rs
  4. 14
      src/log.rs

36
Cargo.lock

@ -26,6 +26,12 @@ version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "clap"
version = "2.33.0"
@ -46,12 +52,12 @@ name = "forgebuild"
version = "0.2.0"
dependencies = [
"glob",
"home",
"hostname",
"lazy_static",
"serde",
"serde_json",
"structopt",
"users",
]
[[package]]
@ -78,15 +84,6 @@ dependencies = [
"libc",
]
[[package]]
name = "home"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2456aef2e6b6a9784192ae780c0f15bc57df0e918585282325e8c8ac27737654"
dependencies = [
"winapi",
]
[[package]]
name = "hostname"
version = "0.3.1"
@ -116,6 +113,15 @@ version = "0.2.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "match_cfg"
version = "0.1.0"
@ -282,6 +288,16 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "vec_map"
version = "0.8.1"

4
Cargo.toml

@ -16,5 +16,5 @@ serde_json = "1.0"
structopt = "0.3"
# Debug Context for translations
serde = { version = "1.0", features = ["derive"] }
# Detect home folder
home = "0.5.3"
# Users information
users = "0.11"

10
src/cli.rs

@ -1,7 +1,11 @@
use std::env;
use std::path::PathBuf;
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)]
#[structopt(
@ -27,7 +31,9 @@ impl Cli {
// Returns an error when the path doesn't exist
PathBuf::from(basedir)
} 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
}

14
src/log.rs

@ -2,7 +2,11 @@ use std::collections::HashMap;
use std::env;
use std::fs;
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;
@ -58,9 +62,13 @@ fn find_translations() -> PathBuf {
match env::var("FORGEBUILDI18N") {
Ok(dir) => PathBuf::from(dir),
Err(_) => {
let home = home_dir().expect("$HOME folder not found");
let mut path = PathBuf::from(home);
//let mut path = home_dir().expect("$HOME folder not found");
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");
println!("{}", path.to_str().unwrap());
if path.is_dir() {
path
} else {

Loading…
Cancel
Save