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