diff options
author | dg <dg@FreeBSD.org> | 1996-03-05 13:11:42 +0000 |
---|---|---|
committer | dg <dg@FreeBSD.org> | 1996-03-05 13:11:42 +0000 |
commit | a4dbe92a7558c1724e8affcfe8f5490cf8eb6ffe (patch) | |
tree | dfd1f6fb69211f8c703ce2fa265540e857952f57 | |
parent | 2a29cb99a44c1ef6f781ab2d28e7f7052538247a (diff) | |
download | FreeBSD-src-a4dbe92a7558c1724e8affcfe8f5490cf8eb6ffe.zip FreeBSD-src-a4dbe92a7558c1724e8affcfe8f5490cf8eb6ffe.tar.gz |
Implemented negative caching on uid/gid lookup failures. This won't
matter much on some systems, but on ftp servers (like wcarchive) where
you run with special stripped group and pwd.db files in the anonymous
ftp /etc, this can be a major speedup for ls(1).
-rw-r--r-- | lib/libc/gen/pwcache.c | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/lib/libc/gen/pwcache.c b/lib/libc/gen/pwcache.c index 7c266c1..05773bd 100644 --- a/lib/libc/gen/pwcache.c +++ b/lib/libc/gen/pwcache.c @@ -53,10 +53,10 @@ user_from_uid(uid, nouser) { static struct ncache { uid_t uid; + int found; char name[UT_NAMESIZE + 1]; } c_uid[NCACHE]; static int pwopen; - static char nbuf[15]; /* 32 bits == 10 digits */ register struct passwd *pw; register struct ncache *cp; @@ -66,15 +66,18 @@ user_from_uid(uid, nouser) setpassent(1); pwopen = 1; } - if ((pw = getpwuid(uid)) == NULL) { + pw = getpwuid(uid); + cp->uid = uid; + if (pw != NULL) { + cp->found = 1; + (void)strncpy(cp->name, pw->pw_name, UT_NAMESIZE); + cp->name[UT_NAMESIZE] = '\0'; + } else { + cp->found = 0; + (void)snprintf(cp->name, UT_NAMESIZE, "%u", uid); if (nouser) return (NULL); - (void)snprintf(nbuf, sizeof(nbuf), "%u", uid); - return (nbuf); } - cp->uid = uid; - (void)strncpy(cp->name, pw->pw_name, UT_NAMESIZE); - cp->name[UT_NAMESIZE] = '\0'; } return (cp->name); } @@ -86,10 +89,10 @@ group_from_gid(gid, nogroup) { static struct ncache { gid_t gid; + int found; char name[UT_NAMESIZE + 1]; } c_gid[NCACHE]; static int gropen; - static char nbuf[15]; /* 32 bits == 10 digits */ struct group *gr; struct ncache *cp; @@ -99,15 +102,18 @@ group_from_gid(gid, nogroup) setgroupent(1); gropen = 1; } - if ((gr = getgrgid(gid)) == NULL) { + gr = getgrgid(gid); + cp->gid = gid; + if (gr != NULL) { + cp->found = 1; + (void)strncpy(cp->name, gr->gr_name, UT_NAMESIZE); + cp->name[UT_NAMESIZE] = '\0'; + } else { + cp->found = 0; + (void)snprintf(cp->name, UT_NAMESIZE, "%u", gid); if (nogroup) return (NULL); - (void)snprintf(nbuf, sizeof(nbuf), "%u", gid); - return (nbuf); } - cp->gid = gid; - (void)strncpy(cp->name, gr->gr_name, UT_NAMESIZE); - cp->name[UT_NAMESIZE] = '\0'; } return (cp->name); } |