Set group before user.

This commit is contained in:
Gunnar Beutner 2013-09-15 10:32:55 +02:00
parent 12ebf48b0e
commit aba260e695
1 changed files with 19 additions and 19 deletions

View File

@ -249,25 +249,6 @@ int main(int argc, char **argv)
po::notify(g_AppParams);
#ifndef _WIN32
if (g_AppParams.count("user")) {
String user = g_AppParams["user"].as<String>();
errno = 0;
struct passwd *pw = getpwnam(user.CStr());
if (!pw) {
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("getpwnam")
<< boost::errinfo_errno(errno));
}
if (setuid(pw->pw_uid) < 0) {
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("setuid")
<< boost::errinfo_errno(errno));
}
}
if (g_AppParams.count("group")) {
String group = g_AppParams["group"].as<String>();
@ -286,6 +267,25 @@ int main(int argc, char **argv)
<< boost::errinfo_errno(errno));
}
}
if (g_AppParams.count("user")) {
String user = g_AppParams["user"].as<String>();
errno = 0;
struct passwd *pw = getpwnam(user.CStr());
if (!pw) {
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("getpwnam")
<< boost::errinfo_errno(errno));
}
if (setuid(pw->pw_uid) < 0) {
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("setuid")
<< boost::errinfo_errno(errno));
}
}
#endif /* _WIN32 */
if (g_AppParams.count("debug"))