Skip to content
Snippets Groups Projects
Verified Commit e3ad91e2 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Return clone of BasicTokenResponse to not keep a ref to the static for too long

Thanks to tnariol!
parent 5edfd9e1
No related branches found
No related tags found
No related merge requests found
...@@ -293,7 +293,7 @@ impl UserInfo { ...@@ -293,7 +293,7 @@ impl UserInfo {
/// ///
/// This will use the in-memory token from the `access_token` slot if it is filled, /// This will use the in-memory token from the `access_token` slot if it is filled,
/// or attempt to load a token from disk if not /// or attempt to load a token from disk if not
pub fn get_access_token(&mut self) -> &Option<BasicTokenResponse> { pub fn get_access_token(&mut self) -> Option<BasicTokenResponse> {
// Try to load our acess token if none is known // Try to load our acess token if none is known
if self.access_token.is_none() { if self.access_token.is_none() {
debug!("No token in memory, trying to load from file"); debug!("No token in memory, trying to load from file");
...@@ -309,7 +309,10 @@ impl UserInfo { ...@@ -309,7 +309,10 @@ impl UserInfo {
self.restore_privileges(); self.restore_privileges();
} }
return &self.access_token; match &self.access_token {
Some(t) => Some(t.clone()),
None => None
}
} }
/// Set the known access token for this user /// Set the known access token for this user
......
...@@ -67,11 +67,9 @@ impl PasswdHooks for OidcPasswd { ...@@ -67,11 +67,9 @@ impl PasswdHooks for OidcPasswd {
let conf = nss_hook_prepare(); let conf = nss_hook_prepare();
info!("[NSS] passwd.get_all_entries called"); info!("[NSS] passwd.get_all_entries called");
let mut context_user = get_context_user(); let user_token_res = get_context_user().get_access_token();
let user_token_res = context_user.get_access_token();
// FIXME Implement caching of system token // FIXME Implement caching of system token
let system_token_res = get_access_token_client(&conf, "nss", "", ""); let system_token_res = get_access_token_client(&conf, "nss", "", "");
let system_token_res = system_token_res.as_ref();
let token = match user_token_res { let token = match user_token_res {
Some(t) => t, Some(t) => t,
None => { None => {
...@@ -100,11 +98,9 @@ impl PasswdHooks for OidcPasswd { ...@@ -100,11 +98,9 @@ impl PasswdHooks for OidcPasswd {
let conf = nss_hook_prepare(); let conf = nss_hook_prepare();
info!("[NSS] passwd.get_entry_by_uid called for {}", uid); info!("[NSS] passwd.get_entry_by_uid called for {}", uid);
let mut context_user = get_context_user(); let user_token_res = get_context_user().get_access_token();
let user_token_res = context_user.get_access_token();
// FIXME Implement caching of system token // FIXME Implement caching of system token
let system_token_res = get_access_token_client(&conf, "nss", "", ""); let system_token_res = get_access_token_client(&conf, "nss", "", "");
let system_token_res = system_token_res.as_ref();
let token = match user_token_res { let token = match user_token_res {
Some(t) => t, Some(t) => t,
None => { None => {
...@@ -133,11 +129,9 @@ impl PasswdHooks for OidcPasswd { ...@@ -133,11 +129,9 @@ impl PasswdHooks for OidcPasswd {
let conf = nss_hook_prepare(); let conf = nss_hook_prepare();
info!("[NSS] passwd.get_entry_by_name called for {}", name); info!("[NSS] passwd.get_entry_by_name called for {}", name);
let mut context_user = get_context_user(); let user_token_res = get_context_user().get_access_token();
let user_token_res = context_user.get_access_token();
// FIXME Implement caching of system token // FIXME Implement caching of system token
let system_token_res = get_access_token_client(&conf, "nss", "", ""); let system_token_res = get_access_token_client(&conf, "nss", "", "");
let system_token_res = system_token_res.as_ref();
let token = match user_token_res { let token = match user_token_res {
Some(t) => t, Some(t) => t,
None => { None => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment