summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/Plugins/CCpp.cpp31
-rw-r--r--lib/Plugins/CCpp.h3
-rw-r--r--lib/Utils/DebugDump.cpp24
-rw-r--r--lib/Utils/DebugDump.h1
4 files changed, 12 insertions, 47 deletions
diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp
index 7d302c79..f7293265 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);
diff --git a/lib/Plugins/CCpp.h b/lib/Plugins/CCpp.h
index 1bdf230e..ed83b960 100644
--- a/lib/Plugins/CCpp.h
+++ b/lib/Plugins/CCpp.h
@@ -37,8 +37,7 @@ class CAnalyzerCCpp : public CAnalyzer
void GetBacktrace(const std::string& pDebugDumpDir, std::string& pBacktrace);
void GetIndependentBacktrace(const std::string& pBacktrace, std::string& pIndependentBacktrace);
void GetIndependentBuildIdPC(const std::string& pBuildIdPC, std::string& pIndependentBuildIdPC);
- gid_t GetGIDFromUID(const std::string& pUID);
- void ExecVP(const char* pCommand, char* const pArgs[], const std::string& pUID, std::string& pOutput);
+ void ExecVP(const char* pCommand, char* const pArgs[], uid_t uid, std::string& pOutput);
std::string CreateHash(const std::string& pInput);
public:
CAnalyzerCCpp();
diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp
index 6fd135e3..465b7ab7 100644
--- a/lib/Utils/DebugDump.cpp
+++ b/lib/Utils/DebugDump.cpp
@@ -178,25 +178,6 @@ void CDebugDump::UnLock()
}
}
-std::string CDebugDump::GetGIDFromUID(const std::string& pUID)
-{
- std::stringstream ret;
- struct passwd* pw;
- while (( pw = getpwent()) != NULL)
- {
- if (pw->pw_uid == atoi(pUID.c_str()))
- {
- ret << pw->pw_gid;
- }
- }
- setpwent();
- if (ret.str() == "")
- {
- ret << "-1";
- }
- return ret.str();
-}
-
void CDebugDump::Create(const std::string& pDir, const std::string& pUID)
{
if (m_bOpened)
@@ -225,8 +206,9 @@ void CDebugDump::Create(const std::string& pDir, const std::string& pUID)
m_bOpened = false;
throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::Create(): Cannot change permissions, dir: " + pDir);
}
- std::string GID = GetGIDFromUID(pUID);
- if (chown(m_sDebugDumpDir.c_str(), atoi(pUID.c_str()), atoi(GID.c_str())) == -1)
+ uid_t uid = atoi(pUID.c_str());
+ struct passwd* pw = getpwuid(uid);
+ if (chown(m_sDebugDumpDir.c_str(), uid, pw ? pw->pw_gid : uid) == -1)
{
UnLock();
m_bOpened = false;
diff --git a/lib/Utils/DebugDump.h b/lib/Utils/DebugDump.h
index 3b47956c..a09a913d 100644
--- a/lib/Utils/DebugDump.h
+++ b/lib/Utils/DebugDump.h
@@ -66,7 +66,6 @@ class CDebugDump
bool IsTextFile(const std::string& pName);
std::string RemoveBackSlashes(const std::string& pDir);
- std::string GetGIDFromUID(const std::string& pUID);
public:
CDebugDump();