@@ -12,9 +12,6 @@ use std::{env, path::PathBuf};
1212#[ cfg( target_family = "windows" ) ]
1313use 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" ) ]
1916const 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" ) ]
157153pub 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