From 5183c9222674e66c7b095b0b9a1e3c01c919b1b4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20K=C3=A1cha?= <ph@cesnet.cz>
Date: Fri, 26 Apr 2024 11:38:02 +0200
Subject: [PATCH] LaBrea: add symbolic uid/gid

---
 hp-labrea/labrea-idea.py | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/hp-labrea/labrea-idea.py b/hp-labrea/labrea-idea.py
index 9b34707..2e030f9 100755
--- a/hp-labrea/labrea-idea.py
+++ b/hp-labrea/labrea-idea.py
@@ -399,6 +399,17 @@ class Filer(object):
         os.rename(pth.join(self.tmp, short_name), pth.join(self.incoming, short_name))
 
 
+def get_uid_gid(str_id, get_nam_func):
+    if str_id:
+        try:
+            id = int(str_id)
+        except ValueError:
+            id = get_nam_func(str_id)[2]
+    else:
+        id = None
+    return id
+
+
 def daemonize(
         work_dir=None, chroot_dir=None,
         umask=None, uid=None, gid=None,
@@ -411,8 +422,10 @@ def daemonize(
         os.umask(umask)
     if work_dir is not None:
         os.chdir(work_dir)
+    gid = get_uid_gid(gid, getgrnam)
     if gid is not None:
         os.setgid(gid)
+    uid = get_uid_gid(uid, getpwnam)
     if uid is not None:
         os.setuid(uid)
     # Doublefork, split session
@@ -572,14 +585,14 @@ def get_args():
         "-u", "--uid",
         default=None,
         dest="uid",
-        type="int",
+        type="string",
         action="store",
         help="user id to run under")
     optp.add_option(
         "-g", "--gid",
         default=None,
         dest="gid",
-        type="int",
+        type="string",
         action="store",
         help="group id to run under")
     optp.add_option(
-- 
GitLab