--- postfix-2.2.4/src/util/dict_db.c.dynamic 2005-03-14 11:16:54.000000000 -0300 +++ postfix-2.2.4/src/util/dict_db.c 2005-07-01 16:37:35.000000000 -0300 @@ -624,6 +624,12 @@ msg_fatal("set DB cache size %d: %m", dict_db_cache_size); if (type == DB_HASH && db->set_h_nelem(db, DICT_DB_NELM) != 0) msg_fatal("set DB hash element count %d: %m", DICT_DB_NELM); + if (dict_flags & DICT_FLAG_UPGRADE) { + if (msg_verbose) + msg_info("upgrading database %s",db_path); + if ((errno = db->upgrade(db,db_path,0)) != 0) + msg_fatal("upgrade of database %s: %m",db_path); + } #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR > 0) if ((errno = db->open(db, 0, db_path, 0, type, db_flags, 0644)) != 0) msg_fatal("open database %s: %m", db_path); --- postfix-2.2.4/src/util/dict.h.dynamic 2003-07-03 12:04:13.000000000 -0300 +++ postfix-2.2.4/src/util/dict.h 2005-07-01 16:37:35.000000000 -0300 @@ -61,6 +61,7 @@ #define DICT_FLAG_NO_REGSUB (1<<11) /* disallow regexp substitution */ #define DICT_FLAG_NO_PROXY (1<<12) /* disallow proxy mapping */ #define DICT_FLAG_NO_UNAUTH (1<<13) /* disallow unauthenticated data */ +#define DICT_FLAG_UPGRADE (1<<30) /* Upgrade the db */ #define DICT_FLAG_PARANOID \ (DICT_FLAG_NO_REGSUB | DICT_FLAG_NO_PROXY | DICT_FLAG_NO_UNAUTH) --- postfix-2.2.4/src/postmap/postmap.c.dynamic 2005-03-13 20:25:03.000000000 -0300 +++ postfix-2.2.4/src/postmap/postmap.c 2005-07-01 16:37:35.000000000 -0300 @@ -5,7 +5,7 @@ /* Postfix lookup table management /* SYNOPSIS /* .fi -/* \fBpostmap\fR [\fB-Nfinoprsvw\fR] [\fB-c \fIconfig_dir\fR] +/* \fBpostmap\fR [\fB-Nfinoprsuvw\fR] [\fB-c \fIconfig_dir\fR] /* [\fB-d \fIkey\fR] [\fB-q \fIkey\fR] /* [\fIfile_type\fR:]\fIfile_name\fR ... /* DESCRIPTION @@ -101,6 +101,8 @@ /* as the original input order. /* This feature is available in Postfix version 2.2 and later, /* and is not available for all database types. +/* .IP \fB-u\fR +/* Upgrade the database to the current version. /* .IP \fB-v\fR /* Enable verbose logging for debugging purposes. Multiple \fB-v\fR /* options make the software increasingly verbose. @@ -525,6 +527,18 @@ dict_close(dict); } +/* postmap_upgrade - upgrade a map */ + +static int postmap_upgrade(const char *map_type, const char *map_name) +{ + DICT *dict; + + dict = dict_open3(map_type, map_name, O_RDWR, + DICT_FLAG_LOCK|DICT_FLAG_UPGRADE); + dict_close(dict); + return (dict != 0); +} + /* usage - explain */ static NORETURN usage(char *myname) @@ -543,6 +557,7 @@ int postmap_flags = POSTMAP_FLAG_AS_OWNER | POSTMAP_FLAG_SAVE_PERM; int open_flags = O_RDWR | O_CREAT | O_TRUNC; int dict_flags = DICT_FLAG_DUP_WARN | DICT_FLAG_FOLD_KEY; + int upgrade=0; char *query = 0; char *delkey = 0; int sequence = 0; @@ -582,7 +597,7 @@ /* * Parse JCL. */ - while ((ch = GETOPT(argc, argv, "Nc:d:finopq:rsvw")) > 0) { + while ((ch = GETOPT(argc, argv, "Nc:d:finopq:rsuvw")) > 0) { switch (ch) { default: usage(argv[0]); @@ -596,8 +611,8 @@ msg_fatal("out of memory"); break; case 'd': - if (sequence || query || delkey) - msg_fatal("specify only one of -s -q or -d"); + if (sequence || query || delkey || upgrade) + msg_fatal("specify only one of -s -q -u or -d"); delkey = optarg; break; case 'f': @@ -617,8 +632,8 @@ postmap_flags &= ~POSTMAP_FLAG_SAVE_PERM; break; case 'q': - if (sequence || query || delkey) - msg_fatal("specify only one of -s -q or -d"); + if (sequence || query || delkey || upgrade) + msg_fatal("specify only one of -s -q -u or -d"); query = optarg; break; case 'r': @@ -626,10 +641,15 @@ dict_flags |= DICT_FLAG_DUP_REPLACE; break; case 's': - if (query || delkey) - msg_fatal("specify only one of -s or -q or -d"); + if (query || delkey || upgrade) + msg_fatal("specify only one of -s or -q -u or -d"); sequence = 1; break; + case 'u': + if (sequence || query || delkey || upgrade) + msg_fatal("specify only one of -s -q -u or -d"); + upgrade=1; + break; case 'v': msg_verbose++; break; @@ -690,6 +710,21 @@ exit(0); } exit(1); + } else if (upgrade) { /* Upgrade the map(s) */ + int success = 1; + if (optind + 1 > argc) + usage(argv[0]); + while (optind < argc) { + if ((path_name = split_at(argv[optind], ':')) != 0) { + success &= postmap_upgrade(argv[optind], path_name); + } else { + success &= postmap_upgrade(var_db_type, path_name); + } + if (!success) + exit(1); + optind++; + } + exit(0); } else { /* create/update map(s) */ if (optind + 1 > argc) usage(argv[0]); --- postfix-2.2.4/man/man1/postmap.1.orig 2005-03-13 22:24:46.000000000 -0300 +++ postfix-2.2.4/man/man1/postmap.1 2005-07-01 17:22:19.000000000 -0300 @@ -9,7 +9,7 @@ .na .nf .fi -\fBpostmap\fR [\fB-Nfinoprsvw\fR] [\fB-c \fIconfig_dir\fR] +\fBpostmap\fR [\fB-Nfinoprsuvw\fR] [\fB-c \fIconfig_dir\fR] [\fB-d \fIkey\fR] [\fB-q \fIkey\fR] [\fIfile_type\fR:]\fIfile_name\fR ... .SH DESCRIPTION @@ -111,6 +111,8 @@ as the original input order. This feature is available in Postfix version 2.2 and later, and is not available for all database types. +.IP \fB-u\fR +Upgrade the database to the current version. .IP \fB-v\fR Enable verbose logging for debugging purposes. Multiple \fB-v\fR options make the software increasingly verbose.