Stuff rpmio/ugid.[ch] contents to lib/misc.[ch]
authorPanu Matilainen <pmatilai@redhat.com>
Fri, 4 Jul 2008 13:09:42 +0000 (16:09 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 4 Jul 2008 13:09:47 +0000 (16:09 +0300)
- no uses outside librpm itself, and there they can be hidden away from
  exported ABI whereas in librpmio they cant

lib/fsm.c
lib/misc.c
lib/misc.h
lib/verify.c
rpmio/Makefile.am
rpmio/rpmio.c
rpmio/ugid.c [deleted file]
rpmio/ugid.h [deleted file]

index f604a73..0905e3c 100644 (file)
--- a/lib/fsm.c
+++ b/lib/fsm.c
@@ -15,7 +15,7 @@
 #include "lib/fsm.h"
 #define        fsmUNSAFE       fsmStage
 #include "lib/rpmfi_internal.h"        /* XXX fi->apath, fi->action... */
-#include "rpmio/ugid.h"                /* XXX unameToUid() and gnameToGid() */
+#include "lib/misc.h"          /* XXX unameToUid() and gnameToGid() */
 
 #include "debug.h"
 
index 841d48a..26546ab 100644 (file)
@@ -34,4 +34,167 @@ rpmRC rpmMkdirPath (const char * dpath, const char * dname)
     return RPMRC_OK;
 }
 
+/* unameToUid(), uidTouname() and the group variants are really poorly
+   implemented. They really ought to use hash tables. I just made the
+   guess that most files would be owned by root or the same person/group
+   who owned the last file. Those two values are cached, everything else
+   is looked up via getpw() and getgr() functions.  If this performs
+   too poorly I'll have to implement it properly :-( */
 
+int unameToUid(const char * thisUname, uid_t * uid)
+{
+static char * lastUname = NULL;
+    static size_t lastUnameLen = 0;
+    static size_t lastUnameAlloced;
+    static uid_t lastUid;
+    struct passwd * pwent;
+    size_t thisUnameLen;
+
+    if (!thisUname) {
+       lastUnameLen = 0;
+       return -1;
+    } else if (strcmp(thisUname, "root") == 0) {
+       *uid = 0;
+       return 0;
+    }
+
+    thisUnameLen = strlen(thisUname);
+    if (lastUname == NULL || thisUnameLen != lastUnameLen ||
+       strcmp(thisUname, lastUname) != 0)
+    {
+       if (lastUnameAlloced < thisUnameLen + 1) {
+           lastUnameAlloced = thisUnameLen + 10;
+           lastUname = xrealloc(lastUname, lastUnameAlloced);  /* XXX memory leak */
+       }
+       strcpy(lastUname, thisUname);
+
+       pwent = getpwnam(thisUname);
+       if (pwent == NULL) {
+           /* FIX: shrug */
+           endpwent();
+           pwent = getpwnam(thisUname);
+           if (pwent == NULL) return -1;
+       }
+
+       lastUid = pwent->pw_uid;
+    }
+
+    *uid = lastUid;
+
+    return 0;
+}
+
+int gnameToGid(const char * thisGname, gid_t * gid)
+{
+static char * lastGname = NULL;
+    static size_t lastGnameLen = 0;
+    static size_t lastGnameAlloced;
+    static gid_t lastGid;
+    size_t thisGnameLen;
+    struct group * grent;
+
+    if (thisGname == NULL) {
+       lastGnameLen = 0;
+       return -1;
+    } else if (strcmp(thisGname, "root") == 0) {
+       *gid = 0;
+       return 0;
+    }
+
+    thisGnameLen = strlen(thisGname);
+    if (lastGname == NULL || thisGnameLen != lastGnameLen ||
+       strcmp(thisGname, lastGname) != 0)
+    {
+       if (lastGnameAlloced < thisGnameLen + 1) {
+           lastGnameAlloced = thisGnameLen + 10;
+           lastGname = xrealloc(lastGname, lastGnameAlloced);  /* XXX memory leak */
+       }
+       strcpy(lastGname, thisGname);
+
+       grent = getgrnam(thisGname);
+       if (grent == NULL) {
+           /* FIX: shrug */
+           endgrent();
+           grent = getgrnam(thisGname);
+           if (grent == NULL) {
+               /* XXX The filesystem package needs group/lock w/o getgrnam. */
+               if (strcmp(thisGname, "lock") == 0) {
+                   *gid = lastGid = 54;
+                   return 0;
+               } else
+               if (strcmp(thisGname, "mail") == 0) {
+                   *gid = lastGid = 12;
+                   return 0;
+               } else
+               return -1;
+           }
+       }
+       lastGid = grent->gr_gid;
+    }
+
+    *gid = lastGid;
+
+    return 0;
+}
+
+const char * uidToUname(uid_t uid)
+{
+    static uid_t lastUid = (uid_t) -1;
+static char * lastUname = NULL;
+    static size_t lastUnameLen = 0;
+
+    if (uid == (uid_t) -1) {
+       lastUid = (uid_t) -1;
+       return NULL;
+    } else if (uid == (uid_t) 0) {
+       return "root";
+    } else if (uid == lastUid) {
+       return lastUname;
+    } else {
+       struct passwd * pwent = getpwuid(uid);
+       size_t len;
+
+       if (pwent == NULL) return NULL;
+
+       lastUid = uid;
+       len = strlen(pwent->pw_name);
+       if (lastUnameLen < len + 1) {
+           lastUnameLen = len + 20;
+           lastUname = xrealloc(lastUname, lastUnameLen);
+       }
+       strcpy(lastUname, pwent->pw_name);
+
+       return lastUname;
+    }
+}
+
+const char * gidToGname(gid_t gid)
+{
+    static gid_t lastGid = (gid_t) -1;
+static char * lastGname = NULL;
+    static size_t lastGnameLen = 0;
+
+    if (gid == (gid_t) -1) {
+       lastGid = (gid_t) -1;
+       return NULL;
+    } else if (gid == (gid_t) 0) {
+       return "root";
+    } else if (gid == lastGid) {
+       return lastGname;
+    } else {
+       struct group * grent = getgrgid(gid);
+       size_t len;
+
+       if (grent == NULL) return NULL;
+
+       lastGid = gid;
+       len = strlen(grent->gr_name);
+       if (lastGnameLen < len + 1) {
+           lastGnameLen = len + 20;
+           lastGname = xrealloc(lastGname, lastGnameLen);
+       }
+       strcpy(lastGname, grent->gr_name);
+
+       return lastGname;
+    }
+}
index 4029d98..0f0c81c 100644 (file)
@@ -22,6 +22,19 @@ extern "C" {
  */
 rpmRC rpmMkdirPath (const char * dpath, const char * dname);
 
+/*
+ * These may be called w/ a NULL argument to flush the cache -- they return
+ * -1 if the user can't be found.
+ */
+int     unameToUid(const char * thisUname, uid_t * uid);
+int     gnameToGid(const char * thisGname, gid_t * gid);
+
+/*
+ * Call w/ -1 to flush the cache, returns NULL if the user can't be found.
+ */
+const char * uidToUname(uid_t uid);
+const char * gidToGname(gid_t gid);
+
 #ifdef __cplusplus
 }
 #endif
