getpwuid() and getpwnam() both support YP maps, insecure and secure.

Remove local ypgetpw{uid,nam} which don't support secure maps.
(Using chpass/chfn with secure maps and these local functions turns off
users by putting * in password entry.)
This commit is contained in:
phil 2000-10-27 16:16:03 +00:00
parent bcab9b6601
commit 18ee5233a8
2 changed files with 6 additions and 131 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: chpass.c,v 1.19 2000/07/07 15:13:22 itojun Exp $ */
/* $NetBSD: chpass.c,v 1.20 2000/10/27 16:16:03 phil Exp $ */
/*-
* Copyright (c) 1988, 1993, 1994
@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1993, 1994\n\
#if 0
static char sccsid[] = "@(#)chpass.c 8.4 (Berkeley) 4/2/94";
#else
__RCSID("$NetBSD: chpass.c,v 1.19 2000/07/07 15:13:22 itojun Exp $");
__RCSID("$NetBSD: chpass.c,v 1.20 2000/10/27 16:16:03 phil Exp $");
#endif
#endif /* not lint */
@ -187,23 +187,13 @@ main(argc, argv)
if (op == EDITENTRY || op == NEWSH) {
if (username != NULL) {
#ifdef YP
if (use_yp)
pw = ypgetpwnam(username);
else
#endif /* YP */
pw = getpwnam(username);
pw = getpwnam(username);
if (pw == NULL)
errx(1, "unknown user: %s", username);
if (uid && uid != pw->pw_uid)
baduser();
} else {
#ifdef YP
if (use_yp)
pw = ypgetpwuid(uid);
else
#endif /* YP */
pw = getpwuid(uid);
pw = getpwuid(uid);
if (pw == NULL)
errx(1, "unknown user: uid %u\n", uid);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pw_yp.c,v 1.17 2000/10/11 14:46:01 is Exp $ */
/* $NetBSD: pw_yp.c,v 1.18 2000/10/27 16:16:03 phil Exp $ */
/*
* Copyright (c) 1988 The Regents of the University of California.
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)pw_yp.c 1.0 2/2/93";
#else
__RCSID("$NetBSD: pw_yp.c,v 1.17 2000/10/11 14:46:01 is Exp $");
__RCSID("$NetBSD: pw_yp.c,v 1.18 2000/10/27 16:16:03 phil Exp $");
#endif
#endif /* not lint */
@ -65,9 +65,6 @@ __RCSID("$NetBSD: pw_yp.c,v 1.17 2000/10/11 14:46:01 is Exp $");
static char *domain;
static struct passwd *interpret __P((struct passwd *, char *));
static char *pwskip __P((char *));
/*
* Check if rpc.yppasswdd is running on the master YP server.
* XXX this duplicates some code, but is much less complex
@ -199,118 +196,6 @@ pw_yp(pw, uid)
return (0);
}
static char *
pwskip(p)
char *p;
{
while (*p && *p != ':' && *p != '\n')
++p;
if (*p)
*p++ = 0;
return (p);
}
static struct passwd *
interpret(pwent, line)
struct passwd *pwent;
char *line;
{
char *p = line;
pwent->pw_passwd = "*";
pwent->pw_uid = 0;
pwent->pw_gid = 0;
pwent->pw_gecos = "";
pwent->pw_dir = "";
pwent->pw_shell = "";
pwent->pw_change = 0;
pwent->pw_expire = 0;
pwent->pw_class = "";
/* line without colon separators is no good, so ignore it */
if(!strchr(p,':'))
return(NULL);
pwent->pw_name = p;
p = pwskip(p);
pwent->pw_passwd = p;
p = pwskip(p);
pwent->pw_uid = (uid_t)strtoul(p, NULL, 10);
p = pwskip(p);
pwent->pw_gid = (gid_t)strtoul(p, NULL, 10);
p = pwskip(p);
pwent->pw_gecos = p;
p = pwskip(p);
pwent->pw_dir = p;
p = pwskip(p);
pwent->pw_shell = p;
while (*p && *p != '\n')
p++;
*p = '\0';
return (pwent);
}
struct passwd *
ypgetpwnam(nam)
const char *nam;
{
static struct passwd pwent;
static char line[1024];
char *val;
int reason, vallen;
/*
* Get local domain
*/
if (!domain && (reason = yp_get_default_domain(&domain)))
errx(1, "can't get local YP domain. Reason: %s",
yperr_string(reason));
val = NULL;
reason = yp_match(domain, "passwd.byname", nam, strlen(nam),
&val, &vallen);
if (reason != 0) {
if (val)
free (val);
return (NULL);
}
val[vallen] = '\0';
(void)strncpy(line, val, sizeof(line) - 1);
free(val);
return(interpret(&pwent, line));
}
struct passwd *
ypgetpwuid(uid)
uid_t uid;
{
static struct passwd pwent;
static char line[1024];
char *val;
int reason, vallen;
char namebuf[16];
if (!domain && (reason = yp_get_default_domain(&domain)))
errx(1, "can't get local YP domain. Reason: %s\n",
yperr_string(reason));
(void)snprintf(namebuf, sizeof namebuf, "%d", uid);
val = NULL;
reason = yp_match(domain, "passwd.byuid", namebuf, strlen(namebuf),
&val, &vallen);
if (reason != 0) {
if (val)
free (val);
return (NULL);
}
val[vallen] = '\0';
(void)strncpy(line, val, sizeof(line) - 1);
free(val);
return(interpret(&pwent, line));
}
void
yppw_error(name, err, eval)
const char *name;