1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

drop_privs: ignore if uid or gid is zero

0 is the natural default for the info struct.

If you are not 0 (root) then you can't change to root, it will fail
without having done anything.  What the user probably wanted is
just leave it as the uid/gid it was started as.

If you are 0 (root) you are already at 0 and the change has no
meaning.

Net effect is get rid of two warning logs if you left it at 0 in
the info struct and start as non-root.
This commit is contained in:
Andy Green 2017-09-18 12:44:33 +08:00
parent 69e4433f4e
commit 217dfe7c6b

View file

@ -315,11 +315,11 @@ lws_plat_drop_app_privileges(struct lws_context_creation_info *info)
int n;
#endif
if (info->gid != -1)
if (info->gid && info->gid != -1)
if (setgid(info->gid))
lwsl_warn("setgid: %s\n", strerror(LWS_ERRNO));
if (info->uid != -1) {
if (info->uid && info->uid != -1) {
struct passwd *p = getpwuid(info->uid);
if (p) {