1 /* names.c -- user/group name/id cache (plus hostname and buildtime) */
17 static uid_t uids[1024];
18 static char *unames[1024];
19 static int uid_used = 0;
21 static gid_t gids[1024];
22 static char *gnames[1024];
23 static int gid_used = 0;
25 static time_t buildtime;
28 * getUname() takes a uid, gets the username, and creates an entry in the
29 * table to hold a string containing the user name.
31 char *getUname(uid_t uid)
37 while (x < uid_used) {
44 /* XXX - This is the other hard coded limit */
46 fprintf(stderr, "RPMERR_INTERNAL: Hit limit in getUname()\n");
47 exit(RPMERR_INTERNAL);
54 unames[x] = strdup(pw->pw_name);
62 * getUnameS() takes a username, gets the uid, and creates an entry in the
63 * table to hold a string containing the user name.
65 char *getUnameS(char *uname)
71 while (x < uid_used) {
72 if (!strcmp(unames[x],uname)) {
78 /* XXX - This is the other hard coded limit */
80 fprintf(stderr, "RPMERR_INTERNAL: Hit limit in getUname()\n");
81 exit(RPMERR_INTERNAL);
88 unames[x] = strdup(pw->pw_name);
91 unames[x] = strdup(uname);
97 * getGname() takes a gid, gets the group name, and creates an entry in the
98 * table to hold a string containing the group name.
100 char *getGname(gid_t gid)
106 while (x < gid_used) {
107 if (gids[x] == gid) {
113 /* XXX - This is the other hard coded limit */
115 fprintf(stderr, "RPMERR_INTERNAL: Hit limit in getGname()\n");
116 exit(RPMERR_INTERNAL);
123 gnames[x] = strdup(gr->gr_name);
131 * getGnameS() takes a group name, gets the gid, and creates an entry in the
132 * table to hold a string containing the group name.
134 char *getGnameS(char *gname)
140 while (x < gid_used) {
141 if (!strcmp(gnames[x], gname)) {
147 /* XXX - This is the other hard coded limit */
149 fprintf(stderr, "RPMERR_INTERNAL: Hit limit in getGname()\n");
150 exit(RPMERR_INTERNAL);
153 gr = getgrnam(gname);
156 gids[x] = gr->gr_gid;
157 gnames[x] = strdup(gr->gr_name);
160 gnames[x] = strdup(gname);
165 void markBuildTime(void)
167 buildtime = time(NULL);
170 time_t *getBuildTime(void)
175 char *buildHost(void)
177 static char hostname[1024];
178 static int gotit = 0;
182 gethostname(hostname, sizeof(hostname));
183 if ((hbn = gethostbyname(hostname))) {
184 strcpy(hostname, hbn->h_name);
186 rpmMessage(RPMMESS_WARNING, "Could not canonicalize hostname: %s\n",