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
Lukas Weichelt
nss-pam-webapi
Commits
c576ee52
Verified
Commit
c576ee52
authored
4 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Unify Passwd structs
parent
f2190c07
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/cache.rs
+9
-9
9 additions, 9 deletions
src/cache.rs
src/nss.rs
+1
-14
1 addition, 14 deletions
src/nss.rs
src/unix.rs
+20
-15
20 additions, 15 deletions
src/unix.rs
with
30 additions
and
38 deletions
src/cache.rs
+
9
−
9
View file @
c576ee52
...
...
@@ -128,7 +128,7 @@ impl UserInfo {
self
.try_resolve
()
.ok
();
}
match
&
self
.passwd
{
Some
(
passwd
)
=>
Ok
(
passwd
.
pw_
uid
),
Some
(
passwd
)
=>
Ok
(
passwd
.uid
),
None
=>
match
self
.uid
{
Some
(
uid
)
=>
Ok
(
uid
),
None
=>
Err
(
io
::
Error
::
new
(
io
::
ErrorKind
::
InvalidInput
,
"foo"
))
...
...
@@ -141,13 +141,13 @@ impl UserInfo {
pub
fn
set_uid
(
&
mut
self
,
uid
:
uid_t
)
{
self
.uid
=
Some
(
uid
);
if
self
.passwd
.is_some
()
&&
self
.passwd
.as_ref
()
.unwrap
()
.
pw_
uid
!=
uid
{
if
self
.passwd
.is_some
()
&&
self
.passwd
.as_ref
()
.unwrap
()
.uid
!=
uid
{
// Invalidate passwd because UID does not match anymore
self
.passwd
=
None
;
self
.try_resolve
()
.ok
();
}
self
.username
=
match
&
self
.passwd
{
Some
(
p
)
=>
Some
(
p
.
pw_
name
.to_string
()),
Some
(
p
)
=>
Some
(
p
.name
.to_string
()),
None
=>
None
};
}
...
...
@@ -159,7 +159,7 @@ impl UserInfo {
self
.try_resolve
()
.ok
();
}
match
&
self
.passwd
{
Some
(
passwd
)
=>
Ok
(
passwd
.
pw_
name
.to_string
()),
Some
(
passwd
)
=>
Ok
(
passwd
.name
.to_string
()),
None
=>
match
&
self
.username
{
Some
(
username
)
=>
Ok
(
username
.to_string
()),
None
=>
Err
(
io
::
Error
::
new
(
io
::
ErrorKind
::
InvalidInput
,
"foo"
))
...
...
@@ -172,13 +172,13 @@ impl UserInfo {
pub
fn
set_username
(
&
mut
self
,
username
:
String
)
{
self
.username
=
Some
(
username
);
if
self
.passwd
.is_some
()
&&
self
.passwd
.as_ref
()
.unwrap
()
.
pw_
name
!=
self
.username
.as_ref
()
.unwrap
()
.to_string
()
{
if
self
.passwd
.is_some
()
&&
self
.passwd
.as_ref
()
.unwrap
()
.name
!=
self
.username
.as_ref
()
.unwrap
()
.to_string
()
{
// Invalidate passwd because UID does not match anymore
self
.passwd
=
None
;
self
.try_resolve
()
.ok
();
}
self
.uid
=
match
&
self
.passwd
{
Some
(
p
)
=>
Some
(
p
.
pw_
uid
),
Some
(
p
)
=>
Some
(
p
.uid
),
None
=>
None
};
}
...
...
@@ -186,8 +186,8 @@ impl UserInfo {
/// Set the full passwd struct from outside
pub
fn
set_passwd
(
&
mut
self
,
passwd
:
Passwd
)
{
self
.passwd
=
Some
(
passwd
.clone
());
self
.username
=
Some
(
passwd
.
pw_
name
);
self
.uid
=
Some
(
passwd
.
pw_
uid
);
self
.username
=
Some
(
passwd
.name
);
self
.uid
=
Some
(
passwd
.uid
);
}
/// Return the home directory from the passwd slot,
...
...
@@ -197,7 +197,7 @@ impl UserInfo {
self
.try_resolve
()
.ok
();
}
match
&
self
.passwd
{
Some
(
passwd
)
=>
Ok
(
passwd
.
pw_
dir
.clone
()),
Some
(
passwd
)
=>
Ok
(
passwd
.dir
.clone
()),
None
=>
Err
(
io
::
Error
::
new
(
io
::
ErrorKind
::
InvalidInput
,
"foo"
))
}
}
...
...
This diff is collapsed.
Click to expand it.
src/nss.rs
+
1
−
14
View file @
c576ee52
...
...
@@ -25,23 +25,10 @@ use crate::cache::get_context_user;
use
crate
::
logging
::
setup_log
;
use
crate
::
oauth
::{
get_data_jq
,
get_usable_token
};
use
serde
::{
Serialize
,
Deserialize
};
use
libnss
::
interop
::
Response
;
use
libnss
::
passwd
::{
PasswdHooks
,
Passwd
};
#[derive(Serialize,
Deserialize)]
#[serde(remote
=
"Passwd"
)]
struct
PasswdDef
{
name
:
String
,
passwd
:
String
,
uid
:
libc
::
uid_t
,
gid
:
libc
::
gid_t
,
gecos
:
String
,
dir
:
String
,
shell
:
String
}
#[derive(Deserialize)]
struct
PasswdHelper
(
#[serde(with
=
"PasswdDef"
)]
Passwd
);
use
crate
::
unix
::
PasswdHelper
;
fn
nss_hook_prepare
()
->
Config
{
let
conf
=
get_config
(
None
);
...
...
This diff is collapsed.
Click to expand it.
src/unix.rs
+
20
−
15
View file @
c576ee52
...
...
@@ -22,29 +22,34 @@ use std::io;
use
std
::
mem
::
uninitialized
;
use
std
::
ptr
::
null_mut
;
#[derive(Clone)]
use
libnss
;
use
serde
::{
Serialize
,
Deserialize
};
#[derive(Clone,
Deserialize,
Serialize)]
#[serde(remote
=
"libnss::passwd::Passwd"
)]
pub
struct
Passwd
{
pub
pw_
name
:
String
,
pub
pw_
passwd
:
String
,
pub
pw_
uid
:
uid_t
,
pub
pw_
gid
:
gid_t
,
pub
pw_
gecos
:
String
,
pub
pw_
dir
:
String
,
pub
pw_
shell
:
String
pub
name
:
String
,
pub
passwd
:
String
,
pub
uid
:
uid_t
,
pub
gid
:
gid_t
,
pub
gecos
:
String
,
pub
dir
:
String
,
pub
shell
:
String
}
#[derive(Deserialize)]
pub
struct
PasswdHelper
(
#[serde(with
=
"Passwd"
)]
pub
libnss
::
passwd
::
Passwd
);
const
MAX_BUFLEN
:
size_t
=
1024
*
1024
;
fn
getpwxx_fillpw
(
c_passwd
:
passwd
)
->
Passwd
{
unsafe
{
Passwd
{
pw_
name
:
CStr
::
from_ptr
(
c_passwd
.pw_name
)
.to_string_lossy
()
.into_owned
(),
pw_
passwd
:
CStr
::
from_ptr
(
c_passwd
.pw_passwd
)
.to_string_lossy
()
.into_owned
(),
pw_
uid
:
c_passwd
.pw_uid
,
pw_
gid
:
c_passwd
.pw_gid
,
pw_
gecos
:
CStr
::
from_ptr
(
c_passwd
.pw_gecos
)
.to_string_lossy
()
.into_owned
(),
pw_
dir
:
CStr
::
from_ptr
(
c_passwd
.pw_dir
)
.to_string_lossy
()
.into_owned
(),
pw_
shell
:
CStr
::
from_ptr
(
c_passwd
.pw_shell
)
.to_string_lossy
()
.into_owned
(),
name
:
CStr
::
from_ptr
(
c_passwd
.pw_name
)
.to_string_lossy
()
.into_owned
(),
passwd
:
CStr
::
from_ptr
(
c_passwd
.pw_passwd
)
.to_string_lossy
()
.into_owned
(),
uid
:
c_passwd
.pw_uid
,
gid
:
c_passwd
.pw_gid
,
gecos
:
CStr
::
from_ptr
(
c_passwd
.pw_gecos
)
.to_string_lossy
()
.into_owned
(),
dir
:
CStr
::
from_ptr
(
c_passwd
.pw_dir
)
.to_string_lossy
()
.into_owned
(),
shell
:
CStr
::
from_ptr
(
c_passwd
.pw_shell
)
.to_string_lossy
()
.into_owned
(),
}
}
}
...
...
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