Added kadm5_lock() and unlock.
This commit is contained in:

committed by
Nicolas Williams

parent
109607a355
commit
58d72035f1
22
lib/hdb/db.c
22
lib/hdb/db.c
@@ -65,12 +65,24 @@ DB_lock(krb5_context context, HDB *db, int operation)
|
||||
{
|
||||
DB *d = (DB*)db->hdb_db;
|
||||
int fd = (*d->fd)(d);
|
||||
krb5_error_code ret;
|
||||
|
||||
if (db->lock_count > 0) {
|
||||
assert( db->lock_type == HDB_WLOCK );
|
||||
db->lock_count++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(fd < 0) {
|
||||
krb5_set_error_message(context, HDB_ERR_CANT_LOCK_DB,
|
||||
"Can't lock database: %s", db->hdb_name);
|
||||
return HDB_ERR_CANT_LOCK_DB;
|
||||
}
|
||||
return hdb_lock(fd, operation);
|
||||
ret = hdb_lock(fd, operation);
|
||||
if (ret)
|
||||
return ret;
|
||||
db->lock_count++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static krb5_error_code
|
||||
@@ -78,6 +90,14 @@ DB_unlock(krb5_context context, HDB *db)
|
||||
{
|
||||
DB *d = (DB*)db->hdb_db;
|
||||
int fd = (*d->fd)(d);
|
||||
|
||||
if (db->lock_count > 1) {
|
||||
db->lock_count--;
|
||||
return 0;
|
||||
}
|
||||
assert( db->lock_count == 1 );
|
||||
db->lock_count--;
|
||||
|
||||
if(fd < 0) {
|
||||
krb5_set_error_message(context, HDB_ERR_CANT_LOCK_DB,
|
||||
"Can't unlock database: %s", db->hdb_name);
|
||||
|
@@ -75,9 +75,21 @@ DB_lock(krb5_context context, HDB *db, int operation)
|
||||
{
|
||||
DB *d = (DB*)db->hdb_db;
|
||||
int fd;
|
||||
krb5_error_code ret;
|
||||
|
||||
if (db->lock_count > 0) {
|
||||
assert( db->lock_type == HDB_WLOCK );
|
||||
db->lock_count++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((*d->fd)(d, &fd))
|
||||
return HDB_ERR_CANT_LOCK_DB;
|
||||
return hdb_lock(fd, operation);
|
||||
ret = hdb_lock(fd, operation);
|
||||
if (ret)
|
||||
return ret;
|
||||
db->lock_count++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static krb5_error_code
|
||||
@@ -85,6 +97,14 @@ DB_unlock(krb5_context context, HDB *db)
|
||||
{
|
||||
DB *d = (DB*)db->hdb_db;
|
||||
int fd;
|
||||
|
||||
if (db->lock_count > 1) {
|
||||
db->lock_count--;
|
||||
return 0;
|
||||
}
|
||||
assert( db->lock_count == 1 );
|
||||
db->lock_count--;
|
||||
|
||||
if ((*d->fd)(d, &fd))
|
||||
return HDB_ERR_CANT_LOCK_DB;
|
||||
return hdb_unlock(fd);
|
||||
|
@@ -648,12 +648,24 @@ mdb_lock(krb5_context context, HDB *db, int operation)
|
||||
{
|
||||
DB *d = (DB*)db->hdb_db;
|
||||
int fd = (*d->fd)(d);
|
||||
krb5_error_code ret;
|
||||
|
||||
if (db->lock_count > 0) {
|
||||
assert( db->lock_type == HDB_WLOCK );
|
||||
db->lock_count++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(fd < 0) {
|
||||
krb5_set_error_message(context, HDB_ERR_CANT_LOCK_DB,
|
||||
"Can't lock database: %s", db->hdb_name);
|
||||
return HDB_ERR_CANT_LOCK_DB;
|
||||
}
|
||||
return hdb_lock(fd, operation);
|
||||
ret = hdb_lock(fd, operation);
|
||||
if (ret)
|
||||
return ret;
|
||||
db->lock_count++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static krb5_error_code
|
||||
@@ -661,6 +673,14 @@ mdb_unlock(krb5_context context, HDB *db)
|
||||
{
|
||||
DB *d = (DB*)db->hdb_db;
|
||||
int fd = (*d->fd)(d);
|
||||
|
||||
if (db->lock_count > 1) {
|
||||
db->lock_count--;
|
||||
return 0;
|
||||
}
|
||||
assert( db->lock_count == 1 );
|
||||
db->lock_count--;
|
||||
|
||||
if(fd < 0) {
|
||||
krb5_set_error_message(context, HDB_ERR_CANT_LOCK_DB,
|
||||
"Can't unlock database: %s", db->hdb_name);
|
||||
|
@@ -103,6 +103,8 @@ typedef struct HDB{
|
||||
hdb_master_key hdb_master_key;
|
||||
int hdb_openp;
|
||||
int hdb_capability_flags;
|
||||
int lock_count;
|
||||
int lock_type;
|
||||
/**
|
||||
* Open (or create) the a Kerberos database.
|
||||
*
|
||||
|
@@ -36,6 +36,8 @@
|
||||
#ifndef __HDB_LOCL_H__
|
||||
#define __HDB_LOCL_H__
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
Reference in New Issue
Block a user