diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2002-07-19 02:38:41 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2002-07-19 02:38:41 +0000 |
commit | e2e599c8ed62c4886dfcebc74b0d3bf7436b418e (patch) | |
tree | 9a49861d623e3d5520a4114bbb545f3beb994dcf /usr.sbin/ypserv/mkalias | |
parent | 1cccfea064ca712bce2bfdebd5da7f086362a656 (diff) |
4344 lines of KNF diff
Diffstat (limited to 'usr.sbin/ypserv/mkalias')
-rw-r--r-- | usr.sbin/ypserv/mkalias/mkalias.c | 105 |
1 files changed, 44 insertions, 61 deletions
diff --git a/usr.sbin/ypserv/mkalias/mkalias.c b/usr.sbin/ypserv/mkalias/mkalias.c index 2537331e8bd..2203dc52054 100644 --- a/usr.sbin/ypserv/mkalias/mkalias.c +++ b/usr.sbin/ypserv/mkalias/mkalias.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mkalias.c,v 1.9 2002/06/09 02:21:55 deraadt Exp $ */ +/* $OpenBSD: mkalias.c,v 1.10 2002/07/19 02:38:40 deraadt Exp $ */ /* * Copyright (c) 1997 Mats O Jansson <moj@stacken.kth.se> @@ -32,7 +32,7 @@ */ #ifndef LINT -static char rcsid[] = "$OpenBSD: mkalias.c,v 1.9 2002/06/09 02:21:55 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: mkalias.c,v 1.10 2002/07/19 02:38:40 deraadt Exp $"; #endif #include <ctype.h> @@ -52,10 +52,7 @@ static char rcsid[] = "$OpenBSD: mkalias.c,v 1.9 2002/06/09 02:21:55 deraadt Exp extern char *__progname; /* from crt0.o */ void -split_address(address, len, user, host) - char *address; - int len; - char *user, *host; +split_address(char *address, int len, char *user, char *host) { char *c, *s, *r; int i = 0; @@ -72,10 +69,9 @@ split_address(address, len, user, host) c++; } *s = '\0'; - } - - if (r = strrchr(address, '!')) { + + if ((r = strrchr(address, '!'))) { s = host; for (c = address; i < len; i++) { if (c == r) { @@ -91,9 +87,7 @@ split_address(address, len, user, host) } int -check_host(address, host, dflag, uflag, Eflag) - char *address, *host; - int dflag, uflag, Eflag; +check_host(char *address, char *host, int dflag, int uflag, int Eflag) { char answer[PACKETSZ]; int status; @@ -117,9 +111,7 @@ check_host(address, host, dflag, uflag, Eflag) } void -capitalize(name, len) - char *name; - int len; +capitalize(char *name, int len) { char last = ' '; char *c; @@ -130,7 +122,7 @@ capitalize(name, len) last = '.'; c++; } - + i = 0; if (last == '.') { for (c = name; i < len; i++) { @@ -139,13 +131,10 @@ capitalize(name, len) last = *c++; } } - } int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { int usage = 0; int eflag = 0; @@ -169,9 +158,9 @@ main(argc, argv) char user[4096], host[4096]; /* XXX: DB bsize = 4096 in ypdb.c */ char datestr[11]; char myname[MAXHOSTNAMELEN]; - + while ((ch = getopt(argc, argv, "Edensuv")) != -1) - switch(ch) { + switch (ch) { case 'E': eflag++; /* Check hostname */ Eflag++; /* .. even check MX records */ @@ -211,45 +200,44 @@ main(argc, argv) if (usage) { fprintf(stderr, - "usage: %s [-v] [-e|-E [-d] [-u]] [-n] input [output]\n", - __progname); + "usage: %s [-v] [-e|-E [-d] [-u]] [-n] input [output]\n", + __progname); exit(1); } - + db = ypdb_open(input, O_RDONLY, 0444); if (db == NULL) { fprintf(stderr, - "%s: Unable to open input database %s\n", - __progname, - input); + "%s: Unable to open input database %s\n", + __progname, input); exit(1); } if (output != NULL) { if (strlen(output) + strlen(YPDB_SUFFIX) > MAXPATHLEN) { fprintf(stderr,"%s: %s: file name too long\n", - __progname, output); + __progname, output); } snprintf(db_outfile, sizeof(db_outfile), - "%s%s", output, YPDB_SUFFIX); + "%s%s", output, YPDB_SUFFIX); slash = strrchr(output, '/'); - if (slash != NULL) - slash[1] = 0; /* truncate to dir */ + if (slash != NULL) + slash[1] = 0; /* truncate to dir */ else *output = 0; /* elminate */ - + /* note: output is now directory where map goes ! */ - - if (strlen(output) + strlen(mapname) - + strlen(YPDB_SUFFIX) > MAXPATHLEN) { + + if (strlen(output) + strlen(mapname) + + strlen(YPDB_SUFFIX) > MAXPATHLEN) { fprintf(stderr,"%s: %s: directory name too long\n", __progname, output); exit(1); } - + snprintf(db_tempname, sizeof(db_tempname), "%s%s%s", output, - mapname, YPDB_SUFFIX); + mapname, YPDB_SUFFIX); fd = mkstemps(db_tempname, 3); if (fd == -1) goto fail; @@ -264,18 +252,15 @@ fail: if (fd != -1) unlink(db_tempname); fprintf(stderr, - "%s: Unable to open output database %s\n", - __progname, - db_outfile); + "%s: Unable to open output database %s\n", + __progname, db_outfile); exit(1); } } - for (key = ypdb_firstkey(db); - key.dptr != NULL; - key = ypdb_nextkey(db)) { - - val = ypdb_fetch(db, key); + for (key = ypdb_firstkey(db); key.dptr != NULL; + key = ypdb_nextkey(db)) { + val = ypdb_fetch(db, key); if (val.dptr == NULL) continue; /* No value */ @@ -295,8 +280,7 @@ fail: if (eflag && check_host(val.dptr, host, dflag, uflag, Eflag)) { printf("Invalid host %s in %*.*s:%*.*s\n", - host, - key.dsize, key.dsize, key.dptr, + host, key.dsize, key.dsize, key.dptr, val.dsize, val.dsize, val.dptr); continue; } @@ -308,22 +292,21 @@ fail: status = ypdb_store(new_db, val, key, YPDB_INSERT); if (status != 0) { printf("%s: problem storing %*.*s %*.*s\n", - __progname, - val.dsize, val.dsize, val.dptr, - key.dsize, key.dsize, key.dptr); + __progname, val.dsize, val.dsize, val.dptr, + key.dsize, key.dsize, key.dptr); } } if (vflag) { printf("%*.*s --> %*.*s\n", - val.dsize, val.dsize, val.dptr, - key.dsize, key.dsize, key.dptr); + val.dsize, val.dsize, val.dptr, + key.dsize, key.dsize, key.dptr); } } if (new_db != NULL) { - snprintf(datestr, sizeof datestr, "%010u", time(NULL)); + snprintf(datestr, sizeof datestr, "%010u", time(NULL)); key.dptr = YP_LAST_KEY; key.dsize = strlen(YP_LAST_KEY); val.dptr = datestr; @@ -331,14 +314,14 @@ fail: status = ypdb_store(new_db, key, val, YPDB_INSERT); if (status != 0) { printf("%s: problem storing %*.*s %*.*s\n", - __progname, - key.dsize, key.dsize, key.dptr, - val.dsize, val.dsize, val.dptr); + __progname, + key.dsize, key.dsize, key.dptr, + val.dsize, val.dsize, val.dptr); } } if (new_db != NULL) { - gethostname(myname, sizeof(myname)); + gethostname(myname, sizeof(myname)); key.dptr = YP_MASTER_KEY; key.dsize = strlen(YP_MASTER_KEY); val.dptr = myname; @@ -346,9 +329,9 @@ fail: status = ypdb_store(new_db, key, val, YPDB_INSERT); if (status != 0) { printf("%s: problem storing %*.*s %*.*s\n", - __progname, - key.dsize, key.dsize, key.dptr, - val.dsize, val.dsize, val.dptr); + __progname, + key.dsize, key.dsize, key.dptr, + val.dsize, val.dsize, val.dptr); } } |