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/reg_db.c | |
parent | 5b32737374419525dd57216f595440847bb3c619 (diff) | |
download | samba-01a1e5cdb0339a7cb3a85280b118985562bb2d7f.tar.gz samba-01a1e5cdb0339a7cb3a85280b118985562bb2d7f.tar.xz 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/reg_db.c')
-rw-r--r-- | source3/registry/reg_db.c | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/source3/registry/reg_db.c b/source3/registry/reg_db.c index ab8fc14d909..ddc08cf2ce4 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 |