fix pwcache again

This commit is contained in:
albert 2004-08-10 04:47:07 +00:00
parent ef0b63de31
commit 1e1ec4ad84

View File

@ -30,7 +30,6 @@ static struct pwbuf {
char *user_from_uid(uid_t uid) { char *user_from_uid(uid_t uid) {
struct pwbuf **p; struct pwbuf **p;
struct passwd *pw; struct passwd *pw;
size_t len;
p = &pwhash[HASH(uid)]; p = &pwhash[HASH(uid)];
while (*p) { while (*p) {
@ -41,11 +40,11 @@ char *user_from_uid(uid_t uid) {
*p = (struct pwbuf *) xmalloc(sizeof(struct pwbuf)); *p = (struct pwbuf *) xmalloc(sizeof(struct pwbuf));
(*p)->uid = uid; (*p)->uid = uid;
pw = getpwuid(uid); pw = getpwuid(uid);
len = pw ? strlen(pw) : 0; if(!pw || strlen(pw->pw_name) >= P_G_SZ)
if (len >= P_G_SZ)
sprintf((*p)->name, "%u", uid); sprintf((*p)->name, "%u", uid);
else else
strcpy((*p)->name, pw->pw_name); strcpy((*p)->name, pw->pw_name);
(*p)->next = NULL; (*p)->next = NULL;
return((*p)->name); return((*p)->name);
} }
@ -59,7 +58,6 @@ static struct grpbuf {
char *group_from_gid(gid_t gid) { char *group_from_gid(gid_t gid) {
struct grpbuf **g; struct grpbuf **g;
struct group *gr; struct group *gr;
size_t len;
g = &grphash[HASH(gid)]; g = &grphash[HASH(gid)];
while (*g) { while (*g) {
@ -70,8 +68,7 @@ char *group_from_gid(gid_t gid) {
*g = (struct grpbuf *) malloc(sizeof(struct grpbuf)); *g = (struct grpbuf *) malloc(sizeof(struct grpbuf));
(*g)->gid = gid; (*g)->gid = gid;
gr = getgrgid(gid); gr = getgrgid(gid);
len = gr ? strlen(gr) : 0; if (!gr || strlen(gr->gr_name) >= P_G_SZ)
if (len >= P_G_SZ)
sprintf((*g)->name, "%u", gid); sprintf((*g)->name, "%u", gid);
else else
strcpy((*g)->name, gr->gr_name); strcpy((*g)->name, gr->gr_name);