Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

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

    r860 r988  
    2929#include "printing/notify.h"
    3030#include "printing/pcap.h"
     31#include "printing/printer_list.h"
     32#include "printing/queue_process.h"
    3133#include "serverid.h"
    3234#include "smbd/smbd.h"
     
    3436#include "messages.h"
    3537#include "util_tdb.h"
     38#include "lib/param/loadparm.h"
     39#include "lib/util/sys_rw_data.h"
    3640
    3741extern struct current_user current_user;
     
    3943
    4044/* Current printer interface */
    41 static bool remove_from_jobs_added(const char* sharename, uint32 jobid);
     45static bool remove_from_jobs_added(const char* sharename, uint32_t jobid);
    4246
    4347/*
     
    5660
    5761static TDB_CONTEXT *rap_tdb;
    58 static uint16 next_rap_jobid;
     62static uint16_t next_rap_jobid;
    5963struct rap_jobid_key {
    6064        fstring sharename;
    61         uint32  jobid;
     65        uint32_t  jobid;
    6266};
    6367
     
    6771***************************************************************************/
    6872
    69 uint16 pjobid_to_rap(const char* sharename, uint32 jobid)
    70 {
    71         uint16 rap_jobid;
     73uint16_t pjobid_to_rap(const char* sharename, uint32_t jobid)
     74{
     75        uint16_t rap_jobid;
    7276        TDB_DATA data, key;
    7377        struct rap_jobid_key jinfo;
    74         uint8 buf[2];
     78        uint8_t buf[2];
    7579
    7680        DEBUG(10,("pjobid_to_rap: called.\n"));
     
    8690        fstrcpy( jinfo.sharename, sharename );
    8791        jinfo.jobid = jobid;
    88         key.dptr = (uint8 *)&jinfo;
     92        key.dptr = (uint8_t *)&jinfo;
    8993        key.dsize = sizeof(jinfo);
    9094
    9195        data = tdb_fetch(rap_tdb, key);
    92         if (data.dptr && data.dsize == sizeof(uint16)) {
     96        if (data.dptr && data.dsize == sizeof(uint16_t)) {
    9397                rap_jobid = SVAL(data.dptr, 0);
    9498                SAFE_FREE(data.dptr);
     
    113117}
    114118
    115 bool rap_to_pjobid(uint16 rap_jobid, fstring sharename, uint32 *pjobid)
     119bool rap_to_pjobid(uint16_t rap_jobid, fstring sharename, uint32_t *pjobid)
    116120{
    117121        TDB_DATA data, key;
    118         uint8 buf[2];
     122        uint8_t buf[2];
    119123
    120124        DEBUG(10,("rap_to_pjobid called.\n"));
     
    146150}
    147151
    148 void rap_jobid_delete(const char* sharename, uint32 jobid)
     152void rap_jobid_delete(const char* sharename, uint32_t jobid)
    149153{
    150154        TDB_DATA key, data;
    151         uint16 rap_jobid;
     155        uint16_t rap_jobid;
    152156        struct rap_jobid_key jinfo;
    153         uint8 buf[2];
     157        uint8_t buf[2];
    154158
    155159        DEBUG(10,("rap_jobid_delete: called.\n"));
     
    161165        fstrcpy( jinfo.sharename, sharename );
    162166        jinfo.jobid = jobid;
    163         key.dptr = (uint8 *)&jinfo;
     167        key.dptr = (uint8_t *)&jinfo;
    164168        key.dsize = sizeof(jinfo);
    165169
    166170        data = tdb_fetch(rap_tdb, key);
    167         if (!data.dptr || (data.dsize != sizeof(uint16))) {
     171        if (!data.dptr || (data.dsize != sizeof(uint16_t))) {
    168172                DEBUG(10,("rap_jobid_delete: cannot find jobid %u\n",
    169173                        (unsigned int)jobid ));
     
    195199        int services = lp_numservices();
    196200        int snum;
    197 
    198         unlink(cache_path("printing.tdb"));
    199         mkdir(cache_path("printing"),0755);
     201        bool ok;
     202        char *print_cache_path;
     203
     204        if (!printer_list_parent_init()) {
     205                return false;
     206        }
     207
     208        print_cache_path = cache_path("printing");
     209        if (print_cache_path == NULL) {
     210                return false;
     211        }
     212        ok = directory_create_or_exist(print_cache_path, 0755);
     213        TALLOC_FREE(print_cache_path);
     214        if (!ok) {
     215                return false;
     216        }
     217
     218        print_cache_path = cache_path("printing.tdb");
     219        if (print_cache_path == NULL) {
     220                return false;
     221        }
     222        unlink(print_cache_path);
     223        TALLOC_FREE(print_cache_path);
    200224
    201225        /* handle a Samba upgrade */
     
    203227        for (snum = 0; snum < services; snum++) {
    204228                struct tdb_print_db *pdb;
    205                 if (!lp_print_ok(snum))
     229                if (!lp_printable(snum))
    206230                        continue;
    207231
     
    209233                if (!pdb)
    210234                        continue;
    211                 if (tdb_lock_bystring(pdb->tdb, sversion) == -1) {
     235                if (tdb_lock_bystring(pdb->tdb, sversion) != 0) {
    212236                        DEBUG(0,("print_backend_init: Failed to open printer %s database\n", lp_const_servicename(snum) ));
    213237                        release_print_db(pdb);
     
    277301****************************************************************************/
    278302
    279 static TDB_DATA print_key(uint32 jobid, uint32 *tmp)
     303static TDB_DATA print_key(uint32_t jobid, uint32_t *tmp)
    280304{
    281305        TDB_DATA ret;
    282306
    283307        SIVAL(tmp, 0, jobid);
    284         ret.dptr = (uint8 *)tmp;
     308        ret.dptr = (uint8_t *)tmp;
    285309        ret.dsize = sizeof(*tmp);
    286310        return ret;
     
    290314 Pack the devicemode to store it in a tdb.
    291315****************************************************************************/
    292 static int pack_devicemode(struct spoolss_DeviceMode *devmode, uint8 *buf, int buflen)
     316static int pack_devicemode(struct spoolss_DeviceMode *devmode, uint8_t *buf, int buflen)
    293317{
    294318        enum ndr_err_code ndr_err;
     
    324348****************************************************************************/
    325349static int unpack_devicemode(TALLOC_CTX *mem_ctx,
    326                       const uint8 *buf, int buflen,
     350                      const uint8_t *buf, int buflen,
    327351                      struct spoolss_DeviceMode **devmode)
    328352{
     
    374398***********************************************************************/
    375399
    376 static int unpack_pjob(TALLOC_CTX *mem_ctx, uint8 *buf, int buflen,
     400static int unpack_pjob(TALLOC_CTX *mem_ctx, uint8_t *buf, int buflen,
    377401                       struct printjob *pjob)
    378402{
    379403        int     len = 0;
    380404        int     used;
    381         uint32 pjpid, pjjobid, pjsysjob, pjfd, pjstarttime, pjstatus;
    382         uint32 pjsize, pjpage_count, pjspooled, pjsmbjob;
     405        uint32_t pjpid, pjjobid, pjsysjob, pjfd, pjstarttime, pjstatus;
     406        uint32_t pjsize, pjpage_count, pjspooled, pjsmbjob;
    383407
    384408        if (!buf || !pjob) {
     
    435459static struct printjob *print_job_find(TALLOC_CTX *mem_ctx,
    436460                                       const char *sharename,
    437                                        uint32 jobid)
     461                                       uint32_t jobid)
    438462{
    439463        struct printjob         *pjob;
     
    479503}
    480504
    481 /* Convert a unix jobid to a smb jobid */
    482 
    483 struct unixjob_traverse_state {
     505struct job_traverse_state {
    484506        int sysjob;
    485         uint32 sysjob_to_jobid_value;
     507        uint32_t jobid;
    486508};
    487509
    488 static int unixjob_traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key,
    489                                TDB_DATA data, void *private_data)
     510/* find spoolss jobid based on sysjob */
     511static int sysjob_to_jobid_traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key,
     512                                       TDB_DATA data, void *private_data)
    490513{
    491514        struct printjob *pjob;
    492         struct unixjob_traverse_state *state =
    493                 (struct unixjob_traverse_state *)private_data;
     515        struct job_traverse_state *state =
     516                (struct job_traverse_state *)private_data;
    494517
    495518        if (!data.dptr || data.dsize == 0)
     
    497520
    498521        pjob = (struct printjob *)data.dptr;
    499         if (key.dsize != sizeof(uint32))
     522        if (key.dsize != sizeof(uint32_t))
    500523                return 0;
    501524
    502525        if (state->sysjob == pjob->sysjob) {
    503                 state->sysjob_to_jobid_value = pjob->jobid;
     526                state->jobid = pjob->jobid;
    504527                return 1;
    505528        }
     
    508531}
    509532
    510 static uint32 sysjob_to_jobid_pdb(struct tdb_print_db *pdb, int sysjob)
    511 {
    512         struct unixjob_traverse_state state;
     533uint32_t sysjob_to_jobid_pdb(struct tdb_print_db *pdb, int sysjob)
     534{
     535        struct job_traverse_state state;
    513536
    514537        state.sysjob = sysjob;
    515         state.sysjob_to_jobid_value = (uint32)-1;
    516 
    517         tdb_traverse(pdb->tdb, unixjob_traverse_fn, &state);
    518 
    519         return state.sysjob_to_jobid_value;
     538        state.jobid = (uint32_t)-1;
     539
     540        tdb_traverse(pdb->tdb, sysjob_to_jobid_traverse_fn, &state);
     541
     542        return state.jobid;
    520543}
    521544
     
    525548****************************************************************************/
    526549
    527 uint32 sysjob_to_jobid(int unix_jobid)
     550uint32_t sysjob_to_jobid(int unix_jobid)
    528551{
    529552        int services = lp_numservices();
    530553        int snum;
    531         struct unixjob_traverse_state state;
     554        struct job_traverse_state state;
    532555
    533556        state.sysjob = unix_jobid;
    534         state.sysjob_to_jobid_value = (uint32)-1;
     557        state.jobid = (uint32_t)-1;
    535558
    536559        for (snum = 0; snum < services; snum++) {
    537560                struct tdb_print_db *pdb;
    538                 if (!lp_print_ok(snum))
     561                if (!lp_printable(snum))
    539562                        continue;
    540563                pdb = get_print_db_byname(lp_const_servicename(snum));
     
    542565                        continue;
    543566                }
    544                 tdb_traverse(pdb->tdb, unixjob_traverse_fn, &state);
     567                tdb_traverse(pdb->tdb, sysjob_to_jobid_traverse_fn, &state);
    545568                release_print_db(pdb);
    546                 if (state.sysjob_to_jobid_value != (uint32)-1)
    547                         return state.sysjob_to_jobid_value;
    548         }
    549         return (uint32)-1;
     569                if (state.jobid != (uint32_t)-1)
     570                        return state.jobid;
     571        }
     572        return (uint32_t)-1;
     573}
     574
     575/* find sysjob based on spoolss jobid */
     576static int jobid_to_sysjob_traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key,
     577                                       TDB_DATA data, void *private_data)
     578{
     579        struct printjob *pjob;
     580        struct job_traverse_state *state =
     581                (struct job_traverse_state *)private_data;
     582
     583        if (!data.dptr || data.dsize == 0)
     584                return 0;
     585
     586        pjob = (struct printjob *)data.dptr;
     587        if (key.dsize != sizeof(uint32_t))
     588                return 0;
     589
     590        if (state->jobid == pjob->jobid) {
     591                state->sysjob = pjob->sysjob;
     592                return 1;
     593        }
     594
     595        return 0;
     596}
     597
     598int jobid_to_sysjob_pdb(struct tdb_print_db *pdb, uint32_t jobid)
     599{
     600        struct job_traverse_state state;
     601
     602        state.sysjob = -1;
     603        state.jobid = jobid;
     604
     605        tdb_traverse(pdb->tdb, jobid_to_sysjob_traverse_fn, &state);
     606
     607        return state.sysjob;
    550608}
    551609
     
    575633   appropriate win32 API constant. */
    576634
    577 static uint32 map_to_spoolss_status(uint32 lpq_status)
     635static uint32_t map_to_spoolss_status(uint32_t lpq_status)
    578636{
    579637        int i = 0;
     
    598656
    599657        SIVAL(&store_jobid, 0, jobid);
    600         data.dptr = (uint8 *) &store_jobid;
     658        data.dptr = (uint8_t *) &store_jobid;
    601659        data.dsize = 4;
    602660
     
    627685        key = string_tdb_data("INFO/jobs_changed");
    628686
    629         if (tdb_chainlock_with_timeout(pdb->tdb, key, 5) == -1)
     687        if (tdb_chainlock_with_timeout(pdb->tdb, key, 5) != 0)
    630688                goto out;
    631689
     
    639697        job_count = data.dsize / 4;
    640698        for (i = 0; i < job_count; i++) {
    641                 uint32 ch_jobid;
     699                uint32_t ch_jobid;
    642700
    643701                ch_jobid = IVAL(data.dptr, i*4);
     
    646704                                memmove(data.dptr + (i*4), data.dptr + (i*4) + 4, (job_count - i - 1)*4 );
    647705                        data.dsize -= 4;
    648                         if (tdb_store(pdb->tdb, key, data, TDB_REPLACE) == -1)
     706                        if (tdb_store(pdb->tdb, key, data, TDB_REPLACE) != 0)
    649707                                goto out;
    650708                        break;
     
    668726static void pjob_store_notify(struct tevent_context *ev,
    669727                              struct messaging_context *msg_ctx,
    670                               const char* sharename, uint32 jobid,
     728                              const char* sharename, uint32_t jobid,
    671729                              struct printjob *old_data,
    672730                              struct printjob *new_data,
     
    734792static bool pjob_store(struct tevent_context *ev,
    735793                       struct messaging_context *msg_ctx,
    736                        const char* sharename, uint32 jobid,
     794                       const char* sharename, uint32_t jobid,
    737795                       struct printjob *pjob)
    738796{
     
    741799        bool                    ret = False;
    742800        struct tdb_print_db     *pdb = get_print_db_byname(sharename);
    743         uint8                   *buf = NULL;
     801        uint8_t                 *buf = NULL;
    744802        int                     len, newlen, buflen;
    745803
     
    760818                buflen = newlen;
    761819                len += tdb_pack(buf+len, buflen-len, "ddddddddddfffff",
    762                                 (uint32)pjob->pid,
    763                                 (uint32)pjob->jobid,
    764                                 (uint32)pjob->sysjob,
    765                                 (uint32)pjob->fd,
    766                                 (uint32)pjob->starttime,
    767                                 (uint32)pjob->status,
    768                                 (uint32)pjob->size,
    769                                 (uint32)pjob->page_count,
    770                                 (uint32)pjob->spooled,
    771                                 (uint32)pjob->smbjob,
     820                                (uint32_t)pjob->pid,
     821                                (uint32_t)pjob->jobid,
     822                                (uint32_t)pjob->sysjob,
     823                                (uint32_t)pjob->fd,
     824                                (uint32_t)pjob->starttime,
     825                                (uint32_t)pjob->status,
     826                                (uint32_t)pjob->size,
     827                                (uint32_t)pjob->page_count,
     828                                (uint32_t)pjob->spooled,
     829                                (uint32_t)pjob->smbjob,
    772830                                pjob->filename,
    773831                                pjob->jobname,
     
    779837
    780838                if (buflen != len) {
    781                         buf = (uint8 *)SMB_REALLOC(buf, len);
     839                        buf = (uint8_t *)SMB_REALLOC(buf, len);
    782840                        if (!buf) {
    783841                                DEBUG(0,("pjob_store: failed to enlarge buffer!\n"));
     
    843901static void pjob_delete(struct tevent_context *ev,
    844902                        struct messaging_context *msg_ctx,
    845                         const char* sharename, uint32 jobid)
     903                        const char* sharename, uint32_t jobid)
    846904{
    847905        uint32_t tmp;
    848906        struct printjob *pjob;
    849         uint32 job_status = 0;
     907        uint32_t job_status = 0;
    850908        struct tdb_print_db *pdb;
    851909        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     
    891949                           struct messaging_context *msg_ctx,
    892950                           const char *sharename, print_queue_struct *q,
    893                            uint32 jobid)
     951                           uint32_t jobid)
    894952{
    895953        struct printjob pj, *old_pj;
     
    899957        }
    900958
    901         if (jobid == (uint32)-1) {
     959        if (jobid == (uint32_t)-1) {
    902960                jobid = q->sysjob + UNIX_JOB_START;
    903961        }
     
    9531011        struct traverse_struct *ts = (struct traverse_struct *)state;
    9541012        struct printjob pjob;
    955         uint32 jobid;
     1013        uint32_t jobid;
    9561014        int i = 0;
    9571015
     
    11331191        TDB_DATA key;
    11341192        TDB_DATA data;
    1135         pid_t updating_pid = sys_getpid();
    1136         uint8 buffer[4];
     1193        pid_t updating_pid = getpid();
     1194        uint8_t buffer[4];
    11371195
    11381196        struct tdb_print_db *pdb = get_print_db_byname(sharename);
     
    11441202        key = string_tdb_data(keystr);
    11451203
    1146         DEBUG(5, ("set_updating_pid: %s updating lpq cache for print share %s\n",
     1204        DEBUG(5, ("set_updating_pid: %supdating lpq cache for print share %s\n",
    11471205                updating ? "" : "not ",
    11481206                sharename ));
     
    11921250{
    11931251        TDB_DATA data;
    1194         int max_reported_jobs = lp_max_reported_jobs(pts->snum);
     1252        int max_reported_jobs = lp_max_reported_print_jobs(pts->snum);
    11951253        print_queue_struct *queue = pts->queue;
    11961254        size_t len;
     
    12121270                qcount++;
    12131271                data.dsize += tdb_pack(NULL, 0, "ddddddff",
    1214                                 (uint32)queue[i].sysjob,
    1215                                 (uint32)queue[i].size,
    1216                                 (uint32)queue[i].page_count,
    1217                                 (uint32)queue[i].status,
    1218                                 (uint32)queue[i].priority,
    1219                                 (uint32)queue[i].time,
     1272                                (uint32_t)queue[i].sysjob,
     1273                                (uint32_t)queue[i].size,
     1274                                (uint32_t)queue[i].page_count,
     1275                                (uint32_t)queue[i].status,
     1276                                (uint32_t)queue[i].priority,
     1277                                (uint32_t)queue[i].time,
    12201278                                queue[i].fs_user,
    12211279                                queue[i].fs_file);
    12221280        }
    12231281
    1224         if ((data.dptr = (uint8 *)SMB_MALLOC(data.dsize)) == NULL)
     1282        if ((data.dptr = (uint8_t *)SMB_MALLOC(data.dsize)) == NULL)
    12251283                return;
    12261284
     
    12321290
    12331291                len += tdb_pack(data.dptr + len, data.dsize - len, "ddddddff",
    1234                                 (uint32)queue[i].sysjob,
    1235                                 (uint32)queue[i].size,
    1236                                 (uint32)queue[i].page_count,
    1237                                 (uint32)queue[i].status,
    1238                                 (uint32)queue[i].priority,
    1239                                 (uint32)queue[i].time,
     1292                                (uint32_t)queue[i].sysjob,
     1293                                (uint32_t)queue[i].size,
     1294                                (uint32_t)queue[i].page_count,
     1295                                (uint32_t)queue[i].status,
     1296                                (uint32_t)queue[i].priority,
     1297                                (uint32_t)queue[i].time,
    12401298                                queue[i].fs_user,
    12411299                                queue[i].fs_file);
     
    12631321}
    12641322
    1265 static void check_job_added(const char *sharename, TDB_DATA data, uint32 jobid)
     1323static void check_job_added(const char *sharename, TDB_DATA data, uint32_t jobid)
    12661324{
    12671325        unsigned int i;
     
    12691327
    12701328        for (i = 0; i < job_count; i++) {
    1271                 uint32 ch_jobid;
     1329                uint32_t ch_jobid;
    12721330
    12731331                ch_jobid = IVAL(data.dptr, i*4);
     
    13051363
    13061364        if (last_qscan_time == ((time_t)-1)
    1307                 || (time_now - last_qscan_time) >= lp_lpqcachetime()
     1365                || (time_now - last_qscan_time) >= lp_lpq_cache_time()
    13081366                || last_qscan_time > (time_now + MAX_CACHE_VALID_TIME))
    13091367        {
    1310                 uint32 u;
     1368                uint32_t u;
    13111369                time_t msg_pending_time;
    13121370
     
    13141372                        "(last_qscan_time = %d, time now = %d, qcachetime = %d)\n",
    13151373                        sharename, (int)last_qscan_time, (int)time_now,
    1316                         (int)lp_lpqcachetime() ));
     1374                        (int)lp_lpq_cache_time() ));
    13171375
    13181376                /* check if another smbd has already sent a message to update the
     
    14081466
    14091467        for (i=0; i<qcount; i++) {
    1410                 uint32 jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob);
    1411                 if (jobid == (uint32)-1) {
     1468                uint32_t jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob);
     1469                if (jobid == (uint32_t)-1) {
    14121470                        /* assume its a unix print job */
    14131471                        print_unix_job(ev, msg_ctx,
     
    14781536
    14791537        status.qcount = qcount;
    1480         data.dptr = (uint8 *)&status;
     1538        data.dptr = (uint8_t *)&status;
    14811539        data.dsize = sizeof(status);
    14821540        tdb_store(pdb->tdb, key, data, TDB_REPLACE);
     
    14881546
    14891547        slprintf(keystr, sizeof(keystr)-1, "CACHE/%s", sharename);
    1490         tdb_store_int32(pdb->tdb, keystr, (int32)time(NULL));
     1548        tdb_store_int32(pdb->tdb, keystr, (int32_t)time(NULL));
    14911549
    14921550        /* clear the msg pending record for this queue */
     
    15461604        slprintf(keystr, sizeof(keystr) - 1, "LOCK/%s", sharename);
    15471605        /* Only wait 10 seconds for this. */
    1548         if (tdb_lock_bystring_with_timeout(pdb->tdb, keystr, 10) == -1) {
     1606        if (tdb_lock_bystring_with_timeout(pdb->tdb, keystr, 10) != 0) {
    15491607                DEBUG(0,("print_queue_update_with_lock: Failed to lock printer %s database\n", sharename));
    15501608                release_print_db(pdb);
     
    16061664        size_t len;
    16071665
    1608         len = tdb_unpack( (uint8 *)data->data, data->length, "fdPP",
     1666        len = tdb_unpack( (uint8_t *)data->data, data->length, "fdPP",
    16091667                sharename,
    16101668                &printing_type,
     
    16281686}
    16291687
    1630 static void printing_pause_fd_handler(struct tevent_context *ev,
    1631                                       struct tevent_fd *fde,
    1632                                       uint16_t flags,
    1633                                       void *private_data)
    1634 {
    1635         /*
    1636          * If pause_pipe[1] is closed it means the parent smbd
    1637          * and children exited or aborted.
    1638          */
    1639         exit_server_cleanly(NULL);
    1640 }
    1641 
    1642 extern struct child_pid *children;
    1643 extern int num_children;
    1644 
    1645 static void add_child_pid(pid_t pid)
    1646 {
    1647         struct child_pid *child;
    1648 
    1649         child = SMB_MALLOC_P(struct child_pid);
    1650         if (child == NULL) {
    1651                 DEBUG(0, ("Could not add child struct -- malloc failed\n"));
    1652                 return;
    1653         }
    1654         child->pid = pid;
    1655         DLIST_ADD(children, child);
    1656         num_children += 1;
    1657 }
    1658 
    1659 /****************************************************************************
    1660  Notify smbds of new printcap data
    1661 **************************************************************************/
    1662 static void reload_pcap_change_notify(struct tevent_context *ev,
    1663                                       struct messaging_context *msg_ctx)
    1664 {
    1665         /*
    1666          * Reload the printers first in the background process so that
    1667          * newly added printers get default values created in the registry.
    1668          *
    1669          * This will block the process for some time (~1 sec per printer), but
    1670          * it doesn't block smbd's servering clients.
    1671          */
    1672         reload_printers_full(ev, msg_ctx);
    1673 
    1674         message_send_all(msg_ctx, MSG_PRINTER_PCAP, NULL, 0, NULL);
    1675 }
    1676 
    1677 static bool printer_housekeeping_fn(const struct timeval *now,
    1678                                     void *private_data)
    1679 {
    1680         static time_t last_pcap_reload_time = 0;
    1681         time_t printcap_cache_time = (time_t)lp_printcap_cache_time();
    1682         time_t t = time_mono(NULL);
    1683 
    1684         DEBUG(5, ("printer housekeeping\n"));
    1685 
    1686         /* if periodic printcap rescan is enabled, see if it's time to reload */
    1687         if ((printcap_cache_time != 0)
    1688          && (t >= (last_pcap_reload_time + printcap_cache_time))) {
    1689                 DEBUG( 3,( "Printcap cache time expired.\n"));
    1690                 pcap_cache_reload(server_event_context(),
    1691                                   smbd_messaging_context(),
    1692                                   &reload_pcap_change_notify);
    1693                 last_pcap_reload_time = t;
    1694         }
    1695 
    1696         return true;
    1697 }
    1698 
    1699 static void printing_sig_term_handler(struct tevent_context *ev,
    1700                                       struct tevent_signal *se,
    1701                                       int signum,
    1702                                       int count,
    1703                                       void *siginfo,
    1704                                       void *private_data)
    1705 {
    1706         exit_server_cleanly("termination signal");
    1707 }
    1708 
    1709 static void printing_sig_hup_handler(struct tevent_context *ev,
    1710                                   struct tevent_signal *se,
    1711                                   int signum,
    1712                                   int count,
    1713                                   void *siginfo,
    1714                                   void *private_data)
    1715 {
    1716         struct messaging_context *msg_ctx = talloc_get_type_abort(
    1717                 private_data, struct messaging_context);
    1718 
    1719         DEBUG(1,("Reloading printers after SIGHUP\n"));
    1720         pcap_cache_reload(ev, msg_ctx,
    1721                           &reload_pcap_change_notify);
    1722 }
    1723 
    1724 static void printing_conf_updated(struct messaging_context *msg,
    1725                                   void *private_data,
    1726                                   uint32_t msg_type,
    1727                                   struct server_id server_id,
    1728                                   DATA_BLOB *data)
    1729 {
    1730         DEBUG(5,("Reloading printers after conf change\n"));
    1731         pcap_cache_reload(messaging_event_context(msg), msg,
    1732                           &reload_pcap_change_notify);
    1733 }
    1734 
    1735 
    1736 static pid_t background_lpq_updater_pid = -1;
    1737 
    1738 /****************************************************************************
    1739 main thread of the background lpq updater
    1740 ****************************************************************************/
    1741 void start_background_queue(struct tevent_context *ev,
    1742                             struct messaging_context *msg_ctx)
    1743 {
    1744         /* Use local variables for this as we don't
    1745          * need to save the parent side of this, just
    1746          * ensure it closes when the process exits.
    1747          */
    1748         int pause_pipe[2];
    1749 
    1750         DEBUG(3,("start_background_queue: Starting background LPQ thread\n"));
    1751 
    1752         if (pipe(pause_pipe) == -1) {
    1753                 DEBUG(5,("start_background_queue: cannot create pipe. %s\n", strerror(errno) ));
    1754                 exit(1);
    1755         }
    1756 
    1757         background_lpq_updater_pid = sys_fork();
    1758 
    1759         if (background_lpq_updater_pid == -1) {
    1760                 DEBUG(5,("start_background_queue: background LPQ thread failed to start. %s\n", strerror(errno) ));
    1761                 exit(1);
    1762         }
    1763 
    1764         /* Track the printing pid along with other smbd children */
    1765         add_child_pid(background_lpq_updater_pid);
    1766 
    1767         if(background_lpq_updater_pid == 0) {
    1768                 struct tevent_fd *fde;
    1769                 int ret;
    1770                 NTSTATUS status;
    1771                 struct tevent_signal *se;
    1772 
    1773                 /* Child. */
    1774                 DEBUG(5,("start_background_queue: background LPQ thread started\n"));
    1775 
    1776                 close(pause_pipe[0]);
    1777                 pause_pipe[0] = -1;
    1778 
    1779                 status = reinit_after_fork(msg_ctx, ev, procid_self(), true);
    1780 
    1781                 if (!NT_STATUS_IS_OK(status)) {
    1782                         DEBUG(0,("reinit_after_fork() failed\n"));
    1783                         smb_panic("reinit_after_fork() failed");
    1784                 }
    1785 
    1786                 se = tevent_add_signal(ev, ev, SIGTERM, 0,
    1787                                        printing_sig_term_handler,
    1788                                        NULL);
    1789                 if (se == NULL) {
    1790                         smb_panic("failed to setup SIGTERM handler");
    1791                 }
    1792                 se = tevent_add_signal(ev, ev, SIGHUP, 0,
    1793                                        printing_sig_hup_handler,
    1794                                        msg_ctx);
    1795                 if (se == NULL) {
    1796                         smb_panic("failed to setup SIGHUP handler");
    1797                 }
    1798 
    1799                 if (!serverid_register(procid_self(),
    1800                                        FLAG_MSG_GENERAL|FLAG_MSG_SMBD
    1801                                        |FLAG_MSG_PRINT_GENERAL)) {
    1802                         exit(1);
    1803                 }
    1804 
    1805                 if (!locking_init()) {
    1806                         exit(1);
    1807                 }
    1808 
    1809                 messaging_register(msg_ctx, NULL, MSG_PRINTER_UPDATE,
    1810                                    print_queue_receive);
    1811                 messaging_register(msg_ctx, NULL, MSG_SMB_CONF_UPDATED,
    1812                                    printing_conf_updated);
    1813 
    1814                 fde = tevent_add_fd(ev, ev, pause_pipe[1], TEVENT_FD_READ,
    1815                                     printing_pause_fd_handler,
    1816                                     NULL);
    1817                 if (!fde) {
    1818                         DEBUG(0,("tevent_add_fd() failed for pause_pipe\n"));
    1819                         smb_panic("tevent_add_fd() failed for pause_pipe");
    1820                 }
    1821 
    1822                 /* reload on startup to ensure parent smbd is refreshed */
    1823                 pcap_cache_reload(server_event_context(),
    1824                                   smbd_messaging_context(),
    1825                                   &reload_pcap_change_notify);
    1826 
    1827                 if (!(event_add_idle(ev, NULL,
    1828                                      timeval_set(SMBD_HOUSEKEEPING_INTERVAL, 0),
    1829                                      "printer_housekeeping",
    1830                                      printer_housekeeping_fn,
    1831                                      NULL))) {
    1832                         DEBUG(0, ("Could not add printing housekeeping event\n"));
    1833                         exit(1);
    1834                 }
    1835 
    1836                 DEBUG(5,("start_background_queue: background LPQ thread waiting for messages\n"));
    1837                 ret = tevent_loop_wait(ev);
    1838                 /* should not be reached */
    1839                 DEBUG(0,("background_queue: tevent_loop_wait() exited with %d - %s\n",
    1840                          ret, (ret == 0) ? "out of events" : strerror(errno)));
    1841                 exit(1);
    1842         }
    1843 
    1844         close(pause_pipe[1]);
    1845 }
    1846 
    18471688/****************************************************************************
    18481689update the internal database from the system print queue for a queue
    18491690****************************************************************************/
     1691
     1692extern pid_t background_lpq_updater_pid;
    18501693
    18511694static void print_queue_update(struct messaging_context *msg_ctx,
     
    18561699        char *lpqcommand = NULL;
    18571700        char *lprmcommand = NULL;
    1858         uint8 *buffer = NULL;
     1701        uint8_t *buffer = NULL;
    18591702        size_t len = 0;
    18601703        size_t newlen;
     
    18691712
    18701713        lpqcommand = talloc_string_sub2(ctx,
    1871                         lp_lpqcommand(snum),
     1714                        lp_lpq_command(talloc_tos(), snum),
    18721715                        "%p",
    1873                         lp_printername(snum),
     1716                        lp_printername(talloc_tos(), snum),
    18741717                        false, false, false);
    18751718        if (!lpqcommand) {
     
    18771720        }
    18781721        lpqcommand = talloc_sub_advanced(ctx,
    1879                         lp_servicename(snum),
     1722                        lp_servicename(talloc_tos(), snum),
    18801723                        current_user_info.unix_name,
    18811724                        "",
     
    18891732
    18901733        lprmcommand = talloc_string_sub2(ctx,
    1891                         lp_lprmcommand(snum),
     1734                        lp_lprm_command(talloc_tos(), snum),
    18921735                        "%p",
    1893                         lp_printername(snum),
     1736                        lp_printername(talloc_tos(), snum),
    18941737                        false, false, false);
    18951738        if (!lprmcommand) {
     
    18971740        }
    18981741        lprmcommand = talloc_sub_advanced(ctx,
    1899                         lp_servicename(snum),
     1742                        lp_servicename(talloc_tos(), snum),
    19001743                        current_user_info.unix_name,
    19011744                        "",
     
    19331776                lprmcommand );
    19341777
    1935         buffer = SMB_XMALLOC_ARRAY( uint8, len );
     1778        buffer = SMB_XMALLOC_ARRAY( uint8_t, len );
    19361779
    19371780        /* now pack the buffer */
     
    19721815
    19731816        messaging_send_buf(msg_ctx, pid_to_procid(background_lpq_updater_pid),
    1974                            MSG_PRINTER_UPDATE, (uint8 *)buffer, len);
     1817                           MSG_PRINTER_UPDATE, (uint8_t *)buffer, len);
    19751818
    19761819        SAFE_FREE( buffer );
     
    19901833        TDB_CONTEXT *tdb = NULL;
    19911834        const char *printername;
    1992         uint32 mypid = (uint32)sys_getpid();
     1835        uint32_t mypid = (uint32_t)getpid();
    19931836        bool ret = False;
    19941837        size_t i;
     
    20041847
    20051848                for ( idx=0; idx<num_services; idx++ ) {
    2006                         if (lp_snum_ok(idx) && lp_print_ok(idx) )
     1849                        if (lp_snum_ok(idx) && lp_printable(idx) )
    20071850                                print_notify_register_pid(idx);
    20081851                }
     
    20191862        }
    20201863
    2021         if (tdb_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) == -1) {
     1864        if (tdb_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) != 0) {
    20221865                DEBUG(0,("print_notify_register_pid: Failed to lock printer %s\n",
    20231866                                        printername));
     
    20331876        for (i = 0; i < data.dsize; i += 8) {
    20341877                if (IVAL(data.dptr,i) == mypid) {
    2035                         uint32 new_refcount = IVAL(data.dptr, i+4) + 1;
     1878                        uint32_t new_refcount = IVAL(data.dptr, i+4) + 1;
    20361879                        SIVAL(data.dptr, i+4, new_refcount);
    20371880                        break;
     
    20411884        if (i == data.dsize) {
    20421885                /* We weren't in the list. Realloc. */
    2043                 data.dptr = (uint8 *)SMB_REALLOC(data.dptr, data.dsize + 8);
     1886                data.dptr = (uint8_t *)SMB_REALLOC(data.dptr, data.dsize + 8);
    20441887                if (!data.dptr) {
    20451888                        DEBUG(0,("print_notify_register_pid: Relloc fail for printer %s\n",
     
    20531896
    20541897        /* Store back the record. */
    2055         if (tdb_store_bystring(tdb, NOTIFY_PID_LIST_KEY, data, TDB_REPLACE) == -1) {
     1898        if (tdb_store_bystring(tdb, NOTIFY_PID_LIST_KEY, data, TDB_REPLACE) != 0) {
    20561899                DEBUG(0,("print_notify_register_pid: Failed to update pid \
    20571900list for printer %s\n", printername));
     
    20811924        TDB_CONTEXT *tdb = NULL;
    20821925        const char *printername;
    2083         uint32 mypid = (uint32)sys_getpid();
     1926        uint32_t mypid = (uint32_t)getpid();
    20841927        size_t i;
    20851928        bool ret = False;
     
    20941937
    20951938                for ( idx=0; idx<num_services; idx++ ) {
    2096                         if ( lp_snum_ok(idx) && lp_print_ok(idx) )
     1939                        if ( lp_snum_ok(idx) && lp_printable(idx) )
    20971940                                print_notify_deregister_pid(idx);
    20981941                }
     
    21091952        }
    21101953
    2111         if (tdb_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) == -1) {
     1954        if (tdb_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) != 0) {
    21121955                DEBUG(0,("print_notify_register_pid: Failed to lock \
    21131956printer %s database\n", printername));
     
    21231966        for (i = 0; i < data.dsize; ) {
    21241967                if (IVAL(data.dptr,i) == mypid) {
    2125                         uint32 refcount = IVAL(data.dptr, i+4);
     1968                        uint32_t refcount = IVAL(data.dptr, i+4);
    21261969
    21271970                        refcount--;
     
    21431986
    21441987        /* Store back the record. */
    2145         if (tdb_store_bystring(tdb, NOTIFY_PID_LIST_KEY, data, TDB_REPLACE) == -1) {
     1988        if (tdb_store_bystring(tdb, NOTIFY_PID_LIST_KEY, data, TDB_REPLACE) != 0) {
    21461989                DEBUG(0,("print_notify_register_pid: Failed to update pid \
    21471990list for printer %s\n", printername));
     
    21642007****************************************************************************/
    21652008
    2166 bool print_job_exists(const char* sharename, uint32 jobid)
     2009bool print_job_exists(const char* sharename, uint32_t jobid)
    21672010{
    21682011        struct tdb_print_db *pdb = get_print_db_byname(sharename);
     
    21852028struct spoolss_DeviceMode *print_job_devmode(TALLOC_CTX *mem_ctx,
    21862029                                             const char *sharename,
    2187                                              uint32 jobid)
     2030                                             uint32_t jobid)
    21882031{
    21892032        struct printjob *pjob = print_job_find(mem_ctx, sharename, jobid);
     
    22012044bool print_job_set_name(struct tevent_context *ev,
    22022045                        struct messaging_context *msg_ctx,
    2203                         const char *sharename, uint32 jobid, const char *name)
     2046                        const char *sharename, uint32_t jobid, const char *name)
    22042047{
    22052048        struct printjob *pjob;
     
    22112054
    22122055        pjob = print_job_find(tmp_ctx, sharename, jobid);
    2213         if (!pjob || pjob->pid != sys_getpid()) {
     2056        if (!pjob || pjob->pid != getpid()) {
    22142057                ret = false;
    22152058                goto err_out;
     
    22322075
    22332076        pjob = print_job_find(mem_ctx, sharename, jobid);
    2234         if (!pjob || pjob->pid != sys_getpid()) {
     2077        if (!pjob || pjob->pid != getpid()) {
    22352078                return false;
    22362079        }
     
    22452088***************************************************************************/
    22462089
    2247 static bool remove_from_jobs_added(const char* sharename, uint32 jobid)
     2090static bool remove_from_jobs_added(const char* sharename, uint32_t jobid)
    22482091{
    22492092        struct tdb_print_db *pdb = get_print_db_byname(sharename);
     
    22612104        key = string_tdb_data("INFO/jobs_added");
    22622105
    2263         if (tdb_chainlock_with_timeout(pdb->tdb, key, 5) == -1)
     2106        if (tdb_chainlock_with_timeout(pdb->tdb, key, 5) != 0)
    22642107                goto out;
    22652108
     
    22732116        job_count = data.dsize / 4;
    22742117        for (i = 0; i < job_count; i++) {
    2275                 uint32 ch_jobid;
     2118                uint32_t ch_jobid;
    22762119
    22772120                ch_jobid = IVAL(data.dptr, i*4);
     
    22802123                                memmove(data.dptr + (i*4), data.dptr + (i*4) + 4, (job_count - i - 1)*4 );
    22812124                        data.dsize -= 4;
    2282                         if (tdb_store(pdb->tdb, key, data, TDB_REPLACE) == -1)
     2125                        if (tdb_store(pdb->tdb, key, data, TDB_REPLACE) != 0)
    22832126                                goto out;
    22842127                        break;
     
    23062149static bool print_job_delete1(struct tevent_context *ev,
    23072150                              struct messaging_context *msg_ctx,
    2308                               int snum, uint32 jobid)
     2151                              int snum, uint32_t jobid)
    23092152{
    23102153        const char* sharename = lp_const_servicename(snum);
     
    23502193        {
    23512194                result = (*(current_printif->job_delete))(
    2352                         lp_printername(snum),
    2353                         lp_lprmcommand(snum),
     2195                        lp_printername(talloc_tos(), snum),
     2196                        lp_lprm_command(talloc_tos(), snum),
    23542197                        pjob);
    23552198
     
    23842227****************************************************************************/
    23852228
    2386 static bool is_owner(const struct auth_serversupplied_info *server_info,
     2229static bool is_owner(const struct auth_session_info *server_info,
    23872230                     const char *servicename,
    2388                      uint32 jobid)
     2231                     uint32_t jobid)
    23892232{
    23902233        struct printjob *pjob;
     
    24012244        }
    24022245
    2403         ret = strequal(pjob->user, server_info->sanitized_username);
     2246        ret = strequal(pjob->user, server_info->unix_info->sanitized_username);
    24042247err_out:
    24052248        talloc_free(tmp_ctx);
     
    24112254****************************************************************************/
    24122255
    2413 WERROR print_job_delete(const struct auth_serversupplied_info *server_info,
     2256WERROR print_job_delete(const struct auth_session_info *server_info,
    24142257                        struct messaging_context *msg_ctx,
    24152258                        int snum, uint32_t jobid)
     
    24302273
    24312274        if (!owner &&
    2432             !print_access_check(server_info, msg_ctx, snum,
    2433                                 JOB_ACCESS_ADMINISTER)) {
    2434                 DEBUG(3, ("delete denied by security descriptor\n"));
    2435 
    2436                 /* BEGIN_ADMIN_LOG */
    2437                 sys_adminlog( LOG_ERR,
    2438                               "Permission denied-- user not allowed to delete, \
    2439 pause, or resume print job. User name: %s. Printer name: %s.",
    2440                               uidtoname(server_info->utok.uid),
    2441                               lp_printername(snum) );
    2442                 /* END_ADMIN_LOG */
     2275            !W_ERROR_IS_OK(print_access_check(server_info, msg_ctx, snum,
     2276                                              JOB_ACCESS_ADMINISTER))) {
     2277                DEBUG(0, ("print job delete denied."
     2278                          "User name: %s, Printer name: %s.",
     2279                          uidtoname(server_info->unix_token->uid),
     2280                          lp_printername(tmp_ctx, snum)));
    24432281
    24442282                werr = WERR_ACCESS_DENIED;
     
    24902328****************************************************************************/
    24912329
    2492 WERROR print_job_pause(const struct auth_serversupplied_info *server_info,
     2330WERROR print_job_pause(const struct auth_session_info *server_info,
    24932331                     struct messaging_context *msg_ctx,
    2494                      int snum, uint32 jobid)
     2332                     int snum, uint32_t jobid)
    24952333{
    24962334        const char* sharename = lp_const_servicename(snum);
     
    25202358
    25212359        if (!is_owner(server_info, lp_const_servicename(snum), jobid) &&
    2522             !print_access_check(server_info, msg_ctx, snum,
    2523                                 JOB_ACCESS_ADMINISTER)) {
    2524                 DEBUG(3, ("pause denied by security descriptor\n"));
    2525 
    2526                 /* BEGIN_ADMIN_LOG */
    2527                 sys_adminlog( LOG_ERR,
    2528                         "Permission denied-- user not allowed to delete, \
    2529 pause, or resume print job. User name: %s. Printer name: %s.",
    2530                               uidtoname(server_info->utok.uid),
    2531                               lp_printername(snum) );
    2532                 /* END_ADMIN_LOG */
     2360            !W_ERROR_IS_OK(print_access_check(server_info, msg_ctx, snum,
     2361                                              JOB_ACCESS_ADMINISTER))) {
     2362                DEBUG(0, ("print job pause denied."
     2363                          "User name: %s, Printer name: %s.",
     2364                          uidtoname(server_info->unix_token->uid),
     2365                          lp_printername(tmp_ctx, snum)));
    25332366
    25342367                werr = WERR_ACCESS_DENIED;
     
    25632396****************************************************************************/
    25642397
    2565 WERROR print_job_resume(const struct auth_serversupplied_info *server_info,
     2398WERROR print_job_resume(const struct auth_session_info *server_info,
    25662399                      struct messaging_context *msg_ctx,
    2567                       int snum, uint32 jobid)
     2400                      int snum, uint32_t jobid)
    25682401{
    25692402        const char *sharename = lp_const_servicename(snum);
     
    25922425
    25932426        if (!is_owner(server_info, lp_const_servicename(snum), jobid) &&
    2594             !print_access_check(server_info, msg_ctx, snum,
    2595                                 JOB_ACCESS_ADMINISTER)) {
    2596                 DEBUG(3, ("resume denied by security descriptor\n"));
    2597 
    2598                 /* BEGIN_ADMIN_LOG */
    2599                 sys_adminlog( LOG_ERR,
    2600                          "Permission denied-- user not allowed to delete, \
    2601 pause, or resume print job. User name: %s. Printer name: %s.",
    2602                               uidtoname(server_info->utok.uid),
    2603                               lp_printername(snum) );
    2604                 /* END_ADMIN_LOG */
     2427            !W_ERROR_IS_OK(print_access_check(server_info, msg_ctx, snum,
     2428                                              JOB_ACCESS_ADMINISTER))) {
     2429                DEBUG(0, ("print job resume denied."
     2430                          "User name: %s, Printer name: %s.",
     2431                          uidtoname(server_info->unix_token->uid),
     2432                          lp_printername(tmp_ctx, snum)));
     2433
    26052434                werr = WERR_ACCESS_DENIED;
    26062435                goto err_out;
     
    26342463ssize_t print_job_write(struct tevent_context *ev,
    26352464                        struct messaging_context *msg_ctx,
    2636                         int snum, uint32 jobid, const char *buf, size_t size)
     2465                        int snum, uint32_t jobid, const char *buf, size_t size)
    26372466{
    26382467        const char* sharename = lp_const_servicename(snum);
     
    26512480
    26522481        /* don't allow another process to get this info - it is meaningless */
    2653         if (pjob->pid != sys_getpid()) {
     2482        if (pjob->pid != getpid()) {
    26542483                return_code = -1;
    26552484                goto err_out;
     
    27382567
    27392568static WERROR allocate_print_jobid(struct tdb_print_db *pdb, int snum,
    2740                                    const char *sharename, uint32 *pjobid)
     2569                                   const char *sharename, uint32_t *pjobid)
    27412570{
    27422571        int i;
    2743         uint32 jobid;
     2572        uint32_t jobid;
    27442573        enum TDB_ERROR terr;
    27452574        int ret;
    27462575
    2747         *pjobid = (uint32)-1;
     2576        *pjobid = (uint32_t)-1;
    27482577
    27492578        for (i = 0; i < 3; i++) {
     
    27512580                ret = tdb_lock_bystring_with_timeout(pdb->tdb,
    27522581                                                     "INFO/nextjob", 20);
    2753                 if (ret == -1) {
     2582                if (ret != 0) {
    27542583                        DEBUG(0, ("allocate_print_jobid: "
    27552584                                  "Failed to lock printing database %s\n",
     
    27792608
    27802609                ret = tdb_store_int32(pdb->tdb, "INFO/nextjob", jobid);
    2781                 if (ret == -1) {
     2610                if (ret != 0) {
    27822611                        terr = tdb_error(pdb->tdb);
    27832612                        DEBUG(3, ("allocate_print_jobid: "
     
    28122641                dum.dsize = 0;
    28132642                if (tdb_store(pdb->tdb, print_key(jobid, &tmp), dum,
    2814                               TDB_INSERT) == -1) {
     2643                              TDB_INSERT) != 0) {
    28152644                        DEBUG(3, ("allocate_print_jobid: "
    28162645                                  "jobid (%d) failed to store placeholder.\n",
     
    28292658***************************************************************************/
    28302659
    2831 static bool add_to_jobs_added(struct tdb_print_db *pdb, uint32 jobid)
     2660static bool add_to_jobs_added(struct tdb_print_db *pdb, uint32_t jobid)
    28322661{
    28332662        TDB_DATA data;
    2834         uint32 store_jobid;
     2663        uint32_t store_jobid;
    28352664
    28362665        SIVAL(&store_jobid, 0, jobid);
    2837         data.dptr = (uint8 *)&store_jobid;
     2666        data.dptr = (uint8_t *)&store_jobid;
    28382667        data.dsize = 4;
    28392668
     
    28492678***************************************************************************/
    28502679
    2851 static WERROR print_job_checks(const struct auth_serversupplied_info *server_info,
     2680static WERROR print_job_checks(const struct auth_session_info *server_info,
    28522681                               struct messaging_context *msg_ctx,
    28532682                               int snum, int *njobs)
     
    28582687        int ret;
    28592688
    2860         if (!print_access_check(server_info, msg_ctx, snum,
    2861                                 PRINTER_ACCESS_USE)) {
     2689        if (!W_ERROR_IS_OK(print_access_check(server_info, msg_ctx, snum,
     2690                                              PRINTER_ACCESS_USE))) {
    28622691                DEBUG(3, ("print_job_checks: "
    28632692                          "job start denied by security descriptor\n"));
     
    28722701
    28732702        /* see if we have sufficient disk space */
    2874         if (lp_minprintspace(snum)) {
    2875                 minspace = lp_minprintspace(snum);
    2876                 ret = sys_fsusage(lp_pathname(snum), &dspace, &dsize);
     2703        if (lp_min_print_space(snum)) {
     2704                minspace = lp_min_print_space(snum);
     2705                ret = sys_fsusage(lp_path(talloc_tos(), snum), &dspace, &dsize);
    28772706                if (ret == 0 && dspace < 2*minspace) {
    28782707                        DEBUG(3, ("print_job_checks: "
     
    29132742        const char *path;
    29142743        int len;
     2744        mode_t mask;
    29152745
    29162746        /* if this file is within the printer path, it means that smbd
     
    29192749         * already already there */
    29202750        if (output_file) {
    2921                 path = lp_pathname(snum);
     2751                path = lp_path(talloc_tos(), snum);
    29222752                len = strlen(path);
    29232753                if (strncmp(output_file, path, len) == 0 &&
     
    29372767
    29382768                        DEBUG(3, ("print_job_spool_file:"
    2939                                   "External spooling activated"));
     2769                                  "External spooling activated\n"));
    29402770
    29412771                        /* we do not open the file until spooling is done */
     
    29482778
    29492779        slprintf(pjob->filename, sizeof(pjob->filename)-1,
    2950                  "%s/%sXXXXXX", lp_pathname(snum), PRINT_SPOOL_PREFIX);
     2780                 "%s/%sXXXXXX", lp_path(talloc_tos(), snum),
     2781                 PRINT_SPOOL_PREFIX);
     2782        mask = umask(S_IRWXO | S_IRWXG);
    29512783        pjob->fd = mkstemp(pjob->filename);
     2784        umask(mask);
    29522785
    29532786        if (pjob->fd == -1) {
     
    29742807***************************************************************************/
    29752808
    2976 WERROR print_job_start(const struct auth_serversupplied_info *server_info,
     2809WERROR print_job_start(const struct auth_session_info *server_info,
    29772810                       struct messaging_context *msg_ctx,
    29782811                       const char *clientmachine,
     
    29922825        }
    29932826
    2994         path = lp_pathname(snum);
     2827        path = lp_path(talloc_tos(), snum);
    29952828
    29962829        werr = print_job_checks(server_info, msg_ctx, snum, &njobs);
     
    30132846        ZERO_STRUCT(pjob);
    30142847
    3015         pjob.pid = sys_getpid();
     2848        pjob.pid = getpid();
    30162849        pjob.jobid = jobid;
    30172850        pjob.sysjob = -1;
     
    30292862
    30302863        fstrcpy(pjob.user, lp_printjob_username(snum));
    3031         standard_sub_advanced(sharename, server_info->sanitized_username,
    3032                               path, server_info->utok.gid,
    3033                               server_info->sanitized_username,
    3034                               server_info->info3->base.domain.string,
    3035                               pjob.user, sizeof(pjob.user)-1);
    3036         /* ensure NULL termination */
    3037         pjob.user[sizeof(pjob.user)-1] = '\0';
     2864        standard_sub_advanced(sharename, server_info->unix_info->sanitized_username,
     2865                              path, server_info->unix_token->gid,
     2866                              server_info->unix_info->sanitized_username,
     2867                              server_info->info->domain_name,
     2868                              pjob.user, sizeof(pjob.user));
    30382869
    30392870        fstrcpy(pjob.queuename, lp_const_servicename(snum));
     
    30752906
    30762907void print_job_endpage(struct messaging_context *msg_ctx,
    3077                        int snum, uint32 jobid)
     2908                       int snum, uint32_t jobid)
    30782909{
    30792910        const char* sharename = lp_const_servicename(snum);
     
    30892920        }
    30902921        /* don't allow another process to get this info - it is meaningless */
    3091         if (pjob->pid != sys_getpid()) {
     2922        if (pjob->pid != getpid()) {
    30922923                goto err_out;
    30932924        }
     
    31062937
    31072938NTSTATUS print_job_end(struct messaging_context *msg_ctx, int snum,
    3108                        uint32 jobid, enum file_close_type close_type)
     2939                       uint32_t jobid, enum file_close_type close_type)
    31092940{
    31102941        const char* sharename = lp_const_servicename(snum);
     
    31262957        }
    31272958
    3128         if (pjob->spooled || pjob->pid != sys_getpid()) {
     2959        if (pjob->spooled || pjob->pid != getpid()) {
    31292960                status = NT_STATUS_ACCESS_DENIED;
    31302961                goto err_out;
     
    31843015        /* don't strip out characters like '$' from the printername */
    31853016        lpq_cmd = talloc_string_sub2(tmp_ctx,
    3186                                      lp_lpqcommand(snum),
     3017                                     lp_lpq_command(talloc_tos(), snum),
    31873018                                     "%p",
    3188                                      lp_printername(snum),
     3019                                     lp_printername(talloc_tos(), snum),
    31893020                                     false, false, false);
    31903021        if (lpq_cmd == NULL) {
     
    31933024        }
    31943025        lpq_cmd = talloc_sub_advanced(tmp_ctx,
    3195                                       lp_servicename(snum),
     3026                                      lp_servicename(talloc_tos(), snum),
    31963027                                      current_user_info.unix_name,
    31973028                                      "",
     
    32463077        TDB_DATA data, cgdata, jcdata;
    32473078        print_queue_struct *queue = NULL;
    3248         uint32 qcount = 0;
    3249         uint32 extra_count = 0;
     3079        uint32_t qcount = 0;
     3080        uint32_t extra_count = 0;
    32503081        uint32_t changed_count = 0;
    32513082        int total_count = 0;
    32523083        size_t len = 0;
    3253         uint32 i;
    3254         int max_reported_jobs = lp_max_reported_jobs(snum);
    3255         bool ret = False;
    3256         const char* sharename = lp_servicename(snum);
     3084        uint32_t i;
     3085        int max_reported_jobs = lp_max_reported_print_jobs(snum);
     3086        bool ret = false;
     3087        const char* sharename = lp_servicename(talloc_tos(), snum);
    32573088        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
    32583089        if (tmp_ctx == NULL) {
     
    32973128        /* Retrieve the linearised queue data. */
    32983129
    3299         for( i = 0; i < qcount; i++) {
    3300                 uint32 qjob, qsize, qpage_count, qstatus, qpriority, qtime;
     3130        for(i = 0; i < qcount; i++) {
     3131                uint32_t qjob, qsize, qpage_count, qstatus, qpriority, qtime;
    33013132                len += tdb_unpack(data.dptr + len, data.dsize - len, "ddddddff",
    33023133                                &qjob,
     
    33193150
    33203151        /* Add new jobids to the queue. */
    3321         for( i = 0; i < extra_count; i++) {
    3322                 uint32 jobid;
     3152        for (i = 0; i < extra_count; i++) {
     3153                uint32_t jobid;
    33233154                struct printjob *pjob;
    33243155
     
    33323163                }
    33333164
    3334                 queue[total_count].sysjob = jobid;
     3165                queue[total_count].sysjob = pjob->sysjob;
    33353166                queue[total_count].size = pjob->size;
    33363167                queue[total_count].page_count = pjob->page_count;
     
    33473178        for (i = 0; i < changed_count; i++) {
    33483179                uint32_t jobid = IVAL(jcdata.dptr, i * 4);
     3180                struct printjob *pjob;
    33493181                uint32_t j;
    33503182                bool found = false;
    33513183
     3184                pjob = print_job_find(tmp_ctx, sharename, jobid);
     3185                if (pjob == NULL) {
     3186                        DEBUG(5,("get_stored_queue_info: failed to find "
     3187                                 "changed job = %u\n",
     3188                                 (unsigned int)jobid));
     3189                        remove_from_jobs_changed(sharename, jobid);
     3190                        continue;
     3191                }
     3192
    33523193                for (j = 0; j < total_count; j++) {
    3353                         if (queue[j].sysjob == jobid) {
     3194                        if (queue[j].sysjob == pjob->sysjob) {
    33543195                                found = true;
    33553196                                break;
     
    33583199
    33593200                if (found) {
    3360                         struct printjob *pjob;
    3361 
    33623201                        DEBUG(5,("get_stored_queue_info: changed job: %u\n",
    3363                                  (unsigned int) jobid));
    3364 
    3365                         pjob = print_job_find(tmp_ctx, sharename, jobid);
    3366                         if (pjob == NULL) {
    3367                                 DEBUG(5,("get_stored_queue_info: failed to find "
    3368                                          "changed job = %u\n",
    3369                                          (unsigned int) jobid));
    3370                                 remove_from_jobs_changed(sharename, jobid);
    3371                                 continue;
    3372                         }
    3373 
    3374                         queue[j].sysjob = jobid;
     3202                                 (unsigned int)jobid));
     3203
     3204                        queue[j].sysjob = pjob->sysjob;
    33753205                        queue[j].size = pjob->size;
    33763206                        queue[j].page_count = pjob->page_count;
     
    33823212                        talloc_free(pjob);
    33833213
    3384                         DEBUG(5,("get_stored_queue_info: updated queue[%u], jobid: %u, jobname: %s\n",
    3385                                  (unsigned int) j, (unsigned int) jobid, pjob->jobname));
     3214                        DEBUG(5,("updated queue[%u], jobid: %u, sysjob: %u, "
     3215                                 "jobname: %s\n",
     3216                                 (unsigned int)j, (unsigned int)jobid,
     3217                                 (unsigned int)queue[j].sysjob, pjob->jobname));
    33863218                }
    33873219
     
    34023234        *pcount = total_count;
    34033235
    3404         ret = True;
     3236        ret = true;
    34053237
    34063238  out:
     
    34803312****************************************************************************/
    34813313
    3482 WERROR print_queue_pause(const struct auth_serversupplied_info *server_info,
     3314WERROR print_queue_pause(const struct auth_session_info *server_info,
    34833315                         struct messaging_context *msg_ctx, int snum)
    34843316{
     
    34863318        struct printif *current_printif = get_printer_fns( snum );
    34873319
    3488         if (!print_access_check(server_info, msg_ctx, snum,
    3489                                 PRINTER_ACCESS_ADMINISTER)) {
     3320        if (!W_ERROR_IS_OK(print_access_check(server_info, msg_ctx, snum,
     3321                                              PRINTER_ACCESS_ADMINISTER))) {
    34903322                return WERR_ACCESS_DENIED;
    34913323        }
     
    35173349****************************************************************************/
    35183350
    3519 WERROR print_queue_resume(const struct auth_serversupplied_info *server_info,
     3351WERROR print_queue_resume(const struct auth_session_info *server_info,
    35203352                          struct messaging_context *msg_ctx, int snum)
    35213353{
     
    35233355        struct printif *current_printif = get_printer_fns( snum );
    35243356
    3525         if (!print_access_check(server_info, msg_ctx, snum,
    3526                                 PRINTER_ACCESS_ADMINISTER)) {
     3357        if (!W_ERROR_IS_OK(print_access_check(server_info, msg_ctx, snum,
     3358                                              PRINTER_ACCESS_ADMINISTER))) {
    35273359                return WERR_ACCESS_DENIED;
    35283360        }
     
    35543386****************************************************************************/
    35553387
    3556 WERROR print_queue_purge(const struct auth_serversupplied_info *server_info,
     3388WERROR print_queue_purge(const struct auth_session_info *server_info,
    35573389                         struct messaging_context *msg_ctx, int snum)
    35583390{
     
    35653397        print_queue_update(msg_ctx, snum, True);
    35663398
    3567         can_job_admin = print_access_check(server_info,
    3568                                           msg_ctx,
    3569                                           snum,
    3570                                            JOB_ACCESS_ADMINISTER);
     3399        can_job_admin = W_ERROR_IS_OK(print_access_check(server_info,
     3400                                                        msg_ctx,
     3401                                                        snum,
     3402                                                        JOB_ACCESS_ADMINISTER));
    35713403        njobs = print_queue_status(msg_ctx, snum, &queue, &status);
    35723404
     
    35743406                become_root();
    35753407
    3576         for (i=0;i<njobs;i++) {
    3577                 bool owner = is_owner(server_info, lp_const_servicename(snum),
    3578                                       queue[i].sysjob);
     3408        for (i = 0; i < njobs; i++) {
     3409                struct tdb_print_db *pdb;
     3410                int jobid;
     3411                bool owner;
     3412                pdb = get_print_db_byname(lp_const_servicename(snum));
     3413                if (pdb == NULL) {
     3414                        DEBUG(1, ("failed to find printdb for %s\n",
     3415                                  lp_const_servicename(snum)));
     3416                        continue;
     3417                }
     3418                jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob);
     3419                if (jobid == (uint32_t)-1) {
     3420                        DEBUG(2, ("jobid for system job %d not found\n",
     3421                                  queue[i].sysjob));
     3422                        continue;       /* unix job */
     3423                }
     3424                owner = is_owner(server_info, lp_const_servicename(snum),
     3425                                 jobid);
    35793426
    35803427                if (owner || can_job_admin) {
    35813428                        print_job_delete1(server_event_context(), msg_ctx,
    3582                                           snum, queue[i].sysjob);
     3429                                          snum, jobid);
    35833430                }
    35843431        }
Note: See TracChangeset for help on using the changeset viewer.