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" ] ...@@ -14,7 +14,7 @@ crate-type = [ "cdylib" ]
[dependencies] [dependencies]
pamsm = { version = "^0.4.2", features = ["libpam"] } pamsm = { version = "^0.4.2", features = ["libpam"] }
libnss = "^0.1.0" libnss = "^0.4.0"
paste = "^0.1" paste = "^0.1"
libc = "^0.2.0" libc = "^0.2.0"
lazy_static = "^1.3.0" lazy_static = "^1.3.0"
......
...@@ -49,7 +49,7 @@ fn nss_hook_prepare() -> Config { ...@@ -49,7 +49,7 @@ fn nss_hook_prepare() -> Config {
return conf; 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_id = ClientId::new(get_or_error(&config, "nss.client_id", Response::Unavail)?);
let client_secret = match get_optional(&config, "nss.client_secret") { let client_secret = match get_optional(&config, "nss.client_secret") {
Some(v) => Some(ClientSecret::new(v)), Some(v) => Some(ClientSecret::new(v)),
...@@ -82,7 +82,7 @@ fn get_bearer_token(config: Config) -> Result<String, Response> { ...@@ -82,7 +82,7 @@ fn get_bearer_token(config: Config) -> Result<String, Response> {
let result = request.request(http_client); let result = request.request(http_client);
match result { match result {
Ok(t) => Ok(t), Ok(t) => Ok("".to_string()),
Err(e) => match e { Err(e) => match e {
RequestTokenError::Request(re) => match re { RequestTokenError::Request(re) => match re {
reqwest::Error::Reqwest(ree) => { reqwest::Error::Reqwest(ree) => {
...@@ -118,32 +118,35 @@ fn get_bearer_token(config: Config) -> Result<String, Response> { ...@@ -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)?; let token = get_bearer_token(config)?;
Ok("".to_string())
} }
struct OidcPasswd; struct OidcPasswd;
impl PasswdHooks for OidcPasswd { impl PasswdHooks for OidcPasswd {
fn get_all_entries() -> Vec<Passwd> { fn get_all_entries() -> Response<Vec<Passwd>> {
let config = nss_hook_prepare(); let config = nss_hook_prepare();
vec![ Response::Success(
Passwd { vec![
name: "test".to_string(), Passwd {
passwd: "x".to_string(), name: "test".to_string(),
uid: 1005, passwd: "x".to_string(),
gid: 1005, uid: 1005,
gecos: "Test Account".to_string(), gid: 1005,
dir: "/home/test".to_string(), gecos: "Test Account".to_string(),
shell: "/bin/bash".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 { if uid == 1005 {
return Some(Passwd { return Response::Success(Passwd {
name: "test".to_string(), name: "test".to_string(),
passwd: "x".to_string(), passwd: "x".to_string(),
uid: 1005, uid: 1005,
...@@ -154,12 +157,12 @@ impl PasswdHooks for OidcPasswd { ...@@ -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" { if name == "test" {
return Some(Passwd { return Response::Success(Passwd {
name: "test".to_string(), name: "test".to_string(),
passwd: "x".to_string(), passwd: "x".to_string(),
uid: 1005, uid: 1005,
...@@ -170,7 +173,7 @@ impl PasswdHooks for OidcPasswd { ...@@ -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