Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/printing/printing.c

    r478 r740  
    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
    2537extern struct current_user current_user;
     
    2739
    2840/* Current printer interface */
    29 static bool remove_from_jobs_changed(const char* sharename, uint32 jobid);
     41static bool remove_from_jobs_added(const char* sharename, uint32 jobid);
    3042
    3143/*
     
    134146}
    135147
    136 static void rap_jobid_delete(const char* sharename, uint32 jobid)
     148void rap_jobid_delete(const char* sharename, uint32 jobid)
    137149{
    138150        TDB_DATA key, data;
     
    275287}
    276288
     289/****************************************************************************
     290 Pack the devicemode to store it in a tdb.
     291****************************************************************************/
     292static int pack_devicemode(struct spoolss_DeviceMode *devmode, uint8 *buf, int buflen)
     293{
     294        enum ndr_err_code ndr_err;
     295        DATA_BLOB blob;
     296        int len = 0;
     297
     298        if (devmode) {
     299                ndr_err = ndr_push_struct_blob(&blob, talloc_tos(),
     300                                               devmode,
     301                                               (ndr_push_flags_fn_t)
     302                                               ndr_push_spoolss_DeviceMode);
     303                if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     304                        DEBUG(10, ("pack_devicemode: "
     305                                   "error encoding spoolss_DeviceMode\n"));
     306                        goto done;
     307                }
     308        } else {
     309                ZERO_STRUCT(blob);
     310        }
     311
     312        len = tdb_pack(buf, buflen, "B", blob.length, blob.data);
     313
     314        if (devmode) {
     315                DEBUG(8, ("Packed devicemode [%s]\n", devmode->formname));
     316        }
     317
     318done:
     319        return len;
     320}
     321
     322/****************************************************************************
     323 Unpack the devicemode to store it in a tdb.
     324****************************************************************************/
     325static int unpack_devicemode(TALLOC_CTX *mem_ctx,
     326                      const uint8 *buf, int buflen,
     327                      struct spoolss_DeviceMode **devmode)
     328{
     329        struct spoolss_DeviceMode *dm;
     330        enum ndr_err_code ndr_err;
     331        char *data = NULL;
     332        int data_len = 0;
     333        DATA_BLOB blob;
     334        int len = 0;
     335
     336        *devmode = NULL;
     337
     338        len = tdb_unpack(buf, buflen, "B", &data_len, &data);
     339        if (!data) {
     340                return len;
     341        }
     342
     343        dm = talloc_zero(mem_ctx, struct spoolss_DeviceMode);
     344        if (!dm) {
     345                goto done;
     346        }
     347
     348        blob = data_blob_const(data, data_len);
     349
     350        ndr_err = ndr_pull_struct_blob(&blob, dm, dm,
     351                        (ndr_pull_flags_fn_t)ndr_pull_spoolss_DeviceMode);
     352        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     353                DEBUG(10, ("unpack_devicemode: "
     354                           "error parsing spoolss_DeviceMode\n"));
     355                goto done;
     356        }
     357
     358        DEBUG(8, ("Unpacked devicemode [%s](%s)\n",
     359                  dm->devicename, dm->formname));
     360        if (dm->driverextra_data.data) {
     361                DEBUG(8, ("with a private section of %d bytes\n",
     362                          dm->__driverextra_length));
     363        }
     364
     365        *devmode = dm;
     366
     367done:
     368        SAFE_FREE(data);
     369        return len;
     370}
     371
    277372/***********************************************************************
    278373 unpack a pjob from a tdb buffer
    279374***********************************************************************/
    280375
    281 int unpack_pjob( uint8 *buf, int buflen, struct printjob *pjob )
     376static int unpack_pjob( uint8 *buf, int buflen, struct printjob *pjob )
    282377{
    283378        int     len = 0;
     
    289384                return -1;
    290385
    291         len += tdb_unpack(buf+len, buflen-len, "dddddddddffff",
     386        len += tdb_unpack(buf+len, buflen-len, "dddddddddfffff",
    292387                                &pjpid,
    293388                                &pjsysjob,
     
    302397                                pjob->jobname,
    303398                                pjob->user,
     399                                pjob->clientmachine,
    304400                                pjob->queuename);
    305401
     
    307403                return -1;
    308404
    309         if ( (used = unpack_devicemode(&pjob->nt_devmode, buf+len, buflen-len)) == -1 )
     405        used = unpack_devicemode(NULL, buf+len, buflen-len, &pjob->devmode);
     406        if (used == -1) {
    310407                return -1;
     408        }
    311409
    312410        len += used;
     
    352450        }
    353451
    354         if ( pjob.nt_devmode ) {
    355                 free_nt_devicemode( &pjob.nt_devmode );
    356         }
     452        talloc_free(pjob.devmode);
    357453
    358454        ZERO_STRUCT( pjob );
     
    438534
    439535static const struct {
    440         uint32 lpq_status;
    441         uint32 spoolss_status;
     536        uint32_t lpq_status;
     537        uint32_t spoolss_status;
    442538} lpq_to_spoolss_status_map[] = {
    443539        { LPQ_QUEUED, JOB_STATUS_QUEUED },
     
    452548        { LPQ_BLOCKED, JOB_STATUS_BLOCKED_DEVQ },
    453549        { LPQ_USER_INTERVENTION, JOB_STATUS_USER_INTERVENTION },
    454         { -1, 0 }
     550        { (uint32_t)-1, 0 }
    455551};
    456552
     
    471567}
    472568
    473 static void pjob_store_notify(const char* sharename, uint32 jobid, struct printjob *old_data,
    474                               struct printjob *new_data)
    475 {
    476         bool new_job = False;
    477 
    478         if (!old_data)
    479                 new_job = True;
    480 
    481         /* Job attributes that can't be changed.  We only send
    482            notification for these on a new job. */
     569/***************************************************************************
     570 Append a jobid to the 'jobs changed' list.
     571***************************************************************************/
     572
     573static bool add_to_jobs_changed(struct tdb_print_db *pdb, uint32_t jobid)
     574{
     575        TDB_DATA data;
     576        uint32_t store_jobid;
     577
     578        SIVAL(&store_jobid, 0, jobid);
     579        data.dptr = (uint8 *) &store_jobid;
     580        data.dsize = 4;
     581
     582        DEBUG(10,("add_to_jobs_added: Added jobid %u\n", (unsigned int)jobid ));
     583
     584        return (tdb_append(pdb->tdb, string_tdb_data("INFO/jobs_changed"),
     585                           data) == 0);
     586}
     587
     588/***************************************************************************
     589 Remove a jobid from the 'jobs changed' list.
     590***************************************************************************/
     591
     592static bool remove_from_jobs_changed(const char* sharename, uint32_t jobid)
     593{
     594        struct tdb_print_db *pdb = get_print_db_byname(sharename);
     595        TDB_DATA data, key;
     596        size_t job_count, i;
     597        bool ret = False;
     598        bool gotlock = False;
     599
     600        if (!pdb) {
     601                return False;
     602        }
     603
     604        ZERO_STRUCT(data);
     605
     606        key = string_tdb_data("INFO/jobs_changed");
     607
     608        if (tdb_chainlock_with_timeout(pdb->tdb, key, 5) == -1)
     609                goto out;
     610
     611        gotlock = True;
     612
     613        data = tdb_fetch(pdb->tdb, key);
     614
     615        if (data.dptr == NULL || data.dsize == 0 || (data.dsize % 4 != 0))
     616                goto out;
     617
     618        job_count = data.dsize / 4;
     619        for (i = 0; i < job_count; i++) {
     620                uint32 ch_jobid;
     621
     622                ch_jobid = IVAL(data.dptr, i*4);
     623                if (ch_jobid == jobid) {
     624                        if (i < job_count -1 )
     625                                memmove(data.dptr + (i*4), data.dptr + (i*4) + 4, (job_count - i - 1)*4 );
     626                        data.dsize -= 4;
     627                        if (tdb_store(pdb->tdb, key, data, TDB_REPLACE) == -1)
     628                                goto out;
     629                        break;
     630                }
     631        }
     632
     633        ret = True;
     634  out:
     635
     636        if (gotlock)
     637                tdb_chainunlock(pdb->tdb, key);
     638        SAFE_FREE(data.dptr);
     639        release_print_db(pdb);
     640        if (ret)
     641                DEBUG(10,("remove_from_jobs_changed: removed jobid %u\n", (unsigned int)jobid ));
     642        else
     643                DEBUG(10,("remove_from_jobs_changed: Failed to remove jobid %u\n", (unsigned int)jobid ));
     644        return ret;
     645}
     646
     647static void pjob_store_notify(struct tevent_context *ev,
     648                              struct messaging_context *msg_ctx,
     649                              const char* sharename, uint32 jobid,
     650                              struct printjob *old_data,
     651                              struct printjob *new_data,
     652                              bool *pchanged)
     653{
     654        bool new_job = false;
     655        bool changed = false;
     656
     657        if (old_data == NULL) {
     658                new_job = true;
     659        }
    483660
    484661        /* ACHTUNG!  Due to a bug in Samba's spoolss parsing of the
     
    490667
    491668        if (new_job) {
    492                 notify_job_submitted(sharename, jobid, new_data->starttime);
    493                 notify_job_username(sharename, jobid, new_data->user);
    494         }
    495 
    496         if (new_job || !strequal(old_data->jobname, new_data->jobname))
    497                 notify_job_name(sharename, jobid, new_data->jobname);
    498 
    499         /* Job attributes of a new job or attributes that can be
    500            modified. */
    501 
    502         if (new_job || !strequal(old_data->jobname, new_data->jobname))
    503                 notify_job_name(sharename, jobid, new_data->jobname);
    504 
    505         if (new_job || old_data->status != new_data->status)
    506                 notify_job_status(sharename, jobid, map_to_spoolss_status(new_data->status));
    507 
    508         if (new_job || old_data->size != new_data->size)
    509                 notify_job_total_bytes(sharename, jobid, new_data->size);
    510 
    511         if (new_job || old_data->page_count != new_data->page_count)
    512                 notify_job_total_pages(sharename, jobid, new_data->page_count);
     669                notify_job_submitted(ev, msg_ctx,
     670                                     sharename, jobid, new_data->starttime);
     671                notify_job_username(ev, msg_ctx,
     672                                    sharename, jobid, new_data->user);
     673                notify_job_name(ev, msg_ctx,
     674                                sharename, jobid, new_data->jobname);
     675                notify_job_status(ev, msg_ctx,
     676                                  sharename, jobid, map_to_spoolss_status(new_data->status));
     677                notify_job_total_bytes(ev, msg_ctx,
     678                                       sharename, jobid, new_data->size);
     679                notify_job_total_pages(ev, msg_ctx,
     680                                       sharename, jobid, new_data->page_count);
     681        } else {
     682                if (!strequal(old_data->jobname, new_data->jobname)) {
     683                        notify_job_name(ev, msg_ctx, sharename,
     684                                        jobid, new_data->jobname);
     685                        changed = true;
     686                }
     687
     688                if (old_data->status != new_data->status) {
     689                        notify_job_status(ev, msg_ctx,
     690                                          sharename, jobid,
     691                                          map_to_spoolss_status(new_data->status));
     692                }
     693
     694                if (old_data->size != new_data->size) {
     695                        notify_job_total_bytes(ev, msg_ctx,
     696                                               sharename, jobid, new_data->size);
     697                }
     698
     699                if (old_data->page_count != new_data->page_count) {
     700                        notify_job_total_pages(ev, msg_ctx,
     701                                               sharename, jobid,
     702                                               new_data->page_count);
     703                }
     704        }
     705
     706        *pchanged = changed;
    513707}
    514708
     
    517711****************************************************************************/
    518712
    519 static bool pjob_store(const char* sharename, uint32 jobid, struct printjob *pjob)
     713static bool pjob_store(struct tevent_context *ev,
     714                       struct messaging_context *msg_ctx,
     715                       const char* sharename, uint32 jobid,
     716                       struct printjob *pjob)
    520717{
    521718        uint32_t tmp;
     
    541738                len = 0;
    542739                buflen = newlen;
    543                 len += tdb_pack(buf+len, buflen-len, "dddddddddffff",
     740                len += tdb_pack(buf+len, buflen-len, "dddddddddfffff",
    544741                                (uint32)pjob->pid,
    545742                                (uint32)pjob->sysjob,
     
    554751                                pjob->jobname,
    555752                                pjob->user,
     753                                pjob->clientmachine,
    556754                                pjob->queuename);
    557755
    558                 len += pack_devicemode(pjob->nt_devmode, buf+len, buflen-len);
     756                len += pack_devicemode(pjob->devmode, buf+len, buflen-len);
    559757
    560758                if (buflen != len) {
     
    576774                         TDB_REPLACE) == 0);
    577775
    578         release_print_db(pdb);
    579 
    580776        /* Send notify updates for what has changed */
    581777
    582778        if ( ret ) {
     779                bool changed = false;
    583780                struct printjob old_pjob;
    584781
     
    587784                        if ( unpack_pjob( old_data.dptr, old_data.dsize, &old_pjob ) != -1 )
    588785                        {
    589                                 pjob_store_notify( sharename, jobid, &old_pjob , pjob );
    590                                 free_nt_devicemode( &old_pjob.nt_devmode );
     786                                pjob_store_notify(server_event_context(),
     787                                                  msg_ctx,
     788                                                  sharename, jobid, &old_pjob,
     789                                                  pjob,
     790                                                  &changed);
     791                                talloc_free(old_pjob.devmode);
     792
     793                                if (changed) {
     794                                        add_to_jobs_changed(pdb, jobid);
     795                                }
    591796                        }
     797
    592798                }
    593799                else {
    594800                        /* new job */
    595                         pjob_store_notify( sharename, jobid, NULL, pjob );
    596                 }
    597         }
    598 
     801                        pjob_store_notify(server_event_context(), msg_ctx,
     802                                          sharename, jobid, NULL, pjob,
     803                                          &changed);
     804                }
     805        }
     806
     807        release_print_db(pdb);
    599808done:
    600809        SAFE_FREE( old_data.dptr );
     
    608817****************************************************************************/
    609818
    610 void pjob_delete(const char* sharename, uint32 jobid)
     819static void pjob_delete(struct tevent_context *ev,
     820                        struct messaging_context *msg_ctx,
     821                        const char* sharename, uint32 jobid)
    611822{
    612823        uint32_t tmp;
     
    634845
    635846        job_status = JOB_STATUS_DELETING|JOB_STATUS_DELETED;
    636         notify_job_status(sharename, jobid, job_status);
     847        notify_job_status(ev, msg_ctx, sharename, jobid, job_status);
    637848
    638849        /* Remove from printing.tdb */
    639850
    640851        tdb_delete(pdb->tdb, print_key(jobid, &tmp));
    641         remove_from_jobs_changed(sharename, jobid);
     852        remove_from_jobs_added(sharename, jobid);
    642853        release_print_db( pdb );
    643854        rap_jobid_delete(sharename, jobid);
     
    648859****************************************************************************/
    649860
    650 static void print_unix_job(const char *sharename, print_queue_struct *q, uint32 jobid)
     861static void print_unix_job(struct tevent_context *ev,
     862                           struct messaging_context *msg_ctx,
     863                           const char *sharename, print_queue_struct *q,
     864                           uint32 jobid)
    651865{
    652866        struct printjob pj, *old_pj;
     
    679893        fstrcpy(pj.queuename, old_pj ? old_pj->queuename : sharename );
    680894
    681         pjob_store(sharename, jobid, &pj);
     895        pjob_store(ev, msg_ctx, sharename, jobid, &pj);
    682896}
    683897
     
    690904        const char *lprm_command;
    691905        struct printif *print_if;
     906        struct tevent_context *ev;
     907        struct messaging_context *msg_ctx;
    692908};
    693909
     
    709925        if ( unpack_pjob( data.dptr, data.dsize, &pjob ) == -1 )
    710926                return 0;
    711         free_nt_devicemode( &pjob.nt_devmode );
     927        talloc_free(pjob.devmode);
    712928
    713929
     
    723939                        DEBUG(10,("traverse_fn_delete: pjob %u deleted due to !smbjob\n",
    724940                                                (unsigned int)jobid ));
    725                         pjob_delete(ts->sharename, jobid);
     941                        pjob_delete(ts->ev, ts->msg_ctx,
     942                                    ts->sharename, jobid);
    726943                        return 0;
    727944                }
     
    739956                        DEBUG(10,("traverse_fn_delete: pjob %u deleted due to !process_exists (%u)\n",
    740957                                                (unsigned int)jobid, (unsigned int)pjob.pid ));
    741                         pjob_delete(ts->sharename, jobid);
     958                        pjob_delete(ts->ev, ts->msg_ctx,
     959                                    ts->sharename, jobid);
    742960                } else
    743961                        ts->total_jobs++;
     
    769987                                                /* if we can't delete, then reset the job status */
    770988                                                pjob.status = LPQ_QUEUED;
    771                                                 pjob_store(ts->sharename, jobid, &pjob);
     989                                                pjob_store(ts->ev, ts->msg_ctx,
     990                                                           ts->sharename, jobid, &pjob);
    772991                                        }
    773992                                        else {
    774993                                                /* if we deleted the job, the remove the tdb record */
    775                                                 pjob_delete(ts->sharename, jobid);
     994                                                pjob_delete(ts->ev,
     995                                                            ts->msg_ctx,
     996                                                            ts->sharename, jobid);
    776997                                                pjob.status = LPQ_DELETED;
    777998                                        }
     
    8011022                                                (unsigned int)pjob.starttime,
    8021023                                                (unsigned int)ts->lpq_time ));
    803                         pjob_delete(ts->sharename, jobid);
     1024                        pjob_delete(ts->ev, ts->msg_ctx,
     1025                                    ts->sharename, jobid);
    8041026                } else
    8051027                        ts->total_jobs++;
     
    9981220}
    9991221
    1000 static TDB_DATA get_jobs_changed_data(struct tdb_print_db *pdb)
     1222static TDB_DATA get_jobs_added_data(struct tdb_print_db *pdb)
    10011223{
    10021224        TDB_DATA data;
     
    10041226        ZERO_STRUCT(data);
    10051227
    1006         data = tdb_fetch(pdb->tdb, string_tdb_data("INFO/jobs_changed"));
     1228        data = tdb_fetch(pdb->tdb, string_tdb_data("INFO/jobs_added"));
    10071229        if (data.dptr == NULL || data.dsize == 0 || (data.dsize % 4 != 0)) {
    10081230                SAFE_FREE(data.dptr);
     
    10131235}
    10141236
    1015 static void check_job_changed(const char *sharename, TDB_DATA data, uint32 jobid)
     1237static void check_job_added(const char *sharename, TDB_DATA data, uint32 jobid)
    10161238{
    10171239        unsigned int i;
     
    10231245                ch_jobid = IVAL(data.dptr, i*4);
    10241246                if (ch_jobid == jobid)
    1025                         remove_from_jobs_changed(sharename, jobid);
     1247                        remove_from_jobs_added(sharename, jobid);
    10261248        }
    10271249}
     
    10931315
    10941316/****************************************************************************
    1095  main work for updating the lpq cahe for a printer queue
    1096 ****************************************************************************/
    1097 
    1098 static void print_queue_update_internal( const char *sharename,
     1317 main work for updating the lpq cache for a printer queue
     1318****************************************************************************/
     1319
     1320static void print_queue_update_internal( struct tevent_context *ev,
     1321                                         struct messaging_context *msg_ctx,
     1322                                         const char *sharename,
    10991323                                         struct printif *current_printif,
    11001324                                         char *lpq_command, char *lprm_command )
     
    11401364           in hash order. */
    11411365
    1142         qsort(queue, qcount, sizeof(print_queue_struct),
    1143                 QSORT_CAST(printjob_comp));
     1366        TYPESAFE_QSORT(queue, qcount, printjob_comp);
    11441367
    11451368        /*
     
    11541377        */
    11551378
    1156         jcdata = get_jobs_changed_data(pdb);
     1379        jcdata = get_jobs_added_data(pdb);
    11571380
    11581381        for (i=0; i<qcount; i++) {
     
    11611384                if (jobid == (uint32)-1) {
    11621385                        /* assume its a unix print job */
    1163                         print_unix_job(sharename, &queue[i], jobid);
     1386                        print_unix_job(ev, msg_ctx,
     1387                                       sharename, &queue[i], jobid);
    11641388                        continue;
    11651389                }
     
    11711395                           with jobs in the queue. All we can do is treat them
    11721396                           like unix jobs. Pity. */
    1173                         print_unix_job(sharename, &queue[i], jobid);
     1397                        print_unix_job(ev, msg_ctx,
     1398                                       sharename, &queue[i], jobid);
    11741399                        continue;
    11751400                }
     
    11821407                        pjob->status = queue[i].status;
    11831408
    1184                 pjob_store(sharename, jobid, pjob);
    1185 
    1186                 check_job_changed(sharename, jcdata, jobid);
     1409                pjob_store(ev, msg_ctx, sharename, jobid, pjob);
     1410
     1411                check_job_added(sharename, jcdata, jobid);
    11871412        }
    11881413
     
    11991424        tstruct.lprm_command = lprm_command;
    12001425        tstruct.print_if = current_printif;
     1426        tstruct.ev = ev;
     1427        tstruct.msg_ctx = msg_ctx;
    12011428
    12021429        tdb_traverse(pdb->tdb, traverse_fn_delete, (void *)&tstruct);
     
    12561483****************************************************************************/
    12571484
    1258 static void print_queue_update_with_lock( const char *sharename,
     1485static void print_queue_update_with_lock( struct tevent_context *ev,
     1486                                          struct messaging_context *msg_ctx,
     1487                                          const char *sharename,
    12591488                                          struct printif *current_printif,
    12601489                                          char *lpq_command, char *lprm_command )
     
    13251554        /* do the main work now */
    13261555
    1327         print_queue_update_internal( sharename, current_printif,
    1328                 lpq_command, lprm_command );
     1556        print_queue_update_internal(ev, msg_ctx,
     1557                                    sharename, current_printif,
     1558                                    lpq_command, lprm_command);
    13291559
    13301560        /* Delete our pid from the db. */
     
    13361566this is the receive function of the background lpq updater
    13371567****************************************************************************/
    1338 static void print_queue_receive(struct messaging_context *msg,
     1568void print_queue_receive(struct messaging_context *msg,
    13391569                                void *private_data,
    13401570                                uint32_t msg_type,
     
    13601590        }
    13611591
    1362         print_queue_update_with_lock(sharename,
     1592        print_queue_update_with_lock(server_event_context(), msg, sharename,
    13631593                get_printer_fns_from_type((enum printing_types)printing_type),
    13641594                lpqcommand, lprmcommand );
     
    13811611}
    13821612
     1613extern struct child_pid *children;
     1614extern int num_children;
     1615
    13831616static void add_child_pid(pid_t pid)
    13841617{
    1385         extern struct child_pid *children;
    13861618        struct child_pid *child;
    1387         extern int num_children;
    13881619
    13891620        child = SMB_MALLOC_P(struct child_pid);
     
    14021633main thread of the background lpq updater
    14031634****************************************************************************/
    1404 void start_background_queue(void)
     1635void start_background_queue(struct tevent_context *ev,
     1636                            struct messaging_context *msg_ctx)
    14051637{
    14061638        /* Use local variables for this as we don't
     
    14301662                struct tevent_fd *fde;
    14311663                int ret;
     1664                NTSTATUS status;
    14321665
    14331666                /* Child. */
     
    14371670                pause_pipe[0] = -1;
    14381671
    1439                 if (!NT_STATUS_IS_OK(reinit_after_fork(smbd_messaging_context(),
    1440                                                        smbd_event_context(),
    1441                                                        true))) {
     1672                status = reinit_after_fork(msg_ctx, ev, procid_self(), true);
     1673
     1674                if (!NT_STATUS_IS_OK(status)) {
    14421675                        DEBUG(0,("reinit_after_fork() failed\n"));
    14431676                        smb_panic("reinit_after_fork() failed");
     
    14451678
    14461679                smbd_setup_sig_term_handler();
    1447                 smbd_setup_sig_hup_handler();
    1448 
    1449                 claim_connection( NULL, "smbd lpq backend",
    1450                         FLAG_MSG_GENERAL|FLAG_MSG_SMBD|FLAG_MSG_PRINT_GENERAL);
     1680                smbd_setup_sig_hup_handler(ev, msg_ctx);
     1681
     1682                if (!serverid_register(procid_self(),
     1683                                       FLAG_MSG_GENERAL|FLAG_MSG_SMBD
     1684                                       |FLAG_MSG_PRINT_GENERAL)) {
     1685                        exit(1);
     1686                }
    14511687
    14521688                if (!locking_init()) {
     
    14541690                }
    14551691
    1456                 messaging_register(smbd_messaging_context(), NULL,
    1457                                    MSG_PRINTER_UPDATE, print_queue_receive);
    1458 
    1459                 fde = tevent_add_fd(smbd_event_context(), smbd_event_context(),
    1460                                     pause_pipe[1], TEVENT_FD_READ,
     1692                messaging_register(msg_ctx, NULL, MSG_PRINTER_UPDATE,
     1693                                   print_queue_receive);
     1694
     1695                fde = tevent_add_fd(ev, ev, pause_pipe[1], TEVENT_FD_READ,
    14611696                                    printing_pause_fd_handler,
    14621697                                    NULL);
     
    14671702
    14681703                DEBUG(5,("start_background_queue: background LPQ thread waiting for messages\n"));
    1469                 ret = tevent_loop_wait(smbd_event_context());
     1704                ret = tevent_loop_wait(ev);
    14701705                /* should not be reached */
    14711706                DEBUG(0,("background_queue: tevent_loop_wait() exited with %d - %s\n",
     
    14811716****************************************************************************/
    14821717
    1483 static void print_queue_update(int snum, bool force)
     1718static void print_queue_update(struct messaging_context *msg_ctx,
     1719                               int snum, bool force)
    14841720{
    14851721        fstring key;
     
    15021738                        lp_lpqcommand(snum),
    15031739                        "%p",
    1504                         PRINTERNAME(snum),
     1740                        lp_printername(snum),
    15051741                        false, false, false);
    15061742        if (!lpqcommand) {
     
    15221758                        lp_lprmcommand(snum),
    15231759                        "%p",
    1524                         PRINTERNAME(snum),
     1760                        lp_printername(snum),
    15251761                        false, false, false);
    15261762        if (!lprmcommand) {
     
    15471783                DEBUG(4,("print_queue_update: updating queue [%s] myself\n", sharename));
    15481784                current_printif = get_printer_fns( snum );
    1549                 print_queue_update_with_lock( sharename, current_printif, lpqcommand, lprmcommand );
     1785                print_queue_update_with_lock(server_event_context(), msg_ctx,
     1786                                             sharename, current_printif,
     1787                                             lpqcommand, lprmcommand);
    15501788
    15511789                return;
     
    16001838        /* finally send the message */
    16011839
    1602         messaging_send_buf(smbd_messaging_context(),
    1603                            pid_to_procid(background_lpq_updater_pid),
     1840        messaging_send_buf(msg_ctx, pid_to_procid(background_lpq_updater_pid),
    16041841                           MSG_PRINTER_UPDATE, (uint8 *)buffer, len);
    16051842
     
    18082045
    18092046/****************************************************************************
    1810  Give the fd used for a jobid.
    1811 ****************************************************************************/
    1812 
    1813 int print_job_fd(const char* sharename, uint32 jobid)
    1814 {
    1815         struct printjob *pjob = print_job_find(sharename, jobid);
    1816         if (!pjob)
    1817                 return -1;
    1818         /* don't allow another process to get this info - it is meaningless */
    1819         if (pjob->pid != sys_getpid())
    1820                 return -1;
    1821         return pjob->fd;
    1822 }
    1823 
    1824 /****************************************************************************
    18252047 Give the filename used for a jobid.
    18262048 Only valid for the process doing the spooling and when the job
     
    18432065****************************************************************************/
    18442066
    1845 NT_DEVICEMODE *print_job_devmode(const char* sharename, uint32 jobid)
     2067struct spoolss_DeviceMode *print_job_devmode(const char* sharename, uint32 jobid)
    18462068{
    18472069        struct printjob *pjob = print_job_find(sharename, jobid);
     
    18502072                return NULL;
    18512073
    1852         return pjob->nt_devmode;
    1853 }
    1854 
    1855 /****************************************************************************
    1856  Set the place in the queue for a job.
    1857 ****************************************************************************/
    1858 
    1859 bool print_job_set_place(const char *sharename, uint32 jobid, int place)
    1860 {
    1861         DEBUG(2,("print_job_set_place not implemented yet\n"));
    1862         return False;
     2074        return pjob->devmode;
    18632075}
    18642076
     
    18672079****************************************************************************/
    18682080
    1869 bool print_job_set_name(const char *sharename, uint32 jobid, char *name)
     2081bool print_job_set_name(struct tevent_context *ev,
     2082                        struct messaging_context *msg_ctx,
     2083                        const char *sharename, uint32 jobid, const char *name)
    18702084{
    18712085        struct printjob *pjob;
     
    18762090
    18772091        fstrcpy(pjob->jobname, name);
    1878         return pjob_store(sharename, jobid, pjob);
    1879 }
     2092        return pjob_store(ev, msg_ctx, sharename, jobid, pjob);
     2093}
     2094
     2095/****************************************************************************
     2096 Get the name of a job. Only possible for owner.
     2097****************************************************************************/
     2098
     2099bool print_job_get_name(TALLOC_CTX *mem_ctx, const char *sharename, uint32_t jobid, char **name)
     2100{
     2101        struct printjob *pjob;
     2102
     2103        pjob = print_job_find(sharename, jobid);
     2104        if (!pjob || pjob->pid != sys_getpid()) {
     2105                return false;
     2106        }
     2107
     2108        *name = talloc_strdup(mem_ctx, pjob->jobname);
     2109        if (!*name) {
     2110                return false;
     2111        }
     2112
     2113        return true;
     2114}
     2115
    18802116
    18812117/***************************************************************************
    1882  Remove a jobid from the 'jobs changed' list.
     2118 Remove a jobid from the 'jobs added' list.
    18832119***************************************************************************/
    18842120
    1885 static bool remove_from_jobs_changed(const char* sharename, uint32 jobid)
     2121static bool remove_from_jobs_added(const char* sharename, uint32 jobid)
    18862122{
    18872123        struct tdb_print_db *pdb = get_print_db_byname(sharename);
     
    18972133        ZERO_STRUCT(data);
    18982134
    1899         key = string_tdb_data("INFO/jobs_changed");
     2135        key = string_tdb_data("INFO/jobs_added");
    19002136
    19012137        if (tdb_chainlock_with_timeout(pdb->tdb, key, 5) == -1)
     
    19322168        release_print_db(pdb);
    19332169        if (ret)
    1934                 DEBUG(10,("remove_from_jobs_changed: removed jobid %u\n", (unsigned int)jobid ));
     2170                DEBUG(10,("remove_from_jobs_added: removed jobid %u\n", (unsigned int)jobid ));
    19352171        else
    1936                 DEBUG(10,("remove_from_jobs_changed: Failed to remove jobid %u\n", (unsigned int)jobid ));
     2172                DEBUG(10,("remove_from_jobs_added: Failed to remove jobid %u\n", (unsigned int)jobid ));
    19372173        return ret;
    19382174}
     
    19422178****************************************************************************/
    19432179
    1944 static bool print_job_delete1(int snum, uint32 jobid)
     2180static bool print_job_delete1(struct tevent_context *ev,
     2181                              struct messaging_context *msg_ctx,
     2182                              int snum, uint32 jobid)
    19452183{
    19462184        const char* sharename = lp_const_servicename(snum);
     
    19712209
    19722210        pjob->status = LPQ_DELETING;
    1973         pjob_store(sharename, jobid, pjob);
     2211        pjob_store(ev, msg_ctx, sharename, jobid, pjob);
    19742212
    19752213        if (pjob->spooled && pjob->sysjob != -1)
    19762214        {
    19772215                result = (*(current_printif->job_delete))(
    1978                         PRINTERNAME(snum),
     2216                        lp_printername(snum),
    19792217                        lp_lprmcommand(snum),
    19802218                        pjob);
     
    19892227                        if (!pdb)
    19902228                                return False;
    1991                         pjob_delete(sharename, jobid);
     2229                        pjob_delete(ev, msg_ctx, sharename, jobid);
    19922230                        /* Ensure we keep a rough count of the number of total jobs... */
    19932231                        tdb_change_int32_atomic(pdb->tdb, "INFO/total_jobs", &njobs, -1);
     
    19962234        }
    19972235
    1998         remove_from_jobs_changed( sharename, jobid );
     2236        remove_from_jobs_added( sharename, jobid );
    19992237
    20002238        return (result == 0);
     
    20052243****************************************************************************/
    20062244
    2007 static bool is_owner(struct auth_serversupplied_info *server_info,
     2245static bool is_owner(const struct auth_serversupplied_info *server_info,
    20082246                     const char *servicename,
    20092247                     uint32 jobid)
     
    20212259****************************************************************************/
    20222260
    2023 bool print_job_delete(struct auth_serversupplied_info *server_info, int snum,
    2024                       uint32 jobid, WERROR *errcode)
    2025 {
    2026         const char* sharename = lp_const_servicename( snum );
     2261WERROR print_job_delete(const struct auth_serversupplied_info *server_info,
     2262                        struct messaging_context *msg_ctx,
     2263                        int snum, uint32_t jobid)
     2264{
     2265        const char* sharename = lp_const_servicename(snum);
    20272266        struct printjob *pjob;
    20282267        bool    owner;
    20292268        char    *fname;
    20302269
    2031         *errcode = WERR_OK;
    2032 
    20332270        owner = is_owner(server_info, lp_const_servicename(snum), jobid);
    20342271
     
    20372274
    20382275        if (!owner &&
    2039             !print_access_check(server_info, snum, JOB_ACCESS_ADMINISTER)) {
     2276            !print_access_check(server_info, msg_ctx, snum,
     2277                                JOB_ACCESS_ADMINISTER)) {
    20402278                DEBUG(3, ("delete denied by security descriptor\n"));
    2041                 *errcode = WERR_ACCESS_DENIED;
    20422279
    20432280                /* BEGIN_ADMIN_LOG */
     
    20462283pause, or resume print job. User name: %s. Printer name: %s.",
    20472284                              uidtoname(server_info->utok.uid),
    2048                               PRINTERNAME(snum) );
     2285                              lp_printername(snum) );
    20492286                /* END_ADMIN_LOG */
    20502287
    2051                 return False;
     2288                return WERR_ACCESS_DENIED;
    20522289        }
    20532290
     
    20592296         */
    20602297
    2061         if ( (fname = print_job_fname( sharename, jobid )) != NULL )
    2062         {
     2298        fname = print_job_fname(sharename, jobid);
     2299        if (fname != NULL) {
    20632300                /* remove the spool file */
    2064                 DEBUG(10,("print_job_delete: Removing spool file [%s]\n", fname ));
    2065                 if ( unlink( fname ) == -1 ) {
    2066                         *errcode = map_werror_from_unix(errno);
    2067                         return False;
    2068                 }
    2069         }
    2070 
    2071         if (!print_job_delete1(snum, jobid)) {
    2072                 *errcode = WERR_ACCESS_DENIED;
    2073                 return False;
     2301                DEBUG(10, ("print_job_delete: "
     2302                           "Removing spool file [%s]\n", fname));
     2303                if (unlink(fname) == -1) {
     2304                        return map_werror_from_unix(errno);
     2305                }
     2306        }
     2307
     2308        if (!print_job_delete1(server_event_context(), msg_ctx, snum, jobid)) {
     2309                return WERR_ACCESS_DENIED;
    20742310        }
    20752311
     
    20772313           job still exists */
    20782314
    2079         print_queue_update(snum, True);
     2315        print_queue_update(msg_ctx, snum, True);
    20802316
    20812317        pjob = print_job_find(sharename, jobid);
    2082         if ( pjob && (pjob->status != LPQ_DELETING) )
    2083                 *errcode = WERR_ACCESS_DENIED;
    2084 
    2085         return (pjob == NULL );
     2318        if (pjob && (pjob->status != LPQ_DELETING)) {
     2319                return WERR_ACCESS_DENIED;
     2320        }
     2321
     2322        return WERR_PRINTER_HAS_JOBS_QUEUED;
    20862323}
    20872324
     
    20902327****************************************************************************/
    20912328
    2092 bool print_job_pause(struct auth_serversupplied_info *server_info, int snum,
    2093                      uint32 jobid, WERROR *errcode)
     2329bool print_job_pause(const struct auth_serversupplied_info *server_info,
     2330                     struct messaging_context *msg_ctx,
     2331                     int snum, uint32 jobid, WERROR *errcode)
    20942332{
    20952333        const char* sharename = lp_const_servicename(snum);
     
    21132351
    21142352        if (!is_owner(server_info, lp_const_servicename(snum), jobid) &&
    2115             !print_access_check(server_info, snum, JOB_ACCESS_ADMINISTER)) {
     2353            !print_access_check(server_info, msg_ctx, snum,
     2354                                JOB_ACCESS_ADMINISTER)) {
    21162355                DEBUG(3, ("pause denied by security descriptor\n"));
    21172356
     
    21212360pause, or resume print job. User name: %s. Printer name: %s.",
    21222361                              uidtoname(server_info->utok.uid),
    2123                               PRINTERNAME(snum) );
     2362                              lp_printername(snum) );
    21242363                /* END_ADMIN_LOG */
    21252364
     
    21412380        /* Send a printer notify message */
    21422381
    2143         notify_job_status(sharename, jobid, JOB_STATUS_PAUSED);
     2382        notify_job_status(server_event_context(), msg_ctx, sharename, jobid,
     2383                          JOB_STATUS_PAUSED);
    21442384
    21452385        /* how do we tell if this succeeded? */
     
    21522392****************************************************************************/
    21532393
    2154 bool print_job_resume(struct auth_serversupplied_info *server_info, int snum,
    2155                       uint32 jobid, WERROR *errcode)
     2394bool print_job_resume(const struct auth_serversupplied_info *server_info,
     2395                      struct messaging_context *msg_ctx,
     2396                      int snum, uint32 jobid, WERROR *errcode)
    21562397{
    21572398        const char *sharename = lp_const_servicename(snum);
     
    21752416
    21762417        if (!is_owner(server_info, lp_const_servicename(snum), jobid) &&
    2177             !print_access_check(server_info, snum, JOB_ACCESS_ADMINISTER)) {
     2418            !print_access_check(server_info, msg_ctx, snum,
     2419                                JOB_ACCESS_ADMINISTER)) {
    21782420                DEBUG(3, ("resume denied by security descriptor\n"));
    21792421                *errcode = WERR_ACCESS_DENIED;
     
    21842426pause, or resume print job. User name: %s. Printer name: %s.",
    21852427                              uidtoname(server_info->utok.uid),
    2186                               PRINTERNAME(snum) );
     2428                              lp_printername(snum) );
    21872429                /* END_ADMIN_LOG */
    21882430                return False;
     
    22012443        /* Send a printer notify message */
    22022444
    2203         notify_job_status(sharename, jobid, JOB_STATUS_QUEUED);
     2445        notify_job_status(server_event_context(), msg_ctx, sharename, jobid,
     2446                          JOB_STATUS_QUEUED);
    22042447
    22052448        return True;
     
    22102453****************************************************************************/
    22112454
    2212 ssize_t print_job_write(int snum, uint32 jobid, const char *buf, SMB_OFF_T pos, size_t size)
     2455ssize_t print_job_write(struct tevent_context *ev,
     2456                        struct messaging_context *msg_ctx,
     2457                        int snum, uint32 jobid, const char *buf, size_t size)
    22132458{
    22142459        const char* sharename = lp_const_servicename(snum);
    2215         int return_code;
     2460        ssize_t return_code;
    22162461        struct printjob *pjob;
    22172462
     
    22242469                return -1;
    22252470
    2226         return_code = write_data_at_offset(pjob->fd, buf, size, pos);
     2471        /* if SMBD is spooling this can't be allowed */
     2472        if (pjob->status == PJOB_SMBD_SPOOLING) {
     2473                return -1;
     2474        }
     2475
     2476        return_code = write_data(pjob->fd, buf, size);
    22272477
    22282478        if (return_code>0) {
    22292479                pjob->size += size;
    2230                 pjob_store(sharename, jobid, pjob);
     2480                pjob_store(ev, msg_ctx, sharename, jobid, pjob);
    22312481        }
    22322482        return return_code;
     
    22712521****************************************************************************/
    22722522
    2273 int print_queue_length(int snum, print_status_struct *pstatus)
     2523int print_queue_length(struct messaging_context *msg_ctx, int snum,
     2524                       print_status_struct *pstatus)
    22742525{
    22752526        const char* sharename = lp_const_servicename( snum );
     
    22812532        /* make sure the database is up to date */
    22822533        if (print_cache_expired(lp_const_servicename(snum), True))
    2283                 print_queue_update(snum, False);
     2534                print_queue_update(msg_ctx, snum, False);
    22842535
    22852536        /* also fetch the queue status */
     
    22972548***************************************************************************/
    22982549
    2299 static bool allocate_print_jobid(struct tdb_print_db *pdb, int snum, const char *sharename, uint32 *pjobid)
     2550static WERROR allocate_print_jobid(struct tdb_print_db *pdb, int snum,
     2551                                   const char *sharename, uint32 *pjobid)
    23002552{
    23012553        int i;
    23022554        uint32 jobid;
     2555        enum TDB_ERROR terr;
     2556        int ret;
    23032557
    23042558        *pjobid = (uint32)-1;
     
    23062560        for (i = 0; i < 3; i++) {
    23072561                /* Lock the database - only wait 20 seconds. */
    2308                 if (tdb_lock_bystring_with_timeout(pdb->tdb, "INFO/nextjob", 20) == -1) {
    2309                         DEBUG(0,("allocate_print_jobid: failed to lock printing database %s\n", sharename));
    2310                         return False;
     2562                ret = tdb_lock_bystring_with_timeout(pdb->tdb,
     2563                                                     "INFO/nextjob", 20);
     2564                if (ret == -1) {
     2565                        DEBUG(0, ("allocate_print_jobid: "
     2566                                  "Failed to lock printing database %s\n",
     2567                                  sharename));
     2568                        terr = tdb_error(pdb->tdb);
     2569                        return ntstatus_to_werror(map_nt_error_from_tdb(terr));
    23112570                }
    23122571
    23132572                if (!tdb_fetch_uint32(pdb->tdb, "INFO/nextjob", &jobid)) {
    2314                         if (tdb_error(pdb->tdb) != TDB_ERR_NOEXIST) {
    2315                                 DEBUG(0, ("allocate_print_jobid: failed to fetch INFO/nextjob for print queue %s\n",
    2316                                         sharename));
     2573                        terr = tdb_error(pdb->tdb);
     2574                        if (terr != TDB_ERR_NOEXIST) {
     2575                                DEBUG(0, ("allocate_print_jobid: "
     2576                                          "Failed to fetch INFO/nextjob "
     2577                                          "for print queue %s\n", sharename));
    23172578                                tdb_unlock_bystring(pdb->tdb, "INFO/nextjob");
    2318                                 return False;
     2579                                return ntstatus_to_werror(map_nt_error_from_tdb(terr));
    23192580                        }
    2320                         DEBUG(10,("allocate_print_jobid: no existing jobid in %s\n", sharename));
     2581                        DEBUG(10, ("allocate_print_jobid: "
     2582                                   "No existing jobid in %s\n", sharename));
    23212583                        jobid = 0;
    23222584                }
    23232585
    2324                 DEBUG(10,("allocate_print_jobid: read jobid %u from %s\n", jobid, sharename));
     2586                DEBUG(10, ("allocate_print_jobid: "
     2587                           "Read jobid %u from %s\n", jobid, sharename));
    23252588
    23262589                jobid = NEXT_JOBID(jobid);
    23272590
    2328                 if (tdb_store_int32(pdb->tdb, "INFO/nextjob", jobid)==-1) {
    2329                         DEBUG(3, ("allocate_print_jobid: failed to store INFO/nextjob.\n"));
     2591                ret = tdb_store_int32(pdb->tdb, "INFO/nextjob", jobid);
     2592                if (ret == -1) {
     2593                        terr = tdb_error(pdb->tdb);
     2594                        DEBUG(3, ("allocate_print_jobid: "
     2595                                  "Failed to store INFO/nextjob.\n"));
    23302596                        tdb_unlock_bystring(pdb->tdb, "INFO/nextjob");
    2331                         return False;
     2597                        return ntstatus_to_werror(map_nt_error_from_tdb(terr));
    23322598                }
    23332599
     
    23382604                        break;
    23392605                }
    2340                 DEBUG(10,("allocate_print_jobid: found jobid %u in %s\n", jobid, sharename));
     2606                DEBUG(10, ("allocate_print_jobid: "
     2607                           "Found jobid %u in %s\n", jobid, sharename));
    23412608        }
    23422609
    23432610        if (i > 2) {
    2344                 DEBUG(0, ("allocate_print_jobid: failed to allocate a print job for queue %s\n",
    2345                         sharename));
     2611                DEBUG(0, ("allocate_print_jobid: "
     2612                          "Failed to allocate a print job for queue %s\n",
     2613                          sharename));
    23462614                /* Probably full... */
    2347                 errno = ENOSPC;
    2348                 return False;
     2615                return WERR_NO_SPOOL_SPACE;
    23492616        }
    23502617
     
    23572624                if (tdb_store(pdb->tdb, print_key(jobid, &tmp), dum,
    23582625                              TDB_INSERT) == -1) {
    2359                         DEBUG(3, ("allocate_print_jobid: jobid (%d) failed to store placeholder.\n",
    2360                                 jobid ));
    2361                         return False;
     2626                        DEBUG(3, ("allocate_print_jobid: "
     2627                                  "jobid (%d) failed to store placeholder.\n",
     2628                                  jobid ));
     2629                        terr = tdb_error(pdb->tdb);
     2630                        return ntstatus_to_werror(map_nt_error_from_tdb(terr));
    23622631                }
    23632632        }
    23642633
    23652634        *pjobid = jobid;
    2366         return True;
     2635        return WERR_OK;
    23672636}
    23682637
    23692638/***************************************************************************
    2370  Append a jobid to the 'jobs changed' list.
     2639 Append a jobid to the 'jobs added' list.
    23712640***************************************************************************/
    23722641
    2373 static bool add_to_jobs_changed(struct tdb_print_db *pdb, uint32 jobid)
     2642static bool add_to_jobs_added(struct tdb_print_db *pdb, uint32 jobid)
    23742643{
    23752644        TDB_DATA data;
     
    23802649        data.dsize = 4;
    23812650
    2382         DEBUG(10,("add_to_jobs_changed: Added jobid %u\n", (unsigned int)jobid ));
    2383 
    2384         return (tdb_append(pdb->tdb, string_tdb_data("INFO/jobs_changed"),
     2651        DEBUG(10,("add_to_jobs_added: Added jobid %u\n", (unsigned int)jobid ));
     2652
     2653        return (tdb_append(pdb->tdb, string_tdb_data("INFO/jobs_added"),
    23852654                           data) == 0);
     2655}
     2656
     2657
     2658/***************************************************************************
     2659 Do all checks needed to determine if we can start a job.
     2660***************************************************************************/
     2661
     2662static WERROR print_job_checks(const struct auth_serversupplied_info *server_info,
     2663                               struct messaging_context *msg_ctx,
     2664                               int snum, int *njobs)
     2665{
     2666        const char *sharename = lp_const_servicename(snum);
     2667        uint64_t dspace, dsize;
     2668        uint64_t minspace;
     2669        int ret;
     2670
     2671        if (!print_access_check(server_info, msg_ctx, snum,
     2672                                PRINTER_ACCESS_USE)) {
     2673                DEBUG(3, ("print_job_checks: "
     2674                          "job start denied by security descriptor\n"));
     2675                return WERR_ACCESS_DENIED;
     2676        }
     2677
     2678        if (!print_time_access_check(server_info, msg_ctx, sharename)) {
     2679                DEBUG(3, ("print_job_checks: "
     2680                          "job start denied by time check\n"));
     2681                return WERR_ACCESS_DENIED;
     2682        }
     2683
     2684        /* see if we have sufficient disk space */
     2685        if (lp_minprintspace(snum)) {
     2686                minspace = lp_minprintspace(snum);
     2687                ret = sys_fsusage(lp_pathname(snum), &dspace, &dsize);
     2688                if (ret == 0 && dspace < 2*minspace) {
     2689                        DEBUG(3, ("print_job_checks: "
     2690                                  "disk space check failed.\n"));
     2691                        return WERR_NO_SPOOL_SPACE;
     2692                }
     2693        }
     2694
     2695        /* for autoloaded printers, check that the printcap entry still exists */
     2696        if (lp_autoloaded(snum) && !pcap_printername_ok(sharename)) {
     2697                DEBUG(3, ("print_job_checks: printer name %s check failed.\n",
     2698                          sharename));
     2699                return WERR_ACCESS_DENIED;
     2700        }
     2701
     2702        /* Insure the maximum queue size is not violated */
     2703        *njobs = print_queue_length(msg_ctx, snum, NULL);
     2704        if (*njobs > lp_maxprintjobs(snum)) {
     2705                DEBUG(3, ("print_job_checks: Queue %s number of jobs (%d) "
     2706                          "larger than max printjobs per queue (%d).\n",
     2707                          sharename, *njobs, lp_maxprintjobs(snum)));
     2708                return WERR_NO_SPOOL_SPACE;
     2709        }
     2710
     2711        return WERR_OK;
     2712}
     2713
     2714/***************************************************************************
     2715 Create a job file.
     2716***************************************************************************/
     2717
     2718static WERROR print_job_spool_file(int snum, uint32_t jobid,
     2719                                   const char *output_file,
     2720                                   struct printjob *pjob)
     2721{
     2722        WERROR werr;
     2723        SMB_STRUCT_STAT st;
     2724        const char *path;
     2725        int len;
     2726
     2727        /* if this file is within the printer path, it means that smbd
     2728         * is spooling it and will pass us control when it is finished.
     2729         * Verify that the file name is ok, within path, and it is
     2730         * already already there */
     2731        if (output_file) {
     2732                path = lp_pathname(snum);
     2733                len = strlen(path);
     2734                if (strncmp(output_file, path, len) == 0 &&
     2735                    (output_file[len - 1] == '/' || output_file[len] == '/')) {
     2736
     2737                        /* verify path is not too long */
     2738                        if (strlen(output_file) >= sizeof(pjob->filename)) {
     2739                                return WERR_INVALID_NAME;
     2740                        }
     2741
     2742                        /* verify that the file exists */
     2743                        if (sys_stat(output_file, &st, false) != 0) {
     2744                                return WERR_INVALID_NAME;
     2745                        }
     2746
     2747                        fstrcpy(pjob->filename, output_file);
     2748
     2749                        DEBUG(3, ("print_job_spool_file:"
     2750                                  "External spooling activated"));
     2751
     2752                        /* we do not open the file until spooling is done */
     2753                        pjob->fd = -1;
     2754                        pjob->status = PJOB_SMBD_SPOOLING;
     2755
     2756                        return WERR_OK;
     2757                }
     2758        }
     2759
     2760        slprintf(pjob->filename, sizeof(pjob->filename)-1,
     2761                 "%s/%s%.8u.XXXXXX", lp_pathname(snum),
     2762                 PRINT_SPOOL_PREFIX, (unsigned int)jobid);
     2763        pjob->fd = mkstemp(pjob->filename);
     2764
     2765        if (pjob->fd == -1) {
     2766                werr = map_werror_from_unix(errno);
     2767                if (W_ERROR_EQUAL(werr, WERR_ACCESS_DENIED)) {
     2768                        /* Common setup error, force a report. */
     2769                        DEBUG(0, ("print_job_spool_file: "
     2770                                  "insufficient permissions to open spool "
     2771                                  "file %s.\n", pjob->filename));
     2772                } else {
     2773                        /* Normal case, report at level 3 and above. */
     2774                        DEBUG(3, ("print_job_spool_file: "
     2775                                  "can't open spool file %s\n",
     2776                                  pjob->filename));
     2777                }
     2778                return werr;
     2779        }
     2780
     2781        return WERR_OK;
    23862782}
    23872783
     
    23902786***************************************************************************/
    23912787
    2392 uint32 print_job_start(struct auth_serversupplied_info *server_info, int snum,
    2393                        const char *jobname, NT_DEVICEMODE *nt_devmode )
    2394 {
    2395         uint32 jobid;
     2788WERROR print_job_start(const struct auth_serversupplied_info *server_info,
     2789                       struct messaging_context *msg_ctx,
     2790                       const char *clientmachine,
     2791                       int snum, const char *docname, const char *filename,
     2792                       struct spoolss_DeviceMode *devmode, uint32_t *_jobid)
     2793{
     2794        uint32_t jobid;
    23962795        char *path;
    23972796        struct printjob pjob;
     
    23992798        struct tdb_print_db *pdb = get_print_db_byname(sharename);
    24002799        int njobs;
    2401 
    2402         errno = 0;
    2403 
    2404         if (!pdb)
    2405                 return (uint32)-1;
    2406 
    2407         if (!print_access_check(server_info, snum, PRINTER_ACCESS_USE)) {
    2408                 DEBUG(3, ("print_job_start: job start denied by security descriptor\n"));
     2800        WERROR werr;
     2801
     2802        if (!pdb) {
     2803                return WERR_INTERNAL_DB_CORRUPTION;
     2804        }
     2805
     2806        path = lp_pathname(snum);
     2807
     2808        werr = print_job_checks(server_info, msg_ctx, snum, &njobs);
     2809        if (!W_ERROR_IS_OK(werr)) {
    24092810                release_print_db(pdb);
    2410                 return (uint32)-1;
    2411         }
    2412 
    2413         if (!print_time_access_check(lp_servicename(snum))) {
    2414                 DEBUG(3, ("print_job_start: job start denied by time check\n"));
    2415                 release_print_db(pdb);
    2416                 return (uint32)-1;
    2417         }
    2418 
    2419         path = lp_pathname(snum);
    2420 
    2421         /* see if we have sufficient disk space */
    2422         if (lp_minprintspace(snum)) {
    2423                 uint64_t dspace, dsize;
    2424                 if (sys_fsusage(path, &dspace, &dsize) == 0 &&
    2425                     dspace < 2*(uint64_t)lp_minprintspace(snum)) {
    2426                         DEBUG(3, ("print_job_start: disk space check failed.\n"));
    2427                         release_print_db(pdb);
    2428                         errno = ENOSPC;
    2429                         return (uint32)-1;
    2430                 }
    2431         }
    2432 
    2433         /* for autoloaded printers, check that the printcap entry still exists */
    2434         if (lp_autoloaded(snum) && !pcap_printername_ok(lp_const_servicename(snum))) {
    2435                 DEBUG(3, ("print_job_start: printer name %s check failed.\n", lp_const_servicename(snum) ));
    2436                 release_print_db(pdb);
    2437                 errno = ENOENT;
    2438                 return (uint32)-1;
    2439         }
    2440 
    2441         /* Insure the maximum queue size is not violated */
    2442         if ((njobs = print_queue_length(snum,NULL)) > lp_maxprintjobs(snum)) {
    2443                 DEBUG(3, ("print_job_start: Queue %s number of jobs (%d) larger than max printjobs per queue (%d).\n",
    2444                         sharename, njobs, lp_maxprintjobs(snum) ));
    2445                 release_print_db(pdb);
    2446                 errno = ENOSPC;
    2447                 return (uint32)-1;
    2448         }
    2449 
    2450         DEBUG(10,("print_job_start: Queue %s number of jobs (%d), max printjobs = %d\n",
    2451                 sharename, njobs, lp_maxprintjobs(snum) ));
    2452 
    2453         if (!allocate_print_jobid(pdb, snum, sharename, &jobid))
     2811                return werr;
     2812        }
     2813
     2814        DEBUG(10, ("print_job_start: "
     2815                   "Queue %s number of jobs (%d), max printjobs = %d\n",
     2816                   sharename, njobs, lp_maxprintjobs(snum)));
     2817
     2818        werr = allocate_print_jobid(pdb, snum, sharename, &jobid);
     2819        if (!W_ERROR_IS_OK(werr)) {
    24542820                goto fail;
     2821        }
    24552822
    24562823        /* create the database entry */
     
    24662833        pjob.spooled = False;
    24672834        pjob.smbjob = True;
    2468         pjob.nt_devmode = nt_devmode;
    2469 
    2470         fstrcpy(pjob.jobname, jobname);
     2835        pjob.devmode = devmode;
     2836
     2837        fstrcpy(pjob.jobname, docname);
     2838
     2839        fstrcpy(pjob.clientmachine, clientmachine);
    24712840
    24722841        fstrcpy(pjob.user, lp_printjob_username(snum));
     
    24742843                              path, server_info->utok.gid,
    24752844                              server_info->sanitized_username,
    2476                               pdb_get_domain(server_info->sam_account),
     2845                              server_info->info3->base.domain.string,
    24772846                              pjob.user, sizeof(pjob.user)-1);
    24782847        /* ensure NULL termination */
     
    24822851
    24832852        /* we have a job entry - now create the spool file */
    2484         slprintf(pjob.filename, sizeof(pjob.filename)-1, "%s/%s%.8u.XXXXXX",
    2485                  path, PRINT_SPOOL_PREFIX, (unsigned int)jobid);
    2486         pjob.fd = mkstemp(pjob.filename);
    2487 
    2488         if (pjob.fd == -1) {
    2489                 if (errno == EACCES) {
    2490                         /* Common setup error, force a report. */
    2491                         DEBUG(0, ("print_job_start: insufficient permissions \
    2492 to open spool file %s.\n", pjob.filename));
    2493                 } else {
    2494                         /* Normal case, report at level 3 and above. */
    2495                         DEBUG(3, ("print_job_start: can't open spool file %s,\n", pjob.filename));
    2496                         DEBUGADD(3, ("errno = %d (%s).\n", errno, strerror(errno)));
    2497                 }
     2853        werr = print_job_spool_file(snum, jobid, filename, &pjob);
     2854        if (!W_ERROR_IS_OK(werr)) {
    24982855                goto fail;
    24992856        }
    25002857
    2501         pjob_store(sharename, jobid, &pjob);
    2502 
    2503         /* Update the 'jobs changed' entry used by print_queue_status. */
    2504         add_to_jobs_changed(pdb, jobid);
     2858        pjob_store(server_event_context(), msg_ctx, sharename, jobid, &pjob);
     2859
     2860        /* Update the 'jobs added' entry used by print_queue_status. */
     2861        add_to_jobs_added(pdb, jobid);
    25052862
    25062863        /* Ensure we keep a rough count of the number of total jobs... */
     
    25092866        release_print_db(pdb);
    25102867
    2511         return jobid;
    2512 
    2513  fail:
    2514         if (jobid != -1)
    2515                 pjob_delete(sharename, jobid);
     2868        *_jobid = jobid;
     2869        return WERR_OK;
     2870
     2871fail:
     2872        if (jobid != -1) {
     2873                pjob_delete(server_event_context(), msg_ctx, sharename, jobid);
     2874        }
    25162875
    25172876        release_print_db(pdb);
    25182877
    2519         DEBUG(3, ("print_job_start: returning fail. Error = %s\n", strerror(errno) ));
    2520         return (uint32)-1;
     2878        DEBUG(3, ("print_job_start: returning fail. "
     2879                  "Error = %s\n", win_errstr(werr)));
     2880        return werr;
    25212881}
    25222882
     
    25252885****************************************************************************/
    25262886
    2527 void print_job_endpage(int snum, uint32 jobid)
     2887void print_job_endpage(struct messaging_context *msg_ctx,
     2888                       int snum, uint32 jobid)
    25282889{
    25292890        const char* sharename = lp_const_servicename(snum);
     
    25382899
    25392900        pjob->page_count++;
    2540         pjob_store(sharename, jobid, pjob);
     2901        pjob_store(server_event_context(), msg_ctx, sharename, jobid, pjob);
    25412902}
    25422903
     
    25472908****************************************************************************/
    25482909
    2549 bool print_job_end(int snum, uint32 jobid, enum file_close_type close_type)
     2910NTSTATUS print_job_end(struct messaging_context *msg_ctx, int snum,
     2911                       uint32 jobid, enum file_close_type close_type)
    25502912{
    25512913        const char* sharename = lp_const_servicename(snum);
     
    25542916        SMB_STRUCT_STAT sbuf;
    25552917        struct printif *current_printif = get_printer_fns( snum );
     2918        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
    25562919
    25572920        pjob = print_job_find(sharename, jobid);
    25582921
    2559         if (!pjob)
    2560                 return False;
    2561 
    2562         if (pjob->spooled || pjob->pid != sys_getpid())
    2563                 return False;
    2564 
    2565         if ((close_type == NORMAL_CLOSE || close_type == SHUTDOWN_CLOSE) &&
    2566             (sys_fstat(pjob->fd, &sbuf, false) == 0)) {
     2922        if (!pjob) {
     2923                return NT_STATUS_PRINT_CANCELLED;
     2924        }
     2925
     2926        if (pjob->spooled || pjob->pid != sys_getpid()) {
     2927                return NT_STATUS_ACCESS_DENIED;
     2928        }
     2929
     2930        if (close_type == NORMAL_CLOSE || close_type == SHUTDOWN_CLOSE) {
     2931                if (pjob->status == PJOB_SMBD_SPOOLING) {
     2932                        /* take over the file now, smbd is done */
     2933                        if (sys_stat(pjob->filename, &sbuf, false) != 0) {
     2934                                status = map_nt_error_from_unix(errno);
     2935                                DEBUG(3, ("print_job_end: "
     2936                                          "stat file failed for jobid %d\n",
     2937                                          jobid));
     2938                                goto fail;
     2939                        }
     2940
     2941                        pjob->status = LPQ_SPOOLING;
     2942
     2943                } else {
     2944
     2945                        if ((sys_fstat(pjob->fd, &sbuf, false) != 0)) {
     2946                                status = map_nt_error_from_unix(errno);
     2947                                close(pjob->fd);
     2948                                DEBUG(3, ("print_job_end: "
     2949                                          "stat file failed for jobid %d\n",
     2950                                          jobid));
     2951                                goto fail;
     2952                        }
     2953
     2954                        close(pjob->fd);
     2955                }
     2956
    25672957                pjob->size = sbuf.st_ex_size;
    2568                 close(pjob->fd);
    2569                 pjob->fd = -1;
    25702958        } else {
    25712959
    25722960                /*
    2573                  * Not a normal close or we couldn't stat the job file,
    2574                  * so something has gone wrong. Cleanup.
     2961                 * Not a normal close, something has gone wrong. Cleanup.
    25752962                 */
    2576                 close(pjob->fd);
    2577                 pjob->fd = -1;
    2578                 DEBUG(3,("print_job_end: failed to stat file for jobid %d\n", jobid ));
     2963                if (pjob->fd != -1) {
     2964                        close(pjob->fd);
     2965                }
    25792966                goto fail;
    25802967        }
     
    25882975                        pjob->filename, pjob->size ? "deleted" : "zero length" ));
    25892976                unlink(pjob->filename);
    2590                 pjob_delete(sharename, jobid);
    2591                 return True;
     2977                pjob_delete(server_event_context(), msg_ctx, sharename, jobid);
     2978                return NT_STATUS_OK;
    25922979        }
    25932980
    25942981        ret = (*(current_printif->job_submit))(snum, pjob);
    25952982
    2596         if (ret)
     2983        if (ret) {
     2984                status = NT_STATUS_PRINT_CANCELLED;
    25972985                goto fail;
     2986        }
    25982987
    25992988        /* The print job has been successfully handed over to the back-end */
     
    26012990        pjob->spooled = True;
    26022991        pjob->status = LPQ_QUEUED;
    2603         pjob_store(sharename, jobid, pjob);
     2992        pjob_store(server_event_context(), msg_ctx, sharename, jobid, pjob);
    26042993
    26052994        /* make sure the database is up to date */
    26062995        if (print_cache_expired(lp_const_servicename(snum), True))
    2607                 print_queue_update(snum, False);
    2608 
    2609         return True;
     2996                print_queue_update(msg_ctx, snum, False);
     2997
     2998        return NT_STATUS_OK;
    26102999
    26113000fail:
     
    26133002        /* The print job was not successfully started. Cleanup */
    26143003        /* Still need to add proper error return propagation! 010122:JRR */
     3004        pjob->fd = -1;
    26153005        unlink(pjob->filename);
    2616         pjob_delete(sharename, jobid);
    2617         return False;
     3006        pjob_delete(server_event_context(), msg_ctx, sharename, jobid);
     3007        return status;
    26183008}
    26193009
     
    26223012****************************************************************************/
    26233013
    2624 static bool get_stored_queue_info(struct tdb_print_db *pdb, int snum, int *pcount, print_queue_struct **ppqueue)
    2625 {
    2626         TDB_DATA data, cgdata;
     3014static bool get_stored_queue_info(struct messaging_context *msg_ctx,
     3015                                  struct tdb_print_db *pdb, int snum,
     3016                                  int *pcount, print_queue_struct **ppqueue)
     3017{
     3018        TDB_DATA data, cgdata, jcdata;
    26273019        print_queue_struct *queue = NULL;
    26283020        uint32 qcount = 0;
    26293021        uint32 extra_count = 0;
     3022        uint32_t changed_count = 0;
    26303023        int total_count = 0;
    26313024        size_t len = 0;
     
    26373030        /* make sure the database is up to date */
    26383031        if (print_cache_expired(lp_const_servicename(snum), True))
    2639                 print_queue_update(snum, False);
     3032                print_queue_update(msg_ctx, snum, False);
    26403033
    26413034        *pcount = 0;
     
    26513044                len += tdb_unpack(data.dptr + len, data.dsize - len, "d", &qcount);
    26523045
    2653         /* Get the changed jobs list. */
    2654         cgdata = tdb_fetch(pdb->tdb, string_tdb_data("INFO/jobs_changed"));
     3046        /* Get the added jobs list. */
     3047        cgdata = tdb_fetch(pdb->tdb, string_tdb_data("INFO/jobs_added"));
    26553048        if (cgdata.dptr != NULL && (cgdata.dsize % 4 == 0))
    26563049                extra_count = cgdata.dsize/4;
     3050
     3051        /* Get the changed jobs list. */
     3052        jcdata = tdb_fetch(pdb->tdb, string_tdb_data("INFO/jobs_changed"));
     3053        if (jcdata.dptr != NULL && (jcdata.dsize % 4 == 0))
     3054                changed_count = jcdata.dsize / 4;
    26573055
    26583056        DEBUG(5,("get_stored_queue_info: qcount = %u, extra_count = %u\n", (unsigned int)qcount, (unsigned int)extra_count));
     
    26883086        total_count = qcount;
    26893087
    2690         /* Add in the changed jobids. */
     3088        /* Add new jobids to the queue. */
    26913089        for( i  = 0; i < extra_count; i++) {
    26923090                uint32 jobid;
     
    26943092
    26953093                jobid = IVAL(cgdata.dptr, i*4);
    2696                 DEBUG(5,("get_stored_queue_info: changed job = %u\n", (unsigned int)jobid));
     3094                DEBUG(5,("get_stored_queue_info: added job = %u\n", (unsigned int)jobid));
    26973095                pjob = print_job_find(lp_const_servicename(snum), jobid);
    26983096                if (!pjob) {
    2699                         DEBUG(5,("get_stored_queue_info: failed to find changed job = %u\n", (unsigned int)jobid));
    2700                         remove_from_jobs_changed(sharename, jobid);
     3097                        DEBUG(5,("get_stored_queue_info: failed to find added job = %u\n", (unsigned int)jobid));
     3098                        remove_from_jobs_added(sharename, jobid);
    27013099                        continue;
    27023100                }
     
    27133111        }
    27143112
     3113        /* Update the changed jobids. */
     3114        for (i = 0; i < changed_count; i++) {
     3115                uint32_t jobid = IVAL(jcdata.dptr, i * 4);
     3116                uint32_t j;
     3117                bool found = false;
     3118
     3119                for (j = 0; j < total_count; j++) {
     3120                        if (queue[j].job == jobid) {
     3121                                found = true;
     3122                                break;
     3123                        }
     3124                }
     3125
     3126                if (found) {
     3127                        struct printjob *pjob;
     3128
     3129                        DEBUG(5,("get_stored_queue_info: changed job: %u\n",
     3130                                 (unsigned int) jobid));
     3131
     3132                        pjob = print_job_find(sharename, jobid);
     3133                        if (pjob == NULL) {
     3134                                DEBUG(5,("get_stored_queue_info: failed to find "
     3135                                         "changed job = %u\n",
     3136                                         (unsigned int) jobid));
     3137                                remove_from_jobs_changed(sharename, jobid);
     3138                                continue;
     3139                        }
     3140
     3141                        queue[j].job = jobid;
     3142                        queue[j].size = pjob->size;
     3143                        queue[j].page_count = pjob->page_count;
     3144                        queue[j].status = pjob->status;
     3145                        queue[j].priority = 1;
     3146                        queue[j].time = pjob->starttime;
     3147                        fstrcpy(queue[j].fs_user, pjob->user);
     3148                        fstrcpy(queue[j].fs_file, pjob->jobname);
     3149
     3150                        DEBUG(5,("get_stored_queue_info: updated queue[%u], jobid: %u, jobname: %s\n",
     3151                                 (unsigned int) j, (unsigned int) jobid, pjob->jobname));
     3152                }
     3153
     3154                remove_from_jobs_changed(sharename, jobid);
     3155        }
     3156
    27153157        /* Sort the queue by submission time otherwise they are displayed
    27163158           in hash order. */
    27173159
    2718         qsort(queue, total_count, sizeof(print_queue_struct), QSORT_CAST(printjob_comp));
     3160        TYPESAFE_QSORT(queue, total_count, printjob_comp);
    27193161
    27203162        DEBUG(5,("get_stored_queue_info: total_count = %u\n", (unsigned int)total_count));
     
    27403182****************************************************************************/
    27413183
    2742 int print_queue_status(int snum,
     3184int print_queue_status(struct messaging_context *msg_ctx, int snum,
    27433185                       print_queue_struct **ppqueue,
    27443186                       print_status_struct *status)
     
    27533195
    27543196        if (print_cache_expired(lp_const_servicename(snum), True))
    2755                 print_queue_update(snum, False);
     3197                print_queue_update(msg_ctx, snum, False);
    27563198
    27573199        /* return if we are done */
     
    27903232         */
    27913233
    2792         if (!get_stored_queue_info(pdb, snum, &count, ppqueue)) {
     3234        if (!get_stored_queue_info(msg_ctx, pdb, snum, &count, ppqueue)) {
    27933235                release_print_db(pdb);
    27943236                return 0;
     
    28033245****************************************************************************/
    28043246
    2805 WERROR print_queue_pause(struct auth_serversupplied_info *server_info, int snum)
     3247WERROR print_queue_pause(const struct auth_serversupplied_info *server_info,
     3248                         struct messaging_context *msg_ctx, int snum)
    28063249{
    28073250        int ret;
    28083251        struct printif *current_printif = get_printer_fns( snum );
    28093252
    2810         if (!print_access_check(server_info, snum,
     3253        if (!print_access_check(server_info, msg_ctx, snum,
    28113254                                PRINTER_ACCESS_ADMINISTER)) {
    28123255                return WERR_ACCESS_DENIED;
     
    28293272        /* Send a printer notify message */
    28303273
    2831         notify_printer_status(snum, PRINTER_STATUS_PAUSED);
     3274        notify_printer_status(server_event_context(), msg_ctx, snum,
     3275                              PRINTER_STATUS_PAUSED);
    28323276
    28333277        return WERR_OK;
     
    28383282****************************************************************************/
    28393283
    2840 WERROR print_queue_resume(struct auth_serversupplied_info *server_info, int snum)
     3284WERROR print_queue_resume(const struct auth_serversupplied_info *server_info,
     3285                          struct messaging_context *msg_ctx, int snum)
    28413286{
    28423287        int ret;
    28433288        struct printif *current_printif = get_printer_fns( snum );
    28443289
    2845         if (!print_access_check(server_info, snum,
     3290        if (!print_access_check(server_info, msg_ctx, snum,
    28463291                                PRINTER_ACCESS_ADMINISTER)) {
    28473292                return WERR_ACCESS_DENIED;
     
    28603305        /* make sure the database is up to date */
    28613306        if (print_cache_expired(lp_const_servicename(snum), True))
    2862                 print_queue_update(snum, True);
     3307                print_queue_update(msg_ctx, snum, True);
    28633308
    28643309        /* Send a printer notify message */
    28653310
    2866         notify_printer_status(snum, PRINTER_STATUS_OK);
     3311        notify_printer_status(server_event_context(), msg_ctx, snum,
     3312                              PRINTER_STATUS_OK);
    28673313
    28683314        return WERR_OK;
     
    28733319****************************************************************************/
    28743320
    2875 WERROR print_queue_purge(struct auth_serversupplied_info *server_info, int snum)
     3321WERROR print_queue_purge(const struct auth_serversupplied_info *server_info,
     3322                         struct messaging_context *msg_ctx, int snum)
    28763323{
    28773324        print_queue_struct *queue;
     
    28813328
    28823329        /* Force and update so the count is accurate (i.e. not a cached count) */
    2883         print_queue_update(snum, True);
    2884 
    2885         can_job_admin = print_access_check(server_info, snum,
     3330        print_queue_update(msg_ctx, snum, True);
     3331
     3332        can_job_admin = print_access_check(server_info,
     3333                                           msg_ctx,
     3334                                           snum,
    28863335                                           JOB_ACCESS_ADMINISTER);
    2887         njobs = print_queue_status(snum, &queue, &status);
     3336        njobs = print_queue_status(msg_ctx, snum, &queue, &status);
    28883337
    28893338        if ( can_job_admin )
     
    28953344
    28963345                if (owner || can_job_admin) {
    2897                         print_job_delete1(snum, queue[i].job);
     3346                        print_job_delete1(server_event_context(), msg_ctx,
     3347                                          snum, queue[i].job);
    28983348                }
    28993349        }
     
    29033353
    29043354        /* update the cache */
    2905         print_queue_update( snum, True );
     3355        print_queue_update(msg_ctx, snum, True);
    29063356
    29073357        SAFE_FREE(queue);
Note: See TracChangeset for help on using the changeset viewer.