diff options
Diffstat (limited to 'src/user_init/user_init.c')
-rw-r--r-- | src/user_init/user_init.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/user_init/user_init.c b/src/user_init/user_init.c new file mode 100644 index 00000000..1f79ec90 --- /dev/null +++ b/src/user_init/user_init.c @@ -0,0 +1,23 @@ +#include <sys/types.h> +#include <pwd.h> +#include <grp.h> +#include <unistd.h> +#include <stdlib.h> + +#include "rc.h" + +#define USERINIT RC_LIBEXECDIR "/sh/user-init.sh" + +int main(int argc, char **argv) { + struct passwd *user; + 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; + + execl(user->pw_shell, "-", "-c", USERINIT, argv[2], NULL); +} |