Sorry JF - no billable hours :-). I fixed the "stream of events" problem
authorJeremy Allison <jra@samba.org>
Thu, 26 Oct 2000 21:43:13 +0000 (21:43 +0000)
committerJeremy Allison <jra@samba.org>
Thu, 26 Oct 2000 21:43:13 +0000 (21:43 +0000)
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
source3/printing/nt_printing.c
source3/rpc_server/srv_spoolss_nt.c
source3/smbd/sec_ctx.c

index d99ec39d220adf9a84beeeaee35c48f334a760b2..c5294fd1ea5ccfbdf8810cc523482bb24ad61184 100644 (file)
@@ -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);
index 48bab48b3cb92df5a881b50350e712187ad170ed..9d4a7f203079db9779528f6c150fc3781c203fae 100644 (file)
@@ -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:
index 928ac450464472d7571974a3b57f636c57c0bfc2..0eb75a7480c3dd0fac429d17b985056d65f621fa 100644 (file)
@@ -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, &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;
index 1f20ef062e83ac2056a49f1eed03cda41d1349c7..f31615622292d2892780ff823ae28b2b41c9a1f0 100644 (file)
@@ -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);