Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 23 Mar 2002 09:14:14 +0000
From:      markm@freebsd.org
To:        audit@freebsd.org
Subject:   chpass fixes take 2 (commit candidate)
Message-ID:  <200203230914.g2N9EEFc002274@grimreaper.grondar.org>

next in thread | raw e-mail | index | archive | help
Index: Makefile
===================================================================
RCS file: /home/ncvs/src/usr.bin/chpass/Makefile,v
retrieving revision 1.24
diff -u -d -r1.24 Makefile
--- Makefile	13 Sep 2001 06:48:16 -0000	1.24
+++ Makefile	23 Mar 2002 00:51:47 -0000
@@ -2,7 +2,6 @@
 # $FreeBSD: src/usr.bin/chpass/Makefile,v 1.24 2001/09/13 06:48:16 ru Exp $
 
 PROG=	chpass
-CFLAGS+=-Wall
 SRCS=	chpass.c edit.c field.c pw_copy.c pw_scan.c pw_util.c pw_yp.c \
 	table.c util.c ypxfr_misc.c ${GENSRCS}
 GENSRCS=yp.h yp_clnt.c yppasswd.h yppasswd_clnt.c yppasswd_private.h \
Index: chpass.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/chpass/chpass.c,v
retrieving revision 1.20
diff -u -d -r1.20 chpass.c
--- chpass.c	22 Mar 2002 01:19:26 -0000	1.20
+++ chpass.c	23 Mar 2002 00:45:13 -0000
@@ -39,10 +39,11 @@
 
 #ifndef lint
 static const char sccsid[] = "From: @(#)chpass.c	8.4 (Berkeley) 4/2/94";
-static const char rcsid[] =
-  "$FreeBSD: src/usr.bin/chpass/chpass.c,v 1.20 2002/03/22 01:19:26 imp Exp $";
 #endif /* not lint */
 
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/signal.h>
@@ -77,6 +78,8 @@
 void	baduser(void);
 void	usage(void);
 
+char localhost[] = "localhost";
+
 int
 main(argc, argv)
 	int argc;
@@ -135,7 +138,7 @@
 #endif
 				yp_domain = optarg;
 				if (yp_server == NULL)
-					yp_server = "localhost";
+					yp_server = localhost;
 #ifdef PARANOID
 			}
 #endif
Index: chpass.h
===================================================================
RCS file: /home/ncvs/src/usr.bin/chpass/chpass.h,v
retrieving revision 1.4
diff -u -d -r1.4 chpass.h
--- chpass.h	22 Mar 2002 01:19:26 -0000	1.4
+++ chpass.h	23 Mar 2002 00:49:56 -0000
@@ -37,8 +37,9 @@
 struct passwd;
 
 typedef struct _entry {
-	char *prompt;
-	int (*func)(), restricted, len;
+	const char *prompt;
+	int (*func)(char *, struct passwd *, struct _entry *);
+	int restricted, len;
 	char *except, *save;
 } ENTRY;
 
Index: edit.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/chpass/edit.c,v
retrieving revision 1.19
diff -u -d -r1.19 edit.c
--- edit.c	26 Jul 2001 23:27:10 -0000	1.19
+++ edit.c	23 Mar 2002 00:45:42 -0000
@@ -29,14 +29,15 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
- *
- * $FreeBSD: src/usr.bin/chpass/edit.c,v 1.19 2001/07/26 23:27:10 mike Exp $
  */
 
 #ifndef lint
 static const char sccsid[] = "@(#)edit.c	8.3 (Berkeley) 4/2/94";
 #endif /* not lint */
 
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
 #include <sys/param.h>
 #include <sys/stat.h>
 
