*/
#include <unistd.h>
#include <errno.h>
+#include <stdio.h>
#define TARGET "/path/to/exec" /* replace with actual target ###EXEC_TARGET:*/
+/* #define REDIRECT_STDIN [path] ###EXEC_REDIRECT_STDIN: */
+/* #define REDIRECT_STDOUT [path] ###EXEC_REDIRECT_STDOUT: */
+/* #define REDIRECT_STDERR [path] ###EXEC_REDIRECT_STDERR: */
+/* #define BINMODE ###EXEC_BINMODE: */
+
+#ifdef BINMODE
+ #define IN_MODE "rb"
+ #define OUT_MODE "ab"
+#else
+ #define IN_MODE "rt"
+ #define OUT_MODE "at"
+#endif
int main(int argc, char *argv[], char *envp[])
{
uid_t euid;
gid_t egid;
int r;
+#if defined REDIRECT_STDIN || defined REDIRECT_STDOUT || defined REDIRECT_STDERR
+ FILE *f;
+#endif
euid = geteuid();
egid = getegid();
+
+#ifdef REDIRECT_STDIN
+ f = freopen(REDIRECT_STDIN, IN_MODE, stdin);
+ if (f == NULL)
+ return (r = errno);
+#endif
+
+#ifdef REDIRECT_STDOUT
+ f = freopen(REDIRECT_STDOUT, OUT_MODE, stdout);
+ if (f == NULL)
+ return (r = errno);
+#endif
+
+#ifdef REDIRECT_STDERR
+ f = freopen(REDIRECT_STDERR, OUT_MODE, stderr);
+ if (f == NULL)
+ return (r = errno);
+#endif
+
if ((r = setreuid(euid, euid)))
return (r = errno);
if ((r = setregid(egid, egid)))
_TARGET = @_PATH($path, $target)
EXEC_TARGET = @_C_DEFINE_STR(TARGET, $_TARGET)
+
+if $stdin
+_REDIRECT_STDIN = @_PATH($io_path, $stdin)
+EXEC_REDIRECT_STDIN = @_C_DEFINE_STR(REDIRECT_STDIN, $_REDIRECT_STDIN )
+else
+EXEC_REDIRECT_STDIN: /* EXEC_REDIRECT_STDIN */
+endif
+
+if $stdout
+_REDIRECT_STDOUT = @_PATH($io_path, $stdout)
+EXEC_REDIRECT_STDOUT = @_C_DEFINE_STR(REDIRECT_STDOUT, $_REDIRECT_STDOUT)
+else
+EXEC_REDIRECT_STDOUT: /* EXEC_REDIRECT_STDOUT */
+endif
+
+if $stderr
+_REDIRECT_STDERR = @_PATH($io_path, $stderr)
+EXEC_REDIRECT_STDERR = @_C_DEFINE_STR(REDIRECT_STDERR, $_REDIRECT_STDERR)
+else
+EXEC_REDIRECT_STDERR: /* EXEC_REDIRECT_STDERR */
+endif
+
+if $binmode
+EXEC_BINMODE: @_C_DEFINE_STR(BINMODE, $binmode)
+else
+EXEC_BINMODE: /* EXEC_BINMODE */
+endif