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
91132875
Verified
Commit
91132875
authored
3 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
[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
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+5
-0
5 additions, 0 deletions
README.md
src/cache.rs
+30
-1
30 additions, 1 deletion
src/cache.rs
with
35 additions
and
1 deletion
README.md
+
5
−
0
View file @
91132875
...
@@ -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.
This diff is collapsed.
Click to expand it.
src/cache.rs
+
30
−
1
View file @
91132875
...
@@ -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_token
s
.remove
(
&
owner
);
self
.
delete_
user_token
(
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