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

[Cache] Implemetn stub for persistence

This implements privilege dropping to handle files in uer homes.
parent 5fb2a6b1
No related branches found
No related tags found
No related merge requests found
...@@ -107,3 +107,8 @@ from the API up to date. It handles the following data: ...@@ -107,3 +107,8 @@ from the API up to date. It handles the following data:
* User access tokens (using corresponding refresh tokens, if available) * User access tokens (using corresponding refresh tokens, if available)
* NSS data * NSS data
## Credits
Special thanks to mirabilos in his position as Senior Unix System Development
Consultant.
...@@ -18,6 +18,9 @@ use std::collections::HashMap; ...@@ -18,6 +18,9 @@ use std::collections::HashMap;
use std::convert::From; use std::convert::From;
use std::time::SystemTime; use std::time::SystemTime;
use libc::{geteuid, seteuid, getpwnam};
use std::ffi::CString;
use oauth2::basic::BasicTokenResponse; use oauth2::basic::BasicTokenResponse;
const TOKEN_DEFAULT_EXPIRES: u64 = 24 * 60 * 60; const TOKEN_DEFAULT_EXPIRES: u64 = 24 * 60 * 60;
...@@ -73,10 +76,36 @@ impl Cache { ...@@ -73,10 +76,36 @@ impl Cache {
self.user_tokens.insert(owner, token); self.user_tokens.insert(owner, token);
} }
pub fn delete_user_token(&self, owner: String) {
self.user_tokens.remove(&owner);
// Try to remove user's token cache file
let original_euid = geteuid();
let target_euid = (*getpwnam(CStr::new(owner).ok().unwrap().as_ptr())).pw_uid;
if original_euid != target_euid {
// We are not already running as the target user
if original_euid == 0 {
// If we are root, try dropping privileges to the target user
seteuid(target_euid);
} else {
// Bail out silently if we are not root
return;
}
}
// FIXME Add delete code here
if original_euid != target_euid {
// Restore original privileges if we dropped them earlier
seteuid(original_euid);
}
}
pub fn cleanup_tokens(&self) { pub fn cleanup_tokens(&self) {
for (owner, token) in self.user_tokens { for (owner, token) in self.user_tokens {
if token.is_expired() { if token.is_expired() {
self.user_tokens.remove(&owner); self.delete_user_token(owner);
} }
} }
} }
......
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