diff options
Diffstat (limited to 'lib/Plugins/CCpp.cpp')
-rw-r--r-- | lib/Plugins/CCpp.cpp | 31 |
1 files changed, 8 insertions, 23 deletions
diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 7d302c7..f729326 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -361,23 +361,7 @@ void CAnalyzerCCpp::GetIndependentBuildIdPC(const std::string& pBuildIdPC, std:: } } -gid_t CAnalyzerCCpp::GetGIDFromUID(const std::string& pUID) -{ - struct passwd* pw; - - while (( pw = getpwent()) != NULL) - { - if (pw->pw_uid == atoi(pUID.c_str())) - { - setpwent(); - return pw->pw_gid; - } - } - setpwent(); - return -1; -} - -void CAnalyzerCCpp::ExecVP(const char* pCommand, char* const pArgs[], const std::string& pUID, std::string& pOutput) +void CAnalyzerCCpp::ExecVP(const char* pCommand, char* const pArgs[], uid_t uid, std::string& pOutput) { int pipeout[2]; char buff[1024]; @@ -385,9 +369,10 @@ void CAnalyzerCCpp::ExecVP(const char* pCommand, char* const pArgs[], const std: pid_t child; gid_t GID[1]; - if ((GID[0] = GetGIDFromUID(pUID)) == -1) + struct passwd* pw = getpwuid(uid); + if (!pw) { - throw CABRTException(EXCEP_PLUGIN, "CAnalyzerCCpp::ExecVP(): cannot get GUI for UID."); + throw CABRTException(EXCEP_PLUGIN, "CAnalyzerCCpp::ExecVP(): cannot get GID for UID."); } pipe(pipeout); /* error check? */ @@ -415,9 +400,9 @@ void CAnalyzerCCpp::ExecVP(const char* pCommand, char* const pArgs[], const std: /* Not a good idea, we won't see any error messages */ /* close(STDERR_FILENO); */ - setgroups(1, GID); - setregid(atoi(pUID.c_str()), atoi(pUID.c_str())); - setreuid(atoi(pUID.c_str()), atoi(pUID.c_str())); + setgroups(1, &pw->pw_gid); + setregid(pw->pw_gid, pw->pw_gid); + setreuid(uid, uid); setsid(); execvp(pCommand, pArgs); @@ -487,7 +472,7 @@ std::string CAnalyzerCCpp::GetLocalUUID(const std::string& pDebugDumpDir) dd.LoadText(FILENAME_UID, UID); dd.LoadText(FILENAME_EXECUTABLE, executable); dd.LoadText(FILENAME_PACKAGE, package); - ExecVP(command, args, UID, buildIdPC); + ExecVP(command, args, atoi(UID.c_str()), buildIdPC); dd.Close(); free(args[1]); GetIndependentBuildIdPC(buildIdPC, independentBuildIdPC); |