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
b3959687
Verified
Commit
b3959687
authored
3 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Make args in get_config optional
Also, rewrite get_config more ellegantly.
parent
9063d349
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/config.rs
+16
-17
16 additions, 17 deletions
src/config.rs
src/pam.rs
+1
-1
1 addition, 1 deletion
src/pam.rs
with
17 additions
and
18 deletions
src/config.rs
+
16
−
17
View file @
b3959687
...
...
@@ -15,29 +15,28 @@
extern
crate
config
;
fn
load_config
(
config_file
:
String
)
->
config
::
Config
{
let
mut
conf
=
config
::
Config
::
default
();
const
DEFAULT_CONFIG_FILE
:
&
str
=
"/etc/nss_pam_oidc"
;
pub
fn
get_config
(
conf_args
:
Option
<
config
::
Config
>
)
->
config
::
Config
{
// Preset default configuration
let
mut
conf
=
config
::
Config
::
default
();
conf
.set
(
"pam.flow"
,
"password"
)
.ok
();
conf
.merge
(
config
::
File
::
with_name
(
&
config_file
))
.unwrap
()
.merge
(
config
::
Environment
::
with_prefix
(
"NSS_PAM_OIDC"
))
.unwrap
();
// Unwrap passed arguments or use empty fallback
let
conf_args
=
conf_args
.unwrap_or_default
();
return
conf
;
}
// Determine config file from args if provided and load config file
let
config_file
=
match
conf_args
.get_str
(
"config"
)
{
Ok
(
filename
)
=>
filename
.to_string
(),
Err
(
_
)
=>
DEFAULT_CONFIG_FILE
.to_string
(),
};
conf
.merge
(
config
::
File
::
with_name
(
&
config_file
))
.ok
();
pub
fn
get_config
(
conf_args
:
config
::
Config
)
->
config
::
Config
{
let
config_file
:
String
;
let
config_file_passed
=
conf_args
.get_str
(
"config"
);
if
config_file_passed
.is_ok
()
{
config_file
=
config_file_passed
.unwrap
()
.to_string
();
}
else
{
config_file
=
"/etc/nss_pam_oidc"
.to_string
();
}
// Override configuration from environment variables
conf
.merge
(
config
::
Environment
::
with_prefix
(
"NSS_PAM_OIDC"
))
.ok
();
let
mut
conf
=
load_config
(
config_file
);
conf
.merge
(
conf_args
)
.
unwrap
();
// Override configuration from args passed on module loading (e.g. args in PAM stack)
conf
.merge
(
conf_args
)
.
ok
();
return
conf
;
}
...
...
This diff is collapsed.
Click to expand it.
src/pam.rs
+
1
−
1
View file @
b3959687
...
...
@@ -138,7 +138,7 @@ fn do_legacy_auth(username: String, password: String, config: Config) -> Result<
fn
pam_sm_prepare
(
argv
:
&
Vec
<
String
>
)
->
Config
{
let
conf_args
=
argv_to_config
(
argv
);
let
conf
=
get_config
(
conf_args
);
let
conf
=
get_config
(
Some
(
conf_args
)
)
;
let
mut
log_level
=
log
::
LevelFilter
::
Error
;
if
conf
.get_bool
(
"debug"
)
.unwrap_or_default
()
||
conf
.get_bool
(
"pam.debug"
)
.unwrap_or_default
()
{
...
...
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