summaryrefslogtreecommitdiff
path: root/source3/utils
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2005-08-29 14:55:40 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:03:25 -0500
commit44707ad2e00a91f459e80efbe8f362b5853b0a62 (patch)
tree438124f4550315df722d959891b66e669222f8e8 /source3/utils
parent77670a2ec33275ae08a37606ee15bf0170b7fcb3 (diff)
downloadsamba-44707ad2e00a91f459e80efbe8f362b5853b0a62.tar.gz
samba-44707ad2e00a91f459e80efbe8f362b5853b0a62.tar.bz2
samba-44707ad2e00a91f459e80efbe8f362b5853b0a62.zip
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)
Diffstat (limited to 'source3/utils')
-rw-r--r--source3/utils/net_rpc_printer.c37
-rw-r--r--source3/utils/net_rpc_registry.c26
-rw-r--r--source3/utils/profiles.c26
3 files changed, 53 insertions, 36 deletions
diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c
index 6194f40b09..e82db46b9f 100644
--- a/source3/utils/net_rpc_printer.c
+++ b/source3/utils/net_rpc_printer.c
@@ -2159,7 +2159,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const
BOOL got_dst_spoolss_pipe = False;
POLICY_HND hnd_src, hnd_dst;
PRINTER_INFO_CTR ctr_enum, ctr_dst, ctr_dst_publish;
- REGVAL_CTR reg_ctr;
+ REGVAL_CTR *reg_ctr;
struct cli_state *cli_dst = NULL;
char *devicename = NULL, *unc_name = NULL, *url = NULL;
fstring longname;
@@ -2351,13 +2351,16 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const
curkey += strlen(subkey) + 1;
+ if ( !(reg_ctr = TALLOC_ZERO_P( mem_ctx, REGVAL_CTR )) )
+ return NT_STATUS_NO_MEMORY;
+
/* enumerate all src subkeys */
if (!net_spoolss_enumprinterdataex(cli, mem_ctx, 0,
&hnd_src, subkey,
- &reg_ctr))
+ reg_ctr))
goto done;
- for (j=0; j < reg_ctr.num_values; j++) {
+ for (j=0; j < reg_ctr->num_values; j++) {
REGISTRY_VALUE value;
UNISTR2 data;
@@ -2365,20 +2368,20 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const
/* although samba replies with sane data in most cases we
should try to avoid writing wrong registry data */
- if (strequal(reg_ctr.values[j]->valuename, SPOOL_REG_PORTNAME) ||
- strequal(reg_ctr.values[j]->valuename, SPOOL_REG_UNCNAME) ||
- strequal(reg_ctr.values[j]->valuename, SPOOL_REG_URL) ||
- strequal(reg_ctr.values[j]->valuename, SPOOL_REG_SHORTSERVERNAME) ||
- strequal(reg_ctr.values[j]->valuename, SPOOL_REG_SERVERNAME)) {
+ if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_PORTNAME) ||
+ strequal(reg_ctr->values[j]->valuename, SPOOL_REG_UNCNAME) ||
+ strequal(reg_ctr->values[j]->valuename, SPOOL_REG_URL) ||
+ strequal(reg_ctr->values[j]->valuename, SPOOL_REG_SHORTSERVERNAME) ||
+ strequal(reg_ctr->values[j]->valuename, SPOOL_REG_SERVERNAME)) {
- if (strequal(reg_ctr.values[j]->valuename, SPOOL_REG_PORTNAME)) {
+ if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_PORTNAME)) {
/* although windows uses a multi-sz, we use a sz */
init_unistr2(&data, SAMBA_PRINTER_PORT_NAME, UNI_STR_TERMINATE);
fstrcpy(value.valuename, SPOOL_REG_PORTNAME);
}
- if (strequal(reg_ctr.values[j]->valuename, SPOOL_REG_UNCNAME)) {
+ if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_UNCNAME)) {
if (asprintf(&unc_name, "\\\\%s\\%s", longname, sharename) < 0) {
nt_status = NT_STATUS_NO_MEMORY;
@@ -2388,7 +2391,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const
fstrcpy(value.valuename, SPOOL_REG_UNCNAME);
}
- if (strequal(reg_ctr.values[j]->valuename, SPOOL_REG_URL)) {
+ if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_URL)) {
continue;
@@ -2403,13 +2406,13 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const
#endif
}
- if (strequal(reg_ctr.values[j]->valuename, SPOOL_REG_SERVERNAME)) {
+ if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_SERVERNAME)) {
init_unistr2(&data, longname, UNI_STR_TERMINATE);
fstrcpy(value.valuename, SPOOL_REG_SERVERNAME);
}
- if (strequal(reg_ctr.values[j]->valuename, SPOOL_REG_SHORTSERVERNAME)) {
+ if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_SHORTSERVERNAME)) {
init_unistr2(&data, global_myname(), UNI_STR_TERMINATE);
fstrcpy(value.valuename, SPOOL_REG_SHORTSERVERNAME);
@@ -2430,21 +2433,21 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const
} else {
if (opt_verbose)
- display_reg_value(subkey, *(reg_ctr.values[j]));
+ display_reg_value(subkey, *(reg_ctr->values[j]));
/* here we have to set all subkeys on the dst server */
if (!net_spoolss_setprinterdataex(cli_dst, mem_ctx, &hnd_dst,
- subkey, reg_ctr.values[j]))
+ subkey, reg_ctr->values[j]))
goto done;
}
DEBUGADD(1,("\tSetPrinterDataEx of key [%s\\%s] succeeded\n",
- subkey, reg_ctr.values[j]->valuename));
+ subkey, reg_ctr->values[j]->valuename));
}
- regval_ctr_destroy(&reg_ctr);
+ TALLOC_FREE( reg_ctr );
}
safe_free(keylist);
diff --git a/source3/utils/net_rpc_registry.c b/source3/utils/net_rpc_registry.c
index 8a97f64584..8bb01cd89a 100644
--- a/source3/utils/net_rpc_registry.c
+++ b/source3/utils/net_rpc_registry.c
@@ -331,28 +331,35 @@ static BOOL write_registry_tree( REGF_FILE *infile, REGF_NK_REC *nk,
const char *parentpath )
{
REGF_NK_REC *key, *subkey;
- REGVAL_CTR values;
- REGSUBKEY_CTR subkeys;
+ REGVAL_CTR *values;
+ REGSUBKEY_CTR *subkeys;
int i;
pstring path;
- regsubkey_ctr_init( &subkeys );
- regval_ctr_init( &values );
-
+ if ( !( subkeys = TALLOC_ZERO_P( infile->mem_ctx, REGSUBKEY_CTR )) ) {
+ DEBUG(0,("write_registry_tree: talloc() failed!\n"));
+ return False;
+ }
+
+ if ( !(values = TALLOC_ZERO_P( subkeys, REGVAL_CTR )) ) {
+ DEBUG(0,("write_registry_tree: talloc() failed!\n"));
+ return False;
+ }
+
/* copy values into the REGVAL_CTR */
for ( i=0; i<nk->num_values; i++ ) {
- regval_ctr_addvalue( &values, nk->values[i].valuename, nk->values[i].type,
+ regval_ctr_addvalue( values, nk->values[i].valuename, nk->values[i].type,
nk->values[i].data, (nk->values[i].data_size & ~VK_DATA_IN_OFFSET) );
}
/* copy subkeys into the REGSUBKEY_CTR */
while ( (subkey = regfio_fetch_subkey( infile, nk )) ) {
- regsubkey_ctr_addkey( &subkeys, subkey->keyname );
+ regsubkey_ctr_addkey( subkeys, subkey->keyname );
}
- key = regfio_write_key( outfile, nk->keyname, &values, &subkeys, nk->sec_desc->sec_desc, parent );
+ key = regfio_write_key( outfile, nk->keyname, values, subkeys, nk->sec_desc->sec_desc, parent );
/* write each one of the subkeys out */
@@ -362,8 +369,7 @@ static BOOL write_registry_tree( REGF_FILE *infile, REGF_NK_REC *nk,
write_registry_tree( infile, subkey, key, outfile, path );
}
- regval_ctr_destroy( &values );
- regsubkey_ctr_destroy( &subkeys );
+ TALLOC_FREE( subkeys );
d_printf("[%s]\n", path );
diff --git a/source3/utils/profiles.c b/source3/utils/profiles.c
index 284e15230a..52970bdffc 100644
--- a/source3/utils/profiles.c
+++ b/source3/utils/profiles.c
@@ -67,8 +67,8 @@ static BOOL copy_registry_tree( REGF_FILE *infile, REGF_NK_REC *nk,
{
REGF_NK_REC *key, *subkey;
SEC_DESC *new_sd;
- REGVAL_CTR values;
- REGSUBKEY_CTR subkeys;
+ REGVAL_CTR *values;
+ REGSUBKEY_CTR *subkeys;
int i;
pstring path;
@@ -82,23 +82,30 @@ static BOOL copy_registry_tree( REGF_FILE *infile, REGF_NK_REC *nk,
if ( swap_sid_in_acl( new_sd, &old_sid, &new_sid ) )
DEBUG(2,("Updating ACL for %s\n", nk->keyname ));
- regsubkey_ctr_init( &subkeys );
- regval_ctr_init( &values );
+ if ( !(subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR )) ) {
+ DEBUG(0,("copy_registry_tree: talloc() failure!\n"));
+ return False;
+ }
+
+ if ( !(values = TALLOC_ZERO_P( subkeys, REGVAL_CTR )) ) {
+ DEBUG(0,("copy_registry_tree: talloc() failure!\n"));
+ return False;
+ }
/* copy values into the REGVAL_CTR */
for ( i=0; i<nk->num_values; i++ ) {
- regval_ctr_addvalue( &values, nk->values[i].valuename, nk->values[i].type,
+ regval_ctr_addvalue( values, nk->values[i].valuename, nk->values[i].type,
nk->values[i].data, (nk->values[i].data_size & ~VK_DATA_IN_OFFSET) );
}
/* copy subkeys into the REGSUBKEY_CTR */
while ( (subkey = regfio_fetch_subkey( infile, nk )) ) {
- regsubkey_ctr_addkey( &subkeys, subkey->keyname );
+ regsubkey_ctr_addkey( subkeys, subkey->keyname );
}
- key = regfio_write_key( outfile, nk->keyname, &values, &subkeys, new_sd, parent );
+ key = regfio_write_key( outfile, nk->keyname, values, subkeys, new_sd, parent );
/* write each one of the subkeys out */
@@ -110,8 +117,9 @@ static BOOL copy_registry_tree( REGF_FILE *infile, REGF_NK_REC *nk,
return False;
}
- regval_ctr_destroy( &values );
- regsubkey_ctr_destroy( &subkeys );
+ /* values is a talloc()'d child of subkeys here so just throw it all away */
+
+ TALLOC_FREE( subkeys );
DEBUG(1,("[%s]\n", path));