]> granicus.if.org Git - icinga2/commitdiff
Make getpwnam/getgrnam error messages more user-friendly.
authorGunnar Beutner <gunnar.beutner@netways.de>
Thu, 10 Oct 2013 09:28:07 +0000 (11:28 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Thu, 10 Oct 2013 09:28:07 +0000 (11:28 +0200)
icinga-app/icinga.cpp

index d4265b7ba04da24b23000aa4792714d18e77db5d..1cd6e03bbd90ffa31dee2ed5966f32271614835b 100644 (file)
@@ -243,9 +243,13 @@ int main(int argc, char **argv)
                struct group *gr = getgrnam(group.CStr());
 
                if (!gr) {
-                       BOOST_THROW_EXCEPTION(posix_error()
-                               << boost::errinfo_api_function("getgrnam")
-                               << boost::errinfo_errno(errno));
+                       if (errno == 0) {
+                               BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid group specified: " + group));
+                       } else {
+                               BOOST_THROW_EXCEPTION(posix_error()
+                                       << boost::errinfo_api_function("getgrnam")
+                                       << boost::errinfo_errno(errno));
+                       }
                }
 
                if (setgid(gr->gr_gid) < 0) {
@@ -262,9 +266,13 @@ int main(int argc, char **argv)
                struct passwd *pw = getpwnam(user.CStr());
 
                if (!pw) {
-                       BOOST_THROW_EXCEPTION(posix_error()
-                               << boost::errinfo_api_function("getpwnam")
-                               << boost::errinfo_errno(errno));
+                       if (errno == 0) {
+                               BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid user specified: " + user));
+                       } else {
+                               BOOST_THROW_EXCEPTION(posix_error()
+                                       << boost::errinfo_api_function("getpwnam")
+                                       << boost::errinfo_errno(errno));
+                       }
                }
 
                if (setuid(pw->pw_uid) < 0) {