Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit 5d8f245

Browse files
authored
remove dependency on the users crate (#3150)
1 parent 0f6073b commit 5d8f245

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

src/agent/Cargo.lock

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/agent/onefuzz-agent/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ azure_storage_blobs = { version = "0.12", default-features = false, features = [
4343

4444

4545
[target.'cfg(target_family = "unix")'.dependencies]
46-
users = "0.11"
4746
nix = "0.26"
4847

4948
[target.'cfg(target_family = "windows")'.dependencies]

src/agent/onefuzz-agent/src/commands.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ use std::{env, path::PathBuf};
1212
#[cfg(target_family = "windows")]
1313
use tokio::sync::{OnceCell, SetError};
1414

15-
#[cfg(target_family = "unix")]
16-
use users::{get_user_by_name, os::unix::UserExt};
17-
1815
#[cfg(target_family = "unix")]
1916
const ONEFUZZ_SERVICE_USER: &str = "onefuzz";
2017

@@ -72,7 +69,6 @@ pub async fn add_ssh_key(key_info: &SshKeyInfo) -> Result<()> {
7269
}
7370

7471
let stdout = String::from_utf8_lossy(&result.stdout).to_string();
75-
7672
if stdout.contains(admins) {
7773
let result = Command::new("icacls.exe")
7874
.arg(&admin_auth_keys_path)
@@ -155,13 +151,25 @@ pub async fn add_ssh_key(key_info: &SshKeyInfo) -> Result<()> {
155151

156152
#[cfg(target_family = "unix")]
157153
pub async fn add_ssh_key(key_info: &SshKeyInfo) -> Result<()> {
158-
let user =
159-
get_user_by_name(ONEFUZZ_SERVICE_USER).ok_or_else(|| format_err!("unable to find user"))?;
160-
info!("adding ssh key:{:?} to user:{:?}", key_info, user);
154+
let result = Command::new("sh")
155+
.arg("-c")
156+
.arg(format!("echo ~{}", ONEFUZZ_SERVICE_USER))
157+
.stdin(Stdio::null())
158+
.stdout(Stdio::piped())
159+
.stderr(Stdio::piped())
160+
.spawn()
161+
.context("failed to launch bash commans to retrieve home dir")?
162+
.wait_with_output()
163+
.await
164+
.context("failed to execute bash command to retrieve home dir")?;
165+
if !result.status.success() {
166+
bail!("command to retrieve home dir failed : {:?}", result);
167+
}
161168

162-
let home_path = user.home_dir().to_owned();
169+
let home_path_str = String::from_utf8_lossy(&result.stdout).to_string();
170+
let home_path = std::path::PathBuf::from(home_path_str.trim());
163171
if !home_path.exists() {
164-
bail!("unable to add SSH key to missing home directory");
172+
bail!("home dir does not exist: {}", home_path.display());
165173
}
166174

167175
let mut ssh_path = home_path.join(".ssh");

0 commit comments

Comments
 (0)