]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Code clean-up - bora-vmsoft/lib/procMgr/procMgrPosix.c
authorOliver Kurth <okurth@vmware.com>
Wed, 16 Jan 2019 22:53:03 +0000 (14:53 -0800)
committerOliver Kurth <okurth@vmware.com>
Wed, 16 Jan 2019 22:53:03 +0000 (14:53 -0800)
Recent discussions about setting "errno" to ENOENT when either
getpwuid_r() or getpwnam_r() return 0 (success) if there is no passwd
entry for the user have vacillated.

Since none of the current callers of the routines in procMgrPosix.c
query the contents of "errno", the current consensus is to simply log
a warning message along with reason for the failure.

open-vm-tools/lib/procMgr/procMgrPosix.c

index d07b5d3ffea7cc8580d3013eeb268748a130d1d4..267933e334c5429cbfe7e2168f173341f9e3fb38 100644 (file)
@@ -2205,9 +2205,8 @@ ProcMgr_ImpersonateUserStart(const char *user,  // IN: UTF-8 encoded user name
        * set the return pointer (ppw) if there's no entry for the user,
        * according to POSIX 1003.1-2003, so patch up the errno.
        */
-      if (error == 0) {
-         errno = ENOENT;
-      }
+      Warning("Failed to lookup user with uid: %" FMTUID ". Reason: %s\n", 0,
+              error == 0 ? "entry not found" : Err_Errno2String(error));
       return FALSE;
    }
 
@@ -2220,17 +2219,16 @@ ProcMgr_ImpersonateUserStart(const char *user,  // IN: UTF-8 encoded user name
        return FALSE;
    }
 
-   error = getpwnam_r(userLocal, &pw, buffer, sizeof buffer, &ppw);
-
-   free(userLocal);
-
-   if (error != 0 || !ppw) {
-      if (error == 0) {
-         error = ENOENT;
-      }
+   if ((error = getpwnam_r(userLocal, &pw, buffer, sizeof buffer, &ppw)) != 0 ||
+       !ppw) {
+      Warning("Failed to lookup user name %s. Reason: %s\n", userLocal,
+              error == 0 ? "entry not found" : Err_Errno2String(error));
+      free(userLocal);
       return FALSE;
    }
 
+   free(userLocal);
+
    // first change group
 #if defined(USERWORLD)
    ret = Id_SetREGid(ppw->pw_gid, ppw->pw_gid);
@@ -2306,9 +2304,8 @@ ProcMgr_ImpersonateUserStop(void)
 
    if ((error = getpwuid_r(0, &pw, buffer, sizeof buffer, &ppw)) != 0 ||
        !ppw) {
-      if (error == 0) {
-         error = ENOENT;
-      }
+      Warning("Failed to lookup user with uid: %" FMTUID ". Reason: %s\n", 0,
+              error == 0 ? "entry not found" : Err_Errno2String(error));
       return FALSE;
    }
 
@@ -2432,9 +2429,8 @@ ProcMgr_GetImpersonatedUserInfo(char **userName,            // OUT
        * set the return pointer (ppw) if there's no entry for the user,
        * according to POSIX 1003.1-2003, so patch up the errno.
        */
-      if (error == 0) {
-         error = ENOENT;
-      }
+      Warning("Failed to lookup user with uid: %" FMTUID ". Reason: %s\n", uid,
+              error == 0 ? "entry not found" : Err_Errno2String(error));
       return FALSE;
    }