From ce2f963e563c0db13c543d873a9214620b1b3b6c Mon Sep 17 00:00:00 2001 From: Dominik George <dominik.george@teckids.org> Date: Fri, 7 May 2021 13:38:33 +0200 Subject: [PATCH] [NSS] Fix response API by using recent libnss-rs version Also, fix types for stub implementations --- Cargo.toml | 2 +- src/nss.rs | 45 ++++++++++++++++++++++++--------------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f407f3a..a56e8de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/nss.rs b/src/nss.rs index c321cb8..ea6fdb7 100644 --- a/src/nss.rs +++ b/src/nss.rs @@ -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 } } -- GitLab