index 7229ebf..1865026 100644 (file)
@@ -14,7 +14,7 @@
 #include <rpm/rpmfileutil.h>
 
 #include "lib/psm.h"
-#include "rpmio/ugid.h"        /* uidToUname(), gnameToGid */
+#include "lib/misc.h"  /* uidToUname(), gnameToGid */
 
 #include "debug.h"
 
index 2e9ccd3..e2147cb 100644 (file)
@@ -14,8 +14,8 @@ usrlib_LTLIBRARIES = librpmio.la
 librpmio_la_SOURCES = \
        argv.c base64.h base64.c digest.h digest.c fts.c macro.c \
        rpmhook.c rpmio.c rpmlog.c rpmlua.c rpmmalloc.c \
-       rpmpgp.c rpmsq.c rpmsw.c url.c ugid.c \
-       rpmio_internal.h rpmlua.h rpmhook.h ugid.h fts.h \
+       rpmpgp.c rpmsq.c rpmsw.c url.c \
+       rpmio_internal.h rpmlua.h rpmhook.h fts.h \
        rpmstring.c rpmfileutil.c \
        rpmkeyring.c
 
index 30afe73..86dcaf3 100644 (file)
@@ -26,7 +26,6 @@ extern int h_errno;
 #include <rpm/rpmfileutil.h>
 
 #include "rpmio/rpmio_internal.h"
-#include "rpmio/ugid.h"
 
 #include "debug.h"
 
