Changeset 746 for vendor/current/source3/printing
- Timestamp:
- Nov 27, 2012, 4:56:06 PM (13 years ago)
- Location:
- vendor/current/source3/printing
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/printing/load.c
r740 r746 31 31 char *str; 32 32 char *saveptr; 33 char *auto_serv = NULL; 33 34 34 35 if (pnum < 0) … … 39 40 return; 40 41 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) { 42 46 return; 47 } 43 48 44 49 for (p = strtok_r(str, LIST_SEP, &saveptr); p; -
vendor/current/source3/printing/lpq_parse.c
r478 r746 165 165 } 166 166 167 buf-> job = atoi(tok[JOBTOK]);167 buf->sysjob = atoi(tok[JOBTOK]); 168 168 buf->size = atoi(tok[TOTALTOK]); 169 169 buf->status = strequal(tok[RANKTOK],"active")?LPQ_PRINTING:LPQ_QUEUED; … … 282 282 } 283 283 284 buf-> job= atoi(tokarr[LPRNG_JOBTOK]);284 buf->sysjob = atoi(tokarr[LPRNG_JOBTOK]); 285 285 buf->size = atoi(tokarr[LPRNG_TOTALTOK]); 286 286 … … 385 385 } 386 386 387 buf-> job = atoi(tok[1]);387 buf->sysjob = atoi(tok[1]); 388 388 buf->status = strequal(tok[0],"HELD")?LPQ_PAUSED:LPQ_QUEUED; 389 389 buf->priority = 0; … … 421 421 } 422 422 423 buf-> job = atoi(tok[3]);423 buf->sysjob = atoi(tok[3]); 424 424 buf->status = strequal(tok[2],"RUNNING")?LPQ_PRINTING:LPQ_QUEUED; 425 425 buf->priority = 0; … … 512 512 /* fill things from header line */ 513 513 buf->time = jobtime; 514 buf-> job = jobid;514 buf->sysjob = jobid; 515 515 buf->status = jobstat; 516 516 buf->priority = jobprio; … … 652 652 } 653 653 654 buf-> job = atoi(tok[1]);654 buf->sysjob = atoi(tok[1]); 655 655 buf->size = atoi(tok[3]); 656 656 if (count > 7 && strequal(tok[7],"on")) { … … 727 727 } 728 728 729 buf-> job = atoi(tok[2]);729 buf->sysjob = atoi(tok[2]); 730 730 buf->size = atoi(tok[4]); 731 731 buf->status = strequal(tok[3],"active")?LPQ_PRINTING:LPQ_QUEUED; … … 807 807 } 808 808 809 buf-> job = atoi(tok[4]);809 buf->sysjob = atoi(tok[4]); 810 810 811 811 buf->size = atoi(tok[7]); … … 897 897 trim_char(parse_line->jobname, '\0', ' '); 898 898 899 buf-> job = atoi(parse_line->jobid);899 buf->sysjob = atoi(parse_line->jobid); 900 900 buf->priority = 0; 901 901 buf->size = atoi(parse_line->size); … … 958 958 959 959 /* Get the jobid */ 960 buf-> job = atoi(parse_line->jobid);960 buf->sysjob = atoi(parse_line->jobid); 961 961 962 962 /* Get the job name */ … … 1024 1024 switch (toknum) { 1025 1025 case 0: 1026 buf-> job = atoi(tok);1026 buf->sysjob = atoi(tok); 1027 1027 break; 1028 1028 case 1: … … 1153 1153 } 1154 1154 1155 /****************************************************************************1156 Parse a file name from the system spooler to generate a jobid.1157 ****************************************************************************/1158 1159 uint32_t print_parse_jobid(const char *fname)1160 {1161 int jobid;1162 const char *p = strstr_m(fname,PRINT_SPOOL_PREFIX);1163 1164 if (!p) {1165 return (uint32_t)-1;1166 }1167 p += strlen(PRINT_SPOOL_PREFIX);1168 jobid = atoi(p);1169 if (jobid <= 0) {1170 return (uint32_t)-1;1171 }1172 return (uint32_t)jobid;1173 } -
vendor/current/source3/printing/nt_printing.c
r740 r746 1494 1494 1495 1495 static 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); 1498 1501 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); 1503 1513 if (!NT_STATUS_IS_OK(status)) { 1504 return status;1514 goto err_out; 1505 1515 } 1506 1516 1507 1517 status = unlink_internals(conn, NULL, 0, smb_fname, false); 1508 1509 TALLOC_FREE(smb_fname);1518 err_out: 1519 talloc_free(tmp_ctx); 1510 1520 return status; 1511 1521 } … … 1520 1530 const struct spoolss_DriverInfo8 *r) 1521 1531 { 1522 int i = 0; 1523 char *s; 1524 const char *file; 1532 const char *short_arch; 1525 1533 connection_struct *conn; 1526 1534 NTSTATUS nt_status; … … 1573 1581 } 1574 1582 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 */ 1577 1591 1578 1592 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); 1584 1595 } 1585 1596 1586 1597 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); 1592 1600 } 1593 1601 1594 1602 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); 1600 1605 } 1601 1606 1602 1607 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 } 1611 1611 1612 1612 if (r->dependent_files) { 1613 int i = 0; 1613 1614 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]); 1624 1617 i++; 1625 1618 } … … 1871 1864 printer, ""); 1872 1865 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 1871 void nt_printer_add(TALLOC_CTX *mem_ctx, 1872 const struct auth_serversupplied_info *session_info, 1873 struct messaging_context *msg_ctx, 1874 const char *printer) 1875 { 1876 WERROR result; 1877 1878 result = winreg_create_printer_internal(mem_ctx, session_info, msg_ctx, 1879 printer); 1880 if (!W_ERROR_IS_OK(result)) { 1881 DEBUG(0, ("nt_printer_add: failed to add printer %s: %s\n", 1882 printer, win_errstr(result))); 1883 } 1884 } -
vendor/current/source3/printing/nt_printing_migrate.c
r740 r746 4 4 * 5 5 * Copyright (c) Andreas Schneider 2010. 6 * Copyright (C) Bjoern Baumbach <bb@sernet.de> 2011 6 7 * 7 8 * This program is free software; you can redistribute it and/or modify … … 28 29 #include "rpc_client/cli_winreg_spoolss.h" 29 30 31 static 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 30 45 NTSTATUS printing_tdb_migrate_form(TALLOC_CTX *mem_ctx, 31 46 struct rpc_pipe_client *winreg_pipe, … … 74 89 b, 75 90 &f1); 91 if (W_ERROR_EQUAL(result, WERR_FILE_EXISTS)) { 92 /* Don't migrate form if it already exists. */ 93 result = WERR_OK; 94 } 76 95 if (!W_ERROR_IS_OK(result)) { 77 96 return werror_to_ntstatus(result); … … 97 116 const char *driver_name; 98 117 uint32_t driver_version; 118 int i; 99 119 100 120 blob = data_blob_const(data, length); … … 115 135 ZERO_STRUCT(a); 116 136 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 } 117 143 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); 118 149 119 150 d3.architecture = r.environment; -
vendor/current/source3/printing/print_cups.c
r740 r746 32 32 #include <cups/language.h> 33 33 34 #if (CUPS_VERSION_MAJOR > 1) || (CUPS_VERSION_MINOR > 5) 35 #define HAVE_CUPS_1_6 1 36 #endif 37 38 #ifndef HAVE_CUPS_1_6 39 #define ippGetGroupTag(attr) attr->group_tag 40 #define ippGetName(attr) attr->name 41 #define ippGetValueTag(attr) attr->value_tag 42 #define ippGetStatusCode(ipp) ipp->request.status.status_code 43 #define ippGetInteger(attr, element) attr->values[element].integer 44 #define ippGetString(attr, element, language) attr->values[element].string.text 45 46 static ipp_attribute_t * 47 ippFirstAttribute(ipp_t *ipp) 48 { 49 if (!ipp) 50 return (NULL); 51 return (ipp->current = ipp->attrs); 52 } 53 54 static ipp_attribute_t * 55 ippNextAttribute(ipp_t *ipp) 56 { 57 if (!ipp || !ipp->current) 58 return (NULL); 59 return (ipp->current = ipp->current->next); 60 } 61 62 static int ippSetOperation(ipp_t *ipp, ipp_op_t op) 63 { 64 ipp->request.op.operation_id = op; 65 return (1); 66 } 67 68 static int ippSetRequestId(ipp_t *ipp, int request_id) 69 { 70 ipp->request.any.request_id = request_id; 71 return (1); 72 } 73 #endif 74 34 75 static SIG_ATOMIC_T gotalarm; 35 76 … … 168 209 bool ret_ok = false; 169 210 170 for (attr = response->attrs; attr != NULL;) {211 for (attr = ippFirstAttribute(response); attr != NULL;) { 171 212 /* 172 213 * Skip leading attributes until we hit a printer... 173 214 */ 174 215 175 while (attr != NULL && attr->group_tag!= IPP_TAG_PRINTER)176 attr = attr->next;216 while (attr != NULL && ippGetGroupTag(attr) != IPP_TAG_PRINTER) 217 attr = ippNextAttribute(response); 177 218 178 219 if (attr == NULL) … … 186 227 info = NULL; 187 228 188 while (attr != NULL && attr->group_tag== IPP_TAG_PRINTER) {229 while (attr != NULL && ippGetGroupTag(attr) == IPP_TAG_PRINTER) { 189 230 size_t size; 190 if (strcmp( attr->name, "printer-name") == 0 &&191 attr->value_tag== IPP_TAG_NAME) {231 if (strcmp(ippGetName(attr), "printer-name") == 0 && 232 ippGetValueTag(attr) == IPP_TAG_NAME) { 192 233 if (!pull_utf8_talloc(mem_ctx, 193 234 &name, 194 attr->values[0].string.text,235 ippGetString(attr, 0, NULL), 195 236 &size)) { 196 237 goto err_out; … … 198 239 } 199 240 200 if (strcmp( attr->name, "printer-info") == 0 &&201 attr->value_tag== IPP_TAG_TEXT) {241 if (strcmp(ippGetName(attr), "printer-info") == 0 && 242 ippGetValueTag(attr) == IPP_TAG_TEXT) { 202 243 if (!pull_utf8_talloc(mem_ctx, 203 244 &info, 204 attr->values[0].string.text,245 ippGetString(attr, 0, NULL), 205 246 &size)) { 206 247 goto err_out; … … 208 249 } 209 250 210 if (strcmp( attr->name, "printer-location") == 0 &&211 attr->value_tag== IPP_TAG_TEXT) {251 if (strcmp(ippGetName(attr), "printer-location") == 0 && 252 ippGetValueTag(attr) == IPP_TAG_TEXT) { 212 253 if (!pull_utf8_talloc(mem_ctx, 213 254 &location, 214 attr->values[0].string.text,255 ippGetString(attr, 0, NULL), 215 256 &size)) { 216 257 goto err_out; … … 218 259 } 219 260 220 attr = attr->next;261 attr = ippNextAttribute(response); 221 262 } 222 263 … … 298 339 request = ippNew(); 299 340 300 request->request.op.operation_id = CUPS_GET_PRINTERS;301 request->request.op.request_id = 1;341 ippSetOperation(request, CUPS_GET_PRINTERS); 342 ippSetRequestId(request, 1); 302 343 303 344 language = cupsLangDefault(); … … 340 381 request = ippNew(); 341 382 342 request->request.op.operation_id = CUPS_GET_CLASSES;343 request->request.op.request_id = 1;383 ippSetOperation(request, CUPS_GET_CLASSES); 384 ippSetRequestId(request, 1); 344 385 345 386 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, … … 604 645 request = ippNew(); 605 646 606 request->request.op.operation_id = IPP_CANCEL_JOB;607 request->request.op.request_id = 1;647 ippSetOperation(request, IPP_CANCEL_JOB); 648 ippSetRequestId(request, 1); 608 649 609 650 language = cupsLangDefault(); … … 631 672 632 673 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) { 633 if ( response->request.status.status_code>= IPP_OK_CONFLICT) {674 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 634 675 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob, 635 676 ippErrorString(cupsLastError()))); … … 701 742 request = ippNew(); 702 743 703 request->request.op.operation_id = IPP_HOLD_JOB;704 request->request.op.request_id = 1;744 ippSetOperation(request, IPP_HOLD_JOB); 745 ippSetRequestId(request, 1); 705 746 706 747 language = cupsLangDefault(); … … 727 768 728 769 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) { 729 if ( response->request.status.status_code>= IPP_OK_CONFLICT) {770 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 730 771 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob, 731 772 ippErrorString(cupsLastError()))); … … 797 838 request = ippNew(); 798 839 799 request->request.op.operation_id = IPP_RELEASE_JOB;800 request->request.op.request_id = 1;840 ippSetOperation(request, IPP_RELEASE_JOB); 841 ippSetRequestId(request, 1); 801 842 802 843 language = cupsLangDefault(); … … 823 864 824 865 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) { 825 if ( response->request.status.status_code>= IPP_OK_CONFLICT) {866 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 826 867 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob, 827 868 ippErrorString(cupsLastError()))); … … 853 894 */ 854 895 855 static int cups_job_submit(int snum, struct printjob *pjob) 896 static int cups_job_submit(int snum, struct printjob *pjob, 897 enum printing_types printing_type, 898 char *lpq_cmd) 856 899 { 857 900 TALLOC_CTX *frame = talloc_stackframe(); … … 872 915 char *filename = NULL; 873 916 size_t size; 874 uint32_t jobid = (uint32_t)-1;875 917 876 918 DEBUG(5,("cups_job_submit(%d, %p)\n", snum, pjob)); … … 903 945 request = ippNew(); 904 946 905 request->request.op.operation_id = IPP_PRINT_JOB;906 request->request.op.request_id = 1;947 ippSetOperation(request, IPP_PRINT_JOB); 948 ippSetRequestId(request, 1); 907 949 908 950 language = cupsLangDefault(); … … 934 976 pjob->clientmachine); 935 977 936 /* Get the jobid from the filename. */937 jobid = print_parse_jobid(pjob->filename);938 if (jobid == (uint32_t)-1) {939 DEBUG(0,("cups_job_submit: failed to parse jobid from name %s\n",940 pjob->filename ));941 jobid = 0;942 }943 944 978 if (!push_utf8_talloc(frame, &jobname, pjob->jobname, &size)) { 945 979 goto out; … … 947 981 new_jobname = talloc_asprintf(frame, 948 982 "%s%.8u %s", PRINT_SPOOL_PREFIX, 949 (unsigned int)jobid, 950 jobname); 983 pjob->jobid, jobname); 951 984 if (new_jobname == NULL) { 952 985 goto out; … … 980 1013 } 981 1014 if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) { 982 if ( response->request.status.status_code>= IPP_OK_CONFLICT) {1015 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 983 1016 DEBUG(0,("Unable to print file to %s - %s\n", 984 1017 lp_printername(snum), … … 988 1021 attr_job_id = ippFindAttribute(response, "job-id", IPP_TAG_INTEGER); 989 1022 if(attr_job_id) { 990 pjob->sysjob = attr_job_id->values[0].integer;1023 pjob->sysjob = ippGetInteger(attr_job_id, 0); 991 1024 DEBUG(5,("cups_job_submit: job-id %d\n", pjob->sysjob)); 992 1025 } else { … … 1110 1143 request = ippNew(); 1111 1144 1112 request->request.op.operation_id = IPP_GET_JOBS;1113 request->request.op.request_id = 1;1145 ippSetOperation(request, IPP_GET_JOBS); 1146 ippSetRequestId(request, 1); 1114 1147 1115 1148 language = cupsLangDefault(); … … 1139 1172 } 1140 1173 1141 if ( response->request.status.status_code>= IPP_OK_CONFLICT) {1174 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 1142 1175 DEBUG(0,("Unable to get jobs for %s - %s\n", uri, 1143 ippErrorString( response->request.status.status_code)));1176 ippErrorString(ippGetStatusCode(response)))); 1144 1177 goto out; 1145 1178 } … … 1153 1186 queue = NULL; 1154 1187 1155 for (attr = response->attrs; attr != NULL; attr = attr->next) {1188 for (attr = ippFirstAttribute(response); attr != NULL; attr = ippNextAttribute(response)) { 1156 1189 /* 1157 1190 * Skip leading attributes until we hit a job... 1158 1191 */ 1159 1192 1160 while (attr != NULL && attr->group_tag!= IPP_TAG_JOB)1161 attr = attr->next;1193 while (attr != NULL && ippGetGroupTag(attr) != IPP_TAG_JOB) 1194 attr = ippNextAttribute(response); 1162 1195 1163 1196 if (attr == NULL) … … 1194 1227 job_name = NULL; 1195 1228 1196 while (attr != NULL && attr->group_tag== IPP_TAG_JOB) {1197 if (attr->name== NULL) {1198 attr = attr->next;1229 while (attr != NULL && ippGetGroupTag(attr) == IPP_TAG_JOB) { 1230 if (ippGetName(attr) == NULL) { 1231 attr = ippNextAttribute(response); 1199 1232 break; 1200 1233 } 1201 1234 1202 if (strcmp(attr->name, "job-id") == 0 &&1203 attr->value_tag== IPP_TAG_INTEGER)1204 job_id = attr->values[0].integer;1205 1206 if (strcmp(attr->name, "job-k-octets") == 0 &&1207 attr->value_tag== IPP_TAG_INTEGER)1208 job_k_octets = attr->values[0].integer;1209 1210 if (strcmp(attr->name, "job-priority") == 0 &&1211 attr->value_tag== IPP_TAG_INTEGER)1212 job_priority = attr->values[0].integer;1213 1214 if (strcmp(attr->name, "job-state") == 0 &&1215 attr->value_tag== IPP_TAG_ENUM)1216 job_status = (ipp_jstate_t) (attr->values[0].integer);1217 1218 if (strcmp(attr->name, "time-at-creation") == 0 &&1219 attr->value_tag== IPP_TAG_INTEGER)1220 job_time = attr->values[0].integer;1221 1222 if (strcmp(attr->name, "job-name") == 0 &&1223 attr->value_tag== IPP_TAG_NAME) {1235 if (strcmp(ippGetName(attr), "job-id") == 0 && 1236 ippGetValueTag(attr) == IPP_TAG_INTEGER) 1237 job_id = ippGetInteger(attr, 0); 1238 1239 if (strcmp(ippGetName(attr), "job-k-octets") == 0 && 1240 ippGetValueTag(attr) == IPP_TAG_INTEGER) 1241 job_k_octets = ippGetInteger(attr, 0); 1242 1243 if (strcmp(ippGetName(attr), "job-priority") == 0 && 1244 ippGetValueTag(attr) == IPP_TAG_INTEGER) 1245 job_priority = ippGetInteger(attr, 0); 1246 1247 if (strcmp(ippGetName(attr), "job-state") == 0 && 1248 ippGetValueTag(attr) == IPP_TAG_ENUM) 1249 job_status = (ipp_jstate_t)ippGetInteger(attr, 0); 1250 1251 if (strcmp(ippGetName(attr), "time-at-creation") == 0 && 1252 ippGetValueTag(attr) == IPP_TAG_INTEGER) 1253 job_time = ippGetInteger(attr, 0); 1254 1255 if (strcmp(ippGetName(attr), "job-name") == 0 && 1256 ippGetValueTag(attr) == IPP_TAG_NAME) { 1224 1257 if (!pull_utf8_talloc(frame, 1225 1258 &job_name, 1226 attr->values[0].string.text,1259 ippGetString(attr, 0, NULL), 1227 1260 &size)) { 1228 1261 goto out; … … 1230 1263 } 1231 1264 1232 if (strcmp(attr->name, "job-originating-user-name") == 0 &&1233 attr->value_tag== IPP_TAG_NAME) {1265 if (strcmp(ippGetName(attr), "job-originating-user-name") == 0 && 1266 ippGetValueTag(attr) == IPP_TAG_NAME) { 1234 1267 if (!pull_utf8_talloc(frame, 1235 1268 &user_name, 1236 attr->values[0].string.text,1269 ippGetString(attr, 0, NULL), 1237 1270 &size)) { 1238 1271 goto out; … … 1240 1273 } 1241 1274 1242 attr = attr->next;1275 attr = ippNextAttribute(response); 1243 1276 } 1244 1277 … … 1254 1287 } 1255 1288 1256 temp-> job= job_id;1289 temp->sysjob = job_id; 1257 1290 temp->size = job_k_octets * 1024; 1258 1291 temp->status = job_status == IPP_JOB_PENDING ? LPQ_QUEUED : … … 1286 1319 request = ippNew(); 1287 1320 1288 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;1289 request->request.op.request_id = 1;1321 ippSetOperation(request, IPP_GET_PRINTER_ATTRIBUTES); 1322 ippSetRequestId(request, 1); 1290 1323 1291 1324 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, … … 1313 1346 } 1314 1347 1315 if ( response->request.status.status_code>= IPP_OK_CONFLICT) {1348 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 1316 1349 DEBUG(0,("Unable to get printer status for %s - %s\n", printername, 1317 ippErrorString( response->request.status.status_code)));1350 ippErrorString(ippGetStatusCode(response)))); 1318 1351 goto out; 1319 1352 } … … 1324 1357 1325 1358 if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL) { 1326 if ( attr->values[0].integer== IPP_PRINTER_STOPPED)1359 if (ippGetInteger(attr, 0) == IPP_PRINTER_STOPPED) 1327 1360 status->status = LPSTAT_STOPPED; 1328 1361 else … … 1334 1367 char *msg = NULL; 1335 1368 if (!pull_utf8_talloc(frame, &msg, 1336 attr->values[0].string.text,1369 ippGetString(attr, 0, NULL), 1337 1370 &size)) { 1338 1371 SAFE_FREE(queue); … … 1410 1443 request = ippNew(); 1411 1444 1412 request->request.op.operation_id = IPP_PAUSE_PRINTER;1413 request->request.op.request_id = 1;1445 ippSetOperation(request, IPP_PAUSE_PRINTER); 1446 ippSetRequestId(request, 1); 1414 1447 1415 1448 language = cupsLangDefault(); … … 1441 1474 1442 1475 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) { 1443 if ( response->request.status.status_code>= IPP_OK_CONFLICT) {1476 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 1444 1477 DEBUG(0,("Unable to pause printer %s - %s\n", 1445 1478 lp_printername(snum), … … 1514 1547 request = ippNew(); 1515 1548 1516 request->request.op.operation_id = IPP_RESUME_PRINTER;1517 request->request.op.request_id = 1;1549 ippSetOperation(request, IPP_RESUME_PRINTER); 1550 ippSetRequestId(request, 1); 1518 1551 1519 1552 language = cupsLangDefault(); … … 1545 1578 1546 1579 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) { 1547 if ( response->request.status.status_code>= IPP_OK_CONFLICT) {1580 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 1548 1581 DEBUG(0,("Unable to resume printer %s - %s\n", 1549 1582 lp_printername(snum), -
vendor/current/source3/printing/print_generic.c
r740 r746 140 140 141 141 /**************************************************************************** 142 get the current list of queued jobs 143 ****************************************************************************/ 144 static 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 /**************************************************************************** 142 198 Submit a file for printing - called from print_job_end() 143 199 ****************************************************************************/ 144 200 145 static int generic_job_submit(int snum, struct printjob *pjob) 201 static int generic_job_submit(int snum, struct printjob *pjob, 202 enum printing_types printing_type, 203 char *lpq_cmd) 146 204 { 147 205 int ret = -1; … … 153 211 TALLOC_CTX *ctx = talloc_tos(); 154 212 fstring job_page_count, job_size; 213 print_queue_struct *q; 214 print_status_struct status; 155 215 156 216 /* we print from the directory path to give the best chance of … … 203 263 "%c", job_page_count, 204 264 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 205 295 206 296 out: … … 211 301 TALLOC_FREE(current_directory); 212 302 return ret; 213 }214 215 216 /****************************************************************************217 get the current list of queued jobs218 ****************************************************************************/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't231 get it rigt when using the background update daemon. Make the caller232 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;270 303 } 271 304 -
vendor/current/source3/printing/print_iprint.c
r740 r746 35 35 #define NOVELL_SERVER_VERSION_OES_SP1 33554432 36 36 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 51 static ipp_attribute_t * 52 ippFirstAttribute(ipp_t *ipp) 53 { 54 if (!ipp) 55 return (NULL); 56 return (ipp->current = ipp->attrs); 57 } 58 59 static ipp_attribute_t * 60 ippNextAttribute(ipp_t *ipp) 61 { 62 if (!ipp || !ipp->current) 63 return (NULL); 64 return (ipp->current = ipp->current->next); 65 } 66 67 static int ippSetOperation(ipp_t *ipp, ipp_op_t op) 68 { 69 ipp->request.op.operation_id = op; 70 return (1); 71 } 72 73 static int ippSetRequestId(ipp_t *ipp, int request_id) 74 { 75 ipp->request.any.request_id = request_id; 76 return (1); 77 } 78 #endif 79 37 80 /* 38 81 * 'iprint_passwd_cb()' - The iPrint password callback... … … 93 136 request = ippNew(); 94 137 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); 97 140 98 141 language = cupsLangDefault(); … … 115 158 116 159 if (((response = cupsDoRequest(http, request, "/ipp/")) == NULL) || 117 ( response->request.status.status_code>= IPP_OK_CONFLICT))160 (ippGetStatusCode(response) >= IPP_OK_CONFLICT)) 118 161 goto out; 119 162 120 163 if (((attr = ippFindAttribute(response, "server-version", 121 164 IPP_TAG_STRING)) != NULL)) { 122 if ((ver = strstr( attr->values[0].string.text,165 if ((ver = strstr(ippGetString(attr, 0, NULL), 123 166 NOVELL_SERVER_VERSION_STRING)) != NULL) { 124 167 ver += strlen(NOVELL_SERVER_VERSION_STRING); … … 136 179 } 137 180 138 if ((os = strstr( attr->values[0].string.text,181 if ((os = strstr(ippGetString(attr, 0, NULL), 139 182 NOVELL_SERVER_SYSNAME)) != NULL) { 140 183 os += strlen(NOVELL_SERVER_SYSNAME); … … 185 228 request = ippNew(); 186 229 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); 189 232 190 233 language = cupsLangDefault(); … … 231 274 } 232 275 233 for (attr = response->attrs; attr != NULL;) {276 for (attr = ippFirstAttribute(response); attr != NULL;) { 234 277 /* 235 278 * Skip leading attributes until we hit a printer... 236 279 */ 237 280 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); 240 283 241 284 if (attr == NULL) … … 251 294 secure = 0; 252 295 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); 262 305 263 306 /* … … 267 310 * printer should show up 268 311 */ 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)))) 274 317 smb_enabled = 0; 275 318 … … 280 323 * printer should show up 281 324 */ 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)))) 287 330 secure = 1; 288 331 289 attr = attr->next;332 attr = ippNextAttribute(response); 290 333 } 291 334 … … 344 387 request = ippNew(); 345 388 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); 349 391 350 392 language = cupsLangDefault(); … … 369 411 } 370 412 371 for (attr = response->attrs; attr != NULL;) {413 for (attr = ippFirstAttribute(response); attr != NULL;) { 372 414 /* 373 415 * Skip leading attributes until we hit a printer... 374 416 */ 375 417 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); 378 420 379 421 if (attr == NULL) … … 384 426 */ 385 427 386 while (attr != NULL && attr->group_tag== IPP_TAG_PRINTER)428 while (attr != NULL && ippGetGroupTag(attr) == IPP_TAG_PRINTER) 387 429 { 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)) 394 436 { 395 for (i = 0; i< attr->num_values; i++)437 for (i = 0; i<ippGetCount(attr); i++) 396 438 { 397 char *url = attr->values[i].string.text;439 char *url = ippGetString(attr, i, NULL); 398 440 if (!url || !strlen(url)) 399 441 continue; … … 401 443 } 402 444 } 403 attr = attr->next;445 attr = ippNextAttribute(response); 404 446 } 405 447 } … … 467 509 request = ippNew(); 468 510 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); 471 513 472 514 language = cupsLangDefault(); … … 494 536 495 537 if ((response = cupsDoRequest(http, request, httpPath)) != NULL) { 496 if ( response->request.status.status_code>= IPP_OK_CONFLICT) {538 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 497 539 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob, 498 540 ippErrorString(cupsLastError()))); … … 565 607 request = ippNew(); 566 608 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); 569 611 570 612 language = cupsLangDefault(); … … 594 636 595 637 if ((response = cupsDoRequest(http, request, httpPath)) != NULL) { 596 if ( response->request.status.status_code>= IPP_OK_CONFLICT) {638 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 597 639 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob, 598 640 ippErrorString(cupsLastError()))); … … 665 707 request = ippNew(); 666 708 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); 669 711 670 712 language = cupsLangDefault(); … … 694 736 695 737 if ((response = cupsDoRequest(http, request, httpPath)) != NULL) { 696 if ( response->request.status.status_code>= IPP_OK_CONFLICT) {738 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 697 739 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob, 698 740 ippErrorString(cupsLastError()))); … … 723 765 */ 724 766 725 static int iprint_job_submit(int snum, struct printjob *pjob) 767 static int iprint_job_submit(int snum, struct printjob *pjob, 768 enum printing_types printing_type, 769 char *lpq_cmd) 726 770 { 727 771 int ret = 1; /* Return value */ … … 764 808 request = ippNew(); 765 809 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); 768 812 769 813 language = cupsLangDefault(); … … 798 842 799 843 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) { 801 845 DEBUG(0,("Unable to print file to %s - %s\n", 802 846 lp_printername(snum), … … 818 862 819 863 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) 821 865 { 822 pjob->sysjob = attr->values[0].integer;866 pjob->sysjob = ippGetInteger(attr, 0); 823 867 } 824 868 } … … 867 911 int job_k_octets; /* job-k-octets attribute */ 868 912 time_t job_time; /* time-at-creation attribute */ 869 time_t printer_current_time = 0; /* printer's current time */870 913 time_t printer_up_time = 0; /* printer's uptime */ 871 914 ipp_jstate_t job_status; /* job-status attribute */ … … 940 983 request = ippNew(); 941 984 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); 944 987 945 988 language = cupsLangDefault(); … … 972 1015 } 973 1016 974 if ( response->request.status.status_code>= IPP_OK_CONFLICT) {1017 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 975 1018 DEBUG(0,("Unable to get printer status for %s - %s\n", printername, 976 ippErrorString( response->request.status.status_code)));1019 ippErrorString(ippGetStatusCode(response)))); 977 1020 *q = queue; 978 1021 goto out; … … 984 1027 985 1028 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) 987 1030 status->status = LPSTAT_STOPPED; 988 1031 else … … 992 1035 if ((attr = ippFindAttribute(response, "printer-state-message", 993 1036 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)); 999 1038 1000 1039 if ((attr = ippFindAttribute(response, "printer-up-time", 1001 1040 IPP_TAG_INTEGER)) != NULL) 1002 printer_up_time = attr->values[0].integer;1041 printer_up_time = ippGetInteger(attr, 0); 1003 1042 1004 1043 ippDelete(response); … … 1017 1056 request = ippNew(); 1018 1057 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); 1021 1060 1022 1061 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, … … 1046 1085 } 1047 1086 1048 if ( response->request.status.status_code>= IPP_OK_CONFLICT) {1087 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 1049 1088 DEBUG(0,("Unable to get jobs for %s - %s\n", uri, 1050 ippErrorString( response->request.status.status_code)));1089 ippErrorString(ippGetStatusCode(response)))); 1051 1090 goto out; 1052 1091 } … … 1060 1099 queue = NULL; 1061 1100 1062 for (attr = response->attrs; attr != NULL; attr = attr->next) {1101 for (attr = ippFirstAttribute(response); attr != NULL; attr = ippNextAttribute(response)) { 1063 1102 /* 1064 1103 * Skip leading attributes until we hit a job... 1065 1104 */ 1066 1105 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); 1069 1108 1070 1109 if (attr == NULL) … … 1101 1140 job_name = NULL; 1102 1141 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); 1106 1145 break; 1107 1146 } 1108 1147 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) 1127 1166 { 1128 1167 /* … … 1134 1173 1135 1174 if (jobUseUnixTime) 1136 job_time = attr->values[0].integer;1175 job_time = ippGetInteger(attr, 0); 1137 1176 else 1138 job_time = time(NULL) - printer_up_time + attr->values[0].integer;1177 job_time = time(NULL) - printer_up_time + ippGetInteger(attr, 0); 1139 1178 } 1140 1179 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); 1152 1191 } 1153 1192 … … 1163 1202 } 1164 1203 1165 temp-> job= job_id;1204 temp->sysjob = job_id; 1166 1205 temp->size = job_k_octets * 1024; 1167 1206 temp->status = job_status == IPP_JOB_PENDING ? LPQ_QUEUED : -
vendor/current/source3/printing/printer_list.c
r740 r746 92 92 data = dbwrap_fetch_bystring_upper(db, key, key); 93 93 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")); 95 96 status = NT_STATUS_NOT_FOUND; 96 97 goto done; … … 192 193 193 194 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); 195 196 196 197 status = dbwrap_store_bystring_upper(db, key, data, TDB_REPLACE); -
vendor/current/source3/printing/printing.c
r740 r746 374 374 ***********************************************************************/ 375 375 376 static int unpack_pjob( uint8 *buf, int buflen, struct printjob *pjob ) 376 static int unpack_pjob(TALLOC_CTX *mem_ctx, uint8 *buf, int buflen, 377 struct printjob *pjob) 377 378 { 378 379 int len = 0; 379 380 int used; 380 uint32 pjpid, pj sysjob, pjfd, pjstarttime, pjstatus;381 uint32 pjpid, pjjobid, pjsysjob, pjfd, pjstarttime, pjstatus; 381 382 uint32 pjsize, pjpage_count, pjspooled, pjsmbjob; 382 383 383 if ( !buf || !pjob )384 if (!buf || !pjob) { 384 385 return -1; 385 386 len += tdb_unpack(buf+len, buflen-len, "dddddddddfffff", 386 } 387 388 len += tdb_unpack(buf+len, buflen-len, "ddddddddddfffff", 387 389 &pjpid, 390 &pjjobid, 388 391 &pjsysjob, 389 392 &pjfd, … … 400 403 pjob->queuename); 401 404 402 if ( len == -1 )405 if (len == -1) { 403 406 return -1; 404 405 used = unpack_devicemode(NULL, buf+len, buflen-len, &pjob->devmode); 407 } 408 409 used = unpack_devicemode(mem_ctx, buf+len, buflen-len, &pjob->devmode); 406 410 if (used == -1) { 407 411 return -1; … … 411 415 412 416 pjob->pid = pjpid; 417 pjob->jobid = pjjobid; 413 418 pjob->sysjob = pjsysjob; 414 419 pjob->fd = pjfd; … … 428 433 ****************************************************************************/ 429 434 430 static struct printjob *print_job_find(const char *sharename, uint32 jobid) 431 { 432 static struct printjob pjob; 435 static struct printjob *print_job_find(TALLOC_CTX *mem_ctx, 436 const char *sharename, 437 uint32 jobid) 438 { 439 struct printjob *pjob; 433 440 uint32_t tmp; 434 441 TDB_DATA ret; … … 446 453 447 454 if (!ret.dptr) { 448 DEBUG(10,("print_job_find: failed to find jobid %u.\n", (unsigned int)jobid )); 455 DEBUG(10, ("print_job_find: failed to find jobid %u.\n", 456 jobid)); 449 457 return NULL; 450 458 } 451 459 452 talloc_free(pjob.devmode); 453 454 ZERO_STRUCT( pjob ); 455 456 if ( unpack_pjob( ret.dptr, ret.dsize, &pjob ) == -1 ) { 457 DEBUG(10,("print_job_find: failed to unpack jobid %u.\n", (unsigned int)jobid )); 458 SAFE_FREE(ret.dptr); 459 return NULL; 460 } 461 460 pjob = talloc_zero(mem_ctx, struct printjob); 461 if (pjob == NULL) { 462 goto err_out; 463 } 464 465 if (unpack_pjob(mem_ctx, ret.dptr, ret.dsize, pjob) == -1) { 466 DEBUG(10, ("failed to unpack jobid %u.\n", jobid)); 467 talloc_free(pjob); 468 pjob = NULL; 469 goto err_out; 470 } 471 472 DEBUG(10,("print_job_find: returning system job %d for jobid %u.\n", 473 pjob->sysjob, jobid)); 474 SMB_ASSERT(pjob->jobid == jobid); 475 476 err_out: 462 477 SAFE_FREE(ret.dptr); 463 464 DEBUG(10,("print_job_find: returning system job %d for jobid %u.\n", 465 (int)pjob.sysjob, (unsigned int)jobid )); 466 467 return &pjob; 478 return pjob; 468 479 } 469 480 … … 490 501 491 502 if (state->sysjob == pjob->sysjob) { 492 uint32 jobid = IVAL(key.dptr,0); 493 494 state->sysjob_to_jobid_value = jobid; 503 state->sysjob_to_jobid_value = pjob->jobid; 495 504 return 1; 496 505 } 497 506 498 507 return 0; 508 } 509 510 static uint32 sysjob_to_jobid_pdb(struct tdb_print_db *pdb, int sysjob) 511 { 512 struct unixjob_traverse_state state; 513 514 state.sysjob = sysjob; 515 state.sysjob_to_jobid_value = (uint32)-1; 516 517 tdb_traverse(pdb->tdb, unixjob_traverse_fn, &state); 518 519 return state.sysjob_to_jobid_value; 499 520 } 500 521 … … 738 759 len = 0; 739 760 buflen = newlen; 740 len += tdb_pack(buf+len, buflen-len, "ddddddddd fffff",761 len += tdb_pack(buf+len, buflen-len, "ddddddddddfffff", 741 762 (uint32)pjob->pid, 763 (uint32)pjob->jobid, 742 764 (uint32)pjob->sysjob, 743 765 (uint32)pjob->fd, … … 776 798 /* Send notify updates for what has changed */ 777 799 778 if ( ret) {800 if (ret) { 779 801 bool changed = false; 780 802 struct printjob old_pjob; 781 803 782 if ( old_data.dsize ) 783 { 784 if ( unpack_pjob( old_data.dptr, old_data.dsize, &old_pjob ) != -1 ) 785 { 786 pjob_store_notify(server_event_context(), 804 if (old_data.dsize) { 805 TALLOC_CTX *tmp_ctx = talloc_new(ev); 806 if (tmp_ctx == NULL) 807 goto done; 808 809 len = unpack_pjob(tmp_ctx, old_data.dptr, 810 old_data.dsize, &old_pjob); 811 if (len != -1 ) { 812 pjob_store_notify(ev, 787 813 msg_ctx, 788 814 sharename, jobid, &old_pjob, 789 815 pjob, 790 816 &changed); 791 talloc_free(old_pjob.devmode);792 793 817 if (changed) { 794 818 add_to_jobs_changed(pdb, jobid); 795 819 } 796 820 } 797 798 } 799 else {821 talloc_free(tmp_ctx); 822 823 } else { 800 824 /* new job */ 801 pjob_store_notify( server_event_context(), msg_ctx,825 pjob_store_notify(ev, msg_ctx, 802 826 sharename, jobid, NULL, pjob, 803 827 &changed); … … 805 829 } 806 830 831 done: 807 832 release_print_db(pdb); 808 done:809 833 SAFE_FREE( old_data.dptr ); 810 834 SAFE_FREE( buf ); … … 825 849 uint32 job_status = 0; 826 850 struct tdb_print_db *pdb; 827 828 pdb = get_print_db_byname( sharename ); 829 830 if (!pdb) 851 TALLOC_CTX *tmp_ctx = talloc_new(ev); 852 if (tmp_ctx == NULL) { 831 853 return; 832 833 pjob = print_job_find( sharename, jobid ); 834 854 } 855 856 pdb = get_print_db_byname(sharename); 857 if (!pdb) { 858 goto err_out; 859 } 860 861 pjob = print_job_find(tmp_ctx, sharename, jobid); 835 862 if (!pjob) { 836 DEBUG(5, ("pjob_delete: we were asked to delete nonexistent job %u\n", 837 (unsigned int)jobid)); 838 release_print_db(pdb); 839 return; 863 DEBUG(5, ("we were asked to delete nonexistent job %u\n", 864 jobid)); 865 goto err_release; 840 866 } 841 867 … … 851 877 tdb_delete(pdb->tdb, print_key(jobid, &tmp)); 852 878 remove_from_jobs_added(sharename, jobid); 853 release_print_db( pdb );854 879 rap_jobid_delete(sharename, jobid); 880 err_release: 881 release_print_db(pdb); 882 err_out: 883 talloc_free(tmp_ctx); 855 884 } 856 885 … … 865 894 { 866 895 struct printjob pj, *old_pj; 867 868 if (jobid == (uint32)-1) 869 jobid = q->job + UNIX_JOB_START; 896 TALLOC_CTX *tmp_ctx = talloc_new(ev); 897 if (tmp_ctx == NULL) { 898 return; 899 } 900 901 if (jobid == (uint32)-1) { 902 jobid = q->sysjob + UNIX_JOB_START; 903 } 870 904 871 905 /* Preserve the timestamp on an existing unix print job */ 872 906 873 old_pj = print_job_find( sharename, jobid);907 old_pj = print_job_find(tmp_ctx, sharename, jobid); 874 908 875 909 ZERO_STRUCT(pj); 876 910 877 911 pj.pid = (pid_t)-1; 878 pj.sysjob = q->job; 912 pj.jobid = jobid; 913 pj.sysjob = q->sysjob; 879 914 pj.fd = -1; 880 915 pj.starttime = old_pj ? old_pj->starttime : q->time; … … 894 929 895 930 pjob_store(ev, msg_ctx, sharename, jobid, &pj); 931 talloc_free(tmp_ctx); 896 932 } 897 933 … … 906 942 struct tevent_context *ev; 907 943 struct messaging_context *msg_ctx; 944 TALLOC_CTX *mem_ctx; 908 945 }; 909 946 … … 922 959 return 0; 923 960 924 jobid = IVAL(key.dptr, 0); 925 if ( unpack_pjob( data.dptr, data.dsize, &pjob ) == -1 ) 961 if (unpack_pjob(ts->mem_ctx, data.dptr, data.dsize, &pjob) == -1) 926 962 return 0; 927 963 talloc_free(pjob.devmode); 928 964 jobid = pjob.jobid; 929 965 930 966 if (!pjob.smbjob) { 931 967 /* remove a unix job if it isn't in the system queue any more */ 932 933 968 for (i=0;i<ts->qcount;i++) { 934 uint32 u_jobid = (ts->queue[i].job + UNIX_JOB_START); 935 if (jobid == u_jobid) 969 if (ts->queue[i].sysjob == pjob.sysjob) { 936 970 break; 971 } 937 972 } 938 973 if (i == ts->qcount) { … … 965 1000 /* this check only makes sense for jobs submitted from Windows clients */ 966 1001 967 if ( pjob.smbjob) {1002 if (pjob.smbjob) { 968 1003 for (i=0;i<ts->qcount;i++) { 969 uint32 curr_jobid;970 971 1004 if ( pjob.status == LPQ_DELETED ) 972 1005 continue; 973 1006 974 curr_jobid = print_parse_jobid(ts->queue[i].fs_file); 975 976 if (jobid == curr_jobid) { 1007 if (ts->queue[i].sysjob == pjob.sysjob) { 977 1008 978 1009 /* try to clean up any jobs that need to be deleted */ … … 1029 1060 } 1030 1061 1031 /* Save the pjob attributes we will store. 1032 FIXME!!! This is the only place where queue->job 1033 represents the SMB jobid --jerry */ 1034 1035 ts->queue[i].job = jobid; 1062 /* Save the pjob attributes we will store. */ 1063 ts->queue[i].sysjob = pjob.sysjob; 1036 1064 ts->queue[i].size = pjob.size; 1037 1065 ts->queue[i].page_count = pjob.page_count; … … 1184 1212 qcount++; 1185 1213 data.dsize += tdb_pack(NULL, 0, "ddddddff", 1186 (uint32)queue[i]. job,1214 (uint32)queue[i].sysjob, 1187 1215 (uint32)queue[i].size, 1188 1216 (uint32)queue[i].page_count, … … 1204 1232 1205 1233 len += tdb_pack(data.dptr + len, data.dsize - len, "ddddddff", 1206 (uint32)queue[i]. job,1234 (uint32)queue[i].sysjob, 1207 1235 (uint32)queue[i].size, 1208 1236 (uint32)queue[i].page_count, … … 1318 1346 ****************************************************************************/ 1319 1347 1320 static void print_queue_update_internal( 1321 1322 1323 1324 char *lpq_command, char *lprm_command)1348 static void print_queue_update_internal(struct tevent_context *ev, 1349 struct messaging_context *msg_ctx, 1350 const char *sharename, 1351 struct printif *current_printif, 1352 char *lpq_command, char *lprm_command) 1325 1353 { 1326 1354 int i, qcount; … … 1334 1362 fstring keystr, cachestr; 1335 1363 struct tdb_print_db *pdb = get_print_db_byname(sharename); 1336 1337 if (!pdb) { 1364 TALLOC_CTX *tmp_ctx = talloc_new(ev); 1365 1366 if ((pdb == NULL) || (tmp_ctx == NULL)) { 1338 1367 return; 1339 1368 } … … 1376 1405 fill in any system job numbers as we go 1377 1406 */ 1378 1379 1407 jcdata = get_jobs_added_data(pdb); 1380 1408 1381 1409 for (i=0; i<qcount; i++) { 1382 uint32 jobid = print_parse_jobid(queue[i].fs_file); 1383 1410 uint32 jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob); 1384 1411 if (jobid == (uint32)-1) { 1385 1412 /* assume its a unix print job */ … … 1390 1417 1391 1418 /* we have an active SMB print job - update its status */ 1392 pjob = print_job_find( sharename, jobid);1419 pjob = print_job_find(tmp_ctx, sharename, jobid); 1393 1420 if (!pjob) { 1394 1421 /* err, somethings wrong. Probably smbd was restarted 1395 1422 with jobs in the queue. All we can do is treat them 1396 1423 like unix jobs. Pity. */ 1424 DEBUG(1, ("queued print job %d not found in jobs list, " 1425 "assuming unix job\n", jobid)); 1397 1426 print_unix_job(ev, msg_ctx, 1398 1427 sharename, &queue[i], jobid); 1399 1428 continue; 1400 1429 } 1401 1402 pjob->sysjob = queue[i].job;1403 1430 1404 1431 /* don't reset the status on jobs to be deleted */ … … 1426 1453 tstruct.ev = ev; 1427 1454 tstruct.msg_ctx = msg_ctx; 1455 tstruct.mem_ctx = tmp_ctx; 1428 1456 1429 1457 tdb_traverse(pdb->tdb, traverse_fn_delete, (void *)&tstruct); … … 1433 1461 1434 1462 SAFE_FREE(tstruct.queue); 1463 talloc_free(tmp_ctx); 1435 1464 1436 1465 DEBUG(10,("print_queue_update_internal: printer %s INFO/total_jobs = %d\n", … … 1628 1657 } 1629 1658 1659 static bool printer_housekeeping_fn(const struct timeval *now, 1660 void *private_data) 1661 { 1662 static time_t last_pcap_reload_time = 0; 1663 time_t printcap_cache_time = (time_t)lp_printcap_cache_time(); 1664 time_t t = time_mono(NULL); 1665 1666 DEBUG(5, ("printer housekeeping\n")); 1667 1668 /* if periodic printcap rescan is enabled, see if it's time to reload */ 1669 if ((printcap_cache_time != 0) 1670 && (t >= (last_pcap_reload_time + printcap_cache_time))) { 1671 DEBUG( 3,( "Printcap cache time expired.\n")); 1672 pcap_cache_reload(server_event_context(), 1673 smbd_messaging_context(), 1674 &reload_pcap_change_notify); 1675 last_pcap_reload_time = t; 1676 } 1677 1678 return true; 1679 } 1680 1630 1681 static pid_t background_lpq_updater_pid = -1; 1631 1682 … … 1699 1750 DEBUG(0,("tevent_add_fd() failed for pause_pipe\n")); 1700 1751 smb_panic("tevent_add_fd() failed for pause_pipe"); 1752 } 1753 1754 if (!(event_add_idle(ev, NULL, 1755 timeval_set(SMBD_HOUSEKEEPING_INTERVAL, 0), 1756 "printer_housekeeping", 1757 printer_housekeeping_fn, 1758 NULL))) { 1759 DEBUG(0, ("Could not add printing housekeeping event\n")); 1760 exit(1); 1701 1761 } 1702 1762 … … 2045 2105 2046 2106 /**************************************************************************** 2047 Give the filename used for a jobid.2107 Return the device mode asigned to a specific print job. 2048 2108 Only valid for the process doing the spooling and when the job 2049 2109 has not been spooled. 2050 2110 ****************************************************************************/ 2051 2111 2052 char *print_job_fname(const char* sharename, uint32 jobid) 2053 { 2054 struct printjob *pjob = print_job_find(sharename, jobid); 2055 if (!pjob || pjob->spooled || pjob->pid != sys_getpid()) 2112 struct spoolss_DeviceMode *print_job_devmode(TALLOC_CTX *mem_ctx, 2113 const char *sharename, 2114 uint32 jobid) 2115 { 2116 struct printjob *pjob = print_job_find(mem_ctx, sharename, jobid); 2117 if (pjob == NULL) { 2056 2118 return NULL; 2057 return pjob->filename; 2058 } 2059 2060 2061 /**************************************************************************** 2062 Give the filename used for a jobid. 2063 Only valid for the process doing the spooling and when the job 2064 has not been spooled. 2065 ****************************************************************************/ 2066 2067 struct spoolss_DeviceMode *print_job_devmode(const char* sharename, uint32 jobid) 2068 { 2069 struct printjob *pjob = print_job_find(sharename, jobid); 2070 2071 if ( !pjob ) 2072 return NULL; 2119 } 2073 2120 2074 2121 return pjob->devmode; … … 2084 2131 { 2085 2132 struct printjob *pjob; 2086 2087 pjob = print_job_find(sharename, jobid); 2088 if (!pjob || pjob->pid != sys_getpid()) 2089 return False; 2133 bool ret; 2134 TALLOC_CTX *tmp_ctx = talloc_new(ev); 2135 if (tmp_ctx == NULL) { 2136 return false; 2137 } 2138 2139 pjob = print_job_find(tmp_ctx, sharename, jobid); 2140 if (!pjob || pjob->pid != sys_getpid()) { 2141 ret = false; 2142 goto err_out; 2143 } 2090 2144 2091 2145 fstrcpy(pjob->jobname, name); 2092 return pjob_store(ev, msg_ctx, sharename, jobid, pjob); 2146 ret = pjob_store(ev, msg_ctx, sharename, jobid, pjob); 2147 err_out: 2148 talloc_free(tmp_ctx); 2149 return ret; 2093 2150 } 2094 2151 … … 2101 2158 struct printjob *pjob; 2102 2159 2103 pjob = print_job_find( sharename, jobid);2160 pjob = print_job_find(mem_ctx, sharename, jobid); 2104 2161 if (!pjob || pjob->pid != sys_getpid()) { 2105 2162 return false; 2106 2163 } 2107 2164 2108 *name = talloc_strdup(mem_ctx, pjob->jobname); 2109 if (!*name) { 2110 return false; 2111 } 2112 2165 *name = pjob->jobname; 2113 2166 return true; 2114 2167 } … … 2183 2236 { 2184 2237 const char* sharename = lp_const_servicename(snum); 2185 struct printjob *pjob = print_job_find(sharename, jobid);2238 struct printjob *pjob; 2186 2239 int result = 0; 2187 2240 struct printif *current_printif = get_printer_fns( snum ); 2188 2189 if (!pjob) 2190 return False; 2241 bool ret; 2242 TALLOC_CTX *tmp_ctx = talloc_new(ev); 2243 if (tmp_ctx == NULL) { 2244 return false; 2245 } 2246 2247 pjob = print_job_find(tmp_ctx, sharename, jobid); 2248 if (!pjob) { 2249 ret = false; 2250 goto err_out; 2251 } 2191 2252 2192 2253 /* … … 2194 2255 */ 2195 2256 2196 if (pjob->status == LPQ_DELETING) 2197 return True; 2257 if (pjob->status == LPQ_DELETING) { 2258 ret = true; 2259 goto err_out; 2260 } 2198 2261 2199 2262 /* Hrm - we need to be able to cope with deleting a job before it … … 2225 2288 int njobs = 1; 2226 2289 2227 if (!pdb) 2228 return False; 2290 if (!pdb) { 2291 ret = false; 2292 goto err_out; 2293 } 2229 2294 pjob_delete(ev, msg_ctx, sharename, jobid); 2230 2295 /* Ensure we keep a rough count of the number of total jobs... */ … … 2236 2301 remove_from_jobs_added( sharename, jobid ); 2237 2302 2238 return (result == 0); 2303 ret = (result == 0); 2304 err_out: 2305 talloc_free(tmp_ctx); 2306 return ret; 2239 2307 } 2240 2308 … … 2247 2315 uint32 jobid) 2248 2316 { 2249 struct printjob *pjob = print_job_find(servicename, jobid); 2250 2251 if (!pjob || !server_info) 2252 return False; 2253 2254 return strequal(pjob->user, server_info->sanitized_username); 2317 struct printjob *pjob; 2318 bool ret; 2319 TALLOC_CTX *tmp_ctx = talloc_new(server_info); 2320 if (tmp_ctx == NULL) { 2321 return false; 2322 } 2323 2324 pjob = print_job_find(tmp_ctx, servicename, jobid); 2325 if (!pjob || !server_info) { 2326 ret = false; 2327 goto err_out; 2328 } 2329 2330 ret = strequal(pjob->user, server_info->sanitized_username); 2331 err_out: 2332 talloc_free(tmp_ctx); 2333 return ret; 2255 2334 } 2256 2335 … … 2266 2345 struct printjob *pjob; 2267 2346 bool owner; 2268 char *fname; 2347 WERROR werr; 2348 TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx); 2349 if (tmp_ctx == NULL) { 2350 return WERR_NOT_ENOUGH_MEMORY; 2351 } 2269 2352 2270 2353 owner = is_owner(server_info, lp_const_servicename(snum), jobid); … … 2286 2369 /* END_ADMIN_LOG */ 2287 2370 2288 return WERR_ACCESS_DENIED; 2371 werr = WERR_ACCESS_DENIED; 2372 goto err_out; 2289 2373 } 2290 2374 … … 2296 2380 */ 2297 2381 2298 fname = print_job_fname(sharename, jobid); 2299 if (fname != NULL) { 2300 /* remove the spool file */ 2301 DEBUG(10, ("print_job_delete: " 2302 "Removing spool file [%s]\n", fname)); 2303 if (unlink(fname) == -1) { 2304 return map_werror_from_unix(errno); 2382 pjob = print_job_find(tmp_ctx, sharename, jobid); 2383 if (!pjob || pjob->spooled || pjob->pid != getpid()) { 2384 DEBUG(10, ("Skipping spool file removal for job %u\n", jobid)); 2385 } else { 2386 DEBUG(10, ("Removing spool file [%s]\n", pjob->filename)); 2387 if (unlink(pjob->filename) == -1) { 2388 werr = map_werror_from_unix(errno); 2389 goto err_out; 2305 2390 } 2306 2391 } 2307 2392 2308 2393 if (!print_job_delete1(server_event_context(), msg_ctx, snum, jobid)) { 2309 return WERR_ACCESS_DENIED; 2394 werr = WERR_ACCESS_DENIED; 2395 goto err_out; 2310 2396 } 2311 2397 … … 2315 2401 print_queue_update(msg_ctx, snum, True); 2316 2402 2317 pjob = print_job_find( sharename, jobid);2403 pjob = print_job_find(tmp_ctx, sharename, jobid); 2318 2404 if (pjob && (pjob->status != LPQ_DELETING)) { 2319 return WERR_ACCESS_DENIED; 2320 } 2321 2322 return WERR_PRINTER_HAS_JOBS_QUEUED; 2405 werr = WERR_ACCESS_DENIED; 2406 goto err_out; 2407 } 2408 werr = WERR_PRINTER_HAS_JOBS_QUEUED; 2409 2410 err_out: 2411 talloc_free(tmp_ctx); 2412 return werr; 2323 2413 } 2324 2414 … … 2327 2417 ****************************************************************************/ 2328 2418 2329 boolprint_job_pause(const struct auth_serversupplied_info *server_info,2419 WERROR print_job_pause(const struct auth_serversupplied_info *server_info, 2330 2420 struct messaging_context *msg_ctx, 2331 int snum, uint32 jobid , WERROR *errcode)2421 int snum, uint32 jobid) 2332 2422 { 2333 2423 const char* sharename = lp_const_servicename(snum); … … 2335 2425 int ret = -1; 2336 2426 struct printif *current_printif = get_printer_fns( snum ); 2337 2338 pjob = print_job_find(sharename, jobid); 2339 2427 WERROR werr; 2428 TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx); 2429 if (tmp_ctx == NULL) { 2430 return WERR_NOT_ENOUGH_MEMORY; 2431 } 2432 2433 pjob = print_job_find(tmp_ctx, sharename, jobid); 2340 2434 if (!pjob || !server_info) { 2341 2435 DEBUG(10, ("print_job_pause: no pjob or user for jobid %u\n", 2342 2436 (unsigned int)jobid )); 2343 return False; 2437 werr = WERR_INVALID_PARAM; 2438 goto err_out; 2344 2439 } 2345 2440 … … 2347 2442 DEBUG(10, ("print_job_pause: not spooled or bad sysjob = %d for jobid %u\n", 2348 2443 (int)pjob->sysjob, (unsigned int)jobid )); 2349 return False; 2444 werr = WERR_INVALID_PARAM; 2445 goto err_out; 2350 2446 } 2351 2447 … … 2363 2459 /* END_ADMIN_LOG */ 2364 2460 2365 *errcode= WERR_ACCESS_DENIED;2366 return False;2461 werr = WERR_ACCESS_DENIED; 2462 goto err_out; 2367 2463 } 2368 2464 … … 2371 2467 2372 2468 if (ret != 0) { 2373 *errcode= WERR_INVALID_PARAM;2374 return False;2469 werr = WERR_INVALID_PARAM; 2470 goto err_out; 2375 2471 } 2376 2472 … … 2384 2480 2385 2481 /* how do we tell if this succeeded? */ 2386 2387 return True; 2482 werr = WERR_OK; 2483 err_out: 2484 talloc_free(tmp_ctx); 2485 return werr; 2388 2486 } 2389 2487 … … 2392 2490 ****************************************************************************/ 2393 2491 2394 boolprint_job_resume(const struct auth_serversupplied_info *server_info,2492 WERROR print_job_resume(const struct auth_serversupplied_info *server_info, 2395 2493 struct messaging_context *msg_ctx, 2396 int snum, uint32 jobid , WERROR *errcode)2494 int snum, uint32 jobid) 2397 2495 { 2398 2496 const char *sharename = lp_const_servicename(snum); … … 2400 2498 int ret; 2401 2499 struct printif *current_printif = get_printer_fns( snum ); 2402 2403 pjob = print_job_find(sharename, jobid); 2404 2500 WERROR werr; 2501 TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx); 2502 if (tmp_ctx == NULL) 2503 return WERR_NOT_ENOUGH_MEMORY; 2504 2505 pjob = print_job_find(tmp_ctx, sharename, jobid); 2405 2506 if (!pjob || !server_info) { 2406 2507 DEBUG(10, ("print_job_resume: no pjob or user for jobid %u\n", 2407 2508 (unsigned int)jobid )); 2408 return False; 2509 werr = WERR_INVALID_PARAM; 2510 goto err_out; 2409 2511 } 2410 2512 … … 2412 2514 DEBUG(10, ("print_job_resume: not spooled or bad sysjob = %d for jobid %u\n", 2413 2515 (int)pjob->sysjob, (unsigned int)jobid )); 2414 return False; 2516 werr = WERR_INVALID_PARAM; 2517 goto err_out; 2415 2518 } 2416 2519 … … 2419 2522 JOB_ACCESS_ADMINISTER)) { 2420 2523 DEBUG(3, ("resume denied by security descriptor\n")); 2421 *errcode = WERR_ACCESS_DENIED;2422 2524 2423 2525 /* BEGIN_ADMIN_LOG */ … … 2428 2530 lp_printername(snum) ); 2429 2531 /* END_ADMIN_LOG */ 2430 return False; 2532 werr = WERR_ACCESS_DENIED; 2533 goto err_out; 2431 2534 } 2432 2535 … … 2434 2537 2435 2538 if (ret != 0) { 2436 *errcode= WERR_INVALID_PARAM;2437 return False;2539 werr = WERR_INVALID_PARAM; 2540 goto err_out; 2438 2541 } 2439 2542 … … 2446 2549 JOB_STATUS_QUEUED); 2447 2550 2448 return True; 2551 werr = WERR_OK; 2552 err_out: 2553 talloc_free(tmp_ctx); 2554 return werr; 2449 2555 } 2450 2556 … … 2460 2566 ssize_t return_code; 2461 2567 struct printjob *pjob; 2462 2463 pjob = print_job_find(sharename, jobid); 2464 2465 if (!pjob) 2568 TALLOC_CTX *tmp_ctx = talloc_new(ev); 2569 if (tmp_ctx == NULL) { 2466 2570 return -1; 2571 } 2572 2573 pjob = print_job_find(tmp_ctx, sharename, jobid); 2574 if (!pjob) { 2575 return_code = -1; 2576 goto err_out; 2577 } 2578 2467 2579 /* don't allow another process to get this info - it is meaningless */ 2468 if (pjob->pid != sys_getpid()) 2469 return -1; 2580 if (pjob->pid != sys_getpid()) { 2581 return_code = -1; 2582 goto err_out; 2583 } 2470 2584 2471 2585 /* if SMBD is spooling this can't be allowed */ 2472 2586 if (pjob->status == PJOB_SMBD_SPOOLING) { 2473 return -1; 2587 return_code = -1; 2588 goto err_out; 2474 2589 } 2475 2590 2476 2591 return_code = write_data(pjob->fd, buf, size); 2477 2478 if (return_code>0) { 2592 if (return_code > 0) { 2479 2593 pjob->size += size; 2480 2594 pjob_store(ev, msg_ctx, sharename, jobid, pjob); 2481 2595 } 2596 err_out: 2597 talloc_free(tmp_ctx); 2482 2598 return return_code; 2483 2599 } … … 2759 2875 2760 2876 slprintf(pjob->filename, sizeof(pjob->filename)-1, 2761 "%s/%s%.8u.XXXXXX", lp_pathname(snum), 2762 PRINT_SPOOL_PREFIX, (unsigned int)jobid); 2877 "%s/%sXXXXXX", lp_pathname(snum), PRINT_SPOOL_PREFIX); 2763 2878 pjob->fd = mkstemp(pjob->filename); 2764 2879 … … 2826 2941 2827 2942 pjob.pid = sys_getpid(); 2943 pjob.jobid = jobid; 2828 2944 pjob.sysjob = -1; 2829 2945 pjob.fd = -1; … … 2890 3006 const char* sharename = lp_const_servicename(snum); 2891 3007 struct printjob *pjob; 2892 2893 pjob = print_job_find(sharename, jobid); 2894 if (!pjob) 3008 TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx); 3009 if (tmp_ctx == NULL) { 2895 3010 return; 3011 } 3012 3013 pjob = print_job_find(tmp_ctx, sharename, jobid); 3014 if (!pjob) { 3015 goto err_out; 3016 } 2896 3017 /* don't allow another process to get this info - it is meaningless */ 2897 if (pjob->pid != sys_getpid()) 2898 return; 3018 if (pjob->pid != sys_getpid()) { 3019 goto err_out; 3020 } 2899 3021 2900 3022 pjob->page_count++; 2901 3023 pjob_store(server_event_context(), msg_ctx, sharename, jobid, pjob); 3024 err_out: 3025 talloc_free(tmp_ctx); 2902 3026 } 2903 3027 … … 2915 3039 int ret; 2916 3040 SMB_STRUCT_STAT sbuf; 2917 struct printif *current_printif = get_printer_fns( snum);3041 struct printif *current_printif = get_printer_fns(snum); 2918 3042 NTSTATUS status = NT_STATUS_UNSUCCESSFUL; 2919 2920 pjob = print_job_find(sharename, jobid); 2921 3043 char *lpq_cmd; 3044 TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx); 3045 if (tmp_ctx == NULL) { 3046 return NT_STATUS_NO_MEMORY; 3047 } 3048 3049 pjob = print_job_find(tmp_ctx, sharename, jobid); 2922 3050 if (!pjob) { 2923 return NT_STATUS_PRINT_CANCELLED; 3051 status = NT_STATUS_PRINT_CANCELLED; 3052 goto err_out; 2924 3053 } 2925 3054 2926 3055 if (pjob->spooled || pjob->pid != sys_getpid()) { 2927 return NT_STATUS_ACCESS_DENIED; 3056 status = NT_STATUS_ACCESS_DENIED; 3057 goto err_out; 2928 3058 } 2929 3059 … … 2979 3109 } 2980 3110 2981 ret = (*(current_printif->job_submit))(snum, pjob); 2982 3111 /* don't strip out characters like '$' from the printername */ 3112 lpq_cmd = talloc_string_sub2(tmp_ctx, 3113 lp_lpqcommand(snum), 3114 "%p", 3115 lp_printername(snum), 3116 false, false, false); 3117 if (lpq_cmd == NULL) { 3118 status = NT_STATUS_PRINT_CANCELLED; 3119 goto fail; 3120 } 3121 lpq_cmd = talloc_sub_advanced(tmp_ctx, 3122 lp_servicename(snum), 3123 current_user_info.unix_name, 3124 "", 3125 current_user.ut.gid, 3126 get_current_username(), 3127 current_user_info.domain, 3128 lpq_cmd); 3129 if (lpq_cmd == NULL) { 3130 status = NT_STATUS_PRINT_CANCELLED; 3131 goto fail; 3132 } 3133 3134 ret = (*(current_printif->job_submit))(snum, pjob, 3135 current_printif->type, lpq_cmd); 2983 3136 if (ret) { 2984 3137 status = NT_STATUS_PRINT_CANCELLED; … … 3005 3158 unlink(pjob->filename); 3006 3159 pjob_delete(server_event_context(), msg_ctx, sharename, jobid); 3160 err_out: 3161 talloc_free(tmp_ctx); 3007 3162 return status; 3008 3163 } … … 3027 3182 bool ret = False; 3028 3183 const char* sharename = lp_servicename(snum); 3184 TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx); 3185 if (tmp_ctx == NULL) { 3186 return false; 3187 } 3029 3188 3030 3189 /* make sure the database is up to date */ … … 3076 3235 queue[i].fs_user, 3077 3236 queue[i].fs_file); 3078 queue[i]. job = qjob;3237 queue[i].sysjob = qjob; 3079 3238 queue[i].size = qsize; 3080 3239 queue[i].page_count = qpage_count; … … 3093 3252 jobid = IVAL(cgdata.dptr, i*4); 3094 3253 DEBUG(5,("get_stored_queue_info: added job = %u\n", (unsigned int)jobid)); 3095 pjob = print_job_find( lp_const_servicename(snum), jobid);3254 pjob = print_job_find(tmp_ctx, lp_const_servicename(snum), jobid); 3096 3255 if (!pjob) { 3097 3256 DEBUG(5,("get_stored_queue_info: failed to find added job = %u\n", (unsigned int)jobid)); … … 3100 3259 } 3101 3260 3102 queue[total_count]. job = jobid;3261 queue[total_count].sysjob = jobid; 3103 3262 queue[total_count].size = pjob->size; 3104 3263 queue[total_count].page_count = pjob->page_count; … … 3109 3268 fstrcpy(queue[total_count].fs_file, pjob->jobname); 3110 3269 total_count++; 3270 talloc_free(pjob); 3111 3271 } 3112 3272 … … 3118 3278 3119 3279 for (j = 0; j < total_count; j++) { 3120 if (queue[j]. job == jobid) {3280 if (queue[j].sysjob == jobid) { 3121 3281 found = true; 3122 3282 break; … … 3130 3290 (unsigned int) jobid)); 3131 3291 3132 pjob = print_job_find( sharename, jobid);3292 pjob = print_job_find(tmp_ctx, sharename, jobid); 3133 3293 if (pjob == NULL) { 3134 3294 DEBUG(5,("get_stored_queue_info: failed to find " … … 3139 3299 } 3140 3300 3141 queue[j]. job = jobid;3301 queue[j].sysjob = jobid; 3142 3302 queue[j].size = pjob->size; 3143 3303 queue[j].page_count = pjob->page_count; … … 3147 3307 fstrcpy(queue[j].fs_user, pjob->user); 3148 3308 fstrcpy(queue[j].fs_file, pjob->jobname); 3309 talloc_free(pjob); 3149 3310 3150 3311 DEBUG(5,("get_stored_queue_info: updated queue[%u], jobid: %u, jobname: %s\n", … … 3174 3335 SAFE_FREE(data.dptr); 3175 3336 SAFE_FREE(cgdata.dptr); 3337 talloc_free(tmp_ctx); 3176 3338 return ret; 3177 3339 } … … 3341 3503 for (i=0;i<njobs;i++) { 3342 3504 bool owner = is_owner(server_info, lp_const_servicename(snum), 3343 queue[i]. job);3505 queue[i].sysjob); 3344 3506 3345 3507 if (owner || can_job_admin) { 3346 3508 print_job_delete1(server_event_context(), msg_ctx, 3347 snum, queue[i]. job);3509 snum, queue[i].sysjob); 3348 3510 } 3349 3511 } -
vendor/current/source3/printing/printspoolss.c
r740 r746 83 83 } 84 84 85 /* Ok, now we have to open an actual file. 85 /* 86 * Ok, now we have to open an actual file. 86 87 * Here is the reason: 87 88 * We want to write the spool job to this file in … … 93 94 * take over once we call EndDocPrinter(). 94 95 * 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", 98 103 lp_pathname(SNUM(fsp->conn)), 99 104 PRINT_SPOOL_PREFIX); … … 140 145 status = dcerpc_spoolss_OpenPrinter(b, pf, pf->svcname, 141 146 "RAW", devmode_ctr, 142 SEC_FLAG_MAXIMUM_ALLOWED,147 PRINTER_ACCESS_USE, 143 148 &pf->handle, &werr); 144 149 if (!NT_STATUS_IS_OK(status)) { -
vendor/current/source3/printing/tests/vlp.c
r740 r746 238 238 slprintf(job.jobname, sizeof(job.jobname) - 1, "%s", argv[2]); 239 239 240 if (!(pw = getpwuid(getuid()))) { 240 if (!(pw = getpwuid(geteuid()))) { 241 printf("getpwuid failed\n"); 241 242 return 1; 242 243 }
Note:
See TracChangeset
for help on using the changeset viewer.