Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nss-pam-webapi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
magicfelix
nss-pam-webapi
Commits
559454b2
Verified
Commit
559454b2
authored
3 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
[Cache] Implement XDG base directory fetching
parent
6794776a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Cargo.toml
+1
-0
1 addition, 0 deletions
Cargo.toml
src/cache.rs
+24
-1
24 additions, 1 deletion
src/cache.rs
with
25 additions
and
1 deletion
Cargo.toml
+
1
−
0
View file @
559454b2
...
...
@@ -24,6 +24,7 @@ config = "^0.11.0"
serde
=
"^1.0.125"
log
=
"^0.4.11"
syslog
=
"^5.0.0"
xdg
=
"^2.2.0"
[profile.release]
opt-level
=
'z'
...
...
This diff is collapsed.
Click to expand it.
src/cache.rs
+
24
−
1
View file @
559454b2
...
...
@@ -23,6 +23,9 @@ use std::ffi::CString;
use
oauth2
::
basic
::
BasicTokenResponse
;
use
std
::
env
;
use
xdg
::{
BaseDirectories
,
BaseDirectoriesError
};
const
TOKEN_DEFAULT_EXPIRES
:
u64
=
24
*
60
*
60
;
struct
UserToken
{
...
...
@@ -31,7 +34,6 @@ struct UserToken {
refresh_token
:
Option
<
String
>
,
}
impl
UserToken
{
fn
is_expired
(
&
self
)
->
bool
{
match
SystemTime
::
now
()
.duration_since
(
SystemTime
::
UNIX_EPOCH
)
{
...
...
@@ -91,6 +93,27 @@ impl Cache {
seteuid
(
self
.original_euid
);
}
fn
get_user_xdg_base_directories
(
&
self
,
username
:
String
)
->
Result
<
BaseDirectories
,
BaseDirectoriesError
>
{
let
saved_home
=
env
::
var_os
(
"HOME"
);
let
nam
=
match
CString
::
new
(
username
)
{
Ok
(
nam
)
=>
nam
,
Err
(
_
)
=>
CString
::
new
(
"nobody"
)
.ok
()
.unwrap
()
};
let
user_home
=
CString
::
from_raw
((
*
getpwnam
(
nam
.as_ptr
()))
.pw_dir
)
.to_str
()
.unwrap
();
env
::
set_var
(
"HOME"
,
user_home
);
let
base_dirs
=
BaseDirectories
::
new
()
?
;
if
saved_home
!=
None
{
env
::
set_var
(
"HOME"
,
saved_home
.unwrap
());
}
else
{
env
::
remove_var
(
"HOME"
);
}
return
Ok
(
base_dirs
);
}
pub
fn
load_user_token
(
&
self
,
owner
:
String
)
->
Option
<&
UserToken
>
{
return
self
.user_tokens
.get
(
&
owner
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment