Compare commits

..

2 Commits

Author SHA1 Message Date
Kevin Yue
54e2371022 Fix the save credentials not working (#435) 2024-10-30 19:46:53 +08:00
Eric Dallo
511cc5ebd7 Fix flake.nix vpnc-script hardcoded path (#413) 2024-08-18 21:13:26 +08:00
2 changed files with 16 additions and 13 deletions

View File

@@ -111,11 +111,11 @@ impl AuthCookieCredential {
pub struct CachedCredential { pub struct CachedCredential {
username: String, username: String,
password: Option<String>, password: Option<String>,
auth_cookie: AuthCookieCredential, auth_cookie: Option<AuthCookieCredential>,
} }
impl CachedCredential { impl CachedCredential {
pub fn new(username: String, password: Option<String>, auth_cookie: AuthCookieCredential) -> Self { pub fn new(username: String, password: Option<String>, auth_cookie: Option<AuthCookieCredential>) -> Self {
Self { Self {
username, username,
password, password,
@@ -131,12 +131,12 @@ impl CachedCredential {
self.password.as_deref() self.password.as_deref()
} }
pub fn auth_cookie(&self) -> &AuthCookieCredential { pub fn auth_cookie(&self) -> Option<&AuthCookieCredential> {
&self.auth_cookie self.auth_cookie.as_ref()
} }
pub fn set_auth_cookie(&mut self, auth_cookie: AuthCookieCredential) { pub fn set_auth_cookie(&mut self, auth_cookie: AuthCookieCredential) {
self.auth_cookie = auth_cookie; self.auth_cookie = Some(auth_cookie);
} }
pub fn set_username(&mut self, username: String) { pub fn set_username(&mut self, username: String) {
@@ -150,11 +150,7 @@ impl CachedCredential {
impl From<PasswordCredential> for CachedCredential { impl From<PasswordCredential> for CachedCredential {
fn from(value: PasswordCredential) -> Self { fn from(value: PasswordCredential) -> Self {
Self::new( Self::new(value.username().to_owned(), Some(value.password().to_owned()), None)
value.username().to_owned(),
Some(value.password().to_owned()),
AuthCookieCredential::new("", "", ""),
)
} }
} }
#[derive(Debug, Serialize, Deserialize, Type, Clone)] #[derive(Debug, Serialize, Deserialize, Type, Clone)]
@@ -198,11 +194,16 @@ impl Credential {
Some(cred.prelogon_user_auth_cookie()), Some(cred.prelogon_user_auth_cookie()),
None, None,
), ),
// Use the empty string as the password if auth_cookie is present
Credential::Cached(cred) => ( Credential::Cached(cred) => (
cred.password(), if cred.auth_cookie.is_some() {
None
} else {
cred.password()
},
None, None,
Some(cred.auth_cookie.user_auth_cookie()), cred.auth_cookie.as_ref().map(|c| c.user_auth_cookie()),
Some(cred.auth_cookie.prelogon_user_auth_cookie()), cred.auth_cookie.as_ref().map(|c| c.prelogon_user_auth_cookie()),
None, None,
), ),
}; };

View File

@@ -42,6 +42,8 @@
overrideMain = {...}: { overrideMain = {...}: {
postPatch = '' postPatch = ''
substituteInPlace crates/common/src/vpn_utils.rs \
--replace-fail /etc/vpnc/vpnc-script ${pkgs.vpnc-scripts}/bin/vpnc-script
substituteInPlace crates/gpapi/src/lib.rs \ substituteInPlace crates/gpapi/src/lib.rs \
--replace-fail /usr/bin/gpclient $out/bin/gpclient \ --replace-fail /usr/bin/gpclient $out/bin/gpclient \
--replace-fail /usr/bin/gpservice $out/bin/gpservice \ --replace-fail /usr/bin/gpservice $out/bin/gpservice \