Slight semantics change: ALWAYS use YP if the system is bound to a
YP server. This is required if the passwd database is to stay in sync if this program is run on the YP server. Note, local passwd database operations can still be performed by passing the -l flag.
This commit is contained in:
parent
27643ee095
commit
51956e9393
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: chpass.c,v 1.8 1996/05/15 21:50:43 jtc Exp $ */
|
||||
/* $NetBSD: chpass.c,v 1.9 1996/08/09 09:22:11 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1988, 1993, 1994
|
||||
|
@ -43,7 +43,7 @@ static char copyright[] =
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)chpass.c 8.4 (Berkeley) 4/2/94";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: chpass.c,v 1.8 1996/05/15 21:50:43 jtc Exp $";
|
||||
static char rcsid[] = "$NetBSD: chpass.c,v 1.9 1996/08/09 09:22:11 thorpej Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -66,14 +66,17 @@ static char rcsid[] = "$NetBSD: chpass.c,v 1.8 1996/05/15 21:50:43 jtc Exp $";
|
|||
#include "chpass.h"
|
||||
#include "pathnames.h"
|
||||
|
||||
char *progname = "chpass";
|
||||
extern char *__progname; /* from crt0.o */
|
||||
|
||||
char *tempname;
|
||||
uid_t uid;
|
||||
int use_yp;
|
||||
|
||||
void (*Pw_error) __P((const char *, int, int));
|
||||
|
||||
#ifdef YP
|
||||
int use_yp;
|
||||
int force_yp = 0;
|
||||
extern struct passwd *ypgetpwnam(), *ypgetpwuid();
|
||||
extern int _yp_check __P((char **)); /* buried deep inside libc */
|
||||
#endif
|
||||
|
||||
void baduser __P((void));
|
||||
|
@ -104,52 +107,55 @@ main(argc, argv)
|
|||
op = NEWSH;
|
||||
arg = optarg;
|
||||
break;
|
||||
#ifdef YP
|
||||
case 'l':
|
||||
use_yp = 0;
|
||||
break;
|
||||
case 'y':
|
||||
if (!use_yp) {
|
||||
warnx("YP not in use.");
|
||||
usage();
|
||||
}
|
||||
force_yp = 1;
|
||||
break;
|
||||
#ifdef YP
|
||||
if (!use_yp)
|
||||
errx(1, "YP not in use.");
|
||||
#else
|
||||
errx(1, "YP support not compiled in.");
|
||||
#endif
|
||||
case '?':
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
#ifdef YP
|
||||
if (use_yp)
|
||||
Pw_error = yppw_error;
|
||||
else
|
||||
#endif
|
||||
Pw_error = pw_error;
|
||||
|
||||
#ifdef YP
|
||||
if (op == LOADENTRY && use_yp)
|
||||
errx(1, "cannot load entry using NIS.\n\tUse the -l flag to load local.");
|
||||
errx(1, "cannot load entry using YP.\n\tUse the -l flag to load local.");
|
||||
#endif
|
||||
uid = getuid();
|
||||
|
||||
if (op == EDITENTRY || op == NEWSH)
|
||||
switch(argc) {
|
||||
case 0:
|
||||
pw = getpwuid(uid);
|
||||
#ifdef YP
|
||||
if (pw && !force_yp)
|
||||
use_yp = 0;
|
||||
else if (use_yp)
|
||||
if (use_yp)
|
||||
pw = ypgetpwuid(uid);
|
||||
else
|
||||
#endif /* YP */
|
||||
pw = getpwuid(uid);
|
||||
if (!pw)
|
||||
errx(1, "unknown user: uid %u\n", uid);
|
||||
break;
|
||||
case 1:
|
||||
pw = getpwnam(*argv);
|
||||
#ifdef YP
|
||||
if (pw && !force_yp)
|
||||
use_yp = 0;
|
||||
else if (use_yp)
|
||||
if (use_yp)
|
||||
pw = ypgetpwnam(*argv);
|
||||
else
|
||||
#endif /* YP */
|
||||
pw = getpwnam(*argv);
|
||||
if (!pw)
|
||||
errx(1, "unknown user: %s", *argv);
|
||||
if (uid && uid != pw->pw_uid)
|
||||
|
@ -164,7 +170,7 @@ main(argc, argv)
|
|||
if (!arg[0])
|
||||
usage();
|
||||
if (p_shell(arg, pw, (ENTRY *)NULL))
|
||||
pw_error((char *)NULL, 0, 1);
|
||||
(*Pw_error)((char *)NULL, 0, 1);
|
||||
}
|
||||
|
||||
if (op == LOADENTRY) {
|
||||
|
@ -175,20 +181,26 @@ main(argc, argv)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
/* Get the passwd lock file and open the passwd file for reading. */
|
||||
pw_init();
|
||||
tfd = pw_lock(0);
|
||||
if (tfd < 0)
|
||||
errx(1, "the passwd file is busy.");
|
||||
pfd = open(_PATH_MASTERPASSWD, O_RDONLY, 0);
|
||||
if (pfd < 0)
|
||||
pw_error(_PATH_MASTERPASSWD, 1, 1);
|
||||
if (!use_yp) {
|
||||
/*
|
||||
* Get the passwd lock file and open the passwd file for
|
||||
* reading.
|
||||
*/
|
||||
pw_init();
|
||||
tfd = pw_lock(0);
|
||||
if (tfd < 0)
|
||||
errx(1, "the passwd file is busy.");
|
||||
pfd = open(_PATH_MASTERPASSWD, O_RDONLY, 0);
|
||||
if (pfd < 0)
|
||||
pw_error(_PATH_MASTERPASSWD, 1, 1);
|
||||
}
|
||||
|
||||
/* Edit the user passwd information if requested. */
|
||||
if (op == EDITENTRY) {
|
||||
dfd = mkstemp(tempname);
|
||||
if (dfd < 0)
|
||||
pw_error(tempname, 1, 1);
|
||||
if (dfd < 0) {
|
||||
(*Pw_error)(tempname, 1, 1);
|
||||
}
|
||||
display(tempname, dfd, pw);
|
||||
edit(tempname, pw);
|
||||
(void)unlink(tempname);
|
||||
|
@ -197,7 +209,7 @@ main(argc, argv)
|
|||
#ifdef YP
|
||||
if (use_yp) {
|
||||
if (pw_yp(pw, uid))
|
||||
pw_error((char *)NULL, 0, 1);
|
||||
yppw_error((char *)NULL, 0, 1);
|
||||
else
|
||||
exit(0);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: chpass.h,v 1.4 1996/05/15 21:50:44 jtc Exp $ */
|
||||
/* $NetBSD: chpass.h,v 1.5 1996/08/09 09:22:14 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1993, 1994
|
||||
|
@ -43,6 +43,8 @@ typedef struct _entry {
|
|||
char *except, *save;
|
||||
} ENTRY;
|
||||
|
||||
extern int use_yp;
|
||||
|
||||
/* Field numbers. */
|
||||
#define E_BPHONE 8
|
||||
#define E_HPHONE 9
|
||||
|
@ -70,3 +72,10 @@ int p_shell __P((char *, struct passwd *, ENTRY *));
|
|||
int p_uid __P((char *, struct passwd *, ENTRY *));
|
||||
char *ttoa __P((time_t));
|
||||
int verify __P((char *, struct passwd *));
|
||||
|
||||
#ifdef YP
|
||||
void yppw_error __P((const char *name, int, int));
|
||||
void yppw_prompt __P((void));
|
||||
#endif
|
||||
|
||||
extern void (*Pw_error) __P((const char *name, int, int));
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: edit.c,v 1.6 1996/05/15 21:50:45 jtc Exp $ */
|
||||
/* $NetBSD: edit.c,v 1.7 1996/08/09 09:22:16 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993, 1994
|
||||
|
@ -37,7 +37,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)edit.c 8.3 (Berkeley) 4/2/94";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: edit.c,v 1.6 1996/05/15 21:50:45 jtc Exp $";
|
||||
static char rcsid[] = "$NetBSD: edit.c,v 1.7 1996/08/09 09:22:16 thorpej Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -66,18 +66,23 @@ edit(tempname, pw)
|
|||
|
||||
for (;;) {
|
||||
if (stat(tempname, &begin))
|
||||
pw_error(tempname, 1, 1);
|
||||
(*Pw_error)(tempname, 1, 1);
|
||||
pw_edit(1, tempname);
|
||||
if (stat(tempname, &end))
|
||||
pw_error(tempname, 1, 1);
|
||||
(*Pw_error)(tempname, 1, 1);
|
||||
if (begin.st_mtime == end.st_mtime) {
|
||||
warnx("no changes made");
|
||||
unlink(tempname);
|
||||
pw_error(NULL, 0, 0);
|
||||
(*Pw_error)(NULL, 0, 0);
|
||||
}
|
||||
if (verify(tempname, pw))
|
||||
break;
|
||||
pw_prompt();
|
||||
#ifdef YP
|
||||
if (use_yp)
|
||||
yppw_prompt();
|
||||
else
|
||||
#endif
|
||||
pw_prompt();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,10 +101,11 @@ display(tempname, fd, pw)
|
|||
char *bp, *p, *ttoa();
|
||||
|
||||
if (!(fp = fdopen(fd, "w")))
|
||||
pw_error(tempname, 1, 1);
|
||||
(*Pw_error)(tempname, 1, 1);
|
||||
|
||||
(void)fprintf(fp,
|
||||
"#Changing user database information for %s.\n", pw->pw_name);
|
||||
"#Changing user %sdatabase information for %s.\n",
|
||||
use_yp ? "YP " : "", pw->pw_name);
|
||||
if (!uid) {
|
||||
(void)fprintf(fp, "Login: %s\n", pw->pw_name);
|
||||
(void)fprintf(fp, "Password: %s\n", pw->pw_passwd);
|
||||
|
@ -151,9 +157,9 @@ verify(tempname, pw)
|
|||
static char buf[LINE_MAX];
|
||||
|
||||
if (!(fp = fopen(tempname, "r")))
|
||||
pw_error(tempname, 1, 1);
|
||||
(*Pw_error)(tempname, 1, 1);
|
||||
if (fstat(fileno(fp), &sb))
|
||||
pw_error(tempname, 1, 1);
|
||||
(*Pw_error)(tempname, 1, 1);
|
||||
if (sb.st_size == 0) {
|
||||
warnx("corrupted temporary file");
|
||||
goto bad;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: pw_yp.c,v 1.5 1995/03/26 04:55:33 glass Exp $ */
|
||||
/* $NetBSD: pw_yp.c,v 1.6 1996/08/09 09:22:18 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988 The Regents of the University of California.
|
||||
|
@ -36,7 +36,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)pw_yp.c 1.0 2/2/93";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: pw_yp.c,v 1.5 1995/03/26 04:55:33 glass Exp $";
|
||||
static char rcsid[] = "$NetBSD: pw_yp.c,v 1.6 1996/08/09 09:22:18 thorpej Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -55,8 +55,6 @@ static char rcsid[] = "$NetBSD: pw_yp.c,v 1.5 1995/03/26 04:55:33 glass Exp $";
|
|||
#include <rpcsvc/yppasswd.h>
|
||||
#undef passwd
|
||||
|
||||
extern char *progname;
|
||||
|
||||
static char *domain;
|
||||
|
||||
pw_yp(pw, uid)
|
||||
|
@ -74,21 +72,18 @@ pw_yp(pw, uid)
|
|||
/*
|
||||
* Get local domain
|
||||
*/
|
||||
if (!domain && (r = yp_get_default_domain(&domain))) {
|
||||
fprintf(stderr, "%s: can't get local YP domain. Reason: %s\n",
|
||||
progname, yperr_string(r));
|
||||
return(0);
|
||||
}
|
||||
if (!domain && (r = yp_get_default_domain(&domain)))
|
||||
errx(1, "can't get local YP domain. Reason: %s",
|
||||
yperr_string(r));
|
||||
|
||||
/*
|
||||
* Find the host for the passwd map; it should be running
|
||||
* the daemon.
|
||||
*/
|
||||
if ((r = yp_master(domain, "passwd.byname", &master)) != 0) {
|
||||
fprintf(stderr,
|
||||
"%s: can't find the master YP server. Reason: %s\n",
|
||||
progname, yperr_string(r));
|
||||
return(0);
|
||||
warnx("can't find the master YP server. Reason: %s",
|
||||
yperr_string(r));
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -96,21 +91,17 @@ pw_yp(pw, uid)
|
|||
*/
|
||||
if ((rpcport = getrpcport(master, YPPASSWDPROG, YPPASSWDPROC_UPDATE,
|
||||
IPPROTO_UDP)) == 0) {
|
||||
fprintf(stderr,
|
||||
"%s: master YP server not running yppasswd daemon.\n",
|
||||
progname);
|
||||
fprintf(stderr, "\tCan't change password.\n");
|
||||
return(0);
|
||||
warnx("master YP server not running yppasswd daemon.\n\t%s\n",
|
||||
"Can't change password.");
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Be sure the port is priviledged
|
||||
*/
|
||||
if (rpcport >= IPPORT_RESERVED) {
|
||||
(void)fprintf(stderr,
|
||||
"%s: yppasswd daemon running on an invalid port.\n",
|
||||
progname);
|
||||
return(0);
|
||||
warnx("yppasswd daemon is on an invalid port.");
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* prompt for old password */
|
||||
|
@ -118,10 +109,10 @@ pw_yp(pw, uid)
|
|||
yppasswd.oldpass = "none";
|
||||
yppasswd.oldpass = getpass("Old password:");
|
||||
if (!yppasswd.oldpass) {
|
||||
(void)fprintf(stderr, "Cancelled.\n");
|
||||
return(0);
|
||||
warnx("Cancelled.");
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
/* tell rpc.yppasswdd */
|
||||
yppasswd.newpw.pw_name = pw->pw_name;
|
||||
yppasswd.newpw.pw_passwd= pw->pw_passwd;
|
||||
|
@ -133,9 +124,9 @@ pw_yp(pw, uid)
|
|||
|
||||
client = clnt_create(master, YPPASSWDPROG, YPPASSWDVERS, "udp");
|
||||
if (client==NULL) {
|
||||
fprintf(stderr, "can't contact yppasswdd on %s: Reason: %s\n",
|
||||
warnx("cannot contact yppasswdd on %s: Reason: %s",
|
||||
master, yperr_string(YPERR_YPBIND));
|
||||
return(0);
|
||||
return (1);
|
||||
}
|
||||
client->cl_auth = authunix_create_default();
|
||||
tv.tv_sec = 5;
|
||||
|
@ -143,15 +134,15 @@ pw_yp(pw, uid)
|
|||
r = clnt_call(client, YPPASSWDPROC_UPDATE,
|
||||
xdr_yppasswd, &yppasswd, xdr_int, &status, tv);
|
||||
if (r) {
|
||||
fprintf(stderr, "%s: rpc to yppasswdd failed. %d\n", progname, r);
|
||||
return(0);
|
||||
} else if (status) {
|
||||
printf("Couldn't change YP password information.\n");
|
||||
return(0);
|
||||
}
|
||||
printf("The YP password information has been changed on %s, the master YP passwd server.\n", master);
|
||||
|
||||
return(1);
|
||||
warnx("rpc to yppasswdd failed.");
|
||||
return (1);
|
||||
} else if (status)
|
||||
printf("Couldn't change YP password.\n");
|
||||
else
|
||||
printf("%s %s, %s\n",
|
||||
"The YP password information has been changed on",
|
||||
master, "the master YP passwd server.");
|
||||
return (0);
|
||||
}
|
||||
|
||||
static char *
|
||||
|
@ -218,11 +209,9 @@ ypgetpwnam(nam)
|
|||
/*
|
||||
* Get local domain
|
||||
*/
|
||||
if (!domain && (reason = yp_get_default_domain(&domain))) {
|
||||
fprintf(stderr, "%s: can't get local YP domain. Reason: %s\n",
|
||||
progname, yperr_string(reason));
|
||||
exit(1);
|
||||
}
|
||||
if (!domain && (reason = yp_get_default_domain(&domain)))
|
||||
errx(1, "can't get local YP domain. Reason: %s",
|
||||
yperr_string(reason));
|
||||
|
||||
reason = yp_match(domain, "passwd.byname", nam, strlen(nam),
|
||||
&val, &vallen);
|
||||
|
@ -250,11 +239,9 @@ ypgetpwuid(uid)
|
|||
int reason, vallen;
|
||||
char namebuf[16];
|
||||
|
||||
if (!domain && (reason = yp_get_default_domain(&domain))) {
|
||||
fprintf(stderr, "%s: can't get local YP domain. Reason: %s\n",
|
||||
progname, yperr_string(reason));
|
||||
exit(1);
|
||||
}
|
||||
if (!domain && (reason = yp_get_default_domain(&domain)))
|
||||
errx(1, "can't get local YP domain. Reason: %s\n",
|
||||
yperr_string(reason));
|
||||
|
||||
sprintf(namebuf, "%d", uid);
|
||||
reason = yp_match(domain, "passwd.byuid", namebuf, strlen(namebuf),
|
||||
|
@ -273,4 +260,29 @@ ypgetpwuid(uid)
|
|||
return(interpret(&pwent, line));
|
||||
}
|
||||
|
||||
void
|
||||
yppw_error(name, err, eval)
|
||||
const char *name;
|
||||
int err, eval;
|
||||
{
|
||||
|
||||
if (err)
|
||||
warn(name);
|
||||
|
||||
errx(eval, "YP passwd information unchanged");
|
||||
}
|
||||
|
||||
void
|
||||
yppw_prompt()
|
||||
{
|
||||
int c;
|
||||
|
||||
(void)printf("re-edit the password file? [y]: ");
|
||||
(void)fflush(stdout);
|
||||
c = getchar();
|
||||
if (c != EOF && c != '\n')
|
||||
while (getchar() != '\n');
|
||||
if (c == 'n')
|
||||
yppw_error(NULL, 0, 0);
|
||||
}
|
||||
#endif /* YP */
|
||||
|
|
Loading…
Reference in New Issue