Skip to content

Commit

Permalink
privs: refactor SCGetUser/GroupID to void functions
Browse files Browse the repository at this point in the history
SCGetUserID/SCGetGroupID either FatalErrored out or
returned zero. As a result, the functions got refactored
into non-returning void functions.
  • Loading branch information
Lukas Sismis authored and victorjulien committed Nov 2, 2023
1 parent 5b4ba0f commit 5300cb6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
13 changes: 2 additions & 11 deletions src/suricata.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions src/util-privs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -204,8 +204,6 @@ int SCGetUserID(const char *user_name, const char *group_name, uint32_t *uid, ui

*uid = userid;
*gid = groupid;

return 0;
}

/**
Expand All @@ -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;
Expand Down Expand Up @@ -244,8 +242,6 @@ int SCGetGroupID(const char *group_name, uint32_t *gid)
endgrent();

*gid = grpid;

return 0;
}

#ifdef __OpenBSD__
Expand Down
4 changes: 2 additions & 2 deletions src/util-privs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5300cb6

Please sign in to comment.