@@ -100,7 +101,7 @@
 	struct passwd *pw;
 {
 	FILE *fp;
-	char *bp, *p, *ttoa();
+	char *bp, *p;
 
 	if (!(fp = fdopen(fd, "w")))
 		pw_error(tempname, 1, 1);
@@ -260,7 +261,7 @@
 	    pw->pw_name, pw->pw_passwd, (unsigned long)pw->pw_uid, 
 	    (unsigned long)pw->pw_gid, pw->pw_class, (long)pw->pw_change,
 	    (long)pw->pw_expire, pw->pw_gecos, pw->pw_dir,
-	    pw->pw_shell) >= sizeof(buf)) {
+	    pw->pw_shell) >= (int)sizeof(buf)) {
 		warnx("entries too long");
 		free(p);
 		return (0);
Index: field.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/chpass/field.c,v
retrieving revision 1.4
diff -u -d -r1.4 field.c
--- field.c	6 Dec 1998 22:58:14 -0000	1.4
+++ field.c	23 Mar 2002 00:45:59 -0000
@@ -35,6 +35,9 @@
 static const char sccsid[] = "@(#)field.c	8.4 (Berkeley) 4/2/94";
 #endif /* not lint */
 
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
 #include <sys/param.h>
 #include <sys/stat.h>
 
@@ -56,7 +59,7 @@
 p_login(p, pw, ep)
 	char *p;
 	struct passwd *pw;
-	ENTRY *ep;
+	ENTRY *ep __unused;
 {
 	if (!*p) {
 		warnx("empty login field");
@@ -85,10 +88,10 @@
 p_passwd(p, pw, ep)
 	char *p;
 	struct passwd *pw;
-	ENTRY *ep;
+	ENTRY *ep __unused;
 {
 	if (!*p)
-		pw->pw_passwd = "";	/* "NOLOGIN"; */
+		pw->pw_passwd = strdup("");	/* "NOLOGIN"; */
 	else if (!(pw->pw_passwd = strdup(p))) {
 		warnx("can't save password entry");
 		return (1);
@@ -102,7 +105,7 @@
 p_uid(p, pw, ep)
 	char *p;
 	struct passwd *pw;
-	ENTRY *ep;
+	ENTRY *ep __unused;
 {
 	uid_t id;
 	char *np;
@@ -130,7 +133,7 @@
 p_gid(p, pw, ep)
 	char *p;
 	struct passwd *pw;
-	ENTRY *ep;
+	ENTRY *ep __unused;
 {
 	struct group *gr;
 	gid_t id;
@@ -163,10 +166,10 @@
 p_class(p, pw, ep)
 	char *p;
 	struct passwd *pw;
-	ENTRY *ep;
+	ENTRY *ep __unused;
 {
 	if (!*p)
-		pw->pw_class = "";
+		pw->pw_class = strdup("");
 	else if (!(pw->pw_class = strdup(p))) {
 		warnx("can't save entry");
 		return (1);
@@ -180,7 +183,7 @@
 p_change(p, pw, ep)
 	char *p;
 	struct passwd *pw;
-	ENTRY *ep;
+	ENTRY *ep __unused;
 {
 	if (!atot(p, &pw->pw_change))
 		return (0);
@@ -193,7 +196,7 @@
 p_expire(p, pw, ep)
 	char *p;
 	struct passwd *pw;
-	ENTRY *ep;
+	ENTRY *ep __unused;
 {
 	if (!atot(p, &pw->pw_expire))
 		return (0);
@@ -205,11 +208,11 @@
 int
 p_gecos(p, pw, ep)
 	char *p;
-	struct passwd *pw;
+	struct passwd *pw __unused;
 	ENTRY *ep;
 {
 	if (!*p)
-		ep->save = "";
+		ep->save = strdup("");
 	else if (!(ep->save = strdup(p))) {
 		warnx("can't save entry");
 		return (1);
@@ -222,7 +225,7 @@
 p_hdir(p, pw, ep)
 	char *p;
 	struct passwd *pw;
-	ENTRY *ep;
+	ENTRY *ep __unused;
 {
 	if (!*p) {
 		warnx("empty home directory field");
@@ -240,13 +243,13 @@
 p_shell(p, pw, ep)
 	char *p;
 	struct passwd *pw;
-	ENTRY *ep;
+	ENTRY *ep __unused;
 {
-	char *t, *ok_shell();
+	char *t;
 	struct stat sbuf;
 
 	if (!*p) {
-		pw->pw_shell = _PATH_BSHELL;
+		pw->pw_shell = strdup(_PATH_BSHELL);
 		return (0);
 	}
 	/* only admin can change from or to "restricted" shells */
Index: pw_copy.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/chpass/pw_copy.c,v
retrieving revision 1.11
diff -u -d -r1.11 pw_copy.c
--- pw_copy.c	18 Mar 2002 02:22:53 -0000	1.11
+++ pw_copy.c	23 Mar 2002 00:46:11 -0000
@@ -37,6 +37,9 @@
 static const char sccsid[] = "@(#)pw_copy.c	8.4 (Berkeley) 4/2/94";
 #endif /* not lint */
 
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
 /*
  * This module is used to copy the master password file, replacing a single
  * record, by chpass(1) and passwd(1).
Index: pw_yp.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/chpass/pw_yp.c,v
retrieving revision 1.19
diff -u -d -r1.19 pw_yp.c
--- pw_yp.c	6 Feb 2002 15:26:04 -0000	1.19
+++ pw_yp.c	23 Mar 2002 09:08:10 -0000
@@ -34,35 +34,39 @@
  * Written by Bill Paul <wpaul@ctr.columbia.edu>
  * Center for Telecommunications Research
  * Columbia University, New York City
- *
- * $FreeBSD: src/usr.bin/chpass/pw_yp.c,v 1.19 2002/02/06 15:26:04 des Exp $
  */
 
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
 #ifdef YP
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <netdb.h>
-#include <time.h>
-#include <sys/types.h>
+#include <sys/param.h>
 #include <sys/stat.h>
-#include <pwd.h>
-#include <errno.h>
-#include <err.h>
-#include <unistd.h>
-#include <db.h>
-#include <fcntl.h>
-#include <utmp.h>
-#include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/param.h>
-#include <limits.h>
+#include <sys/types.h>
+
 #include <rpc/rpc.h>
 #include <rpcsvc/yp.h>
-struct dom_binding {};
 #include <rpcsvc/ypclnt.h>
 #include <rpcsvc/yppasswd.h>
+
+#include <db.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <netdb.h>
 #include <pw_util.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>  
+#include <time.h>
+#include <unistd.h>
+#include <utmp.h>
+
+/* struct dom_binding {}; */
+
 #include "pw_yp.h"
 #include "ypxfr_extern.h"
 #include "yppasswd_private.h"
@@ -77,6 +81,10 @@
         0,              /* lorder */
 };
 
+static char passwdbyname[] = "passwd.byname";
+static char localhost[] = "localhost";
+static char blank[] = "";
+
 int force_old = 0;
 int _use_yp = 0;
 int suser_override = 0;
@@ -139,7 +147,7 @@
 	return;
 }
 
-void
+static void
 copy_local_pass(char *p, int m)
 {
 	register char *t;
@@ -178,7 +186,7 @@
  * environment.
  */
 static int
-my_yp_match(char *server, char *domain, char *map, char *key,
+my_yp_match(char *server, char *domain, const char *map, char *key,
     unsigned long keylen, char **result, unsigned long *resultlen)
 {
 	ypreq_key ypkey;
@@ -194,27 +202,17 @@
 	 * the record we were looking for. Letting use_yp() know
 	 * that the lookup failed is sufficient.
 	 */
-	if ((clnt = clnt_create(server, YPPROG,YPVERS,"udp")) == NULL) {
+	if ((clnt = clnt_create(server, YPPROG,YPVERS,"udp")) == NULL)
 		return(1);
-#ifdef notdef
-		warnx("failed to create UDP handle: %s",
-					clnt_spcreateerror(server));
-		pw_error(tempname, 0, 1);
-#endif
-	}
 
 	ypkey.domain = domain;
-	ypkey.map = map;
+	ypkey.map = strdup(map);
 	ypkey.key.keydat_len = keylen;
 	ypkey.key.keydat_val = key;
 
 	if ((ypval = ypproc_match_2(&ypkey, clnt)) == NULL) {
 		clnt_destroy(clnt);
 		return(1);
-#ifdef notdef
-		warnx("%s",clnt_sperror(clnt,"YPPROC_MATCH failed"));
-		pw_error(tempname, 0, 1);
-#endif
 	}
 
 	clnt_destroy(clnt);
@@ -222,16 +220,6 @@
 	if (ypval->stat != YP_TRUE) {
 		xdr_free(xdr_ypresp_val, (char *)ypval);
 		return(1);
-#ifdef notdef
-		int stat = ypval->stat;
-		xdr_free(xdr_ypresp_val, (char *)ypval);
-		if (stat == YP_NOMAP && strstr(map, "master.passwd"))
-			return(1);
-		if (stat == YP_NOKEY)
-			return(1);
-		warnx("ypmatch failed: %s", yperr_string(ypprot_err(stat)));
-		pw_error(tempname, 0, 1);
-#endif
 	}
 
 
@@ -366,7 +354,7 @@
 
 	/* Get master server of passwd map. */
 
-	if ((mastername = ypxfr_get_master(yp_domain, "passwd.byname",
+	if ((mastername = ypxfr_get_master(yp_domain, passwdbyname,
 				yp_server, yp_server ? 0 : 1)) == NULL) {
 		warnx("can't get name of master NIS server");
 		pw_error(tempname, 0, 1);
@@ -394,11 +382,11 @@
 	}
 
 	/* See if _we_ are the master server. */
-	if (!force_old && !getuid() && (localport = getrpcport("localhost",
+	if (!force_old && !getuid() && (localport = getrpcport(localhost,
 		YPPASSWDPROG, YPPASSWDPROC_UPDATE, IPPROTO_UDP)) != 0) {
 		if (localport == rval) {
 			suser_override = 1;
-			mastername = "localhost";
+			mastername = localhost;
 		}
 	}
 
@@ -427,7 +415,7 @@
 	CLIENT *clnt;
 	char *master, *password;
 	int *status = NULL;
-	struct rpc_err err;
+	struct rpc_err lerr;
 
 	nconf = NULL;
 	_use_yp = 1;
@@ -449,9 +437,10 @@
 		master_yppasswd.newpw.pw_gecos = strdup(pw->pw_gecos);
 		master_yppasswd.newpw.pw_dir = strdup(pw->pw_dir);
 		master_yppasswd.newpw.pw_shell = strdup(pw->pw_shell);
-		master_yppasswd.newpw.pw_class = pw->pw_class != NULL ?
-						strdup(pw->pw_class) : "";
-		master_yppasswd.oldpass = ""; /* not really needed */
+		master_yppasswd.newpw.pw_class = pw->pw_class != NULL
+						? strdup(pw->pw_class)
+						: blank;
+		master_yppasswd.oldpass = blank; /* not really needed */
 		master_yppasswd.domain = yp_domain;
 	} else {
 		yppasswd.newpw.pw_passwd = strdup(pw->pw_passwd);
@@ -461,7 +450,7 @@
 		yppasswd.newpw.pw_gecos = strdup(pw->pw_gecos);
 		yppasswd.newpw.pw_dir = strdup(pw->pw_dir);
 		yppasswd.newpw.pw_shell = strdup(pw->pw_shell);
-		yppasswd.oldpass = "";
+		yppasswd.oldpass = blank;
 	}
 
 	/* Get the user's password for authentication purposes. */
@@ -519,15 +508,15 @@
 	else
 		status = yppasswdproc_update_1(&yppasswd, clnt);
 
-	clnt_geterr(clnt, &err);
+	clnt_geterr(clnt, &lerr);
 
 	auth_destroy(clnt->cl_auth);
 	clnt_destroy(clnt);
 
 	/* Call failed: signal the error. */
 
-	if (err.re_status != RPC_SUCCESS || status == NULL || *status) {
-		warnx("NIS update failed: %s", clnt_sperrno(err.re_status));
+	if (lerr.re_status != RPC_SUCCESS || status == NULL || *status) {
+		warnx("NIS update failed: %s", clnt_sperrno(lerr.re_status));
 		pw_error(NULL, 0, 1);
 	}
 
Index: table.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/chpass/table.c,v
retrieving revision 1.7
diff -u -d -r1.7 table.c
--- table.c	23 Feb 1999 02:41:26 -0000	1.7
+++ table.c	23 Mar 2002 00:46:44 -0000
@@ -35,6 +35,9 @@
 static const char sccsid[] = "@(#)table.c	8.3 (Berkeley) 4/2/94";
 #endif /* not lint */
 
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
 #include <sys/types.h>
 #include <stddef.h>
 #include "chpass.h"
@@ -43,23 +46,23 @@
 char e2[] = ":,";
 
 ENTRY list[] = {
-	{ "login",		p_login,  1,   5, e1,   },
-	{ "password",		p_passwd, 1,   8, e1,   },
-	{ "uid",		p_uid,    1,   3, e1,   },
-	{ "gid",		p_gid,    1,   3, e1,   },
-	{ "class",		p_class,  1,   5, e1,   },
-	{ "change",		p_change, 1,   6, NULL, },
-	{ "expire",		p_expire, 1,   6, NULL, },
+	{ "login",		p_login,  1,   5, e1,   NULL },
+	{ "password",		p_passwd, 1,   8, e1,   NULL },
+	{ "uid",		p_uid,    1,   3, e1,   NULL },
+	{ "gid",		p_gid,    1,   3, e1,   NULL },
+	{ "class",		p_class,  1,   5, e1,   NULL },
+	{ "change",		p_change, 1,   6, NULL, NULL },
+	{ "expire",		p_expire, 1,   6, NULL, NULL },
 #ifdef RESTRICT_FULLNAME_CHANGE		/* do not allow fullname changes */
-	{ "full name",		p_gecos,  1,   9, e2,   },
+	{ "full name",		p_gecos,  1,   9, e2,   NULL },
 #else
-	{ "full name",		p_gecos,  0,   9, e2,   },
+	{ "full name",		p_gecos,  0,   9, e2,   NULL },
 #endif
-	{ "office phone",	p_gecos,  0,  12, e2,   },
-	{ "home phone",		p_gecos,  0,  10, e2,   },
-	{ "office location",	p_gecos,  0,  15, e2,   },
-	{ "other information",	p_gecos,  0,  11, e1,   },
-	{ "home directory",	p_hdir,   1,  14, e1,   },
-	{ "shell",		p_shell,  0,   5, e1,   },
-	{ NULL, 0, },
+	{ "office phone",	p_gecos,  0,  12, e2,   NULL },
+	{ "home phone",		p_gecos,  0,  10, e2,   NULL },
+	{ "office location",	p_gecos,  0,  15, e2,   NULL },
+	{ "other information",	p_gecos,  0,  11, e1,   NULL },
+	{ "home directory",	p_hdir,   1,  14, e1,   NULL },
+	{ "shell",		p_shell,  0,   5, e1,   NULL },
+	{ NULL, NULL, 0, 0, NULL, NULL },
 };
Index: util.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/chpass/util.c,v
retrieving revision 1.9
diff -u -d -r1.9 util.c
--- util.c	18 Mar 2002 09:49:18 -0000	1.9
+++ util.c	23 Mar 2002 00:46:57 -0000
@@ -32,13 +32,12 @@
  */
 
 #ifndef lint
-#if 0
-static char sccsid[] = "@(#)util.c	8.4 (Berkeley) 4/2/94";
-#endif
-static const char rcsid[] =
-  "$FreeBSD: src/usr.bin/chpass/util.c,v 1.9 2002/03/18 09:49:18 cjc Exp $";
+static const char sccsid[] = "@(#)util.c	8.4 (Berkeley) 4/2/94";
 #endif /* not lint */
 
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
 #include <sys/types.h>
 
 #include <ctype.h>
@@ -52,7 +51,7 @@
 #include "chpass.h"
 #include "pathnames.h"
 
-static char *months[] =
+static const char *months[] =
 	{ "January", "February", "March", "April", "May", "June",
 	  "July", "August", "September", "October", "November",
 	  "December", NULL };
@@ -80,7 +79,8 @@
 	time_t *store;
 {
 	static struct tm *lt;
-	char *t, **mp;
+	char *t;
+	const char **mp;
 	time_t tval;
 	int day, month, year;
 

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200203230914.g2N9EEFc002274>