* SUCH DAMAGE.
*/
+#if 0
#ifndef lint
static const char copyright[] =
"@(#) Copyright (c) 1988, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
-#if 0
#ifndef lint
static char sccsid[] = "@(#)chpass.c 8.4 (Berkeley) 4/2/94";
#endif /* not lint */
#endif
-
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/signal.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-#include <ctype.h>
#include <err.h>
#include <errno.h>
-#include <fcntl.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
static void baduser(void);
static void usage(void);
-char localhost[] = "localhost";
-
int
main(int argc, char *argv[])
{
enum { NEWSH, LOADENTRY, EDITENTRY, NEWPW, NEWEXP } op;
- struct passwd *pw = NULL, lpw, *old_pw;
+ struct passwd lpw, *old_pw, *pw;
int ch, pfd, tfd;
const char *password;
char *arg = NULL;
const char *yp_domain = NULL, *yp_host = NULL;
#endif
+ pw = old_pw = NULL;
op = EDITENTRY;
#ifdef YP
while ((ch = getopt(argc, argv, "a:p:s:e:d:h:loy")) != -1)
}
#ifdef YP
- if ((pw->pw_fields & _PWF_SOURCE) == _PWF_NIS) {
+ if (pw != NULL && (pw->pw_fields & _PWF_SOURCE) == _PWF_NIS) {
ypclnt = ypclnt_new(yp_domain, "passwd.byname", yp_host);
master_mode = (ypclnt != NULL &&
ypclnt_connect(ypclnt) != -1 &&
pw_fini();
if (pw == NULL)
err(1, "edit()");
- if (pw_equal(old_pw, pw))
+ /*
+ * pw_equal does not check for crypted passwords, so we
+ * should do it explicitly
+ */
+ if (pw_equal(old_pw, pw) &&
+ strcmp(old_pw->pw_passwd, pw->pw_passwd) == 0)
errx(0, "user information unchanged");
}
#ifdef YP
case _PWF_NIS:
ypclnt = ypclnt_new(yp_domain, "passwd.byname", yp_host);
- if (ypclnt == NULL ||
- ypclnt_connect(ypclnt) == -1 ||
+ if (ypclnt == NULL) {
+ warnx("ypclnt_new failed");
+ exit(1);
+ }
+ if (ypclnt_connect(ypclnt) == -1 ||
ypclnt_passwd(ypclnt, pw, password) == -1) {
warnx("%s", ypclnt->error);
ypclnt_free(ypclnt);
{
(void)fprintf(stderr,
- "Usage: chpass%s %s [user]\n",
+ "usage: chpass%s %s [user]\n",
#ifdef YP
" [-d domain] [-h host]",
#else