From b5ac72cc646a981469ee65305da83f273c4cd093 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 26 Oct 2000 21:43:13 +0000 Subject: Sorry JF - no billable hours :-). I fixed the "stream of events" problem with PCL drivers. The problem was we were updating the changeid on every SETPRINTERDATA/DELETEPRINTERDATA call. We should not do this, we should just update the 'setprinter' called count. We update the changeid on calls to SETPRINTER/ADDPRINTER/ADDPRINTEREX etc. Also fixed the correct returning of the create time on printers. Jeremy. (This used to be commit 521f09829fd329f87b3d19e8871e2b989c98a58e) --- source3/include/proto.h | 1 + source3/printing/nt_printing.c | 56 +++++++++++++++++++++++++++---------- source3/rpc_server/srv_spoolss_nt.c | 12 ++++---- source3/smbd/sec_ctx.c | 2 -- 4 files changed, 49 insertions(+), 22 deletions(-) diff --git a/source3/include/proto.h b/source3/include/proto.h index d99ec39d22..c5294fd1ea 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -1737,6 +1737,7 @@ NT_DEVICEMODE *construct_nt_devicemode(const fstring default_devicename); NT_DEVICEMODE *dup_nt_devicemode(NT_DEVICEMODE *nt_devicemode); void free_nt_devicemode(NT_DEVICEMODE **devmode_ptr); void get_printer_subst_params(int snum, fstring *printername, fstring *sharename, fstring *portname); +uint32 mod_a_printer(NT_PRINTER_INFO_LEVEL printer, uint32 level); uint32 add_a_printer(NT_PRINTER_INFO_LEVEL printer, uint32 level); uint32 get_a_printer(NT_PRINTER_INFO_LEVEL **pp_printer, uint32 level, fstring sharename); uint32 free_a_printer(NT_PRINTER_INFO_LEVEL **pp_printer, uint32 level); diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c index 48bab48b3c..9d4a7f2030 100644 --- a/source3/printing/nt_printing.c +++ b/source3/printing/nt_printing.c @@ -1230,14 +1230,12 @@ uint32 del_a_printer(char *sharename) /**************************************************************************** ****************************************************************************/ -static uint32 add_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info) +static uint32 update_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info) { pstring key; char *buf; int buflen, len, ret; TDB_DATA kbuf, dbuf; - NTTIME time_nt; - time_t time_unix = time(NULL); /* * in addprinter: no servername and the printer is the name @@ -1264,10 +1262,6 @@ static uint32 add_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info) * behind a SAMBA share. */ - unix_to_nt_time(&time_nt, time_unix); - info->changeid=time_nt.low; - info->c_setprinter++; - buf = NULL; buflen = 0; @@ -1684,6 +1678,7 @@ static uint32 get_a_printer_2_default(NT_PRINTER_INFO_LEVEL_2 **info_ptr, fstrin info.untiltime = 0; /* Minutes since 12:00am GMT */ info.priority = 1; info.default_priority = 1; + info.setuptime = (uint32)time(NULL); if ((info.devmode = construct_nt_devicemode(info.printername)) == NULL) goto fail; @@ -1725,12 +1720,8 @@ static uint32 get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 **info_ptr, fstring sharen kbuf.dsize = strlen(key)+1; dbuf = tdb_fetch(tdb, kbuf); -#if 1 /* JRATEST */ if (!dbuf.dptr) return get_a_printer_2_default(info_ptr, sharename); -#else - if (!dbuf.dptr) return 1; -#endif len += tdb_unpack(dbuf.dptr+len, dbuf.dsize-len, "dddddddddddfffffPfffff", &info.attributes, @@ -1762,9 +1753,7 @@ static uint32 get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 **info_ptr, fstring sharen len += unpack_devicemode(&info.devmode,dbuf.dptr+len, dbuf.dsize-len); len += unpack_specifics(&info.specific,dbuf.dptr+len, dbuf.dsize-len); -#if 1 /* JRATEST */ nt_printing_getsec(sharename, &info.secdesc_buf); -#endif /* JRATEST */ safe_free(dbuf.dptr); *info_ptr=memdup(&info, sizeof(info)); @@ -1859,7 +1848,36 @@ void get_printer_subst_params(int snum, fstring *printername, fstring *sharename */ /**************************************************************************** + Modify a printer. This is called from SETPRINTERDATA/DELETEPRINTERDATA. ****************************************************************************/ + +uint32 mod_a_printer(NT_PRINTER_INFO_LEVEL printer, uint32 level) +{ + uint32 success; + + dump_a_printer(printer, level); + + switch (level) + { + case 2: + { + printer.info_2->c_setprinter++; + success=update_a_printer_2(printer.info_2); + break; + } + default: + success=1; + break; + } + + return (success); +} + +/**************************************************************************** + Add a printer. This is called from ADDPRINTER(EX) and also SETPRINTER. + We split this out from mod_a_printer as it updates the id's and timestamps. +****************************************************************************/ + uint32 add_a_printer(NT_PRINTER_INFO_LEVEL printer, uint32 level) { uint32 success; @@ -1870,7 +1888,17 @@ uint32 add_a_printer(NT_PRINTER_INFO_LEVEL printer, uint32 level) { case 2: { - success=add_a_printer_2(printer.info_2); + /* + * Update the changestamp. + * Note we must *not* do this in mod_a_printer(). + */ + NTTIME time_nt; + time_t time_unix = time(NULL); + unix_to_nt_time(&time_nt, time_unix); + printer.info_2->changeid=time_nt.low; + + printer.info_2->c_setprinter++; + success=update_a_printer_2(printer.info_2); break; } default: diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 928ac45046..0eb75a7480 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1816,7 +1816,7 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring counter_printer_0 *session_counter; uint32 global_counter; struct tm *t; - time_t setup_time = time(NULL); + time_t setuptime; print_queue_struct *queue=NULL; print_status_struct status; @@ -1869,8 +1869,8 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring printer->total_jobs = 0; printer->total_bytes = 0; - t=gmtime(&setup_time); - ntprinter->info_2->setuptime = (uint32)setup_time; /* FIXME !! */ + setuptime = (time_t)ntprinter->info_2->setuptime; + t=gmtime(&setuptime); printer->year = t->tm_year+1900; printer->month = t->tm_mon+1; @@ -4957,7 +4957,7 @@ uint32 _spoolss_enumprinterdata(POLICY_HND *handle, uint32 idx, return ERROR_NOT_ENOUGH_MEMORY; } - ZERO_STRUCTP(*data_out); + memset(*data_out,'\0',in_data_len); memcpy(*data_out, data, (size_t)data_len); *out_data_len=data_len; @@ -5009,7 +5009,7 @@ uint32 _spoolss_setprinterdata( POLICY_HND *handle, if (!add_a_specific_param(printer->info_2, param)) status = ERROR_INVALID_PARAMETER; else - status = add_a_printer(*printer, 2); + status = mod_a_printer(*printer, 2); free_a_printer(&printer, 2); return status; @@ -5051,7 +5051,7 @@ uint32 _spoolss_deleteprinterdata( POLICY_HND *handle, const UNISTR2 *value) if(!unlink_specific_param_if_exist(printer->info_2, ¶m)) status = ERROR_INVALID_PARAMETER; else - status = add_a_printer(*printer, 2); + status = mod_a_printer(*printer, 2); free_a_printer(&printer, 2); return status; diff --git a/source3/smbd/sec_ctx.c b/source3/smbd/sec_ctx.c index 1f20ef062e..f316156222 100644 --- a/source3/smbd/sec_ctx.c +++ b/source3/smbd/sec_ctx.c @@ -318,10 +318,8 @@ void set_sec_ctx(uid_t uid, gid_t gid, int ngroups, gid_t *groups, NT_USER_TOKEN ctx_p->ngroups = ngroups; safe_free(ctx_p->groups); -#if 1 /* JRATEST */ if (token && (token == ctx_p->token)) smb_panic("DUPLICATE_TOKEN"); -#endif delete_nt_token(&ctx_p->token); -- cgit