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

use initgroups in plat unix

Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
Andy Green 2015-03-04 16:16:41 +08:00
parent 418a49b9e8
commit 3a9f79e693

View file

@ -1,5 +1,8 @@
#include "private-libwebsockets.h"
#include <pwd.h>
#include <grp.h>
/*
* included from libwebsockets.c for unix builds
*/
@ -250,12 +253,22 @@ lws_plat_set_socket_options(struct libwebsocket_context *context, int fd)
LWS_VISIBLE void
lws_plat_drop_app_privileges(struct lws_context_creation_info *info)
{
if (info->uid != -1) {
struct passwd *p = getpwuid(info->uid);
if (p) {
initgroups(p->pw_name, info->gid);
if (setuid(info->uid))
lwsl_warn("setuid: %s\n", strerror(LWS_ERRNO));
else
lwsl_notice(" Set privs to user '%s'\n", p->pw_name);
} else
lwsl_warn("getpwuid: unable to find uid %d", info->uid);
}
if (info->gid != -1)
if (setgid(info->gid))
lwsl_warn("setgid: %s\n", strerror(LWS_ERRNO));
if (info->uid != -1)
if (setuid(info->uid))
lwsl_warn("setuid: %s\n", strerror(LWS_ERRNO));
}
LWS_VISIBLE int