/* idcache.c -- map user and group IDs, cached for speed
- Copyright (C) 1985, 1988, 1989, 1990 Free Software Foundation, Inc.
+ Copyright (C) 1985, 1988, 1989, 1990, 1997 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
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
+#if HAVE_CONFIG_H
+# include <config.h>
#endif
#include <stdio.h>
#include <grp.h>
#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
-#include <string.h>
+# include <string.h>
#else
-#include <strings.h>
+# include <strings.h>
#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+#if HAVE_UNISTD_H
+# include <unistd.h>
#endif
+
#ifndef _POSIX_VERSION
struct passwd *getpwuid ();
struct passwd *getpwnam ();
static struct userid *user_alist;
+#ifdef NOT_USED
/* The members of this list have names not in the local passwd file. */
static struct userid *nouser_alist;
+#endif /* NOT_USED */
-/* Translate UID to a login name or a stringified number,
- with cache. */
+/* Translate UID to a login name, with cache.
+ If UID cannot be resolved, return NULL.
+ Cache lookup failures, too. */
char *
getuser (uid)
{
register struct userid *tail;
struct passwd *pwent;
- char usernum_string[20];
for (tail = user_alist; tail; tail = tail->next)
if (tail->id.u == uid)
pwent = getpwuid (uid);
tail = (struct userid *) xmalloc (sizeof (struct userid));
tail->id.u = uid;
- if (pwent == 0)
- {
- sprintf (usernum_string, "%u", (unsigned) uid);
- tail->name = xstrdup (usernum_string);
- }
- else
- tail->name = xstrdup (pwent->pw_name);
+ tail->name = (pwent ? xstrdup (pwent->pw_name) : NULL);
/* Add to the head of the list, so most recently used is first. */
tail->next = user_alist;
return tail->name;
}
+#ifdef NOT_USED
+
/* Translate USER to a UID, with cache.
Return NULL if there is no such user.
(We also cache which user names have no passwd entry,
return 0;
}
+#endif /* NOT_USED */
+
/* Use the same struct as for userids. */
static struct userid *group_alist;
static struct userid *nogroup_alist;
{
register struct userid *tail;
struct group *grent;
- char groupnum_string[20];
for (tail = group_alist; tail; tail = tail->next)
if (tail->id.g == gid)
grent = getgrgid (gid);
tail = (struct userid *) xmalloc (sizeof (struct userid));
tail->id.g = gid;
- if (grent == 0)
- {
- sprintf (groupnum_string, "%u", (unsigned int) gid);
- tail->name = xstrdup (groupnum_string);
- }
- else
- tail->name = xstrdup (grent->gr_name);
+ tail->name = (grent ? xstrdup (grent->gr_name) : NULL);
/* Add to the head of the list, so most recently used is first. */
tail->next = group_alist;
return tail->name;
}
-/* Translate GROUP to a UID, with cache.
+#ifdef NOT_USED
+
+/* Translate GROUP to a GID, with cache.
Return NULL if there is no such group.
(We also cache which group names have no group entry,
so we don't keep looking them up.) */
nogroup_alist = tail;
return 0;
}
+
+#endif /* NOT_USED */