Main Page   Modules   Data Structures   File List   Data Fields   Globals   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 typedef /*@owned@*/ /*@null@*/ const char * ugstr_t;
00013 
00014 static uid_t uids[1024];
00015 static ugstr_t unames[1024];
00016 static int uid_used = 0;
00017 
00018 static gid_t gids[1024];
00019 static ugstr_t gnames[1024];
00020 static int gid_used = 0;
00021     
00022 void freeNames(void)
00023 {
00024     int x;
00025     for (x = 0; x < uid_used; x++)
00026         unames[x] = _free(unames[x]);
00027     for (x = 0; x < gid_used; x++)
00028         gnames[x] = _free(gnames[x]);
00029 }
00030 
00031 const char *getUname(uid_t uid)
00032 {
00033     struct passwd *pw;
00034     int x;
00035 
00036     for (x = 0; x < uid_used; x++) {
00037         if (unames[x] == NULL) continue;
00038         if (uids[x] == uid)
00039             return unames[x];
00040     }
00041 
00042     /* XXX - This is the other hard coded limit */
00043     if (x == 1024)
00044         rpmlog(RPMLOG_CRIT, _("getUname: too many uid's\n"));
00045     uid_used++;
00046     
00047     pw = getpwuid(uid);
00048     uids[x] = uid;
00049     unames[x] = (pw ? xstrdup(pw->pw_name) : NULL);
00050     return unames[x];
00051 }
00052 
00053 const char *getUnameS(const char *uname)
00054 {
00055     struct passwd *pw;
00056     int x;
00057 
00058     for (x = 0; x < uid_used; x++) {
00059         if (unames[x] == NULL) continue;
00060         if (!strcmp(unames[x],uname))
00061             return unames[x];
00062     }
00063 
00064     /* XXX - This is the other hard coded limit */
00065     if (x == 1024)
00066         rpmlog(RPMLOG_CRIT, _("getUnameS: too many uid's\n"));
00067     uid_used++;
00068     
00069     pw = getpwnam(uname);
00070     uids[x] = (pw ? pw->pw_uid : -1);
00071     unames[x] = (pw ? xstrdup(pw->pw_name) : xstrdup(uname));
00072     return unames[x];
00073 }
00074 
00075 uid_t getUidS(const char *uname)
00076 {
00077     struct passwd *pw;
00078     int x;
00079 
00080     for (x = 0; x < uid_used; x++) {
00081         if (unames[x] == NULL) continue;
00082         if (!strcmp(unames[x],uname))
00083             return uids[x];
00084     }
00085 
00086     /* XXX - This is the other hard coded limit */
00087     if (x == 1024)
00088         rpmlog(RPMLOG_CRIT, _("getUidS: too many uid's\n"));
00089     uid_used++;
00090     
00091     pw = getpwnam(uname);
00092     uids[x] = (pw ? pw->pw_uid : -1);
00093     unames[x] = (pw ? xstrdup(pw->pw_name) : xstrdup(uname));
00094     return uids[x];
00095 }
00096 
00097 const char *getGname(gid_t gid)
00098 {
00099     struct group *gr;
00100     int x;
00101 
00102     for (x = 0; x < gid_used; x++) {
00103         if (gnames[x] == NULL) continue;
00104         if (gids[x] == gid)
00105             return gnames[x];
00106     }
00107 
00108     /* XXX - This is the other hard coded limit */
00109     if (x == 1024)
00110         rpmlog(RPMLOG_CRIT, _("getGname: too many gid's\n"));
00111     gid_used++;
00112     
00113     gr = getgrgid(gid);
00114     gids[x] = gid;
00115     gnames[x] = (gr ? xstrdup(gr->gr_name) : NULL);
00116     return gnames[x];
00117 }
00118 
00119 const char *getGnameS(const char *gname)
00120 {
00121     struct group *gr;
00122     int x;
00123 
00124     for (x = 0; x < gid_used; x++) {
00125         if (gnames[x] == NULL) continue;
00126         if (!strcmp(gnames[x], gname))
00127             return gnames[x];
00128     }
00129 
00130     /* XXX - This is the other hard coded limit */
00131     if (x == 1024)
00132         rpmlog(RPMLOG_CRIT, _("getGnameS: too many gid's\n"));
00133     gid_used++;
00134     
00135     gr = getgrnam(gname);
00136     gids[x] = (gr ? gr->gr_gid : -1);
00137     gnames[x] = (gr ? xstrdup(gr->gr_name) : xstrdup(gname));
00138     return gnames[x];
00139 }
00140 
00141 gid_t getGidS(const char *gname)
00142 {
00143     struct group *gr;
00144     int x;
00145 
00146     for (x = 0; x < gid_used; x++) {
00147         if (gnames[x] == NULL) continue;
00148         if (!strcmp(gnames[x], gname))
00149             return gids[x];
00150     }
00151 
00152     /* XXX - This is the other hard coded limit */
00153     if (x == 1024)
00154         rpmlog(RPMLOG_CRIT, _("getGidS: too many gid's\n"));
00155     gid_used++;
00156     
00157     gr = getgrnam(gname);
00158     gids[x] = (gr ? gr->gr_gid : -1);
00159     gnames[x] = (gr ? xstrdup(gr->gr_name) : xstrdup(gname));
00160     return gids[x];
00161 }
00162 
00163 int_32 *const getBuildTime(void)
00164 {
00165     static int_32 buildTime[1];
00166 
00167     if (buildTime[0] == 0)
00168         buildTime[0] = (int_32) time(NULL);
00169     return buildTime;
00170 }
00171 
00172 const char *const buildHost(void)
00173 {
00174     static char hostname[1024];
00175     static int gotit = 0;
00176     struct hostent *hbn;
00177 
00178     if (! gotit) {
00179         (void) gethostname(hostname, sizeof(hostname));
00180         /*@-unrecog -multithreaded @*/
00181         hbn = gethostbyname(hostname);
00182         /*@=unrecog =multithreaded @*/
00183         if (hbn)
00184             strcpy(hostname, hbn->h_name);
00185         else
00186             rpmMessage(RPMMESS_WARNING,
00187                         _("Could not canonicalize hostname: %s\n"), hostname);
00188         gotit = 1;
00189     }
00190     return(hostname);
00191 }

Generated on Wed Mar 13 15:34:46 2002 for rpm by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002