From bc9e6678f6b917f67317a2987866bf1787a3e076 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 15 Aug 2011 17:06:31 +0000 Subject: Process now supports setuid for the child process. Really cool. --- src/process.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/process.cpp') diff --git a/src/process.cpp b/src/process.cpp index 8ea6ce3..b3f2801 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -61,6 +61,51 @@ Bu::Process::Process( Flags eFlags, const char *sName, const char *argv, ...) : delete[] list; } +Bu::Process::Process( Flags eFlags, const Bu::Process::Options &opt, const char *sName, char *const argv[] ) : + iStdIn( -1 ), + iStdOut( -1 ), + iStdErr( -1 ), + iPid( 0 ), + iProcStatus( 0 ), + bBlocking( true ), + bStdOutEos( true ), + bStdErrEos( true ), + opt( opt ) +{ + gexec( eFlags, sName, argv ); +} + +Bu::Process::Process( Flags eFlags, const Bu::Process::Options &opt, const char *sName, const char *argv, ...) : + iStdIn( -1 ), + iStdOut( -1 ), + iStdErr( -1 ), + iPid( 0 ), + iProcStatus( 0 ), + bBlocking( true ), + bStdOutEos( true ), + bStdErrEos( true ), + opt( opt ) +{ + int iCnt = 0; + va_list ap; + va_start( ap, argv ); + for(; va_arg( ap, const char *); iCnt++ ) { } + va_end( ap ); + + char const **list = new char const *[iCnt+2]; + va_start( ap, argv ); + list[0] = argv; + for( int j = 1; j <= iCnt; j++ ) + { + list[j] = va_arg( ap, const char *); + } + list[iCnt+1] = NULL; + va_end( ap ); + + gexec( eFlags, sName, (char *const *)list ); + delete[] list; +} + Bu::Process::~Process() { close(); @@ -109,6 +154,10 @@ void Bu::Process::gexec( Flags eFlags, const char *sName, char *const argv[] ) ::close( iaStdErr[0] ); dup2( iaStdErr[1], 2 ); } + if( (opt.eFlags&Options::SetUid) ) + { + setuid( opt.iUid ); + } execvp( sName, argv ); throw Bu::ExceptionBase("Hey, execvp failed!"); } -- cgit v1.2.3