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/libads/ldap_printer.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'source3/libads') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index f4ecbdd93c..db544fe209 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -265,8 +265,7 @@ WERROR get_remote_printer_publishing_data(struct cli_state *cli, { WERROR result; char *printername, *servername; - REGVAL_CTR dsdriver_ctr, dsspooler_ctr; - BOOL got_dsdriver = False, got_dsspooler = False; + REGVAL_CTR *dsdriver_ctr, *dsspooler_ctr; uint32 i; POLICY_HND pol; @@ -286,36 +285,44 @@ WERROR get_remote_printer_publishing_data(struct cli_state *cli, return result; } - result = cli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSDRIVER_KEY, &dsdriver_ctr); + if ( !(dsdriver_ctr = TALLOC_ZERO_P( mem_ctx, REGVAL_CTR )) ) + return WERR_NOMEM; + + result = cli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSDRIVER_KEY, dsdriver_ctr); if (!W_ERROR_IS_OK(result)) { DEBUG(3, ("Unable to do enumdataex on %s, error is %s.\n", printername, dos_errstr(result))); } else { + uint32 num_values = regval_ctr_numvals( dsdriver_ctr ); /* Have the data we need now, so start building */ - got_dsdriver = True; - for (i=0; i < dsdriver_ctr.num_values; i++) - map_regval_to_ads(mem_ctx, mods, - dsdriver_ctr.values[i]); + for (i=0; i < num_values; i++) { + map_regval_to_ads(mem_ctx, mods, dsdriver_ctr->values[i]); + } } - result = cli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSSPOOLER_KEY, &dsspooler_ctr); + if ( !(dsspooler_ctr = TALLOC_ZERO_P( mem_ctx, REGVAL_CTR )) ) + return WERR_NOMEM; + + result = cli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSSPOOLER_KEY, dsspooler_ctr); if (!W_ERROR_IS_OK(result)) { DEBUG(3, ("Unable to do enumdataex on %s, error is %s.\n", printername, dos_errstr(result))); } else { - got_dsspooler = True; - for (i=0; i < dsspooler_ctr.num_values; i++) - map_regval_to_ads(mem_ctx, mods, - dsspooler_ctr.values[i]); + uint32 num_values = regval_ctr_numvals( dsspooler_ctr ); + + for (i=0; ivalues[i]); + } } ads_mod_str(mem_ctx, mods, SPOOL_REG_PRINTERNAME, printer); - if (got_dsdriver) regval_ctr_destroy(&dsdriver_ctr); - if (got_dsspooler) regval_ctr_destroy(&dsspooler_ctr); + TALLOC_FREE( dsdriver_ctr ); + TALLOC_FREE( dsspooler_ctr ); + cli_spoolss_close_printer(cli, mem_ctx, &pol); return result; @@ -328,9 +335,9 @@ BOOL get_local_printer_publishing_data(TALLOC_CTX *mem_ctx, uint32 key,val; for (key=0; key < data->num_keys; key++) { - REGVAL_CTR ctr = data->keys[key].values; - for (val=0; val < ctr.num_values; val++) - map_regval_to_ads(mem_ctx, mods, ctr.values[val]); + REGVAL_CTR *ctr = data->keys[key].values; + for (val=0; val < ctr->num_values; val++) + map_regval_to_ads(mem_ctx, mods, ctr->values[val]); } return True; } -- cgit