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;
|
DB *d = (DB*)db->hdb_db;
|
||||||
int fd = (*d->fd)(d);
|
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) {
|
if(fd < 0) {
|
||||||
krb5_set_error_message(context, HDB_ERR_CANT_LOCK_DB,
|
krb5_set_error_message(context, HDB_ERR_CANT_LOCK_DB,
|
||||||
"Can't lock database: %s", db->hdb_name);
|
"Can't lock database: %s", db->hdb_name);
|
||||||
return HDB_ERR_CANT_LOCK_DB;
|
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
|
static krb5_error_code
|
||||||
@@ -78,6 +90,14 @@ DB_unlock(krb5_context context, HDB *db)
|
|||||||
{
|
{
|
||||||
DB *d = (DB*)db->hdb_db;
|
DB *d = (DB*)db->hdb_db;
|
||||||
int fd = (*d->fd)(d);
|
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) {
|
if(fd < 0) {
|
||||||
krb5_set_error_message(context, HDB_ERR_CANT_LOCK_DB,
|
krb5_set_error_message(context, HDB_ERR_CANT_LOCK_DB,
|
||||||
"Can't unlock database: %s", db->hdb_name);
|
"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;
|
DB *d = (DB*)db->hdb_db;
|
||||||
int fd;
|
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))
|
if ((*d->fd)(d, &fd))
|
||||||
return HDB_ERR_CANT_LOCK_DB;
|
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
|
static krb5_error_code
|
||||||
@@ -85,6 +97,14 @@ DB_unlock(krb5_context context, HDB *db)
|
|||||||
{
|
{
|
||||||
DB *d = (DB*)db->hdb_db;
|
DB *d = (DB*)db->hdb_db;
|
||||||
int fd;
|
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))
|
if ((*d->fd)(d, &fd))
|
||||||
return HDB_ERR_CANT_LOCK_DB;
|
return HDB_ERR_CANT_LOCK_DB;
|
||||||
return hdb_unlock(fd);
|
return hdb_unlock(fd);
|
||||||
|
@@ -648,12 +648,24 @@ mdb_lock(krb5_context context, HDB *db, int operation)
|
|||||||
{
|
{
|
||||||
DB *d = (DB*)db->hdb_db;
|
DB *d = (DB*)db->hdb_db;
|
||||||
int fd = (*d->fd)(d);
|
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) {
|
if(fd < 0) {
|
||||||
krb5_set_error_message(context, HDB_ERR_CANT_LOCK_DB,
|
krb5_set_error_message(context, HDB_ERR_CANT_LOCK_DB,
|
||||||
"Can't lock database: %s", db->hdb_name);
|
"Can't lock database: %s", db->hdb_name);
|
||||||
return HDB_ERR_CANT_LOCK_DB;
|
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
|
static krb5_error_code
|
||||||
@@ -661,6 +673,14 @@ mdb_unlock(krb5_context context, HDB *db)
|
|||||||
{
|
{
|
||||||
DB *d = (DB*)db->hdb_db;
|
DB *d = (DB*)db->hdb_db;
|
||||||
int fd = (*d->fd)(d);
|
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) {
|
if(fd < 0) {
|
||||||
krb5_set_error_message(context, HDB_ERR_CANT_LOCK_DB,
|
krb5_set_error_message(context, HDB_ERR_CANT_LOCK_DB,
|
||||||
"Can't unlock database: %s", db->hdb_name);
|
"Can't unlock database: %s", db->hdb_name);
|
||||||
|
@@ -103,6 +103,8 @@ typedef struct HDB{
|
|||||||
hdb_master_key hdb_master_key;
|
hdb_master_key hdb_master_key;
|
||||||
int hdb_openp;
|
int hdb_openp;
|
||||||
int hdb_capability_flags;
|
int hdb_capability_flags;
|
||||||
|
int lock_count;
|
||||||
|
int lock_type;
|
||||||
/**
|
/**
|
||||||
* Open (or create) the a Kerberos database.
|
* Open (or create) the a Kerberos database.
|
||||||
*
|
*
|
||||||
|
@@ -36,6 +36,8 @@
|
|||||||
#ifndef __HDB_LOCL_H__
|
#ifndef __HDB_LOCL_H__
|
||||||
#define __HDB_LOCL_H__
|
#define __HDB_LOCL_H__
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@@ -1333,6 +1333,18 @@ kadm5_ad_chpass_principal_with_key(void *server_handle,
|
|||||||
return KADM5_RPC_ERROR;
|
return KADM5_RPC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static kadm5_ret_t
|
||||||
|
kadm5_ad_lock(void *server_handle)
|
||||||
|
{
|
||||||
|
return ENOTSUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
static kadm5_ret_t
|
||||||
|
kadm5_ad_unlock(void *server_handle)
|
||||||
|
{
|
||||||
|
return ENOTSUP;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_funcs(kadm5_ad_context *c)
|
set_funcs(kadm5_ad_context *c)
|
||||||
{
|
{
|
||||||
@@ -1349,6 +1361,8 @@ set_funcs(kadm5_ad_context *c)
|
|||||||
SET(c, modify_principal);
|
SET(c, modify_principal);
|
||||||
SET(c, randkey_principal);
|
SET(c, randkey_principal);
|
||||||
SET(c, rename_principal);
|
SET(c, rename_principal);
|
||||||
|
SET(c, lock);
|
||||||
|
SET(c, unlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
kadm5_ret_t
|
kadm5_ret_t
|
||||||
|
@@ -325,3 +325,16 @@ out:
|
|||||||
kadm5_free_principal_ent(server_handle, &princ_ent);
|
kadm5_free_principal_ent(server_handle, &princ_ent);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
kadm5_ret_t
|
||||||
|
kadm5_lock(void *server_handle)
|
||||||
|
{
|
||||||
|
return __CALL(lock, (server_handle));
|
||||||
|
}
|
||||||
|
|
||||||
|
kadm5_ret_t
|
||||||
|
kadm5_unlock(void *server_handle)
|
||||||
|
{
|
||||||
|
return __CALL(unlock, (server_handle));
|
||||||
|
}
|
||||||
|
@@ -35,6 +35,22 @@
|
|||||||
|
|
||||||
RCSID("$Id$");
|
RCSID("$Id$");
|
||||||
|
|
||||||
|
static kadm5_ret_t
|
||||||
|
kadm5_s_lock(void *server_handle)
|
||||||
|
{
|
||||||
|
kadm5_server_context *context = server_handle;
|
||||||
|
|
||||||
|
return context->db->hdb_lock(context->context, context->db, HDB_WLOCK);
|
||||||
|
}
|
||||||
|
|
||||||
|
static kadm5_ret_t
|
||||||
|
kadm5_s_unlock(void *server_handle)
|
||||||
|
{
|
||||||
|
kadm5_server_context *context = server_handle;
|
||||||
|
|
||||||
|
return context->db->hdb_unlock(context->context, context->db);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_funcs(kadm5_server_context *c)
|
set_funcs(kadm5_server_context *c)
|
||||||
{
|
{
|
||||||
@@ -51,6 +67,8 @@ set_funcs(kadm5_server_context *c)
|
|||||||
SET(c, modify_principal);
|
SET(c, modify_principal);
|
||||||
SET(c, randkey_principal);
|
SET(c, randkey_principal);
|
||||||
SET(c, rename_principal);
|
SET(c, rename_principal);
|
||||||
|
SET(c, lock);
|
||||||
|
SET(c, unlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NO_UNIX_SOCKETS
|
#ifndef NO_UNIX_SOCKETS
|
||||||
|
@@ -45,6 +45,18 @@
|
|||||||
|
|
||||||
RCSID("$Id$");
|
RCSID("$Id$");
|
||||||
|
|
||||||
|
static kadm5_ret_t
|
||||||
|
kadm5_c_lock(void *server_handle)
|
||||||
|
{
|
||||||
|
return ENOTSUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
static kadm5_ret_t
|
||||||
|
kadm5_c_unlock(void *server_handle)
|
||||||
|
{
|
||||||
|
return ENOTSUP;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_funcs(kadm5_client_context *c)
|
set_funcs(kadm5_client_context *c)
|
||||||
{
|
{
|
||||||
@@ -61,6 +73,8 @@ set_funcs(kadm5_client_context *c)
|
|||||||
SET(c, modify_principal);
|
SET(c, modify_principal);
|
||||||
SET(c, randkey_principal);
|
SET(c, randkey_principal);
|
||||||
SET(c, rename_principal);
|
SET(c, rename_principal);
|
||||||
|
SET(c, lock);
|
||||||
|
SET(c, unlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
kadm5_ret_t
|
kadm5_ret_t
|
||||||
|
@@ -54,6 +54,8 @@ struct kadm_func {
|
|||||||
kadm5_ret_t (*rename_principal) (void*, krb5_principal, krb5_principal);
|
kadm5_ret_t (*rename_principal) (void*, krb5_principal, krb5_principal);
|
||||||
kadm5_ret_t (*chpass_principal_with_key) (void *, krb5_principal,
|
kadm5_ret_t (*chpass_principal_with_key) (void *, krb5_principal,
|
||||||
int, krb5_key_data *);
|
int, krb5_key_data *);
|
||||||
|
kadm5_ret_t (*lock) (void *);
|
||||||
|
kadm5_ret_t (*unlock) (void *);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* XXX should be integrated */
|
/* XXX should be integrated */
|
||||||
|
Reference in New Issue
Block a user