/* Various processing of names.
- Copyright (C) 1988, 92, 94, 96, 97, 1998 Free Software Foundation, Inc.
+ Copyright (C) 1988, 92, 94, 96, 97, 98, 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
static uid_t cached_uid; /* valid only if cached_uname is not empty */
static gid_t cached_gid; /* valid only if cached_gname is not empty */
+/* These variables are valid only if nonempty. */
+static char cached_no_such_uname[UNAME_FIELD_SIZE] = "";
+static char cached_no_such_gname[GNAME_FIELD_SIZE] = "";
+
+/* These variables are valid only if nonzero. It's not worth optimizing
+ the case for weird systems where 0 is not a valid uid or gid. */
+static uid_t cached_no_such_uid = 0;
+static gid_t cached_no_such_gid = 0;
+
/*------------------------------------------.
| Given UID, find the corresponding UNAME. |
`------------------------------------------*/
{
struct passwd *passwd;
+ if (uid != 0 && uid == cached_no_such_uid)
+ {
+ *uname = '\0';
+ return;
+ }
+
if (!cached_uname[0] || uid != cached_uid)
{
passwd = getpwuid (uid);
}
else
{
+ cached_no_such_uid = uid;
*uname = '\0';
return;
}
{
struct group *group;
+ if (gid != 0 && gid == cached_no_such_gid)
+ {
+ *gname = '\0';
+ return;
+ }
+
if (!cached_gname[0] || gid != cached_gid)
{
setgrent (); /* FIXME: why?! */
}
else
{
+ cached_no_such_gid = gid;
*gname = '\0';
return;
}
{
struct passwd *passwd;
+ if (cached_no_such_uname[0]
+ && strncmp (uname, cached_no_such_uname, UNAME_FIELD_SIZE) == 0)
+ return 0;
+
if (!cached_uname[0]
|| uname[0] != cached_uname[0]
|| strncmp (uname, cached_uname, UNAME_FIELD_SIZE) != 0)
strncpy (cached_uname, uname, UNAME_FIELD_SIZE);
}
else
- return 0;
+ {
+ strncpy (cached_no_such_uname, uname, UNAME_FIELD_SIZE);
+ return 0;
+ }
}
*uidp = cached_uid;
return 1;
{
struct group *group;
+ if (cached_no_such_gname[0]
+ && strncmp (gname, cached_no_such_gname, GNAME_FIELD_SIZE) == 0)
+ return 0;
+
if (!cached_gname[0]
|| gname[0] != cached_gname[0]
|| strncmp (gname, cached_gname, GNAME_FIELD_SIZE) != 0)
strncpy (cached_gname, gname, GNAME_FIELD_SIZE);
}
else
- return 0;
+ {
+ strncpy (cached_no_such_gname, gname, GNAME_FIELD_SIZE);
+ return 0;
+ }
}
*gidp = cached_gid;
return 1;