Support db1 and db3 at the same time
This commit is contained in:
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#include "hdb_locl.h"
|
#include "hdb_locl.h"
|
||||||
|
|
||||||
#if defined(HAVE_DB1) && !defined(HAVE_DB3)
|
#if defined(HAVE_DB1)
|
||||||
|
|
||||||
#if defined(HAVE_DB_185_H)
|
#if defined(HAVE_DB_185_H)
|
||||||
#include <db_185.h>
|
#include <db_185.h>
|
||||||
@@ -336,8 +336,8 @@ DB_open(krb5_context context, HDB *db, int flags, mode_t mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
krb5_error_code
|
krb5_error_code
|
||||||
hdb_db_create(krb5_context context, HDB **db,
|
hdb_db1_create(krb5_context context, HDB **db,
|
||||||
const char *filename)
|
const char *filename)
|
||||||
{
|
{
|
||||||
DB1_HDB **db1 = (DB1_HDB **)db;
|
DB1_HDB **db1 = (DB1_HDB **)db;
|
||||||
*db = calloc(1, sizeof(**db1)); /* Allocate space for the larger db1 */
|
*db = calloc(1, sizeof(**db1)); /* Allocate space for the larger db1 */
|
||||||
@@ -376,4 +376,4 @@ hdb_db_create(krb5_context context, HDB **db,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* defined(HAVE_DB1) && !defined(HAVE_DB3) */
|
#endif /* defined(HAVE_DB1) */
|
||||||
|
@@ -450,8 +450,8 @@ DB_open(krb5_context context, HDB *db, int flags, mode_t mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
krb5_error_code
|
krb5_error_code
|
||||||
hdb_db_create(krb5_context context, HDB **db,
|
hdb_db3_create(krb5_context context, HDB **db,
|
||||||
const char *filename)
|
const char *filename)
|
||||||
{
|
{
|
||||||
DB3_HDB **db3 = (DB3_HDB **)db;
|
DB3_HDB **db3 = (DB3_HDB **)db;
|
||||||
*db = calloc(1, sizeof(**db3)); /* Allocate space for the larger db3 */
|
*db = calloc(1, sizeof(**db3)); /* Allocate space for the larger db3 */
|
||||||
|
@@ -64,14 +64,17 @@
|
|||||||
const int hdb_interface_version = HDB_INTERFACE_VERSION;
|
const int hdb_interface_version = HDB_INTERFACE_VERSION;
|
||||||
|
|
||||||
static struct hdb_method methods[] = {
|
static struct hdb_method methods[] = {
|
||||||
#if HAVE_DB1 || HAVE_DB3
|
/* "db:" should be db3 if we have db3, or db1 if we have db1 */
|
||||||
{ HDB_INTERFACE_VERSION, NULL, NULL, "db:", hdb_db_create},
|
#if HAVE_DB3
|
||||||
|
{ HDB_INTERFACE_VERSION, NULL, NULL, "db:", hdb_db3_create},
|
||||||
|
#elif HAVE_DB1
|
||||||
|
{ HDB_INTERFACE_VERSION, NULL, NULL, "db:", hdb_db1_create},
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_DB1
|
#if HAVE_DB1
|
||||||
{ HDB_INTERFACE_VERSION, NULL, NULL, "db1:", hdb_db_create},
|
{ HDB_INTERFACE_VERSION, NULL, NULL, "db1:", hdb_db1_create},
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_DB3
|
#if HAVE_DB3
|
||||||
{ HDB_INTERFACE_VERSION, NULL, NULL, "db3:", hdb_db_create},
|
{ HDB_INTERFACE_VERSION, NULL, NULL, "db3:", hdb_db3_create},
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_DB1
|
#if HAVE_DB1
|
||||||
{ HDB_INTERFACE_VERSION, NULL, NULL, "mit-db:", hdb_mitdb_create},
|
{ HDB_INTERFACE_VERSION, NULL, NULL, "mit-db:", hdb_mitdb_create},
|
||||||
@@ -94,14 +97,22 @@ static struct hdb_method methods[] = {
|
|||||||
{ 0, NULL, NULL, NULL, NULL}
|
{ 0, NULL, NULL, NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* It'd be nice if we could try opening an HDB with each supported
|
||||||
|
* backend until one works or all fail. It may not be possible for all
|
||||||
|
* flavors, but where it's possible we should.
|
||||||
|
*/
|
||||||
#if defined(HAVE_LMDB)
|
#if defined(HAVE_LMDB)
|
||||||
static struct hdb_method dbmetod =
|
static struct hdb_method default_dbmethod =
|
||||||
{ HDB_INTERFACE_VERSION, NULL, NULL, "", hdb_mdb_create };
|
{ HDB_INTERFACE_VERSION, NULL, NULL, "", hdb_mdb_create };
|
||||||
#elif defined(HAVE_DB1) || defined(HAVE_DB3)
|
#elif defined(HAVE_DB3)
|
||||||
static struct hdb_method dbmetod =
|
static struct hdb_method default_dbmethod =
|
||||||
{ HDB_INTERFACE_VERSION, NULL, NULL, "", hdb_db_create };
|
{ HDB_INTERFACE_VERSION, NULL, NULL, "", hdb_db3_create };
|
||||||
|
#elif defined(HAVE_DB1)
|
||||||
|
static struct hdb_method default_dbmethod =
|
||||||
|
{ HDB_INTERFACE_VERSION, NULL, NULL, "", hdb_db1_create };
|
||||||
#elif defined(HAVE_NDBM)
|
#elif defined(HAVE_NDBM)
|
||||||
static struct hdb_method dbmetod =
|
static struct hdb_method default_dbmethod =
|
||||||
{ HDB_INTERFACE_VERSION, NULL, NULL, "", hdb_ndbm_create };
|
{ HDB_INTERFACE_VERSION, NULL, NULL, "", hdb_ndbm_create };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -321,13 +332,17 @@ find_method (const char *filename, const char **rest)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if defined(HAVE_DB1) || defined(HAVE_DB3) || defined(HAVE_LMDB) || defined(HAVE_NDBM)
|
#if defined(HAVE_DB1) || defined(HAVE_DB3) || defined(HAVE_LMDB) || defined(HAVE_NDBM)
|
||||||
/* XXX This doesn't handle Windows */
|
if (strncmp(filename, "/", sizeof("/") - 1) == 0
|
||||||
if (strncmp(filename, "/", 1) == 0
|
|| strncmp(filename, "./", sizeof("./") - 1) == 0
|
||||||
|| strncmp(filename, "./", 2) == 0
|
|| strncmp(filename, "../", sizeof("../") - 1) == 0
|
||||||
|| strncmp(filename, "../", 3) == 0)
|
#ifdef WIN32
|
||||||
|
|| strncmp(filename, "\\\\", sizeof("\\\\") - 1)
|
||||||
|
|| (isalpha(filename[0]) && filename[1] == ':')
|
||||||
|
#endif
|
||||||
|
)
|
||||||
{
|
{
|
||||||
*rest = filename;
|
*rest = filename;
|
||||||
return &dbmetod;
|
return &default_dbmethod;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user