From a834a73e341059be154426390304a42e4a011f72 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 25 Sep 2002 15:19:00 +0000 Subject: sync'ing up for 3.0alpha20 release (This used to be commit 65e7b5273bb58802bf0c389b77f7fcae0a1f6139) --- source3/registry/reg_frontend.c | 315 ---------------------------------------- source3/registry/reg_printing.c | 140 ++++++++++-------- 2 files changed, 78 insertions(+), 377 deletions(-) (limited to 'source3/registry') diff --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c index 45c1f240010..a9dfb52f011 100644 --- a/source3/registry/reg_frontend.c +++ b/source3/registry/reg_frontend.c @@ -37,321 +37,6 @@ REGISTRY_HOOK reg_hooks[] = { }; -/* - * 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; - char **pp; - - if ( 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 { - pp = talloc_realloc( ctr->ctx, ctr->subkeys, sizeof(char*)*(ctr->num_subkeys+1) ); - if ( pp ) - 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++; - } - - 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 key_index ) -{ - if ( ! (key_index < ctr->num_subkeys) ) - return NULL; - - return ctr->subkeys[key_index]; -} - -/*********************************************************************** - free memory held by a REGSUBKEY_CTR structure - **********************************************************************/ - -void regsubkey_ctr_destroy( REGSUBKEY_CTR *ctr ) -{ - if ( ctr ) { - talloc_destroy( ctr->ctx ); - ZERO_STRUCTP( ctr ); - } -} - - -/* - * 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; -} - -/*********************************************************************** - 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; - - 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) ); - 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 ); - } - } - - return copy; -} - -/********************************************************************** - free the memory allocated to a REGISTRY_VALUE - *********************************************************************/ - -void free_registry_value( REGISTRY_VALUE *val ) -{ - if ( !val ) - return; - - SAFE_FREE( val->data_p ); - SAFE_FREE( 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() - **********************************************************************/ - -REGISTRY_VALUE* regval_ctr_specific_value( REGVAL_CTR *ctr, uint32 idx ) -{ - if ( !(idx < ctr->num_values) ) - return NULL; - - return ctr->values[idx]; -} - -/*********************************************************************** - 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 registry 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 ); - - /* allocate a slot in the array of pointers */ - - 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; - } - - /* allocate a new value 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; - ctr->values[ctr->num_values]->data_p = talloc_memdup( ctr->ctx, data_p, size ); - ctr->values[ctr->num_values]->size = size; - 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. - **********************************************************************/ - -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 - **********************************************************************/ - -void regval_ctr_destroy( REGVAL_CTR *ctr ) -{ - if ( ctr ) { - talloc_destroy( ctr->ctx ); - ZERO_STRUCTP( ctr ); - } -} - /*********************************************************************** Open the registry database and initialize the REGISTRY_HOOK cache ***********************************************************************/ diff --git a/source3/registry/reg_printing.c b/source3/registry/reg_printing.c index 8f53fe9ea5c..a58a91a0a89 100644 --- a/source3/registry/reg_printing.c +++ b/source3/registry/reg_printing.c @@ -240,6 +240,7 @@ static int print_subpath_values_environments( char *key, REGVAL_CTR *val ) int buffer_size = 0; int i, length; char *filename; + UNISTR2 data;; DEBUG(8,("print_subpath_values_environments: Enter key => [%s]\n", key ? key : "NULL")); @@ -287,15 +288,23 @@ static int print_subpath_values_environments( char *key, REGVAL_CTR *val ) info3 = driver_ctr.info_3; filename = dos_basename( info3->driverpath ); - regval_ctr_addvalue( val, "Driver", REG_SZ, filename, strlen(filename)+1 ); + init_unistr2( &data, filename, strlen(filename)+1 ); + regval_ctr_addvalue( val, "Driver", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) ); + filename = dos_basename( info3->configfile ); - regval_ctr_addvalue( val, "Configuration File", REG_SZ, filename, strlen(filename)+1 ); + init_unistr2( &data, filename, strlen(filename)+1 ); + regval_ctr_addvalue( val, "Configuration File", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) ); + filename = dos_basename( info3->datafile ); - regval_ctr_addvalue( val, "Data File", REG_SZ, filename, strlen(filename)+1 ); + init_unistr2( &data, filename, strlen(filename)+1 ); + regval_ctr_addvalue( val, "Data File", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) ); + 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 ); + init_unistr2( &data, filename, strlen(filename)+1 ); + regval_ctr_addvalue( val, "Help File", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) ); + + init_unistr2( &data, info3->defaultdatatype, strlen(info3->defaultdatatype)+1 ); + regval_ctr_addvalue( val, "Data Type", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) ); regval_ctr_addvalue( val, "Version", REG_DWORD, (char*)&info3->cversion, sizeof(info3->cversion) ); @@ -313,19 +322,20 @@ static int print_subpath_values_environments( char *key, REGVAL_CTR *val ) length = strlen(filename); - buffer2 = Realloc( buffer, buffer_size + length + 1 ); + buffer2 = Realloc( buffer, buffer_size + (length + 1)*sizeof(uint16) ); if ( !buffer2 ) break; buffer = buffer2; + + init_unistr2( &data, filename, length+1 ); + memcpy( buffer+buffer_size, (char*)data.buffer, data.uni_str_len*sizeof(uint16) ); - memcpy( buffer+buffer_size, filename, length+1 ); - - buffer_size += length + 1; + buffer_size += (length + 1)*sizeof(uint16); } /* terminated by double NULL. Add the final one here */ - buffer2 = Realloc( buffer, buffer_size + 1 ); + buffer2 = Realloc( buffer, buffer_size + 2 ); if ( !buffer2 ) { SAFE_FREE( buffer ); buffer_size = 0; @@ -333,12 +343,14 @@ static int print_subpath_values_environments( char *key, REGVAL_CTR *val ) else { buffer = buffer2; buffer[buffer_size++] = '\0'; + buffer[buffer_size++] = '\0'; } } regval_ctr_addvalue( val, "Dependent Files", REG_MULTI_SZ, buffer, buffer_size ); free_a_printer_driver( driver_ctr, 3 ); + SAFE_FREE( key2 ); SAFE_FREE( buffer ); @@ -453,11 +465,12 @@ static int print_subpath_printers( char *key, REGSUBKEY_CTR *subkeys ) int n_services = lp_numservices(); int snum; fstring sname; + int i; int num_subkeys = 0; char *keystr, *key2 = NULL; char *base, *new_path; NT_PRINTER_INFO_LEVEL *printer = NULL; - + fstring *subkey_names = NULL; DEBUG(10,("print_subpath_printers: key=>[%s]\n", key ? key : "NULL" )); @@ -483,22 +496,23 @@ static int print_subpath_printers( char *key, REGSUBKEY_CTR *subkeys ) key2 = strdup( key ); keystr = key2; reg_split_path( keystr, &base, &new_path ); + + if ( !W_ERROR_IS_OK( get_a_printer(&printer, 2, base) ) ) + goto done; + + num_subkeys = get_printer_subkeys( &printer->info_2->data, new_path?new_path:"", &subkey_names ); + for ( i=0; iuntiltime, 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, "winprint", sizeof("winprint")+1 ); + + init_unistr2( &data, info2->printername, strlen(info2->printername)+1 ); + regval_ctr_addvalue( val, "Name", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) ); + init_unistr2( &data, info2->location, strlen(info2->location)+1 ); + regval_ctr_addvalue( val, "Location", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) ); + init_unistr2( &data, info2->comment, strlen(info2->comment)+1 ); + regval_ctr_addvalue( val, "Comment", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) ); + init_unistr2( &data, info2->parameters, strlen(info2->parameters)+1 ); + regval_ctr_addvalue( val, "Parameters", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) ); + init_unistr2( &data, info2->portname, strlen(info2->portname)+1 ); + regval_ctr_addvalue( val, "Port", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) ); + init_unistr2( &data, info2->servername, strlen(info2->servername)+1 ); + regval_ctr_addvalue( val, "Server", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) ); + init_unistr2( &data, info2->sharename, strlen(info2->sharename)+1 ); + regval_ctr_addvalue( val, "Share", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) ); + init_unistr2( &data, info2->drivername, strlen(info2->drivername)+1 ); + regval_ctr_addvalue( val, "Driver", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) ); + init_unistr2( &data, info2->sepfile, strlen(info2->sepfile)+1 ); + regval_ctr_addvalue( val, "Separator File", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) ); + init_unistr2( &data, "winprint", strlen("winprint")+1 ); + regval_ctr_addvalue( val, "Print Processor", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) ); /* use a prs_struct for converting the devmode and security @@ -607,43 +630,36 @@ static int print_subpath_values_printers( char *key, REGVAL_CTR *val ) prs_mem_free( &prs ); - free_a_printer( &printer, 2 ); num_values = regval_ctr_numvals( val ); + goto done; } - - - keystr = new_path; - reg_split_path( keystr, &base, &new_path ); - - /* here should be no more path components here */ - - if ( new_path || strcmp(base, SPOOL_PRINTERDATA_KEY) ) - goto done; - /* now enumerate the PrinterDriverData key */ + /* now enumerate the 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 */ -#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 ); + p_data = &printer->info_2->data; + if ( (key_index = lookup_printerkey( p_data, new_path )) == -1 ) { + DEBUG(10,("print_subpath_values_printer: Unknown keyname [%s]\n", new_path)); + goto done; } -#endif - - free_a_printer( &printer, 2 ); - - num_values = regval_ctr_numvals( val ); + num_values = regval_ctr_numvals( &p_data->keys[key_index].values ); + + for ( i=0; ikeys[key_index].values, i) ); + + done: + if ( printer ) + free_a_printer( &printer, 2 ); + SAFE_FREE( key2 ); return num_values; -- cgit