@@ -11,6 +11,7 @@ use std::io::prelude::*;
11
11
use std:: process:: { Command , Stdio } ;
12
12
use std:: os:: unix:: io:: { AsRawFd , FromRawFd } ;
13
13
use std:: fmt;
14
+ use std:: path:: Path ;
14
15
use openssl;
15
16
use bindings:: * ;
16
17
use openssl:: sign:: Verifier ;
@@ -90,9 +91,9 @@ impl fmt::Display for ConfigError {
90
91
match * self {
91
92
ConfigError :: Io ( ref ioerr) => write ! ( f, "{}" , ioerr) ,
92
93
ConfigError :: Toml ( _) => write ! ( f, "TOML format error" ) ,
93
- ConfigError :: MissingField ( _ ) => write ! ( f, "field: 'authenticator_path ' is not found" ) ,
94
- ConfigError :: InvalidValueType ( _ ) => {
95
- write ! ( f, "field: 'authenticator_path ' has an invalid value type" )
94
+ ConfigError :: MissingField ( ref field ) => write ! ( f, "field: '{} ' is not found" , field ) ,
95
+ ConfigError :: InvalidValueType ( ref field ) => {
96
+ write ! ( f, "field: '{} ' has an invalid value type" , field )
96
97
}
97
98
}
98
99
}
@@ -114,6 +115,20 @@ fn get_authenticator_path() -> Result<String, ConfigError> {
114
115
Ok ( authenticator_path. to_owned ( ) )
115
116
}
116
117
118
+ fn get_win_mnt ( ) -> Result < String , ConfigError > {
119
+ let mut config_file = File :: open ( "/etc/pam_wsl_hello/config" ) ?;
120
+ let mut config = String :: new ( ) ;
121
+ config_file. read_to_string ( & mut config) ?;
122
+
123
+ let config_value = config. parse :: < Value > ( ) ?;
124
+ let win_mnt = config_value
125
+ . get ( "win_mnt" )
126
+ . ok_or ( ConfigError :: MissingField ( "win_mnt" . to_owned ( ) ) ) ?
127
+ . as_str ( )
128
+ . ok_or ( ConfigError :: InvalidValueType ( "win_mnt" . to_owned ( ) ) ) ?;
129
+ Ok ( win_mnt. to_owned ( ) )
130
+ }
131
+
117
132
#[ derive( Debug ) ]
118
133
enum HelloAuthenticationError {
119
134
GetUserError ( i32 ) ,
@@ -206,7 +221,7 @@ fn authenticate_via_hello(pamh: *mut pam_handle_t) -> Result<i32, HelloAuthentic
206
221
let authenticator_path = get_authenticator_path ( ) ?;
207
222
let authenticator = Command :: new ( & authenticator_path)
208
223
. arg ( credential_key_name)
209
- . current_dir ( "/mnt/c" )
224
+ . current_dir ( Path :: new ( & get_win_mnt ( ) ? ) )
210
225
. stdin ( challenge_tmpfile_in)
211
226
. stdout ( Stdio :: piped ( ) )
212
227
. spawn ( )
0 commit comments