diff options
author | Gerald Carter <jerry@samba.org> | 2005-08-29 14:55:40 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 11:03:25 -0500 |
commit | 44707ad2e00a91f459e80efbe8f362b5853b0a62 (patch) | |
tree | 438124f4550315df722d959891b66e669222f8e8 /source3/rpc_server/srv_spoolss_nt.c | |
parent | 77670a2ec33275ae08a37606ee15bf0170b7fcb3 (diff) | |
download | samba-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/rpc_server/srv_spoolss_nt.c')
-rw-r--r-- | source3/rpc_server/srv_spoolss_nt.c | 167 |
1 files changed, 38 insertions, 129 deletions
diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 5391ac5f41..ee35b5853f 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -274,62 +274,6 @@ static Printer_entry *find_printer_index_by_hnd(pipes_struct *p, POLICY_HND *hnd return find_printer; } -#ifdef ENABLE_PRINT_HND_OBJECT_CACHE -/**************************************************************************** - look for a printer object cached on an open printer handle -****************************************************************************/ - -WERROR find_printer_in_print_hnd_cache( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL_2 **info2, - const char *servername, const char *printername ) -{ - Printer_entry *p; - - DEBUG(10,("find_printer_in_print_hnd_cache: printer [\\\\%s\\%s]\n", - servername, printername)); - - for ( p=printers_list; p; p=p->next ) - { - if ( p->printer_type==PRINTER_HANDLE_IS_PRINTER - && p->printer_info - && strequal( p->sharename, printername ) - && strequal( p->servername, servername ) ) - { - DEBUG(10,("Found printer\n")); - *info2 = dup_printer_2( ctx, p->printer_info->info_2 ); - if ( *info2 ) - return WERR_OK; - } - } - - return WERR_INVALID_PRINTER_NAME; -} - -/**************************************************************************** - destroy any cached printer_info_2 structures on open handles -****************************************************************************/ - -void invalidate_printer_hnd_cache( char *printername ) -{ - Printer_entry *p; - - DEBUG(10,("invalidate_printer_hnd_cache: printer [%s]\n", printername)); - - for ( p=printers_list; p; p=p->next ) - { - if ( p->printer_type==PRINTER_HANDLE_IS_PRINTER - && p->printer_info - && StrCaseCmp(p->sharename, printername)==0) - { - DEBUG(10,("invalidating printer_info cache for handl:\n")); - free_a_printer( &p->printer_info, 2 ); - p->printer_info = NULL; - } - } - - return; -} -#endif - /**************************************************************************** Close printer index by handle. ****************************************************************************/ @@ -1216,24 +1160,6 @@ static void receive_notify2_message_list(int msg_type, pid_t src, void *msg, siz return; } -#ifdef ENABLE_PRINT_HND_OBJECT_CACHE -/******************************************************************** - callback to MSG_PRINTER_CHANGED. When a printer is changed by - one smbd, all of processes must clear their printer cache immediately. - ********************************************************************/ - -void receive_printer_mod_msg(int msg_type, pid_t src, void *buf, size_t len) -{ - fstring printername; - - fstrcpy( printername, buf ); - - DEBUG(10,("receive_printer_mod_msg: Printer change [%s]\n", printername )); - - invalidate_printer_hnd_cache( printername ); -} -#endif - /******************************************************************** Send a message to ourself about new driver being installed so we can upgrade the information for each printer bound to this @@ -1804,7 +1730,10 @@ static BOOL convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni, switch (level) { case 2: - ret = uni_2_asc_printer_info_2(uni->info_2, &printer->info_2); + /* printer->info_2 is already a valid printer */ + ret = uni_2_asc_printer_info_2(uni->info_2, printer->info_2); + printer->info_2->setuptime = time(NULL); + break; default: break; @@ -2272,8 +2201,8 @@ static WERROR delete_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char WERROR set_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value, uint32 type, uint8 *data, int real_len ) { - delete_printer_data( printer->info_2, key, value ); - + /* the registry objects enforce uniqueness based on value name */ + return add_printer_data( printer->info_2, key, value, type, data, real_len ); } @@ -4234,22 +4163,19 @@ static BOOL construct_printer_info_2(Printer_entry *print_hnd, PRINTER_INFO_2 *p printer->cjobs = count; /* jobs */ printer->averageppm = ntprinter->info_2->averageppm; /* average pages per minute */ - if((printer->devmode = construct_dev_mode(snum)) == NULL) { + if ( !(printer->devmode = construct_dev_mode(snum)) ) DEBUG(8, ("Returning NULL Devicemode!\n")); - } - if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->len != 0) { - /* steal the printer info sec_desc structure. [badly done]. */ - printer->secdesc = ntprinter->info_2->secdesc_buf->sec; - ntprinter->info_2->secdesc_buf->sec = NULL; /* Stolen memory. */ - ntprinter->info_2->secdesc_buf->len = 0; /* Stolen memory. */ - ntprinter->info_2->secdesc_buf->max_len = 0; /* Stolen memory. */ - } - else { - printer->secdesc = NULL; + printer->secdesc = NULL; + + if ( ntprinter->info_2->secdesc_buf + && ntprinter->info_2->secdesc_buf->len != 0 ) + { + printer->secdesc = dup_sec_desc( get_talloc_ctx(), ntprinter->info_2->secdesc_buf->sec ); } free_a_printer(&ntprinter, 2); + return True; } @@ -4274,32 +4200,12 @@ static BOOL construct_printer_info_3(Printer_entry *print_hnd, PRINTER_INFO_3 ** ZERO_STRUCTP(printer); - printer->flags = 4; /* These are the components of the SD we are returning. */ - if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->len != 0) { - /* steal the printer info sec_desc structure. [badly done]. */ - printer->secdesc = ntprinter->info_2->secdesc_buf->sec; - -#if 0 - /* - * Set the flags for the components we are returning. - */ + /* These are the components of the SD we are returning. */ - if (printer->secdesc->owner_sid) - printer->flags |= OWNER_SECURITY_INFORMATION; + printer->flags = 0x4; - if (printer->secdesc->grp_sid) - printer->flags |= GROUP_SECURITY_INFORMATION; - - if (printer->secdesc->dacl) - printer->flags |= DACL_SECURITY_INFORMATION; - - if (printer->secdesc->sacl) - printer->flags |= SACL_SECURITY_INFORMATION; -#endif - - ntprinter->info_2->secdesc_buf->sec = NULL; /* Stolen the malloced memory. */ - ntprinter->info_2->secdesc_buf->len = 0; /* Stolen the malloced memory. */ - ntprinter->info_2->secdesc_buf->max_len = 0; /* Stolen the malloced memory. */ + if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->len != 0) { + printer->secdesc = dup_sec_desc( get_talloc_ctx(), ntprinter->info_2->secdesc_buf->sec ); } free_a_printer(&ntprinter, 2); @@ -4582,16 +4488,20 @@ static WERROR enum_all_printers_info_2(RPC_BUFFER *buffer, uint32 offered, uint3 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) { DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum)); - if (construct_printer_info_2(NULL, ¤t_prt, snum)) { - if((tp=SMB_REALLOC_ARRAY(printers, PRINTER_INFO_2, *returned +1)) == NULL) { + if (construct_printer_info_2(NULL, ¤t_prt, snum)) + { + if ( !(tp=SMB_REALLOC_ARRAY(printers, PRINTER_INFO_2, *returned +1)) ) { DEBUG(2,("enum_all_printers_info_2: failed to enlarge printers buffer!\n")); SAFE_FREE(printers); *returned = 0; return WERR_NOMEM; } - else printers = tp; + DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_2\n", *returned)); + + printers = tp; memcpy(&printers[*returned], ¤t_prt, sizeof(PRINTER_INFO_2)); + (*returned)++; } } @@ -4617,9 +4527,10 @@ static WERROR enum_all_printers_info_2(RPC_BUFFER *buffer, uint32 offered, uint3 out: /* clear memory */ - for (i=0; i<*returned; i++) { + + for (i=0; i<*returned; i++) free_devmode(printers[i].devmode); - } + SAFE_FREE(printers); if ( !W_ERROR_IS_OK(result) ) @@ -7905,8 +7816,6 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S int i, key_index, num_values; int name_length; - ZERO_STRUCT( printer ); - *out_type = 0; *out_max_data_len = 0; @@ -7927,7 +7836,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S if (!W_ERROR_IS_OK(result)) return result; - p_data = &printer->info_2->data; + p_data = printer->info_2->data; key_index = lookup_printerkey( p_data, SPOOL_PRINTERDATA_KEY ); result = WERR_OK; @@ -7945,11 +7854,11 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S biggest_valuesize = 0; biggest_datasize = 0; - num_values = regval_ctr_numvals( &p_data->keys[key_index].values ); - + num_values = regval_ctr_numvals( p_data->keys[key_index].values ); + for ( i=0; i<num_values; i++ ) { - val = regval_ctr_specific_value( &p_data->keys[key_index].values, i ); + val = regval_ctr_specific_value( p_data->keys[key_index].values, i ); name_length = strlen(val->valuename); if ( strlen(val->valuename) > biggest_valuesize ) @@ -7979,7 +7888,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S */ if ( key_index != -1 ) - val = regval_ctr_specific_value( &p_data->keys[key_index].values, idx ); + val = regval_ctr_specific_value( p_data->keys[key_index].values, idx ); if ( !val ) { @@ -8937,7 +8846,7 @@ WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, goto done; } - if ( lookup_printerkey( &printer->info_2->data, keyname ) == -1 ) { + if ( lookup_printerkey( printer->info_2->data, keyname ) == -1 ) { DEBUG(4,("_spoolss_getprinterdataex: Invalid keyname [%s]\n", keyname )); free_a_printer( &printer, 2 ); status = WERR_BADFILE; @@ -9158,7 +9067,7 @@ WERROR _spoolss_enumprinterkey(pipes_struct *p, SPOOL_Q_ENUMPRINTERKEY *q_u, SPO /* get the list of subkey names */ unistr2_to_ascii( key, &q_u->key, sizeof(key)-1 ); - data = &printer->info_2->data; + data = printer->info_2->data; num_keys = get_printer_subkeys( data, key, &keynames ); @@ -9301,7 +9210,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ /* now look for a match on the key name */ - p_data = &printer->info_2->data; + p_data = printer->info_2->data; unistr2_to_ascii(key, &q_u->key, sizeof(key) - 1); if ( (key_index = lookup_printerkey( p_data, key)) == -1 ) @@ -9316,7 +9225,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ /* allocate the memory for the array of pointers -- if necessary */ - num_entries = regval_ctr_numvals( &p_data->keys[key_index].values ); + num_entries = regval_ctr_numvals( p_data->keys[key_index].values ); if ( num_entries ) { if ( (enum_values=TALLOC_ARRAY(p->mem_ctx, PRINTER_ENUM_VALUES, num_entries)) == NULL ) @@ -9339,7 +9248,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ { /* lookup the registry value */ - val = regval_ctr_specific_value( &p_data->keys[key_index].values, i ); + val = regval_ctr_specific_value( p_data->keys[key_index].values, i ); DEBUG(10,("retrieved value number [%d] [%s]\n", i, regval_name(val) )); /* copy the data */ |