Skip to content

Commit 5fcc2a1

Browse files
authored
feat: support custom /c mountpoints (nullpo-head#13)
Detect mount from /etc/wsl.conf, store specified MNT in the module's config file, read it in the Rust module
1 parent dcdc08c commit 5fcc2a1

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

install.sh

+13-1
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,19 @@ if [ ! -e build/pam_wsl_hello.so ] || \
4141
fi
4242

4343
MNT=/mnt/c
44+
45+
if [ -f "/etc/wsl.conf" ]; then
46+
# Get value specified in the form of 'root = /some/path/'
47+
WSL_CONF_ROOT="$(cat /etc/wsl.conf | sed -n "s/^[[:space:]]*root[[:space:]]*=\(.*\)/\1/p")"
48+
# Trim path
49+
WSL_CONF_ROOT="$(echo $WSL_CONF_ROOT | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
50+
if [ -n "$WSL_CONF_ROOT" ]; then
51+
MNT="${WSL_CONF_ROOT}c"
52+
fi
53+
fi
54+
4455
if [[ ! -e "${MNT}" ]]; then
45-
echo "'/mnt/c' was not found. Please input the mount point of your C drive to invoke Windows commands."
56+
echo "'$MNT' was not found. Please input the mount point of your C drive to invoke Windows commands."
4657
echo -n ": "
4758
read MNT
4859
fi
@@ -106,6 +117,7 @@ if [ ! -e "/etc/pam_wsl_hello/config" ] || prompt_yn "'/etc/pam_wsl_hello/config
106117
set -x
107118
sudo touch /etc/pam_wsl_hello/config
108119
sudo echo "authenticator_path = \"$PAM_WSL_HELLO_WINPATH/WindowsHelloAuthenticator/WindowsHelloAuthenticator.exe\"" | sudo tee /etc/pam_wsl_hello/config
120+
sudo echo "win_mnt = \"$MNT\"" | sudo tee -a /etc/pam_wsl_hello/config
109121
else
110122
echo "Skipping creation of '/etc/pam_wsl_hello/config'..."
111123
fi

src/auth.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::io::prelude::*;
1111
use std::process::{Command, Stdio};
1212
use std::os::unix::io::{AsRawFd, FromRawFd};
1313
use std::fmt;
14+
use std::path::Path;
1415
use openssl;
1516
use bindings::*;
1617
use openssl::sign::Verifier;
@@ -90,9 +91,9 @@ impl fmt::Display for ConfigError {
9091
match *self {
9192
ConfigError::Io(ref ioerr) => write!(f, "{}", ioerr),
9293
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)
9697
}
9798
}
9899
}
@@ -114,6 +115,20 @@ fn get_authenticator_path() -> Result<String, ConfigError> {
114115
Ok(authenticator_path.to_owned())
115116
}
116117

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+
117132
#[derive(Debug)]
118133
enum HelloAuthenticationError {
119134
GetUserError(i32),
@@ -206,7 +221,7 @@ fn authenticate_via_hello(pamh: *mut pam_handle_t) -> Result<i32, HelloAuthentic
206221
let authenticator_path = get_authenticator_path()?;
207222
let authenticator = Command::new(&authenticator_path)
208223
.arg(credential_key_name)
209-
.current_dir("/mnt/c")
224+
.current_dir(Path::new(&get_win_mnt()?))
210225
.stdin(challenge_tmpfile_in)
211226
.stdout(Stdio::piped())
212227
.spawn()

0 commit comments

Comments
 (0)