summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/ypserv/common/ypdb.c4
-rw-r--r--usr.sbin/ypserv/makedbm/makedbm.c55
-rw-r--r--usr.sbin/ypserv/mkalias/mkalias.c88
-rw-r--r--usr.sbin/ypserv/mknetid/mknetid.c55
-rw-r--r--usr.sbin/ypserv/revnetgroup/revnetgroup.c18
-rw-r--r--usr.sbin/ypserv/stdethers/stdethers.c32
-rw-r--r--usr.sbin/ypserv/ypserv/ypserv.c23
-rw-r--r--usr.sbin/ypserv/ypxfr/ypxfr.c86
8 files changed, 160 insertions, 201 deletions
diff --git a/usr.sbin/ypserv/common/ypdb.c b/usr.sbin/ypserv/common/ypdb.c
index 2ad55aee289..0d9fadde304 100644
--- a/usr.sbin/ypserv/common/ypdb.c
+++ b/usr.sbin/ypserv/common/ypdb.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ypdb.c,v 1.8 2002/07/19 02:38:40 deraadt Exp $ */
+/* $OpenBSD: ypdb.c,v 1.9 2002/07/19 20:59:40 deraadt Exp $ */
/*
* Copyright (c) 1990, 1993
@@ -61,6 +61,7 @@ ypdb_open(const char *file, int flags, int mode)
char path[MAXPATHLEN];
DBM *db;
+ memset(&info, 0, sizeof info);
info.flags = 0;
info.cachesize = 0;
info.maxkeypage = 0;
@@ -85,6 +86,7 @@ ypdb_open_suf(const char *file, int flags, int mode)
BTREEINFO info;
DBM *db;
+ memset(&info, 0, sizeof info);
info.flags = 0;
info.cachesize = 0;
info.maxkeypage = 0;
diff --git a/usr.sbin/ypserv/makedbm/makedbm.c b/usr.sbin/ypserv/makedbm/makedbm.c
index cb3275f988c..4f1ba5b908f 100644
--- a/usr.sbin/ypserv/makedbm/makedbm.c
+++ b/usr.sbin/ypserv/makedbm/makedbm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: makedbm.c,v 1.18 2002/07/19 02:38:40 deraadt Exp $ */
+/* $OpenBSD: makedbm.c,v 1.19 2002/07/19 20:59:40 deraadt Exp $ */
/*
* Copyright (c) 1994-97 Mats O Jansson <moj@stacken.kth.se>
@@ -32,7 +32,7 @@
*/
#ifndef LINT
-static char rcsid[] = "$OpenBSD: makedbm.c,v 1.18 2002/07/19 02:38:40 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: makedbm.c,v 1.19 2002/07/19 20:59:40 deraadt Exp $";
#endif
#include <stdio.h>
@@ -294,6 +294,16 @@ create_database(char *infile, char *database, char *yp_input_file,
}
+void
+usage(void)
+{
+ fprintf(stderr,"usage: makedbm [-u | -U] file\n"
+ " makedbm [-bls] [-i YP_INPUT_FILE] [-o YP_OUTPUT_FILE]\n"
+ " [-d YP_DOMAIN_NAME] [-m YP_MASTER_NAME] "
+ "infile outfile\n");
+ exit(1);
+}
+
int
main(int argc, char *argv[])
{
@@ -301,7 +311,6 @@ main(int argc, char *argv[])
char *yp_input_file, *yp_output_file;
char *yp_master_name,*yp_domain_name;
char *infile,*outfile;
- int usage = 0;
int ch;
extern int optind;
@@ -350,36 +359,24 @@ main(int argc, char *argv[])
uflag++;
break;
default:
- usage++;
+ usage();
break;
}
- if ((uflag != 0) && (aflag != 0)) {
- usage++;
- } else {
-
- if (uflag != 0) {
- if (argc == (optind + 1)) {
- infile = argv[optind];
- } else {
- usage++;
- }
- } else {
- if (argc == (optind + 2)) {
- infile = argv[optind];
- outfile = argv[optind+1];
- } else {
- usage++;
- }
- }
- }
+ if ((uflag != 0) && (aflag != 0))
+ usage();
- if (usage) {
- fprintf(stderr,"%s%s%s",
- "usage:\tmakedbm [-u|-U] file\n\tmakedbm [-bls]",
- " [-i YP_INPUT_FILE] [-o YP_OUTPUT_FILE]\n\t\t",
- "[-d YP_DOMAIN_NAME] [-m YP_MASTER_NAME] infile outfile\n");
- exit(1);
+ if (uflag != 0) {
+ if (argc == (optind + 1))
+ infile = argv[optind];
+ else
+ usage();
+ } else {
+ if (argc == (optind + 2)) {
+ infile = argv[optind];
+ outfile = argv[optind+1];
+ } else
+ usage();
}
if (uflag != 0) {
diff --git a/usr.sbin/ypserv/mkalias/mkalias.c b/usr.sbin/ypserv/mkalias/mkalias.c
index 2203dc52054..fc7f38c4c6d 100644
--- a/usr.sbin/ypserv/mkalias/mkalias.c
+++ b/usr.sbin/ypserv/mkalias/mkalias.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mkalias.c,v 1.10 2002/07/19 02:38:40 deraadt Exp $ */
+/* $OpenBSD: mkalias.c,v 1.11 2002/07/19 20:59: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.10 2002/07/19 02:38:40 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: mkalias.c,v 1.11 2002/07/19 20:59:40 deraadt Exp $";
#endif
#include <ctype.h>
@@ -49,8 +49,6 @@ static char rcsid[] = "$OpenBSD: mkalias.c,v 1.10 2002/07/19 02:38:40 deraadt Ex
#include "ypdb.h"
#include "ypdef.h"
-extern char *__progname; /* from crt0.o */
-
void
split_address(char *address, int len, char *user, char *host)
{
@@ -133,31 +131,29 @@ capitalize(char *name, int len)
}
}
+void
+usage(void)
+{
+ fprintf(stderr,
+ "usage: mkalias [-v] [-e|-E [-d] [-u]] [-n] input [output]\n");
+ exit(1);
+}
+
int
main(int argc, char *argv[])
{
- int usage = 0;
- int eflag = 0;
- int dflag = 0;
- int nflag = 0;
- int sflag = 0;
- int uflag = 0;
- int vflag = 0;
- int Eflag = 0;
- int ch, fd;
- char *input = NULL;
- char *output = NULL;
+ int eflag = 0, dflag = 0, nflag = 0, sflag = 0;
+ int uflag = 0, vflag = 0, Eflag = 0;
+ int status, ch, fd;
+ char *input = NULL, *output = NULL;
DBM *db;
datum key, val;
- char *slash;
DBM *new_db = NULL;
static char mapname[] = "ypdbXXXXXXXXXX";
- char db_mapname[MAXPATHLEN], db_outfile[MAXPATHLEN],
- db_tempname[MAXPATHLEN];
- int status;
+ char db_mapname[MAXPATHLEN], db_outfile[MAXPATHLEN];
+ char db_tempname[MAXPATHLEN];
char user[4096], host[4096]; /* XXX: DB bsize = 4096 in ypdb.c */
- char datestr[11];
- char myname[MAXHOSTNAMELEN];
+ char myname[MAXHOSTNAMELEN], datestr[11], *slash;
while ((ch = getopt(argc, argv, "Edensuv")) != -1)
switch (ch) {
@@ -184,39 +180,31 @@ main(int argc, char *argv[])
vflag++; /* Verbose */
break;
default:
- usage++;
+ usage();
break;
}
- if (optind == argc) {
- usage++;
- } else {
- input = argv[optind++];
- if (optind < argc)
- output = argv[optind++];
- if (optind < argc)
- usage++;
- }
+ if (optind == argc)
+ usage();
- if (usage) {
- fprintf(stderr,
- "usage: %s [-v] [-e|-E [-d] [-u]] [-n] input [output]\n",
- __progname);
- exit(1);
- }
+ input = argv[optind++];
+ if (optind < argc)
+ output = argv[optind++];
+ if (optind < argc)
+ usage();
db = ypdb_open(input, O_RDONLY, 0444);
if (db == NULL) {
fprintf(stderr,
- "%s: Unable to open input database %s\n",
- __progname, input);
+ "mkalias: Unable to open input database %s\n",
+ input);
exit(1);
}
if (output != NULL) {
if (strlen(output) + strlen(YPDB_SUFFIX) > MAXPATHLEN) {
- fprintf(stderr,"%s: %s: file name too long\n",
- __progname, output);
+ fprintf(stderr,"mkalias: %s: file name too long\n",
+ output);
}
snprintf(db_outfile, sizeof(db_outfile),
"%s%s", output, YPDB_SUFFIX);
@@ -231,8 +219,8 @@ main(int argc, char *argv[])
if (strlen(output) + strlen(mapname) +
strlen(YPDB_SUFFIX) > MAXPATHLEN) {
- fprintf(stderr,"%s: %s: directory name too long\n",
- __progname, output);
+ fprintf(stderr,"mkalias: %s: directory name too long\n",
+ output);
exit(1);
}
@@ -252,8 +240,8 @@ fail:
if (fd != -1)
unlink(db_tempname);
fprintf(stderr,
- "%s: Unable to open output database %s\n",
- __progname, db_outfile);
+ "mkalias: Unable to open output database %s\n",
+ db_outfile);
exit(1);
}
}
@@ -291,8 +279,8 @@ fail:
if (new_db != NULL) {
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,
+ printf("mkalias: problem storing %*.*s %*.*s\n",
+ val.dsize, val.dsize, val.dptr,
key.dsize, key.dsize, key.dptr);
}
}
@@ -313,8 +301,7 @@ fail:
val.dsize = strlen(datestr);
status = ypdb_store(new_db, key, val, YPDB_INSERT);
if (status != 0) {
- printf("%s: problem storing %*.*s %*.*s\n",
- __progname,
+ printf("mkalias: problem storing %*.*s %*.*s\n",
key.dsize, key.dsize, key.dptr,
val.dsize, val.dsize, val.dptr);
}
@@ -328,8 +315,7 @@ fail:
val.dsize = strlen(myname);
status = ypdb_store(new_db, key, val, YPDB_INSERT);
if (status != 0) {
- printf("%s: problem storing %*.*s %*.*s\n",
- __progname,
+ printf("mkalias: problem storing %*.*s %*.*s\n",
key.dsize, key.dsize, key.dptr,
val.dsize, val.dsize, val.dptr);
}
diff --git a/usr.sbin/ypserv/mknetid/mknetid.c b/usr.sbin/ypserv/mknetid/mknetid.c
index 0c1a702021a..defa83e1e59 100644
--- a/usr.sbin/ypserv/mknetid/mknetid.c
+++ b/usr.sbin/ypserv/mknetid/mknetid.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mknetid.c,v 1.8 2002/07/19 02:38:40 deraadt Exp $ */
+/* $OpenBSD: mknetid.c,v 1.9 2002/07/19 20:59:40 deraadt Exp $ */
/*
* Copyright (c) 1996 Mats O Jansson <moj@stacken.kth.se>
@@ -32,7 +32,7 @@
*/
#ifndef LINT
-static char rcsid[] = "$OpenBSD: mknetid.c,v 1.8 2002/07/19 02:38:40 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: mknetid.c,v 1.9 2002/07/19 20:59:40 deraadt Exp $";
#endif
#include <sys/param.h>
@@ -84,7 +84,6 @@ char *NetidFile = "/etc/netid";
#define HASHMAX 55
-char *ProgramName = "mknetid";
struct user *root = NULL, *tail = NULL;
struct user *hroot[HASHMAX], *htail[HASHMAX];
@@ -377,8 +376,8 @@ print_passwd_group(int qflag, char *domain)
if (p != u) {
if (!qflag) {
- fprintf(stderr, "%s: unix.%d@%s %s\n",
- ProgramName, u->usr_uid, domain,
+ fprintf(stderr, "mknetid: unix.%d@%s %s\n",
+ u->usr_uid, domain,
"multiply defined, other definitions ignored");
}
} else {
@@ -503,15 +502,21 @@ print_netid(FILE *mfile, char *fname)
}
}
+void
+usage(void)
+{
+ fprintf(stderr,
+ "usage: mknetid [-d domain] [-q] [-p passwdfile] [-g groupfile]\n"
+ " [-h hostfile] [-m netidfile]\n");
+ exit(1);
+}
+
int
main(int argc, char *argv[])
{
- int qflag, ch, usage;
- char *domain;
FILE *pfile, *gfile, *hfile, *mfile;
-
- qflag = usage = 0;
- domain = NULL;
+ int qflag = 0, ch;
+ char *domain = NULL;
while ((ch = getopt(argc, argv, "d:g:h:m:p:q")) != -1)
switch (ch) {
@@ -534,44 +539,34 @@ main(int argc, char *argv[])
qflag++;
break;
default:
- usage++;
+ usage();
break;
}
- if (argc > optind) {
- usage++;
- }
+ if (argc > optind)
+ usage();
- if (usage) {
- fprintf(stderr,
- "usage:\t%s [-d domain] [-q] [-p passwdfile] [-g groupfile]\n"
- "\t\t[-h hostfile] [-m netidfile]\n",
- ProgramName);
- exit(1);
- }
-
- if (domain == NULL) {
+ if (domain == NULL)
yp_get_default_domain(&domain);
- }
pfile = fopen(PasswdFile, "r");
if (pfile == NULL) {
- fprintf(stderr,"%s: can't open file \"%s\"\n",
- ProgramName, PasswdFile);
+ fprintf(stderr,"mknetid: can't open file \"%s\"\n",
+ PasswdFile);
exit(1);
}
gfile = fopen(GroupFile, "r");
if (gfile == NULL) {
- fprintf(stderr,"%s: can't open file \"%s\"\n",
- ProgramName, PasswdFile);
+ fprintf(stderr,"mknetid: can't open file \"%s\"\n",
+ PasswdFile);
exit(1);
}
hfile = fopen(HostFile, "r");
if (hfile == NULL) {
- fprintf(stderr,"%s: can't open file \"%s\"\n",
- ProgramName, PasswdFile);
+ fprintf(stderr,"mknetid: can't open file \"%s\"\n",
+ PasswdFile);
exit(1);
}
diff --git a/usr.sbin/ypserv/revnetgroup/revnetgroup.c b/usr.sbin/ypserv/revnetgroup/revnetgroup.c
index 084ce0e38ca..97776c85dae 100644
--- a/usr.sbin/ypserv/revnetgroup/revnetgroup.c
+++ b/usr.sbin/ypserv/revnetgroup/revnetgroup.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: revnetgroup.c,v 1.3 2002/07/19 02:38:40 deraadt Exp $ */
+/* $OpenBSD: revnetgroup.c,v 1.4 2002/07/19 20:59:40 deraadt Exp $ */
/*
* Copyright (c) 1995
* Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
@@ -47,7 +47,7 @@
#include "hash.h"
#ifndef lint
-static const char rcsid[] = "$OpenBSD: revnetgroup.c,v 1.3 2002/07/19 02:38:40 deraadt Exp $";
+static const char rcsid[] = "$OpenBSD: revnetgroup.c,v 1.4 2002/07/19 20:59:40 deraadt Exp $";
#endif
/* Default location of netgroup file. */
@@ -63,9 +63,9 @@ struct group_entry *gtable[TABLESIZE];
struct member_entry *mtable[TABLESIZE];
void
-usage(char *prog)
+usage(void)
{
- fprintf (stderr,"usage: %s -u|-h [-f netgroup file]\n",prog);
+ fprintf (stderr,"usage: revnetgroup -u|-h [-f netgroup file]\n");
exit(1);
}
@@ -83,21 +83,21 @@ main(int argc, char *argv[])
int hosts = -1, i;
if (argc < 2)
- usage(argv[0]);
+ usage();
while ((ch = getopt(argc, argv, "uhf:")) != -1) {
switch (ch) {
case 'u':
if (hosts != -1) {
warnx("please use only one of -u or -h");
- usage(argv[0]);
+ usage();
}
hosts = 0;
break;
case 'h':
if (hosts != -1) {
warnx("please use only one of -u or -h");
- usage(argv[0]);
+ usage();
}
hosts = 1;
break;
@@ -105,13 +105,13 @@ main(int argc, char *argv[])
netgroup = optarg;
break;
default:
- usage(argv[0]);
+ usage();
break;
}
}
if (hosts == -1)
- usage(argv[0]);
+ usage();
if (strcmp(netgroup, "-")) {
if ((fp = fopen(netgroup, "r")) == NULL) {
diff --git a/usr.sbin/ypserv/stdethers/stdethers.c b/usr.sbin/ypserv/stdethers/stdethers.c
index 37c4706ce34..52690bc9a61 100644
--- a/usr.sbin/ypserv/stdethers/stdethers.c
+++ b/usr.sbin/ypserv/stdethers/stdethers.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: stdethers.c,v 1.5 2002/07/19 02:38:40 deraadt Exp $ */
+/* $OpenBSD: stdethers.c,v 1.6 2002/07/19 20:59:40 deraadt Exp $ */
/*
* Copyright (c) 1995 Mats O Jansson <moj@stacken.kth.se>
@@ -32,7 +32,7 @@
*/
#ifndef LINT
-static char rcsid[] = "$OpenBSD: stdethers.c,v 1.5 2002/07/19 02:38:40 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: stdethers.c,v 1.6 2002/07/19 20:59:40 deraadt Exp $";
#endif
#include <sys/types.h>
@@ -44,8 +44,6 @@ static char rcsid[] = "$OpenBSD: stdethers.c,v 1.5 2002/07/19 02:38:40 deraadt E
#include <string.h>
#include <ctype.h>
-char *ProgramName = "stdethers";
-
extern int ether_line(char *, struct ether_addr *, char *);
extern char *ether_ntoa(struct ether_addr *);
@@ -78,6 +76,7 @@ read_line(FILE *fp, char *buf, int size)
do {
while (fgets(buf, size, fp)) {
int len = strlen(buf);
+
done += len;
if (len > 1 && buf[len-2] == '\\' &&
buf[len-1] == '\n') {
@@ -99,7 +98,14 @@ read_line(FILE *fp, char *buf, int size)
return done;
}
} while (size > 0 && !feof(fp));
- return done;
+ return (done);
+}
+
+void
+usage(void)
+{
+ fprintf(stderr, "usage: stdethers [file]\n");
+ exit(1);
}
int
@@ -107,7 +113,6 @@ main(int argc, char *argv[])
{
FILE *data_file;
char data_line[1024];
- int usage = 0;
int line_no = 0;
int len;
char *p, *k, *v;
@@ -115,18 +120,13 @@ main(int argc, char *argv[])
char hostname[256];
if (argc > 2)
- usage++;
-
- if (usage) {
- fprintf(stderr, "usage: %s [file]\n", ProgramName);
- exit(1);
- }
+ usage();
if (argc == 2) {
data_file = fopen(argv[1], "r");
if (data_file == NULL) {
- fprintf(stderr, "%s: can't open %s\n",
- ProgramName, argv[1]);
+ fprintf(stderr, "stdethers: can't open %s\n",
+ argv[1]);
exit(1);
}
} else
@@ -173,8 +173,8 @@ main(int argc, char *argv[])
fprintf(stdout, "%s\t%s\n", NTOA(&eth_addr),
hostname);
} else {
- fprintf(stderr, "%s: ignoring line %d: \"%s\"\n",
- ProgramName, line_no, data_line);
+ fprintf(stderr, "stdethers: ignoring line %d: \"%s\"\n",
+ line_no, data_line);
}
}
return(0);
diff --git a/usr.sbin/ypserv/ypserv/ypserv.c b/usr.sbin/ypserv/ypserv/ypserv.c
index 36b0d91765c..924921f573f 100644
--- a/usr.sbin/ypserv/ypserv/ypserv.c
+++ b/usr.sbin/ypserv/ypserv/ypserv.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ypserv.c,v 1.23 2002/07/19 02:38:40 deraadt Exp $ */
+/* $OpenBSD: ypserv.c,v 1.24 2002/07/19 20:59:40 deraadt Exp $ */
/*
* Copyright (c) 1994 Mats O Jansson <moj@stacken.kth.se>
@@ -32,7 +32,7 @@
*/
#ifndef LINT
-static char rcsid[] = "$OpenBSD: ypserv.c,v 1.23 2002/07/19 02:38:40 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: ypserv.c,v 1.24 2002/07/19 20:59:40 deraadt Exp $";
#endif
#include <sys/types.h>
@@ -71,7 +71,6 @@ static int _rpcfdtype; /* Whether Stream or Datagram ? */
static int _rpcsvcdirty; /* Still serving ? */
int usedns = FALSE;
-char *progname = "ypserv";
char *aclfile = NULL;
void sig_child(int);
@@ -390,10 +389,17 @@ my_svc_run()
}
}
+void
+usage(void)
+{
+ (void)fprintf(stderr, "usage: ypserv [-a aclfile] [-d] [-x]\n");
+ exit(1);
+}
+
int
main(int argc, char *argv[])
{
- int usage = 0, xflag = 0, allowv1 = 0, ch, sock, proto;
+ int xflag = 0, allowv1 = 0, ch, sock, proto;
struct sockaddr_in saddr;
int asize = sizeof (saddr);
extern char *optarg;
@@ -414,17 +420,12 @@ main(int argc, char *argv[])
xflag = TRUE;
break;
default:
- usage++;
+ usage();
break;
}
- if (usage) {
- (void)fprintf(stderr, "usage: %s [-a aclfile] [-d] [-x]\n",progname);
- exit(1);
- }
-
if (geteuid() != 0) {
- (void)fprintf(stderr, "%s: must be root to run.\n",progname);
+ (void)fprintf(stderr, "ypserv: must be root to run.\n");
exit(1);
}
diff --git a/usr.sbin/ypserv/ypxfr/ypxfr.c b/usr.sbin/ypserv/ypxfr/ypxfr.c
index e1a978fa5d1..12d4e7323b1 100644
--- a/usr.sbin/ypserv/ypxfr/ypxfr.c
+++ b/usr.sbin/ypserv/ypxfr/ypxfr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ypxfr.c,v 1.28 2002/07/19 02:38:40 deraadt Exp $ */
+/* $OpenBSD: ypxfr.c,v 1.29 2002/07/19 20:59:40 deraadt Exp $ */
/*
* Copyright (c) 1994 Mats O Jansson <moj@stacken.kth.se>
@@ -32,7 +32,7 @@
*/
#ifndef LINT
-static const char rcsid[] = "$OpenBSD: ypxfr.c,v 1.28 2002/07/19 02:38:40 deraadt Exp $";
+static const char rcsid[] = "$OpenBSD: ypxfr.c,v 1.29 2002/07/19 20:59:40 deraadt Exp $";
#endif
#include <sys/types.h>
@@ -59,14 +59,8 @@ static const char rcsid[] = "$OpenBSD: ypxfr.c,v 1.28 2002/07/19 02:38:40 deraad
#include "ypdb.h"
#include "ypdef.h"
-extern char *__progname; /* from crt0.o */
DBM *db;
-extern bool_t xdr_ypresp_all_seq();
-
-extern int (*ypresp_allfn)();
-extern void *ypresp_data;
-
static int
ypxfr_foreach(u_long status, char *keystr, int keylen, char *valstr, int vallen,
void *data)
@@ -106,8 +100,8 @@ get_local_ordernum(char *domain, char *map, u_int32_t *lordernum)
snprintf(map_path, sizeof map_path, "%s/%s", YP_DB_PATH, domain);
if (!((stat(map_path, &finfo) == 0) &&
((finfo.st_mode & S_IFMT) == S_IFDIR))) {
- fprintf(stderr, "%s: domain %s not found locally\n",
- __progname, domain);
+ fprintf(stderr, "ypxfr: domain %s not found locally\n",
+ domain);
status = YPPUSH_NODOM;
goto bail;
}
@@ -130,7 +124,7 @@ get_local_ordernum(char *domain, char *map, u_int32_t *lordernum)
k.dptr = (char *)&order_key;
k.dsize = YP_LAST_LEN;
- v = ypdb_fetch(db,k);
+ v = ypdb_fetch(db, k);
ypdb_close(db);
if (v.dptr == NULL) {
@@ -173,11 +167,10 @@ get_map(CLIENT *client, char *domain, char *map,
int status;
status = yp_all_host(client, domain, map, incallback);
- if ((status == 0) || (status == YPERR_NOMORE)) {
+ if (status == 0 || status == YPERR_NOMORE)
status = YPPUSH_SUCC;
- } else {
+ else
status = YPPUSH_YPERR;
- }
return (status);
}
@@ -225,10 +218,9 @@ add_order(DBM *db, u_int32_t ordernum)
int
add_master(CLIENT *client, char *domain, char *map, DBM *db)
{
- char keystr[] = YP_MASTER_KEY;
- char *master;
- int status;
+ char keystr[] = YP_MASTER_KEY, *master;
datum key, val;
+ int status;
master = NULL;
@@ -255,10 +247,8 @@ add_master(CLIENT *client, char *domain, char *map, DBM *db)
int
add_interdomain(CLIENT *client, char *domain, char *map, DBM *db)
{
- char keystr[] = YP_INTERDOMAIN_KEY;
- char *value;
- int vallen;
- int status;
+ char keystr[] = YP_INTERDOMAIN_KEY, *value;
+ int vallen, status;
datum k, v;
/* Get INTERDOMAIN */
@@ -280,7 +270,6 @@ add_interdomain(CLIENT *client, char *domain, char *map, DBM *db)
status = YPPUSH_DBM;
}
}
-
return 1;
}
@@ -304,16 +293,13 @@ add_secure(CLIENT *client, char *domain, char *map, DBM *db)
if (v.dptr != NULL) {
status = ypdb_store(db, k, v, YPDB_INSERT);
- if (status >= 0) {
+ if (status >= 0)
status = YPPUSH_SUCC;
- } else {
+ else
status = YPPUSH_DBM;
- }
}
}
-
return status;
-
}
int
@@ -338,8 +324,8 @@ send_clear(CLIENT *client)
int
send_reply(CLIENT *client, u_long status, u_long tid)
{
- struct timeval tv;
struct ypresp_xfr resp;
+ struct timeval tv;
int r;
tv.tv_sec = 10;
@@ -356,23 +342,27 @@ send_reply(CLIENT *client, u_long status, u_long tid)
}
+void
+usage(void)
+{
+ fprintf(stderr, "usage: ypxfr [-cf] [-d domain] [-h host] [-s domain] "
+ "[-C tid prog ipadd port] mapname\n");
+ exit(1);
+}
+
int
main(int argc, char *argv[])
{
- int usage = 0, cflag = 0, fflag = 0, Cflag = 0;
+ int cflag = 0, fflag = 0, Cflag = 0;
char *domain, *host = NULL, *srcdomain = NULL;
char *tid = NULL, *prog = NULL, *ipadd = NULL;
char *port = NULL, *map = NULL;
int status, xfr_status, ch, srvport;
u_int32_t ordernum, new_ordernum;
struct ypall_callback callback;
- CLIENT *client;
+ CLIENT *client = NULL;
extern char *optarg;
- status = YPPUSH_SUCC;
- client = NULL;
- db = NULL;
-
yp_get_default_domain(&domain);
while ((ch = getopt(argc, argv, "cd:fh:s:C:")) != -1)
@@ -397,11 +387,8 @@ main(int argc, char *argv[])
srcdomain = optarg;
break;
case 'C':
- if (optind + 3 >= argc) {
- usage++;
- optind = argc;
- break;
- }
+ if (optind + 3 >= argc)
+ usage();
Cflag++;
tid = optarg;
prog = argv[optind++];
@@ -409,23 +396,16 @@ main(int argc, char *argv[])
port = argv[optind++];
break;
default:
- usage++;
+ usage();
break;
}
- if (optind + 1 != argc) {
- usage++;
- } else {
- map = argv[optind];
- }
+ status = YPPUSH_SUCC;
- if (usage) {
- status = YPPUSH_BADARGS;
- fprintf(stderr, "usage: %s "
- "[-cf] [-d domain] [-h host] [-s domain] "
- "[-C tid prog ipadd port] mapname\n",
- __progname);
- }
+ if (optind + 1 != argc)
+ usage();
+
+ map = argv[optind];
if (status > 0) {
ypopenlog();
@@ -556,7 +536,5 @@ main(int argc, char *argv[])
status = send_reply(client, xfr_status, atoi(tid));
clnt_destroy(client);
}
-
return (0);
-
}