]> granicus.if.org Git - icinga2/commitdiff
Set group before user.
authorGunnar Beutner <gunnar.beutner@netways.de>
Sun, 15 Sep 2013 08:32:55 +0000 (10:32 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sun, 15 Sep 2013 08:32:55 +0000 (10:32 +0200)
icinga-app/icinga.cpp

index 734a19d9315f5a453999cdee0a50d40370e79121..90efd84d3f72af4cf5a0a72b20b72a39d08140a6 100644 (file)
@@ -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<String>();
+       if (g_AppParams.count("group")) {
+               String group = g_AppParams["group"].as<String>();
 
                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<String>();
+       if (g_AppParams.count("user")) {
+               String user = g_AppParams["user"].as<String>();
 
                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));
                }
        }