Changeset 751 for trunk/server/source3/printing
- Timestamp:
- Nov 29, 2012, 1:59:04 PM (13 years ago)
- Location:
- trunk/server/source3/printing
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/source3/printing/load.c
r745 r751 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; -
trunk/server/source3/printing/lpq_parse.c
r480 r751 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 } -
trunk/server/source3/printing/nt_printing.c
r745 r751 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 } -
trunk/server/source3/printing/nt_printing_migrate.c
r745 r751 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; -
trunk/server/source3/printing/print_cups.c
r745 r751 36 36 #endif 37 37 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 50 static ipp_attribute_t * 51 ippFirstAttribute(ipp_t *ipp) 52 { 53 if (!ipp) 54 return (NULL); 55 return (ipp->current = ipp->attrs); 56 } 57 58 static ipp_attribute_t * 59 ippNextAttribute(ipp_t *ipp) 60 { 61 if (!ipp || !ipp->current) 62 return (NULL); 63 return (ipp->current = ipp->current->next); 64 } 65 66 static int ippSetOperation(ipp_t *ipp, ipp_op_t op) 67 { 68 ipp->request.op.operation_id = op; 69 return (1); 70 } 71 72 static int ippSetRequestId(ipp_t *ipp, int request_id) 73 { 74 ipp->request.any.request_id = request_id; 75 return (1); 76 } 77 #endif 78 38 79 static SIG_ATOMIC_T gotalarm; 39 80 … … 172 213 bool ret_ok = false; 173 214 174 for (attr = response->attrs; attr != NULL;) {215 for (attr = ippFirstAttribute(response); attr != NULL;) { 175 216 /* 176 217 * Skip leading attributes until we hit a printer... 177 218 */ 178 219 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); 181 222 182 223 if (attr == NULL) … … 190 231 info = NULL; 191 232 192 while (attr != NULL && attr->group_tag== IPP_TAG_PRINTER) {233 while (attr != NULL && ippGetGroupTag(attr) == IPP_TAG_PRINTER) { 193 234 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) { 196 237 if (!pull_utf8_talloc(mem_ctx, 197 238 &name, 198 attr->values[0].string.text,239 ippGetString(attr, 0, NULL), 199 240 &size)) { 200 241 goto err_out; … … 202 243 } 203 244 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) { 206 247 if (!pull_utf8_talloc(mem_ctx, 207 248 &info, 208 attr->values[0].string.text,249 ippGetString(attr, 0, NULL), 209 250 &size)) { 210 251 goto err_out; … … 212 253 } 213 254 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) { 216 257 if (!pull_utf8_talloc(mem_ctx, 217 258 &location, 218 attr->values[0].string.text,259 ippGetString(attr, 0, NULL), 219 260 &size)) { 220 261 goto err_out; … … 222 263 } 223 264 224 attr = attr->next;265 attr = ippNextAttribute(response); 225 266 } 226 267 … … 302 343 request = ippNew(); 303 344 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); 306 347 307 348 language = cupsLangDefault(); … … 344 385 request = ippNew(); 345 386 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); 348 389 349 390 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, … … 608 649 request = ippNew(); 609 650 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); 612 653 613 654 language = cupsLangDefault(); … … 635 676 636 677 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) { 637 if ( response->request.status.status_code>= IPP_OK_CONFLICT) {678 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 638 679 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob, 639 680 ippErrorString(cupsLastError()))); … … 705 746 request = ippNew(); 706 747 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); 709 750 710 751 language = cupsLangDefault(); … … 731 772 732 773 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) { 733 if ( response->request.status.status_code>= IPP_OK_CONFLICT) {774 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 734 775 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob, 735 776 ippErrorString(cupsLastError()))); … … 801 842 request = ippNew(); 802 843 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); 805 846 806 847 language = cupsLangDefault(); … … 827 868 828 869 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) { 829 if ( response->request.status.status_code>= IPP_OK_CONFLICT) {870 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 830 871 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob, 831 872 ippErrorString(cupsLastError()))); … … 857 898 */ 858 899 859 static int cups_job_submit(int snum, struct printjob *pjob) 900 static int cups_job_submit(int snum, struct printjob *pjob, 901 enum printing_types printing_type, 902 char *lpq_cmd) 860 903 { 861 904 TALLOC_CTX *frame = talloc_stackframe(); … … 876 919 char *filename = NULL; 877 920 size_t size; 878 uint32_t jobid = (uint32_t)-1;879 921 880 922 DEBUG(5,("cups_job_submit(%d, %p)\n", snum, pjob)); … … 907 949 request = ippNew(); 908 950 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); 911 953 912 954 language = cupsLangDefault(); … … 938 980 pjob->clientmachine); 939 981 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 948 982 if (!push_utf8_talloc(frame, &jobname, pjob->jobname, &size)) { 949 983 goto out; … … 951 985 new_jobname = talloc_asprintf(frame, 952 986 "%s%.8u %s", PRINT_SPOOL_PREFIX, 953 (unsigned int)jobid, 954 jobname); 987 pjob->jobid, jobname); 955 988 if (new_jobname == NULL) { 956 989 goto out; … … 984 1017 } 985 1018 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) { 987 1020 DEBUG(0,("Unable to print file to %s - %s\n", 988 1021 lp_printername(snum), … … 992 1025 attr_job_id = ippFindAttribute(response, "job-id", IPP_TAG_INTEGER); 993 1026 if(attr_job_id) { 994 pjob->sysjob = attr_job_id->values[0].integer;1027 pjob->sysjob = ippGetInteger(attr_job_id, 0); 995 1028 DEBUG(5,("cups_job_submit: job-id %d\n", pjob->sysjob)); 996 1029 } else { … … 1114 1147 request = ippNew(); 1115 1148 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); 1118 1151 1119 1152 language = cupsLangDefault(); … … 1143 1176 } 1144 1177 1145 if ( response->request.status.status_code>= IPP_OK_CONFLICT) {1178 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 1146 1179 DEBUG(0,("Unable to get jobs for %s - %s\n", uri, 1147 ippErrorString( response->request.status.status_code)));1180 ippErrorString(ippGetStatusCode(response)))); 1148 1181 goto out; 1149 1182 } … … 1157 1190 queue = NULL; 1158 1191 1159 for (attr = response->attrs; attr != NULL; attr = attr->next) {1192 for (attr = ippFirstAttribute(response); attr != NULL; attr = ippNextAttribute(response)) { 1160 1193 /* 1161 1194 * Skip leading attributes until we hit a job... 1162 1195 */ 1163 1196 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); 1166 1199 1167 1200 if (attr == NULL) … … 1198 1231 job_name = NULL; 1199 1232 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); 1203 1236 break; 1204 1237 } 1205 1238 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) { 1228 1261 if (!pull_utf8_talloc(frame, 1229 1262 &job_name, 1230 attr->values[0].string.text,1263 ippGetString(attr, 0, NULL), 1231 1264 &size)) { 1232 1265 goto out; … … 1234 1267 } 1235 1268 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) { 1238 1271 if (!pull_utf8_talloc(frame, 1239 1272 &user_name, 1240 attr->values[0].string.text,1273 ippGetString(attr, 0, NULL), 1241 1274 &size)) { 1242 1275 goto out; … … 1244 1277 } 1245 1278 1246 attr = attr->next;1279 attr = ippNextAttribute(response); 1247 1280 } 1248 1281 … … 1258 1291 } 1259 1292 1260 temp-> job= job_id;1293 temp->sysjob = job_id; 1261 1294 temp->size = job_k_octets * 1024; 1262 1295 temp->status = job_status == IPP_JOB_PENDING ? LPQ_QUEUED : … … 1290 1323 request = ippNew(); 1291 1324 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); 1294 1327 1295 1328 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, … … 1317 1350 } 1318 1351 1319 if ( response->request.status.status_code>= IPP_OK_CONFLICT) {1352 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 1320 1353 DEBUG(0,("Unable to get printer status for %s - %s\n", printername, 1321 ippErrorString( response->request.status.status_code)));1354 ippErrorString(ippGetStatusCode(response)))); 1322 1355 goto out; 1323 1356 } … … 1328 1361 1329 1362 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) 1331 1364 status->status = LPSTAT_STOPPED; 1332 1365 else … … 1338 1371 char *msg = NULL; 1339 1372 if (!pull_utf8_talloc(frame, &msg, 1340 attr->values[0].string.text,1373 ippGetString(attr, 0, NULL), 1341 1374 &size)) { 1342 1375 SAFE_FREE(queue); … … 1414 1447 request = ippNew(); 1415 1448 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); 1418 1451 1419 1452 language = cupsLangDefault(); … … 1445 1478 1446 1479 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) { 1447 if ( response->request.status.status_code>= IPP_OK_CONFLICT) {1480 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 1448 1481 DEBUG(0,("Unable to pause printer %s - %s\n", 1449 1482 lp_printername(snum), … … 1518 1551 request = ippNew(); 1519 1552 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); 1522 1555 1523 1556 language = cupsLangDefault(); … … 1549 1582 1550 1583 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) { 1551 if ( response->request.status.status_code>= IPP_OK_CONFLICT) {1584 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 1552 1585 DEBUG(0,("Unable to resume printer %s - %s\n", 1553 1586 lp_printername(snum), -
trunk/server/source3/printing/print_generic.c
r745 r751 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 -
trunk/server/source3/printing/print_iprint.c
r745 r751 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 : -
trunk/server/source3/printing/printer_list.c
r745 r751 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); -
trunk/server/source3/printing/printing.c
r745 r751 378 378 ***********************************************************************/ 379 379 380 static int unpack_pjob( uint8 *buf, int buflen, struct printjob *pjob ) 380 static int unpack_pjob(TALLOC_CTX *mem_ctx, uint8 *buf, int buflen, 381 struct printjob *pjob) 381 382 { 382 383 int len = 0; 383 384 int used; 384 uint32 pjpid, pj sysjob, pjfd, pjstarttime, pjstatus;385 uint32 pjpid, pjjobid, pjsysjob, pjfd, pjstarttime, pjstatus; 385 386 uint32 pjsize, pjpage_count, pjspooled, pjsmbjob; 386 387 387 if ( !buf || !pjob )388 if (!buf || !pjob) { 388 389 return -1; 389 390 len += tdb_unpack(buf+len, buflen-len, "dddddddddfffff", 390 } 391 392 len += tdb_unpack(buf+len, buflen-len, "ddddddddddfffff", 391 393 &pjpid, 394 &pjjobid, 392 395 &pjsysjob, 393 396 &pjfd, … … 404 407 pjob->queuename); 405 408 406 if ( len == -1 )409 if (len == -1) { 407 410 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); 410 414 if (used == -1) { 411 415 return -1; … … 415 419 416 420 pjob->pid = pjpid; 421 pjob->jobid = pjjobid; 417 422 pjob->sysjob = pjsysjob; 418 423 pjob->fd = pjfd; … … 432 437 ****************************************************************************/ 433 438 434 static struct printjob *print_job_find(const char *sharename, uint32 jobid) 435 { 436 static struct printjob pjob; 439 static struct printjob *print_job_find(TALLOC_CTX *mem_ctx, 440 const char *sharename, 441 uint32 jobid) 442 { 443 struct printjob *pjob; 437 444 uint32_t tmp; 438 445 TDB_DATA ret; … … 450 457 451 458 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)); 453 461 return NULL; 454 462 } 455 463 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 480 err_out: 466 481 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; 472 483 } 473 484 … … 494 505 495 506 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; 499 508 return 1; 500 509 } 501 510 502 511 return 0; 512 } 513 514 static 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; 503 524 } 504 525 … … 742 763 len = 0; 743 764 buflen = newlen; 744 len += tdb_pack(buf+len, buflen-len, "ddddddddd fffff",765 len += tdb_pack(buf+len, buflen-len, "ddddddddddfffff", 745 766 (uint32)pjob->pid, 767 (uint32)pjob->jobid, 746 768 (uint32)pjob->sysjob, 747 769 (uint32)pjob->fd, … … 780 802 /* Send notify updates for what has changed */ 781 803 782 if ( ret) {804 if (ret) { 783 805 bool changed = false; 784 806 struct printjob old_pjob; 785 807 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, 791 817 msg_ctx, 792 818 sharename, jobid, &old_pjob, 793 819 pjob, 794 820 &changed); 795 talloc_free(old_pjob.devmode);796 797 821 if (changed) { 798 822 add_to_jobs_changed(pdb, jobid); 799 823 } 800 824 } 801 802 } 803 else {825 talloc_free(tmp_ctx); 826 827 } else { 804 828 /* new job */ 805 pjob_store_notify( server_event_context(), msg_ctx,829 pjob_store_notify(ev, msg_ctx, 806 830 sharename, jobid, NULL, pjob, 807 831 &changed); … … 809 833 } 810 834 835 done: 811 836 release_print_db(pdb); 812 done:813 837 SAFE_FREE( old_data.dptr ); 814 838 SAFE_FREE( buf ); … … 829 853 uint32 job_status = 0; 830 854 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) { 835 857 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); 839 866 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; 844 870 } 845 871 … … 855 881 tdb_delete(pdb->tdb, print_key(jobid, &tmp)); 856 882 remove_from_jobs_added(sharename, jobid); 857 release_print_db( pdb );858 883 rap_jobid_delete(sharename, jobid); 884 err_release: 885 release_print_db(pdb); 886 err_out: 887 talloc_free(tmp_ctx); 859 888 } 860 889 … … 869 898 { 870 899 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 } 874 908 875 909 /* Preserve the timestamp on an existing unix print job */ 876 910 877 old_pj = print_job_find( sharename, jobid);911 old_pj = print_job_find(tmp_ctx, sharename, jobid); 878 912 879 913 ZERO_STRUCT(pj); 880 914 881 915 pj.pid = (pid_t)-1; 882 pj.sysjob = q->job; 916 pj.jobid = jobid; 917 pj.sysjob = q->sysjob; 883 918 pj.fd = -1; 884 919 pj.starttime = old_pj ? old_pj->starttime : q->time; … … 898 933 899 934 pjob_store(ev, msg_ctx, sharename, jobid, &pj); 935 talloc_free(tmp_ctx); 900 936 } 901 937 … … 910 946 struct tevent_context *ev; 911 947 struct messaging_context *msg_ctx; 948 TALLOC_CTX *mem_ctx; 912 949 }; 913 950 … … 926 963 return 0; 927 964 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) 930 966 return 0; 931 967 talloc_free(pjob.devmode); 932 968 jobid = pjob.jobid; 933 969 934 970 if (!pjob.smbjob) { 935 971 /* remove a unix job if it isn't in the system queue any more */ 936 937 972 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) { 940 974 break; 975 } 941 976 } 942 977 if (i == ts->qcount) { … … 969 1004 /* this check only makes sense for jobs submitted from Windows clients */ 970 1005 971 if ( pjob.smbjob) {1006 if (pjob.smbjob) { 972 1007 for (i=0;i<ts->qcount;i++) { 973 uint32 curr_jobid;974 975 1008 if ( pjob.status == LPQ_DELETED ) 976 1009 continue; 977 1010 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) { 981 1012 982 1013 /* try to clean up any jobs that need to be deleted */ … … 1033 1064 } 1034 1065 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; 1040 1068 ts->queue[i].size = pjob.size; 1041 1069 ts->queue[i].page_count = pjob.page_count; … … 1188 1216 qcount++; 1189 1217 data.dsize += tdb_pack(NULL, 0, "ddddddff", 1190 (uint32)queue[i]. job,1218 (uint32)queue[i].sysjob, 1191 1219 (uint32)queue[i].size, 1192 1220 (uint32)queue[i].page_count, … … 1208 1236 1209 1237 len += tdb_pack(data.dptr + len, data.dsize - len, "ddddddff", 1210 (uint32)queue[i]. job,1238 (uint32)queue[i].sysjob, 1211 1239 (uint32)queue[i].size, 1212 1240 (uint32)queue[i].page_count, … … 1322 1350 ****************************************************************************/ 1323 1351 1324 static void print_queue_update_internal( 1325 1326 1327 1328 char *lpq_command, char *lprm_command)1352 static 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) 1329 1357 { 1330 1358 int i, qcount; … … 1338 1366 fstring keystr, cachestr; 1339 1367 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)) { 1342 1371 return; 1343 1372 } … … 1380 1409 fill in any system job numbers as we go 1381 1410 */ 1382 1383 1411 jcdata = get_jobs_added_data(pdb); 1384 1412 1385 1413 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); 1388 1415 if (jobid == (uint32)-1) { 1389 1416 /* assume its a unix print job */ … … 1394 1421 1395 1422 /* 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); 1397 1424 if (!pjob) { 1398 1425 /* err, somethings wrong. Probably smbd was restarted 1399 1426 with jobs in the queue. All we can do is treat them 1400 1427 like unix jobs. Pity. */ 1428 DEBUG(1, ("queued print job %d not found in jobs list, " 1429 "assuming unix job\n", jobid)); 1401 1430 print_unix_job(ev, msg_ctx, 1402 1431 sharename, &queue[i], jobid); 1403 1432 continue; 1404 1433 } 1405 1406 pjob->sysjob = queue[i].job;1407 1434 1408 1435 /* don't reset the status on jobs to be deleted */ … … 1430 1457 tstruct.ev = ev; 1431 1458 tstruct.msg_ctx = msg_ctx; 1459 tstruct.mem_ctx = tmp_ctx; 1432 1460 1433 1461 tdb_traverse(pdb->tdb, traverse_fn_delete, (void *)&tstruct); … … 1437 1465 1438 1466 SAFE_FREE(tstruct.queue); 1467 talloc_free(tmp_ctx); 1439 1468 1440 1469 DEBUG(10,("print_queue_update_internal: printer %s INFO/total_jobs = %d\n", … … 1632 1661 } 1633 1662 1663 static 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 1634 1685 static pid_t background_lpq_updater_pid = -1; 1635 1686 … … 1703 1754 DEBUG(0,("tevent_add_fd() failed for pause_pipe\n")); 1704 1755 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); 1705 1765 } 1706 1766 … … 2049 2109 2050 2110 /**************************************************************************** 2051 Give the filename used for a jobid.2111 Return the device mode asigned to a specific print job. 2052 2112 Only valid for the process doing the spooling and when the job 2053 2113 has not been spooled. 2054 2114 ****************************************************************************/ 2055 2115 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()) 2116 struct 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) { 2060 2122 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 } 2077 2124 2078 2125 return pjob->devmode; … … 2088 2135 { 2089 2136 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 } 2094 2148 2095 2149 fstrcpy(pjob->jobname, name); 2096 return pjob_store(ev, msg_ctx, sharename, jobid, pjob); 2150 ret = pjob_store(ev, msg_ctx, sharename, jobid, pjob); 2151 err_out: 2152 talloc_free(tmp_ctx); 2153 return ret; 2097 2154 } 2098 2155 … … 2105 2162 struct printjob *pjob; 2106 2163 2107 pjob = print_job_find( sharename, jobid);2164 pjob = print_job_find(mem_ctx, sharename, jobid); 2108 2165 if (!pjob || pjob->pid != sys_getpid()) { 2109 2166 return false; 2110 2167 } 2111 2168 2112 *name = talloc_strdup(mem_ctx, pjob->jobname); 2113 if (!*name) { 2114 return false; 2115 } 2116 2169 *name = pjob->jobname; 2117 2170 return true; 2118 2171 } … … 2187 2240 { 2188 2241 const char* sharename = lp_const_servicename(snum); 2189 struct printjob *pjob = print_job_find(sharename, jobid);2242 struct printjob *pjob; 2190 2243 int result = 0; 2191 2244 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 } 2195 2256 2196 2257 /* … … 2198 2259 */ 2199 2260 2200 if (pjob->status == LPQ_DELETING) 2201 return True; 2261 if (pjob->status == LPQ_DELETING) { 2262 ret = true; 2263 goto err_out; 2264 } 2202 2265 2203 2266 /* Hrm - we need to be able to cope with deleting a job before it … … 2229 2292 int njobs = 1; 2230 2293 2231 if (!pdb) 2232 return False; 2294 if (!pdb) { 2295 ret = false; 2296 goto err_out; 2297 } 2233 2298 pjob_delete(ev, msg_ctx, sharename, jobid); 2234 2299 /* Ensure we keep a rough count of the number of total jobs... */ … … 2240 2305 remove_from_jobs_added( sharename, jobid ); 2241 2306 2242 return (result == 0); 2307 ret = (result == 0); 2308 err_out: 2309 talloc_free(tmp_ctx); 2310 return ret; 2243 2311 } 2244 2312 … … 2251 2319 uint32 jobid) 2252 2320 { 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); 2335 err_out: 2336 talloc_free(tmp_ctx); 2337 return ret; 2259 2338 } 2260 2339 … … 2270 2349 struct printjob *pjob; 2271 2350 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 } 2273 2356 2274 2357 owner = is_owner(server_info, lp_const_servicename(snum), jobid); … … 2290 2373 /* END_ADMIN_LOG */ 2291 2374 2292 return WERR_ACCESS_DENIED; 2375 werr = WERR_ACCESS_DENIED; 2376 goto err_out; 2293 2377 } 2294 2378 … … 2300 2384 */ 2301 2385 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; 2309 2394 } 2310 2395 } 2311 2396 2312 2397 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; 2314 2400 } 2315 2401 … … 2319 2405 print_queue_update(msg_ctx, snum, True); 2320 2406 2321 pjob = print_job_find( sharename, jobid);2407 pjob = print_job_find(tmp_ctx, sharename, jobid); 2322 2408 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 2414 err_out: 2415 talloc_free(tmp_ctx); 2416 return werr; 2327 2417 } 2328 2418 … … 2331 2421 ****************************************************************************/ 2332 2422 2333 boolprint_job_pause(const struct auth_serversupplied_info *server_info,2423 WERROR print_job_pause(const struct auth_serversupplied_info *server_info, 2334 2424 struct messaging_context *msg_ctx, 2335 int snum, uint32 jobid , WERROR *errcode)2425 int snum, uint32 jobid) 2336 2426 { 2337 2427 const char* sharename = lp_const_servicename(snum); … … 2339 2429 int ret = -1; 2340 2430 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); 2344 2438 if (!pjob || !server_info) { 2345 2439 DEBUG(10, ("print_job_pause: no pjob or user for jobid %u\n", 2346 2440 (unsigned int)jobid )); 2347 return False; 2441 werr = WERR_INVALID_PARAM; 2442 goto err_out; 2348 2443 } 2349 2444 … … 2351 2446 DEBUG(10, ("print_job_pause: not spooled or bad sysjob = %d for jobid %u\n", 2352 2447 (int)pjob->sysjob, (unsigned int)jobid )); 2353 return False; 2448 werr = WERR_INVALID_PARAM; 2449 goto err_out; 2354 2450 } 2355 2451 … … 2367 2463 /* END_ADMIN_LOG */ 2368 2464 2369 *errcode= WERR_ACCESS_DENIED;2370 return False;2465 werr = WERR_ACCESS_DENIED; 2466 goto err_out; 2371 2467 } 2372 2468 … … 2375 2471 2376 2472 if (ret != 0) { 2377 *errcode= WERR_INVALID_PARAM;2378 return False;2473 werr = WERR_INVALID_PARAM; 2474 goto err_out; 2379 2475 } 2380 2476 … … 2388 2484 2389 2485 /* how do we tell if this succeeded? */ 2390 2391 return True; 2486 werr = WERR_OK; 2487 err_out: 2488 talloc_free(tmp_ctx); 2489 return werr; 2392 2490 } 2393 2491 … … 2396 2494 ****************************************************************************/ 2397 2495 2398 boolprint_job_resume(const struct auth_serversupplied_info *server_info,2496 WERROR print_job_resume(const struct auth_serversupplied_info *server_info, 2399 2497 struct messaging_context *msg_ctx, 2400 int snum, uint32 jobid , WERROR *errcode)2498 int snum, uint32 jobid) 2401 2499 { 2402 2500 const char *sharename = lp_const_servicename(snum); … … 2404 2502 int ret; 2405 2503 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); 2409 2510 if (!pjob || !server_info) { 2410 2511 DEBUG(10, ("print_job_resume: no pjob or user for jobid %u\n", 2411 2512 (unsigned int)jobid )); 2412 return False; 2513 werr = WERR_INVALID_PARAM; 2514 goto err_out; 2413 2515 } 2414 2516 … … 2416 2518 DEBUG(10, ("print_job_resume: not spooled or bad sysjob = %d for jobid %u\n", 2417 2519 (int)pjob->sysjob, (unsigned int)jobid )); 2418 return False; 2520 werr = WERR_INVALID_PARAM; 2521 goto err_out; 2419 2522 } 2420 2523 … … 2423 2526 JOB_ACCESS_ADMINISTER)) { 2424 2527 DEBUG(3, ("resume denied by security descriptor\n")); 2425 *errcode = WERR_ACCESS_DENIED;2426 2528 2427 2529 /* BEGIN_ADMIN_LOG */ … … 2432 2534 lp_printername(snum) ); 2433 2535 /* END_ADMIN_LOG */ 2434 return False; 2536 werr = WERR_ACCESS_DENIED; 2537 goto err_out; 2435 2538 } 2436 2539 … … 2438 2541 2439 2542 if (ret != 0) { 2440 *errcode= WERR_INVALID_PARAM;2441 return False;2543 werr = WERR_INVALID_PARAM; 2544 goto err_out; 2442 2545 } 2443 2546 … … 2450 2553 JOB_STATUS_QUEUED); 2451 2554 2452 return True; 2555 werr = WERR_OK; 2556 err_out: 2557 talloc_free(tmp_ctx); 2558 return werr; 2453 2559 } 2454 2560 … … 2464 2570 ssize_t return_code; 2465 2571 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) { 2470 2574 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 2471 2583 /* 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 } 2474 2588 2475 2589 /* if SMBD is spooling this can't be allowed */ 2476 2590 if (pjob->status == PJOB_SMBD_SPOOLING) { 2477 return -1; 2591 return_code = -1; 2592 goto err_out; 2478 2593 } 2479 2594 2480 2595 return_code = write_data(pjob->fd, buf, size); 2481 2482 if (return_code>0) { 2596 if (return_code > 0) { 2483 2597 pjob->size += size; 2484 2598 pjob_store(ev, msg_ctx, sharename, jobid, pjob); 2485 2599 } 2600 err_out: 2601 talloc_free(tmp_ctx); 2486 2602 return return_code; 2487 2603 } … … 2763 2879 2764 2880 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); 2767 2882 pjob->fd = mkstemp(pjob->filename); 2768 2883 … … 2830 2945 2831 2946 pjob.pid = sys_getpid(); 2947 pjob.jobid = jobid; 2832 2948 pjob.sysjob = -1; 2833 2949 pjob.fd = -1; … … 2894 3010 const char* sharename = lp_const_servicename(snum); 2895 3011 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) { 2899 3014 return; 3015 } 3016 3017 pjob = print_job_find(tmp_ctx, sharename, jobid); 3018 if (!pjob) { 3019 goto err_out; 3020 } 2900 3021 /* 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 } 2903 3025 2904 3026 pjob->page_count++; 2905 3027 pjob_store(server_event_context(), msg_ctx, sharename, jobid, pjob); 3028 err_out: 3029 talloc_free(tmp_ctx); 2906 3030 } 2907 3031 … … 2919 3043 int ret; 2920 3044 SMB_STRUCT_STAT sbuf; 2921 struct printif *current_printif = get_printer_fns( snum);3045 struct printif *current_printif = get_printer_fns(snum); 2922 3046 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); 2926 3054 if (!pjob) { 2927 return NT_STATUS_PRINT_CANCELLED; 3055 status = NT_STATUS_PRINT_CANCELLED; 3056 goto err_out; 2928 3057 } 2929 3058 2930 3059 if (pjob->spooled || pjob->pid != sys_getpid()) { 2931 return NT_STATUS_ACCESS_DENIED; 3060 status = NT_STATUS_ACCESS_DENIED; 3061 goto err_out; 2932 3062 } 2933 3063 … … 2983 3113 } 2984 3114 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); 2987 3140 if (ret) { 2988 3141 status = NT_STATUS_PRINT_CANCELLED; … … 3009 3162 unlink(pjob->filename); 3010 3163 pjob_delete(server_event_context(), msg_ctx, sharename, jobid); 3164 err_out: 3165 talloc_free(tmp_ctx); 3011 3166 return status; 3012 3167 } … … 3031 3186 bool ret = False; 3032 3187 const char* sharename = lp_servicename(snum); 3188 TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx); 3189 if (tmp_ctx == NULL) { 3190 return false; 3191 } 3033 3192 3034 3193 /* make sure the database is up to date */ … … 3080 3239 queue[i].fs_user, 3081 3240 queue[i].fs_file); 3082 queue[i]. job = qjob;3241 queue[i].sysjob = qjob; 3083 3242 queue[i].size = qsize; 3084 3243 queue[i].page_count = qpage_count; … … 3097 3256 jobid = IVAL(cgdata.dptr, i*4); 3098 3257 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); 3100 3259 if (!pjob) { 3101 3260 DEBUG(5,("get_stored_queue_info: failed to find added job = %u\n", (unsigned int)jobid)); … … 3104 3263 } 3105 3264 3106 queue[total_count]. job = jobid;3265 queue[total_count].sysjob = jobid; 3107 3266 queue[total_count].size = pjob->size; 3108 3267 queue[total_count].page_count = pjob->page_count; … … 3113 3272 fstrcpy(queue[total_count].fs_file, pjob->jobname); 3114 3273 total_count++; 3274 talloc_free(pjob); 3115 3275 } 3116 3276 … … 3122 3282 3123 3283 for (j = 0; j < total_count; j++) { 3124 if (queue[j]. job == jobid) {3284 if (queue[j].sysjob == jobid) { 3125 3285 found = true; 3126 3286 break; … … 3134 3294 (unsigned int) jobid)); 3135 3295 3136 pjob = print_job_find( sharename, jobid);3296 pjob = print_job_find(tmp_ctx, sharename, jobid); 3137 3297 if (pjob == NULL) { 3138 3298 DEBUG(5,("get_stored_queue_info: failed to find " … … 3143 3303 } 3144 3304 3145 queue[j]. job = jobid;3305 queue[j].sysjob = jobid; 3146 3306 queue[j].size = pjob->size; 3147 3307 queue[j].page_count = pjob->page_count; … … 3151 3311 fstrcpy(queue[j].fs_user, pjob->user); 3152 3312 fstrcpy(queue[j].fs_file, pjob->jobname); 3313 talloc_free(pjob); 3153 3314 3154 3315 DEBUG(5,("get_stored_queue_info: updated queue[%u], jobid: %u, jobname: %s\n", … … 3178 3339 SAFE_FREE(data.dptr); 3179 3340 SAFE_FREE(cgdata.dptr); 3341 talloc_free(tmp_ctx); 3180 3342 return ret; 3181 3343 } … … 3345 3507 for (i=0;i<njobs;i++) { 3346 3508 bool owner = is_owner(server_info, lp_const_servicename(snum), 3347 queue[i]. job);3509 queue[i].sysjob); 3348 3510 3349 3511 if (owner || can_job_admin) { 3350 3512 print_job_delete1(server_event_context(), msg_ctx, 3351 snum, queue[i]. job);3513 snum, queue[i].sysjob); 3352 3514 } 3353 3515 } -
trunk/server/source3/printing/printspoolss.c
r745 r751 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)) { -
trunk/server/source3/printing/tests/vlp.c
r745 r751 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.