File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -44,6 +44,8 @@ struct exec_args exec_init(const char **argv)
4444 args .redirect_stdin = EXEC_NO_REDIRECT ;
4545 args .redirect_stdout = EXEC_NO_REDIRECT ;
4646 args .redirect_stderr = EXEC_NO_REDIRECT ;
47+ args .uid = (uid_t )- 1 ;
48+ args .gid = (gid_t )- 1 ;
4749 return args ;
4850}
4951
@@ -100,6 +102,10 @@ struct exec_result do_exec(struct exec_args *args)
100102 if (args -> redirect_stderr != EXEC_NO_REDIRECT &&
101103 dup2 (args -> redirect_stderr , STDERR_FILENO ) < 0 )
102104 goto child_err ;
105+ if (args -> gid != (gid_t )- 1 && setgid (args -> gid ) < 0 )
106+ goto child_err ;
107+ if (args -> uid != (uid_t )- 1 && setuid (args -> uid ) < 0 )
108+ goto child_err ;
103109 if (args -> setsid && setsid () < 0 )
104110 goto child_err ;
105111 sigprocmask (SIG_SETMASK , & old , NULL );
Original file line number Diff line number Diff line change @@ -36,6 +36,8 @@ struct exec_args {
3636 int redirect_stdin ;
3737 int redirect_stdout ;
3838 int redirect_stderr ;
39+ uid_t uid ;
40+ gid_t gid ;
3941 bool setsid : 1 ;
4042};
4143
You can’t perform that action at this time.
0 commit comments