Skip to content

Commit 5300cb6

Browse files
Lukas Sismisvictorjulien
authored andcommitted
privs: refactor SCGetUser/GroupID to void functions
SCGetUserID/SCGetGroupID either FatalErrored out or returned zero. As a result, the functions got refactored into non-returning void functions.
1 parent 5b4ba0f commit 5300cb6

File tree

3 files changed

+8
-21
lines changed

3 files changed

+8
-21
lines changed

src/suricata.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,20 +2155,11 @@ static int InitRunAs(SCInstance *suri)
21552155
}
21562156
/* Get the suricata user ID to given user ID */
21572157
if (suri->do_setuid == TRUE) {
2158-
if (SCGetUserID(suri->user_name, suri->group_name,
2159-
&suri->userid, &suri->groupid) != 0) {
2160-
SCLogError("failed in getting user ID");
2161-
return TM_ECODE_FAILED;
2162-
}
2163-
2158+
SCGetUserID(suri->user_name, suri->group_name, &suri->userid, &suri->groupid);
21642159
sc_set_caps = TRUE;
21652160
/* Get the suricata group ID to given group ID */
21662161
} else if (suri->do_setgid == TRUE) {
2167-
if (SCGetGroupID(suri->group_name, &suri->groupid) != 0) {
2168-
SCLogError("failed in getting group ID");
2169-
return TM_ECODE_FAILED;
2170-
}
2171-
2162+
SCGetGroupID(suri->group_name, &suri->groupid);
21722163
sc_set_caps = TRUE;
21732164
}
21742165
#endif

src/util-privs.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ void SCDropCaps(ThreadVars *tv)
145145
* \param uid pointer to the user id in which result will be stored
146146
* \param gid pointer to the group id in which result will be stored
147147
*
148-
* \retval upon success it return 0
148+
* \retval FatalError on a failure
149149
*/
150-
int SCGetUserID(const char *user_name, const char *group_name, uint32_t *uid, uint32_t *gid)
150+
void SCGetUserID(const char *user_name, const char *group_name, uint32_t *uid, uint32_t *gid)
151151
{
152152
uint32_t userid = 0;
153153
uint32_t groupid = 0;
@@ -204,8 +204,6 @@ int SCGetUserID(const char *user_name, const char *group_name, uint32_t *uid, ui
204204

205205
*uid = userid;
206206
*gid = groupid;
207-
208-
return 0;
209207
}
210208

211209
/**
@@ -214,9 +212,9 @@ int SCGetUserID(const char *user_name, const char *group_name, uint32_t *uid, ui
214212
* \param group_name pointer to the given group name
215213
* \param gid pointer to the group id in which result will be stored
216214
*
217-
* \retval upon success it return 0
215+
* \retval FatalError on a failure
218216
*/
219-
int SCGetGroupID(const char *group_name, uint32_t *gid)
217+
void SCGetGroupID(const char *group_name, uint32_t *gid)
220218
{
221219
uint32_t grpid = 0;
222220
struct group *gp;
@@ -244,8 +242,6 @@ int SCGetGroupID(const char *group_name, uint32_t *gid)
244242
endgrent();
245243

246244
*gid = grpid;
247-
248-
return 0;
249245
}
250246

251247
#ifdef __OpenBSD__

src/util-privs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ void SCDropMainThreadCaps(uint32_t , uint32_t );
9090
#define SCDropMainThreadCaps(...)
9191
#endif /* HAVE_LIBCAP_NG */
9292

93-
int SCGetUserID(const char *, const char *, uint32_t *, uint32_t *);
94-
int SCGetGroupID(const char *, uint32_t *);
93+
void SCGetUserID(const char *, const char *, uint32_t *, uint32_t *);
94+
void SCGetGroupID(const char *, uint32_t *);
9595

9696
#ifdef __OpenBSD__
9797
int SCPledge(void);

0 commit comments

Comments
 (0)