Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

build/names.c

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

Generated on Sun Oct 26 13:01:57 2003 for rpm by doxygen1.2.18