Updating usr.bin/passwd

Change-Id: I5512cd44cb9f1684350050d4e3fb5bb4d1c9b6b1
This commit is contained in:
Lionel Sambuc 2012-12-12 11:53:34 +01:00
parent 2bc7c627ac
commit e8235bc09a
6 changed files with 60 additions and 59 deletions

View file

@ -129,7 +129,7 @@
2009/08/15 20:44:56,usr.bin/mktemp 2009/08/15 20:44:56,usr.bin/mktemp
2012/10/17 12:00:00,usr.bin/nbperf 2012/10/17 12:00:00,usr.bin/nbperf
2010/05/14 17:28:23,usr.bin/newgrp 2010/05/14 17:28:23,usr.bin/newgrp
2012/10/17 12:00:00,usr.bin/passwd/Makefile 2012/10/17 12:00:00,usr.bin/passwd
2010/02/19 16:35:27,usr.bin/sed 2010/02/19 16:35:27,usr.bin/sed
2010/05/27 08:40:19,usr.bin/seq 2010/05/27 08:40:19,usr.bin/seq
2012/10/17 12:00:00,usr.bin/sort 2012/10/17 12:00:00,usr.bin/sort

View file

@ -3,11 +3,6 @@
.include <bsd.own.mk> .include <bsd.own.mk>
.if defined(__MINIX)
# LSC Until it compiles cleanly...
NOGCCERROR:=yes
.endif
USE_FORT?= yes # setuid USE_FORT?= yes # setuid
PROG= passwd PROG= passwd
SRCS= local_passwd.c passwd.c SRCS= local_passwd.c passwd.c

