]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
Add nss getpwuid to the himmelblau daemon
authorDavid Mulder <dmulder@samba.org>
Wed, 31 Jul 2024 16:36:56 +0000 (10:36 -0600)
committerDavid Mulder <dmulder@samba.org>
Wed, 23 Oct 2024 14:21:33 +0000 (14:21 +0000)
Signed-off-by: David Mulder <dmulder@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
himmelblaud/src/himmelblaud.rs
himmelblaud/src/himmelblaud/himmelblaud_getpwuid.rs [new file with mode: 0644]

index 5e2f2ee6221256f75ecb428a87a07ba1b3ac3e51..8904f27db7b7040f1480ba843753bd941c5999f6 100644 (file)
@@ -214,6 +214,7 @@ pub(crate) async fn handle_client(
             Request::NssAccountByName(account_id) => {
                 resolver.getpwnam(&account_id).await?
             }
+            Request::NssAccountByUid(uid) => resolver.getpwuid(uid).await?,
             _ => todo!(),
         };
         reqs.send(resp).await?;
@@ -227,4 +228,5 @@ pub(crate) async fn handle_client(
 
 mod himmelblaud_getpwent;
 mod himmelblaud_getpwnam;
+mod himmelblaud_getpwuid;
 mod himmelblaud_pam_auth;
diff --git a/himmelblaud/src/himmelblaud/himmelblaud_getpwuid.rs b/himmelblaud/src/himmelblaud/himmelblaud_getpwuid.rs
new file mode 100644 (file)
index 0000000..b43948d
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+   Unix SMB/CIFS implementation.
+
+   Himmelblau daemon implementation for nss getpwuid
+
+   Copyright (C) David Mulder 2024
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+use crate::himmelblaud::Resolver;
+use libc::uid_t;
+use ntstatus_gen::NTSTATUS;
+use sock::Response;
+
+impl Resolver {
+    pub(crate) async fn getpwuid(
+        &mut self,
+        uid: uid_t,
+    ) -> Result<Response, Box<NTSTATUS>> {
+        if let Some(upn) = self.uid_cache.fetch(uid) {
+            if let Some(entry) = self.user_cache.fetch(&upn) {
+                Ok(Response::NssAccount(Some(
+                    self.create_passwd_from_upn(&entry.upn, &entry.name)?,
+                )))
+            } else {
+                Ok(Response::NssAccount(Some(
+                    self.create_passwd_from_upn(&upn, "")?,
+                )))
+            }
+        } else {
+            Ok(Response::NssAccount(None))
+        }
+    }
+}