summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Murray <markm@FreeBSD.org>2002-03-24 10:21:22 +0000
committerMark Murray <markm@FreeBSD.org>2002-03-24 10:21:22 +0000
commit04d1b23be991cae809ac39645d9ac7341ec74885 (patch)
tree570b4de402d47f08b3d2e31389b82165ebf55645
parent12d207dc921798d10a6d3a1371214adbd74a8768 (diff)
downloadpw-darwin-04d1b23be991cae809ac39645d9ac7341ec74885.tar.gz
pw-darwin-04d1b23be991cae809ac39645d9ac7341ec74885.tar.zst
pw-darwin-04d1b23be991cae809ac39645d9ac7341ec74885.zip
Fix warns, ANSIfy, use __FBSDID(), sort headers.
-rw-r--r--chpass/Makefile1
-rw-r--r--chpass/chpass.c17
-rw-r--r--chpass/chpass.h5
-rw-r--r--chpass/edit.c19
-rw-r--r--chpass/field.c65
-rw-r--r--chpass/pw_copy.c8
-rw-r--r--chpass/pw_yp.c95
-rw-r--r--chpass/table.c35
-rw-r--r--chpass/util.c24
9 files changed, 114 insertions, 155 deletions
diff --git a/chpass/Makefile b/chpass/Makefile
index 69b93c0..a84cebc 100644
--- a/chpass/Makefile
+++ b/chpass/Makefile
@@ -2,7 +2,6 @@
# $FreeBSD$
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 \
diff --git a/chpass/chpass.c b/chpass/chpass.c
index f88aa23..433d323 100644
--- a/chpass/chpass.c
+++ b/chpass/chpass.c
@@ -39,10 +39,11 @@ static const char copyright[] =
#ifndef lint
static const char sccsid[] = "From: @(#)chpass.c 8.4 (Berkeley) 4/2/94";
-static const char rcsid[] =
- "$FreeBSD$";
#endif /* not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/signal.h>
@@ -77,10 +78,10 @@ uid_t uid;
void baduser(void);
void usage(void);
+char localhost[] = "localhost";
+
int
-main(argc, argv)
- int argc;
- char **argv;
+main(int argc, char *argv[])
{
enum { NEWSH, LOADENTRY, EDITENTRY, NEWPW, NEWEXP } op;
struct passwd *pw = NULL, lpw, old_pw;
@@ -135,7 +136,7 @@ main(argc, argv)
#endif
yp_domain = optarg;
if (yp_server == NULL)
- yp_server = "localhost";
+ yp_server = localhost;
#ifdef PARANOID
}
#endif
@@ -280,13 +281,13 @@ main(argc, argv)
}
void
-baduser()
+baduser(void)
{
errx(1, "%s", strerror(EACCES));
}
void
-usage()
+usage(void)
{
(void)fprintf(stderr,
diff --git a/chpass/chpass.h b/chpass/chpass.h
index 5b2b608..ef0c708 100644
--- a/chpass/chpass.h
+++ b/chpass/chpass.h
@@ -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;
diff --git a/chpass/edit.c b/chpass/edit.c
index 849d5d9..e671d58 100644
--- a/chpass/edit.c
+++ b/chpass/edit.c
@@ -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$
*/
#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>
@@ -62,8 +63,7 @@ static const char sccsid[] = "@(#)edit.c 8.3 (Berkeley) 4/2/94";
extern char *tempname;
void
-edit(pw)
- struct passwd *pw;
+edit(struct passwd *pw)
{
struct stat begin, end;
char *begin_sum, *end_sum;
@@ -95,12 +95,10 @@ edit(pw)
* set conditional flag if the user gets to edit the shell.
*/
void
-display(fd, pw)
- int fd;
- struct passwd *pw;
+display(int fd, struct passwd *pw)
{
FILE *fp;
- char *bp, *p, *ttoa();
+ char *bp, *p;
if (!(fp = fdopen(fd, "w")))
pw_error(tempname, 1, 1);
@@ -181,8 +179,7 @@ display(fd, pw)
}
int
-verify(pw)
- struct passwd *pw;
+verify(struct passwd *pw)
{
ENTRY *ep;
char *p;
@@ -260,7 +257,7 @@ bad: (void)fclose(fp);
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);
diff --git a/chpass/field.c b/chpass/field.c
index 997d21f..264cf08 100644
--- a/chpass/field.c
+++ b/chpass/field.c
@@ -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>
@@ -51,12 +54,11 @@ static const char sccsid[] = "@(#)field.c 8.4 (Berkeley) 4/2/94";
#include "chpass.h"
#include "pathnames.h"
+static char blank[] = "";
+
/* ARGSUSED */
int
-p_login(p, pw, ep)
- char *p;
- struct passwd *pw;
- ENTRY *ep;
+p_login(char *p, struct passwd *pw, ENTRY *ep __unused)
{
if (!*p) {
warnx("empty login field");
@@ -82,13 +84,10 @@ p_login(p, pw, ep)
/* ARGSUSED */
int
-p_passwd(p, pw, ep)
- char *p;
- struct passwd *pw;
- ENTRY *ep;
+p_passwd(char *p, struct passwd *pw, ENTRY *ep __unused)
{
if (!*p)
- pw->pw_passwd = ""; /* "NOLOGIN"; */
+ pw->pw_passwd = blank; /* "NOLOGIN"; */
else if (!(pw->pw_passwd = strdup(p))) {
warnx("can't save password entry");
return (1);
@@ -99,10 +98,7 @@ p_passwd(p, pw, ep)
/* ARGSUSED */
int
-p_uid(p, pw, ep)
- char *p;
- struct passwd *pw;
- ENTRY *ep;
+p_uid(char *p, struct passwd *pw, ENTRY *ep __unused)
{
uid_t id;
char *np;
@@ -127,10 +123,7 @@ p_uid(p, pw, ep)
/* ARGSUSED */
int
-p_gid(p, pw, ep)
- char *p;
- struct passwd *pw;
- ENTRY *ep;
+p_gid(char *p, struct passwd *pw, ENTRY *ep __unused)
{
struct group *gr;
gid_t id;
@@ -160,13 +153,10 @@ p_gid(p, pw, ep)
/* ARGSUSED */
int
-p_class(p, pw, ep)
- char *p;
- struct passwd *pw;
- ENTRY *ep;
+p_class(char *p, struct passwd *pw, ENTRY *ep __unused)
{
if (!*p)
- pw->pw_class = "";
+ pw->pw_class = blank;
else if (!(pw->pw_class = strdup(p))) {
warnx("can't save entry");
return (1);
@@ -177,10 +167,7 @@ p_class(p, pw, ep)
/* ARGSUSED */
int
-p_change(p, pw, ep)
- char *p;
- struct passwd *pw;
- ENTRY *ep;
+p_change(char *p, struct passwd *pw, ENTRY *ep __unused)
{
if (!atot(p, &pw->pw_change))
return (0);
@@ -190,10 +177,7 @@ p_change(p, pw, ep)
/* ARGSUSED */
int
-p_expire(p, pw, ep)
- char *p;
- struct passwd *pw;
- ENTRY *ep;
+p_expire(char *p, struct passwd *pw, ENTRY *ep __unused)
{
if (!atot(p, &pw->pw_expire))
return (0);
@@ -203,13 +187,10 @@ p_expire(p, pw, ep)
/* ARGSUSED */
int
-p_gecos(p, pw, ep)
- char *p;
- struct passwd *pw;
- ENTRY *ep;
+p_gecos(char *p, struct passwd *pw __unused, ENTRY *ep __unused)
{
if (!*p)
- ep->save = "";
+ ep->save = blank;
else if (!(ep->save = strdup(p))) {
warnx("can't save entry");
return (1);
@@ -219,10 +200,7 @@ p_gecos(p, pw, ep)
/* ARGSUSED */
int
-p_hdir(p, pw, ep)
- char *p;
- struct passwd *pw;
- ENTRY *ep;
+p_hdir(char *p, struct passwd *pw, ENTRY *ep __unused)
{
if (!*p) {
warnx("empty home directory field");
@@ -237,16 +215,13 @@ p_hdir(p, pw, ep)
/* ARGSUSED */
int
-p_shell(p, pw, ep)
- char *p;
- struct passwd *pw;
- ENTRY *ep;
+p_shell(char *p, struct passwd *pw, 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 */
diff --git a/chpass/pw_copy.c b/chpass/pw_copy.c
index 2e86dc3..daebd20 100644
--- a/chpass/pw_copy.c
+++ b/chpass/pw_copy.c
@@ -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).
@@ -78,11 +81,8 @@ pw_equal(char *buf, struct passwd *pw)
&& strcmp(pw->pw_shell, buf_pw.pw_shell) == 0);
}
-
void
-pw_copy(ffd, tfd, pw, old_pw)
- int ffd, tfd;
- struct passwd *pw, *old_pw;
+pw_copy(int ffd, int tfd, struct passwd *pw, struct passwd *old_pw)
{
FILE *from, *to;
int done;
diff --git a/chpass/pw_yp.c b/chpass/pw_yp.c
index cc60073..90fa9e0 100644
--- a/chpass/pw_yp.c
+++ b/chpass/pw_yp.c
@@ -34,35 +34,37 @@
* Written by Bill Paul <wpaul@ctr.columbia.edu>
* Center for Telecommunications Research
* Columbia University, New York City
- *
- * $FreeBSD$
*/
+#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>
+
#include "pw_yp.h"
#include "ypxfr_extern.h"
#include "yppasswd_private.h"
@@ -77,6 +79,10 @@ static HASHINFO openinfo = {
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 +145,7 @@ copy_yp_pass(char *p, int x, int m)
return;
}
-void
+static void
copy_local_pass(char *p, int m)
{
register char *t;
@@ -178,7 +184,7 @@ copy_local_pass(char *p, int m)
* 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 +200,17 @@ my_yp_match(char *server, char *domain, char *map, char *key,
* 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 +218,6 @@ my_yp_match(char *server, char *domain, char *map, char *key,
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 +352,7 @@ get_yp_master(int getserver)
/* 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 +380,11 @@ get_yp_master(int getserver)
}
/* 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 +413,7 @@ yp_submit(struct passwd *pw)
CLIENT *clnt;
char *master, *password;
int *status = NULL;
- struct rpc_err err;
+ struct rpc_err lerr;
nconf = NULL;
_use_yp = 1;
@@ -449,9 +435,10 @@ yp_submit(struct passwd *pw)
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 +448,7 @@ yp_submit(struct passwd *pw)
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 +506,15 @@ yp_submit(struct passwd *pw)
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);
}
diff --git a/chpass/table.c b/chpass/table.c
index 572977f..52e9bb8 100644
--- a/chpass/table.c
+++ b/chpass/table.c
@@ -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 e1[] = ": ";
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 },
};
diff --git a/chpass/util.c b/chpass/util.c
index 2bfde62..8703aeb 100644
--- a/chpass/util.c
+++ b/chpass/util.c
@@ -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$";
+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,14 +51,13 @@ static const char rcsid[] =
#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 };
char *
-ttoa(tval)
- time_t tval;
+ttoa(time_t tval)
{
struct tm *tp;
static char tbuf[50];
@@ -75,12 +73,11 @@ ttoa(tval)
}
int
-atot(p, store)
- char *p;
- time_t *store;
+atot(char *p, time_t *store)
{
static struct tm *lt;
- char *t, **mp;
+ char *t;
+ const char **mp;
time_t tval;
int day, month, year;
@@ -136,8 +133,7 @@ bad: return (1);
}
char *
-ok_shell(name)
- char *name;
+ok_shell(char *name)
{
char *p, *sh;