View file

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.13 2006/03/23 23:37:07 wiz Exp $ */ /* $NetBSD: extern.h,v 1.14 2011/09/16 15:39:27 joerg Exp $ */
/* /*
* Copyright (c) 1994 * Copyright (c) 1994
@ -33,7 +33,7 @@
#ifdef USE_PAM #ifdef USE_PAM
void usage(void); __dead void usage(void);
#ifdef KERBEROS5 #ifdef KERBEROS5
void pwkrb5_usage(const char *); void pwkrb5_usage(const char *);

View file

@ -1,4 +1,4 @@
/* $NetBSD: krb5_passwd.c,v 1.18 2009/04/18 09:04:34 mlelstv Exp $ */ /* $NetBSD: krb5_passwd.c,v 1.20 2012/04/22 23:43:51 christos Exp $ */
/* /*
* Copyright (c) 2000, 2005 The NetBSD Foundation, Inc. * Copyright (c) 2000, 2005 The NetBSD Foundation, Inc.
@ -45,6 +45,17 @@
#include "extern.h" #include "extern.h"
static void
pwkrb5_warn(const char *msg, krb5_context context, krb5_error_code ret)
{
const char *errtxt = krb5_get_error_message(context, ret);
if (errtxt != NULL) {
warnx("%s: %s", msg, errtxt);
krb5_free_error_message(context, errtxt);
} else
warnx("%s: %d", msg, ret);
}
#ifdef USE_PAM #ifdef USE_PAM
void void
@ -68,7 +79,7 @@ pwkrb5_process(const char *username, int argc, char **argv)
{ {
krb5_context context; krb5_context context;
krb5_error_code ret; krb5_error_code ret;
krb5_get_init_creds_opt opt; krb5_get_init_creds_opt *opt;
krb5_principal principal; krb5_principal principal;
krb5_creds cred; krb5_creds cred;
int result_code; int result_code;
@ -125,21 +136,23 @@ pwkrb5_process(const char *username, int argc, char **argv)
if (ret != 0) { if (ret != 0) {
if (ret == ENXIO) if (ret == ENXIO)
errx(1, "Kerberos 5 not in use."); errx(1, "Kerberos 5 not in use.");
warnx("Unable to initialize Kerberos 5: %s", errx(1, "Unable to initialize Kerberos 5: %s", strerror(ret));
krb5_get_err_text(context, ret));
goto bad;
} }
krb5_get_init_creds_opt_init(&opt); ret = krb5_get_init_creds_opt_alloc(context, &opt);
if (ret) {
pwkrb5_warn("failed to allocate opts", context, ret);
goto bad;
}
krb5_get_init_creds_opt_set_tkt_life(&opt, 300L); krb5_get_init_creds_opt_set_tkt_life(opt, 300L);
krb5_get_init_creds_opt_set_forwardable(&opt, FALSE); krb5_get_init_creds_opt_set_forwardable(opt, FALSE);
krb5_get_init_creds_opt_set_proxiable(&opt, FALSE); krb5_get_init_creds_opt_set_proxiable(opt, FALSE);
ret = krb5_parse_name(context, username, &principal); ret = krb5_parse_name(context, username, &principal);
if (ret) { if (ret) {
warnx("failed to parse principal: %s", krb5_get_init_creds_opt_free(context, opt);
krb5_get_err_text(context, ret)); pwkrb5_warn("failed to parse principal", context, ret);
goto bad; goto bad;
} }
@ -151,9 +164,9 @@ pwkrb5_process(const char *username, int argc, char **argv)
NULL, NULL,
0L, 0L,
"kadmin/changepw", "kadmin/changepw",
&opt); opt);
krb5_get_init_creds_opt_free(context, opt);
switch (ret) { switch (ret) {
case 0: case 0:
break; break;
@ -168,8 +181,7 @@ pwkrb5_process(const char *username, int argc, char **argv)
goto bad; goto bad;
default: default:
warnx("failed to get credentials: %s", pwkrb5_warn("failed to get credentials", context, ret);
krb5_get_err_text(context, ret));
goto bad; goto bad;
} }
@ -186,8 +198,7 @@ pwkrb5_process(const char *username, int argc, char **argv)
&result_code_string, &result_code_string,
&result_string); &result_string);
if (ret) { if (ret) {
warnx("unable to set password: %s", pwkrb5_warn("unable to set password", context, ret);
krb5_get_err_text(context, ret));
goto bad; goto bad;
} }
@ -259,14 +270,13 @@ krb5_end(void)
krb5_free_context(defcontext); krb5_free_context(defcontext);
} }
int int
krb5_chpw(const char *username) krb5_chpw(const char *username)
{ {
krb5_error_code ret; krb5_error_code ret;
krb5_context context; krb5_context context;
krb5_principal principal; krb5_principal principal;
krb5_get_init_creds_opt opt; krb5_get_init_creds_opt *opt;
krb5_creds cred; krb5_creds cred;
int result_code; int result_code;
krb5_data result_code_string, result_string; krb5_data result_code_string, result_string;
@ -274,22 +284,25 @@ krb5_chpw(const char *username)
ret = krb5_init_context (&context); ret = krb5_init_context (&context);
if (ret) { if (ret) {
warnx("failed kerberos initialisation: %s", pwkrb5_warn("failed kerberos initialisation", context, ret);
krb5_get_err_text(context, ret));
return 1; return 1;
} }
krb5_get_init_creds_opt_init (&opt); ret = krb5_get_init_creds_opt_alloc (context, &opt);
if (ret) {
pwkrb5_warn("failed to allocate credential opt", context, ret);
return 1;
}
krb5_get_init_creds_opt_set_tkt_life (&opt, 300); krb5_get_init_creds_opt_set_tkt_life (opt, 300);
krb5_get_init_creds_opt_set_forwardable (&opt, FALSE); krb5_get_init_creds_opt_set_forwardable (opt, FALSE);
krb5_get_init_creds_opt_set_proxiable (&opt, FALSE); krb5_get_init_creds_opt_set_proxiable (opt, FALSE);
if(username != NULL) { if(username != NULL) {
ret = krb5_parse_name (context, username, &principal); ret = krb5_parse_name (context, username, &principal);
if (ret) { if (ret) {
warnx("failed to parse principal: %s", krb5_get_init_creds_opt_free (context, opt);
krb5_get_err_text(context, ret)); pwkrb5_warn("failed to parse principal", context, ret);
return 1; return 1;
} }
} else } else
@ -303,8 +316,9 @@ krb5_chpw(const char *username)
NULL, NULL,
0, 0,
"kadmin/changepw", "kadmin/changepw",
&opt); opt);
krb5_get_init_creds_opt_free (context, opt);
switch (ret) { switch (ret) {
case 0: case 0:
break; break;
@ -317,8 +331,7 @@ krb5_chpw(const char *username)
return 1; return 1;
break; break;
default: default:
warnx("failed to get credentials: %s", pwkrb5_warn("failed to get credentials", context, ret);
krb5_get_err_text(context, ret));
return 1; return 1;
} }
krb5_data_zero (&result_code_string); krb5_data_zero (&result_code_string);

View file

@ -1,4 +1,4 @@
/* $NetBSD: local_passwd.c,v 1.34 2010/03/02 16:19:13 gdt Exp $ */ /* $NetBSD: local_passwd.c,v 1.36 2012/03/25 05:55:07 dholland Exp $ */
/*- /*-
* Copyright (c) 1990, 1993, 1994 * Copyright (c) 1990, 1993, 1994
@ -34,7 +34,7 @@
#if 0 #if 0
static char sccsid[] = "from: @(#)local_passwd.c 8.3 (Berkeley) 4/2/94"; static char sccsid[] = "from: @(#)local_passwd.c 8.3 (Berkeley) 4/2/94";
#else #else
__RCSID("$NetBSD: local_passwd.c,v 1.34 2010/03/02 16:19:13 gdt Exp $"); __RCSID("$NetBSD: local_passwd.c,v 1.36 2012/03/25 05:55:07 dholland Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -191,9 +191,7 @@ pwlocal_process(const char *username, int argc, char **argv)
login_close(lc); login_close(lc);
} }
#endif #endif
#if 0
printf("AAA: pw_expiry = %x\n", pw_expiry);
#endif
pw->pw_passwd = getnewpasswd(pw, min_pw_len); pw->pw_passwd = getnewpasswd(pw, min_pw_len);
old_change = pw->pw_change; old_change = pw->pw_change;
pw->pw_change = pw_expiry ? pw_expiry + time(NULL) : 0; pw->pw_change = pw_expiry ? pw_expiry + time(NULL) : 0;
@ -219,7 +217,7 @@ pwlocal_process(const char *username, int argc, char **argv)
pw_copy(pfd, tfd, pw, &old_pw); pw_copy(pfd, tfd, pw, &old_pw);
if (pw_mkdb(username, old_change == pw->pw_change) < 0) if (pw_mkdb(username, old_change == pw->pw_change) < 0)
pw_error((char *)NULL, 0, 1); pw_error(NULL, 0, 1);
syslog(LOG_AUTH | LOG_INFO, syslog(LOG_AUTH | LOG_INFO,
"user %s (UID %lu) successfully changed " "user %s (UID %lu) successfully changed "
@ -232,8 +230,7 @@ pwlocal_process(const char *username, int argc, char **argv)
static int force_local; static int force_local;
int int
local_init(progname) local_init(const char *progname)
const char *progname;
{ {
force_local = 0; force_local = 0;
return (0); return (0);
@ -253,7 +250,7 @@ local_arg(char ch, const char *arg)
} }
int int
local_arg_end() local_arg_end(void)
{ {
if (force_local) if (force_local)
return(PW_USE_FORCE); return(PW_USE_FORCE);
@ -261,14 +258,13 @@ local_arg_end()
} }
void void
local_end() local_end(void)
{ {
/* NOOP */ /* NOOP */
} }
int int
local_chpw(uname) local_chpw(const char *uname)
const char *uname;
{ {
struct passwd *pw; struct passwd *pw;
struct passwd old_pw; struct passwd old_pw;
@ -304,9 +300,7 @@ local_chpw(uname)
login_close(lc); login_close(lc);
} }
#endif #endif
#if 0
printf("pw_expiry = %x, pw->pw_expire = %x\n", pw_expiry, pw->pw_expire);
#endif
pw->pw_passwd = getnewpasswd(pw, min_pw_len); pw->pw_passwd = getnewpasswd(pw, min_pw_len);
old_change = pw->pw_change; old_change = pw->pw_change;
pw->pw_change = pw_expiry ? pw_expiry + time(NULL) : 0; pw->pw_change = pw_expiry ? pw_expiry + time(NULL) : 0;
@ -332,7 +326,7 @@ local_chpw(uname)
pw_copy(pfd, tfd, pw, &old_pw); pw_copy(pfd, tfd, pw, &old_pw);
if (pw_mkdb(uname, old_change == pw->pw_change) < 0) if (pw_mkdb(uname, old_change == pw->pw_change) < 0)
pw_error((char *)NULL, 0, 1); pw_error(NULL, 0, 1);
syslog(LOG_AUTH | LOG_INFO, syslog(LOG_AUTH | LOG_INFO,
"user %s (UID %lu) successfully changed " "user %s (UID %lu) successfully changed "

View file

@ -1,4 +1,4 @@
/* $NetBSD: yp_passwd.c,v 1.35 2010/09/08 13:58:46 christos Exp $ */ /* $NetBSD: yp_passwd.c,v 1.37 2012/03/25 05:55:07 dholland Exp $ */
/* /*
* Copyright (c) 1988, 1990, 1993, 1994 * Copyright (c) 1988, 1990, 1993, 1994
@ -34,7 +34,7 @@
#if 0 #if 0
static char sccsid[] = "from: @(#)local_passwd.c 8.3 (Berkeley) 4/2/94"; static char sccsid[] = "from: @(#)local_passwd.c 8.3 (Berkeley) 4/2/94";
#else #else
__RCSID("$NetBSD: yp_passwd.c,v 1.35 2010/09/08 13:58:46 christos Exp $"); __RCSID("$NetBSD: yp_passwd.c,v 1.37 2012/03/25 05:55:07 dholland Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -70,7 +70,7 @@ __RCSID("$NetBSD: yp_passwd.c,v 1.35 2010/09/08 13:58:46 christos Exp $");
static uid_t uid; static uid_t uid;
static char *domain; static char *domain;
static void __dead static void
pwerror(const char *name, int show_err, int eval) pwerror(const char *name, int show_err, int eval)
{ {
@ -329,8 +329,7 @@ pwyp_process(const char *username, int argc, char **argv)
static int yflag; static int yflag;
int int
yp_init(progname) yp_init(const char *progname)
const char *progname;
{ {
int yppwd; int yppwd;