summaryrefslogtreecommitdiff
path: root/source3/registry
diff options
context:
space:
mode:
Diffstat (limited to 'source3/registry')
-rw-r--r--source3/registry/reg_db.c62
-rw-r--r--source3/registry/reg_frontend.c26
2 files changed, 82 insertions, 6 deletions
diff --git a/source3/registry/reg_db.c b/source3/registry/reg_db.c
index ab8fc14d90..ddc08cf2ce 100644
--- a/source3/registry/reg_db.c
+++ b/source3/registry/reg_db.c
@@ -26,6 +26,7 @@
#define DBGC_CLASS DBGC_RPC_SRV
static TDB_CONTEXT *tdb_reg;
+static int tdb_refcount;
#define VALUE_PREFIX "SAMBA_REGVAL"
@@ -196,7 +197,7 @@ static BOOL init_registry_data( void )
Open the registry database
***********************************************************************/
-BOOL init_registry_db( void )
+BOOL regdb_init( void )
{
const char *vstring = "INFO/version";
uint32 vers_id;
@@ -208,13 +209,15 @@ BOOL init_registry_db( void )
{
tdb_reg = tdb_open_log(lock_path("registry.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
if ( !tdb_reg ) {
- DEBUG(0,("init_registry: Failed to open registry %s (%s)\n",
+ DEBUG(0,("regdb_init: Failed to open registry %s (%s)\n",
lock_path("registry.tdb"), strerror(errno) ));
return False;
}
- DEBUG(10,("init_registry: Successfully created registry tdb\n"));
+ DEBUG(10,("regdb_init: Successfully created registry tdb\n"));
}
+
+ tdb_refcount = 1;
vers_id = tdb_fetch_int32(tdb_reg, vstring);
@@ -234,6 +237,59 @@ BOOL init_registry_db( void )
}
/***********************************************************************
+ Open the registry. Must already have been initialized by regdb_init()
+ ***********************************************************************/
+
+WERROR regdb_open( void )
+{
+ WERROR result = WERR_OK;
+
+ if ( tdb_reg ) {
+ DEBUG(10,("regdb_open: incrementing refcount (%d)\n", tdb_refcount));
+ tdb_refcount++;
+ return WERR_OK;
+ }
+
+ become_root();
+
+ tdb_reg = tdb_open_log(lock_path("registry.tdb"), 0, TDB_DEFAULT, O_RDWR, 0600);
+ if ( !tdb_reg ) {
+ result = ntstatus_to_werror( map_nt_error_from_unix( errno ) );
+ DEBUG(0,("regdb_open: Failed to open %s! (%s)\n",
+ lock_path("registry.tdb"), strerror(errno) ));
+ }
+
+ unbecome_root();
+
+ tdb_refcount = 1;
+ DEBUG(10,("regdb_open: refcount reset (%d)\n", tdb_refcount));
+
+ return result;
+}
+
+/***********************************************************************
+ ***********************************************************************/
+
+int regdb_close( void )
+{
+ int ret;
+
+ tdb_refcount--;
+
+ DEBUG(10,("regdb_close: decrementing refcount (%d)\n", tdb_refcount));
+
+ if ( tdb_refcount > 0 )
+ return 0;
+
+ SMB_ASSERT( tdb_refcount >= 0 );
+
+ ret = tdb_close( tdb_reg );
+ tdb_reg = NULL;
+
+ return ret;
+}
+
+/***********************************************************************
Add subkey strings to the registry tdb under a defined key
fmt is the same format as tdb_pack except this function only supports
fstrings
diff --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c
index f5284e9e88..b0e713a882 100644
--- a/source3/registry/reg_frontend.c
+++ b/source3/registry/reg_frontend.c
@@ -110,7 +110,7 @@ BOOL init_registry( void )
int i;
- if ( !init_registry_db() ) {
+ if ( !regdb_init() ) {
DEBUG(0,("init_registry: failed to initialize the registry tdb!\n"));
return False;
}
@@ -132,6 +132,10 @@ BOOL init_registry( void )
svcctl_init_keys();
eventlog_init_keys();
+ /* close and let each smbd open up as necessary */
+
+ regdb_close();
+
return True;
}
@@ -348,10 +352,15 @@ WERROR regkey_open_internal( REGISTRY_KEY **regkey, const char *path,
REGSUBKEY_CTR *subkeys = NULL;
uint32 access_granted;
+ if ( !(W_ERROR_IS_OK(result = regdb_open()) ) )
+ return result;
+
DEBUG(7,("regkey_open_internal: name = [%s]\n", path));
- if ( !(*regkey = TALLOC_ZERO_P(NULL, REGISTRY_KEY)) )
+ if ( !(*regkey = TALLOC_ZERO_P(NULL, REGISTRY_KEY)) ) {
+ regdb_close();
return WERR_NOMEM;
+ }
keyinfo = *regkey;
@@ -399,8 +408,19 @@ WERROR regkey_open_internal( REGISTRY_KEY **regkey, const char *path,
done:
if ( !W_ERROR_IS_OK(result) ) {
- TALLOC_FREE( *regkey );
+ regkey_close_internal( *regkey );
}
return result;
}
+
+/*******************************************************************
+*******************************************************************/
+
+WERROR regkey_close_internal( REGISTRY_KEY *key )
+{
+ TALLOC_FREE( key );
+ regdb_close();
+
+ return WERR_OK;
+}