]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
Add nss getgrgid to the himmelblau daemon
authorDavid Mulder <dmulder@samba.org>
Wed, 31 Jul 2024 20:27:05 +0000 (14:27 -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_getgrgid.rs [new file with mode: 0644]

index 9f6167bb7d047564cc3a094ae6473841f0d12e3e..6af19e2b901ed64055adaf8a6f33cb5b4ee81a35 100644 (file)
@@ -219,6 +219,7 @@ pub(crate) async fn handle_client(
             Request::NssGroupByName(grp_id) => {
                 resolver.getgrnam(&grp_id).await?
             }
+            Request::NssGroupByGid(gid) => resolver.getgrgid(gid).await?,
             _ => todo!(),
         };
         reqs.send(resp).await?;
@@ -231,6 +232,7 @@ pub(crate) async fn handle_client(
 }
 
 mod himmelblaud_getgrent;
+mod himmelblaud_getgrgid;
 mod himmelblaud_getgrnam;
 mod himmelblaud_getpwent;
 mod himmelblaud_getpwnam;
diff --git a/himmelblaud/src/himmelblaud/himmelblaud_getgrgid.rs b/himmelblaud/src/himmelblaud/himmelblaud_getgrgid.rs
new file mode 100644 (file)
index 0000000..9ddf408
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+   Unix SMB/CIFS implementation.
+
+   Himmelblau daemon implementation for nss getgrgid
+
+   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::gid_t;
+use ntstatus_gen::NTSTATUS;
+use sock::{Group, Response};
+
+impl Resolver {
+    pub(crate) async fn getgrgid(
+        &mut self,
+        gid: gid_t,
+    ) -> Result<Response, Box<NTSTATUS>> {
+        if let Some(uuid) = self.uid_cache.fetch(gid) {
+            if let Some(entry) = self.group_cache.fetch(&uuid) {
+                return Ok(Response::NssGroup(Some(Group {
+                    name: entry.uuid.clone(),
+                    passwd: "x".to_string(),
+                    gid,
+                    members: entry.members(),
+                })));
+            }
+        }
+        Ok(Response::NssGroup(None))
+    }
+}