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
28fa5862
Verified
Commit
28fa5862
authored
4 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
[PAM] Fix and properly document PAM token handling code
parent
af019b9a
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
src/cache.rs
+4
-0
4 additions, 0 deletions
src/cache.rs
src/pam.rs
+17
-1
17 additions, 1 deletion
src/pam.rs
with
21 additions
and
1 deletion
src/cache.rs
+
4
−
0
View file @
28fa5862
...
@@ -398,6 +398,7 @@ fn get_original_euid() -> uid_t {
...
@@ -398,6 +398,7 @@ fn get_original_euid() -> uid_t {
unsafe
{
unsafe
{
if
!
original_euid_set
{
if
!
original_euid_set
{
original_euid
=
geteuid
();
original_euid
=
geteuid
();
debug!
(
"Original EUID stored as {}"
,
original_euid
);
original_euid_set
=
true
;
original_euid_set
=
true
;
}
}
original_euid
original_euid
...
@@ -412,5 +413,8 @@ lazy_static! {
...
@@ -412,5 +413,8 @@ lazy_static! {
static
ref
CONTEXT_USER
:
Mutex
<
UserInfo
>
=
Mutex
::
new
(
UserInfo
::
new
());
static
ref
CONTEXT_USER
:
Mutex
<
UserInfo
>
=
Mutex
::
new
(
UserInfo
::
new
());
}
}
pub
fn
get_context_user
()
->
MutexGuard
<
'static
,
UserInfo
>
{
pub
fn
get_context_user
()
->
MutexGuard
<
'static
,
UserInfo
>
{
// Ensure original EUID is set before first action on context user
get_original_euid
();
CONTEXT_USER
.lock
()
.unwrap
()
CONTEXT_USER
.lock
()
.unwrap
()
}
}
This diff is collapsed.
Click to expand it.
src/pam.rs
+
17
−
1
View file @
28fa5862
...
@@ -92,12 +92,28 @@ impl PamServiceModule for PamOidc {
...
@@ -92,12 +92,28 @@ impl PamServiceModule for PamOidc {
match
get_access_token_password
(
&
conf
,
"pam"
,
username
.to_string
(),
password
.to_string
(),
PamError
::
SERVICE_ERR
,
PamError
::
AUTH_ERR
)
{
match
get_access_token_password
(
&
conf
,
"pam"
,
username
.to_string
(),
password
.to_string
(),
PamError
::
SERVICE_ERR
,
PamError
::
AUTH_ERR
)
{
Ok
(
t
)
=>
{
Ok
(
t
)
=>
{
info!
(
"Authenticated {} using Resource Owner Password Grant"
,
username
);
info!
(
"Authenticated {} using Resource Owner Password Grant"
,
username
);
// Cast a a butt-backwards somersault to get the token where it belongs
// This is because we cannot store the token in the user's home directory
// without resolving the user through getpwnam, and we (probably) cannot
// do getpwnam without having the user's access token, and we (certainly)
// cannot do getpwnam form inside the UserInfo cache object while having
// the UserInfo cache object locked for PAM. Therefore...
// 1. ...mark getpwnam unsafe (prevent cache code from calling it)
set_is_getpwnam_safe
(
false
);
set_is_getpwnam_safe
(
false
);
// 2. ...store the access token (will not go through to $HOME, as getpwnam
// is locked)
get_context_user
()
.set_access_token
(
t
.clone
());
// 3. ...call getpwnam ourselves without having the cache object locked
let
passwd
=
getpwnam_safe
(
username
.to_string
());
let
passwd
=
getpwnam_safe
(
username
.to_string
());
if
passwd
.is_ok
()
{
if
passwd
.is_ok
()
{
// 4. ...if getpwnam was successful, store the token again (this time,
// modulo other errors, it will go through to $HOME)
get_context_user
()
.set_passwd
(
passwd
.unwrap
());
get_context_user
()
.set_passwd
(
passwd
.unwrap
());
get_context_user
()
.set_access_token
(
t
.clone
());
}
}
get_context_user
()
.set_access_token
(
t
);
// 5. ...unlock getpwnam again (somewhat unnecessary)
set_is_getpwnam_safe
(
true
);
set_is_getpwnam_safe
(
true
);
return
PamError
::
SUCCESS
;
return
PamError
::
SUCCESS
;
},
},
...
...
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