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

Samba Server: updated vendor to 3.6.9

Location:
vendor/current/source3/printing
Files:
11 edited

Legend:

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

    r740 r746  
    3131        char *str;
    3232        char *saveptr;
     33        char *auto_serv = NULL;
    3334
    3435        if (pnum < 0)
     
    3940                return;
    4041
    41         if ((str = SMB_STRDUP(lp_auto_services())) == NULL)
     42        auto_serv = lp_auto_services();
     43        str = SMB_STRDUP(auto_serv);
     44        TALLOC_FREE(auto_serv);
     45        if (str == NULL) {
    4246                return;
     47        }
    4348
    4449        for (p = strtok_r(str, LIST_SEP, &saveptr); p;
  • vendor/current/source3/printing/lpq_parse.c

    r478 r746  
    165165        }
    166166
    167         buf->job = atoi(tok[JOBTOK]);
     167        buf->sysjob = atoi(tok[JOBTOK]);
    168168        buf->size = atoi(tok[TOTALTOK]);
    169169        buf->status = strequal(tok[RANKTOK],"active")?LPQ_PRINTING:LPQ_QUEUED;
     
    282282        }
    283283
    284         buf->job = atoi(tokarr[LPRNG_JOBTOK]);
     284        buf->sysjob = atoi(tokarr[LPRNG_JOBTOK]);
    285285        buf->size = atoi(tokarr[LPRNG_TOTALTOK]);
    286286
     
    385385                        }
    386386
    387                         buf->job = atoi(tok[1]);
     387                        buf->sysjob = atoi(tok[1]);
    388388                        buf->status = strequal(tok[0],"HELD")?LPQ_PAUSED:LPQ_QUEUED;
    389389                        buf->priority = 0;
     
    421421                }
    422422
    423                 buf->job = atoi(tok[3]);
     423                buf->sysjob = atoi(tok[3]);
    424424                buf->status = strequal(tok[2],"RUNNING")?LPQ_PRINTING:LPQ_QUEUED;
    425425                buf->priority = 0;
     
    512512                /* fill things from header line */
    513513                buf->time = jobtime;
    514                 buf->job = jobid;
     514                buf->sysjob = jobid;
    515515                buf->status = jobstat;
    516516                buf->priority = jobprio;
     
    652652        }
    653653
    654         buf->job = atoi(tok[1]);
     654        buf->sysjob = atoi(tok[1]);
    655655        buf->size = atoi(tok[3]);
    656656        if (count > 7 && strequal(tok[7],"on")) {
     
    727727        }
    728728
    729         buf->job = atoi(tok[2]);
     729        buf->sysjob = atoi(tok[2]);
    730730        buf->size = atoi(tok[4]);
    731731        buf->status = strequal(tok[3],"active")?LPQ_PRINTING:LPQ_QUEUED;
     
    807807        }
    808808
    809         buf->job = atoi(tok[4]);
     809        buf->sysjob = atoi(tok[4]);
    810810
    811811        buf->size = atoi(tok[7]);
     
    897897        trim_char(parse_line->jobname, '\0', ' ');
    898898
    899         buf->job = atoi(parse_line->jobid);
     899        buf->sysjob = atoi(parse_line->jobid);
    900900        buf->priority = 0;
    901901        buf->size = atoi(parse_line->size);
     
    958958
    959959        /* Get the jobid */
    960         buf->job = atoi(parse_line->jobid);
     960        buf->sysjob = atoi(parse_line->jobid);
    961961
    962962        /* Get the job name */
     
    10241024                switch (toknum) {
    10251025                case 0:
    1026                         buf->job = atoi(tok);
     1026                        buf->sysjob = atoi(tok);
    10271027                        break;
    10281028                case 1:
     
    11531153}
    11541154
    1155 /****************************************************************************
    1156  Parse a file name from the system spooler to generate a jobid.
    1157 ****************************************************************************/
    1158 
    1159 uint32_t print_parse_jobid(const char *fname)
    1160 {
    1161         int jobid;
    1162         const char *p = strstr_m(fname,PRINT_SPOOL_PREFIX);
    1163 
    1164         if (!p) {
    1165                 return (uint32_t)-1;
    1166         }
    1167         p += strlen(PRINT_SPOOL_PREFIX);
    1168         jobid = atoi(p);
    1169         if (jobid <= 0) {
    1170                 return (uint32_t)-1;
    1171         }
    1172         return (uint32_t)jobid;
    1173 }
  • vendor/current/source3/printing/nt_printing.c

    r740 r746  
    14941494
    14951495static NTSTATUS driver_unlink_internals(connection_struct *conn,
    1496                                         const char *name)
    1497 {
     1496                                        const char *short_arch,
     1497                                        int vers,
     1498                                        const char *fname)
     1499{
     1500        TALLOC_CTX *tmp_ctx = talloc_new(conn);
    14981501        struct smb_filename *smb_fname = NULL;
    1499         NTSTATUS status;
    1500 
    1501         status = create_synthetic_smb_fname(talloc_tos(), name, NULL, NULL,
    1502             &smb_fname);
     1502        char *print_dlr_path;
     1503        NTSTATUS status = NT_STATUS_NO_MEMORY;
     1504
     1505        print_dlr_path = talloc_asprintf(tmp_ctx, "%s/%d/%s",
     1506                                         short_arch, vers, fname);
     1507        if (print_dlr_path == NULL) {
     1508                goto err_out;
     1509        }
     1510
     1511        status = create_synthetic_smb_fname(tmp_ctx, print_dlr_path,
     1512                                            NULL, NULL, &smb_fname);
    15031513        if (!NT_STATUS_IS_OK(status)) {
    1504                 return status;
     1514                goto err_out;
    15051515        }
    15061516
    15071517        status = unlink_internals(conn, NULL, 0, smb_fname, false);
    1508 
    1509         TALLOC_FREE(smb_fname);
     1518err_out:
     1519        talloc_free(tmp_ctx);
    15101520        return status;
    15111521}
     
    15201530                         const struct spoolss_DriverInfo8 *r)
    15211531{
    1522         int i = 0;
    1523         char *s;
    1524         const char *file;
     1532        const char *short_arch;
    15251533        connection_struct *conn;
    15261534        NTSTATUS nt_status;
     
    15731581        }
    15741582
    1575         /* now delete the files; must strip the '\print$' string from
    1576            fron of path                                                */
     1583        short_arch = get_short_archi(r->architecture);
     1584        if (short_arch == NULL) {
     1585                DEBUG(0, ("bad architecture %s\n", r->architecture));
     1586                ret = false;
     1587                goto err_out;
     1588        }
     1589
     1590        /* now delete the files */
    15771591
    15781592        if (r->driver_path && r->driver_path[0]) {
    1579                 if ((s = strchr(&r->driver_path[1], '\\')) != NULL) {
    1580                         file = s;
    1581                         DEBUG(10,("deleting driverfile [%s]\n", s));
    1582                         driver_unlink_internals(conn, file);
    1583                 }
     1593                DEBUG(10,("deleting driverfile [%s]\n", r->driver_path));
     1594                driver_unlink_internals(conn, short_arch, r->version, r->driver_path);
    15841595        }
    15851596
    15861597        if (r->config_file && r->config_file[0]) {
    1587                 if ((s = strchr(&r->config_file[1], '\\')) != NULL) {
    1588                         file = s;
    1589                         DEBUG(10,("deleting configfile [%s]\n", s));
    1590                         driver_unlink_internals(conn, file);
    1591                 }
     1598                DEBUG(10,("deleting configfile [%s]\n", r->config_file));
     1599                driver_unlink_internals(conn, short_arch, r->version, r->config_file);
    15921600        }
    15931601
    15941602        if (r->data_file && r->data_file[0]) {
    1595                 if ((s = strchr(&r->data_file[1], '\\')) != NULL) {
    1596                         file = s;
    1597                         DEBUG(10,("deleting datafile [%s]\n", s));
    1598                         driver_unlink_internals(conn, file);
    1599                 }
     1603                DEBUG(10,("deleting datafile [%s]\n", r->data_file));
     1604                driver_unlink_internals(conn, short_arch, r->version, r->data_file);
    16001605        }
    16011606
    16021607        if (r->help_file && r->help_file[0]) {
    1603                 if ((s = strchr(&r->help_file[1], '\\')) != NULL) {
    1604                         file = s;
    1605                         DEBUG(10,("deleting helpfile [%s]\n", s));
    1606                         driver_unlink_internals(conn, file);
    1607                 }
    1608         }
    1609 
    1610         /* check if we are done removing files */
     1608                DEBUG(10,("deleting helpfile [%s]\n", r->help_file));
     1609                driver_unlink_internals(conn, short_arch, r->version, r->help_file);
     1610        }
    16111611
    16121612        if (r->dependent_files) {
     1613                int i = 0;
    16131614                while (r->dependent_files[i] && r->dependent_files[i][0]) {
    1614                         char *p;
    1615 
    1616                         /* bypass the "\print$" portion of the path */
    1617 
    1618                         if ((p = strchr(r->dependent_files[i]+1, '\\')) != NULL) {
    1619                                 file = p;
    1620                                 DEBUG(10,("deleting dependent file [%s]\n", file));
    1621                                 driver_unlink_internals(conn, file);
    1622                         }
    1623 
     1615                        DEBUG(10,("deleting dependent file [%s]\n", r->dependent_files[i]));
     1616                        driver_unlink_internals(conn, short_arch, r->version, r->dependent_files[i]);
    16241617                        i++;
    16251618                }
     
    18711864                                           printer, "");
    18721865        if (!W_ERROR_IS_OK(result)) {
    1873                 DEBUG(0, ("nt_printer_remove: failed to remove rpinter %s",
    1874                           printer));
    1875         }
    1876 }
     1866                DEBUG(0, ("nt_printer_remove: failed to remove printer %s: "
     1867                          "%s\n", printer, win_errstr(result)));
     1868        }
     1869}
     1870
     1871void nt_printer_add(TALLOC_CTX *mem_ctx,
     1872                    const struct auth_serversupplied_info *session_info,
     1873                    struct messaging_context *msg_ctx,
     1874                    const char *printer)
     1875{
     1876        WERROR result;
     1877
     1878        result = winreg_create_printer_internal(mem_ctx, session_info, msg_ctx,
     1879                                                printer);
     1880        if (!W_ERROR_IS_OK(result)) {
     1881                DEBUG(0, ("nt_printer_add: failed to add printer %s: %s\n",
     1882                          printer, win_errstr(result)));
     1883        }
     1884}
  • vendor/current/source3/printing/nt_printing_migrate.c

    r740 r746  
    44 *
    55 *  Copyright (c) Andreas Schneider            2010.
     6 *  Copyright (C) Bjoern Baumbach <bb@sernet.de> 2011
    67 *
    78 *  This program is free software; you can redistribute it and/or modify
     
    2829#include "rpc_client/cli_winreg_spoolss.h"
    2930
     31static const char *driver_file_basename(const char *file)
     32{
     33        const char *basefile;
     34
     35        basefile = strrchr(file, '\\');
     36        if (basefile == NULL) {
     37                basefile = file;
     38        } else {
     39                basefile++;
     40        }
     41
     42        return basefile;
     43}
     44
    3045NTSTATUS printing_tdb_migrate_form(TALLOC_CTX *mem_ctx,
    3146                                   struct rpc_pipe_client *winreg_pipe,
     
    7489                                         b,
    7590                                         &f1);
     91        if (W_ERROR_EQUAL(result, WERR_FILE_EXISTS)) {
     92                /* Don't migrate form if it already exists. */
     93                result = WERR_OK;
     94        }
    7695        if (!W_ERROR_IS_OK(result)) {
    7796                return werror_to_ntstatus(result);
     
    97116        const char *driver_name;
    98117        uint32_t driver_version;
     118        int i;
    99119
    100120        blob = data_blob_const(data, length);
     
    115135        ZERO_STRUCT(a);
    116136
     137        /* remove paths from file names */
     138        if (r.dependent_files != NULL) {
     139                for (i = 0 ; r.dependent_files[i] != NULL; i++) {
     140                        r.dependent_files[i] = driver_file_basename(r.dependent_files[i]);
     141                }
     142        }
    117143        a.string = r.dependent_files;
     144
     145        r.driverpath = driver_file_basename(r.driverpath);
     146        r.configfile = driver_file_basename(r.configfile);
     147        r.datafile = driver_file_basename(r.datafile);
     148        r.helpfile = driver_file_basename(r.helpfile);
    118149
    119150        d3.architecture = r.environment;
  • vendor/current/source3/printing/print_cups.c

    r740 r746  
    3232#include <cups/language.h>
    3333
     34#if (CUPS_VERSION_MAJOR > 1) || (CUPS_VERSION_MINOR > 5)
     35#define HAVE_CUPS_1_6 1
     36#endif
     37
     38#ifndef HAVE_CUPS_1_6
     39#define ippGetGroupTag(attr)  attr->group_tag
     40#define ippGetName(attr)      attr->name
     41#define ippGetValueTag(attr)  attr->value_tag
     42#define ippGetStatusCode(ipp) ipp->request.status.status_code
     43#define ippGetInteger(attr, element) attr->values[element].integer
     44#define ippGetString(attr, element, language) attr->values[element].string.text
     45
     46static ipp_attribute_t *
     47ippFirstAttribute(ipp_t *ipp)
     48{
     49  if (!ipp)
     50    return (NULL);
     51  return (ipp->current = ipp->attrs);
     52}
     53
     54static ipp_attribute_t *
     55ippNextAttribute(ipp_t *ipp)
     56{
     57  if (!ipp || !ipp->current)
     58    return (NULL);
     59  return (ipp->current = ipp->current->next);
     60}
     61
     62static int ippSetOperation(ipp_t *ipp, ipp_op_t op)
     63{
     64    ipp->request.op.operation_id = op;
     65    return (1);
     66}
     67
     68static int ippSetRequestId(ipp_t *ipp, int request_id)
     69{
     70    ipp->request.any.request_id = request_id;
     71    return (1);
     72}
     73#endif
     74
    3475static SIG_ATOMIC_T gotalarm;
    3576
     
    168209        bool ret_ok = false;
    169210
    170         for (attr = response->attrs; attr != NULL;) {
     211        for (attr = ippFirstAttribute(response); attr != NULL;) {
    171212               /*
    172213                * Skip leading attributes until we hit a printer...
    173214                */
    174215
    175                 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
    176                         attr = attr->next;
     216                while (attr != NULL && ippGetGroupTag(attr) != IPP_TAG_PRINTER)
     217                        attr = ippNextAttribute(response);
    177218
    178219                if (attr == NULL)
     
    186227                info       = NULL;
    187228
    188                 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
     229                while (attr != NULL && ippGetGroupTag(attr) == IPP_TAG_PRINTER) {
    189230                        size_t size;
    190                         if (strcmp(attr->name, "printer-name") == 0 &&
    191                             attr->value_tag == IPP_TAG_NAME) {
     231                        if (strcmp(ippGetName(attr), "printer-name") == 0 &&
     232                            ippGetValueTag(attr) == IPP_TAG_NAME) {
    192233                                if (!pull_utf8_talloc(mem_ctx,
    193234                                                &name,
    194                                                 attr->values[0].string.text,
     235                                                ippGetString(attr, 0, NULL),
    195236                                                &size)) {
    196237                                        goto err_out;
     
    198239                        }
    199240
    200                         if (strcmp(attr->name, "printer-info") == 0 &&
    201                             attr->value_tag == IPP_TAG_TEXT) {
     241                        if (strcmp(ippGetName(attr), "printer-info") == 0 &&
     242                            ippGetValueTag(attr) == IPP_TAG_TEXT) {
    202243                                if (!pull_utf8_talloc(mem_ctx,
    203244                                                &info,
    204                                                 attr->values[0].string.text,
     245                                                ippGetString(attr, 0, NULL),
    205246                                                &size)) {
    206247                                        goto err_out;
     
    208249                        }
    209250
    210                         if (strcmp(attr->name, "printer-location") == 0 &&
    211                             attr->value_tag == IPP_TAG_TEXT) {
     251                        if (strcmp(ippGetName(attr), "printer-location") == 0 &&
     252                            ippGetValueTag(attr) == IPP_TAG_TEXT) {
    212253                                if (!pull_utf8_talloc(mem_ctx,
    213254                                                &location,
    214                                                 attr->values[0].string.text,
     255                                                ippGetString(attr, 0, NULL),
    215256                                                &size)) {
    216257                                        goto err_out;
     
    218259                        }
    219260
    220                         attr = attr->next;
     261                        attr = ippNextAttribute(response);
    221262                }
    222263
     
    298339        request = ippNew();
    299340
    300         request->request.op.operation_id = CUPS_GET_PRINTERS;
    301         request->request.op.request_id   = 1;
     341        ippSetOperation(request, CUPS_GET_PRINTERS);
     342        ippSetRequestId(request, 1);
    302343
    303344        language = cupsLangDefault();
     
    340381        request = ippNew();
    341382
    342         request->request.op.operation_id = CUPS_GET_CLASSES;
    343         request->request.op.request_id   = 1;
     383        ippSetOperation(request, CUPS_GET_CLASSES);
     384        ippSetRequestId(request, 1);
    344385
    345386        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
     
    604645        request = ippNew();
    605646
    606         request->request.op.operation_id = IPP_CANCEL_JOB;
    607         request->request.op.request_id   = 1;
     647        ippSetOperation(request, IPP_CANCEL_JOB);
     648        ippSetRequestId(request, 1);
    608649
    609650        language = cupsLangDefault();
     
    631672
    632673        if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
    633                 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     674                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    634675                        DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
    635676                                ippErrorString(cupsLastError())));
     
    701742        request = ippNew();
    702743
    703         request->request.op.operation_id = IPP_HOLD_JOB;
    704         request->request.op.request_id   = 1;
     744        ippSetOperation(request, IPP_HOLD_JOB);
     745        ippSetRequestId(request, 1);
    705746
    706747        language = cupsLangDefault();
     
    727768
    728769        if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
    729                 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     770                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    730771                        DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
    731772                                ippErrorString(cupsLastError())));
     
    797838        request = ippNew();
    798839
    799         request->request.op.operation_id = IPP_RELEASE_JOB;
    800         request->request.op.request_id   = 1;
     840        ippSetOperation(request, IPP_RELEASE_JOB);
     841        ippSetRequestId(request, 1);
    801842
    802843        language = cupsLangDefault();
     
    823864
    824865        if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
    825                 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     866                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    826867                        DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
    827868                                ippErrorString(cupsLastError())));
     
    853894 */
    854895
    855 static int cups_job_submit(int snum, struct printjob *pjob)
     896static int cups_job_submit(int snum, struct printjob *pjob,
     897                           enum printing_types printing_type,
     898                           char *lpq_cmd)
    856899{
    857900        TALLOC_CTX *frame = talloc_stackframe();
     
    872915        char *filename = NULL;
    873916        size_t size;
    874         uint32_t jobid = (uint32_t)-1;
    875917
    876918        DEBUG(5,("cups_job_submit(%d, %p)\n", snum, pjob));
     
    903945        request = ippNew();
    904946
    905         request->request.op.operation_id = IPP_PRINT_JOB;
    906         request->request.op.request_id   = 1;
     947        ippSetOperation(request, IPP_PRINT_JOB);
     948        ippSetRequestId(request, 1);
    907949
    908950        language = cupsLangDefault();
     
    934976                     pjob->clientmachine);
    935977
    936         /* Get the jobid from the filename. */
    937         jobid = print_parse_jobid(pjob->filename);
    938         if (jobid == (uint32_t)-1) {
    939                 DEBUG(0,("cups_job_submit: failed to parse jobid from name %s\n",
    940                                 pjob->filename ));
    941                 jobid = 0;
    942         }
    943 
    944978        if (!push_utf8_talloc(frame, &jobname, pjob->jobname, &size)) {
    945979                goto out;
     
    947981        new_jobname = talloc_asprintf(frame,
    948982                        "%s%.8u %s", PRINT_SPOOL_PREFIX,
    949                         (unsigned int)jobid,
    950                         jobname);
     983                        pjob->jobid, jobname);
    951984        if (new_jobname == NULL) {
    952985                goto out;
     
    9801013        }
    9811014        if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) {
    982                 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     1015                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    9831016                        DEBUG(0,("Unable to print file to %s - %s\n",
    9841017                                 lp_printername(snum),
     
    9881021                        attr_job_id = ippFindAttribute(response, "job-id", IPP_TAG_INTEGER);
    9891022                        if(attr_job_id) {
    990                                 pjob->sysjob = attr_job_id->values[0].integer;
     1023                                pjob->sysjob = ippGetInteger(attr_job_id, 0);
    9911024                                DEBUG(5,("cups_job_submit: job-id %d\n", pjob->sysjob));
    9921025                        } else {
     
    11101143        request = ippNew();
    11111144
    1112         request->request.op.operation_id = IPP_GET_JOBS;
    1113         request->request.op.request_id   = 1;
     1145        ippSetOperation(request, IPP_GET_JOBS);
     1146        ippSetRequestId(request, 1);
    11141147
    11151148        language = cupsLangDefault();
     
    11391172        }
    11401173
    1141         if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     1174        if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    11421175                DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
    1143                          ippErrorString(response->request.status.status_code)));
     1176                         ippErrorString(ippGetStatusCode(response))));
    11441177                goto out;
    11451178        }
     
    11531186        queue  = NULL;
    11541187
    1155         for (attr = response->attrs; attr != NULL; attr = attr->next) {
     1188        for (attr = ippFirstAttribute(response); attr != NULL; attr = ippNextAttribute(response)) {
    11561189               /*
    11571190                * Skip leading attributes until we hit a job...
    11581191                */
    11591192
    1160                 while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
    1161                         attr = attr->next;
     1193                while (attr != NULL && ippGetGroupTag(attr) != IPP_TAG_JOB)
     1194                        attr = ippNextAttribute(response);
    11621195
    11631196                if (attr == NULL)
     
    11941227                job_name     = NULL;
    11951228
    1196                 while (attr != NULL && attr->group_tag == IPP_TAG_JOB) {
    1197                         if (attr->name == NULL) {
    1198                                 attr = attr->next;
     1229                while (attr != NULL && ippGetGroupTag(attr) == IPP_TAG_JOB) {
     1230                        if (ippGetName(attr) == NULL) {
     1231                                attr = ippNextAttribute(response);
    11991232                                break;
    12001233                        }
    12011234
    1202                         if (strcmp(attr->name, "job-id") == 0 &&
    1203                             attr->value_tag == IPP_TAG_INTEGER)
    1204                                 job_id = attr->values[0].integer;
    1205 
    1206                         if (strcmp(attr->name, "job-k-octets") == 0 &&
    1207                             attr->value_tag == IPP_TAG_INTEGER)
    1208                                 job_k_octets = attr->values[0].integer;
    1209 
    1210                         if (strcmp(attr->name, "job-priority") == 0 &&
    1211                             attr->value_tag == IPP_TAG_INTEGER)
    1212                                 job_priority = attr->values[0].integer;
    1213 
    1214                         if (strcmp(attr->name, "job-state") == 0 &&
    1215                             attr->value_tag == IPP_TAG_ENUM)
    1216                                 job_status = (ipp_jstate_t)(attr->values[0].integer);
    1217 
    1218                         if (strcmp(attr->name, "time-at-creation") == 0 &&
    1219                             attr->value_tag == IPP_TAG_INTEGER)
    1220                                 job_time = attr->values[0].integer;
    1221 
    1222                         if (strcmp(attr->name, "job-name") == 0 &&
    1223                             attr->value_tag == IPP_TAG_NAME) {
     1235                        if (strcmp(ippGetName(attr), "job-id") == 0 &&
     1236                            ippGetValueTag(attr) == IPP_TAG_INTEGER)
     1237                                job_id = ippGetInteger(attr, 0);
     1238
     1239                        if (strcmp(ippGetName(attr), "job-k-octets") == 0 &&
     1240                            ippGetValueTag(attr) == IPP_TAG_INTEGER)
     1241                                job_k_octets = ippGetInteger(attr, 0);
     1242
     1243                        if (strcmp(ippGetName(attr), "job-priority") == 0 &&
     1244                            ippGetValueTag(attr) == IPP_TAG_INTEGER)
     1245                                job_priority = ippGetInteger(attr, 0);
     1246
     1247                        if (strcmp(ippGetName(attr), "job-state") == 0 &&
     1248                            ippGetValueTag(attr) == IPP_TAG_ENUM)
     1249                                job_status = (ipp_jstate_t)ippGetInteger(attr, 0);
     1250
     1251                        if (strcmp(ippGetName(attr), "time-at-creation") == 0 &&
     1252                            ippGetValueTag(attr) == IPP_TAG_INTEGER)
     1253                                job_time = ippGetInteger(attr, 0);
     1254
     1255                        if (strcmp(ippGetName(attr), "job-name") == 0 &&
     1256                            ippGetValueTag(attr) == IPP_TAG_NAME) {
    12241257                                if (!pull_utf8_talloc(frame,
    12251258                                                &job_name,
    1226                                                 attr->values[0].string.text,
     1259                                                ippGetString(attr, 0, NULL),
    12271260                                                &size)) {
    12281261                                        goto out;
     
    12301263                        }
    12311264
    1232                         if (strcmp(attr->name, "job-originating-user-name") == 0 &&
    1233                             attr->value_tag == IPP_TAG_NAME) {
     1265                        if (strcmp(ippGetName(attr), "job-originating-user-name") == 0 &&
     1266                            ippGetValueTag(attr) == IPP_TAG_NAME) {
    12341267                                if (!pull_utf8_talloc(frame,
    12351268                                                &user_name,
    1236                                                 attr->values[0].string.text,
     1269                                                ippGetString(attr, 0, NULL),
    12371270                                                &size)) {
    12381271                                        goto out;
     
    12401273                        }
    12411274
    1242                         attr = attr->next;
     1275                        attr = ippNextAttribute(response);
    12431276                }
    12441277
     
    12541287                }
    12551288
    1256                 temp->job      = job_id;
     1289                temp->sysjob   = job_id;
    12571290                temp->size     = job_k_octets * 1024;
    12581291                temp->status   = job_status == IPP_JOB_PENDING ? LPQ_QUEUED :
     
    12861319        request = ippNew();
    12871320
    1288         request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
    1289         request->request.op.request_id   = 1;
     1321        ippSetOperation(request, IPP_GET_PRINTER_ATTRIBUTES);
     1322        ippSetRequestId(request, 1);
    12901323
    12911324        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
     
    13131346        }
    13141347
    1315         if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     1348        if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    13161349                DEBUG(0,("Unable to get printer status for %s - %s\n", printername,
    1317                          ippErrorString(response->request.status.status_code)));
     1350                         ippErrorString(ippGetStatusCode(response))));
    13181351                goto out;
    13191352        }
     
    13241357
    13251358        if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL) {
    1326                 if (attr->values[0].integer == IPP_PRINTER_STOPPED)
     1359                if (ippGetInteger(attr, 0) == IPP_PRINTER_STOPPED)
    13271360                        status->status = LPSTAT_STOPPED;
    13281361                else
     
    13341367                char *msg = NULL;
    13351368                if (!pull_utf8_talloc(frame, &msg,
    1336                                 attr->values[0].string.text,
     1369                                ippGetString(attr, 0, NULL),
    13371370                                &size)) {
    13381371                        SAFE_FREE(queue);
     
    14101443        request = ippNew();
    14111444
    1412         request->request.op.operation_id = IPP_PAUSE_PRINTER;
    1413         request->request.op.request_id   = 1;
     1445        ippSetOperation(request, IPP_PAUSE_PRINTER);
     1446        ippSetRequestId(request, 1);
    14141447
    14151448        language = cupsLangDefault();
     
    14411474
    14421475        if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
    1443                 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     1476                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    14441477                        DEBUG(0,("Unable to pause printer %s - %s\n",
    14451478                                 lp_printername(snum),
     
    15141547        request = ippNew();
    15151548
    1516         request->request.op.operation_id = IPP_RESUME_PRINTER;
    1517         request->request.op.request_id   = 1;
     1549        ippSetOperation(request, IPP_RESUME_PRINTER);
     1550        ippSetRequestId(request, 1);
    15181551
    15191552        language = cupsLangDefault();
     
    15451578
    15461579        if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
    1547                 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     1580                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    15481581                        DEBUG(0,("Unable to resume printer %s - %s\n",
    15491582                                 lp_printername(snum),
  • vendor/current/source3/printing/print_generic.c

    r740 r746  
    140140
    141141/****************************************************************************
     142get the current list of queued jobs
     143****************************************************************************/
     144static int generic_queue_get(const char *printer_name,
     145                             enum printing_types printing_type,
     146                             char *lpq_command,
     147                             print_queue_struct **q,
     148                             print_status_struct *status)
     149{
     150        char **qlines;
     151        int fd;
     152        int numlines, i, qcount;
     153        print_queue_struct *queue = NULL;
     154
     155        /* never do substitution when running the 'lpq command' since we can't
     156           get it rigt when using the background update daemon.  Make the caller
     157           do it before passing off the command string to us here. */
     158
     159        print_run_command(-1, printer_name, False, lpq_command, &fd, NULL);
     160
     161        if (fd == -1) {
     162                DEBUG(5,("generic_queue_get: Can't read print queue status for printer %s\n",
     163                        printer_name ));
     164                return 0;
     165        }
     166
     167        numlines = 0;
     168        qlines = fd_lines_load(fd, &numlines,0,NULL);
     169        close(fd);
     170
     171        /* turn the lpq output into a series of job structures */
     172        qcount = 0;
     173        ZERO_STRUCTP(status);
     174        if (numlines && qlines) {
     175                queue = SMB_MALLOC_ARRAY(print_queue_struct, numlines+1);
     176                if (!queue) {
     177                        TALLOC_FREE(qlines);
     178                        *q = NULL;
     179                        return 0;
     180                }
     181                memset(queue, '\0', sizeof(print_queue_struct)*(numlines+1));
     182
     183                for (i=0; i<numlines; i++) {
     184                        /* parse the line */
     185                        if (parse_lpq_entry(printing_type,qlines[i],
     186                                            &queue[qcount],status,qcount==0)) {
     187                                qcount++;
     188                        }
     189                }
     190        }
     191
     192        TALLOC_FREE(qlines);
     193        *q = queue;
     194        return qcount;
     195}
     196
     197/****************************************************************************
    142198 Submit a file for printing - called from print_job_end()
    143199****************************************************************************/
    144200
    145 static int generic_job_submit(int snum, struct printjob *pjob)
     201static int generic_job_submit(int snum, struct printjob *pjob,
     202                              enum printing_types printing_type,
     203                              char *lpq_cmd)
    146204{
    147205        int ret = -1;
     
    153211        TALLOC_CTX *ctx = talloc_tos();
    154212        fstring job_page_count, job_size;
     213        print_queue_struct *q;
     214        print_status_struct status;
    155215
    156216        /* we print from the directory path to give the best chance of
     
    203263                        "%c", job_page_count,
    204264                        NULL);
     265        if (ret != 0) {
     266                ret = -1;
     267                goto out;
     268        }
     269
     270        /*
     271         * check the queue for the newly submitted job, this allows us to
     272         * determine the backend job identifier (sysjob).
     273         */
     274        pjob->sysjob = -1;
     275        ret = generic_queue_get(lp_printername(snum), printing_type, lpq_cmd,
     276                                &q, &status);
     277        if (ret > 0) {
     278                int i;
     279                for (i = 0; i < ret; i++) {
     280                        if (strcmp(q[i].fs_file, p) == 0) {
     281                                pjob->sysjob = q[i].sysjob;
     282                                DEBUG(5, ("new job %u (%s) matches sysjob %d\n",
     283                                          pjob->jobid, jobname, pjob->sysjob));
     284                                break;
     285                        }
     286                }
     287                SAFE_FREE(q);
     288                ret = 0;
     289        }
     290        if (pjob->sysjob == -1) {
     291                DEBUG(2, ("failed to get sysjob for job %u (%s), tracking as "
     292                          "Unix job\n", pjob->jobid, jobname));
     293        }
     294
    205295
    206296 out:
     
    211301        TALLOC_FREE(current_directory);
    212302        return ret;
    213 }
    214 
    215 
    216 /****************************************************************************
    217 get the current list of queued jobs
    218 ****************************************************************************/
    219 static int generic_queue_get(const char *printer_name,
    220                              enum printing_types printing_type,
    221                              char *lpq_command,
    222                              print_queue_struct **q,
    223                              print_status_struct *status)
    224 {
    225         char **qlines;
    226         int fd;
    227         int numlines, i, qcount;
    228         print_queue_struct *queue = NULL;
    229        
    230         /* never do substitution when running the 'lpq command' since we can't
    231            get it rigt when using the background update daemon.  Make the caller
    232            do it before passing off the command string to us here. */
    233 
    234         print_run_command(-1, printer_name, False, lpq_command, &fd, NULL);
    235 
    236         if (fd == -1) {
    237                 DEBUG(5,("generic_queue_get: Can't read print queue status for printer %s\n",
    238                         printer_name ));
    239                 return 0;
    240         }
    241        
    242         numlines = 0;
    243         qlines = fd_lines_load(fd, &numlines,0,NULL);
    244         close(fd);
    245 
    246         /* turn the lpq output into a series of job structures */
    247         qcount = 0;
    248         ZERO_STRUCTP(status);
    249         if (numlines && qlines) {
    250                 queue = SMB_MALLOC_ARRAY(print_queue_struct, numlines+1);
    251                 if (!queue) {
    252                         TALLOC_FREE(qlines);
    253                         *q = NULL;
    254                         return 0;
    255                 }
    256                 memset(queue, '\0', sizeof(print_queue_struct)*(numlines+1));
    257 
    258                 for (i=0; i<numlines; i++) {
    259                         /* parse the line */
    260                         if (parse_lpq_entry(printing_type,qlines[i],
    261                                             &queue[qcount],status,qcount==0)) {
    262                                 qcount++;
    263                         }
    264                 }               
    265         }
    266 
    267         TALLOC_FREE(qlines);
    268         *q = queue;
    269         return qcount;
    270303}
    271304
  • vendor/current/source3/printing/print_iprint.c

    r740 r746  
    3535#define NOVELL_SERVER_VERSION_OES_SP1           33554432
    3636
     37#if (CUPS_VERSION_MAJOR > 1) || (CUPS_VERSION_MINOR > 5)
     38#define HAVE_CUPS_1_6 1
     39#endif
     40
     41#ifndef HAVE_CUPS_1_6
     42#define ippGetCount(attr)     attr->num_values
     43#define ippGetGroupTag(attr)  attr->group_tag
     44#define ippGetName(attr)      attr->name
     45#define ippGetValueTag(attr)  attr->value_tag
     46#define ippGetStatusCode(ipp) ipp->request.status.status_code
     47#define ippGetBoolean(attr, element) attr->values[element].boolean
     48#define ippGetInteger(attr, element) attr->values[element].integer
     49#define ippGetString(attr, element, language) attr->values[element].string.text
     50
     51static ipp_attribute_t *
     52ippFirstAttribute(ipp_t *ipp)
     53{
     54  if (!ipp)
     55    return (NULL);
     56  return (ipp->current = ipp->attrs);
     57}
     58
     59static ipp_attribute_t *
     60ippNextAttribute(ipp_t *ipp)
     61{
     62  if (!ipp || !ipp->current)
     63    return (NULL);
     64  return (ipp->current = ipp->current->next);
     65}
     66
     67static int ippSetOperation(ipp_t *ipp, ipp_op_t op)
     68{
     69    ipp->request.op.operation_id = op;
     70    return (1);
     71}
     72
     73static int ippSetRequestId(ipp_t *ipp, int request_id)
     74{
     75    ipp->request.any.request_id = request_id;
     76    return (1);
     77}
     78#endif
     79
    3780/*
    3881 * 'iprint_passwd_cb()' - The iPrint password callback...
     
    93136        request = ippNew();
    94137
    95         request->request.op.operation_id = (ipp_op_t)OPERATION_NOVELL_MGMT;
    96         request->request.op.request_id   = 1;
     138        ippSetOperation(request, (ipp_op_t)OPERATION_NOVELL_MGMT);
     139        ippSetRequestId(request, 1);
    97140
    98141        language = cupsLangDefault();
     
    115158
    116159        if (((response = cupsDoRequest(http, request, "/ipp/")) == NULL) ||
    117             (response->request.status.status_code >= IPP_OK_CONFLICT))
     160            (ippGetStatusCode(response) >= IPP_OK_CONFLICT))
    118161                goto out;
    119162
    120163        if (((attr = ippFindAttribute(response, "server-version",
    121164                                      IPP_TAG_STRING)) != NULL)) {
    122                 if ((ver = strstr(attr->values[0].string.text,
     165                if ((ver = strstr(ippGetString(attr, 0, NULL),
    123166                                  NOVELL_SERVER_VERSION_STRING)) != NULL) {
    124167                        ver += strlen(NOVELL_SERVER_VERSION_STRING);
     
    136179                }
    137180
    138                 if ((os = strstr(attr->values[0].string.text,
     181                if ((os = strstr(ippGetString(attr, 0, NULL),
    139182                                  NOVELL_SERVER_SYSNAME)) != NULL) {
    140183                        os += strlen(NOVELL_SERVER_SYSNAME);
     
    185228        request = ippNew();
    186229
    187         request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
    188         request->request.op.request_id   = reqId;
     230        ippSetOperation(request, IPP_GET_PRINTER_ATTRIBUTES);
     231        ippSetRequestId(request, reqId);
    189232
    190233        language = cupsLangDefault();
     
    231274        }
    232275
    233         for (attr = response->attrs; attr != NULL;) {
     276        for (attr = ippFirstAttribute(response); attr != NULL;) {
    234277               /*
    235278                * Skip leading attributes until we hit a printer...
    236279                */
    237280
    238                 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
    239                         attr = attr->next;
     281                while (attr != NULL && ippGetGroupTag(attr) != IPP_TAG_PRINTER)
     282                        attr = ippNextAttribute(response);
    240283
    241284                if (attr == NULL)
     
    251294                secure     = 0;
    252295
    253                 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
    254                         if (strcmp(attr->name, "printer-name") == 0 &&
    255                             attr->value_tag == IPP_TAG_NAME)
    256                                 name = attr->values[0].string.text;
    257 
    258                         if (strcmp(attr->name, "printer-info") == 0 &&
    259                             (attr->value_tag == IPP_TAG_TEXT ||
    260                             attr->value_tag == IPP_TAG_TEXTLANG))
    261                                 info = attr->values[0].string.text;
     296                while (attr != NULL && ippGetGroupTag(attr) == IPP_TAG_PRINTER) {
     297                        if (strcmp(ippGetName(attr), "printer-name") == 0 &&
     298                            ippGetValueTag(attr) == IPP_TAG_NAME)
     299                                name = ippGetString(attr, 0, NULL);
     300
     301                        if (strcmp(ippGetName(attr), "printer-info") == 0 &&
     302                            (ippGetValueTag(attr) == IPP_TAG_TEXT ||
     303                            ippGetValueTag(attr) == IPP_TAG_TEXTLANG))
     304                                info = ippGetString(attr, 0, NULL);
    262305
    263306                       /*
     
    267310                        * printer should show up
    268311                        */
    269                         if (!strcmp(attr->name, "smb-enabled") &&
    270                             ((attr->value_tag == IPP_TAG_INTEGER &&
    271                             !attr->values[0].integer) ||
    272                             (attr->value_tag == IPP_TAG_BOOLEAN &&
    273                             !attr->values[0].boolean)))
     312                        if (!strcmp(ippGetName(attr), "smb-enabled") &&
     313                            ((ippGetValueTag(attr) == IPP_TAG_INTEGER &&
     314                            !ippGetInteger(attr, 0)) ||
     315                            (ippGetValueTag(attr) == IPP_TAG_BOOLEAN &&
     316                            !ippGetBoolean(attr, 0))))
    274317                                smb_enabled = 0;
    275318
     
    280323                        * printer should show up
    281324                        */
    282                         if (!strcmp(attr->name, "security-enabled") &&
    283                             ((attr->value_tag == IPP_TAG_INTEGER &&
    284                             attr->values[0].integer) ||
    285                             (attr->value_tag == IPP_TAG_BOOLEAN &&
    286                             attr->values[0].boolean)))
     325                        if (!strcmp(ippGetName(attr), "security-enabled") &&
     326                            ((ippGetValueTag(attr) == IPP_TAG_INTEGER &&
     327                            ippGetInteger(attr, 0)) ||
     328                            (ippGetValueTag(attr) == IPP_TAG_BOOLEAN &&
     329                            ippGetBoolean(attr, 0))))
    287330                                secure = 1;
    288331
    289                         attr = attr->next;
     332                        attr = ippNextAttribute(response);
    290333                }
    291334
     
    344387        request = ippNew();
    345388
    346         request->request.op.operation_id =
    347                 (ipp_op_t)OPERATION_NOVELL_LIST_PRINTERS;
    348         request->request.op.request_id   = 1;
     389        ippSetOperation(request, (ipp_op_t)OPERATION_NOVELL_LIST_PRINTERS);
     390        ippSetRequestId(request, 1);
    349391
    350392        language = cupsLangDefault();
     
    369411        }
    370412
    371         for (attr = response->attrs; attr != NULL;) {
     413        for (attr = ippFirstAttribute(response); attr != NULL;) {
    372414               /*
    373415                * Skip leading attributes until we hit a printer...
    374416                */
    375417
    376                 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
    377                         attr = attr->next;
     418                while (attr != NULL && ippGetGroupTag(attr) != IPP_TAG_PRINTER)
     419                        attr = ippNextAttribute(response);
    378420
    379421                if (attr == NULL)
     
    384426                */
    385427
    386                 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
     428                while (attr != NULL && ippGetGroupTag(attr) == IPP_TAG_PRINTER)
    387429                {
    388                         if (strcmp(attr->name, "printer-name") == 0 &&
    389                             (attr->value_tag == IPP_TAG_URI ||
    390                              attr->value_tag == IPP_TAG_NAME ||
    391                              attr->value_tag == IPP_TAG_TEXT ||
    392                              attr->value_tag == IPP_TAG_NAMELANG ||
    393                              attr->value_tag == IPP_TAG_TEXTLANG))
     430                        if (strcmp(ippGetName(attr), "printer-name") == 0 &&
     431                            (ippGetValueTag(attr) == IPP_TAG_URI ||
     432                             ippGetValueTag(attr) == IPP_TAG_NAME ||
     433                             ippGetValueTag(attr) == IPP_TAG_TEXT ||
     434                             ippGetValueTag(attr) == IPP_TAG_NAMELANG ||
     435                             ippGetValueTag(attr) == IPP_TAG_TEXTLANG))
    394436                        {
    395                                 for (i = 0; i<attr->num_values; i++)
     437                                for (i = 0; i<ippGetCount(attr); i++)
    396438                                {
    397                                         char *url = attr->values[i].string.text;
     439                                        char *url = ippGetString(attr, i, NULL);
    398440                                        if (!url || !strlen(url))
    399441                                                continue;
     
    401443                                }
    402444                        }
    403                         attr = attr->next;
     445                        attr = ippNextAttribute(response);
    404446                }
    405447        }
     
    467509        request = ippNew();
    468510
    469         request->request.op.operation_id = IPP_CANCEL_JOB;
    470         request->request.op.request_id   = 1;
     511        ippSetOperation(request, IPP_CANCEL_JOB);
     512        ippSetRequestId(request, 1);
    471513
    472514        language = cupsLangDefault();
     
    494536
    495537        if ((response = cupsDoRequest(http, request, httpPath)) != NULL) {
    496                 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     538                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    497539                        DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
    498540                                ippErrorString(cupsLastError())));
     
    565607        request = ippNew();
    566608
    567         request->request.op.operation_id = IPP_HOLD_JOB;
    568         request->request.op.request_id   = 1;
     609        ippSetOperation(request, IPP_HOLD_JOB);
     610        ippSetRequestId(request, 1);
    569611
    570612        language = cupsLangDefault();
     
    594636
    595637        if ((response = cupsDoRequest(http, request, httpPath)) != NULL) {
    596                 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     638                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    597639                        DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
    598640                                ippErrorString(cupsLastError())));
     
    665707        request = ippNew();
    666708
    667         request->request.op.operation_id = IPP_RELEASE_JOB;
    668         request->request.op.request_id   = 1;
     709        ippSetOperation(request, IPP_RELEASE_JOB);
     710        ippSetRequestId(request, 1);
    669711
    670712        language = cupsLangDefault();
     
    694736
    695737        if ((response = cupsDoRequest(http, request, httpPath)) != NULL) {
    696                 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     738                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    697739                        DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
    698740                                ippErrorString(cupsLastError())));
     
    723765 */
    724766
    725 static int iprint_job_submit(int snum, struct printjob *pjob)
     767static int iprint_job_submit(int snum, struct printjob *pjob,
     768                             enum printing_types printing_type,
     769                             char *lpq_cmd)
    726770{
    727771        int             ret = 1;                /* Return value */
     
    764808        request = ippNew();
    765809
    766         request->request.op.operation_id = IPP_PRINT_JOB;
    767         request->request.op.request_id   = 1;
     810        ippSetOperation(request, IPP_PRINT_JOB);
     811        ippSetRequestId(request, 1);
    768812
    769813        language = cupsLangDefault();
     
    798842
    799843        if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) {
    800                 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     844                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    801845                        DEBUG(0,("Unable to print file to %s - %s\n",
    802846                                 lp_printername(snum),
     
    818862
    819863                attr = ippFindAttribute(response, "job-id", IPP_TAG_INTEGER);
    820                 if (attr != NULL && attr->group_tag == IPP_TAG_JOB)
     864                if (attr != NULL && ippGetGroupTag(attr) == IPP_TAG_JOB)
    821865                {
    822                         pjob->sysjob = attr->values[0].integer;
     866                        pjob->sysjob = ippGetInteger(attr, 0);
    823867                }
    824868        }
     
    867911        int             job_k_octets;   /* job-k-octets attribute */
    868912        time_t          job_time;       /* time-at-creation attribute */
    869         time_t          printer_current_time = 0;       /* printer's current time */
    870913        time_t          printer_up_time = 0;    /* printer's uptime */
    871914        ipp_jstate_t    job_status;     /* job-status attribute */
     
    940983        request = ippNew();
    941984
    942         request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
    943         request->request.op.request_id   = 2;
     985        ippSetOperation(request, IPP_GET_PRINTER_ATTRIBUTES);
     986        ippSetRequestId(request, 2);
    944987
    945988        language = cupsLangDefault();
     
    9721015        }
    9731016
    974         if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     1017        if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    9751018                DEBUG(0,("Unable to get printer status for %s - %s\n", printername,
    976                          ippErrorString(response->request.status.status_code)));
     1019                         ippErrorString(ippGetStatusCode(response))));
    9771020                *q = queue;
    9781021                goto out;
     
    9841027
    9851028        if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL) {
    986                 if (attr->values[0].integer == IPP_PRINTER_STOPPED)
     1029                if (ippGetInteger(attr, 0) == IPP_PRINTER_STOPPED)
    9871030                        status->status = LPSTAT_STOPPED;
    9881031                else
     
    9921035        if ((attr = ippFindAttribute(response, "printer-state-message",
    9931036                                     IPP_TAG_TEXT)) != NULL)
    994                 fstrcpy(status->message, attr->values[0].string.text);
    995 
    996         if ((attr = ippFindAttribute(response, "printer-current-time",
    997                                      IPP_TAG_DATE)) != NULL)
    998                 printer_current_time = ippDateToTime(attr->values[0].date);
     1037                fstrcpy(status->message, ippGetString(attr, 0, NULL));
    9991038
    10001039        if ((attr = ippFindAttribute(response, "printer-up-time",
    10011040                                     IPP_TAG_INTEGER)) != NULL)
    1002                 printer_up_time = attr->values[0].integer;
     1041                printer_up_time = ippGetInteger(attr, 0);
    10031042
    10041043        ippDelete(response);
     
    10171056        request = ippNew();
    10181057
    1019         request->request.op.operation_id = IPP_GET_JOBS;
    1020         request->request.op.request_id   = 3;
     1058        ippSetOperation(request, IPP_GET_JOBS);
     1059        ippSetRequestId(request, 3);
    10211060
    10221061        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
     
    10461085        }
    10471086
    1048         if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     1087        if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    10491088                DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
    1050                          ippErrorString(response->request.status.status_code)));
     1089                         ippErrorString(ippGetStatusCode(response))));
    10511090                goto out;
    10521091        }
     
    10601099        queue  = NULL;
    10611100
    1062         for (attr = response->attrs; attr != NULL; attr = attr->next) {
     1101        for (attr = ippFirstAttribute(response); attr != NULL; attr = ippNextAttribute(response)) {
    10631102               /*
    10641103                * Skip leading attributes until we hit a job...
    10651104                */
    10661105
    1067                 while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
    1068                         attr = attr->next;
     1106                while (attr != NULL && ippGetGroupTag(attr) != IPP_TAG_JOB)
     1107                        attr = ippNextAttribute(response);
    10691108
    10701109                if (attr == NULL)
     
    11011140                job_name     = NULL;
    11021141
    1103                 while (attr != NULL && attr->group_tag == IPP_TAG_JOB) {
    1104                         if (attr->name == NULL) {
    1105                                 attr = attr->next;
     1142                while (attr != NULL && ippGetGroupTag(attr) == IPP_TAG_JOB) {
     1143                        if (ippGetName(attr) == NULL) {
     1144                                attr = ippNextAttribute(response);
    11061145                                break;
    11071146                        }
    11081147
    1109                         if (strcmp(attr->name, "job-id") == 0 &&
    1110                             attr->value_tag == IPP_TAG_INTEGER)
    1111                                 job_id = attr->values[0].integer;
    1112 
    1113                         if (strcmp(attr->name, "job-k-octets") == 0 &&
    1114                             attr->value_tag == IPP_TAG_INTEGER)
    1115                                 job_k_octets = attr->values[0].integer;
    1116 
    1117                         if (strcmp(attr->name, "job-priority") == 0 &&
    1118                             attr->value_tag == IPP_TAG_INTEGER)
    1119                                 job_priority = attr->values[0].integer;
    1120 
    1121                         if (strcmp(attr->name, "job-state") == 0 &&
    1122                             attr->value_tag == IPP_TAG_ENUM)
    1123                                 job_status = (ipp_jstate_t)(attr->values[0].integer);
    1124 
    1125                         if (strcmp(attr->name, "time-at-creation") == 0 &&
    1126                             attr->value_tag == IPP_TAG_INTEGER)
     1148                        if (strcmp(ippGetName(attr), "job-id") == 0 &&
     1149                            ippGetValueTag(attr) == IPP_TAG_INTEGER)
     1150                                job_id = ippGetInteger(attr, 0);
     1151
     1152                        if (strcmp(ippGetName(attr), "job-k-octets") == 0 &&
     1153                            ippGetValueTag(attr) == IPP_TAG_INTEGER)
     1154                                job_k_octets = ippGetInteger(attr, 0);
     1155
     1156                        if (strcmp(ippGetName(attr), "job-priority") == 0 &&
     1157                            ippGetValueTag(attr) == IPP_TAG_INTEGER)
     1158                                job_priority = ippGetInteger(attr, 0);
     1159
     1160                        if (strcmp(ippGetName(attr), "job-state") == 0 &&
     1161                            ippGetValueTag(attr) == IPP_TAG_ENUM)
     1162                                job_status = (ipp_jstate_t)ippGetInteger(attr, 0);
     1163
     1164                        if (strcmp(ippGetName(attr), "time-at-creation") == 0 &&
     1165                            ippGetValueTag(attr) == IPP_TAG_INTEGER)
    11271166                        {
    11281167                               /*
     
    11341173
    11351174                                if (jobUseUnixTime)
    1136                                         job_time = attr->values[0].integer;
     1175                                        job_time = ippGetInteger(attr, 0);
    11371176                                else
    1138                                         job_time = time(NULL) - printer_up_time + attr->values[0].integer;
     1177                                        job_time = time(NULL) - printer_up_time + ippGetInteger(attr, 0);
    11391178                        }
    11401179
    1141                         if (strcmp(attr->name, "job-name") == 0 &&
    1142                             (attr->value_tag == IPP_TAG_NAMELANG ||
    1143                              attr->value_tag == IPP_TAG_NAME))
    1144                                 job_name = attr->values[0].string.text;
    1145 
    1146                         if (strcmp(attr->name, "job-originating-user-name") == 0 &&
    1147                             (attr->value_tag == IPP_TAG_NAMELANG ||
    1148                              attr->value_tag == IPP_TAG_NAME))
    1149                                 user_name = attr->values[0].string.text;
    1150 
    1151                         attr = attr->next;
     1180                        if (strcmp(ippGetName(attr), "job-name") == 0 &&
     1181                            (ippGetValueTag(attr) == IPP_TAG_NAMELANG ||
     1182                             ippGetValueTag(attr) == IPP_TAG_NAME))
     1183                                job_name = ippGetString(attr, 0, NULL);
     1184
     1185                        if (strcmp(ippGetName(attr), "job-originating-user-name") == 0 &&
     1186                            (ippGetValueTag(attr) == IPP_TAG_NAMELANG ||
     1187                             ippGetValueTag(attr) == IPP_TAG_NAME))
     1188                                user_name = ippGetString(attr, 0, NULL);
     1189
     1190                        attr = ippNextAttribute(response);
    11521191                }
    11531192
     
    11631202                }
    11641203
    1165                 temp->job      = job_id;
     1204                temp->sysjob   = job_id;
    11661205                temp->size     = job_k_octets * 1024;
    11671206                temp->status   = job_status == IPP_JOB_PENDING ? LPQ_QUEUED :
  • vendor/current/source3/printing/printer_list.c

    r740 r746  
    9292        data = dbwrap_fetch_bystring_upper(db, key, key);
    9393        if (data.dptr == NULL) {
    94                 DEBUG(1, ("Failed to fetch record!\n"));
     94                DEBUG(6, ("Failed to fetch record! "
     95                          "The printer database is empty?\n"));
    9596                status = NT_STATUS_NOT_FOUND;
    9697                goto done;
     
    192193
    193194        len = tdb_pack(data.dptr, data.dsize,
    194                        PL_DATA_FORMAT, time_h, time_l, name, str);
     195                       PL_DATA_FORMAT, time_h, time_l, name, str, str2);
    195196
    196197        status = dbwrap_store_bystring_upper(db, key, data, TDB_REPLACE);
  • vendor/current/source3/printing/printing.c

    r740 r746  
    374374***********************************************************************/
    375375
    376 static int unpack_pjob( uint8 *buf, int buflen, struct printjob *pjob )
     376static int unpack_pjob(TALLOC_CTX *mem_ctx, uint8 *buf, int buflen,
     377                       struct printjob *pjob)
    377378{
    378379        int     len = 0;
    379380        int     used;
    380         uint32 pjpid, pjsysjob, pjfd, pjstarttime, pjstatus;
     381        uint32 pjpid, pjjobid, pjsysjob, pjfd, pjstarttime, pjstatus;
    381382        uint32 pjsize, pjpage_count, pjspooled, pjsmbjob;
    382383
    383         if ( !buf || !pjob )
     384        if (!buf || !pjob) {
    384385                return -1;
    385 
    386         len += tdb_unpack(buf+len, buflen-len, "dddddddddfffff",
     386        }
     387
     388        len += tdb_unpack(buf+len, buflen-len, "ddddddddddfffff",
    387389                                &pjpid,
     390                                &pjjobid,
    388391                                &pjsysjob,
    389392                                &pjfd,
     
    400403                                pjob->queuename);
    401404
    402         if ( len == -1 )
     405        if (len == -1) {
    403406                return -1;
    404 
    405         used = unpack_devicemode(NULL, buf+len, buflen-len, &pjob->devmode);
     407        }
     408
     409        used = unpack_devicemode(mem_ctx, buf+len, buflen-len, &pjob->devmode);
    406410        if (used == -1) {
    407411                return -1;
     
    411415
    412416        pjob->pid = pjpid;
     417        pjob->jobid = pjjobid;
    413418        pjob->sysjob = pjsysjob;
    414419        pjob->fd = pjfd;
     
    428433****************************************************************************/
    429434
    430 static struct printjob *print_job_find(const char *sharename, uint32 jobid)
    431 {
    432         static struct printjob  pjob;
     435static struct printjob *print_job_find(TALLOC_CTX *mem_ctx,
     436                                       const char *sharename,
     437                                       uint32 jobid)
     438{
     439        struct printjob         *pjob;
    433440        uint32_t tmp;
    434441        TDB_DATA                ret;
     
    446453
    447454        if (!ret.dptr) {
    448                 DEBUG(10,("print_job_find: failed to find jobid %u.\n", (unsigned int)jobid ));
     455                DEBUG(10, ("print_job_find: failed to find jobid %u.\n",
     456                           jobid));
    449457                return NULL;
    450458        }
    451459
    452         talloc_free(pjob.devmode);
    453 
    454         ZERO_STRUCT( pjob );
    455 
    456         if ( unpack_pjob( ret.dptr, ret.dsize, &pjob ) == -1 ) {
    457                 DEBUG(10,("print_job_find: failed to unpack jobid %u.\n", (unsigned int)jobid ));
    458                 SAFE_FREE(ret.dptr);
    459                 return NULL;
    460         }
    461 
     460        pjob = talloc_zero(mem_ctx, struct printjob);
     461        if (pjob == NULL) {
     462                goto err_out;
     463        }
     464
     465        if (unpack_pjob(mem_ctx, ret.dptr, ret.dsize, pjob) == -1) {
     466                DEBUG(10, ("failed to unpack jobid %u.\n", jobid));
     467                talloc_free(pjob);
     468                pjob = NULL;
     469                goto err_out;
     470        }
     471
     472        DEBUG(10,("print_job_find: returning system job %d for jobid %u.\n",
     473                  pjob->sysjob, jobid));
     474        SMB_ASSERT(pjob->jobid == jobid);
     475
     476err_out:
    462477        SAFE_FREE(ret.dptr);
    463 
    464         DEBUG(10,("print_job_find: returning system job %d for jobid %u.\n",
    465                         (int)pjob.sysjob, (unsigned int)jobid ));
    466 
    467         return &pjob;
     478        return pjob;
    468479}
    469480
     
    490501
    491502        if (state->sysjob == pjob->sysjob) {
    492                 uint32 jobid = IVAL(key.dptr,0);
    493 
    494                 state->sysjob_to_jobid_value = jobid;
     503                state->sysjob_to_jobid_value = pjob->jobid;
    495504                return 1;
    496505        }
    497506
    498507        return 0;
     508}
     509
     510static uint32 sysjob_to_jobid_pdb(struct tdb_print_db *pdb, int sysjob)
     511{
     512        struct unixjob_traverse_state state;
     513
     514        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;
    499520}
    500521
     
    738759                len = 0;
    739760                buflen = newlen;
    740                 len += tdb_pack(buf+len, buflen-len, "dddddddddfffff",
     761                len += tdb_pack(buf+len, buflen-len, "ddddddddddfffff",
    741762                                (uint32)pjob->pid,
     763                                (uint32)pjob->jobid,
    742764                                (uint32)pjob->sysjob,
    743765                                (uint32)pjob->fd,
     
    776798        /* Send notify updates for what has changed */
    777799
    778         if ( ret ) {
     800        if (ret) {
    779801                bool changed = false;
    780802                struct printjob old_pjob;
    781803
    782                 if ( old_data.dsize )
    783                 {
    784                         if ( unpack_pjob( old_data.dptr, old_data.dsize, &old_pjob ) != -1 )
    785                         {
    786                                 pjob_store_notify(server_event_context(),
     804                if (old_data.dsize) {
     805                        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     806                        if (tmp_ctx == NULL)
     807                                goto done;
     808
     809                        len = unpack_pjob(tmp_ctx, old_data.dptr,
     810                                          old_data.dsize, &old_pjob);
     811                        if (len != -1 ) {
     812                                pjob_store_notify(ev,
    787813                                                  msg_ctx,
    788814                                                  sharename, jobid, &old_pjob,
    789815                                                  pjob,
    790816                                                  &changed);
    791                                 talloc_free(old_pjob.devmode);
    792 
    793817                                if (changed) {
    794818                                        add_to_jobs_changed(pdb, jobid);
    795819                                }
    796820                        }
    797 
    798                 }
    799                 else {
     821                        talloc_free(tmp_ctx);
     822
     823                } else {
    800824                        /* new job */
    801                         pjob_store_notify(server_event_context(), msg_ctx,
     825                        pjob_store_notify(ev, msg_ctx,
    802826                                          sharename, jobid, NULL, pjob,
    803827                                          &changed);
     
    805829        }
    806830
     831done:
    807832        release_print_db(pdb);
    808 done:
    809833        SAFE_FREE( old_data.dptr );
    810834        SAFE_FREE( buf );
     
    825849        uint32 job_status = 0;
    826850        struct tdb_print_db *pdb;
    827 
    828         pdb = get_print_db_byname( sharename );
    829 
    830         if (!pdb)
     851        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     852        if (tmp_ctx == NULL) {
    831853                return;
    832 
    833         pjob = print_job_find( sharename, jobid );
    834 
     854        }
     855
     856        pdb = get_print_db_byname(sharename);
     857        if (!pdb) {
     858                goto err_out;
     859        }
     860
     861        pjob = print_job_find(tmp_ctx, sharename, jobid);
    835862        if (!pjob) {
    836                 DEBUG(5, ("pjob_delete: we were asked to delete nonexistent job %u\n",
    837                                         (unsigned int)jobid));
    838                 release_print_db(pdb);
    839                 return;
     863                DEBUG(5, ("we were asked to delete nonexistent job %u\n",
     864                          jobid));
     865                goto err_release;
    840866        }
    841867
     
    851877        tdb_delete(pdb->tdb, print_key(jobid, &tmp));
    852878        remove_from_jobs_added(sharename, jobid);
    853         release_print_db( pdb );
    854879        rap_jobid_delete(sharename, jobid);
     880err_release:
     881        release_print_db(pdb);
     882err_out:
     883        talloc_free(tmp_ctx);
    855884}
    856885
     
    865894{
    866895        struct printjob pj, *old_pj;
    867 
    868         if (jobid == (uint32)-1)
    869                 jobid = q->job + UNIX_JOB_START;
     896        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     897        if (tmp_ctx == NULL) {
     898                return;
     899        }
     900
     901        if (jobid == (uint32)-1) {
     902                jobid = q->sysjob + UNIX_JOB_START;
     903        }
    870904
    871905        /* Preserve the timestamp on an existing unix print job */
    872906
    873         old_pj = print_job_find(sharename, jobid);
     907        old_pj = print_job_find(tmp_ctx, sharename, jobid);
    874908
    875909        ZERO_STRUCT(pj);
    876910
    877911        pj.pid = (pid_t)-1;
    878         pj.sysjob = q->job;
     912        pj.jobid = jobid;
     913        pj.sysjob = q->sysjob;
    879914        pj.fd = -1;
    880915        pj.starttime = old_pj ? old_pj->starttime : q->time;
     
    894929
    895930        pjob_store(ev, msg_ctx, sharename, jobid, &pj);
     931        talloc_free(tmp_ctx);
    896932}
    897933
     
    906942        struct tevent_context *ev;
    907943        struct messaging_context *msg_ctx;
     944        TALLOC_CTX *mem_ctx;
    908945};
    909946
     
    922959                return 0;
    923960
    924         jobid = IVAL(key.dptr, 0);
    925         if ( unpack_pjob( data.dptr, data.dsize, &pjob ) == -1 )
     961        if (unpack_pjob(ts->mem_ctx, data.dptr, data.dsize, &pjob) == -1)
    926962                return 0;
    927963        talloc_free(pjob.devmode);
    928 
     964        jobid = pjob.jobid;
    929965
    930966        if (!pjob.smbjob) {
    931967                /* remove a unix job if it isn't in the system queue any more */
    932 
    933968                for (i=0;i<ts->qcount;i++) {
    934                         uint32 u_jobid = (ts->queue[i].job + UNIX_JOB_START);
    935                         if (jobid == u_jobid)
     969                        if (ts->queue[i].sysjob == pjob.sysjob) {
    936970                                break;
     971                        }
    937972                }
    938973                if (i == ts->qcount) {
     
    9651000        /* this check only makes sense for jobs submitted from Windows clients */
    9661001
    967         if ( pjob.smbjob ) {
     1002        if (pjob.smbjob) {
    9681003                for (i=0;i<ts->qcount;i++) {
    969                         uint32 curr_jobid;
    970 
    9711004                        if ( pjob.status == LPQ_DELETED )
    9721005                                continue;
    9731006
    974                         curr_jobid = print_parse_jobid(ts->queue[i].fs_file);
    975 
    976                         if (jobid == curr_jobid) {
     1007                        if (ts->queue[i].sysjob == pjob.sysjob) {
    9771008
    9781009                                /* try to clean up any jobs that need to be deleted */
     
    10291060        }
    10301061
    1031         /* Save the pjob attributes we will store.
    1032            FIXME!!! This is the only place where queue->job
    1033            represents the SMB jobid      --jerry */
    1034 
    1035         ts->queue[i].job = jobid;
     1062        /* Save the pjob attributes we will store. */
     1063        ts->queue[i].sysjob = pjob.sysjob;
    10361064        ts->queue[i].size = pjob.size;
    10371065        ts->queue[i].page_count = pjob.page_count;
     
    11841212                qcount++;
    11851213                data.dsize += tdb_pack(NULL, 0, "ddddddff",
    1186                                 (uint32)queue[i].job,
     1214                                (uint32)queue[i].sysjob,
    11871215                                (uint32)queue[i].size,
    11881216                                (uint32)queue[i].page_count,
     
    12041232
    12051233                len += tdb_pack(data.dptr + len, data.dsize - len, "ddddddff",
    1206                                 (uint32)queue[i].job,
     1234                                (uint32)queue[i].sysjob,
    12071235                                (uint32)queue[i].size,
    12081236                                (uint32)queue[i].page_count,
     
    13181346****************************************************************************/
    13191347
    1320 static void print_queue_update_internal( struct tevent_context *ev,
    1321                                          struct messaging_context *msg_ctx,
    1322                                          const char *sharename,
    1323                                          struct printif *current_printif,
    1324                                          char *lpq_command, char *lprm_command )
     1348static void print_queue_update_internal(struct tevent_context *ev,
     1349                                        struct messaging_context *msg_ctx,
     1350                                        const char *sharename,
     1351                                        struct printif *current_printif,
     1352                                        char *lpq_command, char *lprm_command)
    13251353{
    13261354        int i, qcount;
     
    13341362        fstring keystr, cachestr;
    13351363        struct tdb_print_db *pdb = get_print_db_byname(sharename);
    1336 
    1337         if (!pdb) {
     1364        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     1365
     1366        if ((pdb == NULL) || (tmp_ctx == NULL)) {
    13381367                return;
    13391368        }
     
    13761405          fill in any system job numbers as we go
    13771406        */
    1378 
    13791407        jcdata = get_jobs_added_data(pdb);
    13801408
    13811409        for (i=0; i<qcount; i++) {
    1382                 uint32 jobid = print_parse_jobid(queue[i].fs_file);
    1383 
     1410                uint32 jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob);
    13841411                if (jobid == (uint32)-1) {
    13851412                        /* assume its a unix print job */
     
    13901417
    13911418                /* we have an active SMB print job - update its status */
    1392                 pjob = print_job_find(sharename, jobid);
     1419                pjob = print_job_find(tmp_ctx, sharename, jobid);
    13931420                if (!pjob) {
    13941421                        /* err, somethings wrong. Probably smbd was restarted
    13951422                           with jobs in the queue. All we can do is treat them
    13961423                           like unix jobs. Pity. */
     1424                        DEBUG(1, ("queued print job %d not found in jobs list, "
     1425                                  "assuming unix job\n", jobid));
    13971426                        print_unix_job(ev, msg_ctx,
    13981427                                       sharename, &queue[i], jobid);
    13991428                        continue;
    14001429                }
    1401 
    1402                 pjob->sysjob = queue[i].job;
    14031430
    14041431                /* don't reset the status on jobs to be deleted */
     
    14261453        tstruct.ev = ev;
    14271454        tstruct.msg_ctx = msg_ctx;
     1455        tstruct.mem_ctx = tmp_ctx;
    14281456
    14291457        tdb_traverse(pdb->tdb, traverse_fn_delete, (void *)&tstruct);
     
    14331461
    14341462        SAFE_FREE(tstruct.queue);
     1463        talloc_free(tmp_ctx);
    14351464
    14361465        DEBUG(10,("print_queue_update_internal: printer %s INFO/total_jobs = %d\n",
     
    16281657}
    16291658
     1659static bool printer_housekeeping_fn(const struct timeval *now,
     1660                                    void *private_data)
     1661{
     1662        static time_t last_pcap_reload_time = 0;
     1663        time_t printcap_cache_time = (time_t)lp_printcap_cache_time();
     1664        time_t t = time_mono(NULL);
     1665
     1666        DEBUG(5, ("printer housekeeping\n"));
     1667
     1668        /* if periodic printcap rescan is enabled, see if it's time to reload */
     1669        if ((printcap_cache_time != 0)
     1670         && (t >= (last_pcap_reload_time + printcap_cache_time))) {
     1671                DEBUG( 3,( "Printcap cache time expired.\n"));
     1672                pcap_cache_reload(server_event_context(),
     1673                                  smbd_messaging_context(),
     1674                                  &reload_pcap_change_notify);
     1675                last_pcap_reload_time = t;
     1676        }
     1677
     1678        return true;
     1679}
     1680
    16301681static pid_t background_lpq_updater_pid = -1;
    16311682
     
    16991750                        DEBUG(0,("tevent_add_fd() failed for pause_pipe\n"));
    17001751                        smb_panic("tevent_add_fd() failed for pause_pipe");
     1752                }
     1753
     1754                if (!(event_add_idle(ev, NULL,
     1755                                     timeval_set(SMBD_HOUSEKEEPING_INTERVAL, 0),
     1756                                     "printer_housekeeping",
     1757                                     printer_housekeeping_fn,
     1758                                     NULL))) {
     1759                        DEBUG(0, ("Could not add printing housekeeping event\n"));
     1760                        exit(1);
    17011761                }
    17021762
     
    20452105
    20462106/****************************************************************************
    2047  Give the filename used for a jobid.
     2107 Return the device mode asigned to a specific print job.
    20482108 Only valid for the process doing the spooling and when the job
    20492109 has not been spooled.
    20502110****************************************************************************/
    20512111
    2052 char *print_job_fname(const char* sharename, uint32 jobid)
    2053 {
    2054         struct printjob *pjob = print_job_find(sharename, jobid);
    2055         if (!pjob || pjob->spooled || pjob->pid != sys_getpid())
     2112struct spoolss_DeviceMode *print_job_devmode(TALLOC_CTX *mem_ctx,
     2113                                             const char *sharename,
     2114                                             uint32 jobid)
     2115{
     2116        struct printjob *pjob = print_job_find(mem_ctx, sharename, jobid);
     2117        if (pjob == NULL) {
    20562118                return NULL;
    2057         return pjob->filename;
    2058 }
    2059 
    2060 
    2061 /****************************************************************************
    2062  Give the filename used for a jobid.
    2063  Only valid for the process doing the spooling and when the job
    2064  has not been spooled.
    2065 ****************************************************************************/
    2066 
    2067 struct spoolss_DeviceMode *print_job_devmode(const char* sharename, uint32 jobid)
    2068 {
    2069         struct printjob *pjob = print_job_find(sharename, jobid);
    2070 
    2071         if ( !pjob )
    2072                 return NULL;
     2119        }
    20732120
    20742121        return pjob->devmode;
     
    20842131{
    20852132        struct printjob *pjob;
    2086 
    2087         pjob = print_job_find(sharename, jobid);
    2088         if (!pjob || pjob->pid != sys_getpid())
    2089                 return False;
     2133        bool ret;
     2134        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     2135        if (tmp_ctx == NULL) {
     2136                return false;
     2137        }
     2138
     2139        pjob = print_job_find(tmp_ctx, sharename, jobid);
     2140        if (!pjob || pjob->pid != sys_getpid()) {
     2141                ret = false;
     2142                goto err_out;
     2143        }
    20902144
    20912145        fstrcpy(pjob->jobname, name);
    2092         return pjob_store(ev, msg_ctx, sharename, jobid, pjob);
     2146        ret = pjob_store(ev, msg_ctx, sharename, jobid, pjob);
     2147err_out:
     2148        talloc_free(tmp_ctx);
     2149        return ret;
    20932150}
    20942151
     
    21012158        struct printjob *pjob;
    21022159
    2103         pjob = print_job_find(sharename, jobid);
     2160        pjob = print_job_find(mem_ctx, sharename, jobid);
    21042161        if (!pjob || pjob->pid != sys_getpid()) {
    21052162                return false;
    21062163        }
    21072164
    2108         *name = talloc_strdup(mem_ctx, pjob->jobname);
    2109         if (!*name) {
    2110                 return false;
    2111         }
    2112 
     2165        *name = pjob->jobname;
    21132166        return true;
    21142167}
     
    21832236{
    21842237        const char* sharename = lp_const_servicename(snum);
    2185         struct printjob *pjob = print_job_find(sharename, jobid);
     2238        struct printjob *pjob;
    21862239        int result = 0;
    21872240        struct printif *current_printif = get_printer_fns( snum );
    2188 
    2189         if (!pjob)
    2190                 return False;
     2241        bool ret;
     2242        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     2243        if (tmp_ctx == NULL) {
     2244                return false;
     2245        }
     2246
     2247        pjob = print_job_find(tmp_ctx, sharename, jobid);
     2248        if (!pjob) {
     2249                ret = false;
     2250                goto err_out;
     2251        }
    21912252
    21922253        /*
     
    21942255         */
    21952256
    2196         if (pjob->status == LPQ_DELETING)
    2197                 return True;
     2257        if (pjob->status == LPQ_DELETING) {
     2258                ret = true;
     2259                goto err_out;
     2260        }
    21982261
    21992262        /* Hrm - we need to be able to cope with deleting a job before it
     
    22252288                        int njobs = 1;
    22262289
    2227                         if (!pdb)
    2228                                 return False;
     2290                        if (!pdb) {
     2291                                ret = false;
     2292                                goto err_out;
     2293                        }
    22292294                        pjob_delete(ev, msg_ctx, sharename, jobid);
    22302295                        /* Ensure we keep a rough count of the number of total jobs... */
     
    22362301        remove_from_jobs_added( sharename, jobid );
    22372302
    2238         return (result == 0);
     2303        ret = (result == 0);
     2304err_out:
     2305        talloc_free(tmp_ctx);
     2306        return ret;
    22392307}
    22402308
     
    22472315                     uint32 jobid)
    22482316{
    2249         struct printjob *pjob = print_job_find(servicename, jobid);
    2250 
    2251         if (!pjob || !server_info)
    2252                 return False;
    2253 
    2254         return strequal(pjob->user, server_info->sanitized_username);
     2317        struct printjob *pjob;
     2318        bool ret;
     2319        TALLOC_CTX *tmp_ctx = talloc_new(server_info);
     2320        if (tmp_ctx == NULL) {
     2321                return false;
     2322        }
     2323
     2324        pjob = print_job_find(tmp_ctx, servicename, jobid);
     2325        if (!pjob || !server_info) {
     2326                ret = false;
     2327                goto err_out;
     2328        }
     2329
     2330        ret = strequal(pjob->user, server_info->sanitized_username);
     2331err_out:
     2332        talloc_free(tmp_ctx);
     2333        return ret;
    22552334}
    22562335
     
    22662345        struct printjob *pjob;
    22672346        bool    owner;
    2268         char    *fname;
     2347        WERROR werr;
     2348        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     2349        if (tmp_ctx == NULL) {
     2350                return WERR_NOT_ENOUGH_MEMORY;
     2351        }
    22692352
    22702353        owner = is_owner(server_info, lp_const_servicename(snum), jobid);
     
    22862369                /* END_ADMIN_LOG */
    22872370
    2288                 return WERR_ACCESS_DENIED;
     2371                werr = WERR_ACCESS_DENIED;
     2372                goto err_out;
    22892373        }
    22902374
     
    22962380         */
    22972381
    2298         fname = print_job_fname(sharename, jobid);
    2299         if (fname != NULL) {
    2300                 /* remove the spool file */
    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);
     2382        pjob = print_job_find(tmp_ctx, sharename, jobid);
     2383        if (!pjob || pjob->spooled || pjob->pid != getpid()) {
     2384                DEBUG(10, ("Skipping spool file removal for job %u\n", jobid));
     2385        } else {
     2386                DEBUG(10, ("Removing spool file [%s]\n", pjob->filename));
     2387                if (unlink(pjob->filename) == -1) {
     2388                        werr = map_werror_from_unix(errno);
     2389                        goto err_out;
    23052390                }
    23062391        }
    23072392
    23082393        if (!print_job_delete1(server_event_context(), msg_ctx, snum, jobid)) {
    2309                 return WERR_ACCESS_DENIED;
     2394                werr = WERR_ACCESS_DENIED;
     2395                goto err_out;
    23102396        }
    23112397
     
    23152401        print_queue_update(msg_ctx, snum, True);
    23162402
    2317         pjob = print_job_find(sharename, jobid);
     2403        pjob = print_job_find(tmp_ctx, sharename, jobid);
    23182404        if (pjob && (pjob->status != LPQ_DELETING)) {
    2319                 return WERR_ACCESS_DENIED;
    2320         }
    2321 
    2322         return WERR_PRINTER_HAS_JOBS_QUEUED;
     2405                werr = WERR_ACCESS_DENIED;
     2406                goto err_out;
     2407        }
     2408        werr = WERR_PRINTER_HAS_JOBS_QUEUED;
     2409
     2410err_out:
     2411        talloc_free(tmp_ctx);
     2412        return werr;
    23232413}
    23242414
     
    23272417****************************************************************************/
    23282418
    2329 bool print_job_pause(const struct auth_serversupplied_info *server_info,
     2419WERROR print_job_pause(const struct auth_serversupplied_info *server_info,
    23302420                     struct messaging_context *msg_ctx,
    2331                      int snum, uint32 jobid, WERROR *errcode)
     2421                     int snum, uint32 jobid)
    23322422{
    23332423        const char* sharename = lp_const_servicename(snum);
     
    23352425        int ret = -1;
    23362426        struct printif *current_printif = get_printer_fns( snum );
    2337 
    2338         pjob = print_job_find(sharename, jobid);
    2339 
     2427        WERROR werr;
     2428        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     2429        if (tmp_ctx == NULL) {
     2430                return WERR_NOT_ENOUGH_MEMORY;
     2431        }
     2432
     2433        pjob = print_job_find(tmp_ctx, sharename, jobid);
    23402434        if (!pjob || !server_info) {
    23412435                DEBUG(10, ("print_job_pause: no pjob or user for jobid %u\n",
    23422436                        (unsigned int)jobid ));
    2343                 return False;
     2437                werr = WERR_INVALID_PARAM;
     2438                goto err_out;
    23442439        }
    23452440
     
    23472442                DEBUG(10, ("print_job_pause: not spooled or bad sysjob = %d for jobid %u\n",
    23482443                        (int)pjob->sysjob, (unsigned int)jobid ));
    2349                 return False;
     2444                werr = WERR_INVALID_PARAM;
     2445                goto err_out;
    23502446        }
    23512447
     
    23632459                /* END_ADMIN_LOG */
    23642460
    2365                 *errcode = WERR_ACCESS_DENIED;
    2366                 return False;
     2461                werr = WERR_ACCESS_DENIED;
     2462                goto err_out;
    23672463        }
    23682464
     
    23712467
    23722468        if (ret != 0) {
    2373                 *errcode = WERR_INVALID_PARAM;
    2374                 return False;
     2469                werr = WERR_INVALID_PARAM;
     2470                goto err_out;
    23752471        }
    23762472
     
    23842480
    23852481        /* how do we tell if this succeeded? */
    2386 
    2387         return True;
     2482        werr = WERR_OK;
     2483err_out:
     2484        talloc_free(tmp_ctx);
     2485        return werr;
    23882486}
    23892487
     
    23922490****************************************************************************/
    23932491
    2394 bool print_job_resume(const struct auth_serversupplied_info *server_info,
     2492WERROR print_job_resume(const struct auth_serversupplied_info *server_info,
    23952493                      struct messaging_context *msg_ctx,
    2396                       int snum, uint32 jobid, WERROR *errcode)
     2494                      int snum, uint32 jobid)
    23972495{
    23982496        const char *sharename = lp_const_servicename(snum);
     
    24002498        int ret;
    24012499        struct printif *current_printif = get_printer_fns( snum );
    2402 
    2403         pjob = print_job_find(sharename, jobid);
    2404 
     2500        WERROR werr;
     2501        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     2502        if (tmp_ctx == NULL)
     2503                return WERR_NOT_ENOUGH_MEMORY;
     2504
     2505        pjob = print_job_find(tmp_ctx, sharename, jobid);
    24052506        if (!pjob || !server_info) {
    24062507                DEBUG(10, ("print_job_resume: no pjob or user for jobid %u\n",
    24072508                        (unsigned int)jobid ));
    2408                 return False;
     2509                werr = WERR_INVALID_PARAM;
     2510                goto err_out;
    24092511        }
    24102512
     
    24122514                DEBUG(10, ("print_job_resume: not spooled or bad sysjob = %d for jobid %u\n",
    24132515                        (int)pjob->sysjob, (unsigned int)jobid ));
    2414                 return False;
     2516                werr = WERR_INVALID_PARAM;
     2517                goto err_out;
    24152518        }
    24162519
     
    24192522                                JOB_ACCESS_ADMINISTER)) {
    24202523                DEBUG(3, ("resume denied by security descriptor\n"));
    2421                 *errcode = WERR_ACCESS_DENIED;
    24222524
    24232525                /* BEGIN_ADMIN_LOG */
     
    24282530                              lp_printername(snum) );
    24292531                /* END_ADMIN_LOG */
    2430                 return False;
     2532                werr = WERR_ACCESS_DENIED;
     2533                goto err_out;
    24312534        }
    24322535
     
    24342537
    24352538        if (ret != 0) {
    2436                 *errcode = WERR_INVALID_PARAM;
    2437                 return False;
     2539                werr = WERR_INVALID_PARAM;
     2540                goto err_out;
    24382541        }
    24392542
     
    24462549                          JOB_STATUS_QUEUED);
    24472550
    2448         return True;
     2551        werr = WERR_OK;
     2552err_out:
     2553        talloc_free(tmp_ctx);
     2554        return werr;
    24492555}
    24502556
     
    24602566        ssize_t return_code;
    24612567        struct printjob *pjob;
    2462 
    2463         pjob = print_job_find(sharename, jobid);
    2464 
    2465         if (!pjob)
     2568        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     2569        if (tmp_ctx == NULL) {
    24662570                return -1;
     2571        }
     2572
     2573        pjob = print_job_find(tmp_ctx, sharename, jobid);
     2574        if (!pjob) {
     2575                return_code = -1;
     2576                goto err_out;
     2577        }
     2578
    24672579        /* don't allow another process to get this info - it is meaningless */
    2468         if (pjob->pid != sys_getpid())
    2469                 return -1;
     2580        if (pjob->pid != sys_getpid()) {
     2581                return_code = -1;
     2582                goto err_out;
     2583        }
    24702584
    24712585        /* if SMBD is spooling this can't be allowed */
    24722586        if (pjob->status == PJOB_SMBD_SPOOLING) {
    2473                 return -1;
     2587                return_code = -1;
     2588                goto err_out;
    24742589        }
    24752590
    24762591        return_code = write_data(pjob->fd, buf, size);
    2477 
    2478         if (return_code>0) {
     2592        if (return_code > 0) {
    24792593                pjob->size += size;
    24802594                pjob_store(ev, msg_ctx, sharename, jobid, pjob);
    24812595        }
     2596err_out:
     2597        talloc_free(tmp_ctx);
    24822598        return return_code;
    24832599}
     
    27592875
    27602876        slprintf(pjob->filename, sizeof(pjob->filename)-1,
    2761                  "%s/%s%.8u.XXXXXX", lp_pathname(snum),
    2762                  PRINT_SPOOL_PREFIX, (unsigned int)jobid);
     2877                 "%s/%sXXXXXX", lp_pathname(snum), PRINT_SPOOL_PREFIX);
    27632878        pjob->fd = mkstemp(pjob->filename);
    27642879
     
    28262941
    28272942        pjob.pid = sys_getpid();
     2943        pjob.jobid = jobid;
    28282944        pjob.sysjob = -1;
    28292945        pjob.fd = -1;
     
    28903006        const char* sharename = lp_const_servicename(snum);
    28913007        struct printjob *pjob;
    2892 
    2893         pjob = print_job_find(sharename, jobid);
    2894         if (!pjob)
     3008        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     3009        if (tmp_ctx == NULL) {
    28953010                return;
     3011        }
     3012
     3013        pjob = print_job_find(tmp_ctx, sharename, jobid);
     3014        if (!pjob) {
     3015                goto err_out;
     3016        }
    28963017        /* don't allow another process to get this info - it is meaningless */
    2897         if (pjob->pid != sys_getpid())
    2898                 return;
     3018        if (pjob->pid != sys_getpid()) {
     3019                goto err_out;
     3020        }
    28993021
    29003022        pjob->page_count++;
    29013023        pjob_store(server_event_context(), msg_ctx, sharename, jobid, pjob);
     3024err_out:
     3025        talloc_free(tmp_ctx);
    29023026}
    29033027
     
    29153039        int ret;
    29163040        SMB_STRUCT_STAT sbuf;
    2917         struct printif *current_printif = get_printer_fns( snum );
     3041        struct printif *current_printif = get_printer_fns(snum);
    29183042        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
    2919 
    2920         pjob = print_job_find(sharename, jobid);
    2921 
     3043        char *lpq_cmd;
     3044        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     3045        if (tmp_ctx == NULL) {
     3046                return NT_STATUS_NO_MEMORY;
     3047        }
     3048
     3049        pjob = print_job_find(tmp_ctx, sharename, jobid);
    29223050        if (!pjob) {
    2923                 return NT_STATUS_PRINT_CANCELLED;
     3051                status = NT_STATUS_PRINT_CANCELLED;
     3052                goto err_out;
    29243053        }
    29253054
    29263055        if (pjob->spooled || pjob->pid != sys_getpid()) {
    2927                 return NT_STATUS_ACCESS_DENIED;
     3056                status = NT_STATUS_ACCESS_DENIED;
     3057                goto err_out;
    29283058        }
    29293059
     
    29793109        }
    29803110
    2981         ret = (*(current_printif->job_submit))(snum, pjob);
    2982 
     3111        /* don't strip out characters like '$' from the printername */
     3112        lpq_cmd = talloc_string_sub2(tmp_ctx,
     3113                                     lp_lpqcommand(snum),
     3114                                     "%p",
     3115                                     lp_printername(snum),
     3116                                     false, false, false);
     3117        if (lpq_cmd == NULL) {
     3118                status = NT_STATUS_PRINT_CANCELLED;
     3119                goto fail;
     3120        }
     3121        lpq_cmd = talloc_sub_advanced(tmp_ctx,
     3122                                      lp_servicename(snum),
     3123                                      current_user_info.unix_name,
     3124                                      "",
     3125                                      current_user.ut.gid,
     3126                                      get_current_username(),
     3127                                      current_user_info.domain,
     3128                                      lpq_cmd);
     3129        if (lpq_cmd == NULL) {
     3130                status = NT_STATUS_PRINT_CANCELLED;
     3131                goto fail;
     3132        }
     3133
     3134        ret = (*(current_printif->job_submit))(snum, pjob,
     3135                                               current_printif->type, lpq_cmd);
    29833136        if (ret) {
    29843137                status = NT_STATUS_PRINT_CANCELLED;
     
    30053158        unlink(pjob->filename);
    30063159        pjob_delete(server_event_context(), msg_ctx, sharename, jobid);
     3160err_out:
     3161        talloc_free(tmp_ctx);
    30073162        return status;
    30083163}
     
    30273182        bool ret = False;
    30283183        const char* sharename = lp_servicename(snum);
     3184        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     3185        if (tmp_ctx == NULL) {
     3186                return false;
     3187        }
    30293188
    30303189        /* make sure the database is up to date */
     
    30763235                                queue[i].fs_user,
    30773236                                queue[i].fs_file);
    3078                 queue[i].job = qjob;
     3237                queue[i].sysjob = qjob;
    30793238                queue[i].size = qsize;
    30803239                queue[i].page_count = qpage_count;
     
    30933252                jobid = IVAL(cgdata.dptr, i*4);
    30943253                DEBUG(5,("get_stored_queue_info: added job = %u\n", (unsigned int)jobid));
    3095                 pjob = print_job_find(lp_const_servicename(snum), jobid);
     3254                pjob = print_job_find(tmp_ctx, lp_const_servicename(snum), jobid);
    30963255                if (!pjob) {
    30973256                        DEBUG(5,("get_stored_queue_info: failed to find added job = %u\n", (unsigned int)jobid));
     
    31003259                }
    31013260
    3102                 queue[total_count].job = jobid;
     3261                queue[total_count].sysjob = jobid;
    31033262                queue[total_count].size = pjob->size;
    31043263                queue[total_count].page_count = pjob->page_count;
     
    31093268                fstrcpy(queue[total_count].fs_file, pjob->jobname);
    31103269                total_count++;
     3270                talloc_free(pjob);
    31113271        }
    31123272
     
    31183278
    31193279                for (j = 0; j < total_count; j++) {
    3120                         if (queue[j].job == jobid) {
     3280                        if (queue[j].sysjob == jobid) {
    31213281                                found = true;
    31223282                                break;
     
    31303290                                 (unsigned int) jobid));
    31313291
    3132                         pjob = print_job_find(sharename, jobid);
     3292                        pjob = print_job_find(tmp_ctx, sharename, jobid);
    31333293                        if (pjob == NULL) {
    31343294                                DEBUG(5,("get_stored_queue_info: failed to find "
     
    31393299                        }
    31403300
    3141                         queue[j].job = jobid;
     3301                        queue[j].sysjob = jobid;
    31423302                        queue[j].size = pjob->size;
    31433303                        queue[j].page_count = pjob->page_count;
     
    31473307                        fstrcpy(queue[j].fs_user, pjob->user);
    31483308                        fstrcpy(queue[j].fs_file, pjob->jobname);
     3309                        talloc_free(pjob);
    31493310
    31503311                        DEBUG(5,("get_stored_queue_info: updated queue[%u], jobid: %u, jobname: %s\n",
     
    31743335        SAFE_FREE(data.dptr);
    31753336        SAFE_FREE(cgdata.dptr);
     3337        talloc_free(tmp_ctx);
    31763338        return ret;
    31773339}
     
    33413503        for (i=0;i<njobs;i++) {
    33423504                bool owner = is_owner(server_info, lp_const_servicename(snum),
    3343                                       queue[i].job);
     3505                                      queue[i].sysjob);
    33443506
    33453507                if (owner || can_job_admin) {
    33463508                        print_job_delete1(server_event_context(), msg_ctx,
    3347                                           snum, queue[i].job);
     3509                                          snum, queue[i].sysjob);
    33483510                }
    33493511        }
  • vendor/current/source3/printing/printspoolss.c

    r740 r746  
    8383        }
    8484
    85         /* Ok, now we have to open an actual file.
     85        /*
     86         * Ok, now we have to open an actual file.
    8687         * Here is the reason:
    8788         * We want to write the spool job to this file in
     
    9394         * take over once we call EndDocPrinter().
    9495         * Of course we will not start writing until
    95          * StartDocPrinter() actually gives the ok. */
    96 
    97         pf->filename = talloc_asprintf(pf, "%s/%s.XXXXXX",
     96         * StartDocPrinter() actually gives the ok.
     97         * smbd spooler files do not include a print jobid
     98         * path component, as the jobid is only known after
     99         * calling StartDocPrinter().
     100         */
     101
     102        pf->filename = talloc_asprintf(pf, "%s/%sXXXXXX",
    98103                                        lp_pathname(SNUM(fsp->conn)),
    99104                                        PRINT_SPOOL_PREFIX);
     
    140145        status = dcerpc_spoolss_OpenPrinter(b, pf, pf->svcname,
    141146                                            "RAW", devmode_ctr,
    142                                             SEC_FLAG_MAXIMUM_ALLOWED,
     147                                            PRINTER_ACCESS_USE,
    143148                                            &pf->handle, &werr);
    144149        if (!NT_STATUS_IS_OK(status)) {
  • vendor/current/source3/printing/tests/vlp.c

    r740 r746  
    238238        slprintf(job.jobname, sizeof(job.jobname) - 1, "%s", argv[2]);
    239239
    240         if (!(pw = getpwuid(getuid()))) {
     240        if (!(pw = getpwuid(geteuid()))) {
     241                printf("getpwuid failed\n");
    241242                return 1;
    242243        }
Note: See TracChangeset for help on using the changeset viewer.