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. Also, some minor cleanup and RCS id police.
This commit is contained in:
parent
c01edc3a02
commit
27643ee095
@ -1,5 +1,5 @@
|
||||
# $NetBSD: Makefile,v 1.13 1996/08/09 09:19:33 thorpej Exp $
|
||||
# from: @(#)Makefile 5.11 (Berkeley) 2/19/91
|
||||
# $Id: Makefile,v 1.12 1996/05/15 21:55:25 jtc Exp $
|
||||
|
||||
PROG= passwd
|
||||
SRCS= local_passwd.c yp_passwd.c passwd.c getpwent.c
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* $NetBSD: kpasswd_proto.h,v 1.2 1996/08/09 09:19:34 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1989 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
@ -31,7 +33,6 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: @(#)kpasswd_proto.h 5.1 (Berkeley) 2/3/91
|
||||
* $Id $
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* $NetBSD: krb5_passwd.c,v 1.2 1996/08/09 09:19:35 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
@ -32,8 +34,11 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
/*static char sccsid[] = "from: @(#)krb_passwd.c 5.4 (Berkeley) 3/1/91";*/
|
||||
static char rcsid[] = "$Id: krb5_passwd.c,v 1.1 1994/07/27 03:28:16 brezak Exp $";
|
||||
#if 0
|
||||
static char sccsid[] = "from: @(#)krb_passwd.c 5.4 (Berkeley) 3/1/91";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: krb5_passwd.c,v 1.2 1996/08/09 09:19:35 thorpej Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef KERBEROS5
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* $NetBSD: krb_passwd.c,v 1.2 1996/08/09 09:19:36 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
@ -32,8 +34,11 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
/*static char sccsid[] = "from: @(#)krb_passwd.c 5.4 (Berkeley) 3/1/91";*/
|
||||
static char rcsid[] = "$Id: krb_passwd.c,v 1.1 1994/07/27 03:28:19 brezak Exp $";
|
||||
#if 0
|
||||
static char sccsid[] = "from: @(#)krb_passwd.c 5.4 (Berkeley) 3/1/91";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: krb_passwd.c,v 1.2 1996/08/09 09:19:36 thorpej Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef KERBEROS
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* $NetBSD: local_passwd.c,v 1.9 1996/08/09 09:19:39 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
@ -32,8 +34,11 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
/*static char sccsid[] = "from: @(#)local_passwd.c 5.5 (Berkeley) 5/6/91";*/
|
||||
static char rcsid[] = "$Id: local_passwd.c,v 1.8 1996/05/15 21:55:26 jtc Exp $";
|
||||
#if 0
|
||||
static char sccsid[] = "from: @(#)local_passwd.c 5.5 (Berkeley) 5/6/91";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: local_passwd.c,v 1.9 1996/08/09 09:19:39 thorpej Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -48,7 +53,6 @@ static char rcsid[] = "$Id: local_passwd.c,v 1.8 1996/05/15 21:55:26 jtc Exp $";
|
||||
|
||||
uid_t uid;
|
||||
|
||||
char *progname = "passwd";
|
||||
char *tempname;
|
||||
|
||||
local_passwd(uname)
|
||||
@ -59,10 +63,6 @@ local_passwd(uname)
|
||||
char *getnewpasswd();
|
||||
|
||||
if (!(pw = getpwnam(uname))) {
|
||||
#ifdef YP
|
||||
extern int use_yp;
|
||||
if (!use_yp)
|
||||
#endif
|
||||
(void)fprintf(stderr, "passwd: unknown user %s.\n", uname);
|
||||
return(1);
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
.\" $NetBSD: passwd.1,v 1.6 1996/08/09 09:19:40 thorpej Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1990 The Regents of the University of California.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
@ -30,7 +32,6 @@
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" from: @(#)passwd.1 6.11 (Berkeley) 7/24/91
|
||||
.\" $Id: passwd.1,v 1.5 1995/02/12 17:45:56 phil Exp $
|
||||
.\"
|
||||
.Dd July 24, 1991
|
||||
.Dt PASSWD 1
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* $NetBSD: passwd.c,v 1.8 1996/08/09 09:19:41 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
@ -38,10 +40,14 @@ char copyright[] =
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
/*static char sccsid[] = "from: @(#)passwd.c 5.5 (Berkeley) 7/6/91";*/
|
||||
static char rcsid[] = "$Id: passwd.c,v 1.7 1995/02/12 17:45:56 phil Exp $";
|
||||
#if 0
|
||||
static char sccsid[] = "from: @(#)passwd.c 5.5 (Berkeley) 7/6/91";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: passwd.c,v 1.8 1996/08/09 09:19:41 thorpej Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
@ -55,9 +61,12 @@ static char rcsid[] = "$Id: passwd.c,v 1.7 1995/02/12 17:45:56 phil Exp $";
|
||||
|
||||
int use_kerberos;
|
||||
int use_yp;
|
||||
int yppwd;
|
||||
|
||||
extern char *__progname; /* from crt0.o */
|
||||
|
||||
#ifdef YP
|
||||
int force_yp;
|
||||
extern int _yp_check __P((char **)); /* buried deep inside libc */
|
||||
#endif
|
||||
|
||||
main(argc, argv)
|
||||
@ -67,8 +76,6 @@ main(argc, argv)
|
||||
extern int optind;
|
||||
register int ch;
|
||||
char *username;
|
||||
int status = 0;
|
||||
char *basename;
|
||||
|
||||
#if defined(KERBEROS) || defined(KERBEROS5)
|
||||
use_kerberos = 1;
|
||||
@ -77,67 +84,57 @@ main(argc, argv)
|
||||
use_yp = _yp_check(NULL);
|
||||
#endif
|
||||
|
||||
basename = strrchr(argv[0], '/');
|
||||
if (basename == NULL)
|
||||
basename = argv[0];
|
||||
if (strcmp(basename, "yppasswd") == 0) {
|
||||
if (strcmp(__progname, "yppasswd") == 0) {
|
||||
#ifdef YP
|
||||
if (!use_yp) {
|
||||
fprintf(stderr, "yppasswd: YP not in use.\n");
|
||||
exit (1);
|
||||
}
|
||||
if (!use_yp)
|
||||
errx(1, "YP not in use.");
|
||||
use_kerberos = 0;
|
||||
use_yp = 1;
|
||||
force_yp = 1;
|
||||
yppwd = 1;
|
||||
#else
|
||||
fprintf(stderr, "yppasswd: YP not compiled in\n");
|
||||
exit(1);
|
||||
errx(1, "YP support not compiled in.");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
while ((ch = getopt(argc, argv, "lky")) != EOF)
|
||||
while ((ch = getopt(argc, argv, "lky")) != -1)
|
||||
switch (ch) {
|
||||
case 'l': /* change local password file */
|
||||
if (yppwd)
|
||||
usage();
|
||||
use_kerberos = 0;
|
||||
use_yp = 0;
|
||||
break;
|
||||
case 'k': /* change Kerberos password */
|
||||
#if defined(KERBEROS) || defined(KERBEROS5)
|
||||
if (yppwd)
|
||||
usage();
|
||||
use_kerberos = 1;
|
||||
use_yp = 0;
|
||||
break;
|
||||
#else
|
||||
fprintf(stderr, "passwd: Kerberos not compiled in\n");
|
||||
exit(1);
|
||||
errx(1, "Kerberos support not compiled in.");
|
||||
#endif
|
||||
case 'y': /* change YP password */
|
||||
#ifdef YP
|
||||
if (!use_yp) {
|
||||
fprintf(stderr, "passwd: YP not in use.\n");
|
||||
exit(1);
|
||||
}
|
||||
if (yppwd)
|
||||
usage();
|
||||
if (!use_yp)
|
||||
errx(1, "YP not in use.");
|
||||
use_kerberos = 0;
|
||||
use_yp = 1;
|
||||
force_yp = 1;
|
||||
break;
|
||||
#else
|
||||
fprintf(stderr, "passwd: YP not compiled in\n");
|
||||
exit(1);
|
||||
errx(1, "YP support not compiled in.");
|
||||
#endif
|
||||
default:
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
username = getlogin();
|
||||
if (username == NULL) {
|
||||
fprintf(stderr, "passwd: who are you ??\n");
|
||||
exit(1);
|
||||
}
|
||||
if (username == NULL)
|
||||
errx(1, "who are you ??");
|
||||
|
||||
switch(argc) {
|
||||
case 0:
|
||||
@ -145,11 +142,10 @@ main(argc, argv)
|
||||
case 1:
|
||||
#if defined(KERBEROS) || defined(KERBEROS5)
|
||||
if (use_kerberos && strcmp(argv[0], username)) {
|
||||
(void)fprintf(stderr, "passwd: %s\n\t%s\n%s\n",
|
||||
errx(1, "%s\n\t%s\n%s\n",
|
||||
"to change another user's Kerberos password, do",
|
||||
"\"kinit <user>; passwd; kdestroy\";",
|
||||
"to change a user's local passwd, use \"passwd -l <user>\"");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
username = argv[0];
|
||||
@ -164,14 +160,18 @@ main(argc, argv)
|
||||
exit(krb_passwd());
|
||||
#endif
|
||||
#ifdef YP
|
||||
if (force_yp || ((status = local_passwd(username)) && use_yp))
|
||||
if (use_yp)
|
||||
exit(yp_passwd(username));
|
||||
exit(status);
|
||||
#endif
|
||||
exit(local_passwd(username));
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
fprintf(stderr, "usage: passwd [-l] [-k] [-y] user\n");
|
||||
|
||||
if (yppwd)
|
||||
fprintf(stderr, "usage: %s user\n", __progname);
|
||||
else
|
||||
fprintf(stderr, "usage: %s [-l] [-k] [-y] user\n", __progname);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* $NetBSD: yp_passwd.c,v 1.9 1996/08/09 09:19:42 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
@ -30,13 +32,18 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
/*static char sccsid[] = "from: @(#)yp_passwd.c 1.0 2/2/93";*/
|
||||
static char rcsid[] = "$Id: yp_passwd.c,v 1.8 1995/02/08 19:54:12 phil Exp $";
|
||||
#if 0
|
||||
static char sccsid[] = "from: @(#)yp_passwd.c 1.0 2/2/93";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: yp_passwd.c,v 1.9 1996/08/09 09:19:42 thorpej Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef YP
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <netdb.h>
|
||||
@ -54,7 +61,8 @@ static char rcsid[] = "$Id: yp_passwd.c,v 1.8 1995/02/08 19:54:12 phil Exp $";
|
||||
#define _PASSWORD_LEN PASS_MAX
|
||||
#endif
|
||||
|
||||
extern char *progname;
|
||||
extern char *__progname; /* from crt0.o */
|
||||
|
||||
static char *getnewpasswd();
|
||||
static struct passwd *ypgetpwnam();
|
||||
|
||||
@ -70,16 +78,15 @@ pw_error(name, err, eval)
|
||||
|
||||
if (err) {
|
||||
sverrno = errno;
|
||||
(void)fprintf(stderr, "%s: ", progname);
|
||||
(void)fprintf(stderr, "%s: ", __progname);
|
||||
if (name)
|
||||
(void)fprintf(stderr, "%s: ", name);
|
||||
(void)fprintf(stderr, "%s\n", strerror(sverrno));
|
||||
}
|
||||
(void)fprintf(stderr,
|
||||
"%s: YP passwd database unchanged\n", progname);
|
||||
exit(eval);
|
||||
errx(eval, "YP passwd database unchanged");
|
||||
}
|
||||
|
||||
int
|
||||
yp_passwd(username)
|
||||
char *username;
|
||||
{
|
||||
@ -96,57 +103,39 @@ yp_passwd(username)
|
||||
/*
|
||||
* Get local domain
|
||||
*/
|
||||
if (r = yp_get_default_domain(&domain)) {
|
||||
fprintf(stderr, "%s: can't get local YP domain. Reason: %s\n",
|
||||
progname, yperr_string(r));
|
||||
exit(1);
|
||||
}
|
||||
if (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));
|
||||
exit(1);
|
||||
}
|
||||
if ((r = yp_master(domain, "passwd.byname", &master)) != 0)
|
||||
errx(1, "can't find the master YP server. Reason: %s",
|
||||
yperr_string(r));
|
||||
|
||||
/*
|
||||
* Ask the portmapper for the port of the daemon.
|
||||
*/
|
||||
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");
|
||||
exit(1);
|
||||
}
|
||||
YPPASSWDPROC_UPDATE, IPPROTO_UDP)) == 0)
|
||||
errx(1, "master YP server not running yppasswd daemon.\n\t%s\n",
|
||||
"Can't change password.");
|
||||
|
||||
/*
|
||||
* Be sure the port is priviledged
|
||||
*/
|
||||
if (rpcport >= IPPORT_RESERVED) {
|
||||
fprintf(stderr, "%s: yppasswd daemon is on an invalid port.\n",
|
||||
progname);
|
||||
exit(1);
|
||||
}
|
||||
if (rpcport >= IPPORT_RESERVED)
|
||||
errx(1, "yppasswd daemon is on an invalid port.");
|
||||
|
||||
/* Get user's login identity */
|
||||
if (!(pw = ypgetpwnam(username))) {
|
||||
(void)fprintf(stderr, "%s: unknown user %s.\n",
|
||||
progname, username);
|
||||
exit(1);
|
||||
}
|
||||
if (!(pw = ypgetpwnam(username)))
|
||||
errx(1, "unknown user %s", username);
|
||||
|
||||
if (uid && uid != pw->pw_uid) {
|
||||
fprintf(stderr,
|
||||
"%s: you may only change your own password: %s\n",
|
||||
progname, strerror(EACCES));
|
||||
exit(1);
|
||||
}
|
||||
if (uid && uid != pw->pw_uid)
|
||||
errx(1, "you may only change your own password: %s",
|
||||
strerror(EACCES));
|
||||
|
||||
/* prompt for new password */
|
||||
yppasswd.newpw.pw_passwd = getnewpasswd(pw, &yppasswd.oldpass);
|
||||
@ -161,21 +150,23 @@ yp_passwd(username)
|
||||
|
||||
client = clnt_create(master, YPPASSWDPROG, YPPASSWDVERS, "udp");
|
||||
if (client==NULL) {
|
||||
fprintf(stderr, "cannot contact yppasswdd on %s: Reason: %s\n",
|
||||
warnx("cannot contact yppasswdd on %s: Reason: %s",
|
||||
master, yperr_string(YPERR_YPBIND));
|
||||
return(YPERR_YPBIND);
|
||||
}
|
||||
|
||||
client->cl_auth = authunix_create_default();
|
||||
tv.tv_sec = 2;
|
||||
tv.tv_usec = 0;
|
||||
r = clnt_call(client, YPPASSWDPROC_UPDATE,
|
||||
xdr_yppasswd, &yppasswd, xdr_int, &status, tv);
|
||||
xdr_yppasswd, &yppasswd, xdr_int, &status, tv);
|
||||
if (r)
|
||||
fprintf(stderr, "%s: rpc to yppasswdd failed.\n", progname);
|
||||
errx(1, "rpc to yppasswdd failed.");
|
||||
else if (status)
|
||||
printf("Couldn't change YP password.\n");
|
||||
else
|
||||
printf("The YP password has been changed on %s, the master YP passwd server.\n", master);
|
||||
printf("The YP password has been changed on %s, %s\n",
|
||||
master, "the master YP passwd server.");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user