diff options
author | 2015-12-11 07:10:06 +0000 | |
---|---|---|
committer | 2015-12-11 07:10:06 +0000 | |
commit | e50ba63da1b10a71e1ba11b3cd45421c474b8947 (patch) | |
tree | ae6e4946bd28eb656663203a68ff6c0ca790a84b | |
parent | Remove debugging fluff from allocation functions. There's probably more (diff) | |
download | wireguard-openbsd-e50ba63da1b10a71e1ba11b3cd45421c474b8947.tar.xz wireguard-openbsd-e50ba63da1b10a71e1ba11b3cd45421c474b8947.zip |
Add -U option like the sendmail makemap, for dumping DB files back to text
ok sunil@ gilles@
-rw-r--r-- | usr.sbin/smtpd/makemap.8 | 9 | ||||
-rw-r--r-- | usr.sbin/smtpd/makemap.c | 45 |
2 files changed, 49 insertions, 5 deletions
diff --git a/usr.sbin/smtpd/makemap.8 b/usr.sbin/smtpd/makemap.8 index 1a015a7f531..68050dff1a3 100644 --- a/usr.sbin/smtpd/makemap.8 +++ b/usr.sbin/smtpd/makemap.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: makemap.8,v 1.25 2015/10/17 19:42:12 gilles Exp $ +.\" $OpenBSD: makemap.8,v 1.26 2015/12/11 07:10:06 guenther Exp $ .\" .\" Copyright (c) 2009 Jacek Masiulaniec <jacekm@openbsd.org> .\" Copyright (c) 2008-2009 Gilles Chehade <gilles@poolp.org> @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: October 17 2015 $ +.Dd $Mdocdate: December 11 2015 $ .Dt MAKEMAP 8 .Os .Sh NAME @@ -23,6 +23,7 @@ .Nd create database maps for smtpd .Sh SYNOPSIS .Nm makemap +.Op Fl U .Op Fl o Ar dbfile .Op Fl t Ar type .Ar file @@ -81,6 +82,10 @@ There is no mapped value \(en a map of this type will only allow for the lookup of keys. This format can be used for building primary domain maps. .El +.It Fl U +Instead of generating a database map from text input, +dump the contents of a database map as text +with the key and value separated with a tab. .El .Sh PRIMARY DOMAINS Primary domains can be kept in tables. diff --git a/usr.sbin/smtpd/makemap.c b/usr.sbin/smtpd/makemap.c index f48891be924..95acce9c40c 100644 --- a/usr.sbin/smtpd/makemap.c +++ b/usr.sbin/smtpd/makemap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: makemap.c,v 1.57 2015/12/07 12:29:19 sunil Exp $ */ +/* $OpenBSD: makemap.c,v 1.58 2015/12/11 07:10:06 guenther Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -50,10 +50,12 @@ static int parse_setentry(char *, size_t, size_t); static int make_plain(DBT *, char *); static int make_aliases(DBT *, char *); static char *conf_aliases(char *); +static int dump_db(const char *, DBTYPE); DB *db; char *source; char *oflag; +int Uflag; int dbputs; struct smtpd smtpd; @@ -91,7 +93,7 @@ makemap(int argc, char *argv[]) { struct stat sb; char dbname[PATH_MAX]; - char *opts; + const char *opts; char *conf; int ch; DBTYPE dbtype = DB_HASH; @@ -102,7 +104,7 @@ makemap(int argc, char *argv[]) mode = strcmp(__progname, "newaliases") ? P_MAKEMAP : P_NEWALIASES; conf = CONF_FILE; type = T_PLAIN; - opts = "ho:t:d:"; + opts = "ho:t:d:U"; if (mode == P_NEWALIASES) opts = "f:h"; @@ -132,6 +134,9 @@ makemap(int argc, char *argv[]) else errx(1, "unsupported type '%s'", optarg); break; + case 'U': + Uflag = 1; + break; default: usage(); } @@ -174,6 +179,9 @@ makemap(int argc, char *argv[]) source = argv[0]; } + if (Uflag) + return dump_db(source, dbtype); + if (oflag == NULL && asprintf(&oflag, "%s.db", source) == -1) err(1, "asprintf"); @@ -434,6 +442,37 @@ conf_aliases(char *cfgpath) return (path); } +static int +dump_db(const char *dbname, DBTYPE dbtype) +{ + DBT key, val; + char *keystr, *valstr; + int r; + + db = dbopen(dbname, O_RDONLY, 0644, dbtype, NULL); + if (db == NULL) + err(1, "dbopen: %s", dbname); + + for (r = db->seq(db, &key, &val, R_FIRST); r == 0; + r = db->seq(db, &key, &val, R_NEXT)) { + keystr = key.data; + valstr = val.data; + if (keystr[key.size - 1] == '\0') + key.size--; + if (valstr[val.size - 1] == '\0') + val.size--; + printf("%.*s\t%.*s\n", (int)key.size, keystr, + (int)val.size, valstr); + } + if (r == -1) + err(1, "db->seq: %s", dbname); + + if (db->close(db) == -1) + err(1, "dbclose: %s", dbname); + + return 0; +} + static void usage(void) { |