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