From aba260e695423dd2133b14340504fdf398711127 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sun, 15 Sep 2013 10:32:55 +0200 Subject: [PATCH] Set group before user. --- icinga-app/icinga.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 734a19d93..90efd84d3 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -249,40 +249,40 @@ int main(int argc, char **argv) po::notify(g_AppParams); #ifndef _WIN32 - if (g_AppParams.count("user")) { - String user = g_AppParams["user"].as(); + if (g_AppParams.count("group")) { + String group = g_AppParams["group"].as(); errno = 0; - struct passwd *pw = getpwnam(user.CStr()); + struct group *gr = getgrnam(group.CStr()); - if (!pw) { + if (!gr) { BOOST_THROW_EXCEPTION(posix_error() << boost::errinfo_api_function("getpwnam") << boost::errinfo_errno(errno)); } - if (setuid(pw->pw_uid) < 0) { + if (setgid(gr->gr_gid) < 0) { BOOST_THROW_EXCEPTION(posix_error() - << boost::errinfo_api_function("setuid") + << boost::errinfo_api_function("setgid") << boost::errinfo_errno(errno)); } } - if (g_AppParams.count("group")) { - String group = g_AppParams["group"].as(); + if (g_AppParams.count("user")) { + String user = g_AppParams["user"].as(); errno = 0; - struct group *gr = getgrnam(group.CStr()); + struct passwd *pw = getpwnam(user.CStr()); - if (!gr) { + if (!pw) { BOOST_THROW_EXCEPTION(posix_error() << boost::errinfo_api_function("getpwnam") << boost::errinfo_errno(errno)); } - if (setgid(gr->gr_gid) < 0) { + if (setuid(pw->pw_uid) < 0) { BOOST_THROW_EXCEPTION(posix_error() - << boost::errinfo_api_function("setgid") + << boost::errinfo_api_function("setuid") << boost::errinfo_errno(errno)); } } -- 2.40.0