Ignore:
Timestamp:
Nov 29, 2012, 1:59:04 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.9

Location:
trunk/server/source3/printing
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/server/source3/printing/load.c

    r745 r751  
    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;
  • trunk/server/source3/printing/lpq_parse.c

    r480 r751  
    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 }
  • trunk/server/source3/printing/nt_printing.c

    r745 r751  
    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}
  • trunk/server/source3/printing/nt_printing_migrate.c

    r745 r751  
    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;
  • trunk/server/source3/printing/print_cups.c

    r745 r751  
    3636#endif
    3737
     38#if (CUPS_VERSION_MAJOR > 1) || (CUPS_VERSION_MINOR > 5)
     39#define HAVE_CUPS_1_6 1
     40#endif
     41
     42#ifndef HAVE_CUPS_1_6
     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 ippGetInteger(attr, element) attr->values[element].integer
     48#define ippGetString(attr, element, language) attr->values[element].string.text
     49
     50static ipp_attribute_t *
     51ippFirstAttribute(ipp_t *ipp)
     52{
     53  if (!ipp)
     54    return (NULL);
     55  return (ipp->current = ipp->attrs);
     56}
     57
     58static ipp_attribute_t *
     59ippNextAttribute(ipp_t *ipp)
     60{
     61  if (!ipp || !ipp->current)
     62    return (NULL);
     63  return (ipp->current = ipp->current->next);
     64}
     65
     66static int ippSetOperation(ipp_t *ipp, ipp_op_t op)
     67{
     68    ipp->request.op.operation_id = op;
     69    return (1);
     70}
     71
     72static int ippSetRequestId(ipp_t *ipp, int request_id)
     73{
     74    ipp->request.any.request_id = request_id;
     75    return (1);
     76}
     77#endif
     78
    3879static SIG_ATOMIC_T gotalarm;
    3980
     
    172213        bool ret_ok = false;
    173214
    174         for (attr = response->attrs; attr != NULL;) {
     215        for (attr = ippFirstAttribute(response); attr != NULL;) {
    175216               /*
    176217                * Skip leading attributes until we hit a printer...
    177218                */
    178219
    179                 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
    180                         attr = attr->next;
     220                while (attr != NULL && ippGetGroupTag(attr) != IPP_TAG_PRINTER)
     221                        attr = ippNextAttribute(response);
    181222
    182223                if (attr == NULL)
     
    190231                info       = NULL;
    191232
    192                 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
     233                while (attr != NULL && ippGetGroupTag(attr) == IPP_TAG_PRINTER) {
    193234                        size_t size;
    194                         if (strcmp(attr->name, "printer-name") == 0 &&
    195                             attr->value_tag == IPP_TAG_NAME) {
     235                        if (strcmp(ippGetName(attr), "printer-name") == 0 &&
     236                            ippGetValueTag(attr) == IPP_TAG_NAME) {
    196237                                if (!pull_utf8_talloc(mem_ctx,
    197238                                                &name,
    198                                                 attr->values[0].string.text,
     239                                                ippGetString(attr, 0, NULL),
    199240                                                &size)) {
    200241                                        goto err_out;
     
    202243                        }
    203244
    204                         if (strcmp(attr->name, "printer-info") == 0 &&
    205                             attr->value_tag == IPP_TAG_TEXT) {
     245                        if (strcmp(ippGetName(attr), "printer-info") == 0 &&
     246                            ippGetValueTag(attr) == IPP_TAG_TEXT) {
    206247                                if (!pull_utf8_talloc(mem_ctx,
    207248                                                &info,
    208                                                 attr->values[0].string.text,
     249                                                ippGetString(attr, 0, NULL),
    209250                                                &size)) {
    210251                                        goto err_out;
     
    212253                        }
    213254
    214                         if (strcmp(attr->name, "printer-location") == 0 &&
    215                             attr->value_tag == IPP_TAG_TEXT) {
     255                        if (strcmp(ippGetName(attr), "printer-location") == 0 &&
     256                            ippGetValueTag(attr) == IPP_TAG_TEXT) {
    216257                                if (!pull_utf8_talloc(mem_ctx,
    217258                                                &location,
    218                                                 attr->values[0].string.text,
     259                                                ippGetString(attr, 0, NULL),
    219260                                                &size)) {
    220261                                        goto err_out;
     
    222263                        }
    223264
    224                         attr = attr->next;
     265                        attr = ippNextAttribute(response);
    225266                }
    226267
     
    302343        request = ippNew();
    303344
    304         request->request.op.operation_id = CUPS_GET_PRINTERS;
    305         request->request.op.request_id   = 1;
     345        ippSetOperation(request, CUPS_GET_PRINTERS);
     346        ippSetRequestId(request, 1);
    306347
    307348        language = cupsLangDefault();
     
    344385        request = ippNew();
    345386
    346         request->request.op.operation_id = CUPS_GET_CLASSES;
    347         request->request.op.request_id   = 1;
     387        ippSetOperation(request, CUPS_GET_CLASSES);
     388        ippSetRequestId(request, 1);
    348389
    349390        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
     
    608649        request = ippNew();
    609650
    610         request->request.op.operation_id = IPP_CANCEL_JOB;
    611         request->request.op.request_id   = 1;
     651        ippSetOperation(request, IPP_CANCEL_JOB);
     652        ippSetRequestId(request, 1);
    612653
    613654        language = cupsLangDefault();
     
    635676
    636677        if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
    637                 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     678                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    638679                        DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
    639680                                ippErrorString(cupsLastError())));
     
    705746        request = ippNew();
    706747
    707         request->request.op.operation_id = IPP_HOLD_JOB;
    708         request->request.op.request_id   = 1;
     748        ippSetOperation(request, IPP_HOLD_JOB);
     749        ippSetRequestId(request, 1);
    709750
    710751        language = cupsLangDefault();
     
    731772
    732773        if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
    733                 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     774                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    734775                        DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
    735776                                ippErrorString(cupsLastError())));
     
    801842        request = ippNew();
    802843
    803         request->request.op.operation_id = IPP_RELEASE_JOB;
    804         request->request.op.request_id   = 1;
     844        ippSetOperation(request, IPP_RELEASE_JOB);
     845        ippSetRequestId(request, 1);
    805846
    806847        language = cupsLangDefault();
     
    827868
    828869        if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
    829                 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     870                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    830871                        DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
    831872                                ippErrorString(cupsLastError())));
     
    857898 */
    858899
    859 static int cups_job_submit(int snum, struct printjob *pjob)
     900static int cups_job_submit(int snum, struct printjob *pjob,
     901                           enum printing_types printing_type,
     902                           char *lpq_cmd)
    860903{
    861904        TALLOC_CTX *frame = talloc_stackframe();
     
    876919        char *filename = NULL;
    877920        size_t size;
    878         uint32_t jobid = (uint32_t)-1;
    879921
    880922        DEBUG(5,("cups_job_submit(%d, %p)\n", snum, pjob));
     
    907949        request = ippNew();
    908950
    909         request->request.op.operation_id = IPP_PRINT_JOB;
    910         request->request.op.request_id   = 1;
     951        ippSetOperation(request, IPP_PRINT_JOB);
     952        ippSetRequestId(request, 1);
    911953
    912954        language = cupsLangDefault();
     
    938980                     pjob->clientmachine);
    939981
    940         /* Get the jobid from the filename. */
    941         jobid = print_parse_jobid(pjob->filename);
    942         if (jobid == (uint32_t)-1) {
    943                 DEBUG(0,("cups_job_submit: failed to parse jobid from name %s\n",
    944                                 pjob->filename ));
    945                 jobid = 0;
    946         }
    947 
    948982        if (!push_utf8_talloc(frame, &jobname, pjob->jobname, &size)) {
    949983                goto out;
     
    951985        new_jobname = talloc_asprintf(frame,
    952986                        "%s%.8u %s", PRINT_SPOOL_PREFIX,
    953                         (unsigned int)jobid,
    954                         jobname);
     987                        pjob->jobid, jobname);
    955988        if (new_jobname == NULL) {
    956989                goto out;
     
    9841017        }
    9851018        if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) {
    986                 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     1019                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    9871020                        DEBUG(0,("Unable to print file to %s - %s\n",
    9881021                                 lp_printername(snum),
     
    9921025                        attr_job_id = ippFindAttribute(response, "job-id", IPP_TAG_INTEGER);
    9931026                        if(attr_job_id) {
    994                                 pjob->sysjob = attr_job_id->values[0].integer;
     1027                                pjob->sysjob = ippGetInteger(attr_job_id, 0);
    9951028                                DEBUG(5,("cups_job_submit: job-id %d\n", pjob->sysjob));
    9961029                        } else {
     
    11141147        request = ippNew();
    11151148
    1116         request->request.op.operation_id = IPP_GET_JOBS;
    1117         request->request.op.request_id   = 1;
     1149        ippSetOperation(request, IPP_GET_JOBS);
     1150        ippSetRequestId(request, 1);
    11181151
    11191152        language = cupsLangDefault();
     
    11431176        }
    11441177
    1145         if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     1178        if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    11461179                DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
    1147                          ippErrorString(response->request.status.status_code)));
     1180                         ippErrorString(ippGetStatusCode(response))));
    11481181                goto out;
    11491182        }
     
    11571190        queue  = NULL;
    11581191
    1159         for (attr = response->attrs; attr != NULL; attr = attr->next) {
     1192        for (attr = ippFirstAttribute(response); attr != NULL; attr = ippNextAttribute(response)) {
    11601193               /*
    11611194                * Skip leading attributes until we hit a job...
    11621195                */
    11631196
    1164                 while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
    1165                         attr = attr->next;
     1197                while (attr != NULL && ippGetGroupTag(attr) != IPP_TAG_JOB)
     1198                        attr = ippNextAttribute(response);
    11661199
    11671200                if (attr == NULL)
     
    11981231                job_name     = NULL;
    11991232
    1200                 while (attr != NULL && attr->group_tag == IPP_TAG_JOB) {
    1201                         if (attr->name == NULL) {
    1202                                 attr = attr->next;
     1233                while (attr != NULL && ippGetGroupTag(attr) == IPP_TAG_JOB) {
     1234                        if (ippGetName(attr) == NULL) {
     1235                                attr = ippNextAttribute(response);
    12031236                                break;
    12041237                        }
    12051238
    1206                         if (strcmp(attr->name, "job-id") == 0 &&
    1207                             attr->value_tag == IPP_TAG_INTEGER)
    1208                                 job_id = attr->values[0].integer;
    1209 
    1210                         if (strcmp(attr->name, "job-k-octets") == 0 &&
    1211                             attr->value_tag == IPP_TAG_INTEGER)
    1212                                 job_k_octets = attr->values[0].integer;
    1213 
    1214                         if (strcmp(attr->name, "job-priority") == 0 &&
    1215                             attr->value_tag == IPP_TAG_INTEGER)
    1216                                 job_priority = attr->values[0].integer;
    1217 
    1218                         if (strcmp(attr->name, "job-state") == 0 &&
    1219                             attr->value_tag == IPP_TAG_ENUM)
    1220                                 job_status = (ipp_jstate_t)(attr->values[0].integer);
    1221 
    1222                         if (strcmp(attr->name, "time-at-creation") == 0 &&
    1223                             attr->value_tag == IPP_TAG_INTEGER)
    1224                                 job_time = attr->values[0].integer;
    1225 
    1226                         if (strcmp(attr->name, "job-name") == 0 &&
    1227                             attr->value_tag == IPP_TAG_NAME) {
     1239                        if (strcmp(ippGetName(attr), "job-id") == 0 &&
     1240                            ippGetValueTag(attr) == IPP_TAG_INTEGER)
     1241                                job_id = ippGetInteger(attr, 0);
     1242
     1243                        if (strcmp(ippGetName(attr), "job-k-octets") == 0 &&
     1244                            ippGetValueTag(attr) == IPP_TAG_INTEGER)
     1245                                job_k_octets = ippGetInteger(attr, 0);
     1246
     1247                        if (strcmp(ippGetName(attr), "job-priority") == 0 &&
     1248                            ippGetValueTag(attr) == IPP_TAG_INTEGER)
     1249                                job_priority = ippGetInteger(attr, 0);
     1250
     1251                        if (strcmp(ippGetName(attr), "job-state") == 0 &&
     1252                            ippGetValueTag(attr) == IPP_TAG_ENUM)
     1253                                job_status = (ipp_jstate_t)ippGetInteger(attr, 0);
     1254
     1255                        if (strcmp(ippGetName(attr), "time-at-creation") == 0 &&
     1256                            ippGetValueTag(attr) == IPP_TAG_INTEGER)
     1257                                job_time = ippGetInteger(attr, 0);
     1258
     1259                        if (strcmp(ippGetName(attr), "job-name") == 0 &&
     1260                            ippGetValueTag(attr) == IPP_TAG_NAME) {
    12281261                                if (!pull_utf8_talloc(frame,
    12291262                                                &job_name,
    1230                                                 attr->values[0].string.text,
     1263                                                ippGetString(attr, 0, NULL),
    12311264                                                &size)) {
    12321265                                        goto out;
     
    12341267                        }
    12351268
    1236                         if (strcmp(attr->name, "job-originating-user-name") == 0 &&
    1237                             attr->value_tag == IPP_TAG_NAME) {
     1269                        if (strcmp(ippGetName(attr), "job-originating-user-name") == 0 &&
     1270                            ippGetValueTag(attr) == IPP_TAG_NAME) {
    12381271                                if (!pull_utf8_talloc(frame,
    12391272                                                &user_name,
    1240                                                 attr->values[0].string.text,
     1273                                                ippGetString(attr, 0, NULL),
    12411274                                                &size)) {
    12421275                                        goto out;
     
    12441277                        }
    12451278
    1246                         attr = attr->next;
     1279                        attr = ippNextAttribute(response);
    12471280                }
    12481281
     
    12581291                }
    12591292
    1260                 temp->job      = job_id;
     1293                temp->sysjob   = job_id;
    12611294                temp->size     = job_k_octets * 1024;
    12621295                temp->status   = job_status == IPP_JOB_PENDING ? LPQ_QUEUED :
     
    12901323        request = ippNew();
    12911324
    1292         request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
    1293         request->request.op.request_id   = 1;
     1325        ippSetOperation(request, IPP_GET_PRINTER_ATTRIBUTES);
     1326        ippSetRequestId(request, 1);
    12941327
    12951328        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
     
    13171350        }
    13181351
    1319         if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     1352        if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    13201353                DEBUG(0,("Unable to get printer status for %s - %s\n", printername,
    1321                          ippErrorString(response->request.status.status_code)));
     1354                         ippErrorString(ippGetStatusCode(response))));
    13221355                goto out;
    13231356        }
     
    13281361
    13291362        if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL) {
    1330                 if (attr->values[0].integer == IPP_PRINTER_STOPPED)
     1363                if (ippGetInteger(attr, 0) == IPP_PRINTER_STOPPED)
    13311364                        status->status = LPSTAT_STOPPED;
    13321365                else
     
    13381371                char *msg = NULL;
    13391372                if (!pull_utf8_talloc(frame, &msg,
    1340                                 attr->values[0].string.text,
     1373                                ippGetString(attr, 0, NULL),
    13411374                                &size)) {
    13421375                        SAFE_FREE(queue);
     
    14141447        request = ippNew();
    14151448
    1416         request->request.op.operation_id = IPP_PAUSE_PRINTER;
    1417         request->request.op.request_id   = 1;
     1449        ippSetOperation(request, IPP_PAUSE_PRINTER);
     1450        ippSetRequestId(request, 1);
    14181451
    14191452        language = cupsLangDefault();
     
    14451478
    14461479        if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
    1447                 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     1480                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    14481481                        DEBUG(0,("Unable to pause printer %s - %s\n",
    14491482                                 lp_printername(snum),
     
    15181551        request = ippNew();
    15191552
    1520         request->request.op.operation_id = IPP_RESUME_PRINTER;
    1521         request->request.op.request_id   = 1;
     1553        ippSetOperation(request, IPP_RESUME_PRINTER);
     1554        ippSetRequestId(request, 1);
    15221555
    15231556        language = cupsLangDefault();
     
    15491582
    15501583        if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
    1551                 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     1584                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    15521585                        DEBUG(0,("Unable to resume printer %s - %s\n",
    15531586                                 lp_printername(snum),
  • trunk/server/source3/printing/print_generic.c

    r745 r751  
    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
  • trunk/server/source3/printing/print_iprint.c

    r745 r751  
    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 :
  • trunk/server/source3/printing/printer_list.c

    r745 r751  
    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);
  • trunk/server/source3/printing/printing.c

    r745 r751  
    378378***********************************************************************/
    379379
    380 static int unpack_pjob( uint8 *buf, int buflen, struct printjob *pjob )
     380static int unpack_pjob(TALLOC_CTX *mem_ctx, uint8 *buf, int buflen,
     381                       struct printjob *pjob)
    381382{
    382383        int     len = 0;
    383384        int     used;
    384         uint32 pjpid, pjsysjob, pjfd, pjstarttime, pjstatus;
     385        uint32 pjpid, pjjobid, pjsysjob, pjfd, pjstarttime, pjstatus;
    385386        uint32 pjsize, pjpage_count, pjspooled, pjsmbjob;
    386387
    387         if ( !buf || !pjob )
     388        if (!buf || !pjob) {
    388389                return -1;
    389 
    390         len += tdb_unpack(buf+len, buflen-len, "dddddddddfffff",
     390        }
     391
     392        len += tdb_unpack(buf+len, buflen-len, "ddddddddddfffff",
    391393                                &pjpid,
     394                                &pjjobid,
    392395                                &pjsysjob,
    393396                                &pjfd,
     
    404407                                pjob->queuename);
    405408
    406         if ( len == -1 )
     409        if (len == -1) {
    407410                return -1;
    408 
    409         used = unpack_devicemode(NULL, buf+len, buflen-len, &pjob->devmode);
     411        }
     412
     413        used = unpack_devicemode(mem_ctx, buf+len, buflen-len, &pjob->devmode);
    410414        if (used == -1) {
    411415                return -1;
     
    415419
    416420        pjob->pid = pjpid;
     421        pjob->jobid = pjjobid;
    417422        pjob->sysjob = pjsysjob;
    418423        pjob->fd = pjfd;
     
    432437****************************************************************************/
    433438
    434 static struct printjob *print_job_find(const char *sharename, uint32 jobid)
    435 {
    436         static struct printjob  pjob;
     439static struct printjob *print_job_find(TALLOC_CTX *mem_ctx,
     440                                       const char *sharename,
     441                                       uint32 jobid)
     442{
     443        struct printjob         *pjob;
    437444        uint32_t tmp;
    438445        TDB_DATA                ret;
     
    450457
    451458        if (!ret.dptr) {
    452                 DEBUG(10,("print_job_find: failed to find jobid %u.\n", (unsigned int)jobid ));
     459                DEBUG(10, ("print_job_find: failed to find jobid %u.\n",
     460                           jobid));
    453461                return NULL;
    454462        }
    455463
    456         talloc_free(pjob.devmode);
    457 
    458         ZERO_STRUCT( pjob );
    459 
    460         if ( unpack_pjob( ret.dptr, ret.dsize, &pjob ) == -1 ) {
    461                 DEBUG(10,("print_job_find: failed to unpack jobid %u.\n", (unsigned int)jobid ));
    462                 SAFE_FREE(ret.dptr);
    463                 return NULL;
    464         }
    465 
     464        pjob = talloc_zero(mem_ctx, struct printjob);
     465        if (pjob == NULL) {
     466                goto err_out;
     467        }
     468
     469        if (unpack_pjob(mem_ctx, ret.dptr, ret.dsize, pjob) == -1) {
     470                DEBUG(10, ("failed to unpack jobid %u.\n", jobid));
     471                talloc_free(pjob);
     472                pjob = NULL;
     473                goto err_out;
     474        }
     475
     476        DEBUG(10,("print_job_find: returning system job %d for jobid %u.\n",
     477                  pjob->sysjob, jobid));
     478        SMB_ASSERT(pjob->jobid == jobid);
     479
     480err_out:
    466481        SAFE_FREE(ret.dptr);
    467 
    468         DEBUG(10,("print_job_find: returning system job %d for jobid %u.\n",
    469                         (int)pjob.sysjob, (unsigned int)jobid ));
    470 
    471         return &pjob;
     482        return pjob;
    472483}
    473484
     
    494505
    495506        if (state->sysjob == pjob->sysjob) {
    496                 uint32 jobid = IVAL(key.dptr,0);
    497 
    498                 state->sysjob_to_jobid_value = jobid;
     507                state->sysjob_to_jobid_value = pjob->jobid;
    499508                return 1;
    500509        }
    501510
    502511        return 0;
     512}
     513
     514static uint32 sysjob_to_jobid_pdb(struct tdb_print_db *pdb, int sysjob)
     515{
     516        struct unixjob_traverse_state state;
     517
     518        state.sysjob = sysjob;
     519        state.sysjob_to_jobid_value = (uint32)-1;
     520
     521        tdb_traverse(pdb->tdb, unixjob_traverse_fn, &state);
     522
     523        return state.sysjob_to_jobid_value;
    503524}
    504525
     
    742763                len = 0;
    743764                buflen = newlen;
    744                 len += tdb_pack(buf+len, buflen-len, "dddddddddfffff",
     765                len += tdb_pack(buf+len, buflen-len, "ddddddddddfffff",
    745766                                (uint32)pjob->pid,
     767                                (uint32)pjob->jobid,
    746768                                (uint32)pjob->sysjob,
    747769                                (uint32)pjob->fd,
     
    780802        /* Send notify updates for what has changed */
    781803
    782         if ( ret ) {
     804        if (ret) {
    783805                bool changed = false;
    784806                struct printjob old_pjob;
    785807
    786                 if ( old_data.dsize )
    787                 {
    788                         if ( unpack_pjob( old_data.dptr, old_data.dsize, &old_pjob ) != -1 )
    789                         {
    790                                 pjob_store_notify(server_event_context(),
     808                if (old_data.dsize) {
     809                        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     810                        if (tmp_ctx == NULL)
     811                                goto done;
     812
     813                        len = unpack_pjob(tmp_ctx, old_data.dptr,
     814                                          old_data.dsize, &old_pjob);
     815                        if (len != -1 ) {
     816                                pjob_store_notify(ev,
    791817                                                  msg_ctx,
    792818                                                  sharename, jobid, &old_pjob,
    793819                                                  pjob,
    794820                                                  &changed);
    795                                 talloc_free(old_pjob.devmode);
    796 
    797821                                if (changed) {
    798822                                        add_to_jobs_changed(pdb, jobid);
    799823                                }
    800824                        }
    801 
    802                 }
    803                 else {
     825                        talloc_free(tmp_ctx);
     826
     827                } else {
    804828                        /* new job */
    805                         pjob_store_notify(server_event_context(), msg_ctx,
     829                        pjob_store_notify(ev, msg_ctx,
    806830                                          sharename, jobid, NULL, pjob,
    807831                                          &changed);
     
    809833        }
    810834
     835done:
    811836        release_print_db(pdb);
    812 done:
    813837        SAFE_FREE( old_data.dptr );
    814838        SAFE_FREE( buf );
     
    829853        uint32 job_status = 0;
    830854        struct tdb_print_db *pdb;
    831 
    832         pdb = get_print_db_byname( sharename );
    833 
    834         if (!pdb)
     855        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     856        if (tmp_ctx == NULL) {
    835857                return;
    836 
    837         pjob = print_job_find( sharename, jobid );
    838 
     858        }
     859
     860        pdb = get_print_db_byname(sharename);
     861        if (!pdb) {
     862                goto err_out;
     863        }
     864
     865        pjob = print_job_find(tmp_ctx, sharename, jobid);
    839866        if (!pjob) {
    840                 DEBUG(5, ("pjob_delete: we were asked to delete nonexistent job %u\n",
    841                                         (unsigned int)jobid));
    842                 release_print_db(pdb);
    843                 return;
     867                DEBUG(5, ("we were asked to delete nonexistent job %u\n",
     868                          jobid));
     869                goto err_release;
    844870        }
    845871
     
    855881        tdb_delete(pdb->tdb, print_key(jobid, &tmp));
    856882        remove_from_jobs_added(sharename, jobid);
    857         release_print_db( pdb );
    858883        rap_jobid_delete(sharename, jobid);
     884err_release:
     885        release_print_db(pdb);
     886err_out:
     887        talloc_free(tmp_ctx);
    859888}
    860889
     
    869898{
    870899        struct printjob pj, *old_pj;
    871 
    872         if (jobid == (uint32)-1)
    873                 jobid = q->job + UNIX_JOB_START;
     900        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     901        if (tmp_ctx == NULL) {
     902                return;
     903        }
     904
     905        if (jobid == (uint32)-1) {
     906                jobid = q->sysjob + UNIX_JOB_START;
     907        }
    874908
    875909        /* Preserve the timestamp on an existing unix print job */
    876910
    877         old_pj = print_job_find(sharename, jobid);
     911        old_pj = print_job_find(tmp_ctx, sharename, jobid);
    878912
    879913        ZERO_STRUCT(pj);
    880914
    881915        pj.pid = (pid_t)-1;
    882         pj.sysjob = q->job;
     916        pj.jobid = jobid;
     917        pj.sysjob = q->sysjob;
    883918        pj.fd = -1;
    884919        pj.starttime = old_pj ? old_pj->starttime : q->time;
     
    898933
    899934        pjob_store(ev, msg_ctx, sharename, jobid, &pj);
     935        talloc_free(tmp_ctx);
    900936}
    901937
     
    910946        struct tevent_context *ev;
    911947        struct messaging_context *msg_ctx;
     948        TALLOC_CTX *mem_ctx;
    912949};
    913950
     
    926963                return 0;
    927964
    928         jobid = IVAL(key.dptr, 0);
    929         if ( unpack_pjob( data.dptr, data.dsize, &pjob ) == -1 )
     965        if (unpack_pjob(ts->mem_ctx, data.dptr, data.dsize, &pjob) == -1)
    930966                return 0;
    931967        talloc_free(pjob.devmode);
    932 
     968        jobid = pjob.jobid;
    933969
    934970        if (!pjob.smbjob) {
    935971                /* remove a unix job if it isn't in the system queue any more */
    936 
    937972                for (i=0;i<ts->qcount;i++) {
    938                         uint32 u_jobid = (ts->queue[i].job + UNIX_JOB_START);
    939                         if (jobid == u_jobid)
     973                        if (ts->queue[i].sysjob == pjob.sysjob) {
    940974                                break;
     975                        }
    941976                }
    942977                if (i == ts->qcount) {
     
    9691004        /* this check only makes sense for jobs submitted from Windows clients */
    9701005
    971         if ( pjob.smbjob ) {
     1006        if (pjob.smbjob) {
    9721007                for (i=0;i<ts->qcount;i++) {
    973                         uint32 curr_jobid;
    974 
    9751008                        if ( pjob.status == LPQ_DELETED )
    9761009                                continue;
    9771010
    978                         curr_jobid = print_parse_jobid(ts->queue[i].fs_file);
    979 
    980                         if (jobid == curr_jobid) {
     1011                        if (ts->queue[i].sysjob == pjob.sysjob) {
    9811012
    9821013                                /* try to clean up any jobs that need to be deleted */
     
    10331064        }
    10341065
    1035         /* Save the pjob attributes we will store.
    1036            FIXME!!! This is the only place where queue->job
    1037            represents the SMB jobid      --jerry */
    1038 
    1039         ts->queue[i].job = jobid;
     1066        /* Save the pjob attributes we will store. */
     1067        ts->queue[i].sysjob = pjob.sysjob;
    10401068        ts->queue[i].size = pjob.size;
    10411069        ts->queue[i].page_count = pjob.page_count;
     
    11881216                qcount++;
    11891217                data.dsize += tdb_pack(NULL, 0, "ddddddff",
    1190                                 (uint32)queue[i].job,
     1218                                (uint32)queue[i].sysjob,
    11911219                                (uint32)queue[i].size,
    11921220                                (uint32)queue[i].page_count,
     
    12081236
    12091237                len += tdb_pack(data.dptr + len, data.dsize - len, "ddddddff",
    1210                                 (uint32)queue[i].job,
     1238                                (uint32)queue[i].sysjob,
    12111239                                (uint32)queue[i].size,
    12121240                                (uint32)queue[i].page_count,
     
    13221350****************************************************************************/
    13231351
    1324 static void print_queue_update_internal( struct tevent_context *ev,
    1325                                          struct messaging_context *msg_ctx,
    1326                                          const char *sharename,
    1327                                          struct printif *current_printif,
    1328                                          char *lpq_command, char *lprm_command )
     1352static void print_queue_update_internal(struct tevent_context *ev,
     1353                                        struct messaging_context *msg_ctx,
     1354                                        const char *sharename,
     1355                                        struct printif *current_printif,
     1356                                        char *lpq_command, char *lprm_command)
    13291357{
    13301358        int i, qcount;
     
    13381366        fstring keystr, cachestr;
    13391367        struct tdb_print_db *pdb = get_print_db_byname(sharename);
    1340 
    1341         if (!pdb) {
     1368        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     1369
     1370        if ((pdb == NULL) || (tmp_ctx == NULL)) {
    13421371                return;
    13431372        }
     
    13801409          fill in any system job numbers as we go
    13811410        */
    1382 
    13831411        jcdata = get_jobs_added_data(pdb);
    13841412
    13851413        for (i=0; i<qcount; i++) {
    1386                 uint32 jobid = print_parse_jobid(queue[i].fs_file);
    1387 
     1414                uint32 jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob);
    13881415                if (jobid == (uint32)-1) {
    13891416                        /* assume its a unix print job */
     
    13941421
    13951422                /* we have an active SMB print job - update its status */
    1396                 pjob = print_job_find(sharename, jobid);
     1423                pjob = print_job_find(tmp_ctx, sharename, jobid);
    13971424                if (!pjob) {
    13981425                        /* err, somethings wrong. Probably smbd was restarted
    13991426                           with jobs in the queue. All we can do is treat them
    14001427                           like unix jobs. Pity. */
     1428                        DEBUG(1, ("queued print job %d not found in jobs list, "
     1429                                  "assuming unix job\n", jobid));
    14011430                        print_unix_job(ev, msg_ctx,
    14021431                                       sharename, &queue[i], jobid);
    14031432                        continue;
    14041433                }
    1405 
    1406                 pjob->sysjob = queue[i].job;
    14071434
    14081435                /* don't reset the status on jobs to be deleted */
     
    14301457        tstruct.ev = ev;
    14311458        tstruct.msg_ctx = msg_ctx;
     1459        tstruct.mem_ctx = tmp_ctx;
    14321460
    14331461        tdb_traverse(pdb->tdb, traverse_fn_delete, (void *)&tstruct);
     
    14371465
    14381466        SAFE_FREE(tstruct.queue);
     1467        talloc_free(tmp_ctx);
    14391468
    14401469        DEBUG(10,("print_queue_update_internal: printer %s INFO/total_jobs = %d\n",
     
    16321661}
    16331662
     1663static bool printer_housekeeping_fn(const struct timeval *now,
     1664                                    void *private_data)
     1665{
     1666        static time_t last_pcap_reload_time = 0;
     1667        time_t printcap_cache_time = (time_t)lp_printcap_cache_time();
     1668        time_t t = time_mono(NULL);
     1669
     1670        DEBUG(5, ("printer housekeeping\n"));
     1671
     1672        /* if periodic printcap rescan is enabled, see if it's time to reload */
     1673        if ((printcap_cache_time != 0)
     1674         && (t >= (last_pcap_reload_time + printcap_cache_time))) {
     1675                DEBUG( 3,( "Printcap cache time expired.\n"));
     1676                pcap_cache_reload(server_event_context(),
     1677                                  smbd_messaging_context(),
     1678                                  &reload_pcap_change_notify);
     1679                last_pcap_reload_time = t;
     1680        }
     1681
     1682        return true;
     1683}
     1684
    16341685static pid_t background_lpq_updater_pid = -1;
    16351686
     
    17031754                        DEBUG(0,("tevent_add_fd() failed for pause_pipe\n"));
    17041755                        smb_panic("tevent_add_fd() failed for pause_pipe");
     1756                }
     1757
     1758                if (!(event_add_idle(ev, NULL,
     1759                                     timeval_set(SMBD_HOUSEKEEPING_INTERVAL, 0),
     1760                                     "printer_housekeeping",
     1761                                     printer_housekeeping_fn,
     1762                                     NULL))) {
     1763                        DEBUG(0, ("Could not add printing housekeeping event\n"));
     1764                        exit(1);
    17051765                }
    17061766
     
    20492109
    20502110/****************************************************************************
    2051  Give the filename used for a jobid.
     2111 Return the device mode asigned to a specific print job.
    20522112 Only valid for the process doing the spooling and when the job
    20532113 has not been spooled.
    20542114****************************************************************************/
    20552115
    2056 char *print_job_fname(const char* sharename, uint32 jobid)
    2057 {
    2058         struct printjob *pjob = print_job_find(sharename, jobid);
    2059         if (!pjob || pjob->spooled || pjob->pid != sys_getpid())
     2116struct spoolss_DeviceMode *print_job_devmode(TALLOC_CTX *mem_ctx,
     2117                                             const char *sharename,
     2118                                             uint32 jobid)
     2119{
     2120        struct printjob *pjob = print_job_find(mem_ctx, sharename, jobid);
     2121        if (pjob == NULL) {
    20602122                return NULL;
    2061         return pjob->filename;
    2062 }
    2063 
    2064 
    2065 /****************************************************************************
    2066  Give the filename used for a jobid.
    2067  Only valid for the process doing the spooling and when the job
    2068  has not been spooled.
    2069 ****************************************************************************/
    2070 
    2071 struct spoolss_DeviceMode *print_job_devmode(const char* sharename, uint32 jobid)
    2072 {
    2073         struct printjob *pjob = print_job_find(sharename, jobid);
    2074 
    2075         if ( !pjob )
    2076                 return NULL;
     2123        }
    20772124
    20782125        return pjob->devmode;
     
    20882135{
    20892136        struct printjob *pjob;
    2090 
    2091         pjob = print_job_find(sharename, jobid);
    2092         if (!pjob || pjob->pid != sys_getpid())
    2093                 return False;
     2137        bool ret;
     2138        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     2139        if (tmp_ctx == NULL) {
     2140                return false;
     2141        }
     2142
     2143        pjob = print_job_find(tmp_ctx, sharename, jobid);
     2144        if (!pjob || pjob->pid != sys_getpid()) {
     2145                ret = false;
     2146                goto err_out;
     2147        }
    20942148
    20952149        fstrcpy(pjob->jobname, name);
    2096         return pjob_store(ev, msg_ctx, sharename, jobid, pjob);
     2150        ret = pjob_store(ev, msg_ctx, sharename, jobid, pjob);
     2151err_out:
     2152        talloc_free(tmp_ctx);
     2153        return ret;
    20972154}
    20982155
     
    21052162        struct printjob *pjob;
    21062163
    2107         pjob = print_job_find(sharename, jobid);
     2164        pjob = print_job_find(mem_ctx, sharename, jobid);
    21082165        if (!pjob || pjob->pid != sys_getpid()) {
    21092166                return false;
    21102167        }
    21112168
    2112         *name = talloc_strdup(mem_ctx, pjob->jobname);
    2113         if (!*name) {
    2114                 return false;
    2115         }
    2116 
     2169        *name = pjob->jobname;
    21172170        return true;
    21182171}
     
    21872240{
    21882241        const char* sharename = lp_const_servicename(snum);
    2189         struct printjob *pjob = print_job_find(sharename, jobid);
     2242        struct printjob *pjob;
    21902243        int result = 0;
    21912244        struct printif *current_printif = get_printer_fns( snum );
    2192 
    2193         if (!pjob)
    2194                 return False;
     2245        bool ret;
     2246        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     2247        if (tmp_ctx == NULL) {
     2248                return false;
     2249        }
     2250
     2251        pjob = print_job_find(tmp_ctx, sharename, jobid);
     2252        if (!pjob) {
     2253                ret = false;
     2254                goto err_out;
     2255        }
    21952256
    21962257        /*
     
    21982259         */
    21992260
    2200         if (pjob->status == LPQ_DELETING)
    2201                 return True;
     2261        if (pjob->status == LPQ_DELETING) {
     2262                ret = true;
     2263                goto err_out;
     2264        }
    22022265
    22032266        /* Hrm - we need to be able to cope with deleting a job before it
     
    22292292                        int njobs = 1;
    22302293
    2231                         if (!pdb)
    2232                                 return False;
     2294                        if (!pdb) {
     2295                                ret = false;
     2296                                goto err_out;
     2297                        }
    22332298                        pjob_delete(ev, msg_ctx, sharename, jobid);
    22342299                        /* Ensure we keep a rough count of the number of total jobs... */
     
    22402305        remove_from_jobs_added( sharename, jobid );
    22412306
    2242         return (result == 0);
     2307        ret = (result == 0);
     2308err_out:
     2309        talloc_free(tmp_ctx);
     2310        return ret;
    22432311}
    22442312
     
    22512319                     uint32 jobid)
    22522320{
    2253         struct printjob *pjob = print_job_find(servicename, jobid);
    2254 
    2255         if (!pjob || !server_info)
    2256                 return False;
    2257 
    2258         return strequal(pjob->user, server_info->sanitized_username);
     2321        struct printjob *pjob;
     2322        bool ret;
     2323        TALLOC_CTX *tmp_ctx = talloc_new(server_info);
     2324        if (tmp_ctx == NULL) {
     2325                return false;
     2326        }
     2327
     2328        pjob = print_job_find(tmp_ctx, servicename, jobid);
     2329        if (!pjob || !server_info) {
     2330                ret = false;
     2331                goto err_out;
     2332        }
     2333
     2334        ret = strequal(pjob->user, server_info->sanitized_username);
     2335err_out:
     2336        talloc_free(tmp_ctx);
     2337        return ret;
    22592338}
    22602339
     
    22702349        struct printjob *pjob;
    22712350        bool    owner;
    2272         char    *fname;
     2351        WERROR werr;
     2352        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     2353        if (tmp_ctx == NULL) {
     2354                return WERR_NOT_ENOUGH_MEMORY;
     2355        }
    22732356
    22742357        owner = is_owner(server_info, lp_const_servicename(snum), jobid);
     
    22902373                /* END_ADMIN_LOG */
    22912374
    2292                 return WERR_ACCESS_DENIED;
     2375                werr = WERR_ACCESS_DENIED;
     2376                goto err_out;
    22932377        }
    22942378
     
    23002384         */
    23012385
    2302         fname = print_job_fname(sharename, jobid);
    2303         if (fname != NULL) {
    2304                 /* remove the spool file */
    2305                 DEBUG(10, ("print_job_delete: "
    2306                            "Removing spool file [%s]\n", fname));
    2307                 if (unlink(fname) == -1) {
    2308                         return map_werror_from_unix(errno);
     2386        pjob = print_job_find(tmp_ctx, sharename, jobid);
     2387        if (!pjob || pjob->spooled || pjob->pid != getpid()) {
     2388                DEBUG(10, ("Skipping spool file removal for job %u\n", jobid));
     2389        } else {
     2390                DEBUG(10, ("Removing spool file [%s]\n", pjob->filename));
     2391                if (unlink(pjob->filename) == -1) {
     2392                        werr = map_werror_from_unix(errno);
     2393                        goto err_out;
    23092394                }
    23102395        }
    23112396
    23122397        if (!print_job_delete1(server_event_context(), msg_ctx, snum, jobid)) {
    2313                 return WERR_ACCESS_DENIED;
     2398                werr = WERR_ACCESS_DENIED;
     2399                goto err_out;
    23142400        }
    23152401
     
    23192405        print_queue_update(msg_ctx, snum, True);
    23202406
    2321         pjob = print_job_find(sharename, jobid);
     2407        pjob = print_job_find(tmp_ctx, sharename, jobid);
    23222408        if (pjob && (pjob->status != LPQ_DELETING)) {
    2323                 return WERR_ACCESS_DENIED;
    2324         }
    2325 
    2326         return WERR_PRINTER_HAS_JOBS_QUEUED;
     2409                werr = WERR_ACCESS_DENIED;
     2410                goto err_out;
     2411        }
     2412        werr = WERR_PRINTER_HAS_JOBS_QUEUED;
     2413
     2414err_out:
     2415        talloc_free(tmp_ctx);
     2416        return werr;
    23272417}
    23282418
     
    23312421****************************************************************************/
    23322422
    2333 bool print_job_pause(const struct auth_serversupplied_info *server_info,
     2423WERROR print_job_pause(const struct auth_serversupplied_info *server_info,
    23342424                     struct messaging_context *msg_ctx,
    2335                      int snum, uint32 jobid, WERROR *errcode)
     2425                     int snum, uint32 jobid)
    23362426{
    23372427        const char* sharename = lp_const_servicename(snum);
     
    23392429        int ret = -1;
    23402430        struct printif *current_printif = get_printer_fns( snum );
    2341 
    2342         pjob = print_job_find(sharename, jobid);
    2343 
     2431        WERROR werr;
     2432        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     2433        if (tmp_ctx == NULL) {
     2434                return WERR_NOT_ENOUGH_MEMORY;
     2435        }
     2436
     2437        pjob = print_job_find(tmp_ctx, sharename, jobid);
    23442438        if (!pjob || !server_info) {
    23452439                DEBUG(10, ("print_job_pause: no pjob or user for jobid %u\n",
    23462440                        (unsigned int)jobid ));
    2347                 return False;
     2441                werr = WERR_INVALID_PARAM;
     2442                goto err_out;
    23482443        }
    23492444
     
    23512446                DEBUG(10, ("print_job_pause: not spooled or bad sysjob = %d for jobid %u\n",
    23522447                        (int)pjob->sysjob, (unsigned int)jobid ));
    2353                 return False;
     2448                werr = WERR_INVALID_PARAM;
     2449                goto err_out;
    23542450        }
    23552451
     
    23672463                /* END_ADMIN_LOG */
    23682464
    2369                 *errcode = WERR_ACCESS_DENIED;
    2370                 return False;
     2465                werr = WERR_ACCESS_DENIED;
     2466                goto err_out;
    23712467        }
    23722468
     
    23752471
    23762472        if (ret != 0) {
    2377                 *errcode = WERR_INVALID_PARAM;
    2378                 return False;
     2473                werr = WERR_INVALID_PARAM;
     2474                goto err_out;
    23792475        }
    23802476
     
    23882484
    23892485        /* how do we tell if this succeeded? */
    2390 
    2391         return True;
     2486        werr = WERR_OK;
     2487err_out:
     2488        talloc_free(tmp_ctx);
     2489        return werr;
    23922490}
    23932491
     
    23962494****************************************************************************/
    23972495
    2398 bool print_job_resume(const struct auth_serversupplied_info *server_info,
     2496WERROR print_job_resume(const struct auth_serversupplied_info *server_info,
    23992497                      struct messaging_context *msg_ctx,
    2400                       int snum, uint32 jobid, WERROR *errcode)
     2498                      int snum, uint32 jobid)
    24012499{
    24022500        const char *sharename = lp_const_servicename(snum);
     
    24042502        int ret;
    24052503        struct printif *current_printif = get_printer_fns( snum );
    2406 
    2407         pjob = print_job_find(sharename, jobid);
    2408 
     2504        WERROR werr;
     2505        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     2506        if (tmp_ctx == NULL)
     2507                return WERR_NOT_ENOUGH_MEMORY;
     2508
     2509        pjob = print_job_find(tmp_ctx, sharename, jobid);
    24092510        if (!pjob || !server_info) {
    24102511                DEBUG(10, ("print_job_resume: no pjob or user for jobid %u\n",
    24112512                        (unsigned int)jobid ));
    2412                 return False;
     2513                werr = WERR_INVALID_PARAM;
     2514                goto err_out;
    24132515        }
    24142516
     
    24162518                DEBUG(10, ("print_job_resume: not spooled or bad sysjob = %d for jobid %u\n",
    24172519                        (int)pjob->sysjob, (unsigned int)jobid ));
    2418                 return False;
     2520                werr = WERR_INVALID_PARAM;
     2521                goto err_out;
    24192522        }
    24202523
     
    24232526                                JOB_ACCESS_ADMINISTER)) {
    24242527                DEBUG(3, ("resume denied by security descriptor\n"));
    2425                 *errcode = WERR_ACCESS_DENIED;
    24262528
    24272529                /* BEGIN_ADMIN_LOG */
     
    24322534                              lp_printername(snum) );
    24332535                /* END_ADMIN_LOG */
    2434                 return False;
     2536                werr = WERR_ACCESS_DENIED;
     2537                goto err_out;
    24352538        }
    24362539
     
    24382541
    24392542        if (ret != 0) {
    2440                 *errcode = WERR_INVALID_PARAM;
    2441                 return False;
     2543                werr = WERR_INVALID_PARAM;
     2544                goto err_out;
    24422545        }
    24432546
     
    24502553                          JOB_STATUS_QUEUED);
    24512554
    2452         return True;
     2555        werr = WERR_OK;
     2556err_out:
     2557        talloc_free(tmp_ctx);
     2558        return werr;
    24532559}
    24542560
     
    24642570        ssize_t return_code;
    24652571        struct printjob *pjob;
    2466 
    2467         pjob = print_job_find(sharename, jobid);
    2468 
    2469         if (!pjob)
     2572        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     2573        if (tmp_ctx == NULL) {
    24702574                return -1;
     2575        }
     2576
     2577        pjob = print_job_find(tmp_ctx, sharename, jobid);
     2578        if (!pjob) {
     2579                return_code = -1;
     2580                goto err_out;
     2581        }
     2582
    24712583        /* don't allow another process to get this info - it is meaningless */
    2472         if (pjob->pid != sys_getpid())
    2473                 return -1;
     2584        if (pjob->pid != sys_getpid()) {
     2585                return_code = -1;
     2586                goto err_out;
     2587        }
    24742588
    24752589        /* if SMBD is spooling this can't be allowed */
    24762590        if (pjob->status == PJOB_SMBD_SPOOLING) {
    2477                 return -1;
     2591                return_code = -1;
     2592                goto err_out;
    24782593        }
    24792594
    24802595        return_code = write_data(pjob->fd, buf, size);
    2481 
    2482         if (return_code>0) {
     2596        if (return_code > 0) {
    24832597                pjob->size += size;
    24842598                pjob_store(ev, msg_ctx, sharename, jobid, pjob);
    24852599        }
     2600err_out:
     2601        talloc_free(tmp_ctx);
    24862602        return return_code;
    24872603}
     
    27632879
    27642880        slprintf(pjob->filename, sizeof(pjob->filename)-1,
    2765                  "%s/%s%.8u.XXXXXX", lp_pathname(snum),
    2766                  PRINT_SPOOL_PREFIX, (unsigned int)jobid);
     2881                 "%s/%sXXXXXX", lp_pathname(snum), PRINT_SPOOL_PREFIX);
    27672882        pjob->fd = mkstemp(pjob->filename);
    27682883
     
    28302945
    28312946        pjob.pid = sys_getpid();
     2947        pjob.jobid = jobid;
    28322948        pjob.sysjob = -1;
    28332949        pjob.fd = -1;
     
    28943010        const char* sharename = lp_const_servicename(snum);
    28953011        struct printjob *pjob;
    2896 
    2897         pjob = print_job_find(sharename, jobid);
    2898         if (!pjob)
     3012        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     3013        if (tmp_ctx == NULL) {
    28993014                return;
     3015        }
     3016
     3017        pjob = print_job_find(tmp_ctx, sharename, jobid);
     3018        if (!pjob) {
     3019                goto err_out;
     3020        }
    29003021        /* don't allow another process to get this info - it is meaningless */
    2901         if (pjob->pid != sys_getpid())
    2902                 return;
     3022        if (pjob->pid != sys_getpid()) {
     3023                goto err_out;
     3024        }
    29033025
    29043026        pjob->page_count++;
    29053027        pjob_store(server_event_context(), msg_ctx, sharename, jobid, pjob);
     3028err_out:
     3029        talloc_free(tmp_ctx);
    29063030}
    29073031
     
    29193043        int ret;
    29203044        SMB_STRUCT_STAT sbuf;
    2921         struct printif *current_printif = get_printer_fns( snum );
     3045        struct printif *current_printif = get_printer_fns(snum);
    29223046        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
    2923 
    2924         pjob = print_job_find(sharename, jobid);
    2925 
     3047        char *lpq_cmd;
     3048        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     3049        if (tmp_ctx == NULL) {
     3050                return NT_STATUS_NO_MEMORY;
     3051        }
     3052
     3053        pjob = print_job_find(tmp_ctx, sharename, jobid);
    29263054        if (!pjob) {
    2927                 return NT_STATUS_PRINT_CANCELLED;
     3055                status = NT_STATUS_PRINT_CANCELLED;
     3056                goto err_out;
    29283057        }
    29293058
    29303059        if (pjob->spooled || pjob->pid != sys_getpid()) {
    2931                 return NT_STATUS_ACCESS_DENIED;
     3060                status = NT_STATUS_ACCESS_DENIED;
     3061                goto err_out;
    29323062        }
    29333063
     
    29833113        }
    29843114
    2985         ret = (*(current_printif->job_submit))(snum, pjob);
    2986 
     3115        /* don't strip out characters like '$' from the printername */
     3116        lpq_cmd = talloc_string_sub2(tmp_ctx,
     3117                                     lp_lpqcommand(snum),
     3118                                     "%p",
     3119                                     lp_printername(snum),
     3120                                     false, false, false);
     3121        if (lpq_cmd == NULL) {
     3122                status = NT_STATUS_PRINT_CANCELLED;
     3123                goto fail;
     3124        }
     3125        lpq_cmd = talloc_sub_advanced(tmp_ctx,
     3126                                      lp_servicename(snum),
     3127                                      current_user_info.unix_name,
     3128                                      "",
     3129                                      current_user.ut.gid,
     3130                                      get_current_username(),
     3131                                      current_user_info.domain,
     3132                                      lpq_cmd);
     3133        if (lpq_cmd == NULL) {
     3134                status = NT_STATUS_PRINT_CANCELLED;
     3135                goto fail;
     3136        }
     3137
     3138        ret = (*(current_printif->job_submit))(snum, pjob,
     3139                                               current_printif->type, lpq_cmd);
    29873140        if (ret) {
    29883141                status = NT_STATUS_PRINT_CANCELLED;
     
    30093162        unlink(pjob->filename);
    30103163        pjob_delete(server_event_context(), msg_ctx, sharename, jobid);
     3164err_out:
     3165        talloc_free(tmp_ctx);
    30113166        return status;
    30123167}
     
    30313186        bool ret = False;
    30323187        const char* sharename = lp_servicename(snum);
     3188        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     3189        if (tmp_ctx == NULL) {
     3190                return false;
     3191        }
    30333192
    30343193        /* make sure the database is up to date */
     
    30803239                                queue[i].fs_user,
    30813240                                queue[i].fs_file);
    3082                 queue[i].job = qjob;
     3241                queue[i].sysjob = qjob;
    30833242                queue[i].size = qsize;
    30843243                queue[i].page_count = qpage_count;
     
    30973256                jobid = IVAL(cgdata.dptr, i*4);
    30983257                DEBUG(5,("get_stored_queue_info: added job = %u\n", (unsigned int)jobid));
    3099                 pjob = print_job_find(lp_const_servicename(snum), jobid);
     3258                pjob = print_job_find(tmp_ctx, lp_const_servicename(snum), jobid);
    31003259                if (!pjob) {
    31013260                        DEBUG(5,("get_stored_queue_info: failed to find added job = %u\n", (unsigned int)jobid));
     
    31043263                }
    31053264
    3106                 queue[total_count].job = jobid;
     3265                queue[total_count].sysjob = jobid;
    31073266                queue[total_count].size = pjob->size;
    31083267                queue[total_count].page_count = pjob->page_count;
     
    31133272                fstrcpy(queue[total_count].fs_file, pjob->jobname);
    31143273                total_count++;
     3274                talloc_free(pjob);
    31153275        }
    31163276
     
    31223282
    31233283                for (j = 0; j < total_count; j++) {
    3124                         if (queue[j].job == jobid) {
     3284                        if (queue[j].sysjob == jobid) {
    31253285                                found = true;
    31263286                                break;
     
    31343294                                 (unsigned int) jobid));
    31353295
    3136                         pjob = print_job_find(sharename, jobid);
     3296                        pjob = print_job_find(tmp_ctx, sharename, jobid);
    31373297                        if (pjob == NULL) {
    31383298                                DEBUG(5,("get_stored_queue_info: failed to find "
     
    31433303                        }
    31443304
    3145                         queue[j].job = jobid;
     3305                        queue[j].sysjob = jobid;
    31463306                        queue[j].size = pjob->size;
    31473307                        queue[j].page_count = pjob->page_count;
     
    31513311                        fstrcpy(queue[j].fs_user, pjob->user);
    31523312                        fstrcpy(queue[j].fs_file, pjob->jobname);
     3313                        talloc_free(pjob);
    31533314
    31543315                        DEBUG(5,("get_stored_queue_info: updated queue[%u], jobid: %u, jobname: %s\n",
     
    31783339        SAFE_FREE(data.dptr);
    31793340        SAFE_FREE(cgdata.dptr);
     3341        talloc_free(tmp_ctx);
    31803342        return ret;
    31813343}
     
    33453507        for (i=0;i<njobs;i++) {
    33463508                bool owner = is_owner(server_info, lp_const_servicename(snum),
    3347                                       queue[i].job);
     3509                                      queue[i].sysjob);
    33483510
    33493511                if (owner || can_job_admin) {
    33503512                        print_job_delete1(server_event_context(), msg_ctx,
    3351                                           snum, queue[i].job);
     3513                                          snum, queue[i].sysjob);
    33523514                }
    33533515        }
  • trunk/server/source3/printing/printspoolss.c

    r745 r751  
    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)) {
  • trunk/server/source3/printing/tests/vlp.c

    r745 r751  
    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.