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
f2edfa44
Verified
Commit
f2edfa44
authored
3 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
[NSS] Implement stub of passwd endpoint retrieval
parent
b906a8a6
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/nss.rs
+19
-3
19 additions, 3 deletions
src/nss.rs
src/oauth.rs
+14
-4
14 additions, 4 deletions
src/oauth.rs
with
33 additions
and
7 deletions
src/nss.rs
+
19
−
3
View file @
f2edfa44
...
@@ -15,13 +15,18 @@
...
@@ -15,13 +15,18 @@
use
crate
::
config
::{
use
crate
::
config
::{
get_config
,
get_config
,
get_optional
get_optional
,
get_or_error
};
};
use
config
::
Config
;
use
config
::
Config
;
use
crate
::
cache
::
get_cache
;
use
crate
::
cache
::
get_cache
;
use
crate
::
logging
::
setup_log
;
use
crate
::
logging
::
setup_log
;
use
crate
::
oauth
::
get_data
;
use
std
::
collections
::
HashMap
;
use
serde_json
::
value
::
Value
;
use
libc
::{
getpwuid
,
geteuid
};
use
libc
::{
getpwuid
,
geteuid
};
use
std
::
ffi
::
CStr
;
use
std
::
ffi
::
CStr
;
...
@@ -54,14 +59,25 @@ struct OidcPasswd;
...
@@ -54,14 +59,25 @@ struct OidcPasswd;
impl
PasswdHooks
for
OidcPasswd
{
impl
PasswdHooks
for
OidcPasswd
{
fn
get_all_entries
()
->
Response
<
Vec
<
Passwd
>>
{
fn
get_all_entries
()
->
Response
<
Vec
<
Passwd
>>
{
let
config
=
nss_hook_prepare
();
let
conf
=
nss_hook_prepare
();
let
mut
cache
=
get_cache
();
let
user
=
get_current_user
();
let
user
=
get_current_user
();
let
token
=
match
get_
cache
()
.load_user_token
(
&
user
)
{
let
token
=
match
cache
.load_user_token
(
&
user
)
{
Some
(
t
)
=>
t
,
Some
(
t
)
=>
t
,
None
=>
return
Response
::
Unavail
None
=>
return
Response
::
Unavail
};
};
let
data
:
Vec
<
HashMap
<
String
,
Value
>>
=
match
get_data
(
conf
,
"nss"
,
"passwd"
,
token
,
""
)
{
Ok
(
d
)
=>
d
,
Err
(
_
)
=>
return
Response
::
Unavail
};
for
ent
in
&
data
{
for
(
k
,
v
)
in
ent
{
debug!
(
"{} {}"
,
k
,
v
);
}
}
Response
::
Success
(
Response
::
Success
(
vec!
[
vec!
[
Passwd
{
Passwd
{
...
...
This diff is collapsed.
Click to expand it.
src/oauth.rs
+
14
−
4
View file @
f2edfa44
...
@@ -133,21 +133,31 @@ pub fn get_access_token_password<E: Copy>(conf: Config, prefix: &str, username:
...
@@ -133,21 +133,31 @@ pub fn get_access_token_password<E: Copy>(conf: Config, prefix: &str, username:
}
}
}
}
fn
get_data
<
T
:
for
<
'de
>
Deserialize
<
'de
>
,
E
>
(
conf
:
Config
,
token
:
BasicTokenResponse
,
endpoint
:
String
,
error_value
:
E
)
->
Result
<
T
,
E
>
{
pub
fn
get_data
<
T
:
for
<
'de
>
Deserialize
<
'de
>
,
E
:
Copy
>
(
conf
:
Config
,
prefix
:
&
str
,
endpoint
:
&
str
,
token
:
&
BasicTokenResponse
,
error_value
:
E
)
->
Result
<
T
,
E
>
{
let
access_token
=
token
.access_token
()
.secret
();
let
access_token
=
token
.access_token
()
.secret
();
let
endpoint_url
:
String
=
get_or_error
(
&
conf
,
&
full_key
(
prefix
,
&
(
endpoint
.to_string
()
+
"_url"
)),
error_value
)
?
;
info!
(
"Loading JSON data from {}"
,
endpoint_url
);
let
client
=
reqwest
::
blocking
::
Client
::
new
();
let
client
=
reqwest
::
blocking
::
Client
::
new
();
let
res
=
match
client
let
res
=
match
client
.get
(
endpoint
)
.get
(
&
endpoint
_url
)
.header
(
reqwest
::
header
::
AUTHORIZATION
,
format!
(
"Bearer {}"
,
access_token
))
.header
(
reqwest
::
header
::
AUTHORIZATION
,
format!
(
"Bearer {}"
,
access_token
))
.send
()
{
.send
()
{
Ok
(
r
)
=>
r
,
Ok
(
r
)
=>
r
,
Err
(
_
)
=>
return
Err
(
error_value
)
Err
(
e
)
=>
{
error!
(
"Could not complete HTTP request: {}"
,
e
);
return
Err
(
error_value
);
}
};
};
let
data
=
match
res
.json
()
{
let
data
=
match
res
.json
()
{
Ok
(
d
)
=>
d
,
Ok
(
d
)
=>
d
,
Err
(
_
)
=>
return
Err
(
error_value
)
Err
(
e
)
=>
{
error!
(
"Could not parse JSON response: {}"
,
e
);
return
Err
(
error_value
);
}
};
};
debug!
(
"Successfully loaded JSON data from {}"
,
endpoint_url
);
return
Ok
(
data
);
return
Ok
(
data
);
}
}
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