From 78750803d09fdef3e878e73da98d3e7bc338fcb5 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 15 Jul 2002 22:27:07 +0000 Subject: splitting off storage/retrieval routines for abstracting the registry view front end. Now to plug in the various hooks. (This used to be commit 9772acd9ad44af2800dfb9d8610c2d5c23eaceb4) --- source3/registry/reg_frontend.c | 334 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 334 insertions(+) create mode 100644 source3/registry/reg_frontend.c (limited to 'source3/registry') diff --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c new file mode 100644 index 0000000000..c4e332ed6b --- /dev/null +++ b/source3/registry/reg_frontend.c @@ -0,0 +1,334 @@ +/* + * Unix SMB/CIFS implementation. + * RPC Pipe client / server routines + * Copyright (C) Gerald Carter 2002. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* Implementation of registry database functions. */ + +#include "includes.h" + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_RPC_SRV + + + +static TDB_CONTEXT *tdb_reg; + + +/*********************************************************************** + Open the registry database + ***********************************************************************/ + +static BOOL init_registry_data( void ) +{ + pstring keyname; + char *subkeys[3]; + + /* HKEY_LOCAL_MACHINE */ + + pstrcpy( keyname, KEY_HKLM ); + subkeys[0] = "SYSTEM"; + if ( !store_reg_keys( keyname, subkeys, 1 )) + return False; + + pstrcpy( keyname, KEY_HKLM ); + pstrcat( keyname, "/SYSTEM" ); + subkeys[0] = "CurrentControlSet"; + if ( !store_reg_keys( keyname, subkeys, 1 )) + return False; + + pstrcpy( keyname, KEY_HKLM ); + pstrcat( keyname, "/SYSTEM/CurrentControlSet" ); + subkeys[0] = "Control"; + subkeys[1] = "services"; + if ( !store_reg_keys( keyname, subkeys, 2 )) + return False; + + pstrcpy( keyname, KEY_HKLM ); + pstrcat( keyname, "/SYSTEM/CurrentControlSet/Control" ); + subkeys[0] = "Print"; + subkeys[1] = "ProduceOptions"; + if ( !store_reg_keys( keyname, subkeys, 2 )) + return False; + + pstrcpy( keyname, KEY_HKLM ); + pstrcat( keyname, "/SYSTEM/CurrentControlSet/Control/Print" ); + subkeys[0] = "Environments"; + subkeys[1] = "Forms"; + subkeys[2] = "Printers"; + if ( !store_reg_keys( keyname, subkeys, 3 )) + return False; + + pstrcpy( keyname, KEY_HKLM ); + pstrcat( keyname, "/SYSTEM/CurrentControlSet/Control/ProductOptions" ); + if ( !store_reg_keys( keyname, subkeys, 0 )) + return False; + + pstrcpy( keyname, KEY_HKLM ); + pstrcat( keyname, "/SYSTEM/CurrentControlSet/services" ); + subkeys[0] = "Netlogon"; + if ( !store_reg_keys( keyname, subkeys, 1 )) + return False; + + pstrcpy( keyname, KEY_HKLM ); + pstrcat( keyname, "/SYSTEM/CurrentControlSet/services/Netlogon" ); + subkeys[0] = "parameters"; + if ( !store_reg_keys( keyname, subkeys, 1 )) + return False; + + pstrcpy( keyname, KEY_HKLM ); + pstrcat( keyname, "/SYSTEM/CurrentControlSet/services/Netlogon/parameters" ); + if ( !store_reg_keys( keyname, subkeys, 0 )) + return False; + + + /* HKEY_USER */ + + pstrcpy( keyname, KEY_HKU ); + if ( !store_reg_keys( keyname, subkeys, 0 ) ) + return False; + + return True; +} + + +/*********************************************************************** + Open the registry database + ***********************************************************************/ + +BOOL init_registry( void ) +{ + static pid_t local_pid; + + + if (tdb_reg && local_pid == sys_getpid()) + return True; + + /* + * try to open first without creating so we can determine + * if we need to init the data in the registry + */ + + tdb_reg = tdb_open_log(lock_path("registry.tdb"), 0, TDB_DEFAULT, O_RDWR, 0600); + if ( !tdb_reg ) + { + 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", + lock_path("registry.tdb"), strerror(errno) )); + return False; + } + + DEBUG(10,("init_registry: Successfully created registry tdb\n")); + + /* create the registry here */ + if ( !init_registry_data() ) { + DEBUG(0,("init_registry: Failed to initiailize data in registry!\n")); + return False; + } + } + + local_pid = sys_getpid(); + + return True; +} + +/*********************************************************************** + 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 + ***********************************************************************/ + +BOOL store_reg_keys( char *keyname, char **subkeys, uint32 num_subkeys ) +{ + TDB_DATA kbuf, dbuf; + char *buffer, *tmpbuf; + int i = 0; + uint32 len, buflen; + BOOL ret = True; + + if ( !keyname ) + return False; + + /* allocate some initial memory */ + + buffer = malloc(sizeof(pstring)); + buflen = sizeof(pstring); + len = 0; + + /* store the number of subkeys */ + + len += tdb_pack(buffer+len, buflen-len, "d", num_subkeys); + + /* pack all the strings */ + + for (i=0; i buflen ) { + /* allocate some extra space */ + if ((tmpbuf = Realloc( buffer, len*2 )) == NULL) { + DEBUG(0,("store_reg_keys: Failed to realloc memory of size [%d]\n", len*2)); + ret = False; + goto done; + } + buffer = tmpbuf; + buflen = len*2; + + len = tdb_pack(buffer+len, buflen-len, "f", subkeys[i]); + } + } + + /* finally write out the data */ + + kbuf.dptr = keyname; + kbuf.dsize = strlen(keyname)+1; + dbuf.dptr = buffer; + dbuf.dsize = len; + if ( tdb_store( tdb_reg, kbuf, dbuf, TDB_REPLACE ) == -1) { + ret = False; + goto done; + } + +done: + SAFE_FREE( buffer ); + return ret; +} + +/*********************************************************************** + Retrieve an array of strings containing subkeys. Memory should be + released by the caller. The subkeys are stored in a catenated string + of null terminated character strings + ***********************************************************************/ + +int fetch_reg_keys( char* key, char **subkeys ) +{ + pstring path; + uint32 num_items; + TDB_DATA dbuf; + char *buf; + uint32 buflen, len; + int i; + char *s; + + + pstrcpy( path, key ); + + /* convert to key format */ + pstring_sub( path, "\\", "/" ); + + dbuf = tdb_fetch_by_string( tdb_reg, path ); + + buf = dbuf.dptr; + buflen = dbuf.dsize; + + if ( !buf ) { + DEBUG(5,("fetch_reg_keys: Failed to fetch any subkeys for [%s]\n", key)); + return 0; + } + + len = tdb_unpack( buf, buflen, "d", &num_items); + if (num_items) { + if ( (*subkeys = (char*)malloc(sizeof(fstring)*num_items)) == NULL ) { + DEBUG(0,("fetch_reg_keys: Failed to malloc memory for subkey array containing [%d] items!\n", + num_items)); + num_items = -1; + goto done; + } + } + + s = *subkeys; + for (i=0; i Date: Thu, 18 Jul 2002 23:00:24 +0000 Subject: virtual registry framework with initial printing hooks. (This used to be commit a43d9788fa8823d678ee72470421b980165ec2b0) --- source3/registry/reg_cachehook.c | 96 ++++++++++++ source3/registry/reg_db.c | 311 ++++++++++++++++++++++++++++++++++++++ source3/registry/reg_frontend.c | 313 ++++++++------------------------------- source3/registry/reg_printing.c | 243 ++++++++++++++++++++++++++++++ 4 files changed, 709 insertions(+), 254 deletions(-) create mode 100644 source3/registry/reg_cachehook.c create mode 100644 source3/registry/reg_db.c create mode 100644 source3/registry/reg_printing.c (limited to 'source3/registry') diff --git a/source3/registry/reg_cachehook.c b/source3/registry/reg_cachehook.c new file mode 100644 index 0000000000..daf2f24180 --- /dev/null +++ b/source3/registry/reg_cachehook.c @@ -0,0 +1,96 @@ +/* + * Unix SMB/CIFS implementation. + * RPC Pipe client / server routines + * Copyright (C) Gerald Carter 2002. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* Implementation of registry hook cache tree */ + +#include "includes.h" + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_RPC_SRV + +static SORTED_TREE *cache_tree; + +/********************************************************************** + Initialize the cache tree + *********************************************************************/ + +BOOL reghook_cache_init( void ) +{ + cache_tree = sorted_tree_init( NULL, NULL ); + + return ( cache_tree == NULL ); +} + +/********************************************************************** + Add a new REGISTRY_HOOK to the cache. Note that the keyname + is not in the exact format that a SORTED_TREE expects. + *********************************************************************/ + +BOOL reghook_cache_add( REGISTRY_HOOK *hook ) +{ + pstring key; + + if ( !hook ) + return False; + + pstrcpy( key, "\\"); + pstrcat( key, hook->keyname ); + + pstring_sub( key, "\\", "/" ); + + DEBUG(10,("reghook_cache_add: Adding key [%s]\n", key)); + + return sorted_tree_add( cache_tree, key, hook ); +} + +/********************************************************************** + Initialize the cache tree + *********************************************************************/ + +REGISTRY_HOOK* reghook_cache_find( char *keyname ) +{ + char *key; + + if ( !keyname ) + return NULL; + + if ( (key = strdup( keyname )) == NULL ) { + DEBUG(0,("reghook_cache_find: strdup() failed for string [%s] !?!?!\n", + keyname)); + return NULL; + } + + string_sub( key, "\\", "/", 0 ); + + DEBUG(10,("reghook_cache_find: Searching for keyname [%s]\n", key)); + + return sorted_tree_find( cache_tree, key ) ; +} + +/********************************************************************** + Initialize the cache tree + *********************************************************************/ + +void reghook_dump_cache( int debuglevel ) +{ + DEBUG(debuglevel,("reghook_dump_cache: Starting cache dump now...\n")); + + sorted_tree_print_keys( cache_tree, debuglevel ); +} diff --git a/source3/registry/reg_db.c b/source3/registry/reg_db.c new file mode 100644 index 0000000000..a521cdcdd0 --- /dev/null +++ b/source3/registry/reg_db.c @@ -0,0 +1,311 @@ +/* + * Unix SMB/CIFS implementation. + * RPC Pipe client / server routines + * Copyright (C) Gerald Carter 2002. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* Implementation of internal registry database functions. */ + +#include "includes.h" + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_RPC_SRV + +static TDB_CONTEXT *tdb_reg; + + +/*********************************************************************** + Open the registry data in the tdb + ***********************************************************************/ + +static BOOL init_registry_data( void ) +{ + pstring keyname; + char *subkeys[3]; + + /* HKEY_LOCAL_MACHINE */ + + pstrcpy( keyname, KEY_HKLM ); + subkeys[0] = "SYSTEM"; + if ( !regdb_store_reg_keys( keyname, subkeys, 1 )) + return False; + + pstrcpy( keyname, KEY_HKLM ); + pstrcat( keyname, "/SYSTEM" ); + subkeys[0] = "CurrentControlSet"; + if ( !regdb_store_reg_keys( keyname, subkeys, 1 )) + return False; + + pstrcpy( keyname, KEY_HKLM ); + pstrcat( keyname, "/SYSTEM/CurrentControlSet" ); + subkeys[0] = "Control"; + subkeys[1] = "services"; + if ( !regdb_store_reg_keys( keyname, subkeys, 2 )) + return False; + + pstrcpy( keyname, KEY_HKLM ); + pstrcat( keyname, "/SYSTEM/CurrentControlSet/Control" ); + subkeys[0] = "Print"; + subkeys[1] = "ProduceOptions"; + if ( !regdb_store_reg_keys( keyname, subkeys, 2 )) + return False; + +#if 0 /* JERRY */ + pstrcpy( keyname, KEY_HKLM ); + pstrcat( keyname, "/SYSTEM/CurrentControlSet/Control/Print" ); + subkeys[0] = "Environments"; + subkeys[1] = "Forms"; + subkeys[2] = "Printers"; + if ( !regdb_store_reg_keys( keyname, subkeys, 0 )) + return False; +#endif + + pstrcpy( keyname, KEY_HKLM ); + pstrcat( keyname, "/SYSTEM/CurrentControlSet/Control/ProductOptions" ); + if ( !regdb_store_reg_keys( keyname, subkeys, 0 )) + return False; + + pstrcpy( keyname, KEY_HKLM ); + pstrcat( keyname, "/SYSTEM/CurrentControlSet/services" ); + subkeys[0] = "Netlogon"; + if ( !regdb_store_reg_keys( keyname, subkeys, 1 )) + return False; + + pstrcpy( keyname, KEY_HKLM ); + pstrcat( keyname, "/SYSTEM/CurrentControlSet/services/Netlogon" ); + subkeys[0] = "parameters"; + if ( !regdb_store_reg_keys( keyname, subkeys, 1 )) + return False; + + pstrcpy( keyname, KEY_HKLM ); + pstrcat( keyname, "/SYSTEM/CurrentControlSet/services/Netlogon/parameters" ); + if ( !regdb_store_reg_keys( keyname, subkeys, 0 )) + return False; + + + /* HKEY_USER */ + + pstrcpy( keyname, KEY_HKU ); + if ( !regdb_store_reg_keys( keyname, subkeys, 0 ) ) + return False; + + return True; +} + +/*********************************************************************** + Open the registry database + ***********************************************************************/ + +BOOL init_registry_db( void ) +{ + static pid_t local_pid; + + if (tdb_reg && local_pid == sys_getpid()) + return True; + + /* + * try to open first without creating so we can determine + * if we need to init the data in the registry + */ + + tdb_reg = tdb_open_log(lock_path("registry.tdb"), 0, TDB_DEFAULT, O_RDWR, 0600); + if ( !tdb_reg ) + { + 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", + lock_path("registry.tdb"), strerror(errno) )); + return False; + } + + DEBUG(10,("init_registry: Successfully created registry tdb\n")); + + /* create the registry here */ + if ( !init_registry_data() ) { + DEBUG(0,("init_registry: Failed to initiailize data in registry!\n")); + return False; + } + } + + local_pid = sys_getpid(); + + return True; +} + + + +/*********************************************************************** + 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 + + The full path to the registry key is used as database after the + \'s are converted to /'s. + ***********************************************************************/ + +BOOL regdb_store_reg_keys( char *keyname, char **subkeys, uint32 num_subkeys ) +{ + TDB_DATA kbuf, dbuf; + char *buffer, *tmpbuf; + int i = 0; + uint32 len, buflen; + BOOL ret = True; + + if ( !keyname ) + return False; + + /* allocate some initial memory */ + + buffer = malloc(sizeof(pstring)); + buflen = sizeof(pstring); + len = 0; + + /* store the number of subkeys */ + + len += tdb_pack(buffer+len, buflen-len, "d", num_subkeys); + + /* pack all the strings */ + + for (i=0; i buflen ) { + /* allocate some extra space */ + if ((tmpbuf = Realloc( buffer, len*2 )) == NULL) { + DEBUG(0,("store_reg_keys: Failed to realloc memory of size [%d]\n", len*2)); + ret = False; + goto done; + } + buffer = tmpbuf; + buflen = len*2; + + len = tdb_pack(buffer+len, buflen-len, "f", subkeys[i]); + } + } + + /* finally write out the data */ + + kbuf.dptr = keyname; + kbuf.dsize = strlen(keyname)+1; + dbuf.dptr = buffer; + dbuf.dsize = len; + if ( tdb_store( tdb_reg, kbuf, dbuf, TDB_REPLACE ) == -1) { + ret = False; + goto done; + } + +done: + SAFE_FREE( buffer ); + return ret; +} + +/*********************************************************************** + Retrieve an array of strings containing subkeys. Memory should be + released by the caller. The subkeys are stored in a catenated string + of null terminated character strings + ***********************************************************************/ + +int regdb_fetch_reg_keys( char* key, char **subkeys ) +{ + pstring path; + uint32 num_items; + TDB_DATA dbuf; + char *buf; + uint32 buflen, len; + int i; + char *s; + + + pstrcpy( path, key ); + + /* convert to key format */ + pstring_sub( path, "\\", "/" ); + + dbuf = tdb_fetch_by_string( tdb_reg, path ); + + buf = dbuf.dptr; + buflen = dbuf.dsize; + + if ( !buf ) { + DEBUG(5,("fetch_reg_keys: Failed to fetch any subkeys for [%s]\n", key)); + return 0; + } + + len = tdb_unpack( buf, buflen, "d", &num_items); + if (num_items) { + if ( (*subkeys = (char*)malloc(sizeof(fstring)*num_items)) == NULL ) { + DEBUG(0,("fetch_reg_keys: Failed to malloc memory for subkey array containing [%d] items!\n", + num_items)); + num_items = -1; + goto done; + } + } + + s = *subkeys; + for (i=0; iname, subkeys, num_subkeys ); - /* - * try to open first without creating so we can determine - * if we need to init the data in the registry - */ - - tdb_reg = tdb_open_log(lock_path("registry.tdb"), 0, TDB_DEFAULT, O_RDWR, 0600); - if ( !tdb_reg ) - { - 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", - lock_path("registry.tdb"), strerror(errno) )); - return False; - } - - DEBUG(10,("init_registry: Successfully created registry tdb\n")); - - /* create the registry here */ - if ( !init_registry_data() ) { - DEBUG(0,("init_registry: Failed to initiailize data in registry!\n")); - return False; - } - } - - local_pid = sys_getpid(); - - return True; } /*********************************************************************** - 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 + High level wrapper function for storing registry values ***********************************************************************/ -BOOL store_reg_keys( char *keyname, char **subkeys, uint32 num_subkeys ) +BOOL store_reg_values( REGISTRY_KEY *key, REGISTRY_VALUE **val, uint32 num_values ) { - TDB_DATA kbuf, dbuf; - char *buffer, *tmpbuf; - int i = 0; - uint32 len, buflen; - BOOL ret = True; - - if ( !keyname ) - return False; - - /* allocate some initial memory */ - - buffer = malloc(sizeof(pstring)); - buflen = sizeof(pstring); - len = 0; - - /* store the number of subkeys */ - - len += tdb_pack(buffer+len, buflen-len, "d", num_subkeys); - - /* pack all the strings */ - - for (i=0; i buflen ) { - /* allocate some extra space */ - if ((tmpbuf = Realloc( buffer, len*2 )) == NULL) { - DEBUG(0,("store_reg_keys: Failed to realloc memory of size [%d]\n", len*2)); - ret = False; - goto done; - } - buffer = tmpbuf; - buflen = len*2; - - len = tdb_pack(buffer+len, buflen-len, "f", subkeys[i]); - } - } - - /* finally write out the data */ - - kbuf.dptr = keyname; - kbuf.dsize = strlen(keyname)+1; - dbuf.dptr = buffer; - dbuf.dsize = len; - if ( tdb_store( tdb_reg, kbuf, dbuf, TDB_REPLACE ) == -1) { - ret = False; - goto done; - } - -done: - SAFE_FREE( buffer ); - return ret; + return True; } + /*********************************************************************** - Retrieve an array of strings containing subkeys. Memory should be - released by the caller. The subkeys are stored in a catenated string - of null terminated character strings + High level wrapper function for enumerating registry subkeys ***********************************************************************/ -int fetch_reg_keys( char* key, char **subkeys ) +int fetch_reg_keys( REGISTRY_KEY *key, char **subkeys ) { - pstring path; - uint32 num_items; - TDB_DATA dbuf; - char *buf; - uint32 buflen, len; - int i; - char *s; - - - pstrcpy( path, key ); - - /* convert to key format */ - pstring_sub( path, "\\", "/" ); - - dbuf = tdb_fetch_by_string( tdb_reg, path ); - - buf = dbuf.dptr; - buflen = dbuf.dsize; - - if ( !buf ) { - DEBUG(5,("fetch_reg_keys: Failed to fetch any subkeys for [%s]\n", key)); - return 0; - } + int num_subkeys; - len = tdb_unpack( buf, buflen, "d", &num_items); - if (num_items) { - if ( (*subkeys = (char*)malloc(sizeof(fstring)*num_items)) == NULL ) { - DEBUG(0,("fetch_reg_keys: Failed to malloc memory for subkey array containing [%d] items!\n", - num_items)); - num_items = -1; - goto done; - } - } - - s = *subkeys; - for (i=0; ihook && key->hook->ops && key->hook->ops->subkey_fn ) + num_subkeys = key->hook->ops->subkey_fn( key->name, subkeys ); + else + num_subkeys = regdb_fetch_reg_keys( key->name, subkeys ); -done: - SAFE_FREE(dbuf.dptr); - return num_items; + return num_subkeys; } /*********************************************************************** - count the number of subkeys dtored in the registry + High level wrapper function for retreiving a specific registry subkey + given and index. ***********************************************************************/ -int fetch_reg_keys_count( char* key ) +BOOL fetch_reg_keys_specific( REGISTRY_KEY *key, char** subkey, uint32 key_index ) { - pstring path; - uint32 num_items; - TDB_DATA dbuf; - char *buf; - uint32 buflen, len; - - - pstrcpy( path, key ); - - /* convert to key format */ - pstring_sub( path, "\\", "/" ); - - dbuf = tdb_fetch_by_string( tdb_reg, path ); - - buf = dbuf.dptr; - buflen = dbuf.dsize; - - if ( !buf ) { - DEBUG(5,("fetch_reg_keys: Failed to fetch any subkeys for [%s]\n", key)); - return 0; - } - - len = tdb_unpack( buf, buflen, "d", &num_items); - - SAFE_FREE( buf ); + BOOL result; + + if ( key->hook && key->hook->ops && key->hook->ops->subkey_specific_fn ) + result = key->hook->ops->subkey_specific_fn( key->name, subkey, key_index ); + else + result = regdb_fetch_reg_keys_specific( key->name, subkey, key_index ); - return num_items; + return result; } + /*********************************************************************** - retreive a specific subkey specified by index. The subkey parameter - is assumed to be an fstring. + High level wrapper function for enumerating registry values ***********************************************************************/ -BOOL fetch_reg_keys_specific( char* key, char* subkey, uint32 key_index ) +int fetch_reg_values( REGISTRY_KEY *key, REGISTRY_VALUE **val ) { - int num_subkeys, i; - char *subkeys = NULL; - char *s; + int num_values; - num_subkeys = fetch_reg_keys( key, &subkeys ); - if ( num_subkeys == -1 ) - return False; - - s = subkeys; - for ( i=0; ihook && key->hook->ops && key->hook->ops->value_fn ) + num_values = key->hook->ops->value_fn( key->name, val ); + else + num_values = regdb_fetch_reg_values( key->name, val ); - /* go onto the next string */ - s += strlen(s) + 1; - } - - SAFE_FREE(subkeys); - - return True; + return num_values; } - - diff --git a/source3/registry/reg_printing.c b/source3/registry/reg_printing.c new file mode 100644 index 0000000000..8144110d1f --- /dev/null +++ b/source3/registry/reg_printing.c @@ -0,0 +1,243 @@ +/* + * Unix SMB/CIFS implementation. + * RPC Pipe client / server routines + * Copyright (C) Gerald Carter 2002. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* Implementation of registry virtual views for printing information */ + +#include "includes.h" + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_RPC_SRV + +#define MAX_TOP_LEVEL_KEYS 3 + +/* some symbolic indexes into the top_level_keys */ + +#define KEY_INDEX_ENVIR 0 +#define KEY_INDEX_FORMS 1 +#define KEY_INDEX_PRINTER 2 + +static char *top_level_keys[MAX_TOP_LEVEL_KEYS] = { + "Environments", + "Forms", + "Printers" +}; + +/********************************************************************** + It is safe to assume that every registry path passed into on of + the exported functions here begins with KEY_PRINTING else + these functions would have never been called. This is a small utility + function to strip the beginning of the path and make a copy that the + caller can modify. Note that the caller is responsible for releasing + the memory allocated here. + **********************************************************************/ + +static char* trim_reg_path( char *path ) +{ + char *p; + + p = path + strlen(KEY_PRINTING); + + if ( *p ) + return strdup(p); + else + return NULL; +} + +/********************************************************************** + handle enumeration of subkeys below KEY_PRINTING. + *********************************************************************/ + +static int handle_printing_subpath( char *key, char **subkeys, uint32 index ) +{ + int result = 0; + char *p, *base; + int i; + + + /* + * break off the first part of the path + * topmost base **must** be one of the strings + * in top_level_keys[] + */ + + base = key; + p = strchr( key, '\\' ); + if ( p ) + *p = '\0'; + + for ( i=0; i[%s]\n", key)); + + path = trim_reg_path( key ); + + /* check to see if we are dealing with the top level key */ + + if ( !path ) + top_level = True; + + if ( top_level ) { + if ( ! (*subkeys = malloc( sizeof(top_level_keys) )) ) + goto done; + + num_subkeys = MAX_TOP_LEVEL_KEYS; + memcpy( *subkeys, top_level_keys, sizeof(top_level_keys) ); + } + else + num_subkeys = handle_printing_subpath( path, subkeys, -1 ); + +done: + SAFE_FREE( path ); + return num_subkeys; +} + +/********************************************************************** + Count the registry subkey names given a registry path. + Caller is responsible for freeing memory to **subkey + *********************************************************************/ + +BOOL printing_subkey_specific( char *key, char** subkey, uint32 index ) +{ + char *path; + BOOL top_level = False; + BOOL result = False; + + DEBUG(10,("printing_subkey_specific: key=>[%s], index=>[%d]\n", key, index)); + + path = trim_reg_path( key ); + + /* check to see if we are dealing with the top level key */ + + if ( !path ) + top_level = True; + + + + if ( top_level ) { + + /* make sure the index is in range */ + + if ( !(index < MAX_TOP_LEVEL_KEYS) ) + goto done; + + if ( !(*subkey = malloc( strlen(top_level_keys[index])+1 )) ) + goto done; + + strncpy( *subkey, top_level_keys[index], strlen(top_level_keys[index])+1 ); + + result = True; + } + else { + if ( handle_printing_subpath( path, subkey, index ) != -1 ) + result = True; + } + +done: + SAFE_FREE( path ); + + return result; +} + +/********************************************************************** + Enumerate registry values given a registry path. + Caller is responsible for freeing memory + *********************************************************************/ + +int printing_value_info( char *key, REGISTRY_VALUE **val ) +{ + DEBUG(10,("printing_value_info: key=>[%s]\n", key)); + + return 0; +} + +/********************************************************************** + Stub function which always returns failure since we don't want + people storing printing information directly via regostry calls + (for now at least) + *********************************************************************/ + +BOOL printing_store_subkey( char *key, char **subkeys, uint32 num_subkeys ) +{ + return False; +} + +/********************************************************************** + Stub function which always returns failure since we don't want + people storing printing information directly via regostry calls + (for now at least) + *********************************************************************/ + +BOOL printing_store_value( char *key, REGISTRY_VALUE **val, uint32 num_values ) +{ + return False; +} + +/* + * Table of function pointers for accessing printing data + */ + +REGISTRY_OPS printing_ops = { + printing_subkey_info, + printing_subkey_specific, + printing_value_info, + printing_store_subkey, + printing_store_value +}; + -- cgit From 5f894476d86fd5a5b453e7043e087714c9e1c6ef Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 19 Jul 2002 16:45:37 +0000 Subject: Formatting fixup. Fix shadow warning. Jeremy. (This used to be commit beb298898d5700dcd775ee3b1f1965e67214e9e5) --- source3/registry/reg_printing.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/registry') diff --git a/source3/registry/reg_printing.c b/source3/registry/reg_printing.c index 8144110d1f..cbeab13142 100644 --- a/source3/registry/reg_printing.c +++ b/source3/registry/reg_printing.c @@ -153,13 +153,13 @@ done: Caller is responsible for freeing memory to **subkey *********************************************************************/ -BOOL printing_subkey_specific( char *key, char** subkey, uint32 index ) +BOOL printing_subkey_specific( char *key, char** subkey, uint32 indx ) { char *path; BOOL top_level = False; BOOL result = False; - DEBUG(10,("printing_subkey_specific: key=>[%s], index=>[%d]\n", key, index)); + DEBUG(10,("printing_subkey_specific: key=>[%s], index=>[%d]\n", key, indx)); path = trim_reg_path( key ); @@ -174,18 +174,18 @@ BOOL printing_subkey_specific( char *key, char** subkey, uint32 index ) /* make sure the index is in range */ - if ( !(index < MAX_TOP_LEVEL_KEYS) ) + if ( !(indx < MAX_TOP_LEVEL_KEYS) ) goto done; - if ( !(*subkey = malloc( strlen(top_level_keys[index])+1 )) ) + if ( !(*subkey = malloc( strlen(top_level_keys[indx])+1 )) ) goto done; - strncpy( *subkey, top_level_keys[index], strlen(top_level_keys[index])+1 ); + strncpy( *subkey, top_level_keys[indx], strlen(top_level_keys[indx])+1 ); result = True; } else { - if ( handle_printing_subpath( path, subkey, index ) != -1 ) + if ( handle_printing_subpath( path, subkey, indx ) != -1 ) result = True; } -- cgit From 9fe3bd1259e7bda901f7a264bd7fc88c72d2112f Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 19 Jul 2002 18:49:44 +0000 Subject: * refactored registry operations some. subkey lists and registry values are now passed around in containers (REGSUBKEY_CTR & REGVAL_CTR) which each possess a TALLOC_CTX. * removed subkey_specific_fn() from REGISTRY_OPS. Is implemented in the form of a wrapper * temporarily broke the printing registry ops. * implemented inheritence for the data_p of nodes in a SORTED_TREE * All REGISTRY_KEY instances now store a valid REGISTRY_HOOK since the default REGOSTRY_OPS structure is stored in the root of the cache_tree. * Probably some other change I forgot.... T (This used to be commit e7b55e8f017e638342d9c8c1a9259000745a0298) --- source3/registry/reg_cachehook.c | 4 +- source3/registry/reg_db.c | 145 ++++++++++++--------------- source3/registry/reg_frontend.c | 207 ++++++++++++++++++++++++++++++++++----- source3/registry/reg_printing.c | 199 +++++++++++++++++++++++++------------ 4 files changed, 385 insertions(+), 170 deletions(-) (limited to 'source3/registry') diff --git a/source3/registry/reg_cachehook.c b/source3/registry/reg_cachehook.c index daf2f24180..346ba20eb7 100644 --- a/source3/registry/reg_cachehook.c +++ b/source3/registry/reg_cachehook.c @@ -26,6 +26,8 @@ #define DBGC_CLASS DBGC_RPC_SRV static SORTED_TREE *cache_tree; +extern REGISTRY_OPS regdb_ops; /* these are the default */ +static REGISTRY_HOOK default_hook = { KEY_TREE_ROOT, ®db_ops }; /********************************************************************** Initialize the cache tree @@ -33,7 +35,7 @@ static SORTED_TREE *cache_tree; BOOL reghook_cache_init( void ) { - cache_tree = sorted_tree_init( NULL, NULL ); + cache_tree = sorted_tree_init( &default_hook, NULL, NULL ); return ( cache_tree == NULL ); } diff --git a/source3/registry/reg_db.c b/source3/registry/reg_db.c index a521cdcdd0..d44a8d004c 100644 --- a/source3/registry/reg_db.c +++ b/source3/registry/reg_db.c @@ -34,73 +34,72 @@ static TDB_CONTEXT *tdb_reg; static BOOL init_registry_data( void ) { - pstring keyname; - char *subkeys[3]; + pstring keyname; + REGSUBKEY_CTR subkeys; + + ZERO_STRUCTP( &subkeys ); + + regsubkey_ctr_init( &subkeys ); /* HKEY_LOCAL_MACHINE */ pstrcpy( keyname, KEY_HKLM ); - subkeys[0] = "SYSTEM"; - if ( !regdb_store_reg_keys( keyname, subkeys, 1 )) + regsubkey_ctr_addkey( &subkeys, "SYSTEM" ); + if ( !regdb_store_reg_keys( keyname, &subkeys )) return False; + regsubkey_ctr_destroy( &subkeys ); pstrcpy( keyname, KEY_HKLM ); pstrcat( keyname, "/SYSTEM" ); - subkeys[0] = "CurrentControlSet"; - if ( !regdb_store_reg_keys( keyname, subkeys, 1 )) + regsubkey_ctr_addkey( &subkeys, "CurrentControlSet" ); + if ( !regdb_store_reg_keys( keyname, &subkeys )) return False; + regsubkey_ctr_destroy( &subkeys ); pstrcpy( keyname, KEY_HKLM ); pstrcat( keyname, "/SYSTEM/CurrentControlSet" ); - subkeys[0] = "Control"; - subkeys[1] = "services"; - if ( !regdb_store_reg_keys( keyname, subkeys, 2 )) + regsubkey_ctr_addkey( &subkeys, "Control" ); + regsubkey_ctr_addkey( &subkeys, "services" ); + if ( !regdb_store_reg_keys( keyname, &subkeys )) return False; + regsubkey_ctr_destroy( &subkeys ); pstrcpy( keyname, KEY_HKLM ); pstrcat( keyname, "/SYSTEM/CurrentControlSet/Control" ); - subkeys[0] = "Print"; - subkeys[1] = "ProduceOptions"; - if ( !regdb_store_reg_keys( keyname, subkeys, 2 )) - return False; - -#if 0 /* JERRY */ - pstrcpy( keyname, KEY_HKLM ); - pstrcat( keyname, "/SYSTEM/CurrentControlSet/Control/Print" ); - subkeys[0] = "Environments"; - subkeys[1] = "Forms"; - subkeys[2] = "Printers"; - if ( !regdb_store_reg_keys( keyname, subkeys, 0 )) + regsubkey_ctr_addkey( &subkeys, "Print" ); + regsubkey_ctr_addkey( &subkeys, "ProductOptions" ); + if ( !regdb_store_reg_keys( keyname, &subkeys )) return False; -#endif + regsubkey_ctr_destroy( &subkeys ); pstrcpy( keyname, KEY_HKLM ); pstrcat( keyname, "/SYSTEM/CurrentControlSet/Control/ProductOptions" ); - if ( !regdb_store_reg_keys( keyname, subkeys, 0 )) + if ( !regdb_store_reg_keys( keyname, &subkeys )) return False; pstrcpy( keyname, KEY_HKLM ); pstrcat( keyname, "/SYSTEM/CurrentControlSet/services" ); - subkeys[0] = "Netlogon"; - if ( !regdb_store_reg_keys( keyname, subkeys, 1 )) + regsubkey_ctr_addkey( &subkeys, "Netlogon" ); + if ( !regdb_store_reg_keys( keyname, &subkeys )) return False; + regsubkey_ctr_destroy( &subkeys ); pstrcpy( keyname, KEY_HKLM ); pstrcat( keyname, "/SYSTEM/CurrentControlSet/services/Netlogon" ); - subkeys[0] = "parameters"; - if ( !regdb_store_reg_keys( keyname, subkeys, 1 )) + regsubkey_ctr_addkey( &subkeys, "parameters" ); + if ( !regdb_store_reg_keys( keyname, &subkeys )) return False; + regsubkey_ctr_destroy( &subkeys ); pstrcpy( keyname, KEY_HKLM ); pstrcat( keyname, "/SYSTEM/CurrentControlSet/services/Netlogon/parameters" ); - if ( !regdb_store_reg_keys( keyname, subkeys, 0 )) + if ( !regdb_store_reg_keys( keyname, &subkeys )) return False; - /* HKEY_USER */ pstrcpy( keyname, KEY_HKU ); - if ( !regdb_store_reg_keys( keyname, subkeys, 0 ) ) + if ( !regdb_store_reg_keys( keyname, &subkeys ) ) return False; return True; @@ -157,13 +156,14 @@ BOOL init_registry_db( void ) \'s are converted to /'s. ***********************************************************************/ -BOOL regdb_store_reg_keys( char *keyname, char **subkeys, uint32 num_subkeys ) +BOOL regdb_store_reg_keys( char *keyname, REGSUBKEY_CTR *ctr ) { TDB_DATA kbuf, dbuf; char *buffer, *tmpbuf; int i = 0; uint32 len, buflen; BOOL ret = True; + uint32 num_subkeys = regsubkey_ctr_numkeys( ctr ); if ( !keyname ) return False; @@ -176,23 +176,23 @@ BOOL regdb_store_reg_keys( char *keyname, char **subkeys, uint32 num_subkeys ) /* store the number of subkeys */ - len += tdb_pack(buffer+len, buflen-len, "d", num_subkeys); + len += tdb_pack(buffer+len, buflen-len, "d", num_subkeys ); /* pack all the strings */ for (i=0; i buflen ) { /* allocate some extra space */ if ((tmpbuf = Realloc( buffer, len*2 )) == NULL) { - DEBUG(0,("store_reg_keys: Failed to realloc memory of size [%d]\n", len*2)); + DEBUG(0,("regdb_store_reg_keys: Failed to realloc memory of size [%d]\n", len*2)); ret = False; goto done; } buffer = tmpbuf; buflen = len*2; - len = tdb_pack(buffer+len, buflen-len, "f", subkeys[i]); + len = tdb_pack( buffer+len, buflen-len, "f", regsubkey_ctr_specific_key(ctr, i) ); } } @@ -218,7 +218,7 @@ done: of null terminated character strings ***********************************************************************/ -int regdb_fetch_reg_keys( char* key, char **subkeys ) +int regdb_fetch_reg_keys( char* key, REGSUBKEY_CTR *ctr ) { pstring path; uint32 num_items; @@ -226,7 +226,7 @@ int regdb_fetch_reg_keys( char* key, char **subkeys ) char *buf; uint32 buflen, len; int i; - char *s; + fstring subkeyname; pstrcpy( path, key ); @@ -240,72 +240,53 @@ int regdb_fetch_reg_keys( char* key, char **subkeys ) buflen = dbuf.dsize; if ( !buf ) { - DEBUG(5,("fetch_reg_keys: Failed to fetch any subkeys for [%s]\n", key)); + DEBUG(5,("regdb_fetch_reg_keys: Failed to fetch any subkeys for [%s]\n", key)); return 0; } len = tdb_unpack( buf, buflen, "d", &num_items); - if (num_items) { - if ( (*subkeys = (char*)malloc(sizeof(fstring)*num_items)) == NULL ) { - DEBUG(0,("fetch_reg_keys: Failed to malloc memory for subkey array containing [%d] items!\n", - num_items)); - num_items = -1; - goto done; - } - } - s = *subkeys; for (i=0; iname, subkeys, num_subkeys ); + if ( key->hook && key->hook->ops && key->hook->ops->store_subkeys_fn ) + return key->hook->ops->store_subkeys_fn( key->name, subkeys ); + else + return False; } @@ -80,60 +85,210 @@ BOOL store_reg_keys( REGISTRY_KEY *key, char **subkeys, uint32 num_subkeys ) High level wrapper function for storing registry values ***********************************************************************/ -BOOL store_reg_values( REGISTRY_KEY *key, REGISTRY_VALUE **val, uint32 num_values ) +BOOL store_reg_values( REGISTRY_KEY *key, REGVAL_CTR *val ) { - return True; + if ( key->hook && key->hook->ops && key->hook->ops->store_values_fn ) + return key->hook->ops->store_values_fn( key->name, val ); + else + return False; } /*********************************************************************** High level wrapper function for enumerating registry subkeys + Initialize the TALLOC_CTX if necessary ***********************************************************************/ -int fetch_reg_keys( REGISTRY_KEY *key, char **subkeys ) +int fetch_reg_keys( REGISTRY_KEY *key, REGSUBKEY_CTR *subkey_ctr ) { - int num_subkeys; + int result = -1; if ( key->hook && key->hook->ops && key->hook->ops->subkey_fn ) - num_subkeys = key->hook->ops->subkey_fn( key->name, subkeys ); - else - num_subkeys = regdb_fetch_reg_keys( key->name, subkeys ); + result = key->hook->ops->subkey_fn( key->name, subkey_ctr ); - return num_subkeys; + return result; } /*********************************************************************** - High level wrapper function for retreiving a specific registry subkey - given and index. + retreive a specific subkey specified by index. Caller is + responsible for freeing memory ***********************************************************************/ BOOL fetch_reg_keys_specific( REGISTRY_KEY *key, char** subkey, uint32 key_index ) { - BOOL result; - - if ( key->hook && key->hook->ops && key->hook->ops->subkey_specific_fn ) - result = key->hook->ops->subkey_specific_fn( key->name, subkey, key_index ); - else - result = regdb_fetch_reg_keys_specific( key->name, subkey, key_index ); + char *s; + REGSUBKEY_CTR ctr; - return result; + ZERO_STRUCTP( &ctr ); + + regsubkey_ctr_init( &ctr ); + + if ( fetch_reg_keys( key, &ctr) == -1 ) + return False; + + if ( !(s = regsubkey_ctr_specific_key( &ctr, key_index )) ) + return False; + + *subkey = strdup( s ); + + regsubkey_ctr_destroy( &ctr ); + + return True; } /*********************************************************************** High level wrapper function for enumerating registry values + Initialize the TALLOC_CTX if necessary ***********************************************************************/ -int fetch_reg_values( REGISTRY_KEY *key, REGISTRY_VALUE **val ) +int fetch_reg_values( REGISTRY_KEY *key, REGVAL_CTR *val ) { - int num_values; + int result = -1; if ( key->hook && key->hook->ops && key->hook->ops->value_fn ) - num_values = key->hook->ops->value_fn( key->name, val ); - else - num_values = regdb_fetch_reg_values( key->name, val ); + result = key->hook->ops->value_fn( key->name, val ); + + return result; +} + +/*********************************************************************** + Utility function for splitting the base path of a registry path off + by setting base and new_path to the apprapriate offsets withing the + path. + + WARNING!! Does modify the original string! + ***********************************************************************/ + +BOOL reg_split_path( char *path, char **base, char **new_path ) +{ + char *p; + + *new_path = *base = NULL; + + if ( !path) + return False; + + *base = path; + + p = strchr( path, '\\' ); + + if ( p ) { + *p = '\0'; + *new_path = p+1; + } + + return True; +} + + +/* + * Utility functions for REGSUBKEY_CTR + */ + +/*********************************************************************** + Init the talloc context held by a REGSUBKEY_CTR structure + **********************************************************************/ + +void regsubkey_ctr_init( REGSUBKEY_CTR *ctr ) +{ + if ( !ctr->ctx ) + ctr->ctx = talloc_init(); +} + +/*********************************************************************** + Add a new key to the array + **********************************************************************/ + +int regsubkey_ctr_addkey( REGSUBKEY_CTR *ctr, char *keyname ) +{ + uint32 len; + + if ( keyname ) + { + len = strlen( keyname ); + + if ( ctr->subkeys == 0 ) + ctr->subkeys = talloc( ctr->ctx, 1 ); + else + talloc_realloc( ctr->ctx, ctr->subkeys, ctr->num_subkeys+1 ); + + ctr->subkeys[ctr->num_subkeys] = talloc( ctr->ctx, len+1 ); + strncpy( ctr->subkeys[ctr->num_subkeys], keyname, len+1 ); + ctr->num_subkeys++; + } + + return ctr->num_subkeys; +} + +/*********************************************************************** + How many keys does the container hold ? + **********************************************************************/ + +int regsubkey_ctr_numkeys( REGSUBKEY_CTR *ctr ) +{ + return ctr->num_subkeys; +} + +/*********************************************************************** + Retreive a specific key string + **********************************************************************/ + +char* regsubkey_ctr_specific_key( REGSUBKEY_CTR *ctr, uint32 index ) +{ + if ( ! (index < ctr->num_subkeys) ) + return NULL; + + return ctr->subkeys[index]; +} + +/*********************************************************************** + free memory held by a REGSUBKEY_CTR structure + **********************************************************************/ + +void regsubkey_ctr_destroy( REGSUBKEY_CTR *ctr ) +{ + if ( ctr ) + talloc_destroy( ctr->ctx ); - return num_values; + ctr->num_subkeys = 0; + ctr->subkeys = NULL; +} + + +/* + * Utility functions for REGVAL_CTR + */ + +/*********************************************************************** + Init the talloc context held by a REGSUBKEY_CTR structure + **********************************************************************/ + +void regval_ctr_init( REGVAL_CTR *ctr ) +{ + if ( !ctr->ctx ) + ctr->ctx = talloc_init(); +} + +/*********************************************************************** + How many keys does the container hold ? + **********************************************************************/ + +int regval_ctr_numvals( REGVAL_CTR *ctr ) +{ + return ctr->num_values; } +/*********************************************************************** + free memory held by a REGVAL_CTR structure + **********************************************************************/ + +void regval_ctr_destroy( REGVAL_CTR *ctr ) +{ + if ( ctr ) + talloc_destroy( ctr->ctx ); + + ctr->num_values = 0; + ctr->values = NULL; +} diff --git a/source3/registry/reg_printing.c b/source3/registry/reg_printing.c index cbeab13142..b2403a3133 100644 --- a/source3/registry/reg_printing.c +++ b/source3/registry/reg_printing.c @@ -51,9 +51,26 @@ static char *top_level_keys[MAX_TOP_LEVEL_KEYS] = { static char* trim_reg_path( char *path ) { char *p; + uint16 key_len = strlen(KEY_PRINTING); + + /* + * sanity check...this really should never be True. + * It is only here to prevent us from accessing outside + * the path buffer in the extreme case. + */ + + if ( strlen(path) < key_len ) { + DEBUG(0,("trim_reg_path: Registry path too short! [%s]\n", path)); + DEBUG(0,("trim_reg_path: KEY_PRINTING => [%s]!\n", KEY_PRINTING)); + return NULL; + } + p = path + strlen(KEY_PRINTING); + if ( *p == '\\' ) + p++; + if ( *p ) return strdup(p); else @@ -61,15 +78,98 @@ static char* trim_reg_path( char *path ) } /********************************************************************** - handle enumeration of subkeys below KEY_PRINTING. + handle enumeration of subkeys below KEY_PRINTING\Environments + *********************************************************************/ + +static int print_subpath_environments( char *key, REGSUBKEY_CTR *subkeys, int32 idx ) +{ + DEBUG(10,("print_subpath_environments: key=>[%s]\n", key ? key : "NULL" )); + + if ( !key ) + { + /* listed architectures of installed drivers */ + + } + + + return 0; +} + +/********************************************************************** + handle enumeration of subkeys below KEY_PRINTING\Forms *********************************************************************/ -static int handle_printing_subpath( char *key, char **subkeys, uint32 index ) +static int print_subpath_forms( char *key, REGSUBKEY_CTR *subkeys, int32 idx ) +{ + DEBUG(10,("print_subpath_forms: key=>[%s]\n", key ? key : "NULL" )); + + return 0; +} + +/********************************************************************** + handle enumeration of values below KEY_PRINTING\Forms + *********************************************************************/ + +static int print_values_forms( char *key, REGVAL_CTR *val, int idx ) +{ + int num_values = 0; + + DEBUG(10,("print_values_forms: key=>[%s]\n", key ? key : "NULL" )); + + /* handle ..\Forms\ */ + +#if 0 /* JERRY */ + if ( !key ) + { + nt_forms_struct *forms = NULL; + int i; + + if ( (num_values = get_ntforms( &forms )) == 0 ) + return 0; + + if ( !(*values = malloc(sizeof(REGISTRY_VALUE) * num_values)) ) { + DEBUG(0,("print_values_forms: Failed to malloc memory for [%d] REGISTRY_VALUE structs!\n", + num_values)); + return -1; + } + + for ( i=0; i[%s]\n", key ? key : "NULL" )); + + return 0; +} + +/********************************************************************** + Routine to handle enumeration of subkeys and values + below KEY_PRINTING (depending on whether or not subkeys/val are + valid pointers. + *********************************************************************/ + +static int handle_printing_subpath( char *key, REGSUBKEY_CTR *subkeys, + REGVAL_CTR *val, int32 key_index, int32 val_index ) { int result = 0; char *p, *base; int i; - + + DEBUG(10,("handle_printing_subpath: key=>[%s], key_index == [%d], val_index == [%d]\n", + key, key_index, val_index)); /* * break off the first part of the path @@ -77,29 +177,36 @@ static int handle_printing_subpath( char *key, char **subkeys, uint32 index ) * in top_level_keys[] */ - base = key; - p = strchr( key, '\\' ); - if ( p ) - *p = '\0'; + reg_split_path( key, &base, &p); for ( i=0; i[%s], i==[%d]\n", base, i)); + + if ( (key_index != -1) && !(i < MAX_TOP_LEVEL_KEYS) ) return -1; - + /* Call routine to handle each top level key */ switch ( i ) { case KEY_INDEX_ENVIR: + if ( subkeys ) + print_subpath_environments( p, subkeys, key_index ); +#if 0 /* JERRY */ + if ( val ) + print_subpath_values_environments( p, val, val_index ); +#endif break; case KEY_INDEX_FORMS: + result = print_subpath_forms( p, subkeys, key_index ); break; case KEY_INDEX_PRINTER: + result = print_subpath_printers( p, subkeys, key_index ); break; /* default case for top level key that has no handler */ @@ -118,7 +225,7 @@ static int handle_printing_subpath( char *key, char **subkeys, uint32 index ) Caller is responsible for freeing memory to **subkeys *********************************************************************/ -int printing_subkey_info( char *key, char **subkeys ) +int printing_subkey_info( char *key, REGSUBKEY_CTR *subkey_ctr ) { char *path; BOOL top_level = False; @@ -134,32 +241,29 @@ int printing_subkey_info( char *key, char **subkeys ) top_level = True; if ( top_level ) { - if ( ! (*subkeys = malloc( sizeof(top_level_keys) )) ) - goto done; - - num_subkeys = MAX_TOP_LEVEL_KEYS; - memcpy( *subkeys, top_level_keys, sizeof(top_level_keys) ); + for ( num_subkeys=0; num_subkeys[%s], index=>[%d]\n", key, indx)); + DEBUG(10,("printing_value_info: key=>[%s]\n", key)); path = trim_reg_path( key ); @@ -168,43 +272,16 @@ BOOL printing_subkey_specific( char *key, char** subkey, uint32 indx ) if ( !path ) top_level = True; - - - if ( top_level ) { - - /* make sure the index is in range */ - - if ( !(indx < MAX_TOP_LEVEL_KEYS) ) - goto done; - - if ( !(*subkey = malloc( strlen(top_level_keys[indx])+1 )) ) - goto done; - - strncpy( *subkey, top_level_keys[indx], strlen(top_level_keys[indx])+1 ); - - result = True; - } - else { - if ( handle_printing_subpath( path, subkey, indx ) != -1 ) - result = True; + /* fill in values from the getprinterdata_printer_server() */ + if ( top_level ) + { + num_values = 0; } + else + num_values = handle_printing_subpath( path, NULL, val, -1, -1 ); + -done: - SAFE_FREE( path ); - - return result; -} - -/********************************************************************** - Enumerate registry values given a registry path. - Caller is responsible for freeing memory - *********************************************************************/ - -int printing_value_info( char *key, REGISTRY_VALUE **val ) -{ - DEBUG(10,("printing_value_info: key=>[%s]\n", key)); - - return 0; + return num_values; } /********************************************************************** @@ -213,7 +290,7 @@ int printing_value_info( char *key, REGISTRY_VALUE **val ) (for now at least) *********************************************************************/ -BOOL printing_store_subkey( char *key, char **subkeys, uint32 num_subkeys ) +BOOL printing_store_subkey( char *key, REGSUBKEY_CTR *subkeys ) { return False; } @@ -224,7 +301,7 @@ BOOL printing_store_subkey( char *key, char **subkeys, uint32 num_subkeys ) (for now at least) *********************************************************************/ -BOOL printing_store_value( char *key, REGISTRY_VALUE **val, uint32 num_values ) +BOOL printing_store_value( char *key, REGVAL_CTR *val ) { return False; } @@ -235,9 +312,9 @@ BOOL printing_store_value( char *key, REGISTRY_VALUE **val, uint32 num_values ) REGISTRY_OPS printing_ops = { printing_subkey_info, - printing_subkey_specific, printing_value_info, printing_store_subkey, printing_store_value }; + -- cgit From 12e237da6813ca6a40410c73c75152a840f4ea61 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 19 Jul 2002 22:01:23 +0000 Subject: Fixed a compiler warning. (This used to be commit bc0f1c1ec21e69014426e41fb0a5264da63b857a) --- source3/registry/reg_frontend.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/registry') diff --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c index 7b7cade6c0..3e3ec49425 100644 --- a/source3/registry/reg_frontend.c +++ b/source3/registry/reg_frontend.c @@ -234,12 +234,12 @@ int regsubkey_ctr_numkeys( REGSUBKEY_CTR *ctr ) Retreive a specific key string **********************************************************************/ -char* regsubkey_ctr_specific_key( REGSUBKEY_CTR *ctr, uint32 index ) +char* regsubkey_ctr_specific_key( REGSUBKEY_CTR *ctr, uint32 key_index ) { - if ( ! (index < ctr->num_subkeys) ) + if ( ! (key_index < ctr->num_subkeys) ) return NULL; - return ctr->subkeys[index]; + return ctr->subkeys[key_index]; } /*********************************************************************** -- cgit From 3c0a9c46d8057b9499d7d48a67ba15f9942d558a Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 19 Jul 2002 22:16:03 +0000 Subject: fixed seg fault in registry frontend caused by trying to use a destroyed TALLOC_CTX* (This used to be commit 432b9f8d7c20fbf3b2a0906c8a93272abbe43fb6) --- source3/registry/reg_cachehook.c | 11 ++++++++--- source3/registry/reg_db.c | 6 ++++++ source3/registry/reg_frontend.c | 16 +++++++--------- 3 files changed, 21 insertions(+), 12 deletions(-) (limited to 'source3/registry') diff --git a/source3/registry/reg_cachehook.c b/source3/registry/reg_cachehook.c index 346ba20eb7..e2444d8d17 100644 --- a/source3/registry/reg_cachehook.c +++ b/source3/registry/reg_cachehook.c @@ -69,15 +69,20 @@ BOOL reghook_cache_add( REGISTRY_HOOK *hook ) REGISTRY_HOOK* reghook_cache_find( char *keyname ) { char *key; + int len; if ( !keyname ) return NULL; - - if ( (key = strdup( keyname )) == NULL ) { - DEBUG(0,("reghook_cache_find: strdup() failed for string [%s] !?!?!\n", + + len = strlen( keyname ); + if ( !(key = malloc( len + 2 )) ) { + DEBUG(0,("reghook_cache_find: malloc failed for string [%s] !?!?!\n", keyname)); return NULL; } + + *key = '\\'; + strncpy( key+1, keyname, len+1); string_sub( key, "\\", "/", 0 ); diff --git a/source3/registry/reg_db.c b/source3/registry/reg_db.c index d44a8d004c..fb6ebdbf7c 100644 --- a/source3/registry/reg_db.c +++ b/source3/registry/reg_db.c @@ -43,12 +43,14 @@ static BOOL init_registry_data( void ) /* HKEY_LOCAL_MACHINE */ + regsubkey_ctr_init( &subkeys ); pstrcpy( keyname, KEY_HKLM ); regsubkey_ctr_addkey( &subkeys, "SYSTEM" ); if ( !regdb_store_reg_keys( keyname, &subkeys )) return False; regsubkey_ctr_destroy( &subkeys ); + regsubkey_ctr_init( &subkeys ); pstrcpy( keyname, KEY_HKLM ); pstrcat( keyname, "/SYSTEM" ); regsubkey_ctr_addkey( &subkeys, "CurrentControlSet" ); @@ -56,6 +58,7 @@ static BOOL init_registry_data( void ) return False; regsubkey_ctr_destroy( &subkeys ); + regsubkey_ctr_init( &subkeys ); pstrcpy( keyname, KEY_HKLM ); pstrcat( keyname, "/SYSTEM/CurrentControlSet" ); regsubkey_ctr_addkey( &subkeys, "Control" ); @@ -64,6 +67,7 @@ static BOOL init_registry_data( void ) return False; regsubkey_ctr_destroy( &subkeys ); + regsubkey_ctr_init( &subkeys ); pstrcpy( keyname, KEY_HKLM ); pstrcat( keyname, "/SYSTEM/CurrentControlSet/Control" ); regsubkey_ctr_addkey( &subkeys, "Print" ); @@ -77,6 +81,7 @@ static BOOL init_registry_data( void ) if ( !regdb_store_reg_keys( keyname, &subkeys )) return False; + regsubkey_ctr_init( &subkeys ); pstrcpy( keyname, KEY_HKLM ); pstrcat( keyname, "/SYSTEM/CurrentControlSet/services" ); regsubkey_ctr_addkey( &subkeys, "Netlogon" ); @@ -84,6 +89,7 @@ static BOOL init_registry_data( void ) return False; regsubkey_ctr_destroy( &subkeys ); + regsubkey_ctr_init( &subkeys ); pstrcpy( keyname, KEY_HKLM ); pstrcat( keyname, "/SYSTEM/CurrentControlSet/services/Netlogon" ); regsubkey_ctr_addkey( &subkeys, "parameters" ); diff --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c index 3e3ec49425..6090245096 100644 --- a/source3/registry/reg_frontend.c +++ b/source3/registry/reg_frontend.c @@ -248,11 +248,10 @@ char* regsubkey_ctr_specific_key( REGSUBKEY_CTR *ctr, uint32 key_index ) void regsubkey_ctr_destroy( REGSUBKEY_CTR *ctr ) { - if ( ctr ) - talloc_destroy( ctr->ctx ); - - ctr->num_subkeys = 0; - ctr->subkeys = NULL; + if ( ctr ) { + talloc_destroy( ctr->ctx ); + ZERO_STRUCTP( ctr ); + } } @@ -285,10 +284,9 @@ int regval_ctr_numvals( REGVAL_CTR *ctr ) void regval_ctr_destroy( REGVAL_CTR *ctr ) { - if ( ctr ) + if ( ctr ) { talloc_destroy( ctr->ctx ); - - ctr->num_values = 0; - ctr->values = NULL; + ZERO_STRUCTP( ctr ); + } } -- cgit From 39bbeff5b361ffa6a5ff9273cf7fce5f46543703 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 20 Jul 2002 02:42:04 +0000 Subject: fixed a logic error in the sorted_tree_find_child() routine that caused a valid search to fail. The printing registry view now works again. (This used to be commit 2050859f03493d5135984ce1e42baf8f1f2566b9) --- source3/registry/reg_cachehook.c | 4 ++++ source3/registry/reg_frontend.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'source3/registry') diff --git a/source3/registry/reg_cachehook.c b/source3/registry/reg_cachehook.c index e2444d8d17..2139fa7066 100644 --- a/source3/registry/reg_cachehook.c +++ b/source3/registry/reg_cachehook.c @@ -74,6 +74,8 @@ REGISTRY_HOOK* reghook_cache_find( char *keyname ) if ( !keyname ) return NULL; + /* prepend the string with a '\' character */ + len = strlen( keyname ); if ( !(key = malloc( len + 2 )) ) { DEBUG(0,("reghook_cache_find: malloc failed for string [%s] !?!?!\n", @@ -84,6 +86,8 @@ REGISTRY_HOOK* reghook_cache_find( char *keyname ) *key = '\\'; strncpy( key+1, keyname, len+1); + /* swap to a form understood by the SORTED_TREE */ + string_sub( key, "\\", "/", 0 ); DEBUG(10,("reghook_cache_find: Searching for keyname [%s]\n", key)); diff --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c index 6090245096..de2b279546 100644 --- a/source3/registry/reg_frontend.c +++ b/source3/registry/reg_frontend.c @@ -60,7 +60,8 @@ BOOL init_registry( void ) return False; } - reghook_dump_cache(20); + if ( DEBUGLEVEL >= 20 ) + reghook_dump_cache(20); return True; } -- cgit From b516eb62db51fe8a793b73014777ced3038f9aa7 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 20 Jul 2002 04:27:30 +0000 Subject: enumeration of printers keys ( no data yet ) via the registry functions now works :-) (This used to be commit c5768538f6cf6ee824bc6e105a3391bbc2ea8e46) --- source3/registry/reg_cachehook.c | 7 ++++- source3/registry/reg_db.c | 8 +++--- source3/registry/reg_frontend.c | 10 +++++-- source3/registry/reg_printing.c | 62 +++++++++++++++++++++++++++------------- 4 files changed, 59 insertions(+), 28 deletions(-) (limited to 'source3/registry') diff --git a/source3/registry/reg_cachehook.c b/source3/registry/reg_cachehook.c index 2139fa7066..547eed392d 100644 --- a/source3/registry/reg_cachehook.c +++ b/source3/registry/reg_cachehook.c @@ -70,6 +70,7 @@ REGISTRY_HOOK* reghook_cache_find( char *keyname ) { char *key; int len; + REGISTRY_HOOK *hook; if ( !keyname ) return NULL; @@ -92,7 +93,11 @@ REGISTRY_HOOK* reghook_cache_find( char *keyname ) DEBUG(10,("reghook_cache_find: Searching for keyname [%s]\n", key)); - return sorted_tree_find( cache_tree, key ) ; + hook = sorted_tree_find( cache_tree, key ) ; + + SAFE_FREE( key ); + + return hook; } /********************************************************************** diff --git a/source3/registry/reg_db.c b/source3/registry/reg_db.c index fb6ebdbf7c..714e14e48b 100644 --- a/source3/registry/reg_db.c +++ b/source3/registry/reg_db.c @@ -39,8 +39,6 @@ static BOOL init_registry_data( void ) ZERO_STRUCTP( &subkeys ); - regsubkey_ctr_init( &subkeys ); - /* HKEY_LOCAL_MACHINE */ regsubkey_ctr_init( &subkeys ); @@ -215,6 +213,7 @@ BOOL regdb_store_reg_keys( char *keyname, REGSUBKEY_CTR *ctr ) done: SAFE_FREE( buffer ); + return ret; } @@ -238,7 +237,7 @@ int regdb_fetch_reg_keys( char* key, REGSUBKEY_CTR *ctr ) pstrcpy( path, key ); /* convert to key format */ - pstring_sub( path, "\\", "/" ); + pstring_sub( path, "\\", "/" ); dbuf = tdb_fetch_by_string( tdb_reg, path ); @@ -257,7 +256,8 @@ int regdb_fetch_reg_keys( char* key, REGSUBKEY_CTR *ctr ) regsubkey_ctr_addkey( ctr, subkeyname ); } - SAFE_FREE(dbuf.dptr); + SAFE_FREE( dbuf.dptr ); + return num_items; } diff --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c index de2b279546..4e3f09fe4e 100644 --- a/source3/registry/reg_frontend.c +++ b/source3/registry/reg_frontend.c @@ -204,15 +204,19 @@ void regsubkey_ctr_init( REGSUBKEY_CTR *ctr ) int regsubkey_ctr_addkey( REGSUBKEY_CTR *ctr, char *keyname ) { uint32 len; + char **pp; if ( keyname ) { len = strlen( keyname ); if ( ctr->subkeys == 0 ) - ctr->subkeys = talloc( ctr->ctx, 1 ); - else - talloc_realloc( ctr->ctx, ctr->subkeys, ctr->num_subkeys+1 ); + ctr->subkeys = talloc( ctr->ctx, sizeof(char*) ); + else { + pp = talloc_realloc( ctr->ctx, ctr->subkeys, sizeof(char*)*(ctr->num_subkeys+1) ); + if ( pp ) + ctr->subkeys = pp; + } ctr->subkeys[ctr->num_subkeys] = talloc( ctr->ctx, len+1 ); strncpy( ctr->subkeys[ctr->num_subkeys], keyname, len+1 ); diff --git a/source3/registry/reg_printing.c b/source3/registry/reg_printing.c index b2403a3133..99bdb4771f 100644 --- a/source3/registry/reg_printing.c +++ b/source3/registry/reg_printing.c @@ -66,7 +66,7 @@ static char* trim_reg_path( char *path ) } - p = path + strlen(KEY_PRINTING); + p = path + strlen( KEY_PRINTING ); if ( *p == '\\' ) p++; @@ -81,7 +81,7 @@ static char* trim_reg_path( char *path ) handle enumeration of subkeys below KEY_PRINTING\Environments *********************************************************************/ -static int print_subpath_environments( char *key, REGSUBKEY_CTR *subkeys, int32 idx ) +static int print_subpath_environments( char *key, REGSUBKEY_CTR *subkeys ) { DEBUG(10,("print_subpath_environments: key=>[%s]\n", key ? key : "NULL" )); @@ -99,7 +99,7 @@ static int print_subpath_environments( char *key, REGSUBKEY_CTR *subkeys, int32 handle enumeration of subkeys below KEY_PRINTING\Forms *********************************************************************/ -static int print_subpath_forms( char *key, REGSUBKEY_CTR *subkeys, int32 idx ) +static int print_subpath_forms( char *key, REGSUBKEY_CTR *subkeys ) { DEBUG(10,("print_subpath_forms: key=>[%s]\n", key ? key : "NULL" )); @@ -110,7 +110,7 @@ static int print_subpath_forms( char *key, REGSUBKEY_CTR *subkeys, int32 idx ) handle enumeration of values below KEY_PRINTING\Forms *********************************************************************/ -static int print_values_forms( char *key, REGVAL_CTR *val, int idx ) +static int print_values_forms( char *key, REGVAL_CTR *val ) { int num_values = 0; @@ -148,11 +148,33 @@ static int print_values_forms( char *key, REGVAL_CTR *val, int idx ) handle enumeration of subkeys below KEY_PRINTING\Printers *********************************************************************/ -static int print_subpath_printers( char *key, REGSUBKEY_CTR *subkeys, int32 idx ) +static int print_subpath_printers( char *key, REGSUBKEY_CTR *subkeys ) { + int n_services = lp_numservices(); + int snum; + fstring sname; + DEBUG(10,("print_subpath_printers: key=>[%s]\n", key ? key : "NULL" )); - return 0; + if ( !key ) + { + /* enumerate all printers */ + + for (snum=0; snum[%s], key_index == [%d], val_index == [%d]\n", - key, key_index, val_index)); + DEBUG(10,("handle_printing_subpath: key=>[%s]\n", key )); /* * break off the first part of the path @@ -186,27 +206,31 @@ static int handle_printing_subpath( char *key, REGSUBKEY_CTR *subkeys, DEBUG(10,("handle_printing_subpath: base=>[%s], i==[%d]\n", base, i)); - if ( (key_index != -1) && !(i < MAX_TOP_LEVEL_KEYS) ) + if ( !(i < MAX_TOP_LEVEL_KEYS) ) return -1; - + + /* quick hack for now */ + if ( !subkeys ) + return 0; + /* Call routine to handle each top level key */ switch ( i ) { case KEY_INDEX_ENVIR: if ( subkeys ) - print_subpath_environments( p, subkeys, key_index ); + print_subpath_environments( p, subkeys ); #if 0 /* JERRY */ if ( val ) - print_subpath_values_environments( p, val, val_index ); + print_subpath_values_environments( p, val ); #endif break; case KEY_INDEX_FORMS: - result = print_subpath_forms( p, subkeys, key_index ); + result = print_subpath_forms( p, subkeys ); break; case KEY_INDEX_PRINTER: - result = print_subpath_printers( p, subkeys, key_index ); + result = print_subpath_printers( p, subkeys ); break; /* default case for top level key that has no handler */ @@ -245,7 +269,7 @@ int printing_subkey_info( char *key, REGSUBKEY_CTR *subkey_ctr ) regsubkey_ctr_addkey( subkey_ctr, top_level_keys[num_subkeys] ); } else - num_subkeys = handle_printing_subpath( path, subkey_ctr, NULL, -1, -1 ); + num_subkeys = handle_printing_subpath( path, subkey_ctr, NULL ); SAFE_FREE( path ); @@ -274,11 +298,9 @@ int printing_value_info( char *key, REGVAL_CTR *val ) /* fill in values from the getprinterdata_printer_server() */ if ( top_level ) - { num_values = 0; - } else - num_values = handle_printing_subpath( path, NULL, val, -1, -1 ); + num_values = handle_printing_subpath( path, NULL, val ); return num_values; -- cgit From 6dd9f24d05e5db92e15dc53399a0f78ccb69f718 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 20 Jul 2002 13:23:57 +0000 Subject: another intermediate checkin on the way to enumerating forms via the registry. There is a seg fault here which shouldn't bother anyone until I can get it fixed. I just need a check point in case I need to roll back to this version later on. (This used to be commit e62ae94823461e142978a786b2860ea97906cfb3) --- source3/registry/reg_frontend.c | 53 ++++++++++++++++++++++++- source3/registry/reg_printing.c | 86 ++++++++++++++++++++++++++++++----------- 2 files changed, 116 insertions(+), 23 deletions(-) (limited to 'source3/registry') diff --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c index 4e3f09fe4e..6e550c1a0d 100644 --- a/source3/registry/reg_frontend.c +++ b/source3/registry/reg_frontend.c @@ -32,7 +32,6 @@ extern REGISTRY_OPS regdb_ops; /* these are the default */ REGISTRY_HOOK reg_hooks[] = { - { KEY_TREE_ROOT, ®db_ops }, { KEY_PRINTING, &printing_ops }, { NULL, NULL } }; @@ -283,6 +282,58 @@ int regval_ctr_numvals( REGVAL_CTR *ctr ) return ctr->num_values; } +REGISTRY_VALUE* regval_ctr_specific_value( REGVAL_CTR *ctr, uint32 idx ) +{ + if ( !(idx < ctr->num_values) ) + return NULL; + + return ctr->values[idx]; +} + +/*********************************************************************** + Ad a new regostry value to the array + **********************************************************************/ + +int regval_ctr_addvalue( REGVAL_CTR *ctr, char *name, uint16 type, + char *data_p, size_t size ) +{ + REGISTRY_VALUE **ppreg; + uint16 len; + + if ( name ) + { + len = strlen( name ); + + if ( ctr->num_values == 0 ) + ctr->values = talloc( ctr->ctx, sizeof(REGISTRY_VALUE*) ); + else { + ppreg = talloc_realloc( ctr->ctx, ctr->values, sizeof(REGISTRY_VALUE*)*(ctr->num_values+1) ); + if ( ppreg ) + ctr->values = ppreg; + } + + fstrcpy( ctr->values[ctr->num_values]->valuename, name ); + ctr->values[ctr->num_values]->type = type; + switch ( type ) + { + case REG_SZ: + ctr->values[ctr->num_values]->data.string = talloc_strdup( ctr->ctx, data_p ); + break; + case REG_DWORD: + break; + case REG_BINARY: + ctr->values[ctr->num_values]->data.binary = talloc_memdup( ctr->ctx, data_p, size ); + break; + + } + ctr->values[ctr->num_values]->size = size; + + ctr->num_values++; + } + + return ctr->num_values; +} + /*********************************************************************** free memory held by a REGVAL_CTR structure **********************************************************************/ diff --git a/source3/registry/reg_printing.c b/source3/registry/reg_printing.c index 99bdb4771f..993d793c1e 100644 --- a/source3/registry/reg_printing.c +++ b/source3/registry/reg_printing.c @@ -39,6 +39,7 @@ static char *top_level_keys[MAX_TOP_LEVEL_KEYS] = { "Printers" }; + /********************************************************************** It is safe to assume that every registry path passed into on of the exported functions here begins with KEY_PRINTING else @@ -97,12 +98,19 @@ static int print_subpath_environments( char *key, REGSUBKEY_CTR *subkeys ) /********************************************************************** handle enumeration of subkeys below KEY_PRINTING\Forms + Really just a stub function, but left here in case it needs to + be expanded later on *********************************************************************/ static int print_subpath_forms( char *key, REGSUBKEY_CTR *subkeys ) { DEBUG(10,("print_subpath_forms: key=>[%s]\n", key ? key : "NULL" )); + /* there are no subkeys */ + + if ( key ) + return -1; + return 0; } @@ -110,36 +118,74 @@ static int print_subpath_forms( char *key, REGSUBKEY_CTR *subkeys ) handle enumeration of values below KEY_PRINTING\Forms *********************************************************************/ -static int print_values_forms( char *key, REGVAL_CTR *val ) +static int print_subpath_values_forms( char *key, REGVAL_CTR *val ) { - int num_values = 0; + int num_values = 0; + uint32 data[7]; DEBUG(10,("print_values_forms: key=>[%s]\n", key ? key : "NULL" )); /* handle ..\Forms\ */ -#if 0 /* JERRY */ if ( !key ) { - nt_forms_struct *forms = NULL; + nt_forms_struct *forms_list = NULL; + nt_forms_struct *form = NULL; int i; - if ( (num_values = get_ntforms( &forms )) == 0 ) + if ( (num_values = get_ntforms( &forms_list )) == 0 ) return 0; - if ( !(*values = malloc(sizeof(REGISTRY_VALUE) * num_values)) ) { - DEBUG(0,("print_values_forms: Failed to malloc memory for [%d] REGISTRY_VALUE structs!\n", - num_values)); - return -1; + DEBUG(10,("print_subpath_values_forms: [%d] user defined forms returned\n", + num_values)); + + /* handle user defined forms */ + + for ( i=0; iflag; + data[1] = form->width; + data[2] = form->length; + data[3] = form->left; + data[4] = form->top; + data[5] = form->right; + data[6] = form->bottom; + + regval_ctr_addvalue( val, form->name, REG_BINARY, (char*)data, sizeof(data) ); + } + SAFE_FREE( forms_list ); + forms_list = NULL; + + /* handle built-on forms */ + + if ( (num_values = get_builtin_ntforms( &forms_list )) == 0 ) + return 0; + + DEBUG(10,("print_subpath_values_forms: [%d] built-in forms returned\n", + num_values)); + for ( i=0; iflag; + data[1] = form->width; + data[2] = form->length; + data[3] = form->left; + data[4] = form->top; + data[5] = form->right; + data[6] = form->bottom; + + regval_ctr_addvalue( val, form->name, REG_BINARY, (char*)data, sizeof(data) ); } + + SAFE_FREE( forms_list ); } -#endif return num_values; } @@ -150,7 +196,7 @@ static int print_values_forms( char *key, REGVAL_CTR *val ) static int print_subpath_printers( char *key, REGSUBKEY_CTR *subkeys ) { - int n_services = lp_numservices(); + int n_services = lp_numservices(); int snum; fstring sname; @@ -208,29 +254,25 @@ static int handle_printing_subpath( char *key, REGSUBKEY_CTR *subkeys, REGVAL_CT if ( !(i < MAX_TOP_LEVEL_KEYS) ) return -1; - - /* quick hack for now */ - if ( !subkeys ) - return 0; - + /* Call routine to handle each top level key */ switch ( i ) { case KEY_INDEX_ENVIR: if ( subkeys ) print_subpath_environments( p, subkeys ); -#if 0 /* JERRY */ - if ( val ) - print_subpath_values_environments( p, val ); -#endif break; case KEY_INDEX_FORMS: - result = print_subpath_forms( p, subkeys ); + if ( subkeys ) + print_subpath_forms( p, subkeys ); + if ( val ) + print_subpath_values_forms( p, val ); break; case KEY_INDEX_PRINTER: - result = print_subpath_printers( p, subkeys ); + if ( subkeys ) + print_subpath_printers( p, subkeys ); break; /* default case for top level key that has no handler */ -- cgit From 029fba81c660f8a27f4b61f34ecb118f5018efda Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 22 Jul 2002 21:02:18 +0000 Subject: fix seg fault due to memory allocation goof. (This used to be commit 8e94f68a80bda0cbc989fb36466dfbc17a07079d) --- source3/registry/reg_frontend.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source3/registry') diff --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c index 6e550c1a0d..d8a10940fd 100644 --- a/source3/registry/reg_frontend.c +++ b/source3/registry/reg_frontend.c @@ -304,6 +304,8 @@ int regval_ctr_addvalue( REGVAL_CTR *ctr, char *name, uint16 type, { len = strlen( name ); + /* allocate a slot in the array of pointers */ + if ( ctr->num_values == 0 ) ctr->values = talloc( ctr->ctx, sizeof(REGISTRY_VALUE*) ); else { @@ -312,6 +314,12 @@ int regval_ctr_addvalue( REGVAL_CTR *ctr, char *name, uint16 type, ctr->values = ppreg; } + /* allocate a new valuie and store the pointer in the arrya */ + + ctr->values[ctr->num_values] = talloc( ctr->ctx, sizeof(REGISTRY_VALUE) ); + + /* init the value */ + fstrcpy( ctr->values[ctr->num_values]->valuename, name ); ctr->values[ctr->num_values]->type = type; switch ( type ) -- cgit From e8177d1104c8f7a1035f5c9c340ae5c9b594a729 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 23 Jul 2002 04:55:06 +0000 Subject: * changed structure of REG_R_ENUM_VALUE structure since the BUFFER2 is not and [in/out] buffer * registry value enumeration is working now for the Print\Forms key. The format of the binary data is not quite right yet but all installed forms are listed (This used to be commit 998eb9c7312c3c9a9ed1e9ec294593503c0304bf) --- source3/registry/reg_frontend.c | 405 ++++++++++++++++++++++++++-------------- 1 file changed, 260 insertions(+), 145 deletions(-) (limited to 'source3/registry') diff --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c index d8a10940fd..a282207376 100644 --- a/source3/registry/reg_frontend.c +++ b/source3/registry/reg_frontend.c @@ -37,151 +37,6 @@ REGISTRY_HOOK reg_hooks[] = { }; -/*********************************************************************** - Open the registry database and initialize the REGISTRY_HOOK cache - ***********************************************************************/ - -BOOL init_registry( void ) -{ - int i; - - if ( !init_registry_db() ) { - DEBUG(0,("init_registry: failed to initialize the registry tdb!\n")); - return False; - } - - /* build the cache tree of registry hooks */ - - reghook_cache_init(); - - for ( i=0; reg_hooks[i].keyname; i++ ) { - if ( !reghook_cache_add(®_hooks[i]) ) - return False; - } - - if ( DEBUGLEVEL >= 20 ) - reghook_dump_cache(20); - - return True; -} - - - - -/*********************************************************************** - High level wrapper function for storing registry subkeys - ***********************************************************************/ - -BOOL store_reg_keys( REGISTRY_KEY *key, REGSUBKEY_CTR *subkeys ) -{ - if ( key->hook && key->hook->ops && key->hook->ops->store_subkeys_fn ) - return key->hook->ops->store_subkeys_fn( key->name, subkeys ); - else - return False; - -} - -/*********************************************************************** - High level wrapper function for storing registry values - ***********************************************************************/ - -BOOL store_reg_values( REGISTRY_KEY *key, REGVAL_CTR *val ) -{ - if ( key->hook && key->hook->ops && key->hook->ops->store_values_fn ) - return key->hook->ops->store_values_fn( key->name, val ); - else - return False; -} - - -/*********************************************************************** - High level wrapper function for enumerating registry subkeys - Initialize the TALLOC_CTX if necessary - ***********************************************************************/ - -int fetch_reg_keys( REGISTRY_KEY *key, REGSUBKEY_CTR *subkey_ctr ) -{ - int result = -1; - - if ( key->hook && key->hook->ops && key->hook->ops->subkey_fn ) - result = key->hook->ops->subkey_fn( key->name, subkey_ctr ); - - return result; -} - -/*********************************************************************** - retreive a specific subkey specified by index. Caller is - responsible for freeing memory - ***********************************************************************/ - -BOOL fetch_reg_keys_specific( REGISTRY_KEY *key, char** subkey, uint32 key_index ) -{ - char *s; - REGSUBKEY_CTR ctr; - - ZERO_STRUCTP( &ctr ); - - regsubkey_ctr_init( &ctr ); - - if ( fetch_reg_keys( key, &ctr) == -1 ) - return False; - - if ( !(s = regsubkey_ctr_specific_key( &ctr, key_index )) ) - return False; - - *subkey = strdup( s ); - - regsubkey_ctr_destroy( &ctr ); - - return True; -} - - -/*********************************************************************** - High level wrapper function for enumerating registry values - Initialize the TALLOC_CTX if necessary - ***********************************************************************/ - -int fetch_reg_values( REGISTRY_KEY *key, REGVAL_CTR *val ) -{ - int result = -1; - - if ( key->hook && key->hook->ops && key->hook->ops->value_fn ) - result = key->hook->ops->value_fn( key->name, val ); - - return result; -} - -/*********************************************************************** - Utility function for splitting the base path of a registry path off - by setting base and new_path to the apprapriate offsets withing the - path. - - WARNING!! Does modify the original string! - ***********************************************************************/ - -BOOL reg_split_path( char *path, char **base, char **new_path ) -{ - char *p; - - *new_path = *base = NULL; - - if ( !path) - return False; - - *base = path; - - p = strchr( path, '\\' ); - - if ( p ) { - *p = '\0'; - *new_path = p+1; - } - - return True; -} - - /* * Utility functions for REGSUBKEY_CTR */ @@ -209,6 +64,8 @@ int regsubkey_ctr_addkey( REGSUBKEY_CTR *ctr, char *keyname ) { len = strlen( keyname ); + /* allocate a space for the char* in the array */ + if ( ctr->subkeys == 0 ) ctr->subkeys = talloc( ctr->ctx, sizeof(char*) ); else { @@ -217,6 +74,8 @@ int regsubkey_ctr_addkey( REGSUBKEY_CTR *ctr, char *keyname ) ctr->subkeys = pp; } + /* allocate the string and save it in the array */ + ctr->subkeys[ctr->num_subkeys] = talloc( ctr->ctx, len+1 ); strncpy( ctr->subkeys[ctr->num_subkeys], keyname, len+1 ); ctr->num_subkeys++; @@ -282,6 +141,88 @@ int regval_ctr_numvals( REGVAL_CTR *ctr ) return ctr->num_values; } +/*********************************************************************** + allocate memory for and duplicate a REGISTRY_VALUE. + This is malloc'd memory so the caller should free it when done + **********************************************************************/ + +REGISTRY_VALUE* dup_registry_value( REGISTRY_VALUE *val ) +{ + REGISTRY_VALUE *copy = NULL; + BOOL fail = True; + + if ( !val ) + return NULL; + + if ( !(copy = malloc( sizeof(REGISTRY_VALUE) )) ) { + DEBUG(0,("dup_registry_value: malloc() failed!\n")); + return NULL; + } + + /* copy all the non-pointer initial data */ + + memcpy( copy, val, sizeof(REGISTRY_VALUE) ); + + switch ( val->type ) { + case REG_SZ: + if ( !(copy->data.string = strdup( val->data.string )) ) { + DEBUG(0,("dup_registry_value: strdup() failed for [%s]!\n", + val->data.string)); + goto done; + } + break; + + case REG_DWORD: + /* nothing to be done; already copied by memcpy() */ + break; + + case REG_BINARY: + if ( !(copy->data.string = memdup( val->data.binary, val->size )) ) { + DEBUG(0,("dup_registry_value: memdup() failed for [%d] bytes!\n", + val->size)); + goto done; + } + break; + } + + fail = False; + +done: + if ( fail ) + SAFE_FREE( copy ); + + return copy; +} + +/********************************************************************** + free the memory allocated to a REGISTRY_VALUE + *********************************************************************/ + +void free_registry_value( REGISTRY_VALUE *val ) +{ + if ( !val ) + return; + + switch ( val->type ) + { + case REG_SZ: + SAFE_FREE( val->data.string ); + break; + case REG_BINARY: + SAFE_FREE( val->data.binary ); + break; + } + + SAFE_FREE( val ); + + return; +} + +/*********************************************************************** + Retreive a pointer to a specific value. Caller shoud dup the structure + since this memory may go away with a regval_ctr_destroy() + **********************************************************************/ + REGISTRY_VALUE* regval_ctr_specific_value( REGVAL_CTR *ctr, uint32 idx ) { if ( !(idx < ctr->num_values) ) @@ -354,3 +295,177 @@ void regval_ctr_destroy( REGVAL_CTR *ctr ) } } +/*********************************************************************** + Open the registry database and initialize the REGISTRY_HOOK cache + ***********************************************************************/ + +BOOL init_registry( void ) +{ + int i; + + if ( !init_registry_db() ) { + DEBUG(0,("init_registry: failed to initialize the registry tdb!\n")); + return False; + } + + /* build the cache tree of registry hooks */ + + reghook_cache_init(); + + for ( i=0; reg_hooks[i].keyname; i++ ) { + if ( !reghook_cache_add(®_hooks[i]) ) + return False; + } + + if ( DEBUGLEVEL >= 20 ) + reghook_dump_cache(20); + + return True; +} + + + + +/*********************************************************************** + High level wrapper function for storing registry subkeys + ***********************************************************************/ + +BOOL store_reg_keys( REGISTRY_KEY *key, REGSUBKEY_CTR *subkeys ) +{ + if ( key->hook && key->hook->ops && key->hook->ops->store_subkeys_fn ) + return key->hook->ops->store_subkeys_fn( key->name, subkeys ); + else + return False; + +} + +/*********************************************************************** + High level wrapper function for storing registry values + ***********************************************************************/ + +BOOL store_reg_values( REGISTRY_KEY *key, REGVAL_CTR *val ) +{ + if ( key->hook && key->hook->ops && key->hook->ops->store_values_fn ) + return key->hook->ops->store_values_fn( key->name, val ); + else + return False; +} + + +/*********************************************************************** + High level wrapper function for enumerating registry subkeys + Initialize the TALLOC_CTX if necessary + ***********************************************************************/ + +int fetch_reg_keys( REGISTRY_KEY *key, REGSUBKEY_CTR *subkey_ctr ) +{ + int result = -1; + + if ( key->hook && key->hook->ops && key->hook->ops->subkey_fn ) + result = key->hook->ops->subkey_fn( key->name, subkey_ctr ); + + return result; +} + +/*********************************************************************** + retreive a specific subkey specified by index. Caller is + responsible for freeing memory + ***********************************************************************/ + +BOOL fetch_reg_keys_specific( REGISTRY_KEY *key, char** subkey, uint32 key_index ) +{ + char *s; + REGSUBKEY_CTR ctr; + + ZERO_STRUCTP( &ctr ); + + regsubkey_ctr_init( &ctr ); + + if ( fetch_reg_keys( key, &ctr) == -1 ) + return False; + + if ( !(s = regsubkey_ctr_specific_key( &ctr, key_index )) ) + return False; + + *subkey = strdup( s ); + + regsubkey_ctr_destroy( &ctr ); + + return True; +} + + +/*********************************************************************** + High level wrapper function for enumerating registry values + Initialize the TALLOC_CTX if necessary + ***********************************************************************/ + +int fetch_reg_values( REGISTRY_KEY *key, REGVAL_CTR *val ) +{ + int result = -1; + + if ( key->hook && key->hook->ops && key->hook->ops->value_fn ) + result = key->hook->ops->value_fn( key->name, val ); + + return result; +} + + +/*********************************************************************** + retreive a specific subkey specified by index. Caller is + responsible for freeing memory + ***********************************************************************/ + +BOOL fetch_reg_values_specific( REGISTRY_KEY *key, REGISTRY_VALUE **val, uint32 key_index ) +{ + REGVAL_CTR ctr; + REGISTRY_VALUE *v; + + ZERO_STRUCTP( &ctr ); + + regval_ctr_init( &ctr ); + + if ( fetch_reg_values( key, &ctr) == -1 ) + return False; + + if ( !(v = regval_ctr_specific_value( &ctr, key_index )) ) + return False; + + *val = dup_registry_value( v ); + + regval_ctr_destroy( &ctr ); + + return True; +} + +/*********************************************************************** + Utility function for splitting the base path of a registry path off + by setting base and new_path to the apprapriate offsets withing the + path. + + WARNING!! Does modify the original string! + ***********************************************************************/ + +BOOL reg_split_path( char *path, char **base, char **new_path ) +{ + char *p; + + *new_path = *base = NULL; + + if ( !path) + return False; + + *base = path; + + p = strchr( path, '\\' ); + + if ( p ) { + *p = '\0'; + *new_path = p+1; + } + + return True; +} + + + -- cgit From 5b513407c21e6e77d495fafa49a7a5d380087667 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 23 Jul 2002 05:07:40 +0000 Subject: * fix to display correct form information in REG_BINARY information This should be 8 x uint32 (not 7. I'm guessing the 2nd to the last uint32 is the index number for the form? Not that big a deal I don't think. (This used to be commit 88f0e68bc631f1a0032056bc6c7b9213e8a15be8) --- source3/registry/reg_printing.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'source3/registry') diff --git a/source3/registry/reg_printing.c b/source3/registry/reg_printing.c index 993d793c1e..f4c1feb281 100644 --- a/source3/registry/reg_printing.c +++ b/source3/registry/reg_printing.c @@ -121,7 +121,8 @@ static int print_subpath_forms( char *key, REGSUBKEY_CTR *subkeys ) static int print_subpath_values_forms( char *key, REGVAL_CTR *val ) { int num_values = 0; - uint32 data[7]; + uint32 data[8]; + int form_index = 1; DEBUG(10,("print_values_forms: key=>[%s]\n", key ? key : "NULL" )); @@ -145,13 +146,14 @@ static int print_subpath_values_forms( char *key, REGVAL_CTR *val ) { form = &forms_list[i]; - data[0] = form->flag; - data[1] = form->width; - data[2] = form->length; - data[3] = form->left; - data[4] = form->top; - data[5] = form->right; - data[6] = form->bottom; + data[0] = form->width; + data[1] = form->length; + data[2] = form->left; + data[3] = form->top; + data[4] = form->right; + data[5] = form->bottom; + data[6] = form_index++; + data[7] = form->flag; regval_ctr_addvalue( val, form->name, REG_BINARY, (char*)data, sizeof(data) ); @@ -172,16 +174,16 @@ static int print_subpath_values_forms( char *key, REGVAL_CTR *val ) { form = &forms_list[i]; - data[0] = form->flag; - data[1] = form->width; - data[2] = form->length; - data[3] = form->left; - data[4] = form->top; - data[5] = form->right; - data[6] = form->bottom; - + data[0] = form->width; + data[1] = form->length; + data[2] = form->left; + data[3] = form->top; + data[4] = form->right; + data[5] = form->bottom; + data[6] = form_index++; + data[7] = form->flag; + regval_ctr_addvalue( val, form->name, REG_BINARY, (char*)data, sizeof(data) ); - } SAFE_FREE( forms_list ); -- cgit From c808cc3643f06c72f870d0b14a37c7a46627e2fa Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 24 Jul 2002 06:42:09 +0000 Subject: several changes in this checkin * added REG_OPEN_HKCR for supporting regedit.exe * All data n a REGISTRY_VALUE is stored to a pointer now * fixed REG_INFO to correctly display data when double clicking on and entry in the registry editor * Will now enumerate installed driver_info_3 data * fixed numerous bugs related to pointer offsets, memory issues, etc.. in the registry routines * added a simple caching mechanism to fetch_reg_[keys|values]_specific() All that is left now is to enumerate PrinterData and I will have finished what I started out to do.... (This used to be commit 419d7208e8384e4ad2c4dd328ad5e630971bc76c) --- source3/registry/reg_db.c | 9 ++ source3/registry/reg_frontend.c | 138 ++++++++++++--------- source3/registry/reg_printing.c | 258 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 346 insertions(+), 59 deletions(-) (limited to 'source3/registry') diff --git a/source3/registry/reg_db.c b/source3/registry/reg_db.c index 714e14e48b..773a4f7fb5 100644 --- a/source3/registry/reg_db.c +++ b/source3/registry/reg_db.c @@ -106,6 +106,12 @@ static BOOL init_registry_data( void ) if ( !regdb_store_reg_keys( keyname, &subkeys ) ) return False; + /* HKEY_CLASSES_ROOT*/ + + pstrcpy( keyname, KEY_HKCR ); + if ( !regdb_store_reg_keys( keyname, &subkeys ) ) + return False; + return True; } @@ -233,6 +239,7 @@ int regdb_fetch_reg_keys( char* key, REGSUBKEY_CTR *ctr ) int i; fstring subkeyname; + DEBUG(10,("regdb_fetch_reg_keys: Enter key => [%s]\n", key ? key : "NULL")); pstrcpy( path, key ); @@ -258,6 +265,8 @@ int regdb_fetch_reg_keys( char* key, REGSUBKEY_CTR *ctr ) SAFE_FREE( dbuf.dptr ); + DEBUG(10,("regdb_fetch_reg_keys: Exit [%d] items\n", num_items)); + return num_items; } diff --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c index a282207376..db612709d1 100644 --- a/source3/registry/reg_frontend.c +++ b/source3/registry/reg_frontend.c @@ -149,7 +149,6 @@ int regval_ctr_numvals( REGVAL_CTR *ctr ) REGISTRY_VALUE* dup_registry_value( REGISTRY_VALUE *val ) { REGISTRY_VALUE *copy = NULL; - BOOL fail = True; if ( !val ) return NULL; @@ -162,35 +161,15 @@ REGISTRY_VALUE* dup_registry_value( REGISTRY_VALUE *val ) /* copy all the non-pointer initial data */ memcpy( copy, val, sizeof(REGISTRY_VALUE) ); + if ( val->data_p ) + { + if ( !(copy->data_p = memdup( val->data_p, val->size )) ) { + DEBUG(0,("dup_registry_value: memdup() failed for [%d] bytes!\n", + val->size)); + SAFE_FREE( copy ); + } + } - switch ( val->type ) { - case REG_SZ: - if ( !(copy->data.string = strdup( val->data.string )) ) { - DEBUG(0,("dup_registry_value: strdup() failed for [%s]!\n", - val->data.string)); - goto done; - } - break; - - case REG_DWORD: - /* nothing to be done; already copied by memcpy() */ - break; - - case REG_BINARY: - if ( !(copy->data.string = memdup( val->data.binary, val->size )) ) { - DEBUG(0,("dup_registry_value: memdup() failed for [%d] bytes!\n", - val->size)); - goto done; - } - break; - } - - fail = False; - -done: - if ( fail ) - SAFE_FREE( copy ); - return copy; } @@ -203,16 +182,7 @@ void free_registry_value( REGISTRY_VALUE *val ) if ( !val ) return; - switch ( val->type ) - { - case REG_SZ: - SAFE_FREE( val->data.string ); - break; - case REG_BINARY: - SAFE_FREE( val->data.binary ); - break; - } - + SAFE_FREE( val->data_p ); SAFE_FREE( val ); return; @@ -263,19 +233,26 @@ int regval_ctr_addvalue( REGVAL_CTR *ctr, char *name, uint16 type, fstrcpy( ctr->values[ctr->num_values]->valuename, name ); ctr->values[ctr->num_values]->type = type; + ctr->values[ctr->num_values]->data_p = talloc_memdup( ctr->ctx, data_p, size ); + ctr->values[ctr->num_values]->size = size; +#if 0 switch ( type ) { case REG_SZ: ctr->values[ctr->num_values]->data.string = talloc_strdup( ctr->ctx, data_p ); break; + case REG_MULTI_SZ: + ctr->values[ctr->num_values]->data.string = talloc_memdup( ctr->ctx, data_p, size ); + break; case REG_DWORD: + ctr->values[ctr->num_values]->data.dword = *(uint32*)data_p; break; case REG_BINARY: ctr->values[ctr->num_values]->data.binary = talloc_memdup( ctr->ctx, data_p, size ); break; } - ctr->values[ctr->num_values]->size = size; +#endif ctr->num_values++; } @@ -374,23 +351,46 @@ int fetch_reg_keys( REGISTRY_KEY *key, REGSUBKEY_CTR *subkey_ctr ) BOOL fetch_reg_keys_specific( REGISTRY_KEY *key, char** subkey, uint32 key_index ) { + static REGSUBKEY_CTR ctr; + static pstring save_path; + static BOOL ctr_init = False; char *s; - REGSUBKEY_CTR ctr; - ZERO_STRUCTP( &ctr ); + *subkey = NULL; - regsubkey_ctr_init( &ctr ); + /* simple caching for performance; very basic heuristic */ - if ( fetch_reg_keys( key, &ctr) == -1 ) - return False; + if ( !ctr_init ) { + DEBUG(8,("fetch_reg_keys_specific: Initializing cache of subkeys for [%s]\n", key->name)); + ZERO_STRUCTP( &ctr ); + regsubkey_ctr_init( &ctr ); + + pstrcpy( save_path, key->name ); + + if ( fetch_reg_keys( key, &ctr) == -1 ) + return False; + + ctr_init = True; + } + /* clear the cache when key_index == 0 or the path has changed */ + else if ( !key_index || StrCaseCmp( save_path, key->name) ) { + DEBUG(8,("fetch_reg_keys_specific: Updating cache of subkeys for [%s]\n", key->name)); + + regsubkey_ctr_destroy( &ctr ); + regsubkey_ctr_init( &ctr ); + + pstrcpy( save_path, key->name ); + + if ( fetch_reg_keys( key, &ctr) == -1 ) + return False; + } + if ( !(s = regsubkey_ctr_specific_key( &ctr, key_index )) ) return False; *subkey = strdup( s ); - regsubkey_ctr_destroy( &ctr ); - return True; } @@ -416,25 +416,49 @@ int fetch_reg_values( REGISTRY_KEY *key, REGVAL_CTR *val ) responsible for freeing memory ***********************************************************************/ -BOOL fetch_reg_values_specific( REGISTRY_KEY *key, REGISTRY_VALUE **val, uint32 key_index ) +BOOL fetch_reg_values_specific( REGISTRY_KEY *key, REGISTRY_VALUE **val, uint32 val_index ) { - REGVAL_CTR ctr; - REGISTRY_VALUE *v; + static REGVAL_CTR ctr; + static pstring save_path; + static BOOL ctr_init = False; + REGISTRY_VALUE *v; - ZERO_STRUCTP( &ctr ); + *val = NULL; - regval_ctr_init( &ctr ); + /* simple caching for performance; very basic heuristic */ - if ( fetch_reg_values( key, &ctr) == -1 ) - return False; + if ( !ctr_init ) { + DEBUG(8,("fetch_reg_values_specific: Initializing cache of values for [%s]\n", key->name)); - if ( !(v = regval_ctr_specific_value( &ctr, key_index )) ) + ZERO_STRUCTP( &ctr ); + regval_ctr_init( &ctr ); + + pstrcpy( save_path, key->name ); + + if ( fetch_reg_values( key, &ctr) == -1 ) + return False; + + ctr_init = True; + } + /* clear the cache when val_index == 0 or the path has changed */ + else if ( !val_index || StrCaseCmp(save_path, key->name) ) { + + DEBUG(8,("fetch_reg_values_specific: Updating cache of values for [%s]\n", key->name)); + + regval_ctr_destroy( &ctr ); + regval_ctr_init( &ctr ); + + pstrcpy( save_path, key->name ); + + if ( fetch_reg_values( key, &ctr) == -1 ) + return False; + } + + if ( !(v = regval_ctr_specific_value( &ctr, val_index )) ) return False; *val = dup_registry_value( v ); - regval_ctr_destroy( &ctr ); - return True; } diff --git a/source3/registry/reg_printing.c b/source3/registry/reg_printing.c index f4c1feb281..d8e0f18953 100644 --- a/source3/registry/reg_printing.c +++ b/source3/registry/reg_printing.c @@ -84,18 +84,270 @@ static char* trim_reg_path( char *path ) static int print_subpath_environments( char *key, REGSUBKEY_CTR *subkeys ) { + char *environments[] = { + "Windows 4.0", + "Windows NT x86", + "Windows NT R4000", + "Windows NT Alpha_AXP", + "Windows NT PowerPC", + NULL }; + fstring *drivers = NULL; + int i, env_index, num_drivers; + BOOL valid_env = False; + char *base, *new_path; + char *keystr; + char *key2 = NULL; + int num_subkeys = -1; + DEBUG(10,("print_subpath_environments: key=>[%s]\n", key ? key : "NULL" )); + /* listed architectures of installed drivers */ + + if ( !key ) + { + /* Windows 9x drivers */ + + if ( get_ntdrivers( &drivers, environments[0], 0 ) ) + regsubkey_ctr_addkey( subkeys, environments[0] ); + SAFE_FREE( drivers ); + + /* Windows NT/2k intel drivers */ + + if ( get_ntdrivers( &drivers, environments[1], 2 ) + || get_ntdrivers( &drivers, environments[1], 3 ) ) + { + regsubkey_ctr_addkey( subkeys, environments[1] ); + } + SAFE_FREE( drivers ); + + /* Windows NT 4.0; non-intel drivers */ + for ( i=2; environments[i]; i++ ) { + if ( get_ntdrivers( &drivers, environments[i], 2 ) ) + regsubkey_ctr_addkey( subkeys, environments[i] ); + + } + SAFE_FREE( drivers ); + + num_subkeys = regsubkey_ctr_numkeys( subkeys ); + goto done; + } + + /* we are dealing with a subkey of "Environments */ + + key2 = strdup( key ); + keystr = key2; + reg_split_path( keystr, &base, &new_path ); + + /* sanity check */ + + for ( env_index=0; environments[env_index]; env_index++ ) { + if ( StrCaseCmp( environments[env_index], base ) == 0 ) { + valid_env = True; + break; + } + } + + if ( !valid_env ) + return -1; + + /* enumerate driver versions; environment is environments[env_index] */ + + if ( !new_path ) { + switch ( env_index ) { + case 0: /* Win9x */ + if ( get_ntdrivers( &drivers, environments[0], 0 ) ) { + regsubkey_ctr_addkey( subkeys, "0" ); + SAFE_FREE( drivers ); + } + break; + case 1: /* Windows NT/2k - intel */ + if ( get_ntdrivers( &drivers, environments[1], 2 ) ) { + regsubkey_ctr_addkey( subkeys, "2" ); + SAFE_FREE( drivers ); + } + if ( get_ntdrivers( &drivers, environments[1], 3 ) ) { + regsubkey_ctr_addkey( subkeys, "3" ); + SAFE_FREE( drivers ); + } + break; + default: /* Windows NT - nonintel */ + if ( get_ntdrivers( &drivers, environments[env_index], 2 ) ) { + regsubkey_ctr_addkey( subkeys, "2" ); + SAFE_FREE( drivers ); + } + + } + + num_subkeys = regsubkey_ctr_numkeys( subkeys ); + goto done; + } + + /* we finally get to enumerate the drivers */ + + keystr = new_path; + reg_split_path( keystr, &base, &new_path ); + + if ( !new_path ) { + num_drivers = get_ntdrivers( &drivers, environments[env_index], atoi(base) ); + for ( i=0; i\\ + *********************************************************************/ + +static int print_subpath_values_environments( char *key, REGVAL_CTR *val ) +{ + char *keystr; + char *key2 = NULL; + char *base, *new_path; + fstring env; + fstring driver; + int version; + NT_PRINTER_DRIVER_INFO_LEVEL driver_ctr; + NT_PRINTER_DRIVER_INFO_LEVEL_3 *info3; + WERROR w_result; + char *buffer = NULL; + char *buffer2 = NULL; + int buffer_size = 0; + int i, length; + char *filename; + + DEBUG(8,("print_subpath_values_environments: Enter key => [%s]\n", key ? key : "NULL")); + if ( !key ) + return 0; + + /* + * The only key below KEY_PRINTING\Environments that + * posseses values is each specific printer driver + * First get the arch, version, & driver name + */ + + /* env */ + + key2 = strdup( key ); + keystr = key2; + reg_split_path( keystr, &base, &new_path ); + if ( !base || !new_path ) + return 0; + fstrcpy( env, base ); + + /* version */ + + keystr = new_path; + reg_split_path( keystr, &base, &new_path ); + if ( !base || !new_path ) + return 0; + version = atoi( base ); + + /* printer driver name */ + + keystr = new_path; + reg_split_path( keystr, &base, &new_path ); + /* new_path should be NULL here since this must be the last key */ + if ( !base || new_path ) + return 0; + fstrcpy( driver, base ); + + w_result = get_a_printer_driver( &driver_ctr, 3, driver, env, version ); + + if ( !W_ERROR_IS_OK(w_result) ) + return -1; + + /* build the values out of the driver information */ + info3 = driver_ctr.info_3; + + filename = dos_basename( info3->driverpath ); + regval_ctr_addvalue( val, "Driver", REG_SZ, filename, strlen(filename)+1 ); + filename = dos_basename( info3->configfile ); + regval_ctr_addvalue( val, "Configuration File", REG_SZ, filename, strlen(filename)+1 ); + filename = dos_basename( info3->datafile ); + regval_ctr_addvalue( val, "Data File", REG_SZ, filename, strlen(filename)+1 ); + filename = dos_basename( info3->helpfile ); + regval_ctr_addvalue( val, "Help File", REG_SZ, filename, strlen(filename)+1 ); + + regval_ctr_addvalue( val, "Data Type", REG_SZ, info3->defaultdatatype, strlen(info3->defaultdatatype)+1 ); + + regval_ctr_addvalue( val, "Version", REG_DWORD, (char*)&info3->cversion, sizeof(info3->cversion) ); + + if ( info3->dependentfiles ) { - /* listed architectures of installed drivers */ + /* place the list of dependent files in a single + character buffer, separating each file name by + a NULL */ + + for ( i=0; strcmp(info3->dependentfiles[i], ""); i++ ) + { + /* strip the path to only the file's base name */ + + filename = dos_basename( info3->dependentfiles[i] ); + + length = strlen(filename); + + buffer2 = Realloc( buffer, buffer_size + length + 1 ); + if ( !buffer2 ) + break; + buffer = buffer2; + + memcpy( buffer+buffer_size, filename, length+1 ); + buffer_size += length + 1; + } + + /* terminated by double NULL. Add the final one here */ + + buffer2 = Realloc( buffer, buffer_size + 1 ); + if ( !buffer2 ) { + SAFE_FREE( buffer ); + buffer_size = 0; + } + else { + buffer = buffer2; + buffer[buffer_size++] = '\0'; + } } + regval_ctr_addvalue( val, "Dependent Files", REG_MULTI_SZ, buffer, buffer_size ); - return 0; + free_a_printer_driver( driver_ctr, 3 ); + SAFE_FREE( key2 ); + SAFE_FREE( buffer ); + + DEBUG(8,("print_subpath_values_environments: Exit\n")); + + return regval_ctr_numvals( val ); } + /********************************************************************** handle enumeration of subkeys below KEY_PRINTING\Forms Really just a stub function, but left here in case it needs to @@ -263,6 +515,8 @@ static int handle_printing_subpath( char *key, REGSUBKEY_CTR *subkeys, REGVAL_CT case KEY_INDEX_ENVIR: if ( subkeys ) print_subpath_environments( p, subkeys ); + if ( val ) + print_subpath_values_environments( p, val ); break; case KEY_INDEX_FORMS: -- cgit From a12ed7f506263c6ec34c7df6bbcb3e8434841403 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 24 Jul 2002 08:58:03 +0000 Subject: done! printer_info_2, devicemode, sec_desc, & printer data all enumerate and display correctly in regedit.exe. Not sure about REG_SZ values in PrinterDriverData. If we store these in UNICODE, I'll have to fix up a few things. REG_BINARY & REG_DWORD are fine. (This used to be commit 2a30c243ec28734bbc721dfc01b743faa6f73788) --- source3/registry/reg_frontend.c | 33 +++----- source3/registry/reg_printing.c | 178 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 188 insertions(+), 23 deletions(-) (limited to 'source3/registry') diff --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c index db612709d1..c0788c1b75 100644 --- a/source3/registry/reg_frontend.c +++ b/source3/registry/reg_frontend.c @@ -202,7 +202,19 @@ REGISTRY_VALUE* regval_ctr_specific_value( REGVAL_CTR *ctr, uint32 idx ) } /*********************************************************************** - Ad a new regostry value to the array + Retrive the TALLOC_CTX associated with a REGISTRY_VALUE + **********************************************************************/ + +TALLOC_CTX* regval_ctr_getctx( REGVAL_CTR *val ) +{ + if ( !val ) + return NULL; + + return val->ctx; +} + +/*********************************************************************** + Add a new regostry value to the array **********************************************************************/ int regval_ctr_addvalue( REGVAL_CTR *ctr, char *name, uint16 type, @@ -235,25 +247,6 @@ int regval_ctr_addvalue( REGVAL_CTR *ctr, char *name, uint16 type, ctr->values[ctr->num_values]->type = type; ctr->values[ctr->num_values]->data_p = talloc_memdup( ctr->ctx, data_p, size ); ctr->values[ctr->num_values]->size = size; -#if 0 - switch ( type ) - { - case REG_SZ: - ctr->values[ctr->num_values]->data.string = talloc_strdup( ctr->ctx, data_p ); - break; - case REG_MULTI_SZ: - ctr->values[ctr->num_values]->data.string = talloc_memdup( ctr->ctx, data_p, size ); - break; - case REG_DWORD: - ctr->values[ctr->num_values]->data.dword = *(uint32*)data_p; - break; - case REG_BINARY: - ctr->values[ctr->num_values]->data.binary = talloc_memdup( ctr->ctx, data_p, size ); - break; - - } -#endif - ctr->num_values++; } diff --git a/source3/registry/reg_printing.c b/source3/registry/reg_printing.c index d8e0f18953..145b8230c9 100644 --- a/source3/registry/reg_printing.c +++ b/source3/registry/reg_printing.c @@ -453,6 +453,11 @@ static int print_subpath_printers( char *key, REGSUBKEY_CTR *subkeys ) int n_services = lp_numservices(); int snum; fstring sname; + int num_subkeys = 0; + char *keystr, *key2 = NULL; + char *base, *new_path; + NT_PRINTER_INFO_LEVEL *printer = NULL; + DEBUG(10,("print_subpath_printers: key=>[%s]\n", key ? key : "NULL" )); @@ -468,13 +473,178 @@ static int print_subpath_printers( char *key, REGSUBKEY_CTR *subkeys ) regsubkey_ctr_addkey( subkeys, sname ); } + + num_subkeys = regsubkey_ctr_numkeys( subkeys ); + goto done; + } + + /* get information for a specific printer */ + + key2 = strdup( key ); + keystr = key2; + reg_split_path( keystr, &base, &new_path ); + + + if ( !new_path ) { + /* sanity check on the printer name */ + if ( !W_ERROR_IS_OK( get_a_printer(&printer, 2, base) ) ) + goto done; + + free_a_printer( &printer, 2 ); + + regsubkey_ctr_addkey( subkeys, "PrinterDriverData" ); + } + + /* no other subkeys below here */ + +done: + SAFE_FREE( key2 ); + return num_subkeys; +} + +/********************************************************************** + handle enumeration of values below KEY_PRINTING\Printers + *********************************************************************/ + +static int print_subpath_values_printers( char *key, REGVAL_CTR *val ) +{ + int num_values = 0; + char *keystr, *key2 = NULL; + char *base, *new_path; + NT_PRINTER_INFO_LEVEL *printer = NULL; + NT_PRINTER_INFO_LEVEL_2 *info2; + DEVICEMODE *devmode; + prs_struct prs; + uint32 offset; + int snum; + int i; + fstring valuename; + uint8 *data; + uint32 type, data_len; + fstring printername; + + /* + * There are tw cases to deal with here + * (1) enumeration of printer_info_2 values + * (2) enumeration of the PrinterDriverData subney + */ + + if ( !key ) { + /* top level key has no values */ + goto done; + } + + key2 = strdup( key ); + keystr = key2; + reg_split_path( keystr, &base, &new_path ); + + fstrcpy( printername, base ); + + if ( !new_path ) + { + /* we are dealing with the printer itself */ + + if ( !W_ERROR_IS_OK( get_a_printer(&printer, 2, printername) ) ) + goto done; + + info2 = printer->info_2; + + + regval_ctr_addvalue( val, "Attributes", REG_DWORD, (char*)&info2->attributes, sizeof(info2->attributes) ); + regval_ctr_addvalue( val, "Priority", REG_DWORD, (char*)&info2->priority, sizeof(info2->attributes) ); + regval_ctr_addvalue( val, "ChangeID", REG_DWORD, (char*)&info2->changeid, sizeof(info2->changeid) ); + regval_ctr_addvalue( val, "Default Priority", REG_DWORD, (char*)&info2->default_priority, sizeof(info2->default_priority) ); + regval_ctr_addvalue( val, "Status", REG_DWORD, (char*)&info2->status, sizeof(info2->status) ); + regval_ctr_addvalue( val, "StartTime", REG_DWORD, (char*)&info2->starttime, sizeof(info2->starttime) ); + regval_ctr_addvalue( val, "UntilTime", REG_DWORD, (char*)&info2->untiltime, sizeof(info2->untiltime) ); + regval_ctr_addvalue( val, "cjobs", REG_DWORD, (char*)&info2->cjobs, sizeof(info2->cjobs) ); + regval_ctr_addvalue( val, "AveragePPM", REG_DWORD, (char*)&info2->averageppm, sizeof(info2->averageppm) ); + + regval_ctr_addvalue( val, "Name", REG_SZ, info2->printername, sizeof(info2->printername)+1 ); + regval_ctr_addvalue( val, "Location", REG_SZ, info2->location, sizeof(info2->location)+1 ); + regval_ctr_addvalue( val, "Comment", REG_SZ, info2->comment, sizeof(info2->comment)+1 ); + regval_ctr_addvalue( val, "Parameters", REG_SZ, info2->parameters, sizeof(info2->parameters)+1 ); + regval_ctr_addvalue( val, "Port", REG_SZ, info2->portname, sizeof(info2->portname)+1 ); + regval_ctr_addvalue( val, "Server", REG_SZ, info2->servername, sizeof(info2->servername)+1 ); + regval_ctr_addvalue( val, "Share", REG_SZ, info2->sharename, sizeof(info2->sharename)+1 ); + regval_ctr_addvalue( val, "Driver", REG_SZ, info2->drivername, sizeof(info2->drivername)+1 ); + regval_ctr_addvalue( val, "Separator File", REG_SZ, info2->sepfile, sizeof(info2->sepfile)+1 ); + regval_ctr_addvalue( val, "Print Processor", REG_SZ, info2->printprocessor, sizeof(info2->printprocessor)+1 ); + + + /* use a prs_struct for converting the devmode and security + descriptor to REG_BIARY */ + + prs_init( &prs, MAX_PDU_FRAG_LEN, regval_ctr_getctx(val), MARSHALL); + + /* stream the device mode */ + + snum = lp_servicenumber(info2->sharename); + if ( (devmode = construct_dev_mode( snum )) != NULL ) + { + if ( spoolss_io_devmode( "devmode", &prs, 0, devmode ) ) { + + offset = prs_offset( &prs ); + + regval_ctr_addvalue( val, "Default Devmode", REG_BINARY, prs_data_p(&prs), offset ); + } + + + } + + prs_mem_clear( &prs ); + prs_set_offset( &prs, 0 ); + + if ( info2->secdesc_buf && info2->secdesc_buf->len ) + { + if ( sec_io_desc("sec_desc", &info2->secdesc_buf->sec, &prs, 0 ) ) { + + offset = prs_offset( &prs ); + + regval_ctr_addvalue( val, "Security", REG_BINARY, prs_data_p(&prs), offset ); + } + } + + + prs_mem_free( &prs ); + free_a_printer( &printer, 2 ); + + num_values = regval_ctr_numvals( val ); + goto done; + } - else + + + keystr = new_path; + reg_split_path( keystr, &base, &new_path ); + + /* here should be no more path components here */ + + if ( new_path || strcmp(base, "PrinterDriverData") ) + goto done; + + /* now enumerate the PrinterDriverData key */ + if ( !W_ERROR_IS_OK( get_a_printer(&printer, 2, printername) ) ) + goto done; + + info2 = printer->info_2; + + + /* iterate over all printer data and fill the regval container */ + + for ( i=0; get_specific_param_by_index(*printer, 2, i, valuename, &data, &type, &data_len); i++ ) { - /* get information for a specific printer */ + regval_ctr_addvalue( val, valuename, type, data, data_len ); } + + free_a_printer( &printer, 2 ); + + num_values = regval_ctr_numvals( val ); + +done: + SAFE_FREE( key2 ); - return regsubkey_ctr_numkeys( subkeys ); + return num_values; } /********************************************************************** @@ -529,6 +699,8 @@ static int handle_printing_subpath( char *key, REGSUBKEY_CTR *subkeys, REGVAL_CT case KEY_INDEX_PRINTER: if ( subkeys ) print_subpath_printers( p, subkeys ); + if ( val ) + print_subpath_values_printers( p, val ); break; /* default case for top level key that has no handler */ -- cgit From f1ed55d9032200eae68fc88bfb464e653497f315 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 24 Jul 2002 19:53:49 +0000 Subject: * fix return code so we don't let a client just open any key it wants (even nonexistent ones). This gets rid of the Scheduling Agent icon. * fix NT_STATUS return code for bad registry path (NT_STATUS_NO_SUCH_FILE) (This used to be commit 915ee5c0ec0467fea23be8f309bcaa085c6ed9dd) --- source3/registry/reg_db.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/registry') diff --git a/source3/registry/reg_db.c b/source3/registry/reg_db.c index 773a4f7fb5..74012263e5 100644 --- a/source3/registry/reg_db.c +++ b/source3/registry/reg_db.c @@ -252,8 +252,8 @@ int regdb_fetch_reg_keys( char* key, REGSUBKEY_CTR *ctr ) buflen = dbuf.dsize; if ( !buf ) { - DEBUG(5,("regdb_fetch_reg_keys: Failed to fetch any subkeys for [%s]\n", key)); - return 0; + DEBUG(5,("regdb_fetch_reg_keys: tdb lookup failed to locate key [%s]\n", key)); + return -1; } len = tdb_unpack( buf, buflen, "d", &num_items); -- cgit From a23e96316ebf5086a27365d4a9fb63b0e4533f6f Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 26 Jul 2002 22:40:06 +0000 Subject: 3 things: * normalize all registry key strings before storing or looking up paths in the registry tdb * return the current buffer size for REG_INFO even when not returning actual data * fix a segfault report by metze on #samba-technical so that the user/group object picker works again (was the "ProductType" key lookup that was failing). (This used to be commit 5640e6cdb213502d95fff33e06eaeed5ce3aeb76) --- source3/registry/reg_db.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/registry') diff --git a/source3/registry/reg_db.c b/source3/registry/reg_db.c index 74012263e5..b4c8f60ccf 100644 --- a/source3/registry/reg_db.c +++ b/source3/registry/reg_db.c @@ -163,7 +163,8 @@ BOOL init_registry_db( void ) fstrings The full path to the registry key is used as database after the - \'s are converted to /'s. + \'s are converted to /'s. Key string is also normalized to UPPER + case. ***********************************************************************/ BOOL regdb_store_reg_keys( char *keyname, REGSUBKEY_CTR *ctr ) @@ -178,6 +179,8 @@ BOOL regdb_store_reg_keys( char *keyname, REGSUBKEY_CTR *ctr ) if ( !keyname ) return False; + strupper_m( keyname ); + /* allocate some initial memory */ buffer = malloc(sizeof(pstring)); @@ -245,6 +248,7 @@ int regdb_fetch_reg_keys( char* key, REGSUBKEY_CTR *ctr ) /* convert to key format */ pstring_sub( path, "\\", "/" ); + strupper_m( path ); dbuf = tdb_fetch_by_string( tdb_reg, path ); -- cgit From 787cd2c1e9e9c873d4067d78fdb02b31894fff93 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 29 Jul 2002 18:06:22 +0000 Subject: hardcode printprocessor name since it is everywhere else (This used to be commit efbfb8ca5415424827f4b01c9e79439ab8cc9b1c) --- source3/registry/reg_printing.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/registry') diff --git a/source3/registry/reg_printing.c b/source3/registry/reg_printing.c index 145b8230c9..3fd3680489 100644 --- a/source3/registry/reg_printing.c +++ b/source3/registry/reg_printing.c @@ -569,7 +569,7 @@ static int print_subpath_values_printers( char *key, REGVAL_CTR *val ) regval_ctr_addvalue( val, "Share", REG_SZ, info2->sharename, sizeof(info2->sharename)+1 ); regval_ctr_addvalue( val, "Driver", REG_SZ, info2->drivername, sizeof(info2->drivername)+1 ); regval_ctr_addvalue( val, "Separator File", REG_SZ, info2->sepfile, sizeof(info2->sepfile)+1 ); - regval_ctr_addvalue( val, "Print Processor", REG_SZ, info2->printprocessor, sizeof(info2->printprocessor)+1 ); + regval_ctr_addvalue( val, "Print Processor", REG_SZ, "winprint", sizeof("winprint")+1 ); /* use a prs_struct for converting the devmode and security -- cgit From 918e681894c5102407a9bfd1790d113cb6926894 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 4 Aug 2002 14:25:32 +0000 Subject: commented out strupper before key check against internal db, it's no good to check for uppercased strings when we store them not uppercased. jerry, this fix is needed to make usrmgr.exe work again. meanwhile we found out that NT_STATUS code may not be appropriate there. In particular it seem that an NT PDC will send back 02 as error (ERRbadfile) not 0xc000000f (NT_STATUS_NO_SUCH_FILE NT) I think further investigation is need to understand which are aprropriate return codes here. (This used to be commit 2ad0e81c8da62b7e15ab3e414b5e15a94fe5de87) --- source3/registry/reg_db.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/registry') diff --git a/source3/registry/reg_db.c b/source3/registry/reg_db.c index b4c8f60ccf..db32568f15 100644 --- a/source3/registry/reg_db.c +++ b/source3/registry/reg_db.c @@ -248,7 +248,7 @@ int regdb_fetch_reg_keys( char* key, REGSUBKEY_CTR *ctr ) /* convert to key format */ pstring_sub( path, "\\", "/" ); - strupper_m( path ); + /*strupper_m( path );*/ dbuf = tdb_fetch_by_string( tdb_reg, path ); -- cgit From 9542ef87c08de135cf3bf91c17c4b28bd8afb3ea Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 6 Aug 2002 10:10:54 +0000 Subject: Back out idra's change (at his request) - the values in the tdb *should* be upper cased already. However, if you created your registry tdb in the very early versions of jerry's patch, you could find that usrmgr doesn't function. Simply delete the registry.tdb, it will be recreated on startup. Andrew Bartlett (This used to be commit 17136a88c326bf338f948a67c92bb048c5a148af) --- source3/registry/reg_db.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/registry') diff --git a/source3/registry/reg_db.c b/source3/registry/reg_db.c index db32568f15..b4c8f60ccf 100644 --- a/source3/registry/reg_db.c +++ b/source3/registry/reg_db.c @@ -248,7 +248,7 @@ int regdb_fetch_reg_keys( char* key, REGSUBKEY_CTR *ctr ) /* convert to key format */ pstring_sub( path, "\\", "/" ); - /*strupper_m( path );*/ + strupper_m( path ); dbuf = tdb_fetch_by_string( tdb_reg, path ); -- cgit From d8d0a4e909cbbddcfba35ff04b9c25382f961939 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 11 Aug 2002 18:19:03 +0000 Subject: Merge of case fixes from APPLIANCE_HEAD. (This used to be commit f8072d964f527dcb9b520ec06c3522524d47644f) --- source3/registry/reg_db.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/registry') diff --git a/source3/registry/reg_db.c b/source3/registry/reg_db.c index b4c8f60ccf..b0917c8f60 100644 --- a/source3/registry/reg_db.c +++ b/source3/registry/reg_db.c @@ -60,7 +60,7 @@ static BOOL init_registry_data( void ) pstrcpy( keyname, KEY_HKLM ); pstrcat( keyname, "/SYSTEM/CurrentControlSet" ); regsubkey_ctr_addkey( &subkeys, "Control" ); - regsubkey_ctr_addkey( &subkeys, "services" ); + regsubkey_ctr_addkey( &subkeys, "Services" ); if ( !regdb_store_reg_keys( keyname, &subkeys )) return False; regsubkey_ctr_destroy( &subkeys ); @@ -81,7 +81,7 @@ static BOOL init_registry_data( void ) regsubkey_ctr_init( &subkeys ); pstrcpy( keyname, KEY_HKLM ); - pstrcat( keyname, "/SYSTEM/CurrentControlSet/services" ); + pstrcat( keyname, "/SYSTEM/CurrentControlSet/Services" ); regsubkey_ctr_addkey( &subkeys, "Netlogon" ); if ( !regdb_store_reg_keys( keyname, &subkeys )) return False; @@ -89,14 +89,14 @@ static BOOL init_registry_data( void ) regsubkey_ctr_init( &subkeys ); pstrcpy( keyname, KEY_HKLM ); - pstrcat( keyname, "/SYSTEM/CurrentControlSet/services/Netlogon" ); - regsubkey_ctr_addkey( &subkeys, "parameters" ); + pstrcat( keyname, "/SYSTEM/CurrentControlSet/Services/Netlogon" ); + regsubkey_ctr_addkey( &subkeys, "Parameters" ); if ( !regdb_store_reg_keys( keyname, &subkeys )) return False; regsubkey_ctr_destroy( &subkeys ); pstrcpy( keyname, KEY_HKLM ); - pstrcat( keyname, "/SYSTEM/CurrentControlSet/services/Netlogon/parameters" ); + pstrcat( keyname, "/SYSTEM/CurrentControlSet/Services/Netlogon/Parameters" ); if ( !regdb_store_reg_keys( keyname, &subkeys )) return False; -- cgit From 4ed429481c6aa2517b8b1615f95900d7db372cd6 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 16 Aug 2002 15:36:37 +0000 Subject: Fairly large change to printing code. * removed support for PHANTOM_DEVMODE printer data * s/NT_PRINTER_PARAM/REGISTRY_VALUE/g - This was a good bit of work. Everything seems stable, but is not complete. * support for printer data keys other than PrinterDriverData in the store and fetch routines. Still needs to be plugged into the XxxPrinterDataEx() calls. Tested against NT4.0 & 2k. Like I said, it's not done, but doesn't crash so it shouldn't upset anyone (unless you're trying to build a Samba printer server off of HEAD). More work to come. Should settle by Monday. jerry (This used to be commit 7ba7c04c0e961618c82c2112b9627af114c6cc42) --- source3/registry/reg_frontend.c | 91 ++++++++++++++++++++++++++++++++++++++++- source3/registry/reg_printing.c | 6 ++- 2 files changed, 93 insertions(+), 4 deletions(-) (limited to 'source3/registry') diff --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c index c0788c1b75..45c1f24001 100644 --- a/source3/registry/reg_frontend.c +++ b/source3/registry/reg_frontend.c @@ -188,6 +188,38 @@ void free_registry_value( REGISTRY_VALUE *val ) return; } +/********************************************************************** + *********************************************************************/ + +uint8* regval_data_p( REGISTRY_VALUE *val ) +{ + return val->data_p; +} + +/********************************************************************** + *********************************************************************/ + +int regval_size( REGISTRY_VALUE *val ) +{ + return val->size; +} + +/********************************************************************** + *********************************************************************/ + +char* regval_name( REGISTRY_VALUE *val ) +{ + return val->valuename; +} + +/********************************************************************** + *********************************************************************/ + +uint32 regval_type( REGISTRY_VALUE *val ) +{ + return val->type; +} + /*********************************************************************** Retreive a pointer to a specific value. Caller shoud dup the structure since this memory may go away with a regval_ctr_destroy() @@ -214,7 +246,7 @@ TALLOC_CTX* regval_ctr_getctx( REGVAL_CTR *val ) } /*********************************************************************** - Add a new regostry value to the array + Add a new registry value to the array **********************************************************************/ int regval_ctr_addvalue( REGVAL_CTR *ctr, char *name, uint16 type, @@ -237,7 +269,7 @@ int regval_ctr_addvalue( REGVAL_CTR *ctr, char *name, uint16 type, ctr->values = ppreg; } - /* allocate a new valuie and store the pointer in the arrya */ + /* allocate a new value and store the pointer in the arrya */ ctr->values[ctr->num_values] = talloc( ctr->ctx, sizeof(REGISTRY_VALUE) ); @@ -253,6 +285,61 @@ int regval_ctr_addvalue( REGVAL_CTR *ctr, char *name, uint16 type, return ctr->num_values; } +/*********************************************************************** + Delete a single value from the registry container. + No need to free memory since it is talloc'd. + **********************************************************************/ + +int regval_ctr_delvalue( REGVAL_CTR *ctr, char *name ) +{ + int i; + + /* search for the value */ + + for ( i=0; inum_values; i++ ) { + if ( strcmp( ctr->values[i]->valuename, name ) == 0) + break; + } + + /* just return if we don't find it */ + + if ( i == ctr->num_values ) + return ctr->num_values; + + /* just shift everything down one */ + + for ( /* use previous i */; i<(ctr->num_values-1); i++ ) + memcpy( ctr->values[i], ctr->values[i+1], sizeof(REGISTRY_VALUE) ); + + /* paranoia */ + + ZERO_STRUCTP( ctr->values[i] ); + + ctr->num_values--; + + return ctr->num_values; +} + +/*********************************************************************** + Delete a single value from the registry container. + No need to free memory since it is talloc'd. + **********************************************************************/ + +REGISTRY_VALUE* regval_ctr_getvalue( REGVAL_CTR *ctr, char *name ) +{ + int i; + + /* search for the value */ + + for ( i=0; inum_values; i++ ) { + if ( strcmp( ctr->values[i]->valuename, name ) == 0) + return ctr->values[i]; + + } + + return NULL; +} + /*********************************************************************** free memory held by a REGVAL_CTR structure **********************************************************************/ diff --git a/source3/registry/reg_printing.c b/source3/registry/reg_printing.c index 3fd3680489..8f53fe9ea5 100644 --- a/source3/registry/reg_printing.c +++ b/source3/registry/reg_printing.c @@ -492,7 +492,7 @@ static int print_subpath_printers( char *key, REGSUBKEY_CTR *subkeys ) free_a_printer( &printer, 2 ); - regsubkey_ctr_addkey( subkeys, "PrinterDriverData" ); + regsubkey_ctr_addkey( subkeys, SPOOL_PRINTERDATA_KEY ); } /* no other subkeys below here */ @@ -620,7 +620,7 @@ static int print_subpath_values_printers( char *key, REGVAL_CTR *val ) /* here should be no more path components here */ - if ( new_path || strcmp(base, "PrinterDriverData") ) + if ( new_path || strcmp(base, SPOOL_PRINTERDATA_KEY) ) goto done; /* now enumerate the PrinterDriverData key */ @@ -632,10 +632,12 @@ static int print_subpath_values_printers( char *key, REGVAL_CTR *val ) /* iterate over all printer data and fill the regval container */ +#if 0 /* JERRY */ for ( i=0; get_specific_param_by_index(*printer, 2, i, valuename, &data, &type, &data_len); i++ ) { regval_ctr_addvalue( val, valuename, type, data, data_len ); } +#endif free_a_printer( &printer, 2 ); -- cgit