From: Oliver Kurth Date: Wed, 16 Jan 2019 22:53:03 +0000 (-0800) Subject: Code clean-up - bora-vmsoft/lib/procMgr/procMgrPosix.c X-Git-Tag: stable-11.0.0~263 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff766a3e0dae726cf1d171a150633d9e995f2c08;p=thirdparty%2Fopen-vm-tools.git Code clean-up - bora-vmsoft/lib/procMgr/procMgrPosix.c 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. --- diff --git a/open-vm-tools/lib/procMgr/procMgrPosix.c b/open-vm-tools/lib/procMgr/procMgrPosix.c index d07b5d3ff..267933e33 100644 --- a/open-vm-tools/lib/procMgr/procMgrPosix.c +++ b/open-vm-tools/lib/procMgr/procMgrPosix.c @@ -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; }