prefix all struct HDB elements with hdb_

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@12880 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2003-09-19 00:25:35 +00:00
parent ef91ed3046
commit 0540f13b86
29 changed files with 372 additions and 385 deletions

View File

@@ -81,7 +81,7 @@ _hdb_fetch(krb5_context context, HDB *db, unsigned flags, hdb_entry *entry)
int code;
hdb_principal2key(context, entry->principal, &key);
code = db->_get(context, db, key, &value);
code = db->hdb__get(context, db, key, &value);
krb5_data_free(&key);
if(code)
return code;
@@ -89,7 +89,7 @@ _hdb_fetch(krb5_context context, HDB *db, unsigned flags, hdb_entry *entry)
krb5_data_free(&value);
if (code)
return code;
if (db->master_key_set && (flags & HDB_F_DECRYPT)) {
if (db->hdb_master_key_set && (flags & HDB_F_DECRYPT)) {
code = hdb_unseal_keys (context, db, entry);
if (code)
hdb_free_entry(context, entry);
@@ -123,7 +123,7 @@ _hdb_store(krb5_context context, HDB *db, unsigned flags, hdb_entry *entry)
return code;
}
hdb_entry2value(context, entry, &value);
code = db->_put(context, db, flags & HDB_F_REPLACE, key, value);
code = db->hdb__put(context, db, flags & HDB_F_REPLACE, key, value);
krb5_data_free(&value);
krb5_data_free(&key);
return code;
@@ -136,7 +136,7 @@ _hdb_remove(krb5_context context, HDB *db, hdb_entry *entry)
int code;
hdb_principal2key(context, entry->principal, &key);
code = db->_del(context, db, key);
code = db->hdb__del(context, db, key);
krb5_data_free(&key);
return code;
}

View File

@@ -81,7 +81,7 @@ update_keytypes(krb5_context context, HDB *db, hdb_entry *entry, void *data)
save_val = entry->keys.val;
entry->keys.len = n;
entry->keys.val = k;
ret = new->store(context, new, HDB_F_REPLACE, entry);
ret = new->hdb_store(context, new, HDB_F_REPLACE, entry);
entry->keys.len = save_len;
entry->keys.val = save_val;
for(i = 0; i < n; i++)
@@ -94,14 +94,14 @@ static krb5_error_code
update_version2(krb5_context context, HDB *db, hdb_entry *entry, void *data)
{
HDB *new = data;
if(!db->master_key_set) {
if(!db->hdb_master_key_set) {
int i;
for(i = 0; i < entry->keys.len; i++) {
free(entry->keys.val[i].mkvno);
entry->keys.val[i].mkvno = NULL;
}
}
new->store(context, new, HDB_F_REPLACE, entry);
new->hdb_store(context, new, HDB_F_REPLACE, entry);
return 0;
}
@@ -169,7 +169,7 @@ main(int argc, char **argv)
if (ret)
krb5_err(context, 1, ret, "hdb_set_master_keyfile");
}
ret = db->open(context, db, O_RDONLY, 0);
ret = db->hdb_open(context, db, O_RDONLY, 0);
if(ret == HDB_ERR_BADVERSION) {
krb5_data tag;
krb5_data version;
@@ -177,7 +177,7 @@ main(int argc, char **argv)
unsigned ver;
tag.data = HDB_DB_FORMAT_ENTRY;
tag.length = strlen(tag.data);
ret = (*db->_get)(context, db, tag, &version);
ret = (*db->hdb__get)(context, db, tag, &version);
if(ret)
krb5_errx(context, 1, "database is wrong version, "
"but couldn't find version key (%s)",
@@ -197,7 +197,7 @@ main(int argc, char **argv)
ver, HDB_DB_FORMAT);
} else if(ret)
krb5_err(context, 1, ret, "%s", old_database);
ret = new->open(context, new, O_CREAT|O_EXCL|O_RDWR, 0600);
ret = new->hdb_open(context, new, O_CREAT|O_EXCL|O_RDWR, 0600);
if(ret)
krb5_err(context, 1, ret, "%s", new_database);
if(update_version)
@@ -206,8 +206,8 @@ main(int argc, char **argv)
ret = hdb_foreach(context, db, 0, update_keytypes, new);
if(ret != 0)
krb5_err(context, 1, ret, "hdb_foreach");
db->close(context, db);
new->close(context, new);
db->hdb_close(context, db);
new->hdb_close(context, new);
krb5_warnx(context, "wrote converted database to `%s'", new_database);
return 0;
}

View File

