Forked from an inaccessible project.
-
Nik | Klampfradler authoredNik | Klampfradler authored
config.rs 1.69 KiB
/* Copyright 2021 Dominik George <nik@naturalnet.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
extern crate config;
fn load_config(config_file: String) -> config::Config {
let mut conf = config::Config::default();
conf.set("pam.flow", "password");
conf
.merge(config::File::with_name(&config_file)).unwrap()
.merge(config::Environment::with_prefix("NSS_PAM_OIDC")).unwrap();
return conf;
}
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();
}
let mut conf = load_config(config_file);
conf.merge(conf_args).unwrap();
return conf;
}
pub fn argv_to_config(argv: Vec<String>) -> config::Config {
let mut conf = config::Config::default();
for arg in &argv {
if arg.contains("=") {
let split: Vec<&str> = arg.split("=").collect();
conf.set(split[0], split[1]);
} else {
conf.set(arg, true);
}
}
return conf;
}