diff options
Diffstat (limited to 'lib/rpmug.c')
-rw-r--r-- | lib/rpmug.c | 54 |
1 files changed, 23 insertions, 31 deletions
diff --git a/lib/rpmug.c b/lib/rpmug.c index 53a5a6e4d..119d8e585 100644 --- a/lib/rpmug.c +++ b/lib/rpmug.c @@ -1,7 +1,9 @@ #include "system.h" +#include <pthread.h> #include <pwd.h> #include <grp.h> +#include <netdb.h> #include <rpm/rpmlog.h> #include <rpm/rpmstring.h> @@ -9,32 +11,6 @@ #include "lib/rpmug.h" #include "debug.h" -#define HASHTYPE strCache -#define HTKEYTYPE const char * -#include "lib/rpmhash.H" -#include "lib/rpmhash.C" -#undef HASHTYPE -#undef HTKEYTYPE - -static strCache strStash = NULL; - -const char * rpmugStashStr(const char *str) -{ - const char *ret = NULL; - if (str) { - if (strStash == NULL) { - strStash = strCacheCreate(64, rstrhash, strcmp, - (strCacheFreeKey)rfree); - } - - if (!strCacheGetEntry(strStash, str, &ret)) { - strCacheAddEntry(strStash, xstrdup(str)); - (void) strCacheGetEntry(strStash, str, &ret); - } - } - return ret; -} - /* * These really ought to use hash tables. I just made the * guess that most files would be owned by root or the same person/group @@ -55,7 +31,7 @@ int rpmugUid(const char * thisUname, uid_t * uid) if (!thisUname) { lastUnameLen = 0; return -1; - } else if (rstreq(thisUname, "root")) { + } else if (rstreq(thisUname, UID_0_USER)) { *uid = 0; return 0; } @@ -98,7 +74,7 @@ int rpmugGid(const char * thisGname, gid_t * gid) if (thisGname == NULL) { lastGnameLen = 0; return -1; - } else if (rstreq(thisGname, "root")) { + } else if (rstreq(thisGname, GID_0_GROUP)) { *gid = 0; return 0; } @@ -140,7 +116,7 @@ const char * rpmugUname(uid_t uid) lastUid = (uid_t) -1; return NULL; } else if (uid == (uid_t) 0) { - return "root"; + return UID_0_USER; } else if (uid == lastUid) { return lastUname; } else { @@ -171,7 +147,7 @@ const char * rpmugGname(gid_t gid) lastGid = (gid_t) -1; return NULL; } else if (gid == (gid_t) 0) { - return "root"; + return GID_0_GROUP; } else if (gid == lastGid) { return lastGname; } else { @@ -192,11 +168,27 @@ const char * rpmugGname(gid_t gid) } } +static void loadLibs(void) +{ + (void) getpwnam(UID_0_USER); + endpwent(); + (void) getgrnam(GID_0_GROUP); + endgrent(); + (void) gethostbyname("localhost"); +} + +int rpmugInit(void) +{ + static pthread_once_t libsLoaded = PTHREAD_ONCE_INIT; + + pthread_once(&libsLoaded, loadLibs); + return 0; +} + void rpmugFree(void) { rpmugUid(NULL, NULL); rpmugGid(NULL, NULL); rpmugUname(-1); rpmugGname(-1); - strStash = strCacheFree(strStash); } |