@@ -46,7 +46,7 @@ RCSID("$Id$");
static krb5_error_code
DB_close(krb5_context context, HDB *db)
{
DB *d = (DB*)db->db;
DB *d = (DB*)db->hdb_db;
d->close(d);
return 0;
}
@@ -57,7 +57,7 @@ DB_destroy(krb5_context context, HDB *db)
krb5_error_code ret;
ret = hdb_clear_master_key (context, db);
free(db->name);
free(db->hdb_name);
free(db);
return ret;
}
@@ -65,7 +65,7 @@ DB_destroy(krb5_context context, HDB *db)
static krb5_error_code
DB_lock(krb5_context context, HDB *db, int operation)
{
DB *d = (DB*)db->db;
DB *d = (DB*)db->hdb_db;
int fd = (*d->fd)(d);
if(fd < 0)
return HDB_ERR_CANT_LOCK_DB;
@@ -75,7 +75,7 @@ DB_lock(krb5_context context, HDB *db, int operation)
static krb5_error_code
DB_unlock(krb5_context context, HDB *db)
{
DB *d = (DB*)db->db;
DB *d = (DB*)db->hdb_db;
int fd = (*d->fd)(d);
if(fd < 0)
return HDB_ERR_CANT_LOCK_DB;
@@ -87,16 +87,16 @@ static krb5_error_code
DB_seq(krb5_context context, HDB *db,
unsigned flags, hdb_entry *entry, int flag)
{
DB *d = (DB*)db->db;
DB *d = (DB*)db->hdb_db;
DBT key, value;
krb5_data key_data, data;
int code;
code = db->lock(context, db, HDB_RLOCK);
code = db->hdb_lock(context, db, HDB_RLOCK);
if(code == -1)
return HDB_ERR_DB_INUSE;
code = d->seq(d, &key, &value, flag);
db->unlock(context, db); /* XXX check value */
db->hdb_unlock(context, db); /* XXX check value */
if(code == -1)
return errno;
if(code == 1)
@@ -108,7 +108,7 @@ DB_seq(krb5_context context, HDB *db,
data.length = value.size;
if (hdb_value2entry(context, &data, entry))
return DB_seq(context, db, flags, entry, R_NEXT);
if (db->master_key_set && (flags & HDB_F_DECRYPT)) {
if (db->hdb_master_key_set && (flags & HDB_F_DECRYPT)) {
code = hdb_unseal_keys (context, db, entry);
if (code)
hdb_free_entry (context, entry);
@@ -146,7 +146,7 @@ DB_rename(krb5_context context, HDB *db, const char *new_name)
int ret;
char *old, *new;
asprintf(&old, "%s.db", db->name);
asprintf(&old, "%s.db", db->hdb_name);
asprintf(&new, "%s.db", new_name);
ret = rename(old, new);
free(old);
@@ -154,25 +154,25 @@ DB_rename(krb5_context context, HDB *db, const char *new_name)
if(ret)
return errno;
free(db->name);
db->name = strdup(new_name);
free(db->hdb_name);
db->hdb_name = strdup(new_name);
return 0;
}
static krb5_error_code
DB__get(krb5_context context, HDB *db, krb5_data key, krb5_data *reply)
{
DB *d = (DB*)db->db;
DB *d = (DB*)db->hdb_db;
DBT k, v;
int code;
k.data = key.data;
k.size = key.length;
code = db->lock(context, db, HDB_RLOCK);
code = db->hdb_lock(context, db, HDB_RLOCK);
if(code)
return code;
code = d->get(d, &k, &v, 0);
db->unlock(context, db);
db->hdb_unlock(context, db);
if(code < 0)
return errno;
if(code == 1)
@@ -186,7 +186,7 @@ static krb5_error_code
DB__put(krb5_context context, HDB *db, int replace,
krb5_data key, krb5_data value)
{
DB *d = (DB*)db->db;
DB *d = (DB*)db->hdb_db;
DBT k, v;
int code;
@@ -194,11 +194,11 @@ DB__put(krb5_context context, HDB *db, int replace,
k.size = key.length;
v.data = value.data;
v.size = value.length;
code = db->lock(context, db, HDB_WLOCK);
code = db->hdb_lock(context, db, HDB_WLOCK);
if(code)
return code;
code = d->put(d, &k, &v, replace ? 0 : R_NOOVERWRITE);
db->unlock(context, db);
db->hdb_unlock(context, db);
if(code < 0)
return errno;
if(code == 1)
@@ -209,16 +209,16 @@ DB__put(krb5_context context, HDB *db, int replace,
static krb5_error_code
DB__del(krb5_context context, HDB *db, krb5_data key)
{
DB *d = (DB*)db->db;
DB *d = (DB*)db->hdb_db;
DBT k;
krb5_error_code code;
k.data = key.data;
k.size = key.length;
code = db->lock(context, db, HDB_WLOCK);
code = db->hdb_lock(context, db, HDB_WLOCK);
if(code)
return code;
code = d->del(d, &k, 0);
db->unlock(context, db);
db->hdb_unlock(context, db);
if(code == 1)
return HDB_ERR_NOENTRY;
if(code < 0)
@@ -232,20 +232,20 @@ DB_open(krb5_context context, HDB *db, int flags, mode_t mode)
char *fn;
krb5_error_code ret;
asprintf(&fn, "%s.db", db->name);
asprintf(&fn, "%s.db", db->hdb_name);
if (fn == NULL) {
krb5_set_error_string(context, "malloc: out of memory");
return ENOMEM;
}
db->db = dbopen(fn, flags, mode, DB_BTREE, NULL);
db->hdb_db = dbopen(fn, flags, mode, DB_BTREE, NULL);
free(fn);
/* try to open without .db extension */
if(db->db == NULL && errno == ENOENT)
db->db = dbopen(db->name, flags, mode, DB_BTREE, NULL);
if(db->db == NULL) {
if(db->hdb_db == NULL && errno == ENOENT)
db->hdb_db = dbopen(db->hdb_name, flags, mode, DB_BTREE, NULL);
if(db->hdb_db == NULL) {
ret = errno;
krb5_set_error_string(context, "dbopen (%s): %s",
db->name, strerror(ret));
db->hdb_name, strerror(ret));
return ret;
}
if((flags & O_ACCMODE) == O_RDONLY)
@@ -269,30 +269,30 @@ hdb_db_create(krb5_context context, HDB **db,
return ENOMEM;
}
(*db)->db = NULL;
(*db)->name = strdup(filename);
if ((*db)->name == NULL) {
(*db)->hdb_db = NULL;
(*db)->hdb_name = strdup(filename);
if ((*db)->hdb_name == NULL) {
krb5_set_error_string(context, "malloc: out of memory");
free(*db);
*db = NULL;
return ENOMEM;
}
(*db)->master_key_set = 0;
(*db)->openp = 0;
(*db)->open = DB_open;
(*db)->close = DB_close;
(*db)->fetch = _hdb_fetch;
(*db)->store = _hdb_store;
(*db)->remove = _hdb_remove;
(*db)->firstkey = DB_firstkey;
(*db)->nextkey= DB_nextkey;
(*db)->lock = DB_lock;
(*db)->unlock = DB_unlock;
(*db)->rename = DB_rename;
(*db)->_get = DB__get;
(*db)->_put = DB__put;
(*db)->_del = DB__del;
(*db)->destroy = DB_destroy;
(*db)->hdb_master_key_set = 0;
(*db)->hdb_openp = 0;
(*db)->hdb_open = DB_open;
(*db)->hdb_close = DB_close;
(*db)->hdb_fetch = _hdb_fetch;
(*db)->hdb_store = _hdb_store;
(*db)->hdb_remove = _hdb_remove;
(*db)->hdb_firstkey = DB_firstkey;
(*db)->hdb_nextkey= DB_nextkey;
(*db)->hdb_lock = DB_lock;
(*db)->hdb_unlock = DB_unlock;
(*db)->hdb_rename = DB_rename;
(*db)->hdb__get = DB__get;
(*db)->hdb__put = DB__put;
(*db)->hdb__del = DB__del;
(*db)->hdb_destroy = DB_destroy;
return 0;
}

View File

@@ -48,11 +48,11 @@ RCSID("$Id$");
static krb5_error_code
DB_close(krb5_context context, HDB *db)
{
DB *d = (DB*)db->db;
DBC *dbcp = (DBC*)db->dbc;
DB *d = (DB*)db->hdb_db;
DBC *dbcp = (DBC*)db->hdb_dbc;
dbcp->c_close(dbcp);
db->dbc = 0;
db->hdb_dbc = 0;
d->close(d, 0);
return 0;
}
@@ -63,7 +63,7 @@ DB_destroy(krb5_context context, HDB *db)
krb5_error_code ret;
ret = hdb_clear_master_key (context, db);
free(db->name);
free(db->hdb_name);
free(db);
return ret;
}
@@ -71,7 +71,7 @@ DB_destroy(krb5_context context, HDB *db)
static krb5_error_code
DB_lock(krb5_context context, HDB *db, int operation)
{
DB *d = (DB*)db->db;
DB *d = (DB*)db->hdb_db;
int fd;
if ((*d->fd)(d, &fd))
return HDB_ERR_CANT_LOCK_DB;
@@ -81,7 +81,7 @@ DB_lock(krb5_context context, HDB *db, int operation)
static krb5_error_code
DB_unlock(krb5_context context, HDB *db)
{
DB *d = (DB*)db->db;
DB *d = (DB*)db->hdb_db;
int fd;
if ((*d->fd)(d, &fd))
return HDB_ERR_CANT_LOCK_DB;
@@ -94,16 +94,16 @@ DB_seq(krb5_context context, HDB *db,
unsigned flags, hdb_entry *entry, int flag)
{
DBT key, value;
DBC *dbcp = db->dbc;
DBC *dbcp = db->hdb_dbc;
krb5_data key_data, data;
int code;
memset(&key, 0, sizeof(DBT));
memset(&value, 0, sizeof(DBT));
if (db->lock(context, db, HDB_RLOCK))
if (db->hdb_lock(context, db, HDB_RLOCK))
return HDB_ERR_DB_INUSE;
code = dbcp->c_get(dbcp, &key, &value, flag);
db->unlock(context, db); /* XXX check value */
db->hdb_unlock(context, db); /* XXX check value */
if (code == DB_NOTFOUND)
return HDB_ERR_NOENTRY;
if (code)
@@ -115,7 +115,7 @@ DB_seq(krb5_context context, HDB *db,
data.length = value.size;
if (hdb_value2entry(context, &data, entry))
return DB_seq(context, db, flags, entry, DB_NEXT);
if (db->master_key_set && (flags & HDB_F_DECRYPT)) {
if (db->hdb_master_key_set && (flags & HDB_F_DECRYPT)) {
code = hdb_unseal_keys (context, db, entry);
if (code)
hdb_free_entry (context, entry);
@@ -153,7 +153,7 @@ DB_rename(krb5_context context, HDB *db, const char *new_name)
int ret;
char *old, *new;
asprintf(&old, "%s.db", db->name);
asprintf(&old, "%s.db", db->hdb_name);
asprintf(&new, "%s.db", new_name);
ret = rename(old, new);
free(old);
@@ -161,15 +161,15 @@ DB_rename(krb5_context context, HDB *db, const char *new_name)
if(ret)
return errno;
free(db->name);
db->name = strdup(new_name);
free(db->hdb_name);
db->hdb_name = strdup(new_name);
return 0;
}
static krb5_error_code
DB__get(krb5_context context, HDB *db, krb5_data key, krb5_data *reply)
{
DB *d = (DB*)db->db;
DB *d = (DB*)db->hdb_db;
DBT k, v;
int code;
@@ -178,10 +178,10 @@ DB__get(krb5_context context, HDB *db, krb5_data key, krb5_data *reply)
k.data = key.data;
k.size = key.length;
k.flags = 0;
if ((code = db->lock(context, db, HDB_RLOCK)))
if ((code = db->hdb_lock(context, db, HDB_RLOCK)))
return code;
code = d->get(d, NULL, &k, &v, 0);
db->unlock(context, db);
db->hdb_unlock(context, db);
if(code == DB_NOTFOUND)
return HDB_ERR_NOENTRY;
if(code)
@@ -195,7 +195,7 @@ static krb5_error_code
DB__put(krb5_context context, HDB *db, int replace,
krb5_data key, krb5_data value)
{
DB *d = (DB*)db->db;
DB *d = (DB*)db->hdb_db;
DBT k, v;
int code;
@@ -207,10 +207,10 @@ DB__put(krb5_context context, HDB *db, int replace,
v.data = value.data;
v.size = value.length;
v.flags = 0;
if ((code = db->lock(context, db, HDB_WLOCK)))
if ((code = db->hdb_lock(context, db, HDB_WLOCK)))
return code;
code = d->put(d, NULL, &k, &v, replace ? 0 : DB_NOOVERWRITE);
db->unlock(context, db);
db->hdb_unlock(context, db);
if(code == DB_KEYEXIST)
return HDB_ERR_EXISTS;
if(code)
@@ -221,18 +221,18 @@ DB__put(krb5_context context, HDB *db, int replace,
static krb5_error_code
DB__del(krb5_context context, HDB *db, krb5_data key)
{
DB *d = (DB*)db->db;
DB *d = (DB*)db->hdb_db;
DBT k;
krb5_error_code code;
memset(&k, 0, sizeof(DBT));
k.data = key.data;
k.size = key.length;
k.flags = 0;
code = db->lock(context, db, HDB_WLOCK);
code = db->hdb_lock(context, db, HDB_WLOCK);
if(code)
return code;
code = d->del(d, NULL, &k, 0);
db->unlock(context, db);
db->hdb_unlock(context, db);
if(code == DB_NOTFOUND)
return HDB_ERR_NOENTRY;
if(code)
@@ -260,34 +260,34 @@ DB_open(krb5_context context, HDB *db, int flags, mode_t mode)
if (flags & O_TRUNC)
myflags |= DB_TRUNCATE;
asprintf(&fn, "%s.db", db->name);
asprintf(&fn, "%s.db", db->hdb_name);
if (fn == NULL) {
krb5_set_error_string(context, "malloc: out of memory");
return ENOMEM;
}
db_create(&d, NULL, 0);
db->db = d;
db->hdb_db = d;
#if (DB_VERSION_MAJOR > 3) && (DB_VERSION_MINOR > 0)
if ((ret = d->open(db->db, NULL, fn, NULL, DB_BTREE, myflags, mode))) {
if ((ret = d->open(db->hdb_db, NULL, fn, NULL, DB_BTREE, myflags, mode))) {
#else
if ((ret = d->open(db->db, fn, NULL, DB_BTREE, myflags, mode))) {
if ((ret = d->open(db->hdb_db, fn, NULL, DB_BTREE, myflags, mode))) {
#endif
if(ret == ENOENT)
/* try to open without .db extension */
#if (DB_VERSION_MAJOR > 3) && (DB_VERSION_MINOR > 0)
if (d->open(db->db, NULL, db->name, NULL, DB_BTREE, myflags, mode)) {
if (d->open(db->hdb_db, NULL, db->hdb_name, NULL, DB_BTREE, myflags, mode)) {
#else
if (d->open(db->db, db->name, NULL, DB_BTREE, myflags, mode)) {
if (d->open(db->hdb_db, db->hdb_name, NULL, DB_BTREE, myflags, mode)) {
#endif
free(fn);
krb5_set_error_string(context, "opening %s: %s",
db->name, strerror(ret));
db->hdb_name, strerror(ret));
return ret;
}
}
free(fn);
ret = d->cursor(d, NULL, (DBC **)&db->dbc, 0);
ret = d->cursor(d, NULL, (DBC **)&db->hdb_dbc, 0);
if (ret) {
krb5_set_error_string(context, "d->cursor: %s", strerror(ret));
return ret;
@@ -312,30 +312,30 @@ hdb_db_create(krb5_context context, HDB **db,
return ENOMEM;
}
(*db)->db = NULL;
(*db)->name = strdup(filename);
if ((*db)->name == NULL) {
(*db)->hdb_db = NULL;
(*db)->hdb_name = strdup(filename);
if ((*db)->hdb_name == NULL) {
krb5_set_error_string(context, "malloc: out of memory");
free(*db);
*db = NULL;
return ENOMEM;
}
(*db)->master_key_set = 0;
(*db)->openp = 0;
(*db)->open = DB_open;
(*db)->close = DB_close;
(*db)->fetch = _hdb_fetch;
(*db)->store = _hdb_store;
(*db)->remove = _hdb_remove;
(*db)->firstkey = DB_firstkey;
(*db)->nextkey= DB_nextkey;
(*db)->lock = DB_lock;
(*db)->unlock = DB_unlock;
(*db)->rename = DB_rename;
(*db)->_get = DB__get;
(*db)->_put = DB__put;
(*db)->_del = DB__del;
(*db)->destroy = DB_destroy;
(*db)->hdb_master_key_set = 0;
(*db)->hdb_openp = 0;
(*db)->hdb_open = DB_open;
(*db)->hdb_close = DB_close;
(*db)->hdb_fetch = _hdb_fetch;
(*db)->hdb_store = _hdb_store;
(*db)->hdb_remove = _hdb_remove;
(*db)->hdb_firstkey = DB_firstkey;
(*db)->hdb_nextkey= DB_nextkey;
(*db)->hdb_lock = DB_lock;
(*db)->hdb_unlock = DB_unlock;
(*db)->hdb_rename = DB_rename;
(*db)->hdb__get = DB__get;
(*db)->hdb__put = DB__put;
(*db)->hdb__del = DB__del;
(*db)->hdb_destroy = DB_destroy;
return 0;
}
#endif /* HAVE_DB3 */

View File

@@ -216,7 +216,7 @@ LDAP_get_string_value(HDB * db, LDAPMessage * entry,
char **vals;
int ret;
vals = ldap_get_values((LDAP *) db->db, entry, (char *) attribute);
vals = ldap_get_values((LDAP *) db->hdb_db, entry, (char *) attribute);
if (vals == NULL) {
return HDB_ERR_NOENTRY;
}
@@ -238,7 +238,7 @@ LDAP_get_integer_value(HDB * db, LDAPMessage * entry,
{
char **vals;
vals = ldap_get_values((LDAP *) db->db, entry, (char *) attribute);
vals = ldap_get_values((LDAP *) db->hdb_db, entry, (char *) attribute);
if (vals == NULL) {
return HDB_ERR_NOENTRY;
}
@@ -520,14 +520,14 @@ LDAP_dn2principal(krb5_context context, HDB * db, const char *dn,
char **values;
LDAPMessage *res = NULL, *e;
rc = ldap_set_option((LDAP *) db->db, LDAP_OPT_SIZELIMIT, (const void *)&limit);
rc = ldap_set_option((LDAP *) db->hdb_db, LDAP_OPT_SIZELIMIT, (const void *)&limit);
if (rc != LDAP_SUCCESS) {
krb5_set_error_string(context, "ldap_set_option: %s", ldap_err2string(rc));
ret = HDB_ERR_BADVERSION;
goto out;
}
rc = ldap_search_s((LDAP *) db->db, dn, LDAP_SCOPE_BASE,
rc = ldap_search_s((LDAP *) db->hdb_db, dn, LDAP_SCOPE_BASE,
"(objectclass=krb5Principal)", krb5principal_attrs,
0, &res);
if (rc != LDAP_SUCCESS) {
@@ -536,13 +536,13 @@ LDAP_dn2principal(krb5_context context, HDB * db, const char *dn,
goto out;
}
e = ldap_first_entry((LDAP *) db->db, res);
e = ldap_first_entry((LDAP *) db->hdb_db, res);
if (e == NULL) {
ret = HDB_ERR_NOENTRY;
goto out;
}
values = ldap_get_values((LDAP *) db->db, e, "krb5PrincipalName");
values = ldap_get_values((LDAP *) db->hdb_db, e, "krb5PrincipalName");
if (values == NULL) {
ret = HDB_ERR_NOENTRY;
goto out;
@@ -578,14 +578,14 @@ LDAP__lookup_princ(krb5_context context, HDB * db, const char *princname,
goto out;
}
rc = ldap_set_option((LDAP *) db->db, LDAP_OPT_SIZELIMIT, (const void *)&limit);
rc = ldap_set_option((LDAP *) db->hdb_db, LDAP_OPT_SIZELIMIT, (const void *)&limit);
if (rc != LDAP_SUCCESS) {
krb5_set_error_string(context, "ldap_set_option: %s", ldap_err2string(rc));
ret = HDB_ERR_BADVERSION;
goto out;
}
rc = ldap_search_s((LDAP *) db->db, db->name, LDAP_SCOPE_ONELEVEL, filter,
rc = ldap_search_s((LDAP *) db->hdb_db, db->hdb_name, LDAP_SCOPE_ONELEVEL, filter,
krb5kdcentry_attrs, 0, msg);
if (rc != LDAP_SUCCESS) {
krb5_set_error_string(context, "ldap_search_s: %s", ldap_err2string(rc));
@@ -655,7 +655,7 @@ LDAP_message2entry(krb5_context context, HDB * db, LDAPMessage * msg,
ent->kvno = 0;
}
keys = ldap_get_values_len((LDAP *) db->db, msg, "krb5Key");
keys = ldap_get_values_len((LDAP *) db->hdb_db, msg, "krb5Key");
if (keys != NULL) {
int i;
size_t l;
@@ -795,7 +795,7 @@ LDAP_message2entry(krb5_context context, HDB * db, LDAPMessage * msg,
ent->max_renew = NULL;
}
values = ldap_get_values((LDAP *) db->db, msg, "krb5KDCFlags");
values = ldap_get_values((LDAP *) db->hdb_db, msg, "krb5KDCFlags");
if (values != NULL) {
tmp = strtoul(values[0], (char **) NULL, 10);
if (tmp == ULONG_MAX && errno == ERANGE) {
@@ -808,7 +808,7 @@ LDAP_message2entry(krb5_context context, HDB * db, LDAPMessage * msg,
}
ent->flags = int2HDBFlags(tmp);
values = ldap_get_values((LDAP *) db->db, msg, "krb5EncryptionType");
values = ldap_get_values((LDAP *) db->hdb_db, msg, "krb5EncryptionType");
if (values != NULL) {
int i;
@@ -843,8 +843,8 @@ LDAP_message2entry(krb5_context context, HDB * db, LDAPMessage * msg,
static krb5_error_code LDAP_close(krb5_context context, HDB * db)
{
ldap_unbind_ext((LDAP *) db->db, NULL, NULL);
db->db = NULL;
ldap_unbind_ext((LDAP *) db->hdb_db, NULL, NULL);
db->hdb_db = NULL;
return 0;
}
@@ -867,13 +867,13 @@ LDAP_seq(krb5_context context, HDB * db, unsigned flags, hdb_entry * entry)
krb5_error_code ret;
LDAPMessage *e;
msgid = db->openp; /* BOGUS OVERLOADING */
msgid = db->hdb_openp; /* BOGUS OVERLOADING */
if (msgid < 0) {
return HDB_ERR_NOENTRY;
}
do {
rc = ldap_result((LDAP *) db->db, msgid, LDAP_MSG_ONE, NULL, &e);
rc = ldap_result((LDAP *) db->hdb_db, msgid, LDAP_MSG_ONE, NULL, &e);
switch (rc) {
case LDAP_RES_SEARCH_ENTRY:
/* We have an entry. Parse it. */
@@ -883,30 +883,30 @@ LDAP_seq(krb5_context context, HDB * db, unsigned flags, hdb_entry * entry)
case LDAP_RES_SEARCH_RESULT:
/* We're probably at the end of the results. If not, abandon. */
parserc =
ldap_parse_result((LDAP *) db->db, e, NULL, NULL, NULL,
ldap_parse_result((LDAP *) db->hdb_db, e, NULL, NULL, NULL,
NULL, NULL, 1);
if (parserc != LDAP_SUCCESS
&& parserc != LDAP_MORE_RESULTS_TO_RETURN) {
krb5_set_error_string(context, "ldap_parse_result: %s", ldap_err2string(parserc));
ldap_abandon((LDAP *) db->db, msgid);
ldap_abandon((LDAP *) db->hdb_db, msgid);
}
ret = HDB_ERR_NOENTRY;
db->openp = -1;
db->hdb_openp = -1;
break;
case 0:
case -1:
default:
/* Some unspecified error (timeout?). Abandon. */
ldap_msgfree(e);
ldap_abandon((LDAP *) db->db, msgid);
ldap_abandon((LDAP *) db->hdb_db, msgid);
ret = HDB_ERR_NOENTRY;
db->openp = -1;
db->hdb_openp = -1;
break;
}
} while (rc == LDAP_RES_SEARCH_REFERENCE);
if (ret == 0) {
if (db->master_key_set && (flags & HDB_F_DECRYPT)) {
if (db->hdb_master_key_set && (flags & HDB_F_DECRYPT)) {
ret = hdb_unseal_keys(context, db, entry);
if (ret)
hdb_free_entry(context,entry);
@@ -924,20 +924,20 @@ LDAP_firstkey(krb5_context context, HDB * db, unsigned flags,
(void) LDAP__connect(context, db);
rc = ldap_set_option((LDAP *) db->db, LDAP_OPT_SIZELIMIT, (const void *)&limit);
rc = ldap_set_option((LDAP *) db->hdb_db, LDAP_OPT_SIZELIMIT, (const void *)&limit);
if (rc != LDAP_SUCCESS) {
krb5_set_error_string(context, "ldap_set_option: %s", ldap_err2string(rc));
return HDB_ERR_BADVERSION;
}
msgid = ldap_search((LDAP *) db->db, db->name,
msgid = ldap_search((LDAP *) db->hdb_db, db->hdb_name,
LDAP_SCOPE_ONELEVEL, "(objectclass=krb5KDCEntry)",
krb5kdcentry_attrs, 0);
if (msgid < 0) {
return HDB_ERR_NOENTRY;
}
db->openp = msgid;
db->hdb_openp = msgid;
return LDAP_seq(context, db, flags, entry);
}
@@ -966,43 +966,43 @@ static krb5_error_code LDAP__connect(krb5_context context, HDB * db)
*/
struct berval bv = { 0, "" };
if (db->db != NULL) {
if (db->hdb_db != NULL) {
/* connection has been opened. ping server. */
struct sockaddr_un addr;
socklen_t len;
int sd;
if (ldap_get_option((LDAP *) db->db, LDAP_OPT_DESC, &sd) == 0 &&
if (ldap_get_option((LDAP *) db->hdb_db, LDAP_OPT_DESC, &sd) == 0 &&
getpeername(sd, (struct sockaddr *) &addr, &len) < 0) {
/* the other end has died. reopen. */
LDAP_close(context, db);
}
}
if (db->db != NULL) {
if (db->hdb_db != NULL) {
/* server is UP */
return 0;
}
rc = ldap_initialize((LDAP **) & db->db, "ldapi:///");
rc = ldap_initialize((LDAP **) & db->hdb_db, "ldapi:///");
if (rc != LDAP_SUCCESS) {
krb5_set_error_string(context, "ldap_initialize: %s", ldap_err2string(rc));
return HDB_ERR_NOENTRY;
}
rc = ldap_set_option((LDAP *) db->db, LDAP_OPT_PROTOCOL_VERSION, (const void *)&version);
rc = ldap_set_option((LDAP *) db->hdb_db, LDAP_OPT_PROTOCOL_VERSION, (const void *)&version);
if (rc != LDAP_SUCCESS) {
krb5_set_error_string(context, "ldap_set_option: %s", ldap_err2string(rc));
ldap_unbind_ext((LDAP *) db->db, NULL, NULL);
db->db = NULL;
ldap_unbind_ext((LDAP *) db->hdb_db, NULL, NULL);
db->hdb_db = NULL;
return HDB_ERR_BADVERSION;
}
rc = ldap_sasl_bind_s((LDAP *) db->db, NULL, "EXTERNAL", &bv, NULL, NULL, NULL);
rc = ldap_sasl_bind_s((LDAP *) db->hdb_db, NULL, "EXTERNAL", &bv, NULL, NULL, NULL);
if (rc != LDAP_SUCCESS) {
krb5_set_error_string(context, "ldap_sasl_bind_s: %s", ldap_err2string(rc));
ldap_unbind_ext((LDAP *) db->db, NULL, NULL);
db->db = NULL;
ldap_unbind_ext((LDAP *) db->hdb_db, NULL, NULL);
db->hdb_db = NULL;
return HDB_ERR_BADVERSION;
}
@@ -1040,7 +1040,7 @@ LDAP_fetch(krb5_context context, HDB * db, unsigned flags,
return ret;
}
e = ldap_first_entry((LDAP *) db->db, msg);
e = ldap_first_entry((LDAP *) db->hdb_db, msg);
if (e == NULL) {
ret = HDB_ERR_NOENTRY;
goto out;
@@ -1048,7 +1048,7 @@ LDAP_fetch(krb5_context context, HDB * db, unsigned flags,
ret = LDAP_message2entry(context, db, e, entry);
if (ret == 0) {
if (db->master_key_set && (flags & HDB_F_DECRYPT)) {
if (db->hdb_master_key_set && (flags & HDB_F_DECRYPT)) {
ret = hdb_unseal_keys(context, db, entry);
if (ret)
hdb_free_entry(context,entry);
@@ -1079,7 +1079,7 @@ LDAP_store(krb5_context context, HDB * db, unsigned flags,
ret = LDAP__lookup_princ(context, db, name, &msg);
if (ret == 0) {
e = ldap_first_entry((LDAP *) db->db, msg);
e = ldap_first_entry((LDAP *) db->hdb_db, msg);
}
ret = hdb_seal_keys(context, db, entry);
@@ -1120,8 +1120,8 @@ LDAP_store(krb5_context context, HDB * db, unsigned flags,
goto out;
}
if (db->name != NULL) {
ret = asprintf(&dn, "cn=%s,%s", name, db->name);
if (db->hdb_name != NULL) {
ret = asprintf(&dn, "cn=%s,%s", name, db->hdb_name);
} else {
/* A bit bogus, but we don't have a search base */
ret = asprintf(&dn, "cn=%s", name);
@@ -1133,7 +1133,7 @@ LDAP_store(krb5_context context, HDB * db, unsigned flags,
}
} else if (flags & HDB_F_REPLACE) {
/* Entry exists, and we're allowed to replace it. */
dn = ldap_get_dn((LDAP *) db->db, e);
dn = ldap_get_dn((LDAP *) db->hdb_db, e);
} else {
/* Entry exists, but we're not allowed to replace it. Bail. */
ret = HDB_ERR_EXISTS;
@@ -1143,11 +1143,11 @@ LDAP_store(krb5_context context, HDB * db, unsigned flags,
/* write entry into directory */
if (e == NULL) {
/* didn't exist before */
rc = ldap_add_s((LDAP *) db->db, dn, mods);
rc = ldap_add_s((LDAP *) db->hdb_db, dn, mods);
errfn = "ldap_add_s";
} else {
/* already existed, send deltas only */
rc = ldap_modify_s((LDAP *) db->db, dn, mods);
rc = ldap_modify_s((LDAP *) db->hdb_db, dn, mods);
errfn = "ldap_modify_s";
}
@@ -1193,26 +1193,26 @@ LDAP_remove(krb5_context context, HDB * db, hdb_entry * entry)
goto out;
}
e = ldap_first_entry((LDAP *) db->db, msg);
e = ldap_first_entry((LDAP *) db->hdb_db, msg);
if (e == NULL) {
ret = HDB_ERR_NOENTRY;
goto out;
}
dn = ldap_get_dn((LDAP *) db->db, e);
dn = ldap_get_dn((LDAP *) db->hdb_db, e);
if (dn == NULL) {
ret = HDB_ERR_NOENTRY;
goto out;
}
rc = ldap_set_option((LDAP *) db->db, LDAP_OPT_SIZELIMIT, (const void *)&limit);
rc = ldap_set_option((LDAP *) db->hdb_db, LDAP_OPT_SIZELIMIT, (const void *)&limit);
if (rc != LDAP_SUCCESS) {
krb5_set_error_string(context, "ldap_set_option: %s", ldap_err2string(rc));
ret = HDB_ERR_BADVERSION;
goto out;
}
rc = ldap_delete_s((LDAP *) db->db, dn);
rc = ldap_delete_s((LDAP *) db->hdb_db, dn);
if (rc == LDAP_SUCCESS) {
ret = 0;
} else {
@@ -1232,38 +1232,13 @@ LDAP_remove(krb5_context context, HDB * db, hdb_entry * entry)
return ret;
}
static krb5_error_code
LDAP__get(krb5_context context, HDB * db, krb5_data key, krb5_data * reply)
{
fprintf(stderr, "LDAP__get not implemented\n");
abort();
return 0;
}
static krb5_error_code
LDAP__put(krb5_context context, HDB * db, int replace,
krb5_data key, krb5_data value)
{
fprintf(stderr, "LDAP__put not implemented\n");
abort();
return 0;
}
static krb5_error_code
LDAP__del(krb5_context context, HDB * db, krb5_data key)
{
fprintf(stderr, "LDAP__del not implemented\n");
abort();
return 0;
}
static krb5_error_code LDAP_destroy(krb5_context context, HDB * db)
{
krb5_error_code ret;
ret = hdb_clear_master_key(context, db);
if (db->name != NULL) {
free(db->name);
if (db->hdb_name != NULL) {
free(db->hdb_name);
}
free(db);
@@ -1278,8 +1253,9 @@ hdb_ldap_create(krb5_context context, HDB ** db, const char *arg)
krb5_set_error_string(context, "malloc: out of memory");
return ENOMEM;
}
memset(*db, 0, sizeof(**db));
(*db)->db = NULL;
(*db)->hdb_db = NULL;
if (arg == NULL || arg[0] == '\0') {
/*
@@ -1289,10 +1265,10 @@ hdb_ldap_create(krb5_context context, HDB ** db, const char *arg)
* writing entries because we don't know where to
* put new principals.
*/
(*db)->name = NULL;
(*db)->hdb_name = NULL;
} else {
(*db)->name = strdup(arg);
if ((*db)->name == NULL) {
(*db)->hdb_name = strdup(arg);
if ((*db)->hdb_name == NULL) {
krb5_set_error_string(context, "strdup: out of memory");
free(*db);
*db = NULL;
@@ -1300,23 +1276,22 @@ hdb_ldap_create(krb5_context context, HDB ** db, const char *arg)
}
}
(*db)->master_key_set = 0;
(*db)->openp = 0;
(*db)->open = LDAP_open;
(*db)->close = LDAP_close;
(*db)->fetch = LDAP_fetch;
(*db)->store = LDAP_store;
(*db)->remove = LDAP_remove;
(*db)->firstkey = LDAP_firstkey;
(*db)->nextkey = LDAP_nextkey;
(*db)->lock = LDAP_lock;
(*db)->unlock = LDAP_unlock;
(*db)->rename = LDAP_rename;
/* can we ditch these? */
(*db)->_get = LDAP__get;
(*db)->_put = LDAP__put;
(*db)->_del = LDAP__del;
(*db)->destroy = LDAP_destroy;
(*db)->hdb_master_key_set = 0;
(*db)->hdb_openp = 0;
(*db)->hdb_open = LDAP_open;
(*db)->hdb_close = LDAP_close;
(*db)->hdb_fetch = LDAP_fetch;
(*db)->hdb_store = LDAP_store;
(*db)->hdb_remove = LDAP_remove;
(*db)->hdb_firstkey = LDAP_firstkey;
(*db)->hdb_nextkey = LDAP_nextkey;
(*db)->hdb_lock = LDAP_lock;
(*db)->hdb_unlock = LDAP_unlock;
(*db)->hdb_rename = LDAP_rename;
(*db)->hdb__get = NULL;
(*db)->hdb__put = NULL;
(*db)->hdb__del = NULL;
(*db)->hdb_destroy = LDAP_destroy;
return 0;
}

View File

@@ -153,12 +153,12 @@ hdb_foreach(krb5_context context,
{
krb5_error_code ret;
hdb_entry entry;
ret = db->firstkey(context, db, flags, &entry);
ret = db->hdb_firstkey(context, db, flags, &entry);
while(ret == 0){
ret = (*func)(context, db, &entry, data);
hdb_free_entry(context, &entry);
if(ret == 0)
ret = db->nextkey(context, db, flags, &entry);
ret = db->hdb_nextkey(context, db, flags, &entry);
}
if(ret == HDB_ERR_NOENTRY)
ret = 0;
@@ -176,7 +176,7 @@ hdb_check_db_format(krb5_context context, HDB *db)
tag.data = HDB_DB_FORMAT_ENTRY;
tag.length = strlen(tag.data);
ret = (*db->_get)(context, db, tag, &version);
ret = (*db->hdb__get)(context, db, tag, &version);
if(ret)
return ret;
foo = sscanf(version.data, "%u", &ver);
@@ -205,7 +205,7 @@ hdb_init_db(krb5_context context, HDB *db)
snprintf(ver, sizeof(ver), "%u", HDB_DB_FORMAT);
version.data = ver;
version.length = strlen(version.data) + 1; /* zero terminated */
ret = (*db->_put)(context, db, 0, tag, version);
ret = (*db->hdb__put)(context, db, 0, tag, version);
return ret;
}

View File

@@ -52,30 +52,30 @@ enum hdb_lockop{ HDB_RLOCK, HDB_WLOCK };
typedef struct hdb_master_key_data *hdb_master_key;
typedef struct HDB{
void *db;
void *dbc;
char *name;
int master_key_set;
hdb_master_key master_key;
int openp;
void *hdb_db;
void *hdb_dbc;
char *hdb_name;
int hdb_master_key_set;
hdb_master_key hdb_master_key;
int hdb_openp;
krb5_error_code (*open)(krb5_context, struct HDB*, int, mode_t);
krb5_error_code (*close)(krb5_context, struct HDB*);
krb5_error_code (*fetch)(krb5_context, struct HDB*, unsigned, hdb_entry*);
krb5_error_code (*store)(krb5_context, struct HDB*, unsigned, hdb_entry*);
krb5_error_code (*remove)(krb5_context, struct HDB*, hdb_entry*);
krb5_error_code (*firstkey)(krb5_context, struct HDB*,
krb5_error_code (*hdb_open)(krb5_context, struct HDB*, int, mode_t);
krb5_error_code (*hdb_close)(krb5_context, struct HDB*);
krb5_error_code (*hdb_fetch)(krb5_context,struct HDB*,unsigned,hdb_entry*);
krb5_error_code (*hdb_store)(krb5_context,struct HDB*,unsigned,hdb_entry*);
krb5_error_code (*hdb_remove)(krb5_context, struct HDB*, hdb_entry*);
krb5_error_code (*hdb_firstkey)(krb5_context, struct HDB*,
unsigned, hdb_entry*);
krb5_error_code (*nextkey)(krb5_context, struct HDB*,
krb5_error_code (*hdb_nextkey)(krb5_context, struct HDB*,
unsigned, hdb_entry*);
krb5_error_code (*lock)(krb5_context, struct HDB*, int operation);
krb5_error_code (*unlock)(krb5_context, struct HDB*);
krb5_error_code (*rename)(krb5_context, struct HDB*, const char*);
krb5_error_code (*_get)(krb5_context, struct HDB*, krb5_data, krb5_data*);
krb5_error_code (*_put)(krb5_context, struct HDB*, int,
krb5_error_code (*hdb_lock)(krb5_context, struct HDB*, int operation);
krb5_error_code (*hdb_unlock)(krb5_context, struct HDB*);
krb5_error_code (*hdb_rename)(krb5_context, struct HDB*, const char*);
krb5_error_code (*hdb__get)(krb5_context,struct HDB*,krb5_data,krb5_data*);
krb5_error_code (*hdb__put)(krb5_context, struct HDB*, int,
krb5_data, krb5_data);
krb5_error_code (*_del)(krb5_context, struct HDB*, krb5_data);
krb5_error_code (*destroy)(krb5_context, struct HDB*);
krb5_error_code (*hdb__del)(krb5_context, struct HDB*, krb5_data);
krb5_error_code (*hdb_destroy)(krb5_context, struct HDB*);
}HDB;
#define HDB_INTERFACE_VERSION 1

View File

@@ -209,19 +209,19 @@ hdb_get_entry(krb5_context context,
return ret;
ret = hdb_set_master_keyfile (context, db, mkey);
if (ret) {
(*db->destroy)(context, db);
(*db->hdb_destroy)(context, db);
return ret;
}
ret = (*db->open)(context, db, O_RDONLY, 0);
ret = (*db->hdb_open)(context, db, O_RDONLY, 0);
if (ret) {
(*db->destroy)(context, db);
(*db->hdb_destroy)(context, db);
return ret;
}
ent.principal = (krb5_principal)principal;
ret = (*db->fetch)(context, db, HDB_F_DECRYPT, &ent);
(*db->close)(context, db);
(*db->destroy)(context, db);
ret = (*db->hdb_fetch)(context, db, HDB_F_DECRYPT, &ent);
(*db->hdb_close)(context, db);
(*db->hdb_destroy)(context, db);
if(ret == HDB_ERR_NOENTRY)
return KRB5_KT_NOTFOUND;

View File

@@ -423,9 +423,9 @@ hdb_unseal_keys_mkey(krb5_context context, hdb_entry *ent, hdb_master_key mkey)
krb5_error_code
hdb_unseal_keys(krb5_context context, HDB *db, hdb_entry *ent)
{
if (db->master_key_set == 0)
if (db->hdb_master_key_set == 0)
return 0;
return hdb_unseal_keys_mkey(context, ent, db->master_key);
return hdb_unseal_keys_mkey(context, ent, db->hdb_master_key);
}
krb5_error_code
@@ -468,10 +468,10 @@ hdb_seal_keys_mkey(krb5_context context, hdb_entry *ent, hdb_master_key mkey)
krb5_error_code
hdb_seal_keys(krb5_context context, HDB *db, hdb_entry *ent)
{
if (db->master_key_set == 0)
if (db->hdb_master_key_set == 0)
return 0;
return hdb_seal_keys_mkey(context, ent, db->master_key);
return hdb_seal_keys_mkey(context, ent, db->hdb_master_key);
}
krb5_error_code
@@ -485,11 +485,11 @@ hdb_set_master_key (krb5_context context,
ret = hdb_process_master_key(context, 0, key, 0, &mkey);
if (ret)
return ret;
db->master_key = mkey;
db->hdb_master_key = mkey;
#if 0 /* XXX - why? */
des_set_random_generator_seed(key.keyvalue.data);
#endif
db->master_key_set = 1;
db->hdb_master_key_set = 1;
return 0;
}
@@ -508,8 +508,8 @@ hdb_set_master_keyfile (krb5_context context,
krb5_clear_error_string(context);
return 0;
}
db->master_key = key;
db->master_key_set = 1;
db->hdb_master_key = key;
db->hdb_master_key_set = 1;
return ret;
}
@@ -517,9 +517,9 @@ krb5_error_code
hdb_clear_master_key (krb5_context context,
HDB *db)
{
if (db->master_key_set) {
hdb_free_master_key(context, db->master_key);
db->master_key_set = 0;
if (db->hdb_master_key_set) {
hdb_free_master_key(context, db->hdb_master_key);
db->hdb_master_key_set = 0;
}
return 0;
}

View File

@@ -56,7 +56,7 @@ NDBM_destroy(krb5_context context, HDB *db)
krb5_error_code ret;
ret = hdb_clear_master_key (context, db);
free(db->name);
free(db->hdb_name);
free(db);
return 0;
}
@@ -64,14 +64,14 @@ NDBM_destroy(krb5_context context, HDB *db)
static krb5_error_code
NDBM_lock(krb5_context context, HDB *db, int operation)
{
struct ndbm_db *d = db->db;
struct ndbm_db *d = db->hdb_db;
return hdb_lock(d->lock_fd, operation);
}
static krb5_error_code
NDBM_unlock(krb5_context context, HDB *db)
{
struct ndbm_db *d = db->db;
struct ndbm_db *d = db->hdb_db;
return hdb_unlock(d->lock_fd);
}
@@ -80,7 +80,7 @@ NDBM_seq(krb5_context context, HDB *db,
unsigned flags, hdb_entry *entry, int first)
{
struct ndbm_db *d = (struct ndbm_db *)db->db;
struct ndbm_db *d = (struct ndbm_db *)db->hdb_db;
datum key, value;
krb5_data key_data, data;
krb5_error_code ret = 0;
@@ -93,15 +93,15 @@ NDBM_seq(krb5_context context, HDB *db,
return HDB_ERR_NOENTRY;
key_data.data = key.dptr;
key_data.length = key.dsize;
ret = db->lock(context, db, HDB_RLOCK);
ret = db->hdb_lock(context, db, HDB_RLOCK);
if(ret) return ret;
value = dbm_fetch(d->db, key);
db->unlock(context, db);
db->hdb_unlock(context, db);
data.data = value.dptr;
data.length = value.dsize;
if(hdb_value2entry(context, &data, entry))
return NDBM_seq(context, db, flags, entry, 0);
if (db->master_key_set && (flags & HDB_F_DECRYPT)) {
if (db->hdb_master_key_set && (flags & HDB_F_DECRYPT)) {
ret = hdb_unseal_keys (context, db, entry);
if (ret)
hdb_free_entry (context, entry);
@@ -137,7 +137,7 @@ static krb5_error_code
NDBM_rename(krb5_context context, HDB *db, const char *new_name)
{
/* XXX this function will break */
struct ndbm_db *d = db->db;
struct ndbm_db *d = db->hdb_db;
int ret;
char *old_dir, *old_pag, *new_dir, *new_pag;
@@ -145,19 +145,19 @@ NDBM_rename(krb5_context context, HDB *db, const char *new_name)
int lock_fd;
/* lock old and new databases */
ret = db->lock(context, db, HDB_WLOCK);
ret = db->hdb_lock(context, db, HDB_WLOCK);
if(ret)
return ret;
asprintf(&new_lock, "%s.lock", new_name);
if(new_lock == NULL) {
db->unlock(context, db);
db->hdb_unlock(context, db);
krb5_set_error_string(context, "malloc: out of memory");
return ENOMEM;
}
lock_fd = open(new_lock, O_RDWR | O_CREAT, 0600);
if(lock_fd < 0) {
ret = errno;
db->unlock(context, db);
db->hdb_unlock(context, db);
krb5_set_error_string(context, "open(%s): %s", new_lock,
strerror(ret));
free(new_lock);
@@ -166,13 +166,13 @@ NDBM_rename(krb5_context context, HDB *db, const char *new_name)
free(new_lock);
ret = hdb_lock(lock_fd, HDB_WLOCK);
if(ret) {
db->unlock(context, db);
db->hdb_unlock(context, db);
close(lock_fd);
return ret;
}
asprintf(&old_dir, "%s.dir", db->name);
asprintf(&old_pag, "%s.pag", db->name);
asprintf(&old_dir, "%s.dir", db->hdb_name);
asprintf(&old_pag, "%s.pag", db->hdb_name);
asprintf(&new_dir, "%s.dir", new_name);
asprintf(&new_pag, "%s.pag", new_name);
@@ -182,7 +182,7 @@ NDBM_rename(krb5_context context, HDB *db, const char *new_name)
free(new_dir);
free(new_pag);
hdb_unlock(lock_fd);
db->unlock(context, db);
db->hdb_unlock(context, db);
if(ret) {
ret = errno;
@@ -194,25 +194,25 @@ NDBM_rename(krb5_context context, HDB *db, const char *new_name)
close(d->lock_fd);
d->lock_fd = lock_fd;
free(db->name);
db->name = strdup(new_name);
free(db->hdb_name);
db->hdb_name = strdup(new_name);
return 0;
}
static krb5_error_code
NDBM__get(krb5_context context, HDB *db, krb5_data key, krb5_data *reply)
{
struct ndbm_db *d = (struct ndbm_db *)db->db;
struct ndbm_db *d = (struct ndbm_db *)db->hdb_db;
datum k, v;
int code;
k.dptr = key.data;
k.dsize = key.length;
code = db->lock(context, db, HDB_RLOCK);
code = db->hdb_lock(context, db, HDB_RLOCK);
if(code)
return code;
v = dbm_fetch(d->db, k);
db->unlock(context, db);
db->hdb_unlock(context, db);
if(v.dptr == NULL)
return HDB_ERR_NOENTRY;
@@ -224,7 +224,7 @@ static krb5_error_code
NDBM__put(krb5_context context, HDB *db, int replace,
krb5_data key, krb5_data value)
{
struct ndbm_db *d = (struct ndbm_db *)db->db;
struct ndbm_db *d = (struct ndbm_db *)db->hdb_db;
datum k, v;
int code;
@@ -233,11 +233,11 @@ NDBM__put(krb5_context context, HDB *db, int replace,
v.dptr = value.data;
v.dsize = value.length;
code = db->lock(context, db, HDB_WLOCK);
code = db->hdb_lock(context, db, HDB_WLOCK);
if(code)
return code;
code = dbm_store(d->db, k, v, replace ? DBM_REPLACE : DBM_INSERT);
db->unlock(context, db);
db->hdb_unlock(context, db);
if(code == 1)
return HDB_ERR_EXISTS;
if (code < 0)
@@ -248,17 +248,17 @@ NDBM__put(krb5_context context, HDB *db, int replace,
static krb5_error_code
NDBM__del(krb5_context context, HDB *db, krb5_data key)
{
struct ndbm_db *d = (struct ndbm_db *)db->db;
struct ndbm_db *d = (struct ndbm_db *)db->hdb_db;
datum k;
int code;
krb5_error_code ret;
k.dptr = key.data;
k.dsize = key.length;
ret = db->lock(context, db, HDB_WLOCK);
ret = db->hdb_lock(context, db, HDB_WLOCK);
if(ret) return ret;
code = dbm_delete(d->db, k);
db->unlock(context, db);
db->hdb_unlock(context, db);
if(code < 0)
return errno;
return 0;
@@ -275,18 +275,18 @@ NDBM_open(krb5_context context, HDB *db, int flags, mode_t mode)
krb5_set_error_string(context, "malloc: out of memory");
return ENOMEM;
}
asprintf(&lock_file, "%s.lock", (char*)db->name);
asprintf(&lock_file, "%s.lock", (char*)db->hdb_name);
if(lock_file == NULL) {
free(d);
krb5_set_error_string(context, "malloc: out of memory");
return ENOMEM;
}
d->db = dbm_open((char*)db->name, flags, mode);
d->db = dbm_open((char*)db->hdb_name, flags, mode);
if(d->db == NULL){
ret = errno;
free(d);
free(lock_file);
krb5_set_error_string(context, "dbm_open(%s): %s", db->name,
krb5_set_error_string(context, "dbm_open(%s): %s", db->hdb_name,
strerror(ret));
return ret;
}
@@ -301,7 +301,7 @@ NDBM_open(krb5_context context, HDB *db, int flags, mode_t mode)
return ret;
}
free(lock_file);
db->db = d;
db->hdb_db = d;
if((flags & O_ACCMODE) == O_RDONLY)
ret = hdb_check_db_format(context, db);
else
@@ -314,7 +314,7 @@ NDBM_open(krb5_context context, HDB *db, int flags, mode_t mode)
static krb5_error_code
NDBM_close(krb5_context context, HDB *db)
{
struct ndbm_db *d = db->db;
struct ndbm_db *d = db->hdb_db;
dbm_close(d->db);
close(d->lock_fd);
free(d);
@@ -331,30 +331,30 @@ hdb_ndbm_create(krb5_context context, HDB **db,
return ENOMEM;
}
(*db)->db = NULL;
(*db)->name = strdup(filename);
if ((*db)->name == NULL) {
(*db)->hdb_db = NULL;
(*db)->hdb_name = strdup(filename);
if ((*db)->hdb_name == NULL) {
krb5_set_error_string(context, "malloc: out of memory");
free(*db);
*db = NULL;
return ENOMEM;
}
(*db)->master_key_set = 0;
(*db)->openp = 0;
(*db)->open = NDBM_open;
(*db)->close = NDBM_close;
(*db)->fetch = _hdb_fetch;
(*db)->store = _hdb_store;
(*db)->remove = _hdb_remove;
(*db)->firstkey = NDBM_firstkey;
(*db)->nextkey= NDBM_nextkey;
(*db)->lock = NDBM_lock;
(*db)->unlock = NDBM_unlock;
(*db)->rename = NDBM_rename;
(*db)->_get = NDBM__get;
(*db)->_put = NDBM__put;
(*db)->_del = NDBM__del;
(*db)->destroy = NDBM_destroy;
(*db)->hdb_master_key_set = 0;
(*db)->hdb_openp = 0;
(*db)->hdb_open = NDBM_open;
(*db)->hdb_close = NDBM_close;
(*db)->hdb_fetch = _hdb_fetch;
(*db)->hdb_store = _hdb_store;
(*db)->hdb_remove = _hdb_remove;
(*db)->hdb_firstkey = NDBM_firstkey;
(*db)->hdb_nextkey= NDBM_nextkey;
(*db)->hdb_lock = NDBM_lock;
(*db)->hdb_unlock = NDBM_unlock;
(*db)->hdb_rename = NDBM_rename;
(*db)->hdb__get = NDBM__get;
(*db)->hdb__put = NDBM__put;
(*db)->hdb__del = NDBM__del;
(*db)->hdb_destroy = NDBM_destroy;
return 0;
}