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
c4339731
Verified
Commit
c4339731
authored
3 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
[Cache] Do not needlessly push euid around
parent
b009c807
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/cache.rs
+17
-3
17 additions, 3 deletions
src/cache.rs
with
17 additions
and
3 deletions
src/cache.rs
+
17
−
3
View file @
c4339731
...
@@ -54,6 +54,11 @@ impl Cache {
...
@@ -54,6 +54,11 @@ impl Cache {
}
}
fn
drop_privileges
(
&
self
,
username
:
&
String
)
->
Result
<
uid_t
,
&
str
>
{
fn
drop_privileges
(
&
self
,
username
:
&
String
)
->
Result
<
uid_t
,
&
str
>
{
let
current_euid
;
unsafe
{
current_euid
=
geteuid
();
};
let
nam
=
match
CString
::
new
(
username
.as_str
())
{
let
nam
=
match
CString
::
new
(
username
.as_str
())
{
Ok
(
nam
)
=>
nam
,
Ok
(
nam
)
=>
nam
,
Err
(
_
)
=>
return
Err
(
"Invalid username in lookup"
)
Err
(
_
)
=>
return
Err
(
"Invalid username in lookup"
)
...
@@ -63,7 +68,7 @@ impl Cache {
...
@@ -63,7 +68,7 @@ impl Cache {
target_euid
=
(
*
getpwnam
(
nam
.as_ptr
()))
.pw_uid
;
target_euid
=
(
*
getpwnam
(
nam
.as_ptr
()))
.pw_uid
;
};
};
if
target_euid
==
self
.original
_euid
{
if
target_euid
==
current
_euid
{
debug!
(
"No need to drop privileges, already running as {}"
,
username
);
debug!
(
"No need to drop privileges, already running as {}"
,
username
);
return
Ok
(
self
.original_euid
);
return
Ok
(
self
.original_euid
);
}
else
if
self
.original_euid
==
0
{
}
else
if
self
.original_euid
==
0
{
...
@@ -85,9 +90,18 @@ impl Cache {
...
@@ -85,9 +90,18 @@ impl Cache {
}
}
fn
restore_privileges
(
&
self
)
{
fn
restore_privileges
(
&
self
)
{
debug!
(
"Restoring privileges"
)
;
let
current_euid
;
unsafe
{
unsafe
{
seteuid
(
self
.original_euid
);
current_euid
=
geteuid
();
};
if
current_euid
!=
self
.original_euid
{
debug!
(
"Restoring privileges"
);
unsafe
{
seteuid
(
self
.original_euid
);
};
}
else
{
debug!
(
"No need to restore privileges, already running as original user"
);
}
}
}
}
...
...
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