diff --git a/rpmio/ugid.c b/rpmio/ugid.c
deleted file mode 100644 (file)
index c256829..0000000
+++ /dev/null
@@ -1,172 +0,0 @@
-/** \ingroup rpmio
- * \file rpmio/ugid.c
- */
-
-#include "system.h"
-#include "rpmio/ugid.h"
-#include "debug.h"
-
-/* unameToUid(), uidTouname() and the group variants are really poorly
-   implemented. They really ought to use hash tables. I just made the
-   guess that most files would be owned by root or the same person/group
-   who owned the last file. Those two values are cached, everything else
-   is looked up via getpw() and getgr() functions.  If this performs
-   too poorly I'll have to implement it properly :-( */
-
-int unameToUid(const char * thisUname, uid_t * uid)
-{
-static char * lastUname = NULL;
-    static size_t lastUnameLen = 0;
-    static size_t lastUnameAlloced;
-    static uid_t lastUid;
-    struct passwd * pwent;
-    size_t thisUnameLen;
-
-    if (!thisUname) {
-       lastUnameLen = 0;
-       return -1;
-    } else if (strcmp(thisUname, "root") == 0) {
-       *uid = 0;
-       return 0;
-    }
-
-    thisUnameLen = strlen(thisUname);
-    if (lastUname == NULL || thisUnameLen != lastUnameLen ||
-       strcmp(thisUname, lastUname) != 0)
-    {
-       if (lastUnameAlloced < thisUnameLen + 1) {
-           lastUnameAlloced = thisUnameLen + 10;
-           lastUname = xrealloc(lastUname, lastUnameAlloced);  /* XXX memory leak */
-       }
-       strcpy(lastUname, thisUname);
-
-       pwent = getpwnam(thisUname);
-       if (pwent == NULL) {
-           /* FIX: shrug */
-           endpwent();
-           pwent = getpwnam(thisUname);
-           if (pwent == NULL) return -1;
-       }
-
-       lastUid = pwent->pw_uid;
-    }
-
-    *uid = lastUid;
-
-    return 0;
-}
-
-int gnameToGid(const char * thisGname, gid_t * gid)
-{
-static char * lastGname = NULL;
-    static size_t lastGnameLen = 0;
-    static size_t lastGnameAlloced;
-    static gid_t lastGid;
-    size_t thisGnameLen;
-    struct group * grent;
-
-    if (thisGname == NULL) {
-       lastGnameLen = 0;
-       return -1;
-    } else if (strcmp(thisGname, "root") == 0) {
-       *gid = 0;
-       return 0;
-    }
-
-    thisGnameLen = strlen(thisGname);
-    if (lastGname == NULL || thisGnameLen != lastGnameLen ||
-       strcmp(thisGname, lastGname) != 0)
-    {
-       if (lastGnameAlloced < thisGnameLen + 1) {
-           lastGnameAlloced = thisGnameLen + 10;
-           lastGname = xrealloc(lastGname, lastGnameAlloced);  /* XXX memory leak */
-       }
-       strcpy(lastGname, thisGname);
-
-       grent = getgrnam(thisGname);
-       if (grent == NULL) {
-           /* FIX: shrug */
-           endgrent();
-           grent = getgrnam(thisGname);
-           if (grent == NULL) {
-               /* XXX The filesystem package needs group/lock w/o getgrnam. */
-               if (strcmp(thisGname, "lock") == 0) {
-                   *gid = lastGid = 54;
-                   return 0;
-               } else
-               if (strcmp(thisGname, "mail") == 0) {
-                   *gid = lastGid = 12;
-                   return 0;
-               } else
-               return -1;
-           }
-       }
-       lastGid = grent->gr_gid;
-    }
-
-    *gid = lastGid;
-
-    return 0;
-}
-
-const char * uidToUname(uid_t uid)
-{
-    static uid_t lastUid = (uid_t) -1;
-static char * lastUname = NULL;
-    static size_t lastUnameLen = 0;
-
-    if (uid == (uid_t) -1) {
-       lastUid = (uid_t) -1;
-       return NULL;
-    } else if (uid == (uid_t) 0) {
-       return "root";
-    } else if (uid == lastUid) {
-       return lastUname;
-    } else {
-       struct passwd * pwent = getpwuid(uid);
-       size_t len;
-
-       if (pwent == NULL) return NULL;
-
-       lastUid = uid;
-       len = strlen(pwent->pw_name);
-       if (lastUnameLen < len + 1) {
-           lastUnameLen = len + 20;
-           lastUname = xrealloc(lastUname, lastUnameLen);
-       }
-       strcpy(lastUname, pwent->pw_name);
-
-       return lastUname;
-    }
-}
-
-const char * gidToGname(gid_t gid)
-{
-    static gid_t lastGid = (gid_t) -1;
-static char * lastGname = NULL;
-    static size_t lastGnameLen = 0;
-
-    if (gid == (gid_t) -1) {
-       lastGid = (gid_t) -1;
-       return NULL;
-    } else if (gid == (gid_t) 0) {
-       return "root";
-    } else if (gid == lastGid) {
-       return lastGname;
-    } else {
-       struct group * grent = getgrgid(gid);
-       size_t len;
-
-       if (grent == NULL) return NULL;
-
-       lastGid = gid;
-       len = strlen(grent->gr_name);
-       if (lastGnameLen < len + 1) {
-           lastGnameLen = len + 20;
-           lastGname = xrealloc(lastGname, lastGnameLen);
-       }
-       strcpy(lastGname, grent->gr_name);
-
-       return lastGname;
-    }
-}
diff --git a/rpmio/ugid.h b/rpmio/ugid.h
deleted file mode 100644 (file)
index d3556ef..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#ifndef H_UGID
-#define H_UGID
-
-/** \ingroup rpmio
- * \file rpmio/ugid.h
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * These may be called w/ a NULL argument to flush the cache -- they return
- * -1 if the user can't be found.
- */
-int     unameToUid(const char * thisUname, uid_t * uid);
-int     gnameToGid(const char * thisGname, gid_t * gid);
-
-/*
- * Call w/ -1 to flush the cache, returns NULL if the user can't be found.
- */
-const char * uidToUname(uid_t uid);
-const char * gidToGname(gid_t gid);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif  /* H_UGID */
-