summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormaja <maja@openbsd.org>1997-07-22 10:52:59 +0000
committermaja <maja@openbsd.org>1997-07-22 10:52:59 +0000
commit2a04ed5aac73896f7b4474f22ec5cf3377f53e7b (patch)
tree853218b1d3c323be93c10bb31a689d3d13c4ec79
parentrange error fix; mckusick@McKusick.COM (diff)
downloadwireguard-openbsd-2a04ed5aac73896f7b4474f22ec5cf3377f53e7b.tar.xz
wireguard-openbsd-2a04ed5aac73896f7b4474f22ec5cf3377f53e7b.zip
Added support for reading db files created by sendmail -bi. This is the
first step to support mail.aliases and mail.byaddr in ypserv. -moj
-rw-r--r--usr.sbin/ypserv/makedbm/Makefile4
-rw-r--r--usr.sbin/ypserv/makedbm/db.c75
-rw-r--r--usr.sbin/ypserv/makedbm/db.h43
-rw-r--r--usr.sbin/ypserv/makedbm/makedbm.824
-rw-r--r--usr.sbin/ypserv/makedbm/makedbm.c46
5 files changed, 166 insertions, 26 deletions
diff --git a/usr.sbin/ypserv/makedbm/Makefile b/usr.sbin/ypserv/makedbm/Makefile
index f883c0fc8cf..42f73962705 100644
--- a/usr.sbin/ypserv/makedbm/Makefile
+++ b/usr.sbin/ypserv/makedbm/Makefile
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile,v 1.2 1996/05/30 09:53:05 deraadt Exp $
+# $OpenBSD: Makefile,v 1.3 1997/07/22 10:52:59 maja Exp $
PROG= makedbm
-SRCS= makedbm.c ypdb.c
+SRCS= makedbm.c ypdb.c db.c
MAN= makedbm.8
.PATH: ${.CURDIR}/../common
CFLAGS+=-I${.CURDIR}/../common
diff --git a/usr.sbin/ypserv/makedbm/db.c b/usr.sbin/ypserv/makedbm/db.c
new file mode 100644
index 00000000000..b676245ed71
--- /dev/null
+++ b/usr.sbin/ypserv/makedbm/db.c
@@ -0,0 +1,75 @@
+/* $OpenBSD: db.c,v 1.1 1997/07/22 10:52:59 maja Exp $ */
+
+/*
+ * Copyright (c) 1997 Mats O Jansson <moj@stacken.kth.se>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Mats O Jansson
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * 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.
+ */
+
+#ifndef LINT
+static char rcsid[] = "$OpenBSD: db.c,v 1.1 1997/07/22 10:52:59 maja Exp $";
+#endif
+
+#include <sys/types.h>
+#include <db.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <sys/param.h>
+#include "db.h"
+#include "ypdb.h"
+
+/*
+ * This module was created to be able to read database files created
+ * by sendmail -bi.
+ */
+
+int db_hash_list_database(database)
+char *database;
+{
+ DB *db;
+ int status;
+ DBT key, val;
+ char path[MAXPATHLEN];
+
+ snprintf(path, sizeof(path), "%s%s", database, ".db");
+
+ db = dbopen(path, O_RDONLY, 0, DB_HASH, NULL);
+ if (db != NULL) {
+ status = db->seq(db, &key, &val, R_FIRST);
+ while (status == 0) {
+ printf("%*.*s %*.*s\n",
+ key.size-1, key.size-1, key.data,
+ val.size-1, val.size-1, val.data);
+ status = db->seq(db, &key, &val, R_NEXT);
+ }
+ db->close(db);
+ return(1);
+ }
+ return(0);
+}
+
diff --git a/usr.sbin/ypserv/makedbm/db.h b/usr.sbin/ypserv/makedbm/db.h
new file mode 100644
index 00000000000..174a67bc16f
--- /dev/null
+++ b/usr.sbin/ypserv/makedbm/db.h
@@ -0,0 +1,43 @@
+/* $OpenBSD: db.h,v 1.1 1997/07/22 10:52:59 maja Exp $ */
+
+/*
+ * Copyright (c) 1997 Mats O Jansson <moj@stacken.kth.se>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Mats O Jansson
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * 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.
+ */
+
+#ifndef _MAKEDBM_DB_H_
+#define _MAKEDBM_DB_H_
+
+__BEGIN_DECLS
+int db_hash_list_database __P((char *));
+__END_DECLS
+
+#endif /* !_MAKEDBM_DB_H_ */
+
+
diff --git a/usr.sbin/ypserv/makedbm/makedbm.8 b/usr.sbin/ypserv/makedbm/makedbm.8
index 648c31dcf05..151d29f9b22 100644
--- a/usr.sbin/ypserv/makedbm/makedbm.8
+++ b/usr.sbin/ypserv/makedbm/makedbm.8
@@ -1,5 +1,5 @@
-.\" $OpenBSD: makedbm.8,v 1.4 1996/06/26 21:26:35 maja Exp $
-.\" Copyright (c) 1994 Mats O Jansson <moj@stacken.kth.se>
+.\" $OpenBSD: makedbm.8,v 1.5 1997/07/22 10:53:00 maja Exp $
+.\" Copyright (c) 1994-97 Mats O Jansson <moj@stacken.kth.se>
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
@@ -36,8 +36,10 @@
.Nd create a YP database
.Sh SYNOPSIS
.Nm makedbm
-.Op Fl u Ar file
-.Nm /usr/sbin/makedbm
+.Fl u Ar file
+.Nm makedbm
+.Fl U Ar file
+.Nm makedbm
.Op Fl bls
.Op Fl i Ar yp_input_file
.Op Fl o Ar yp_output_file
@@ -47,13 +49,19 @@
.Ar outfile
.Sh DESCRIPTION
.Nm Makedbm
-is the utiliy in YP that creates the
-.Xr db 3
-database file containing the YP map.
-.Pp
+is the utiliy in YP that creates the database file containing the YP map.
+The databse format is a slightly modified version of ndbm.
.Pp
The options are as follows:
.Bl -tag -width indent
+.It Fl u
+Dump a database to standard output.
+.It Fl U
+Same as
+.Fl u
+but also try
+.Xr db 3
+hash format.
.It Fl b
Interdomain. Include an entry in the database informing a YP server to use
DNS to get information about unknown hosts. This option will only have
diff --git a/usr.sbin/ypserv/makedbm/makedbm.c b/usr.sbin/ypserv/makedbm/makedbm.c
index 3f902bdb606..35a7be82a77 100644
--- a/usr.sbin/ypserv/makedbm/makedbm.c
+++ b/usr.sbin/ypserv/makedbm/makedbm.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: makedbm.c,v 1.7 1997/04/04 18:41:46 deraadt Exp $ */
+/* $OpenBSD: makedbm.c,v 1.8 1997/07/22 10:53:01 maja Exp $ */
/*
- * Copyright (c) 1994 Mats O Jansson <moj@stacken.kth.se>
+ * Copyright (c) 1994-97 Mats O Jansson <moj@stacken.kth.se>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,7 @@
*/
#ifndef LINT
-static char rcsid[] = "$OpenBSD: makedbm.c,v 1.7 1997/04/04 18:41:46 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: makedbm.c,v 1.8 1997/07/22 10:53:01 maja Exp $";
#endif
#include <stdio.h>
@@ -45,8 +45,9 @@ static char rcsid[] = "$OpenBSD: makedbm.c,v 1.7 1997/04/04 18:41:46 deraadt Exp
#include <sys/errno.h>
#include "ypdb.h"
#include "ypdef.h"
+#include "db.h"
-char *ProgramName = "makedbm";
+extern char *__progname; /* from crt0.o */
/*
* Read one line
@@ -111,7 +112,7 @@ add_record(db, str1, str2, check)
status = ypdb_store(db, key, val, YPDB_INSERT);
if (status != 0) {
- printf("%s: problem storing %s %s\n",ProgramName,str1,str2);
+ printf("%s: problem storing %s %s\n",__progname,str1,str2);
exit(1);
}
}
@@ -129,7 +130,7 @@ file_date(filename)
} else {
status = stat(filename, &finfo);
if (status < 0) {
- fprintf(stderr, "%s: can't stat %s\n", ProgramName, filename);
+ fprintf(stderr, "%s: can't stat %s\n", __progname, filename);
exit(1);
}
sprintf(datestr, "%010d", finfo.st_mtime);
@@ -139,8 +140,9 @@ file_date(filename)
}
void
-list_database(database)
+list_database(database,Uflag)
char *database;
+ int Uflag;
{
DBM *db;
datum key,val;
@@ -148,7 +150,15 @@ list_database(database)
db = ypdb_open(database, O_RDONLY, 0444);
if (db == NULL) {
- fprintf(stderr, "%s: can't open database %s\n", ProgramName, database);
+
+ if (Uflag != 0) {
+
+ if (db_hash_list_database(database)) return;
+
+ }
+
+
+ fprintf(stderr, "%s: can't open database %s\n", __progname, database);
exit(1);
}
@@ -195,7 +205,7 @@ create_database(infile,database,
} else {
data_file = fopen(infile, "r");
if (errno != 0) {
- (void)fprintf(stderr,"%s: ",ProgramName);
+ (void)fprintf(stderr,"%s: ",__progname);
perror(infile);
exit(1);
}
@@ -203,7 +213,7 @@ create_database(infile,database,
if (strlen(database) + strlen(YPDB_SUFFIX) > MAXPATHLEN) {
fprintf(stderr,"%s: %s: file name too long\n",
- ProgramName, database);
+ __progname, database);
exit(1);
}
snprintf(db_outfile, sizeof(db_outfile), "%s%s", database, YPDB_SUFFIX);
@@ -219,7 +229,7 @@ create_database(infile,database,
if (strlen(database) + strlen(mapname)
+ strlen(YPDB_SUFFIX) > MAXPATHLEN) {
fprintf(stderr,"%s: %s: directory name too long\n",
- ProgramName, database);
+ __progname, database);
exit(1);
}
@@ -313,7 +323,7 @@ main (argc,argv)
int argc;
char *argv[];
{
- int aflag, uflag, bflag, lflag, sflag;
+ int aflag, uflag, bflag, lflag, sflag, Uflag;
char *yp_input_file, *yp_output_file;
char *yp_master_name,*yp_domain_name;
char *infile,*outfile;
@@ -324,11 +334,15 @@ main (argc,argv)
yp_input_file = yp_output_file = NULL;
yp_master_name = yp_domain_name = NULL;
- aflag = uflag = bflag = lflag = sflag = 0;
+ aflag = uflag = bflag = lflag = sflag = Uflag = 0;
infile = outfile = NULL;
- while ((ch = getopt(argc, argv, "blsui:o:m:d:")) != -1)
+ while ((ch = getopt(argc, argv, "Ublsui:o:m:d:")) != -1)
switch (ch) {
+ case 'U':
+ uflag++;
+ Uflag++;
+ break;
case 'b':
bflag++;
aflag++;
@@ -387,14 +401,14 @@ main (argc,argv)
if (usage) {
fprintf(stderr,"%s%s%s",
- "usage:\tmakedbm -u file\n\tmakedbm [-bls]",
+ "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) {
- list_database(infile);
+ list_database(infile,Uflag);
} else {
create_database(infile,outfile,
yp_input_file,yp_output_file,