diff options
author | Gerald Carter <jerry@samba.org> | 2005-10-07 12:14:25 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 11:04:54 -0500 |
commit | 01a1e5cdb0339a7cb3a85280b118985562bb2d7f (patch) | |
tree | 34067426544a5cdfe872943db9a80d1da36f82c1 /source3/registry | |
parent | 5b32737374419525dd57216f595440847bb3c619 (diff) | |
download | samba-01a1e5cdb0339a7cb3a85280b118985562bb2d7f.tar.gz samba-01a1e5cdb0339a7cb3a85280b118985562bb2d7f.tar.bz2 samba-01a1e5cdb0339a7cb3a85280b118985562bb2d7f.zip |
r10819: merging a couple of fixes from trunk
* only keep the registry,tdb file open when we have an open key handle
* tpot's setup.py fix
* removing files that no longer exist in trunk and copying some
that were missing in 3.0
(This used to be commit 6c6bf6ca5fd430a7a20bf20ed08050328660e570)
Diffstat (limited to 'source3/registry')
-rw-r--r-- | source3/registry/reg_db.c | 62 | ||||
-rw-r--r-- | source3/registry/reg_frontend.c | 26 |
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; +} |