]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
privs: refactor SCGetUser/GroupID to void functions
authorLukas Sismis <lsismis@oisf.net>
Fri, 8 Sep 2023 09:13:26 +0000 (11:13 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 2 Nov 2023 19:49:27 +0000 (20:49 +0100)
SCGetUserID/SCGetGroupID either FatalErrored out or
returned zero. As a result, the functions got refactored
into non-returning void functions.

src/suricata.c
src/util-privs.c
src/util-privs.h

index 30e6490826c7df17be52b239ea6fd133002f151e..7f979a7fbfcc8269fad754792f60fd17c643ccde 100644 (file)
@@ -2155,20 +2155,11 @@ static int InitRunAs(SCInstance *suri)
     }
     /* Get the suricata user ID to given user ID */
     if (suri->do_setuid == TRUE) {
-        if (SCGetUserID(suri->user_name, suri->group_name,
-                        &suri->userid, &suri->groupid) != 0) {
-            SCLogError("failed in getting user ID");
-            return TM_ECODE_FAILED;
-        }
-
+        SCGetUserID(suri->user_name, suri->group_name, &suri->userid, &suri->groupid);
         sc_set_caps = TRUE;
     /* Get the suricata group ID to given group ID */
     } else if (suri->do_setgid == TRUE) {
-        if (SCGetGroupID(suri->group_name, &suri->groupid) != 0) {
-            SCLogError("failed in getting group ID");
-            return TM_ECODE_FAILED;
-        }
-
+        SCGetGroupID(suri->group_name, &suri->groupid);
         sc_set_caps = TRUE;
     }
 #endif
index b08516b650e06dfe480fffd9dac999bc388d334c..8210cc8065d9cc47daefdca4b345fe9df9b5f571 100644 (file)
@@ -145,9 +145,9 @@ void SCDropCaps(ThreadVars *tv)
  * \param   uid         pointer to the user id in which result will be stored
  * \param   gid         pointer to the group id in which result will be stored
  *
- * \retval  upon success it return 0
+ * \retval  FatalError on a failure
  */
-int SCGetUserID(const char *user_name, const char *group_name, uint32_t *uid, uint32_t *gid)
+void SCGetUserID(const char *user_name, const char *group_name, uint32_t *uid, uint32_t *gid)
 {
     uint32_t userid = 0;
     uint32_t groupid = 0;
@@ -204,8 +204,6 @@ int SCGetUserID(const char *user_name, const char *group_name, uint32_t *uid, ui
 
     *uid = userid;
     *gid = groupid;
-
-    return 0;
 }
 
 /**
@@ -214,9 +212,9 @@ int SCGetUserID(const char *user_name, const char *group_name, uint32_t *uid, ui
  * \param   group_name  pointer to the given group name
  * \param   gid         pointer to the group id in which result will be stored
  *
- * \retval  upon success it return 0
+ * \retval  FatalError on a failure
  */
-int SCGetGroupID(const char *group_name, uint32_t *gid)
+void SCGetGroupID(const char *group_name, uint32_t *gid)
 {
     uint32_t grpid = 0;
     struct group *gp;
@@ -244,8 +242,6 @@ int SCGetGroupID(const char *group_name, uint32_t *gid)
     endgrent();
 
     *gid = grpid;
-
-    return 0;
 }
 
 #ifdef __OpenBSD__
index 64518814c5d2cc4c9a575a64eb90f215c411391a..454533963d346490b63fc3bce5638bf065ff1e94 100644 (file)
@@ -90,8 +90,8 @@ void SCDropMainThreadCaps(uint32_t , uint32_t );
 #define SCDropMainThreadCaps(...)
 #endif /* HAVE_LIBCAP_NG */
 
-int SCGetUserID(const char *, const char *, uint32_t *, uint32_t *);
-int SCGetGroupID(const char *, uint32_t *);
+void SCGetUserID(const char *, const char *, uint32_t *, uint32_t *);
+void SCGetGroupID(const char *, uint32_t *);
 
 #ifdef __OpenBSD__
 int SCPledge(void);