Browse Source

addressed review comments:
- unified exception throwing for unknown/invalid user names
- wording in comment description

also made some cleanups: removing an unused temp variable, making sure endpwent() is called.


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac268@2571 e5f2f494-b856-4b98-b285-d166d9295462

JINMEI Tatuya 14 years ago
parent
commit
604ecc17cd
2 changed files with 6 additions and 5 deletions
  1. 4 3
      src/bin/auth/change_user.cc
  2. 2 2
      src/bin/auth/change_user.h

+ 4 - 3
src/bin/auth/change_user.cc

@@ -32,12 +32,13 @@ changeUser(const char* const username) {
     const struct passwd *runas_pw = NULL;
 
     runas_pw = getpwnam(username);
+    endpwent();
     if (runas_pw == NULL) {
         try {
             runas_pw = getpwuid(lexical_cast<uid_t>(username));
-        } catch (const bad_lexical_cast& err) {
-            isc_throw(FatalError,
-                      "Failed to parse user name or UID:" << username);
+            endpwent();
+        } catch (const bad_lexical_cast&) {
+            ;                   // fall through to isc_throw below.
         }
     }
     if (runas_pw == NULL) {

+ 2 - 2
src/bin/auth/change_user.h

@@ -19,8 +19,8 @@
 
 /// \brief Change the run time user.
 ///
-/// This function changes the effective user of the authoritative server
-/// process.
+/// This function changes the user of the authoritative server process.
+///
 /// \c username can be either a textual user name or its numeric ID.
 /// If the specified user name (or ID) doesn't specify a local user ID
 /// or the user originally starting the process doesn't have a permission