Main Page   Modules   Compound List   File List   Compound Members   File Members   Related Pages  

build/names.c

Go to the documentation of this file.
00001 
00007 #include "system.h"
00008 
00009 #include "rpmbuild.h"
00010 #include "debug.h"
00011 
00012 static uid_t uids[1024];
00013 /*@owned@*/ /*@null@*/ static const char *unames[1024];
00014 static int uid_used = 0;
00015 
00016 static gid_t gids[1024];
00017 /*@owned@*/ /*@null@*/ static const char *gnames[1024];
00018 static int gid_used = 0;
00019     
00020 void freeNames(void)
00021 {
00022     int x;
00023     for (x = 0; x < uid_used; x++)
00024         free((void *)unames[x]);
00025     for (x = 0; x < gid_used; x++)
00026         free((void *)gnames[x]);
00027 }
00028 
00029 const char *getUname(uid_t uid)
00030 {
00031     struct passwd *pw;
00032     int x;
00033 
00034     for (x = 0; x < uid_used; x++) {
00035         if (uids[x] == uid) {
00036             return unames[x];
00037         }
00038     }
00039 
00040     /* XXX - This is the other hard coded limit */
00041     if (x == 1024)
00042         rpmlog(RPMLOG_CRIT, _("getUname: too many uid's\n"));
00043     
00044     pw = getpwuid(uid);
00045     uids[x] = uid;
00046     uid_used++;
00047     if (pw) {
00048         unames[x] = xstrdup(pw->pw_name);
00049     } else {
00050         unames[x] = NULL;
00051     }
00052     return unames[x];
00053 }
00054 
00055 const char *getUnameS(const char *uname)
00056 {
00057     struct passwd *pw;
00058     int x;
00059 
00060     for (x = 0; x < uid_used; x++) {
00061         if (!strcmp(unames[x],uname)) {
00062             return unames[x];
00063         }
00064     }
00065 
00066     /* XXX - This is the other hard coded limit */
00067     if (x == 1024)
00068         rpmlog(RPMLOG_CRIT, _("getUnameS: too many uid's\n"));
00069     
00070     pw = getpwnam(uname);
00071     uid_used++;
00072     if (pw) {
00073         uids[x] = pw->pw_uid;
00074         unames[x] = xstrdup(pw->pw_name);
00075     } else {
00076         uids[x] = -1;
00077         unames[x] = xstrdup(uname);
00078     }
00079     return unames[x];
00080 }
00081 
00082 const char *getGname(gid_t gid)
00083 {
00084     struct group *gr;
00085     int x;
00086 
00087     for (x = 0; x < gid_used; x++) {
00088         if (gids[x] == gid) {
00089             return gnames[x];
00090         }
00091     }
00092 
00093     /* XXX - This is the other hard coded limit */
00094     if (x == 1024)
00095         rpmlog(RPMLOG_CRIT, _("getGname: too many gid's\n"));
00096     
00097     gr = getgrgid(gid);
00098     gids[x] = gid;
00099     gid_used++;
00100     if (gr) {
00101         gnames[x] = xstrdup(gr->gr_name);
00102     } else {
00103         gnames[x] = NULL;
00104     }
00105     return gnames[x];
00106 }
00107 
00108 const char *getGnameS(const char *gname)
00109 {
00110     struct group *gr;
00111     int x;
00112 
00113     for (x = 0; x < gid_used; x++) {
00114         if (!strcmp(gnames[x], gname)) {
00115             return gnames[x];
00116         }
00117     }
00118 
00119     /* XXX - This is the other hard coded limit */
00120     if (x == 1024)
00121         rpmlog(RPMLOG_CRIT, _("getGnameS: too many gid's\n"));
00122     
00123     gr = getgrnam(gname);
00124     gid_used++;
00125     if (gr) {
00126         gids[x] = gr->gr_gid;
00127         gnames[x] = xstrdup(gr->gr_name);
00128     } else {
00129         gids[x] = -1;
00130         gnames[x] = xstrdup(gname);
00131     }
00132     return gnames[x];
00133 }
00134 
00135 time_t *const getBuildTime(void)
00136 {
00137     static time_t buildTime = 0;
00138 
00139     if (! buildTime)
00140         buildTime = time(NULL);
00141     return &buildTime;
00142 }
00143 
00144 const char *const buildHost(void)
00145 {
00146     static char hostname[1024];
00147     static int gotit = 0;
00148     struct hostent *hbn;
00149 
00150     if (! gotit) {
00151         gethostname(hostname, sizeof(hostname));
00152         if ((hbn = /*@-unrecog@*/ gethostbyname(hostname) /*@=unrecog@*/ )) {
00153             strcpy(hostname, hbn->h_name);
00154         } else {
00155             rpmMessage(RPMMESS_WARNING, _("Could not canonicalize hostname: %s\n"),
00156                     hostname);
00157         }
00158         gotit = 1;
00159     }
00160     return(hostname);
00161 }

Generated at Sun Apr 8 18:42:58 2001 for rpm by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000