16 #include <sys/types.h>
23 #include "lirc/lirc_log.h"
32 GETGROUPS_T groups[32];
33 int group_cnt =
sizeof(groups)/
sizeof(gid_t);
34 char groupnames[256] = {0};
41 user = getenv(
"SUDO_USER");
49 r = getgrouplist(user, pw->pw_gid, groups, &group_cnt);
54 r = setgroups(group_cnt, groups);
59 r = setgid(pw->pw_gid);
64 r = set_some_uid(pw->pw_uid);
69 setenv(
"HOME", pw->pw_dir, 1);
71 for (i = 0; i < group_cnt; i += 1) {
72 snprintf(buff, 5,
" %d", groups[i]);
73 strcat(groupnames, buff);
75 log_debug(
"Groups: [%d]:%s", pw->pw_gid, groupnames);
86 if (strcmp(
"root", new_user) == 0)
87 puts(
"Warning: Running as root.");
88 else if (strlen(new_user) == 0)
89 puts(
"Warning: Cannot change uid.");
91 printf(
"Running as regular user %s\n", new_user);
#define log_debug(fmt,...)
Log a debug message.
logchannel_t
Log channels used to filter messages.
#define log_perror_err(fmt,...)
perror wrapper logging with level LIRC_ERROR.
void drop_root_cli(int(*set_some_uid)(uid_t))
Default view part of drop_sudo_root.
const char * drop_sudo_root(int(*set_some_uid)(uid_t))
Try to drop possible root privileges, returning new user or "" on error.
#define log_perror_warn(fmt,...)
perror wrapper logging with level LIRC_WARNING.
#define log_notice(fmt,...)
Log a notice message.