Skip to content
Snippets Groups Projects
Verified Commit ce2f963e authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

[NSS] Fix response API by using recent libnss-rs version

Also, fix types for stub implementations
parent c96b272e
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,7 @@ crate-type = [ "cdylib" ]
[dependencies]
pamsm = { version = "^0.4.2", features = ["libpam"] }
libnss = "^0.1.0"
libnss = "^0.4.0"
paste = "^0.1"
libc = "^0.2.0"
lazy_static = "^1.3.0"
......
......@@ -49,7 +49,7 @@ fn nss_hook_prepare() -> Config {
return conf;
}
fn get_bearer_token(config: Config) -> Result<String, Response> {
fn get_bearer_token<T>(config: Config) -> Result<String, Response<T>> {
let client_id = ClientId::new(get_or_error(&config, "nss.client_id", Response::Unavail)?);
let client_secret = match get_optional(&config, "nss.client_secret") {
Some(v) => Some(ClientSecret::new(v)),
......@@ -82,7 +82,7 @@ fn get_bearer_token(config: Config) -> Result<String, Response> {
let result = request.request(http_client);
match result {
Ok(t) => Ok(t),
Ok(t) => Ok("".to_string()),
Err(e) => match e {
RequestTokenError::Request(re) => match re {
reqwest::Error::Reqwest(ree) => {
......@@ -118,32 +118,35 @@ fn get_bearer_token(config: Config) -> Result<String, Response> {
}
}
fn do_json_request(config: Config, url: String) -> Result<String, Response> {
fn do_json_request<T>(config: Config, url: String) -> Result<String, Response<T>> {
let token = get_bearer_token(config)?;
Ok("".to_string())
}
struct OidcPasswd;
impl PasswdHooks for OidcPasswd {
fn get_all_entries() -> Vec<Passwd> {
fn get_all_entries() -> Response<Vec<Passwd>> {
let config = nss_hook_prepare();
vec![
Passwd {
name: "test".to_string(),
passwd: "x".to_string(),
uid: 1005,
gid: 1005,
gecos: "Test Account".to_string(),
dir: "/home/test".to_string(),
shell: "/bin/bash".to_string(),
}
]
Response::Success(
vec![
Passwd {
name: "test".to_string(),
passwd: "x".to_string(),
uid: 1005,
gid: 1005,
gecos: "Test Account".to_string(),
dir: "/home/test".to_string(),
shell: "/bin/bash".to_string(),
}
]
)
}
fn get_entry_by_uid(uid: libc::uid_t) -> Option<Passwd> {
fn get_entry_by_uid(uid: libc::uid_t) -> Response<Passwd> {
if uid == 1005 {
return Some(Passwd {
return Response::Success(Passwd {
name: "test".to_string(),
passwd: "x".to_string(),
uid: 1005,
......@@ -154,12 +157,12 @@ impl PasswdHooks for OidcPasswd {
});
}
None
Response::NotFound
}
fn get_entry_by_name(name: String) -> Option<Passwd> {
fn get_entry_by_name(name: String) -> Response<Passwd> {
if name == "test" {
return Some(Passwd {
return Response::Success(Passwd {
name: "test".to_string(),
passwd: "x".to_string(),
uid: 1005,
......@@ -170,7 +173,7 @@ impl PasswdHooks for OidcPasswd {
});
}
None
Response::NotFound
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment