aboutsummaryrefslogtreecommitdiff
path: root/src/user_init/user_init.c
blob: 8e006ea90ad184a1cd790959a0a6da148766b513 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
#include <unistd.h>
#include <stdlib.h>

#include "helpers.h"
#include "rc.h"

#define USERINIT RC_LIBEXECDIR "/sh/user-init.sh"

int main(int argc, char **argv) {
	struct passwd *user;
	char *cmd;
	if (argc < 3)
		return 1;

	user = getpwnam(argv[1]);
	if (!user || initgroups(user->pw_name, user->pw_gid) == -1
			|| setgid(user->pw_gid) == -1
			|| setuid(user->pw_uid) == -1)
		return 1;

	xasprintf(&cmd, "%s %s", USERINIT, argv[2]);
	execl(user->pw_shell, user->pw_shell, "-c", cmd, NULL);
}