Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/printing/printing.c

    r664 r745  
    2121
    2222#include "includes.h"
     23#include "system/syslog.h"
     24#include "system/filesys.h"
    2325#include "printing.h"
     26#include "../librpc/gen_ndr/ndr_spoolss.h"
     27#include "nt_printing.h"
     28#include "../librpc/gen_ndr/netlogon.h"
     29#include "printing/notify.h"
     30#include "printing/pcap.h"
     31#include "serverid.h"
     32#include "smbd/smbd.h"
     33#include "auth.h"
     34#include "messages.h"
     35#include "util_tdb.h"
    2436
    2537#ifdef __OS2__
     
    3143
    3244/* Current printer interface */
    33 static bool remove_from_jobs_changed(const char* sharename, uint32 jobid);
     45static bool remove_from_jobs_added(const char* sharename, uint32 jobid);
    3446
    3547/*
     
    138150}
    139151
    140 static void rap_jobid_delete(const char* sharename, uint32 jobid)
     152void rap_jobid_delete(const char* sharename, uint32 jobid)
    141153{
    142154        TDB_DATA key, data;
     
    279291}
    280292
     293/****************************************************************************
     294 Pack the devicemode to store it in a tdb.
     295****************************************************************************/
     296static int pack_devicemode(struct spoolss_DeviceMode *devmode, uint8 *buf, int buflen)
     297{
     298        enum ndr_err_code ndr_err;
     299        DATA_BLOB blob;
     300        int len = 0;
     301
     302        if (devmode) {
     303                ndr_err = ndr_push_struct_blob(&blob, talloc_tos(),
     304                                               devmode,
     305                                               (ndr_push_flags_fn_t)
     306                                               ndr_push_spoolss_DeviceMode);
     307                if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     308                        DEBUG(10, ("pack_devicemode: "
     309                                   "error encoding spoolss_DeviceMode\n"));
     310                        goto done;
     311                }
     312        } else {
     313                ZERO_STRUCT(blob);
     314        }
     315
     316        len = tdb_pack(buf, buflen, "B", blob.length, blob.data);
     317
     318        if (devmode) {
     319                DEBUG(8, ("Packed devicemode [%s]\n", devmode->formname));
     320        }
     321
     322done:
     323        return len;
     324}
     325
     326/****************************************************************************
     327 Unpack the devicemode to store it in a tdb.
     328****************************************************************************/
     329static int unpack_devicemode(TALLOC_CTX *mem_ctx,
     330                      const uint8 *buf, int buflen,
     331                      struct spoolss_DeviceMode **devmode)
     332{
     333        struct spoolss_DeviceMode *dm;
     334        enum ndr_err_code ndr_err;
     335        char *data = NULL;
     336        int data_len = 0;
     337        DATA_BLOB blob;
     338        int len = 0;
     339
     340        *devmode = NULL;
     341
     342        len = tdb_unpack(buf, buflen, "B", &data_len, &data);
     343        if (!data) {
     344                return len;
     345        }
     346
     347        dm = talloc_zero(mem_ctx, struct spoolss_DeviceMode);
     348        if (!dm) {
     349                goto done;
     350        }
     351
     352        blob = data_blob_const(data, data_len);
     353
     354        ndr_err = ndr_pull_struct_blob(&blob, dm, dm,
     355                        (ndr_pull_flags_fn_t)ndr_pull_spoolss_DeviceMode);
     356        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     357                DEBUG(10, ("unpack_devicemode: "
     358                           "error parsing spoolss_DeviceMode\n"));
     359                goto done;
     360        }
     361
     362        DEBUG(8, ("Unpacked devicemode [%s](%s)\n",
     363                  dm->devicename, dm->formname));
     364        if (dm->driverextra_data.data) {
     365                DEBUG(8, ("with a private section of %d bytes\n",
     366                          dm->__driverextra_length));
     367        }
     368
     369        *devmode = dm;
     370
     371done:
     372        SAFE_FREE(data);
     373        return len;
     374}
     375
    281376/***********************************************************************
    282377 unpack a pjob from a tdb buffer
    283378***********************************************************************/
    284379
    285 int unpack_pjob( uint8 *buf, int buflen, struct printjob *pjob )
     380static int unpack_pjob( uint8 *buf, int buflen, struct printjob *pjob )
    286381{
    287382        int     len = 0;
     
    293388                return -1;
    294389
    295         len += tdb_unpack(buf+len, buflen-len, "dddddddddffff",
     390        len += tdb_unpack(buf+len, buflen-len, "dddddddddfffff",
    296391                                &pjpid,
    297392                                &pjsysjob,
     
    306401                                pjob->jobname,
    307402                                pjob->user,
     403                                pjob->clientmachine,
    308404                                pjob->queuename);
    309405
     
    311407                return -1;
    312408
    313         if ( (used = unpack_devicemode(&pjob->nt_devmode, buf+len, buflen-len)) == -1 )
     409        used = unpack_devicemode(NULL, buf+len, buflen-len, &pjob->devmode);
     410        if (used == -1) {
    314411                return -1;
     412        }
    315413
    316414        len += used;
     
    356454        }
    357455
    358         if ( pjob.nt_devmode ) {
    359                 free_nt_devicemode( &pjob.nt_devmode );
    360         }
     456        talloc_free(pjob.devmode);
    361457
    362458        ZERO_STRUCT( pjob );
     
    442538
    443539static const struct {
    444         uint32 lpq_status;
    445         uint32 spoolss_status;
     540        uint32_t lpq_status;
     541        uint32_t spoolss_status;
    446542} lpq_to_spoolss_status_map[] = {
    447543        { LPQ_QUEUED, JOB_STATUS_QUEUED },
     
    456552        { LPQ_BLOCKED, JOB_STATUS_BLOCKED_DEVQ },
    457553        { LPQ_USER_INTERVENTION, JOB_STATUS_USER_INTERVENTION },
    458         { -1, 0 }
     554        { (uint32_t)-1, 0 }
    459555};
    460556
     
    475571}
    476572
    477 static void pjob_store_notify(const char* sharename, uint32 jobid, struct printjob *old_data,
    478                               struct printjob *new_data)
    479 {
    480         bool new_job = False;
    481 
    482         if (!old_data)
    483                 new_job = True;
    484 
    485         /* Job attributes that can't be changed.  We only send
    486            notification for these on a new job. */
     573/***************************************************************************
     574 Append a jobid to the 'jobs changed' list.
     575***************************************************************************/
     576
     577static bool add_to_jobs_changed(struct tdb_print_db *pdb, uint32_t jobid)
     578{
     579        TDB_DATA data;
     580        uint32_t store_jobid;
     581
     582        SIVAL(&store_jobid, 0, jobid);
     583        data.dptr = (uint8 *) &store_jobid;
     584        data.dsize = 4;
     585
     586        DEBUG(10,("add_to_jobs_added: Added jobid %u\n", (unsigned int)jobid ));
     587
     588        return (tdb_append(pdb->tdb, string_tdb_data("INFO/jobs_changed"),
     589                           data) == 0);
     590}
     591
     592/***************************************************************************
     593 Remove a jobid from the 'jobs changed' list.
     594***************************************************************************/
     595
     596static bool remove_from_jobs_changed(const char* sharename, uint32_t jobid)
     597{
     598        struct tdb_print_db *pdb = get_print_db_byname(sharename);
     599        TDB_DATA data, key;
     600        size_t job_count, i;
     601        bool ret = False;
     602        bool gotlock = False;
     603
     604        if (!pdb) {
     605                return False;
     606        }
     607
     608        ZERO_STRUCT(data);
     609
     610        key = string_tdb_data("INFO/jobs_changed");
     611
     612        if (tdb_chainlock_with_timeout(pdb->tdb, key, 5) == -1)
     613                goto out;
     614
     615        gotlock = True;
     616
     617        data = tdb_fetch(pdb->tdb, key);
     618
     619        if (data.dptr == NULL || data.dsize == 0 || (data.dsize % 4 != 0))
     620                goto out;
     621
     622        job_count = data.dsize / 4;
     623        for (i = 0; i < job_count; i++) {
     624                uint32 ch_jobid;
     625
     626                ch_jobid = IVAL(data.dptr, i*4);
     627                if (ch_jobid == jobid) {
     628                        if (i < job_count -1 )
     629                                memmove(data.dptr + (i*4), data.dptr + (i*4) + 4, (job_count - i - 1)*4 );
     630                        data.dsize -= 4;
     631                        if (tdb_store(pdb->tdb, key, data, TDB_REPLACE) == -1)
     632                                goto out;
     633                        break;
     634                }
     635        }
     636
     637        ret = True;
     638  out:
     639
     640        if (gotlock)
     641                tdb_chainunlock(pdb->tdb, key);
     642        SAFE_FREE(data.dptr);
     643        release_print_db(pdb);
     644        if (ret)
     645                DEBUG(10,("remove_from_jobs_changed: removed jobid %u\n", (unsigned int)jobid ));
     646        else
     647                DEBUG(10,("remove_from_jobs_changed: Failed to remove jobid %u\n", (unsigned int)jobid ));
     648        return ret;
     649}
     650
     651static void pjob_store_notify(struct tevent_context *ev,
     652                              struct messaging_context *msg_ctx,
     653                              const char* sharename, uint32 jobid,
     654                              struct printjob *old_data,
     655                              struct printjob *new_data,
     656                              bool *pchanged)
     657{
     658        bool new_job = false;
     659        bool changed = false;
     660
     661        if (old_data == NULL) {
     662                new_job = true;
     663        }
    487664
    488665        /* ACHTUNG!  Due to a bug in Samba's spoolss parsing of the
     
    494671
    495672        if (new_job) {
    496                 notify_job_submitted(sharename, jobid, new_data->starttime);
    497                 notify_job_username(sharename, jobid, new_data->user);
    498         }
    499 
    500         if (new_job || !strequal(old_data->jobname, new_data->jobname))
    501                 notify_job_name(sharename, jobid, new_data->jobname);
    502 
    503         /* Job attributes of a new job or attributes that can be
    504            modified. */
    505 
    506         if (new_job || !strequal(old_data->jobname, new_data->jobname))
    507                 notify_job_name(sharename, jobid, new_data->jobname);
    508 
    509         if (new_job || old_data->status != new_data->status)
    510                 notify_job_status(sharename, jobid, map_to_spoolss_status(new_data->status));
    511 
    512         if (new_job || old_data->size != new_data->size)
    513                 notify_job_total_bytes(sharename, jobid, new_data->size);
    514 
    515         if (new_job || old_data->page_count != new_data->page_count)
    516                 notify_job_total_pages(sharename, jobid, new_data->page_count);
     673                notify_job_submitted(ev, msg_ctx,
     674                                     sharename, jobid, new_data->starttime);
     675                notify_job_username(ev, msg_ctx,
     676                                    sharename, jobid, new_data->user);
     677                notify_job_name(ev, msg_ctx,
     678                                sharename, jobid, new_data->jobname);
     679                notify_job_status(ev, msg_ctx,
     680                                  sharename, jobid, map_to_spoolss_status(new_data->status));
     681                notify_job_total_bytes(ev, msg_ctx,
     682                                       sharename, jobid, new_data->size);
     683                notify_job_total_pages(ev, msg_ctx,
     684                                       sharename, jobid, new_data->page_count);
     685        } else {
     686                if (!strequal(old_data->jobname, new_data->jobname)) {
     687                        notify_job_name(ev, msg_ctx, sharename,
     688                                        jobid, new_data->jobname);
     689                        changed = true;
     690                }
     691
     692                if (old_data->status != new_data->status) {
     693                        notify_job_status(ev, msg_ctx,
     694                                          sharename, jobid,
     695                                          map_to_spoolss_status(new_data->status));
     696                }
     697
     698                if (old_data->size != new_data->size) {
     699                        notify_job_total_bytes(ev, msg_ctx,
     700                                               sharename, jobid, new_data->size);
     701                }
     702
     703                if (old_data->page_count != new_data->page_count) {
     704                        notify_job_total_pages(ev, msg_ctx,
     705                                               sharename, jobid,
     706                                               new_data->page_count);
     707                }
     708        }
     709
     710        *pchanged = changed;
    517711}
    518712
     
    521715****************************************************************************/
    522716
    523 static bool pjob_store(const char* sharename, uint32 jobid, struct printjob *pjob)
     717static bool pjob_store(struct tevent_context *ev,
     718                       struct messaging_context *msg_ctx,
     719                       const char* sharename, uint32 jobid,
     720                       struct printjob *pjob)
    524721{
    525722        uint32_t tmp;
     
    545742                len = 0;
    546743                buflen = newlen;
    547                 len += tdb_pack(buf+len, buflen-len, "dddddddddffff",
     744                len += tdb_pack(buf+len, buflen-len, "dddddddddfffff",
    548745                                (uint32)pjob->pid,
    549746                                (uint32)pjob->sysjob,
     
    558755                                pjob->jobname,
    559756                                pjob->user,
     757                                pjob->clientmachine,
    560758                                pjob->queuename);
    561759
    562                 len += pack_devicemode(pjob->nt_devmode, buf+len, buflen-len);
     760                len += pack_devicemode(pjob->devmode, buf+len, buflen-len);
    563761
    564762                if (buflen != len) {
     
    580778                         TDB_REPLACE) == 0);
    581779
    582         release_print_db(pdb);
    583 
    584780        /* Send notify updates for what has changed */
    585781
    586782        if ( ret ) {
     783                bool changed = false;
    587784                struct printjob old_pjob;
    588785
     
    591788                        if ( unpack_pjob( old_data.dptr, old_data.dsize, &old_pjob ) != -1 )
    592789                        {
    593                                 pjob_store_notify( sharename, jobid, &old_pjob , pjob );
    594                                 free_nt_devicemode( &old_pjob.nt_devmode );
     790                                pjob_store_notify(server_event_context(),
     791                                                  msg_ctx,
     792                                                  sharename, jobid, &old_pjob,
     793                                                  pjob,
     794                                                  &changed);
     795                                talloc_free(old_pjob.devmode);
     796
     797                                if (changed) {
     798                                        add_to_jobs_changed(pdb, jobid);
     799                                }
    595800                        }
     801
    596802                }
    597803                else {
    598804                        /* new job */
    599                         pjob_store_notify( sharename, jobid, NULL, pjob );
    600                 }
    601         }
    602 
     805                        pjob_store_notify(server_event_context(), msg_ctx,
     806                                          sharename, jobid, NULL, pjob,
     807                                          &changed);
     808                }
     809        }
     810
     811        release_print_db(pdb);
    603812done:
    604813        SAFE_FREE( old_data.dptr );
     
    612821****************************************************************************/
    613822
    614 void pjob_delete(const char* sharename, uint32 jobid)
     823static void pjob_delete(struct tevent_context *ev,
     824                        struct messaging_context *msg_ctx,
     825                        const char* sharename, uint32 jobid)
    615826{
    616827        uint32_t tmp;
     
    638849
    639850        job_status = JOB_STATUS_DELETING|JOB_STATUS_DELETED;
    640         notify_job_status(sharename, jobid, job_status);
     851        notify_job_status(ev, msg_ctx, sharename, jobid, job_status);
    641852
    642853        /* Remove from printing.tdb */
    643854
    644855        tdb_delete(pdb->tdb, print_key(jobid, &tmp));
    645         remove_from_jobs_changed(sharename, jobid);
     856        remove_from_jobs_added(sharename, jobid);
    646857        release_print_db( pdb );
    647858        rap_jobid_delete(sharename, jobid);
     
    652863****************************************************************************/
    653864
    654 static void print_unix_job(const char *sharename, print_queue_struct *q, uint32 jobid)
     865static void print_unix_job(struct tevent_context *ev,
     866                           struct messaging_context *msg_ctx,
     867                           const char *sharename, print_queue_struct *q,
     868                           uint32 jobid)
    655869{
    656870        struct printjob pj, *old_pj;
     
    683897        fstrcpy(pj.queuename, old_pj ? old_pj->queuename : sharename );
    684898
    685         pjob_store(sharename, jobid, &pj);
     899        pjob_store(ev, msg_ctx, sharename, jobid, &pj);
    686900}
    687901
     
    694908        const char *lprm_command;
    695909        struct printif *print_if;
     910        struct tevent_context *ev;
     911        struct messaging_context *msg_ctx;
    696912};
    697913
     
    713929        if ( unpack_pjob( data.dptr, data.dsize, &pjob ) == -1 )
    714930                return 0;
    715         free_nt_devicemode( &pjob.nt_devmode );
     931        talloc_free(pjob.devmode);
    716932
    717933
     
    727943                        DEBUG(10,("traverse_fn_delete: pjob %u deleted due to !smbjob\n",
    728944                                                (unsigned int)jobid ));
    729                         pjob_delete(ts->sharename, jobid);
     945                        pjob_delete(ts->ev, ts->msg_ctx,
     946                                    ts->sharename, jobid);
    730947                        return 0;
    731948                }
     
    743960                        DEBUG(10,("traverse_fn_delete: pjob %u deleted due to !process_exists (%u)\n",
    744961                                                (unsigned int)jobid, (unsigned int)pjob.pid ));
    745                         pjob_delete(ts->sharename, jobid);
     962                        pjob_delete(ts->ev, ts->msg_ctx,
     963                                    ts->sharename, jobid);
    746964                } else
    747965                        ts->total_jobs++;
     
    773991                                                /* if we can't delete, then reset the job status */
    774992                                                pjob.status = LPQ_QUEUED;
    775                                                 pjob_store(ts->sharename, jobid, &pjob);
     993                                                pjob_store(ts->ev, ts->msg_ctx,
     994                                                           ts->sharename, jobid, &pjob);
    776995                                        }
    777996                                        else {
    778997                                                /* if we deleted the job, the remove the tdb record */
    779                                                 pjob_delete(ts->sharename, jobid);
     998                                                pjob_delete(ts->ev,
     999                                                            ts->msg_ctx,
     1000                                                            ts->sharename, jobid);
    7801001                                                pjob.status = LPQ_DELETED;
    7811002                                        }
     
    8051026                                                (unsigned int)pjob.starttime,
    8061027                                                (unsigned int)ts->lpq_time ));
    807                         pjob_delete(ts->sharename, jobid);
     1028                        pjob_delete(ts->ev, ts->msg_ctx,
     1029                                    ts->sharename, jobid);
    8081030                } else
    8091031                        ts->total_jobs++;
     
    10021224}
    10031225
    1004 static TDB_DATA get_jobs_changed_data(struct tdb_print_db *pdb)
     1226static TDB_DATA get_jobs_added_data(struct tdb_print_db *pdb)
    10051227{
    10061228        TDB_DATA data;
     
    10081230        ZERO_STRUCT(data);
    10091231
    1010         data = tdb_fetch(pdb->tdb, string_tdb_data("INFO/jobs_changed"));
     1232        data = tdb_fetch(pdb->tdb, string_tdb_data("INFO/jobs_added"));
    10111233        if (data.dptr == NULL || data.dsize == 0 || (data.dsize % 4 != 0)) {
    10121234                SAFE_FREE(data.dptr);
     
    10171239}
    10181240
    1019 static void check_job_changed(const char *sharename, TDB_DATA data, uint32 jobid)
     1241static void check_job_added(const char *sharename, TDB_DATA data, uint32 jobid)
    10201242{
    10211243        unsigned int i;
     
    10271249                ch_jobid = IVAL(data.dptr, i*4);
    10281250                if (ch_jobid == jobid)
    1029                         remove_from_jobs_changed(sharename, jobid);
     1251                        remove_from_jobs_added(sharename, jobid);
    10301252        }
    10311253}
     
    10971319
    10981320/****************************************************************************
    1099  main work for updating the lpq cahe for a printer queue
    1100 ****************************************************************************/
    1101 
    1102 static void print_queue_update_internal( const char *sharename,
     1321 main work for updating the lpq cache for a printer queue
     1322****************************************************************************/
     1323
     1324static void print_queue_update_internal( struct tevent_context *ev,
     1325                                         struct messaging_context *msg_ctx,
     1326                                         const char *sharename,
    11031327                                         struct printif *current_printif,
    11041328                                         char *lpq_command, char *lprm_command )
     
    11441368           in hash order. */
    11451369
    1146         qsort(queue, qcount, sizeof(print_queue_struct),
    1147                 QSORT_CAST(printjob_comp));
     1370        TYPESAFE_QSORT(queue, qcount, printjob_comp);
    11481371
    11491372        /*
     
    11581381        */
    11591382
    1160         jcdata = get_jobs_changed_data(pdb);
     1383        jcdata = get_jobs_added_data(pdb);
    11611384
    11621385        for (i=0; i<qcount; i++) {
     
    11651388                if (jobid == (uint32)-1) {
    11661389                        /* assume its a unix print job */
    1167                         print_unix_job(sharename, &queue[i], jobid);
     1390                        print_unix_job(ev, msg_ctx,
     1391                                       sharename, &queue[i], jobid);
    11681392                        continue;
    11691393                }
     
    11751399                           with jobs in the queue. All we can do is treat them
    11761400                           like unix jobs. Pity. */
    1177                         print_unix_job(sharename, &queue[i], jobid);
     1401                        print_unix_job(ev, msg_ctx,
     1402                                       sharename, &queue[i], jobid);
    11781403                        continue;
    11791404                }
     
    11861411                        pjob->status = queue[i].status;
    11871412
    1188                 pjob_store(sharename, jobid, pjob);
    1189 
    1190                 check_job_changed(sharename, jcdata, jobid);
     1413                pjob_store(ev, msg_ctx, sharename, jobid, pjob);
     1414
     1415                check_job_added(sharename, jcdata, jobid);
    11911416        }
    11921417
     
    12031428        tstruct.lprm_command = lprm_command;
    12041429        tstruct.print_if = current_printif;
     1430        tstruct.ev = ev;
     1431        tstruct.msg_ctx = msg_ctx;
    12051432
    12061433        tdb_traverse(pdb->tdb, traverse_fn_delete, (void *)&tstruct);
     
    12601487****************************************************************************/
    12611488
    1262 static void print_queue_update_with_lock( const char *sharename,
     1489static void print_queue_update_with_lock( struct tevent_context *ev,
     1490                                          struct messaging_context *msg_ctx,
     1491                                          const char *sharename,
    12631492                                          struct printif *current_printif,
    12641493                                          char *lpq_command, char *lprm_command )
     
    13291558        /* do the main work now */
    13301559
    1331         print_queue_update_internal( sharename, current_printif,
    1332                 lpq_command, lprm_command );
     1560        print_queue_update_internal(ev, msg_ctx,
     1561                                    sharename, current_printif,
     1562                                    lpq_command, lprm_command);
    13331563
    13341564        /* Delete our pid from the db. */
     
    13401570this is the receive function of the background lpq updater
    13411571****************************************************************************/
    1342 static void print_queue_receive(struct messaging_context *msg,
     1572void print_queue_receive(struct messaging_context *msg,
    13431573                                void *private_data,
    13441574                                uint32_t msg_type,
     
    13641594        }
    13651595
    1366         print_queue_update_with_lock(sharename,
     1596        print_queue_update_with_lock(server_event_context(), msg, sharename,
    13671597                get_printer_fns_from_type((enum printing_types)printing_type),
    13681598                lpqcommand, lprmcommand );
     
    13851615}
    13861616
     1617extern struct child_pid *children;
     1618extern int num_children;
     1619
    13871620static void add_child_pid(pid_t pid)
    13881621{
    1389         extern struct child_pid *children;
    13901622        struct child_pid *child;
    1391         extern int num_children;
    13921623
    13931624        child = SMB_MALLOC_P(struct child_pid);
     
    14061637main thread of the background lpq updater
    14071638****************************************************************************/
    1408 void start_background_queue(void)
     1639void start_background_queue(struct tevent_context *ev,
     1640                            struct messaging_context *msg_ctx)
    14091641{
    14101642        /* Use local variables for this as we don't
     
    14341666                struct tevent_fd *fde;
    14351667                int ret;
     1668                NTSTATUS status;
    14361669
    14371670                /* Child. */
     
    14411674                pause_pipe[0] = -1;
    14421675
    1443                 if (!NT_STATUS_IS_OK(reinit_after_fork(smbd_messaging_context(),
    1444                                                        smbd_event_context(),
    1445                                                        true))) {
     1676                status = reinit_after_fork(msg_ctx, ev, procid_self(), true);
     1677
     1678                if (!NT_STATUS_IS_OK(status)) {
    14461679                        DEBUG(0,("reinit_after_fork() failed\n"));
    14471680                        smb_panic("reinit_after_fork() failed");
     
    14491682
    14501683                smbd_setup_sig_term_handler();
    1451                 smbd_setup_sig_hup_handler();
    1452 
    1453                 claim_connection( NULL, "smbd lpq backend",
    1454                         FLAG_MSG_GENERAL|FLAG_MSG_SMBD|FLAG_MSG_PRINT_GENERAL);
     1684                smbd_setup_sig_hup_handler(ev, msg_ctx);
     1685
     1686                if (!serverid_register(procid_self(),
     1687                                       FLAG_MSG_GENERAL|FLAG_MSG_SMBD
     1688                                       |FLAG_MSG_PRINT_GENERAL)) {
     1689                        exit(1);
     1690                }
    14551691
    14561692                if (!locking_init()) {
     
    14581694                }
    14591695
    1460                 messaging_register(smbd_messaging_context(), NULL,
    1461                                    MSG_PRINTER_UPDATE, print_queue_receive);
    1462 
    1463                 fde = tevent_add_fd(smbd_event_context(), smbd_event_context(),
    1464                                     pause_pipe[1], TEVENT_FD_READ,
     1696                messaging_register(msg_ctx, NULL, MSG_PRINTER_UPDATE,
     1697                                   print_queue_receive);
     1698
     1699                fde = tevent_add_fd(ev, ev, pause_pipe[1], TEVENT_FD_READ,
    14651700                                    printing_pause_fd_handler,
    14661701                                    NULL);
     
    14711706
    14721707                DEBUG(5,("start_background_queue: background LPQ thread waiting for messages\n"));
    1473                 ret = tevent_loop_wait(smbd_event_context());
     1708                ret = tevent_loop_wait(ev);
    14741709                /* should not be reached */
    14751710                DEBUG(0,("background_queue: tevent_loop_wait() exited with %d - %s\n",
     
    14851720****************************************************************************/
    14861721
    1487 static void print_queue_update(int snum, bool force)
     1722static void print_queue_update(struct messaging_context *msg_ctx,
     1723                               int snum, bool force)
    14881724{
    14891725        fstring key;
     
    15061742                        lp_lpqcommand(snum),
    15071743                        "%p",
    1508                         PRINTERNAME(snum),
     1744                        lp_printername(snum),
    15091745                        false, false, false);
    15101746        if (!lpqcommand) {
     
    15261762                        lp_lprmcommand(snum),
    15271763                        "%p",
    1528                         PRINTERNAME(snum),
     1764                        lp_printername(snum),
    15291765                        false, false, false);
    15301766        if (!lprmcommand) {
     
    15511787                DEBUG(4,("print_queue_update: updating queue [%s] myself\n", sharename));
    15521788                current_printif = get_printer_fns( snum );
    1553                 print_queue_update_with_lock( sharename, current_printif, lpqcommand, lprmcommand );
     1789                print_queue_update_with_lock(server_event_context(), msg_ctx,
     1790                                             sharename, current_printif,
     1791                                             lpqcommand, lprmcommand);
    15541792
    15551793                return;
     
    16041842        /* finally send the message */
    16051843
    1606         messaging_send_buf(smbd_messaging_context(),
    1607                            pid_to_procid(background_lpq_updater_pid),
     1844        messaging_send_buf(msg_ctx, pid_to_procid(background_lpq_updater_pid),
    16081845                           MSG_PRINTER_UPDATE, (uint8 *)buffer, len);
    16091846
     
    18122049
    18132050/****************************************************************************
    1814  Give the fd used for a jobid.
    1815 ****************************************************************************/
    1816 
    1817 int print_job_fd(const char* sharename, uint32 jobid)
    1818 {
    1819         struct printjob *pjob = print_job_find(sharename, jobid);
    1820         if (!pjob)
    1821                 return -1;
    1822         /* don't allow another process to get this info - it is meaningless */
    1823         if (pjob->pid != sys_getpid())
    1824                 return -1;
    1825         return pjob->fd;
    1826 }
    1827 
    1828 /****************************************************************************
    18292051 Give the filename used for a jobid.
    18302052 Only valid for the process doing the spooling and when the job
     
    18472069****************************************************************************/
    18482070
    1849 NT_DEVICEMODE *print_job_devmode(const char* sharename, uint32 jobid)
     2071struct spoolss_DeviceMode *print_job_devmode(const char* sharename, uint32 jobid)
    18502072{
    18512073        struct printjob *pjob = print_job_find(sharename, jobid);
     
    18542076                return NULL;
    18552077
    1856         return pjob->nt_devmode;
    1857 }
    1858 
    1859 /****************************************************************************
    1860  Set the place in the queue for a job.
    1861 ****************************************************************************/
    1862 
    1863 bool print_job_set_place(const char *sharename, uint32 jobid, int place)
    1864 {
    1865         DEBUG(2,("print_job_set_place not implemented yet\n"));
    1866         return False;
     2078        return pjob->devmode;
    18672079}
    18682080
     
    18712083****************************************************************************/
    18722084
    1873 bool print_job_set_name(const char *sharename, uint32 jobid, char *name)
     2085bool print_job_set_name(struct tevent_context *ev,
     2086                        struct messaging_context *msg_ctx,
     2087                        const char *sharename, uint32 jobid, const char *name)
    18742088{
    18752089        struct printjob *pjob;
     
    18802094
    18812095        fstrcpy(pjob->jobname, name);
    1882         return pjob_store(sharename, jobid, pjob);
    1883 }
     2096        return pjob_store(ev, msg_ctx, sharename, jobid, pjob);
     2097}
     2098
     2099/****************************************************************************
     2100 Get the name of a job. Only possible for owner.
     2101****************************************************************************/
     2102
     2103bool print_job_get_name(TALLOC_CTX *mem_ctx, const char *sharename, uint32_t jobid, char **name)
     2104{
     2105        struct printjob *pjob;
     2106
     2107        pjob = print_job_find(sharename, jobid);
     2108        if (!pjob || pjob->pid != sys_getpid()) {
     2109                return false;
     2110        }
     2111
     2112        *name = talloc_strdup(mem_ctx, pjob->jobname);
     2113        if (!*name) {
     2114                return false;
     2115        }
     2116
     2117        return true;
     2118}
     2119
    18842120
    18852121/***************************************************************************
    1886  Remove a jobid from the 'jobs changed' list.
     2122 Remove a jobid from the 'jobs added' list.
    18872123***************************************************************************/
    18882124
    1889 static bool remove_from_jobs_changed(const char* sharename, uint32 jobid)
     2125static bool remove_from_jobs_added(const char* sharename, uint32 jobid)
    18902126{
    18912127        struct tdb_print_db *pdb = get_print_db_byname(sharename);
     
    19012137        ZERO_STRUCT(data);
    19022138
    1903         key = string_tdb_data("INFO/jobs_changed");
     2139        key = string_tdb_data("INFO/jobs_added");
    19042140
    19052141        if (tdb_chainlock_with_timeout(pdb->tdb, key, 5) == -1)
     
    19362172        release_print_db(pdb);
    19372173        if (ret)
    1938                 DEBUG(10,("remove_from_jobs_changed: removed jobid %u\n", (unsigned int)jobid ));
     2174                DEBUG(10,("remove_from_jobs_added: removed jobid %u\n", (unsigned int)jobid ));
    19392175        else
    1940                 DEBUG(10,("remove_from_jobs_changed: Failed to remove jobid %u\n", (unsigned int)jobid ));
     2176                DEBUG(10,("remove_from_jobs_added: Failed to remove jobid %u\n", (unsigned int)jobid ));
    19412177        return ret;
    19422178}
     
    19462182****************************************************************************/
    19472183
    1948 static bool print_job_delete1(int snum, uint32 jobid)
     2184static bool print_job_delete1(struct tevent_context *ev,
     2185                              struct messaging_context *msg_ctx,
     2186                              int snum, uint32 jobid)
    19492187{
    19502188        const char* sharename = lp_const_servicename(snum);
     
    19752213
    19762214        pjob->status = LPQ_DELETING;
    1977         pjob_store(sharename, jobid, pjob);
     2215        pjob_store(ev, msg_ctx, sharename, jobid, pjob);
    19782216
    19792217        if (pjob->spooled && pjob->sysjob != -1)
    19802218        {
    19812219                result = (*(current_printif->job_delete))(
    1982                         PRINTERNAME(snum),
     2220                        lp_printername(snum),
    19832221                        lp_lprmcommand(snum),
    19842222                        pjob);
     
    19932231                        if (!pdb)
    19942232                                return False;
    1995                         pjob_delete(sharename, jobid);
     2233                        pjob_delete(ev, msg_ctx, sharename, jobid);
    19962234                        /* Ensure we keep a rough count of the number of total jobs... */
    19972235                        tdb_change_int32_atomic(pdb->tdb, "INFO/total_jobs", &njobs, -1);
     
    20002238        }
    20012239
    2002         remove_from_jobs_changed( sharename, jobid );
     2240        remove_from_jobs_added( sharename, jobid );
    20032241
    20042242        return (result == 0);
     
    20092247****************************************************************************/
    20102248
    2011 static bool is_owner(struct auth_serversupplied_info *server_info,
     2249static bool is_owner(const struct auth_serversupplied_info *server_info,
    20122250                     const char *servicename,
    20132251                     uint32 jobid)
     
    20252263****************************************************************************/
    20262264
    2027 bool print_job_delete(struct auth_serversupplied_info *server_info, int snum,
    2028                       uint32 jobid, WERROR *errcode)
    2029 {
    2030         const char* sharename = lp_const_servicename( snum );
     2265WERROR print_job_delete(const struct auth_serversupplied_info *server_info,
     2266                        struct messaging_context *msg_ctx,
     2267                        int snum, uint32_t jobid)
     2268{
     2269        const char* sharename = lp_const_servicename(snum);
    20312270        struct printjob *pjob;
    20322271        bool    owner;
    20332272        char    *fname;
    20342273
    2035         *errcode = WERR_OK;
    2036 
    20372274        owner = is_owner(server_info, lp_const_servicename(snum), jobid);
    20382275
     
    20412278
    20422279        if (!owner &&
    2043             !print_access_check(server_info, snum, JOB_ACCESS_ADMINISTER)) {
     2280            !print_access_check(server_info, msg_ctx, snum,
     2281                                JOB_ACCESS_ADMINISTER)) {
    20442282                DEBUG(3, ("delete denied by security descriptor\n"));
    2045                 *errcode = WERR_ACCESS_DENIED;
    20462283
    20472284                /* BEGIN_ADMIN_LOG */
     
    20502287pause, or resume print job. User name: %s. Printer name: %s.",
    20512288                              uidtoname(server_info->utok.uid),
    2052                               PRINTERNAME(snum) );
     2289                              lp_printername(snum) );
    20532290                /* END_ADMIN_LOG */
    20542291
    2055                 return False;
     2292                return WERR_ACCESS_DENIED;
    20562293        }
    20572294
     
    20632300         */
    20642301
    2065         if ( (fname = print_job_fname( sharename, jobid )) != NULL )
    2066         {
     2302        fname = print_job_fname(sharename, jobid);
     2303        if (fname != NULL) {
    20672304                /* remove the spool file */
    2068                 DEBUG(10,("print_job_delete: Removing spool file [%s]\n", fname ));
    2069                 if ( unlink( fname ) == -1 ) {
    2070                         *errcode = map_werror_from_unix(errno);
    2071                         return False;
    2072                 }
    2073         }
    2074 
    2075         if (!print_job_delete1(snum, jobid)) {
    2076                 *errcode = WERR_ACCESS_DENIED;
    2077                 return False;
     2305                DEBUG(10, ("print_job_delete: "
     2306                           "Removing spool file [%s]\n", fname));
     2307                if (unlink(fname) == -1) {
     2308                        return map_werror_from_unix(errno);
     2309                }
     2310        }
     2311
     2312        if (!print_job_delete1(server_event_context(), msg_ctx, snum, jobid)) {
     2313                return WERR_ACCESS_DENIED;
    20782314        }
    20792315
     
    20812317           job still exists */
    20822318
    2083         print_queue_update(snum, True);
     2319        print_queue_update(msg_ctx, snum, True);
    20842320
    20852321        pjob = print_job_find(sharename, jobid);
    2086         if ( pjob && (pjob->status != LPQ_DELETING) )
    2087                 *errcode = WERR_ACCESS_DENIED;
    2088 
    2089         return (pjob == NULL );
     2322        if (pjob && (pjob->status != LPQ_DELETING)) {
     2323                return WERR_ACCESS_DENIED;
     2324        }
     2325
     2326        return WERR_PRINTER_HAS_JOBS_QUEUED;
    20902327}
    20912328
     
    20942331****************************************************************************/
    20952332
    2096 bool print_job_pause(struct auth_serversupplied_info *server_info, int snum,
    2097                      uint32 jobid, WERROR *errcode)
     2333bool print_job_pause(const struct auth_serversupplied_info *server_info,
     2334                     struct messaging_context *msg_ctx,
     2335                     int snum, uint32 jobid, WERROR *errcode)
    20982336{
    20992337        const char* sharename = lp_const_servicename(snum);
     
    21172355
    21182356        if (!is_owner(server_info, lp_const_servicename(snum), jobid) &&
    2119             !print_access_check(server_info, snum, JOB_ACCESS_ADMINISTER)) {
     2357            !print_access_check(server_info, msg_ctx, snum,
     2358                                JOB_ACCESS_ADMINISTER)) {
    21202359                DEBUG(3, ("pause denied by security descriptor\n"));
    21212360
     
    21252364pause, or resume print job. User name: %s. Printer name: %s.",
    21262365                              uidtoname(server_info->utok.uid),
    2127                               PRINTERNAME(snum) );
     2366                              lp_printername(snum) );
    21282367                /* END_ADMIN_LOG */
    21292368
     
    21452384        /* Send a printer notify message */
    21462385
    2147         notify_job_status(sharename, jobid, JOB_STATUS_PAUSED);
     2386        notify_job_status(server_event_context(), msg_ctx, sharename, jobid,
     2387                          JOB_STATUS_PAUSED);
    21482388
    21492389        /* how do we tell if this succeeded? */
     
    21562396****************************************************************************/
    21572397
    2158 bool print_job_resume(struct auth_serversupplied_info *server_info, int snum,
    2159                       uint32 jobid, WERROR *errcode)
     2398bool print_job_resume(const struct auth_serversupplied_info *server_info,
     2399                      struct messaging_context *msg_ctx,
     2400                      int snum, uint32 jobid, WERROR *errcode)
    21602401{
    21612402        const char *sharename = lp_const_servicename(snum);
     
    21792420
    21802421        if (!is_owner(server_info, lp_const_servicename(snum), jobid) &&
    2181             !print_access_check(server_info, snum, JOB_ACCESS_ADMINISTER)) {
     2422            !print_access_check(server_info, msg_ctx, snum,
     2423                                JOB_ACCESS_ADMINISTER)) {
    21822424                DEBUG(3, ("resume denied by security descriptor\n"));
    21832425                *errcode = WERR_ACCESS_DENIED;
     
    21882430pause, or resume print job. User name: %s. Printer name: %s.",
    21892431                              uidtoname(server_info->utok.uid),
    2190                               PRINTERNAME(snum) );
     2432                              lp_printername(snum) );
    21912433                /* END_ADMIN_LOG */
    21922434                return False;
     
    22052447        /* Send a printer notify message */
    22062448
    2207         notify_job_status(sharename, jobid, JOB_STATUS_QUEUED);
     2449        notify_job_status(server_event_context(), msg_ctx, sharename, jobid,
     2450                          JOB_STATUS_QUEUED);
    22082451
    22092452        return True;
     
    22142457****************************************************************************/
    22152458
    2216 ssize_t print_job_write(int snum, uint32 jobid, const char *buf, SMB_OFF_T pos, size_t size)
     2459ssize_t print_job_write(struct tevent_context *ev,
     2460                        struct messaging_context *msg_ctx,
     2461                        int snum, uint32 jobid, const char *buf, size_t size)
    22172462{
    22182463        const char* sharename = lp_const_servicename(snum);
    2219         int return_code;
     2464        ssize_t return_code;
    22202465        struct printjob *pjob;
    22212466
     
    22282473                return -1;
    22292474
    2230         return_code = write_data_at_offset(pjob->fd, buf, size, pos);
     2475        /* if SMBD is spooling this can't be allowed */
     2476        if (pjob->status == PJOB_SMBD_SPOOLING) {
     2477                return -1;
     2478        }
     2479
     2480        return_code = write_data(pjob->fd, buf, size);
    22312481
    22322482        if (return_code>0) {
    22332483                pjob->size += size;
    2234                 pjob_store(sharename, jobid, pjob);
     2484                pjob_store(ev, msg_ctx, sharename, jobid, pjob);
    22352485        }
    22362486        return return_code;
     
    22752525****************************************************************************/
    22762526
    2277 int print_queue_length(int snum, print_status_struct *pstatus)
     2527int print_queue_length(struct messaging_context *msg_ctx, int snum,
     2528                       print_status_struct *pstatus)
    22782529{
    22792530        const char* sharename = lp_const_servicename( snum );
     
    22852536        /* make sure the database is up to date */
    22862537        if (print_cache_expired(lp_const_servicename(snum), True))
    2287                 print_queue_update(snum, False);
     2538                print_queue_update(msg_ctx, snum, False);
    22882539
    22892540        /* also fetch the queue status */
     
    23012552***************************************************************************/
    23022553
    2303 static bool allocate_print_jobid(struct tdb_print_db *pdb, int snum, const char *sharename, uint32 *pjobid)
     2554static WERROR allocate_print_jobid(struct tdb_print_db *pdb, int snum,
     2555                                   const char *sharename, uint32 *pjobid)
    23042556{
    23052557        int i;
    23062558        uint32 jobid;
     2559        enum TDB_ERROR terr;
     2560        int ret;
    23072561
    23082562        *pjobid = (uint32)-1;
     
    23102564        for (i = 0; i < 3; i++) {
    23112565                /* Lock the database - only wait 20 seconds. */
    2312                 if (tdb_lock_bystring_with_timeout(pdb->tdb, "INFO/nextjob", 20) == -1) {
    2313                         DEBUG(0,("allocate_print_jobid: failed to lock printing database %s\n", sharename));
    2314                         return False;
     2566                ret = tdb_lock_bystring_with_timeout(pdb->tdb,
     2567                                                     "INFO/nextjob", 20);
     2568                if (ret == -1) {
     2569                        DEBUG(0, ("allocate_print_jobid: "
     2570                                  "Failed to lock printing database %s\n",
     2571                                  sharename));
     2572                        terr = tdb_error(pdb->tdb);
     2573                        return ntstatus_to_werror(map_nt_error_from_tdb(terr));
    23152574                }
    23162575
    23172576                if (!tdb_fetch_uint32(pdb->tdb, "INFO/nextjob", &jobid)) {
    2318                         if (tdb_error(pdb->tdb) != TDB_ERR_NOEXIST) {
    2319                                 DEBUG(0, ("allocate_print_jobid: failed to fetch INFO/nextjob for print queue %s\n",
    2320                                         sharename));
     2577                        terr = tdb_error(pdb->tdb);
     2578                        if (terr != TDB_ERR_NOEXIST) {
     2579                                DEBUG(0, ("allocate_print_jobid: "
     2580                                          "Failed to fetch INFO/nextjob "
     2581                                          "for print queue %s\n", sharename));
    23212582                                tdb_unlock_bystring(pdb->tdb, "INFO/nextjob");
    2322                                 return False;
     2583                                return ntstatus_to_werror(map_nt_error_from_tdb(terr));
    23232584                        }
    2324                         DEBUG(10,("allocate_print_jobid: no existing jobid in %s\n", sharename));
     2585                        DEBUG(10, ("allocate_print_jobid: "
     2586                                   "No existing jobid in %s\n", sharename));
    23252587                        jobid = 0;
    23262588                }
    23272589
    2328                 DEBUG(10,("allocate_print_jobid: read jobid %u from %s\n", jobid, sharename));
     2590                DEBUG(10, ("allocate_print_jobid: "
     2591                           "Read jobid %u from %s\n", jobid, sharename));
    23292592
    23302593                jobid = NEXT_JOBID(jobid);
    23312594
    2332                 if (tdb_store_int32(pdb->tdb, "INFO/nextjob", jobid)==-1) {
    2333                         DEBUG(3, ("allocate_print_jobid: failed to store INFO/nextjob.\n"));
     2595                ret = tdb_store_int32(pdb->tdb, "INFO/nextjob", jobid);
     2596                if (ret == -1) {
     2597                        terr = tdb_error(pdb->tdb);
     2598                        DEBUG(3, ("allocate_print_jobid: "
     2599                                  "Failed to store INFO/nextjob.\n"));
    23342600                        tdb_unlock_bystring(pdb->tdb, "INFO/nextjob");
    2335                         return False;
     2601                        return ntstatus_to_werror(map_nt_error_from_tdb(terr));
    23362602                }
    23372603
     
    23422608                        break;
    23432609                }
    2344                 DEBUG(10,("allocate_print_jobid: found jobid %u in %s\n", jobid, sharename));
     2610                DEBUG(10, ("allocate_print_jobid: "
     2611                           "Found jobid %u in %s\n", jobid, sharename));
    23452612        }
    23462613
    23472614        if (i > 2) {
    2348                 DEBUG(0, ("allocate_print_jobid: failed to allocate a print job for queue %s\n",
    2349                         sharename));
     2615                DEBUG(0, ("allocate_print_jobid: "
     2616                          "Failed to allocate a print job for queue %s\n",
     2617                          sharename));
    23502618                /* Probably full... */
    2351                 errno = ENOSPC;
    2352                 return False;
     2619                return WERR_NO_SPOOL_SPACE;
    23532620        }
    23542621
     
    23612628                if (tdb_store(pdb->tdb, print_key(jobid, &tmp), dum,
    23622629                              TDB_INSERT) == -1) {
    2363                         DEBUG(3, ("allocate_print_jobid: jobid (%d) failed to store placeholder.\n",
    2364                                 jobid ));
    2365                         return False;
     2630                        DEBUG(3, ("allocate_print_jobid: "
     2631                                  "jobid (%d) failed to store placeholder.\n",
     2632                                  jobid ));
     2633                        terr = tdb_error(pdb->tdb);
     2634                        return ntstatus_to_werror(map_nt_error_from_tdb(terr));
    23662635                }
    23672636        }
    23682637
    23692638        *pjobid = jobid;
    2370         return True;
     2639        return WERR_OK;
    23712640}
    23722641
    23732642/***************************************************************************
    2374  Append a jobid to the 'jobs changed' list.
     2643 Append a jobid to the 'jobs added' list.
    23752644***************************************************************************/
    23762645
    2377 static bool add_to_jobs_changed(struct tdb_print_db *pdb, uint32 jobid)
     2646static bool add_to_jobs_added(struct tdb_print_db *pdb, uint32 jobid)
    23782647{
    23792648        TDB_DATA data;
     
    23842653        data.dsize = 4;
    23852654
    2386         DEBUG(10,("add_to_jobs_changed: Added jobid %u\n", (unsigned int)jobid ));
    2387 
    2388         return (tdb_append(pdb->tdb, string_tdb_data("INFO/jobs_changed"),
     2655        DEBUG(10,("add_to_jobs_added: Added jobid %u\n", (unsigned int)jobid ));
     2656
     2657        return (tdb_append(pdb->tdb, string_tdb_data("INFO/jobs_added"),
    23892658                           data) == 0);
     2659}
     2660
     2661
     2662/***************************************************************************
     2663 Do all checks needed to determine if we can start a job.
     2664***************************************************************************/
     2665
     2666static WERROR print_job_checks(const struct auth_serversupplied_info *server_info,
     2667                               struct messaging_context *msg_ctx,
     2668                               int snum, int *njobs)
     2669{
     2670        const char *sharename = lp_const_servicename(snum);
     2671        uint64_t dspace, dsize;
     2672        uint64_t minspace;
     2673        int ret;
     2674
     2675        if (!print_access_check(server_info, msg_ctx, snum,
     2676                                PRINTER_ACCESS_USE)) {
     2677                DEBUG(3, ("print_job_checks: "
     2678                          "job start denied by security descriptor\n"));
     2679                return WERR_ACCESS_DENIED;
     2680        }
     2681
     2682        if (!print_time_access_check(server_info, msg_ctx, sharename)) {
     2683                DEBUG(3, ("print_job_checks: "
     2684                          "job start denied by time check\n"));
     2685                return WERR_ACCESS_DENIED;
     2686        }
     2687
     2688        /* see if we have sufficient disk space */
     2689        if (lp_minprintspace(snum)) {
     2690                minspace = lp_minprintspace(snum);
     2691                ret = sys_fsusage(lp_pathname(snum), &dspace, &dsize);
     2692                if (ret == 0 && dspace < 2*minspace) {
     2693                        DEBUG(3, ("print_job_checks: "
     2694                                  "disk space check failed.\n"));
     2695                        return WERR_NO_SPOOL_SPACE;
     2696                }
     2697        }
     2698
     2699        /* for autoloaded printers, check that the printcap entry still exists */
     2700        if (lp_autoloaded(snum) && !pcap_printername_ok(sharename)) {
     2701                DEBUG(3, ("print_job_checks: printer name %s check failed.\n",
     2702                          sharename));
     2703                return WERR_ACCESS_DENIED;
     2704        }
     2705
     2706        /* Insure the maximum queue size is not violated */
     2707        *njobs = print_queue_length(msg_ctx, snum, NULL);
     2708        if (*njobs > lp_maxprintjobs(snum)) {
     2709                DEBUG(3, ("print_job_checks: Queue %s number of jobs (%d) "
     2710                          "larger than max printjobs per queue (%d).\n",
     2711                          sharename, *njobs, lp_maxprintjobs(snum)));
     2712                return WERR_NO_SPOOL_SPACE;
     2713        }
     2714
     2715        return WERR_OK;
     2716}
     2717
     2718/***************************************************************************
     2719 Create a job file.
     2720***************************************************************************/
     2721
     2722static WERROR print_job_spool_file(int snum, uint32_t jobid,
     2723                                   const char *output_file,
     2724                                   struct printjob *pjob)
     2725{
     2726        WERROR werr;
     2727        SMB_STRUCT_STAT st;
     2728        const char *path;
     2729        int len;
     2730
     2731        /* if this file is within the printer path, it means that smbd
     2732         * is spooling it and will pass us control when it is finished.
     2733         * Verify that the file name is ok, within path, and it is
     2734         * already already there */
     2735        if (output_file) {
     2736                path = lp_pathname(snum);
     2737                len = strlen(path);
     2738                if (strncmp(output_file, path, len) == 0 &&
     2739                    (output_file[len - 1] == '/' || output_file[len] == '/')) {
     2740
     2741                        /* verify path is not too long */
     2742                        if (strlen(output_file) >= sizeof(pjob->filename)) {
     2743                                return WERR_INVALID_NAME;
     2744                        }
     2745
     2746                        /* verify that the file exists */
     2747                        if (sys_stat(output_file, &st, false) != 0) {
     2748                                return WERR_INVALID_NAME;
     2749                        }
     2750
     2751                        fstrcpy(pjob->filename, output_file);
     2752
     2753                        DEBUG(3, ("print_job_spool_file:"
     2754                                  "External spooling activated"));
     2755
     2756                        /* we do not open the file until spooling is done */
     2757                        pjob->fd = -1;
     2758                        pjob->status = PJOB_SMBD_SPOOLING;
     2759
     2760                        return WERR_OK;
     2761                }
     2762        }
     2763
     2764        slprintf(pjob->filename, sizeof(pjob->filename)-1,
     2765                 "%s/%s%.8u.XXXXXX", lp_pathname(snum),
     2766                 PRINT_SPOOL_PREFIX, (unsigned int)jobid);
     2767        pjob->fd = mkstemp(pjob->filename);
     2768
     2769        if (pjob->fd == -1) {
     2770                werr = map_werror_from_unix(errno);
     2771                if (W_ERROR_EQUAL(werr, WERR_ACCESS_DENIED)) {
     2772                        /* Common setup error, force a report. */
     2773                        DEBUG(0, ("print_job_spool_file: "
     2774                                  "insufficient permissions to open spool "
     2775                                  "file %s.\n", pjob->filename));
     2776                } else {
     2777                        /* Normal case, report at level 3 and above. */
     2778                        DEBUG(3, ("print_job_spool_file: "
     2779                                  "can't open spool file %s\n",
     2780                                  pjob->filename));
     2781                }
     2782                return werr;
     2783        }
     2784
     2785        return WERR_OK;
    23902786}
    23912787
     
    23942790***************************************************************************/
    23952791
    2396 uint32 print_job_start(struct auth_serversupplied_info *server_info, int snum,
    2397                        const char *jobname, NT_DEVICEMODE *nt_devmode )
    2398 {
    2399         uint32 jobid;
     2792WERROR print_job_start(const struct auth_serversupplied_info *server_info,
     2793                       struct messaging_context *msg_ctx,
     2794                       const char *clientmachine,
     2795                       int snum, const char *docname, const char *filename,
     2796                       struct spoolss_DeviceMode *devmode, uint32_t *_jobid)
     2797{
     2798        uint32_t jobid;
    24002799        char *path;
    24012800        struct printjob pjob;
     
    24032802        struct tdb_print_db *pdb = get_print_db_byname(sharename);
    24042803        int njobs;
    2405 
    2406         errno = 0;
    2407 
    2408         if (!pdb)
    2409                 return (uint32)-1;
    2410 
    2411         if (!print_access_check(server_info, snum, PRINTER_ACCESS_USE)) {
    2412                 DEBUG(3, ("print_job_start: job start denied by security descriptor\n"));
     2804        WERROR werr;
     2805
     2806        if (!pdb) {
     2807                return WERR_INTERNAL_DB_CORRUPTION;
     2808        }
     2809
     2810        path = lp_pathname(snum);
     2811
     2812        werr = print_job_checks(server_info, msg_ctx, snum, &njobs);
     2813        if (!W_ERROR_IS_OK(werr)) {
    24132814                release_print_db(pdb);
    2414                 return (uint32)-1;
    2415         }
    2416 
    2417         if (!print_time_access_check(lp_servicename(snum))) {
    2418                 DEBUG(3, ("print_job_start: job start denied by time check\n"));
    2419                 release_print_db(pdb);
    2420                 return (uint32)-1;
    2421         }
    2422 
    2423         path = lp_pathname(snum);
    2424 
    2425         /* see if we have sufficient disk space */
    2426         if (lp_minprintspace(snum)) {
    2427                 uint64_t dspace, dsize;
    2428                 if (sys_fsusage(path, &dspace, &dsize) == 0 &&
    2429                     dspace < 2*(uint64_t)lp_minprintspace(snum)) {
    2430                         DEBUG(3, ("print_job_start: disk space check failed.\n"));
    2431                         release_print_db(pdb);
    2432                         errno = ENOSPC;
    2433                         return (uint32)-1;
    2434                 }
    2435         }
    2436 
    2437         /* for autoloaded printers, check that the printcap entry still exists */
    2438         if (lp_autoloaded(snum) && !pcap_printername_ok(lp_const_servicename(snum))) {
    2439                 DEBUG(3, ("print_job_start: printer name %s check failed.\n", lp_const_servicename(snum) ));
    2440                 release_print_db(pdb);
    2441                 errno = ENOENT;
    2442                 return (uint32)-1;
    2443         }
    2444 
    2445         /* Insure the maximum queue size is not violated */
    2446         if ((njobs = print_queue_length(snum,NULL)) > lp_maxprintjobs(snum)) {
    2447                 DEBUG(3, ("print_job_start: Queue %s number of jobs (%d) larger than max printjobs per queue (%d).\n",
    2448                         sharename, njobs, lp_maxprintjobs(snum) ));
    2449                 release_print_db(pdb);
    2450                 errno = ENOSPC;
    2451                 return (uint32)-1;
    2452         }
    2453 
    2454         DEBUG(10,("print_job_start: Queue %s number of jobs (%d), max printjobs = %d\n",
    2455                 sharename, njobs, lp_maxprintjobs(snum) ));
    2456 
    2457         if (!allocate_print_jobid(pdb, snum, sharename, &jobid))
     2815                return werr;
     2816        }
     2817
     2818        DEBUG(10, ("print_job_start: "
     2819                   "Queue %s number of jobs (%d), max printjobs = %d\n",
     2820                   sharename, njobs, lp_maxprintjobs(snum)));
     2821
     2822        werr = allocate_print_jobid(pdb, snum, sharename, &jobid);
     2823        if (!W_ERROR_IS_OK(werr)) {
    24582824                goto fail;
     2825        }
    24592826
    24602827        /* create the database entry */
     
    24702837        pjob.spooled = False;
    24712838        pjob.smbjob = True;
    2472         pjob.nt_devmode = nt_devmode;
    2473 
    2474         fstrcpy(pjob.jobname, jobname);
     2839        pjob.devmode = devmode;
     2840
     2841        fstrcpy(pjob.jobname, docname);
     2842
     2843        fstrcpy(pjob.clientmachine, clientmachine);
    24752844
    24762845        fstrcpy(pjob.user, lp_printjob_username(snum));
     
    24782847                              path, server_info->utok.gid,
    24792848                              server_info->sanitized_username,
    2480                               pdb_get_domain(server_info->sam_account),
     2849                              server_info->info3->base.domain.string,
    24812850                              pjob.user, sizeof(pjob.user)-1);
    24822851        /* ensure NULL termination */
     
    24862855
    24872856        /* we have a job entry - now create the spool file */
    2488         slprintf(pjob.filename, sizeof(pjob.filename)-1, "%s/%s%.8u.XXXXXX",
    2489                  path, PRINT_SPOOL_PREFIX, (unsigned int)jobid);
    2490         pjob.fd = mkstemp(pjob.filename);
    2491 
    2492         if (pjob.fd == -1) {
    2493                 if (errno == EACCES) {
    2494                         /* Common setup error, force a report. */
    2495                         DEBUG(0, ("print_job_start: insufficient permissions \
    2496 to open spool file %s.\n", pjob.filename));
    2497                 } else {
    2498                         /* Normal case, report at level 3 and above. */
    2499                         DEBUG(3, ("print_job_start: can't open spool file %s,\n", pjob.filename));
    2500                         DEBUGADD(3, ("errno = %d (%s).\n", errno, strerror(errno)));
    2501                 }
     2857        werr = print_job_spool_file(snum, jobid, filename, &pjob);
     2858        if (!W_ERROR_IS_OK(werr)) {
    25022859                goto fail;
    25032860        }
    25042861
    2505         pjob_store(sharename, jobid, &pjob);
    2506 
    2507         /* Update the 'jobs changed' entry used by print_queue_status. */
    2508         add_to_jobs_changed(pdb, jobid);
     2862        pjob_store(server_event_context(), msg_ctx, sharename, jobid, &pjob);
     2863
     2864        /* Update the 'jobs added' entry used by print_queue_status. */
     2865        add_to_jobs_added(pdb, jobid);
    25092866
    25102867        /* Ensure we keep a rough count of the number of total jobs... */
     
    25132870        release_print_db(pdb);
    25142871
    2515         return jobid;
    2516 
    2517  fail:
    2518         if (jobid != -1)
    2519                 pjob_delete(sharename, jobid);
     2872        *_jobid = jobid;
     2873        return WERR_OK;
     2874
     2875fail:
     2876        if (jobid != -1) {
     2877                pjob_delete(server_event_context(), msg_ctx, sharename, jobid);
     2878        }
    25202879
    25212880        release_print_db(pdb);
    25222881
    2523         DEBUG(3, ("print_job_start: returning fail. Error = %s\n", strerror(errno) ));
    2524         return (uint32)-1;
     2882        DEBUG(3, ("print_job_start: returning fail. "
     2883                  "Error = %s\n", win_errstr(werr)));
     2884        return werr;
    25252885}
    25262886
     
    25292889****************************************************************************/
    25302890
    2531 void print_job_endpage(int snum, uint32 jobid)
     2891void print_job_endpage(struct messaging_context *msg_ctx,
     2892                       int snum, uint32 jobid)
    25322893{
    25332894        const char* sharename = lp_const_servicename(snum);
     
    25422903
    25432904        pjob->page_count++;
    2544         pjob_store(sharename, jobid, pjob);
     2905        pjob_store(server_event_context(), msg_ctx, sharename, jobid, pjob);
    25452906}
    25462907
     
    25512912****************************************************************************/
    25522913
    2553 bool print_job_end(int snum, uint32 jobid, enum file_close_type close_type)
     2914NTSTATUS print_job_end(struct messaging_context *msg_ctx, int snum,
     2915                       uint32 jobid, enum file_close_type close_type)
    25542916{
    25552917        const char* sharename = lp_const_servicename(snum);
     
    25582920        SMB_STRUCT_STAT sbuf;
    25592921        struct printif *current_printif = get_printer_fns( snum );
     2922        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
    25602923
    25612924        pjob = print_job_find(sharename, jobid);
    25622925
    2563         if (!pjob)
    2564                 return False;
    2565 
    2566         if (pjob->spooled || pjob->pid != sys_getpid())
    2567                 return False;
    2568 
    2569         if ((close_type == NORMAL_CLOSE || close_type == SHUTDOWN_CLOSE) &&
    2570             (sys_fstat(pjob->fd, &sbuf, false) == 0)) {
     2926        if (!pjob) {
     2927                return NT_STATUS_PRINT_CANCELLED;
     2928        }
     2929
     2930        if (pjob->spooled || pjob->pid != sys_getpid()) {
     2931                return NT_STATUS_ACCESS_DENIED;
     2932        }
     2933
     2934        if (close_type == NORMAL_CLOSE || close_type == SHUTDOWN_CLOSE) {
     2935                if (pjob->status == PJOB_SMBD_SPOOLING) {
     2936                        /* take over the file now, smbd is done */
     2937                        if (sys_stat(pjob->filename, &sbuf, false) != 0) {
     2938                                status = map_nt_error_from_unix(errno);
     2939                                DEBUG(3, ("print_job_end: "
     2940                                          "stat file failed for jobid %d\n",
     2941                                          jobid));
     2942                                goto fail;
     2943                        }
     2944
     2945                        pjob->status = LPQ_SPOOLING;
     2946
     2947                } else {
     2948
     2949                        if ((sys_fstat(pjob->fd, &sbuf, false) != 0)) {
     2950                                status = map_nt_error_from_unix(errno);
     2951                                close(pjob->fd);
     2952                                DEBUG(3, ("print_job_end: "
     2953                                          "stat file failed for jobid %d\n",
     2954                                          jobid));
     2955                                goto fail;
     2956                        }
     2957
     2958                        close(pjob->fd);
     2959                }
     2960
    25712961                pjob->size = sbuf.st_ex_size;
    2572                 close(pjob->fd);
    2573                 pjob->fd = -1;
    25742962        } else {
    25752963
    25762964                /*
    2577                  * Not a normal close or we couldn't stat the job file,
    2578                  * so something has gone wrong. Cleanup.
     2965                 * Not a normal close, something has gone wrong. Cleanup.
    25792966                 */
    2580                 close(pjob->fd);
    2581                 pjob->fd = -1;
    2582                 DEBUG(3,("print_job_end: failed to stat file for jobid %d\n", jobid ));
     2967                if (pjob->fd != -1) {
     2968                        close(pjob->fd);
     2969                }
    25832970                goto fail;
    25842971        }
     
    25922979                        pjob->filename, pjob->size ? "deleted" : "zero length" ));
    25932980                unlink(pjob->filename);
    2594                 pjob_delete(sharename, jobid);
    2595                 return True;
     2981                pjob_delete(server_event_context(), msg_ctx, sharename, jobid);
     2982                return NT_STATUS_OK;
    25962983        }
    25972984
    25982985        ret = (*(current_printif->job_submit))(snum, pjob);
    25992986
    2600         if (ret)
     2987        if (ret) {
     2988                status = NT_STATUS_PRINT_CANCELLED;
    26012989                goto fail;
     2990        }
    26022991
    26032992        /* The print job has been successfully handed over to the back-end */
     
    26052994        pjob->spooled = True;
    26062995        pjob->status = LPQ_QUEUED;
    2607         pjob_store(sharename, jobid, pjob);
     2996        pjob_store(server_event_context(), msg_ctx, sharename, jobid, pjob);
    26082997
    26092998        /* make sure the database is up to date */
    26102999        if (print_cache_expired(lp_const_servicename(snum), True))
    2611                 print_queue_update(snum, False);
    2612 
    2613         return True;
     3000                print_queue_update(msg_ctx, snum, False);
     3001
     3002        return NT_STATUS_OK;
    26143003
    26153004fail:
     
    26173006        /* The print job was not successfully started. Cleanup */
    26183007        /* Still need to add proper error return propagation! 010122:JRR */
     3008        pjob->fd = -1;
    26193009        unlink(pjob->filename);
    2620         pjob_delete(sharename, jobid);
    2621         return False;
     3010        pjob_delete(server_event_context(), msg_ctx, sharename, jobid);
     3011        return status;
    26223012}
    26233013
     
    26263016****************************************************************************/
    26273017
    2628 static bool get_stored_queue_info(struct tdb_print_db *pdb, int snum, int *pcount, print_queue_struct **ppqueue)
    2629 {
    2630         TDB_DATA data, cgdata;
     3018static bool get_stored_queue_info(struct messaging_context *msg_ctx,
     3019                                  struct tdb_print_db *pdb, int snum,
     3020                                  int *pcount, print_queue_struct **ppqueue)
     3021{
     3022        TDB_DATA data, cgdata, jcdata;
    26313023        print_queue_struct *queue = NULL;
    26323024        uint32 qcount = 0;
    26333025        uint32 extra_count = 0;
     3026        uint32_t changed_count = 0;
    26343027        int total_count = 0;
    26353028        size_t len = 0;
     
    26413034        /* make sure the database is up to date */
    26423035        if (print_cache_expired(lp_const_servicename(snum), True))
    2643                 print_queue_update(snum, False);
     3036                print_queue_update(msg_ctx, snum, False);
    26443037
    26453038        *pcount = 0;
     
    26553048                len += tdb_unpack(data.dptr + len, data.dsize - len, "d", &qcount);
    26563049
    2657         /* Get the changed jobs list. */
    2658         cgdata = tdb_fetch(pdb->tdb, string_tdb_data("INFO/jobs_changed"));
     3050        /* Get the added jobs list. */
     3051        cgdata = tdb_fetch(pdb->tdb, string_tdb_data("INFO/jobs_added"));
    26593052        if (cgdata.dptr != NULL && (cgdata.dsize % 4 == 0))
    26603053                extra_count = cgdata.dsize/4;
     3054
     3055        /* Get the changed jobs list. */
     3056        jcdata = tdb_fetch(pdb->tdb, string_tdb_data("INFO/jobs_changed"));
     3057        if (jcdata.dptr != NULL && (jcdata.dsize % 4 == 0))
     3058                changed_count = jcdata.dsize / 4;
    26613059
    26623060        DEBUG(5,("get_stored_queue_info: qcount = %u, extra_count = %u\n", (unsigned int)qcount, (unsigned int)extra_count));
     
    26923090        total_count = qcount;
    26933091
    2694         /* Add in the changed jobids. */
     3092        /* Add new jobids to the queue. */
    26953093        for( i  = 0; i < extra_count; i++) {
    26963094                uint32 jobid;
     
    26983096
    26993097                jobid = IVAL(cgdata.dptr, i*4);
    2700                 DEBUG(5,("get_stored_queue_info: changed job = %u\n", (unsigned int)jobid));
     3098                DEBUG(5,("get_stored_queue_info: added job = %u\n", (unsigned int)jobid));
    27013099                pjob = print_job_find(lp_const_servicename(snum), jobid);
    27023100                if (!pjob) {
    2703                         DEBUG(5,("get_stored_queue_info: failed to find changed job = %u\n", (unsigned int)jobid));
    2704                         remove_from_jobs_changed(sharename, jobid);
     3101                        DEBUG(5,("get_stored_queue_info: failed to find added job = %u\n", (unsigned int)jobid));
     3102                        remove_from_jobs_added(sharename, jobid);
    27053103                        continue;
    27063104                }
     
    27173115        }
    27183116
     3117        /* Update the changed jobids. */
     3118        for (i = 0; i < changed_count; i++) {
     3119                uint32_t jobid = IVAL(jcdata.dptr, i * 4);
     3120                uint32_t j;
     3121                bool found = false;
     3122
     3123                for (j = 0; j < total_count; j++) {
     3124                        if (queue[j].job == jobid) {
     3125                                found = true;
     3126                                break;
     3127                        }
     3128                }
     3129
     3130                if (found) {
     3131                        struct printjob *pjob;
     3132
     3133                        DEBUG(5,("get_stored_queue_info: changed job: %u\n",
     3134                                 (unsigned int) jobid));
     3135
     3136                        pjob = print_job_find(sharename, jobid);
     3137                        if (pjob == NULL) {
     3138                                DEBUG(5,("get_stored_queue_info: failed to find "
     3139                                         "changed job = %u\n",
     3140                                         (unsigned int) jobid));
     3141                                remove_from_jobs_changed(sharename, jobid);
     3142                                continue;
     3143                        }
     3144
     3145                        queue[j].job = jobid;
     3146                        queue[j].size = pjob->size;
     3147                        queue[j].page_count = pjob->page_count;
     3148                        queue[j].status = pjob->status;
     3149                        queue[j].priority = 1;
     3150                        queue[j].time = pjob->starttime;
     3151                        fstrcpy(queue[j].fs_user, pjob->user);
     3152                        fstrcpy(queue[j].fs_file, pjob->jobname);
     3153
     3154                        DEBUG(5,("get_stored_queue_info: updated queue[%u], jobid: %u, jobname: %s\n",
     3155                                 (unsigned int) j, (unsigned int) jobid, pjob->jobname));
     3156                }
     3157
     3158                remove_from_jobs_changed(sharename, jobid);
     3159        }
     3160
    27193161        /* Sort the queue by submission time otherwise they are displayed
    27203162           in hash order. */
    27213163
    2722         qsort(queue, total_count, sizeof(print_queue_struct), QSORT_CAST(printjob_comp));
     3164        TYPESAFE_QSORT(queue, total_count, printjob_comp);
    27233165
    27243166        DEBUG(5,("get_stored_queue_info: total_count = %u\n", (unsigned int)total_count));
     
    27443186****************************************************************************/
    27453187
    2746 int print_queue_status(int snum,
     3188int print_queue_status(struct messaging_context *msg_ctx, int snum,
    27473189                       print_queue_struct **ppqueue,
    27483190                       print_status_struct *status)
     
    27573199
    27583200        if (print_cache_expired(lp_const_servicename(snum), True))
    2759                 print_queue_update(snum, False);
     3201                print_queue_update(msg_ctx, snum, False);
    27603202
    27613203        /* return if we are done */
     
    27943236         */
    27953237
    2796         if (!get_stored_queue_info(pdb, snum, &count, ppqueue)) {
     3238        if (!get_stored_queue_info(msg_ctx, pdb, snum, &count, ppqueue)) {
    27973239                release_print_db(pdb);
    27983240                return 0;
     
    28073249****************************************************************************/
    28083250
    2809 WERROR print_queue_pause(struct auth_serversupplied_info *server_info, int snum)
     3251WERROR print_queue_pause(const struct auth_serversupplied_info *server_info,
     3252                         struct messaging_context *msg_ctx, int snum)
    28103253{
    28113254        int ret;
    28123255        struct printif *current_printif = get_printer_fns( snum );
    28133256
    2814         if (!print_access_check(server_info, snum,
     3257        if (!print_access_check(server_info, msg_ctx, snum,
    28153258                                PRINTER_ACCESS_ADMINISTER)) {
    28163259                return WERR_ACCESS_DENIED;
     
    28333276        /* Send a printer notify message */
    28343277
    2835         notify_printer_status(snum, PRINTER_STATUS_PAUSED);
     3278        notify_printer_status(server_event_context(), msg_ctx, snum,
     3279                              PRINTER_STATUS_PAUSED);
    28363280
    28373281        return WERR_OK;
     
    28423286****************************************************************************/
    28433287
    2844 WERROR print_queue_resume(struct auth_serversupplied_info *server_info, int snum)
     3288WERROR print_queue_resume(const struct auth_serversupplied_info *server_info,
     3289                          struct messaging_context *msg_ctx, int snum)
    28453290{
    28463291        int ret;
    28473292        struct printif *current_printif = get_printer_fns( snum );
    28483293
    2849         if (!print_access_check(server_info, snum,
     3294        if (!print_access_check(server_info, msg_ctx, snum,
    28503295                                PRINTER_ACCESS_ADMINISTER)) {
    28513296                return WERR_ACCESS_DENIED;
     
    28643309        /* make sure the database is up to date */
    28653310        if (print_cache_expired(lp_const_servicename(snum), True))
    2866                 print_queue_update(snum, True);
     3311                print_queue_update(msg_ctx, snum, True);
    28673312
    28683313        /* Send a printer notify message */
    28693314
    2870         notify_printer_status(snum, PRINTER_STATUS_OK);
     3315        notify_printer_status(server_event_context(), msg_ctx, snum,
     3316                              PRINTER_STATUS_OK);
    28713317
    28723318        return WERR_OK;
     
    28773323****************************************************************************/
    28783324
    2879 WERROR print_queue_purge(struct auth_serversupplied_info *server_info, int snum)
     3325WERROR print_queue_purge(const struct auth_serversupplied_info *server_info,
     3326                         struct messaging_context *msg_ctx, int snum)
    28803327{
    28813328        print_queue_struct *queue;
     
    28853332
    28863333        /* Force and update so the count is accurate (i.e. not a cached count) */
    2887         print_queue_update(snum, True);
    2888 
    2889         can_job_admin = print_access_check(server_info, snum,
     3334        print_queue_update(msg_ctx, snum, True);
     3335
     3336        can_job_admin = print_access_check(server_info,
     3337                                           msg_ctx,
     3338                                           snum,
    28903339                                           JOB_ACCESS_ADMINISTER);
    2891         njobs = print_queue_status(snum, &queue, &status);
     3340        njobs = print_queue_status(msg_ctx, snum, &queue, &status);
    28923341
    28933342        if ( can_job_admin )
     
    28993348
    29003349                if (owner || can_job_admin) {
    2901                         print_job_delete1(snum, queue[i].job);
     3350                        print_job_delete1(server_event_context(), msg_ctx,
     3351                                          snum, queue[i].job);
    29023352                }
    29033353        }
     
    29073357
    29083358        /* update the cache */
    2909         print_queue_update( snum, True );
     3359        print_queue_update(msg_ctx, snum, True);
    29103360
    29113361        SAFE_FREE(queue);
Note: See TracChangeset for help on using the changeset viewer.