Blame SOURCES/cyrus-sasl-2.1.27-Migration-from-BerkeleyDB.patch

138d55
diff -up cyrus-sasl-2.1.27/configure.ac.frombdb cyrus-sasl-2.1.27/configure.ac
138d55
--- cyrus-sasl-2.1.27/configure.ac.frombdb	2021-06-04 13:02:07.790112263 +0200
138d55
+++ cyrus-sasl-2.1.27/configure.ac	2021-06-04 13:02:07.798112327 +0200
138d55
@@ -1091,6 +1091,9 @@ AC_SUBST(SASL_STATIC_SRCS)
138d55
 AC_SUBST(SASL_STATIC_OBJS)
138d55
 AC_SUBST(SASL_STATIC_LIBS)
138d55
 
138d55
+CYRUS_BERKELEY_DB_STATIC_LIB()
138d55
+AC_SUBST(BDB_STATIC_LIBADD)
138d55
+
138d55
 AC_ARG_WITH(plugindir, [  --with-plugindir=DIR    set the directory where plugins will
138d55
                           be found [[LIBDIR/sasl2]] ],
138d55
   plugindir=$withval,
138d55
diff -up cyrus-sasl-2.1.27/m4/berkdb.m4.frombdb cyrus-sasl-2.1.27/m4/berkdb.m4
138d55
--- cyrus-sasl-2.1.27/m4/berkdb.m4.frombdb	2016-01-29 18:35:35.000000000 +0100
138d55
+++ cyrus-sasl-2.1.27/m4/berkdb.m4	2021-06-04 13:02:07.798112327 +0200
138d55
@@ -286,3 +286,10 @@ AC_DEFUN([CYRUS_BERKELEY_DB_CHK],
138d55
 
138d55
 	CPPFLAGS=$cmu_save_CPPFLAGS
138d55
 ])
138d55
+
138d55
+AC_DEFUN([CYRUS_BERKELEY_DB_STATIC_LIB],
138d55
+[
138d55
+BDB_STATIC_LIBADD="/dev/null -lpthread"
138d55
+AC_CHECK_FILE([/usr/lib64/libdb-5.3.a],[BDB_STATIC_LIBADD="/usr/lib64/libdb-5.3.a -lpthread "],[])
138d55
+AC_CHECK_FILE([/usr/lib/libdb-5.3.a],[BDB_STATIC_LIBADD="/usr/lib/libdb-5.3.a -lpthread"],[])
138d55
+])
138d55
diff -up cyrus-sasl-2.1.27/m4/sasldb.m4.frombdb cyrus-sasl-2.1.27/m4/sasldb.m4
138d55
--- cyrus-sasl-2.1.27/m4/sasldb.m4.frombdb	2017-07-13 20:45:19.000000000 +0200
138d55
+++ cyrus-sasl-2.1.27/m4/sasldb.m4	2021-06-04 13:02:07.798112327 +0200
138d55
@@ -111,7 +111,7 @@ AC_MSG_RESULT($dblib)
138d55
 SASL_DB_BACKEND="db_${dblib}.lo"
138d55
 SASL_DB_BACKEND_STATIC="db_${dblib}.o allockey.o"
138d55
 SASL_DB_BACKEND_STATIC_SRCS="\$(top_srcdir)/sasldb/db_${dblib}.c \$(top_srcdir)/sasldb/allockey.c"
138d55
-SASL_DB_UTILS="saslpasswd2 sasldblistusers2"
138d55
+SASL_DB_UTILS="cyrusbdb2current saslpasswd2 sasldblistusers2"
138d55
 SASL_DB_MANS="saslpasswd2.8 sasldblistusers2.8"
138d55
 
138d55
 case "$dblib" in
