I'm calling a cgi-script on an apache webserver. The script needs to create a textfile and write certain values into it.
When I do:
static const std::string outputFile( "/flash/myfile.ini" );
std::fstream fileStr( outputFile.c_str(), ( std::fstream::out | std::fstream::trunc ) );
if( !fileStr.is_open() )
throw std::runtime_error( "Failed to open config file." );
The runtime error is always thrown.
So I wish to run this cgi as root by doing this:
if( 0 != ::setreuid(0, -1) )
throw std::runtime_error( "Failed to set root user." );
But this also fails??
What is going wrong with setreuid??