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
a7216b77
Verified
Commit
a7216b77
authored
3 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
[Cache] Implement removal of user token file
parent
559454b2
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
src/cache.rs
+19
-3
19 additions, 3 deletions
src/cache.rs
src/lib.rs
+2
-0
2 additions, 0 deletions
src/lib.rs
with
21 additions
and
3 deletions
src/cache.rs
+
19
−
3
View file @
a7216b77
...
@@ -13,6 +13,8 @@
...
@@ -13,6 +13,8 @@
* limitations under the License.
* limitations under the License.
*/
*/
use
crate
::
BASE_NAME
;
use
lazy_static
::
lazy_static
;
use
lazy_static
::
lazy_static
;
use
std
::
collections
::
HashMap
;
use
std
::
collections
::
HashMap
;
use
std
::
convert
::
From
;
use
std
::
convert
::
From
;
...
@@ -24,9 +26,13 @@ use std::ffi::CString;
...
@@ -24,9 +26,13 @@ use std::ffi::CString;
use
oauth2
::
basic
::
BasicTokenResponse
;
use
oauth2
::
basic
::
BasicTokenResponse
;
use
std
::
env
;
use
std
::
env
;
use
std
::
fs
::
remove_file
;
use
std
::
io
;
use
std
::
path
::
PathBuf
;
use
xdg
::{
BaseDirectories
,
BaseDirectoriesError
};
use
xdg
::{
BaseDirectories
,
BaseDirectoriesError
};
const
TOKEN_DEFAULT_EXPIRES
:
u64
=
24
*
60
*
60
;
const
TOKEN_DEFAULT_EXPIRES
:
u64
=
24
*
60
*
60
;
const
USER_TOKEN_FILENAME
:
&
str
=
"user_token.json"
;
struct
UserToken
{
struct
UserToken
{
access_token
:
String
,
access_token
:
String
,
...
@@ -61,7 +67,7 @@ impl From<BasicTokenResponse> for UserToken {
...
@@ -61,7 +67,7 @@ impl From<BasicTokenResponse> for UserToken {
struct
Cache
{
struct
Cache
{
user_tokens
:
HashMap
<
String
,
UserToken
>
,
user_tokens
:
HashMap
<
String
,
UserToken
>
,
original_euid
:
uid_t
original_euid
:
uid_t
,
}
}
impl
Cache
{
impl
Cache
{
...
@@ -103,7 +109,7 @@ impl Cache {
...
@@ -103,7 +109,7 @@ impl Cache {
let
user_home
=
CString
::
from_raw
((
*
getpwnam
(
nam
.as_ptr
()))
.pw_dir
)
.to_str
()
.unwrap
();
let
user_home
=
CString
::
from_raw
((
*
getpwnam
(
nam
.as_ptr
()))
.pw_dir
)
.to_str
()
.unwrap
();
env
::
set_var
(
"HOME"
,
user_home
);
env
::
set_var
(
"HOME"
,
user_home
);
let
base_dirs
=
BaseDirectories
::
new
(
)
?
;
let
base_dirs
=
BaseDirectories
::
with_prefix
(
BASE_NAME
)
?
;
if
saved_home
!=
None
{
if
saved_home
!=
None
{
env
::
set_var
(
"HOME"
,
saved_home
.unwrap
());
env
::
set_var
(
"HOME"
,
saved_home
.unwrap
());
...
@@ -114,6 +120,13 @@ impl Cache {
...
@@ -114,6 +120,13 @@ impl Cache {
return
Ok
(
base_dirs
);
return
Ok
(
base_dirs
);
}
}
fn
place_user_cache_file
(
&
self
,
username
:
String
,
filename
:
&
str
)
->
Result
<
PathBuf
,
io
::
Error
>
{
match
self
.get_user_xdg_base_directories
(
username
)
{
Ok
(
b
)
=>
b
.place_cache_file
(
filename
),
Err
(
e
)
=>
Err
(
io
::
Error
::
new
(
io
::
ErrorKind
::
NotFound
,
e
))
}
}
pub
fn
load_user_token
(
&
self
,
owner
:
String
)
->
Option
<&
UserToken
>
{
pub
fn
load_user_token
(
&
self
,
owner
:
String
)
->
Option
<&
UserToken
>
{
return
self
.user_tokens
.get
(
&
owner
);
return
self
.user_tokens
.get
(
&
owner
);
}
}
...
@@ -127,7 +140,10 @@ impl Cache {
...
@@ -127,7 +140,10 @@ impl Cache {
// Try to remove user's token cache file
// Try to remove user's token cache file
self
.drop_privileges
(
owner
)
.ok
();
self
.drop_privileges
(
owner
)
.ok
();
// FIXME Add delete code here
match
self
.place_user_cache_file
(
owner
,
USER_TOKEN_FILENAME
)
{
Ok
(
path
)
=>
remove_file
(
path
),
Err
(
e
)
=>
Err
(
e
)
};
self
.restore_privileges
();
self
.restore_privileges
();
}
}
...
...
This diff is collapsed.
Click to expand it.
src/lib.rs
+
2
−
0
View file @
a7216b77
const
BASE_NAME
:
&
str
=
"nss_pam_oidc"
;
// Modules and macro imports for our own code
// Modules and macro imports for our own code
#[macro_use]
extern
crate
log
;
#[macro_use]
extern
crate
log
;
mod
cache
;
mod
cache
;
...
...
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