From 04d1b23be991cae809ac39645d9ac7341ec74885 Mon Sep 17 00:00:00 2001 From: Mark Murray Date: Sun, 24 Mar 2002 10:21:22 +0000 Subject: Fix warns, ANSIfy, use __FBSDID(), sort headers. --- chpass/Makefile | 1 - chpass/chpass.c | 17 +++++----- chpass/chpass.h | 5 +-- chpass/edit.c | 19 +++++------- chpass/field.c | 65 ++++++++++++-------------------------- chpass/pw_copy.c | 8 ++--- chpass/pw_yp.c | 95 ++++++++++++++++++++++++-------------------------------- chpass/table.c | 35 +++++++++++---------- chpass/util.c | 24 ++++++-------- 9 files changed, 114 insertions(+), 155 deletions(-) (limited to 'chpass') 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 +__FBSDID("$FreeBSD$"); + #include #include #include @@ -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 +__FBSDID("$FreeBSD$"); + #include #include @@ -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 +__FBSDID("$FreeBSD$"); + #include #include @@ -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 +__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 * Center for Telecommunications Research * Columbia University, New York City - * - * $FreeBSD$ */ +#include +__FBSDID("$FreeBSD$"); + #ifdef YP -#include -#include -#include -#include -#include -#include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include +#include + #include #include -struct dom_binding {}; #include #include + +#include +#include +#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include + #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 +__FBSDID("$FreeBSD$"); + #include #include #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 +__FBSDID("$FreeBSD$"); + #include #include @@ -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; -- cgit v1.2.3-56-ge451