138d55
diff -up cyrus-sasl-2.1.27/sasldb/db_gdbm.c.frombdb cyrus-sasl-2.1.27/sasldb/db_gdbm.c
138d55
--- cyrus-sasl-2.1.27/sasldb/db_gdbm.c.frombdb	2017-07-13 14:34:03.000000000 +0200
138d55
+++ cyrus-sasl-2.1.27/sasldb/db_gdbm.c	2021-06-04 13:04:24.098206887 +0200
138d55
@@ -67,6 +67,7 @@ int _sasldb_getdata(const sasl_utils_t *
138d55
   void *cntxt;
138d55
   sasl_getopt_t *getopt;
138d55
   const char *path = SASL_DB_PATH;
138d55
+  int fetch_errno = 0;
138d55
 
138d55
   if (!utils) return SASL_BADPARAM;
138d55
   if (!authid || !propName || !realm || !out || !max_out) {
138d55
@@ -99,6 +100,9 @@ int _sasldb_getdata(const sasl_utils_t *
138d55
   }
138d55
   db = gdbm_open((char *)path, 0, GDBM_READER, S_IRUSR | S_IWUSR, NULL);
138d55
   if (! db) {
138d55
+      utils->log(conn, SASL_LOG_ERR,
138d55
+		 "SASL error opening password file. "
138d55
+		 "Have you performed the migration from db2 using cyrusbdb2current?\n");
138d55
       utils->seterror(cntxt, 0, "Could not open %s: gdbm_errno=%d",
138d55
 		      path, gdbm_errno);
138d55
       result = SASL_FAIL;
138d55
@@ -107,9 +111,10 @@ int _sasldb_getdata(const sasl_utils_t *
138d55
   gkey.dptr = key;
138d55
   gkey.dsize = key_len;
138d55
   gvalue = gdbm_fetch(db, gkey);
138d55
+  fetch_errno = gdbm_errno;
138d55
   gdbm_close(db);
138d55
   if (! gvalue.dptr) {
138d55
-      if (gdbm_errno == GDBM_ITEM_NOT_FOUND) {
138d55
+      if (fetch_errno == GDBM_ITEM_NOT_FOUND) {
138d55
           utils->seterror(conn, SASL_NOLOG,
138d55
 			  "user: %s@%s property: %s not found in %s",
138d55
 			  authid, realm, propName, path);
138d55
@@ -186,7 +191,8 @@ int _sasldb_putdata(const sasl_utils_t *
138d55
   if (! db) {
138d55
       utils->log(conn, SASL_LOG_ERR,
138d55
 		 "SASL error opening password file. "
138d55
-		 "Do you have write permissions?\n");
138d55
+		 "Do you have write permissions?\n"
138d55
+		 "Have you performed the migration from db2 using cyrusbdb2current?\n");
138d55
       utils->seterror(conn, 0, "Could not open %s for write: gdbm_errno=%d",
138d55
                      path, gdbm_errno);
138d55
       result = SASL_FAIL;
138d55
@@ -298,6 +304,9 @@ sasldb_handle _sasldb_getkeyhandle(const
138d55
     db = gdbm_open((char *)path, 0, GDBM_READER, S_IRUSR | S_IWUSR, NULL);
138d55
 
138d55
     if(!db) {
138d55
+        utils->log(conn, SASL_LOG_ERR,
138d55
+		 "SASL error opening password file. "
138d55
+		 "Have you performed the migration from db2 using cyrusbdb2current?\n");
138d55
         utils->seterror(conn, 0, "Could not open %s: gdbm_errno=%d",
138d55
 			 path, gdbm_errno);
138d55
 	return NULL;
138d55
diff -up cyrus-sasl-2.1.27/utils/cyrusbdb2current.8.frombdb cyrus-sasl-2.1.27/utils/cyrusbdb2current.8
138d55
--- cyrus-sasl-2.1.27/utils/cyrusbdb2current.8.frombdb	2021-06-04 13:02:07.798112327 +0200
138d55
+++ cyrus-sasl-2.1.27/utils/cyrusbdb2current.8	2021-06-04 13:02:07.798112327 +0200
138d55
@@ -0,0 +1,159 @@
138d55
+.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40)
138d55
+.\"
138d55
+.\" Standard preamble:
138d55
+.\" ========================================================================
138d55
+.de Sp \" Vertical space (when we can't use .PP)
138d55
+.if t .sp .5v
138d55
+.if n .sp
138d55
+..
138d55
+.de Vb \" Begin verbatim text
138d55
+.ft CW
138d55
+.nf
138d55
+.ne \\$1
138d55
+..
138d55
+.de Ve \" End verbatim text
138d55
+.ft R
138d55
+.fi
138d55
+..
138d55
+.\" Set up some character translations and predefined strings.  \*(-- will
138d55
+.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
138d55
+.\" double quote, and \*(R" will give a right double quote.  \*(C+ will
138d55
+.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
138d55
+.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
138d55
+.\" nothing in troff, for use with C<>.
138d55
+.tr \(*W-
138d55
+.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
138d55
+.ie n \{\
138d55
+.    ds -- \(*W-
138d55
+.    ds PI pi
138d55
+.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
138d55
+.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
138d55
+.    ds L" ""
138d55
+.    ds R" ""
138d55
+.    ds C` ""
138d55
+.    ds C' ""
138d55
+'br\}
138d55
+.el\{\
138d55
+.    ds -- \|\(em\|
138d55
+.    ds PI \(*p
138d55
+.    ds L" ``
138d55
+.    ds R" ''
138d55
+.    ds C`
138d55
+.    ds C'
138d55
+'br\}
138d55
+.\"
138d55
+.\" Escape single quotes in literal strings from groff's Unicode transform.
138d55
+.ie \n(.g .ds Aq \(aq
138d55
+.el       .ds Aq '
138d55
+.\"
138d55
+.\" If the F register is >0, we'll generate index entries on stderr for
138d55
+.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
138d55
+.\" entries marked with X<> in POD.  Of course, you'll have to process the
138d55
+.\" output yourself in some meaningful fashion.
138d55
+.\"
138d55
+.\" Avoid warning from groff about undefined register 'F'.
138d55
+.de IX
138d55
+..
138d55
+.nr rF 0
138d55
+.if \n(.g .if rF .nr rF 1
138d55
+.if (\n(rF:(\n(.g==0)) \{\
138d55
+.    if \nF \{\
138d55
+.        de IX
138d55
+.        tm Index:\\$1\t\\n%\t"\\$2"
138d55
+..
138d55
+.        if !\nF==2 \{\
138d55
+.            nr % 0
138d55
+.            nr F 2
138d55
+.        \}
138d55
+.    \}
138d55
+.\}
138d55
+.rr rF
138d55
+.\"
138d55
+.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
138d55
+.\" Fear.  Run.  Save yourself.  No user-serviceable parts.
138d55
+.    \" fudge factors for nroff and troff
138d55
+.if n \{\
138d55
+.    ds #H 0
138d55
+.    ds #V .8m
138d55
+.    ds #F .3m
138d55
+.    ds #[ \f1
138d55
+.    ds #] \fP
138d55
+.\}
138d55
+.if t \{\
138d55
+.    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
138d55
+.    ds #V .6m
138d55
+.    ds #F 0
138d55
+.    ds #[ \&
138d55
+.    ds #] \&
138d55
+.\}
138d55
+.    \" simple accents for nroff and troff
138d55
+.if n \{\
138d55
+.    ds ' \&
138d55
+.    ds ` \&
138d55
+.    ds ^ \&
138d55
+.    ds , \&
138d55
+.    ds ~ ~
138d55
+.    ds /
138d55
+.\}
138d55
+.if t \{\
138d55
+.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
138d55
+.    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
138d55
+.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
138d55
+.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
138d55
+.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
138d55
+.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
138d55
+.\}
138d55
+.    \" troff and (daisy-wheel) nroff accents
138d55
+.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
138d55
+.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
138d55
+.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
138d55
+.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
138d55
+.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
138d55
+.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
138d55
+.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
138d55
+.ds ae a\h'-(\w'a'u*4/10)'e
138d55
+.ds Ae A\h'-(\w'A'u*4/10)'E
138d55
+.    \" corrections for vroff
138d55
+.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
138d55
+.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
138d55
+.    \" for low resolution devices (crt and lpr)
138d55
+.if \n(.H>23 .if \n(.V>19 \
138d55
+\{\
138d55
+.    ds : e
138d55
+.    ds 8 ss
138d55
+.    ds o a
138d55
+.    ds d- d\h'-1'\(ga
138d55
+.    ds D- D\h'-1'\(hy
138d55
+.    ds th \o'bp'
138d55
+.    ds Th \o'LP'
138d55
+.    ds ae ae
138d55
+.    ds Ae AE
138d55
+.\}
138d55
+.rm #[ #] #H #V #F C
138d55
+.\" ========================================================================
138d55
+.\"
138d55
+.IX Title "CYRUSBDB2CURRENT 1"
138d55
+.TH CYRUSBDB2CURRENT 1 "2021-04-28" "perl v5.30.3" "User Contributed Perl Documentation"
138d55
+.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
138d55
+.\" way too many mistakes in technical documents.
138d55
+.if n .ad l
138d55
+.nh
138d55
+.SH "NAME"
138d55
+cyrusbdb2current \- command\-line utility converting the SASLDB database from
138d55
+BerkeleyDB to the database format currently used bys sasldb.
138d55
+.SH "SYNOPSIS"
138d55
+.IX Header "SYNOPSIS"
138d55
+cyrusbdb2current <sasldb_old_path> <sasldb_new_path>
138d55
+.SH "DESCRIPTION"
138d55
+.IX Header "DESCRIPTION"
138d55
+\&\fBcyrusbdb2current\fR converts the current sasldb database from BerkeleyDB format to the
138d55
+currently used database format. It is \fB\s-1STRONGLY RECOMMENDED\s0\fR to make a backup
138d55
+of the current database before the conversion.
138d55
+.PP
138d55
+We expect that the old path is \fB/etc/sasldb2\fR and the new one is
138d55
+\&\fB/etc/sasl2/sasldb2\fR
138d55
+.SH "SEE ALSO"
138d55
+.IX Header "SEE ALSO"
138d55
+\&\fBsaslpasswd2\fR\|(8)
138d55
+.PP
138d55
+rfc4422 \- Simple Authentication and Security Layer (\s-1SASL\s0)
138d55
diff -up cyrus-sasl-2.1.27/utils/cyrusbdb2current.c.frombdb cyrus-sasl-2.1.27/utils/cyrusbdb2current.c
138d55
--- cyrus-sasl-2.1.27/utils/cyrusbdb2current.c.frombdb	2021-06-04 13:02:07.798112327 +0200
138d55
+++ cyrus-sasl-2.1.27/utils/cyrusbdb2current.c	2021-06-04 13:02:07.798112327 +0200
138d55
@@ -0,0 +1,282 @@
138d55
+#include <config.h>
138d55
+
138d55
+#include <stdio.h>
138d55
+#include <stdlib.h>
138d55
+
138d55
+#include <sasl.h>
138d55
+#include <saslplug.h>
138d55
+#include "../sasldb/sasldb.h"
138d55
+
138d55
+/* Cheating to make the utils work out right */
138d55
+extern const sasl_utils_t *sasl_global_utils;
138d55
+sasl_conn_t *globalconn;
138d55
+
138d55
+typedef void *listcb_t(const char *, const char *, const char *,
138d55
+		       const char *, unsigned);
138d55
+
138d55
+void listusers_cb(const char *authid, const char *realm,
138d55
+		  const char *propName, const char *secret,
138d55
+		  unsigned seclen)
138d55
+{
138d55
+    if (!authid || !propName || !realm) {
138d55
+	fprintf(stderr,"userlist callback has bad param");
138d55
+	return;
138d55
+    }
138d55
+
138d55
+    /* the entries that just say the mechanism exists */
138d55
+    if (strlen(authid)==0) return;
138d55
+
138d55
+    printf("Converting: %s@%s (%s)...",authid,realm,propName);
138d55
+
138d55
+    _sasldb_putdata(sasl_global_utils, globalconn,
138d55
+		    authid, realm, propName,
138d55
+		    secret, seclen);
138d55
+
138d55
+    printf("ok\n");
138d55
+}
138d55
+
138d55
+/*
138d55
+ * List all users in database
138d55
+ */
138d55
+
138d55
+#include <db.h>
138d55
+
138d55
+#define DB_VERSION_FULL ((DB_VERSION_MAJOR << 24) | (DB_VERSION_MINOR << 16) | DB_VERSION_PATCH)
138d55
+/*
138d55
+ * Open the database
138d55
+ *
138d55
+ */
138d55
+static int berkeleydb_open(const char *path,DB **mbdb)
138d55
+{
138d55
+    int ret;
138d55
+
138d55
+#if DB_VERSION_FULL < 0x03000000
138d55
+    ret = db_open(path, DB_HASH, DB_CREATE, 0664, NULL, NULL, mbdb);
138d55
+#else /* DB_VERSION_FULL < 0x03000000 */
138d55
+    ret = db_create(mbdb, NULL, 0);
138d55
+    if (ret == 0 && *mbdb != NULL)
138d55
+    {
138d55
+#if DB_VERSION_FULL >= 0x04010000
138d55
+	ret = (*mbdb)->open(*mbdb, NULL, path, NULL, DB_HASH, DB_CREATE, 0664);
138d55
+#else
138d55
+	ret = (*mbdb)->open(*mbdb, path, NULL, DB_HASH, DB_CREATE, 0664);
138d55
+#endif
138d55
+	if (ret != 0)
138d55
+	{
138d55
+	    (void) (*mbdb)->close(*mbdb, 0);
138d55
+	    *mbdb = NULL;
138d55
+	}
138d55
+    }
138d55
+#endif /* DB_VERSION_FULL < 0x03000000 */
138d55
+
138d55
+    if (ret != 0) {
138d55
+	fprintf(stderr,"Error opening password file %s\n", path);
138d55
+	return SASL_FAIL;
138d55
+    }
138d55
+
138d55
+    return SASL_OK;
138d55
+}
138d55
+
138d55
+/*
138d55
+ * Close the database
138d55
+ *
138d55
+ */
138d55
+
138d55
+static void berkeleydb_close(DB *mbdb)
138d55
+{
138d55
+    int ret;
138d55
+    
138d55
+    ret = mbdb->close(mbdb, 0);
138d55
+    if (ret!=0) {
138d55
+	fprintf(stderr,"error closing sasldb: %s",
138d55
+		db_strerror(ret));
138d55
+    }
138d55
+}
138d55
+
138d55
+int listusers(const char *path, listcb_t *cb)
138d55
+{
138d55
+    int result;
138d55
+    DB *mbdb = NULL;
138d55
+    DBC *cursor;
138d55
+    DBT key, data;
138d55
+
138d55
+    /* open the db */
138d55
+    result=berkeleydb_open(path, &mbdb);
138d55
+    if (result!=SASL_OK) goto cleanup;
138d55
+
138d55
+    /* make cursor */
138d55
+#if DB_VERSION_FULL < 0x03060000
138d55
+    result = mbdb->cursor(mbdb, NULL,&cursor); 
138d55
+#else
138d55
+    result = mbdb->cursor(mbdb, NULL,&cursor, 0); 
138d55
+#endif /* DB_VERSION_FULL < 0x03060000 */
138d55
+
138d55
+    if (result!=0) {
138d55
+	fprintf(stderr,"Making cursor failure: %s\n",db_strerror(result));
138d55
+      result = SASL_FAIL;
138d55
+      goto cleanup;
138d55
+    }
138d55
+
138d55
+    memset(&key,0, sizeof(key));
138d55
+    memset(&data,0,sizeof(data));
138d55
+
138d55
+    /* loop thru */
138d55
+    result = cursor->c_get(cursor, &key, &data,
138d55
+			   DB_FIRST);
138d55
+
138d55
+    while (result != DB_NOTFOUND)
138d55
+    {
138d55
+	char *authid;
138d55
+	char *realm;
138d55
+	char *tmp;
138d55
+	unsigned int len;
138d55
+	char prop[1024];
138d55
+	int numnulls = 0;
138d55
+	unsigned int lup;
138d55
+
138d55
+	/* make sure there are exactly 2 null's */
138d55
+	for (lup=0;lup
138d55
+	    if (((char *)key.data)[lup]=='\0')
138d55
+		numnulls++;
138d55
+
138d55
+	if (numnulls != 2) {
138d55
+	    fprintf(stderr,"warning: probable database corruption\n");
138d55
+	    result = cursor->c_get(cursor, &key, &data, DB_NEXT);
138d55
+	    continue;
138d55
+	}
138d55
+
138d55
+	authid = key.data;
138d55
+	realm  = authid + strlen(authid)+1;
138d55
+	tmp    = realm + strlen(realm)+1;
138d55
+	len = key.size - (tmp - authid);
138d55
+
138d55
+	/* make sure we have enough space of prop */
138d55
+	if (len >=sizeof(prop)) {
138d55
+	    fprintf(stderr,"warning: absurdly long prop name\n");
138d55
+	    result = cursor->c_get(cursor, &key, &data, DB_NEXT);
138d55
+	    continue;
138d55
+	}
138d55
+
138d55
+	memcpy(prop, tmp, key.size - (tmp - ((char *)key.data)));
138d55
+	prop[key.size - (tmp - ((char *)key.data))] = '\0';
138d55
+
138d55
+	if (*authid) {
138d55
+	    /* don't check return values */
138d55
+	    cb(authid,realm,prop,data.data,data.size);
138d55
+	}
138d55
+
138d55
+	result = cursor->c_get(cursor, &key, &data, DB_NEXT);
138d55
+    }
138d55
+
138d55
+    if (result != DB_NOTFOUND) {
138d55
+	fprintf(stderr,"failure: %s\n",db_strerror(result));
138d55
+	result = SASL_FAIL;
138d55
+	goto cleanup;
138d55
+    }
138d55
+
138d55
+    result = cursor->c_close(cursor);
138d55
+    if (result != 0) {
138d55
+        result = SASL_FAIL;
138d55
+        goto cleanup;
138d55
+    }
138d55
+
138d55
+    result = SASL_OK;
138d55
+
138d55
+ cleanup:
138d55
+
138d55
+    if (mbdb != NULL) berkeleydb_close(mbdb);
138d55
+    return result;
138d55
+}
138d55
+
138d55
+
138d55
+char *db = NULL, *db_new=NULL;
138d55
+
138d55
+int good_getopt(void *context __attribute__((unused)), 
138d55
+		const char *plugin_name __attribute__((unused)), 
138d55
+		const char *option,
138d55
+		const char **result,
138d55
+		unsigned *len)
138d55
+{
138d55
+    if (db_new && !strcmp(option, "sasldb_path")) {
138d55
+	*result = db_new;
138d55
+	if (len)
138d55
+	    *len = strlen(db_new);
138d55
+	return SASL_OK;
138d55
+    }
138d55
+
138d55
+    return SASL_FAIL;
138d55
+}
138d55
+
138d55
+static struct sasl_callback goodsasl_cb[] = {
138d55
+    { SASL_CB_GETOPT, (int (*)(void))&good_getopt, NULL },
138d55
+    { SASL_CB_LIST_END, NULL, NULL }
138d55
+};
138d55
+
138d55
+int main(int argc, char **argv)
138d55
+{
138d55
+    int result;
138d55
+    FILE *f;
138d55
+
138d55
+    if (argc != 3) {
138d55
+	fprintf(stderr, "Usage: cyrusbdb2current old_sasldb new_sasldb\n");
138d55
+	fprintf(stderr, "old_sasldb is presumably /etc/sasldb2\n");
138d55
+       	fprintf(stderr, "new_sasldb is presumably /etc/sasl2/sasldb2\n");
138d55
+	return 1;
138d55
+    }
138d55
+
138d55
+    db = argv[1];
138d55
+    db_new = argv[2];
138d55
+
138d55
+    if (strcmp(db, db_new) == 0) {
138d55
+	fprintf(stderr, "Old and new files should be different\n");
138d55
+	return 1;
138d55
+    }
138d55
+
138d55
+
138d55
+    f = fopen(db_new, "rb");
138d55
+    if (f != NULL) {
138d55
+	fprintf(stderr, "The specified target file %s already exists\n", db_new);
138d55
+	fclose(f);
138d55
+	return 1;
138d55
+    }
138d55
+
138d55
+    result = sasl_server_init(goodsasl_cb, "dbconverter");
138d55
+    if (result != SASL_OK) {
138d55
+	fprintf(stderr, "couldn't init saslv2\n");
138d55
+	return 1;
138d55
+    }
138d55
+
138d55
+    result = sasl_server_new("sasldb",
138d55
+			     "localhost",
138d55
+			     NULL,
138d55
+			     NULL,
138d55
+			     NULL,
138d55
+			     NULL,
138d55
+			     0,
138d55
+			     &globalconn);
138d55
+    if (result != SASL_OK) {
138d55
+	fprintf(stderr, "couldn't create globalconn\n");
138d55
+	return 1;
138d55
+    }
138d55
+
138d55
+    if(_sasl_check_db(sasl_global_utils,globalconn) != SASL_OK) {
138d55
+	fprintf(stderr, "target DB %s is not OK\n", db_new);
138d55
+	return 1;
138d55
+    }
138d55
+
138d55
+    printf("\nThis program will take the sasldb file specified on the\n"
138d55
+           "command line and convert it to a new sasldb specified\n"
138d55
+           "on the command line. It is STRONGLY RECOMMENDED that you\n"
138d55
+           "backup sasldb before allowing this program to run\n\n"
138d55
+	   "We are going to convert %s and our output will be in %s\n\n"
138d55
+           "Press return to continue\n", db, db_new);
138d55
+
138d55
+    getchar();
138d55
+
138d55
+    listusers(db, (listcb_t *) &listusers_cb);
138d55
+
138d55
+    sasl_dispose(&globalconn);
138d55
+    sasl_done();
138d55
+
138d55
+    exit(0);
138d55
+}
138d55
diff -up cyrus-sasl-2.1.27/utils/Makefile.am.frombdb cyrus-sasl-2.1.27/utils/Makefile.am
138d55
--- cyrus-sasl-2.1.27/utils/Makefile.am.frombdb	2018-10-05 16:40:16.000000000 +0200
138d55
+++ cyrus-sasl-2.1.27/utils/Makefile.am	2021-06-04 13:02:07.798112327 +0200
138d55
@@ -46,14 +46,14 @@ all_sasl_libs = ../lib/libsasl2.la $(SAS
138d55
 all_sasl_static_libs = ../lib/.libs/libsasl2.a $(SASL_DB_LIB) $(LIB_SOCKET) $(GSSAPIBASE_LIBS) $(GSSAPI_LIBS) $(SASL_KRB_LIB) $(LIB_DES) $(PLAIN_LIBS) $(SRP_LIBS) $(LIB_MYSQL) $(LIB_PGSQL) $(LIB_SQLITE)
138d55
 
138d55
 sbin_PROGRAMS = @SASL_DB_UTILS@ @SMTPTEST_PROGRAM@ pluginviewer
138d55
-EXTRA_PROGRAMS = saslpasswd2 sasldblistusers2 testsuite testsuitestatic smtptest pluginviewer
138d55
+EXTRA_PROGRAMS = saslpasswd2 sasldblistusers2 testsuite testsuitestatic smtptest pluginviewer cyrusbdb2current
138d55
 
138d55
 noinst_PROGRAMS = dbconverter-2
138d55
 
138d55
 if NO_SASL_DB_MANS
138d55
 man_MANS = 
138d55
 else
138d55
-man_MANS = saslpasswd2.8 sasldblistusers2.8 pluginviewer.8
138d55
+man_MANS = saslpasswd2.8 sasldblistusers2.8 pluginviewer.8 cyrusbdb2current.8
138d55
 endif
138d55
 
138d55
 saslpasswd2_LDADD = ../sasldb/libsasldb.la $(all_sasl_libs)
138d55
@@ -63,6 +63,7 @@ sasldblistusers2_SOURCES = sasldblistuse
138d55
 dbconverter_2_LDADD = ../sasldb/libsasldb.la $(all_sasl_libs)
138d55
 pluginviewer_LDADD = $(all_sasl_libs)
138d55
 pluginviewer_SOURCES = pluginviewer.c
138d55
+cyrusbdb2current_LDADD = ../sasldb/libsasldb.la @BDB_STATIC_LIBADD@ $(all_sasl_libs)
138d55
 
138d55
 testsuite_LDADD = $(all_sasl_libs) @DMALLOC_LIBS@
138d55