@@ -43,7 +43,8 @@ int main (int argc, const char * argv[])
4343 std::map<std::string, std::string> config;
4444 std::fstream cfile;
4545 std::string line, key, val;
46- int epos;
46+ int epos = 0 ;
47+ int drop_uid = 0 , drop_gid = 0 ;
4748 cfile.open (" server.config" );
4849 if (!cfile.is_open ()) {
4950 std::cout << " Unable to open server.config file in working directory" << std::endl;
@@ -83,6 +84,17 @@ int main (int argc, const char * argv[])
8384 vhost_alias_str.erase (0 , pos + delimiter.length ());
8485 } while (pos != std::string::npos);
8586
87+ // Check for optional drop_uid, drop_gid. Ensure both are set
88+ if (config.find (" drop_uid" ) != config.end () && config.find (" drop_gid" ) != config.end ()) {
89+ drop_uid = atoi (config[" drop_uid" ].c_str ());
90+ drop_gid = atoi (config[" drop_gid" ].c_str ());
91+
92+ if (drop_uid == 0 || drop_gid == 0 ) {
93+ // Both must be set, otherwise set back to 0 so we dont use
94+ drop_uid = drop_gid = 0 ;
95+ }
96+ }
97+
8698 // Ignore SIGPIPE "Broken pipe" signals when socket connections are broken.
8799 signal (SIGPIPE, handleSigPipe);
88100
@@ -92,7 +104,7 @@ int main (int argc, const char * argv[])
92104 signal (SIGTERM, &handleTermSig);
93105
94106 // Instance and start the server
95- svr = new HTTPServer (vhosts, atoi (config[" port" ].c_str ()), config[" diskpath" ]);
107+ svr = new HTTPServer (vhosts, atoi (config[" port" ].c_str ()), config[" diskpath" ], drop_uid, drop_gid );
96108 if (!svr->start ()) {
97109 svr->stop ();
98110 delete svr;
0 commit comments