From 44707ad2e00a91f459e80efbe8f362b5853b0a62 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 29 Aug 2005 14:55:40 +0000 Subject: r9739: conver the reg_objects (REGSUBKEY_CTR & REGVAL_CTR) to use the new talloc() features: Note that the REGSUB_CTR and REGVAL_CTR objects *must* be talloc()'d since the methods use the object pointer as the talloc context for internal private data. There is no longer a regXXX_ctr_intit() and regXXX_ctr_destroy() pair of functions. Simply TALLOC_ZERO_P() and TALLOC_FREE() the object. Also had to convert the printer_info_2->NT_PRINTER_DATA field to be talloc()'d as well. This is just a stop on the road to cleaning up the printer memory management. (This used to be commit ef721333ab9639cb5346067497e99fbd0d4425dd) --- source3/rpc_server/srv_reg_nt.c | 165 ++++++++++++++++++++++------------------ 1 file changed, 92 insertions(+), 73 deletions(-) (limited to 'source3/rpc_server/srv_reg_nt.c') diff --git a/source3/rpc_server/srv_reg_nt.c b/source3/rpc_server/srv_reg_nt.c index feb89be542..8b861f8431 100644 --- a/source3/rpc_server/srv_reg_nt.c +++ b/source3/rpc_server/srv_reg_nt.c @@ -125,7 +125,7 @@ static WERROR open_registry_key(pipes_struct *p, POLICY_HND *hnd, REGISTRY_KEY * { REGISTRY_KEY *regkey = NULL; WERROR result = WERR_OK; - REGSUBKEY_CTR subkeys; + REGSUBKEY_CTR *subkeys = NULL; pstring subkeyname2; int subkey_len; @@ -167,21 +167,25 @@ static WERROR open_registry_key(pipes_struct *p, POLICY_HND *hnd, REGISTRY_KEY * if ( !(regkey->hook = reghook_cache_find( regkey->name )) ) { DEBUG(0,("open_registry_key: Failed to assigned a REGISTRY_HOOK to [%s]\n", regkey->name )); - return WERR_BADFILE; + result = WERR_BADFILE; + goto done; } /* check if the path really exists; failed is indicated by -1 */ /* if the subkey count failed, bail out */ - regsubkey_ctr_init( &subkeys ); - - if ( fetch_reg_keys( regkey, &subkeys ) == -1 ) { + if ( !(subkeys = TALLOC_ZERO_P( p->mem_ctx, REGSUBKEY_CTR )) ) { + result = WERR_NOMEM; + goto done; + } + + if ( fetch_reg_keys( regkey, subkeys ) == -1 ) { result = WERR_BADFILE; goto done; } if ( !create_policy_hnd( p, hnd, free_regkey_info, regkey ) ) { - result = WERR_BADFILE; + result = WERR_BADFILE; goto done; } @@ -192,7 +196,7 @@ static WERROR open_registry_key(pipes_struct *p, POLICY_HND *hnd, REGISTRY_KEY * done: /* clean up */ - regsubkey_ctr_destroy( &subkeys ); + TALLOC_FREE( subkeys ); if ( ! NT_STATUS_IS_OK(result) ) SAFE_FREE( regkey ); @@ -229,31 +233,32 @@ static BOOL get_subkey_information( REGISTRY_KEY *key, uint32 *maxnum, uint32 *m { int num_subkeys, i; uint32 max_len; - REGSUBKEY_CTR subkeys; + REGSUBKEY_CTR *subkeys; uint32 len; if ( !key ) return False; - regsubkey_ctr_init( &subkeys ); - - if ( fetch_reg_keys( key, &subkeys ) == -1 ) + if ( !(subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR )) ) + return False; + + if ( fetch_reg_keys( key, subkeys ) == -1 ) return False; /* find the longest string */ max_len = 0; - num_subkeys = regsubkey_ctr_numkeys( &subkeys ); + num_subkeys = regsubkey_ctr_numkeys( subkeys ); for ( i=0; ivaluename ? strlen(val->valuename)+1 : 0 ); sizemax = MAX(sizemax, val->size ); - val = regval_ctr_specific_value( &values, i ); + val = regval_ctr_specific_value( values, i ); } *maxnum = num_values; *maxlen = lenmax; *maxsize = sizemax; - regval_ctr_destroy( &values ); + TALLOC_FREE( values ); return True; } @@ -400,7 +406,7 @@ WERROR _reg_open_entry(pipes_struct *p, REG_Q_OPEN_ENTRY *q_u, REG_R_OPEN_ENTRY /* check granted access first; what is the correct mask here? */ - if ( !(parent->access_granted & (SEC_RIGHTS_ENUM_SUBKEYS|SEC_RIGHTS_CREATE_SUBKEY)) ) + if ( !(parent->access_granted & (SEC_RIGHTS_ENUM_SUBKEYS|SEC_RIGHTS_CREATE_SUBKEY|SEC_RIGHTS_QUERY_VALUE|SEC_RIGHTS_SET_VALUE)) ) return WERR_ACCESS_DENIED; /* open the key first to get the appropriate REGISTRY_HOOK @@ -435,7 +441,7 @@ WERROR _reg_query_value(pipes_struct *p, REG_Q_QUERY_VALUE *q_u, REG_R_QUERY_VAL fstring name; REGISTRY_KEY *regkey = find_regkey_index_by_hnd( p, &q_u->pol ); REGISTRY_VALUE *val = NULL; - REGVAL_CTR regvals; + REGVAL_CTR *regvals; int i; if ( !regkey ) @@ -447,7 +453,8 @@ WERROR _reg_query_value(pipes_struct *p, REG_Q_QUERY_VALUE *q_u, REG_R_QUERY_VAL DEBUG(5,("reg_info: looking up value: [%s]\n", name)); - regval_ctr_init( ®vals ); + if ( !(regvals = TALLOC_P( p->mem_ctx, REGVAL_CTR )) ) + return WERR_NOMEM; for ( i=0; fetch_reg_values_specific(regkey, &val, i); i++ ) { @@ -463,7 +470,7 @@ WERROR _reg_query_value(pipes_struct *p, REG_Q_QUERY_VALUE *q_u, REG_R_QUERY_VAL init_reg_r_query_value(q_u->ptr_buf, r_u, val, status); - regval_ctr_destroy( ®vals ); + TALLOC_FREE( regvals ); free_registry_value( val ); return status; @@ -774,8 +781,8 @@ static WERROR reg_load_tree( REGF_FILE *regfile, const char *topkeypath, { REGF_NK_REC *subkey; REGISTRY_KEY registry_key; - REGVAL_CTR values; - REGSUBKEY_CTR subkeys; + REGVAL_CTR *values; + REGSUBKEY_CTR *subkeys; int i; pstring path; WERROR result = WERR_OK; @@ -791,13 +798,16 @@ static WERROR reg_load_tree( REGF_FILE *regfile, const char *topkeypath, /* now start parsing the values and subkeys */ - regsubkey_ctr_init( &subkeys ); - regval_ctr_init( &values ); + if ( !(subkeys = TALLOC_ZERO_P( regfile->mem_ctx, REGSUBKEY_CTR )) ) + return WERR_NOMEM; + if ( !(values = TALLOC_ZERO_P( subkeys, REGVAL_CTR )) ) + return WERR_NOMEM; + /* copy values into the REGVAL_CTR */ for ( i=0; inum_values; i++ ) { - regval_ctr_addvalue( &values, key->values[i].valuename, key->values[i].type, + regval_ctr_addvalue( values, key->values[i].valuename, key->values[i].type, key->values[i].data, (key->values[i].data_size & ~VK_DATA_IN_OFFSET) ); } @@ -805,20 +815,19 @@ static WERROR reg_load_tree( REGF_FILE *regfile, const char *topkeypath, key->subkey_index = 0; while ( (subkey = regfio_fetch_subkey( regfile, key )) ) { - regsubkey_ctr_addkey( &subkeys, subkey->keyname ); + regsubkey_ctr_addkey( subkeys, subkey->keyname ); } /* write this key and values out */ - if ( !store_reg_values( ®istry_key, &values ) - || !store_reg_keys( ®istry_key, &subkeys ) ) + if ( !store_reg_values( ®istry_key, values ) + || !store_reg_keys( ®istry_key, subkeys ) ) { DEBUG(0,("reg_load_tree: Failed to load %s!\n", topkeypath)); result = WERR_REG_IO_FAILURE; } - regval_ctr_destroy( &values ); - regsubkey_ctr_destroy( &subkeys ); + TALLOC_FREE( subkeys ); if ( !W_ERROR_IS_OK(result) ) return result; @@ -904,8 +913,8 @@ static WERROR reg_write_tree( REGF_FILE *regfile, const char *keypath, REGF_NK_REC *parent, SEC_DESC *sec_desc ) { REGF_NK_REC *key; - REGVAL_CTR values; - REGSUBKEY_CTR subkeys; + REGVAL_CTR *values; + REGSUBKEY_CTR *subkeys; int i, num_subkeys; pstring key_tmp; char *keyname, *parentpath; @@ -939,24 +948,27 @@ static WERROR reg_write_tree( REGF_FILE *regfile, const char *keypath, /* lookup the values and subkeys */ - regsubkey_ctr_init( &subkeys ); - regval_ctr_init( &values ); - - fetch_reg_keys( ®istry_key, &subkeys ); - fetch_reg_values( ®istry_key, &values ); + if ( !(subkeys = TALLOC_ZERO_P( regfile->mem_ctx, REGSUBKEY_CTR )) ) + return WERR_NOMEM; + + if ( !(values = TALLOC_ZERO_P( subkeys, REGVAL_CTR )) ) + return WERR_NOMEM; + + fetch_reg_keys( ®istry_key, subkeys ); + fetch_reg_values( ®istry_key, values ); /* write out this key */ - if ( !(key = regfio_write_key( regfile, keyname, &values, &subkeys, sec_desc, parent )) ) { + if ( !(key = regfio_write_key( regfile, keyname, values, subkeys, sec_desc, parent )) ) { result = WERR_CAN_NOT_COMPLETE; goto done; } /* write each one of the subkeys out */ - num_subkeys = regsubkey_ctr_numkeys( &subkeys ); + num_subkeys = regsubkey_ctr_numkeys( subkeys ); for ( i=0; ihandle); REGISTRY_KEY *newparent; POLICY_HND newparent_handle; - REGSUBKEY_CTR subkeys; + REGSUBKEY_CTR *subkeys; BOOL write_result; pstring name; WERROR result; @@ -1138,19 +1149,22 @@ WERROR _reg_create_key_ex(pipes_struct *p, REG_Q_CREATE_KEY_EX *q_u, REG_R_CREAT goto done; } - regsubkey_ctr_init( &subkeys ); - + if ( !(subkeys = TALLOC_ZERO_P( p->mem_ctx, REGSUBKEY_CTR )) ) { + result = WERR_NOMEM; + goto done; + } + /* (4) lookup the current keys and add the new one */ - fetch_reg_keys( newparent, &subkeys ); - regsubkey_ctr_addkey( &subkeys, name ); + fetch_reg_keys( newparent, subkeys ); + regsubkey_ctr_addkey( subkeys, name ); /* now write to the registry backend */ - write_result = store_reg_keys( newparent, &subkeys ); - - regsubkey_ctr_destroy( &subkeys ); + write_result = store_reg_keys( newparent, subkeys ); + TALLOC_FREE( subkeys ); + if ( !write_result ) return WERR_REG_IO_FAILURE; @@ -1177,7 +1191,7 @@ done: WERROR _reg_set_value(pipes_struct *p, REG_Q_SET_VALUE *q_u, REG_R_SET_VALUE *r_u) { REGISTRY_KEY *key = find_regkey_index_by_hnd(p, &q_u->handle); - REGVAL_CTR values; + REGVAL_CTR *values; BOOL write_result; fstring valuename; @@ -1198,19 +1212,20 @@ WERROR _reg_set_value(pipes_struct *p, REG_Q_SET_VALUE *q_u, REG_R_SET_VALUE *r DEBUG(8,("_reg_set_value: Setting value for [%s:%s]\n", key->name, valuename)); - regval_ctr_init( &values ); + if ( !(values = TALLOC_ZERO_P( p->mem_ctx, REGVAL_CTR )) ) + return WERR_NOMEM; /* lookup the current values and add the new one */ - fetch_reg_values( key, &values ); + fetch_reg_values( key, values ); - regval_ctr_addvalue( &values, valuename, q_u->type, q_u->value.buffer, q_u->value.buf_len ); + regval_ctr_addvalue( values, valuename, q_u->type, q_u->value.buffer, q_u->value.buf_len ); /* now write to the registry backend */ - write_result = store_reg_values( key, &values ); + write_result = store_reg_values( key, values ); - regval_ctr_destroy( &values ); + TALLOC_FREE( values ); if ( !write_result ) return WERR_REG_IO_FAILURE; @@ -1226,7 +1241,7 @@ WERROR _reg_delete_key(pipes_struct *p, REG_Q_DELETE_KEY *q_u, REG_R_DELETE_KEY REGISTRY_KEY *parent = find_regkey_index_by_hnd(p, &q_u->handle); REGISTRY_KEY *newparent; POLICY_HND newparent_handle; - REGSUBKEY_CTR subkeys; + REGSUBKEY_CTR *subkeys; BOOL write_result; pstring name; WERROR result; @@ -1285,19 +1300,22 @@ WERROR _reg_delete_key(pipes_struct *p, REG_Q_DELETE_KEY *q_u, REG_R_DELETE_KEY goto done; } - regsubkey_ctr_init( &subkeys ); + if ( !(subkeys = TALLOC_ZERO_P( p->mem_ctx, REGSUBKEY_CTR )) ) { + result = WERR_NOMEM; + goto done; + } /* lookup the current keys and delete the new one */ - fetch_reg_keys( newparent, &subkeys ); + fetch_reg_keys( newparent, subkeys ); - regsubkey_ctr_delkey( &subkeys, name ); + regsubkey_ctr_delkey( subkeys, name ); /* now write to the registry backend */ - write_result = store_reg_keys( newparent, &subkeys ); + write_result = store_reg_keys( newparent, subkeys ); - regsubkey_ctr_destroy( &subkeys ); + TALLOC_FREE( subkeys ); result = write_result ? WERR_OK : WERR_REG_IO_FAILURE; @@ -1317,7 +1335,7 @@ done: WERROR _reg_delete_value(pipes_struct *p, REG_Q_DELETE_VALUE *q_u, REG_R_DELETE_VALUE *r_u) { REGISTRY_KEY *key = find_regkey_index_by_hnd(p, &q_u->handle); - REGVAL_CTR values; + REGVAL_CTR *values; BOOL write_result; fstring valuename; @@ -1336,19 +1354,20 @@ WERROR _reg_delete_value(pipes_struct *p, REG_Q_DELETE_VALUE *q_u, REG_R_DELETE DEBUG(8,("_reg_delete_value: Setting value for [%s:%s]\n", key->name, valuename)); - regval_ctr_init( &values ); + if ( !(values = TALLOC_ZERO_P( p->mem_ctx, REGVAL_CTR )) ) + return WERR_NOMEM; /* lookup the current values and add the new one */ - fetch_reg_values( key, &values ); + fetch_reg_values( key, values ); - regval_ctr_delvalue( &values, valuename ); + regval_ctr_delvalue( values, valuename ); /* now write to the registry backend */ - write_result = store_reg_values( key, &values ); + write_result = store_reg_values( key, values ); - regval_ctr_destroy( &values ); + TALLOC_FREE( values ); if ( !write_result ) return WERR_REG_IO_FAILURE; -- cgit