summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZdenek Prikryl <zprikryl@redhat.com>2009-07-24 15:33:14 +0200
committerZdenek Prikryl <zprikryl@redhat.com>2009-07-24 15:33:14 +0200
commitf889932408f5912379f92e24c0e8f213a1f6c451 (patch)
tree62f6d249184082e0dd2bed25c6d656bbcbca0511
parent052e544305d6b1efde7d28f894ead8771cf62b03 (diff)
parent16db3cc595ab34f21a747d88fb9cdd340ac438f9 (diff)
downloadabrt-f889932408f5912379f92e24c0e8f213a1f6c451.tar.gz
abrt-f889932408f5912379f92e24c0e8f213a1f6c451.tar.xz
abrt-f889932408f5912379f92e24c0e8f213a1f6c451.zip
Merge branch 'master' of git://git.fedorahosted.org/abrt
-rw-r--r--lib/Plugins/CCpp.cpp53
-rw-r--r--lib/Plugins/CCpp.h3
-rw-r--r--lib/Utils/DebugDump.cpp24
-rw-r--r--lib/Utils/DebugDump.h1
4 files changed, 26 insertions, 55 deletions
diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp
index 86ada29c..fe6c56ca 100644
--- a/lib/Plugins/CCpp.cpp
+++ b/lib/Plugins/CCpp.cpp
@@ -78,12 +78,19 @@ std::string CAnalyzerCCpp::CreateHash(const std::string& pInput)
HASH_End(hc, hash, &len, sizeof(hash));
HASH_Destroy(hc);
- unsigned int ii;
- std::stringstream ss;
- for (ii = 0; ii < len; ii++)
- ss << std::setw(2) << std::setfill('0') << std::hex << (hash[ii]&0xff);
+ char hash_str[SHA1_LENGTH*2 + 1];
+ char *d = hash_str;
+ unsigned char *s = hash;
+ while (len)
+ {
+ *d++ = "0123456789abcdef"[*s >> 4];
+ *d++ = "0123456789abcdef"[*s & 0xf];
+ s++;
+ len--;
+ }
+ *d = '\0';
- return ss.str();
+ return hash_str;
}
void CAnalyzerCCpp::InstallDebugInfos(const std::string& pPackage)
@@ -223,9 +230,8 @@ void CAnalyzerCCpp::GetBacktrace(const std::string& pDebugDumpDir, std::string&
}
char* command = (char*)"gdb";
char* args[5] = { (char*)"gdb", (char*)"-batch", (char*)"-x", NULL, NULL };
- args[3] = strdup(tmpFile.c_str());
- ExecVP(command, args, UID, pBacktrace);
- free(args[3]);
+ args[3] = (char*) tmpFile.c_str();
+ ExecVP(command, args, atoi(UID.c_str()), pBacktrace);
}
void CAnalyzerCCpp::GetIndependentBacktrace(const std::string& pBacktrace, std::string& pIndependentBacktrace)
@@ -354,23 +360,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];
@@ -378,9 +368,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? */
@@ -408,9 +399,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);
@@ -480,7 +471,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 d60c9a41..d79b61ee 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 36b48cc6..b2767bad 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();