diff options
| author | Jonathan Cowper-Andrewes <Jonathan.Ca@Sun.COM> | 2009-01-19 10:00:04 +0000 |
|---|---|---|
| committer | Jonathan Cowper-Andrewes <Jonathan.Ca@Sun.COM> | 2009-01-19 10:00:04 +0000 |
| commit | 95c2d3023b88b9097d9822eb47ace5466e6d1cf4 (patch) | |
| tree | 1e998105b908c87ac180519e07150e1184593f74 /usr/src/lib/print | |
| parent | 16070783c69283175b84d52ad8b44be53e5fcdd5 (diff) | |
| download | illumos-joyent-95c2d3023b88b9097d9822eb47ace5466e6d1cf4.tar.gz | |
6757330 discard zero byte size printjob to remote queue
6792042 several printing source files are not cstyle clean
Diffstat (limited to 'usr/src/lib/print')
| -rw-r--r-- | usr/src/lib/print/libpapi-ipp/common/ipp-support.c | 77 | ||||
| -rw-r--r-- | usr/src/lib/print/libpapi-ipp/common/job.c | 97 | ||||
| -rw-r--r-- | usr/src/lib/print/libpapi-lpd/common/lpd-job.c | 75 |
3 files changed, 140 insertions, 109 deletions
diff --git a/usr/src/lib/print/libpapi-ipp/common/ipp-support.c b/usr/src/lib/print/libpapi-ipp/common/ipp-support.c index 3196afccd9..ab3d1a337c 100644 --- a/usr/src/lib/print/libpapi-ipp/common/ipp-support.c +++ b/usr/src/lib/print/libpapi-ipp/common/ipp-support.c @@ -20,14 +20,13 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ /* $Id: ipp-support.c 148 2006-04-25 16:54:17Z njacobs $ */ -#pragma ident "%Z%%M% %I% %E% SMI" #include <papi_impl.h> #include <stdlib.h> @@ -155,13 +154,13 @@ ipp_initialize_request(service_t *svc, papi_attribute_t ***request, uint16_t operation) { papiAttributeListAddInteger(request, PAPI_ATTR_EXCL, - "version-major", 1); + "version-major", 1); papiAttributeListAddInteger(request, PAPI_ATTR_EXCL, - "version-minor", 1); + "version-minor", 1); papiAttributeListAddInteger(request, PAPI_ATTR_EXCL, - "request-id", (short)lrand48()); + "request-id", (short)lrand48()); papiAttributeListAddInteger(request, PAPI_ATTR_EXCL, - "operation-id", operation); + "operation-id", operation); } void @@ -181,17 +180,17 @@ ipp_initialize_operational_attributes(service_t *svc, papi_attribute_t ***op, * requesting-user-name (process user or none) */ papiAttributeListAddString(op, PAPI_ATTR_EXCL, - "attributes-charset", charset); + "attributes-charset", charset); papiAttributeListAddString(op, PAPI_ATTR_EXCL, - "attributes-natural-language", language); + "attributes-natural-language", language); if (printer != NULL) ipp_add_printer_uri(svc, printer, op); if ((printer != NULL) && (job_id >= 0)) papiAttributeListAddInteger(op, PAPI_ATTR_EXCL, - "job-id", job_id); + "job-id", job_id); if ((pw = getpwuid(getuid())) != NULL) user = pw->pw_name; @@ -204,7 +203,7 @@ ipp_initialize_operational_attributes(service_t *svc, papi_attribute_t ***op, user = svc->user; } papiAttributeListAddString(op, PAPI_ATTR_REPLACE, - "requesting-user-name", user); + "requesting-user-name", user); } #ifndef OPID_CUPS_GET_DEFAULT /* for servers that will enumerate */ @@ -232,23 +231,23 @@ _default_destination(service_t *svc, char **uri) ipp_initialize_request(svc, &request, OPID_CUPS_GET_DEFAULT); ipp_initialize_operational_attributes(svc, &op, NULL, -1); papiAttributeListAddString(&op, PAPI_ATTR_APPEND, - "requested-attributes", "printer-uri-supported"); + "requested-attributes", "printer-uri-supported"); papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, - "operational-attributes-group", op); + "operational-attributes-group", op); papiAttributeListFree(op); result = ipp_send_request(svc, request, &response); papiAttributeListFree(request); op = NULL; papiAttributeListGetCollection(response, NULL, - "printer-attributes-group", &op); + "printer-attributes-group", &op); if (uri != NULL) { char *tmp = NULL; papiAttributeListGetString(op, NULL, "printer-uri", &tmp); papiAttributeListGetString(op, NULL, - "printer-uri-supported", &tmp); + "printer-uri-supported", &tmp); if (tmp != NULL) *uri = strdup(tmp); } @@ -341,7 +340,7 @@ ipp_request_read(void *fd, void *buffer, size_t length) } #ifdef DEBUG printf("ipp_request_read(0x%8.8x, 0x%8.8x, %d) = %d\n", - fd, buffer, length, rc); + fd, buffer, length, rc); httpDumpData(stdout, "ipp_request_read:", buffer, length); #endif @@ -365,16 +364,16 @@ ipp_send_initial_request_block(service_t *svc, papi_attribute_t **request, httpClearFields(svc->connection); if (svc->transfer_encoding == TRANSFER_ENCODING_CHUNKED) httpSetField(svc->connection, HTTP_FIELD_TRANSFER_ENCODING, - "chunked"); + "chunked"); else { sprintf(length, "%lu", (unsigned long)(file_size + chunk_size)); httpSetField(svc->connection, HTTP_FIELD_CONTENT_LENGTH, - length); + length); } httpSetField(svc->connection, HTTP_FIELD_CONTENT_TYPE, - "application/ipp"); + "application/ipp"); httpSetField(svc->connection, HTTP_FIELD_AUTHORIZATION, - svc->connection->authstring); + svc->connection->authstring); /* flush any state information about this connection */ httpFlush(svc->connection); @@ -451,15 +450,15 @@ setAuthString(service_t *svc) return (-1); if (strncmp(http->fields[HTTP_FIELD_WWW_AUTHENTICATE], - "Basic", 5) == 0) { + "Basic", 5) == 0) { char plain[BUFSIZ]; snprintf(plain, sizeof (plain), "%s:%s", user, passphrase); httpEncode64(encoded, plain); snprintf(http->authstring, sizeof (http->authstring), - "Basic %s", encoded); + "Basic %s", encoded); } else if (strncmp(http->fields[HTTP_FIELD_WWW_AUTHENTICATE], - "Digest", 6) == 0) { + "Digest", 6) == 0) { char realm[HTTP_MAX_VALUE]; char nonce[HTTP_MAX_VALUE]; char line [BUFSIZ]; @@ -468,12 +467,12 @@ setAuthString(service_t *svc) char *uri = svc->post; httpGetSubField(http, HTTP_FIELD_WWW_AUTHENTICATE, - "realm", realm); + "realm", realm); httpGetSubField(http, HTTP_FIELD_WWW_AUTHENTICATE, - "nonce", nonce); + "nonce", nonce); snprintf(line, sizeof (line), "%s:%s:%s", user, realm, - passphrase); + passphrase); md5_calc(urp, line, strlen(line)); snprintf(line, sizeof (line), "POST:%s", uri); @@ -483,9 +482,9 @@ setAuthString(service_t *svc) md5_calc(encoded, line, strlen(line)); snprintf(http->authstring, sizeof (http->authstring), - "Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", " - "uri=\"%s\", response=\"%s\"", user, realm, nonce, uri, - encoded); + "Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", " + "uri=\"%s\", response=\"%s\"", user, realm, nonce, uri, + encoded); } return (0); @@ -498,14 +497,14 @@ ipp_status_info(service_t *svc, papi_attribute_t **response) int32_t status = 0; papiAttributeListGetCollection(response, NULL, - "operational-attributes-group", &operational); + "operational-attributes-group", &operational); if (operational != NULL) { char *message = NULL; papiAttributeListGetString(response, NULL, - "status-message", &message); + "status-message", &message); papiAttributeListAddString(&svc->attributes, PAPI_ATTR_REPLACE, - "detailed-status-message", message); + "detailed-status-message", message); } papiAttributeListGetInteger(response, NULL, "status-code", &status); @@ -518,6 +517,7 @@ ipp_send_request_with_file(service_t *svc, papi_attribute_t **request, { papi_status_t result = PAPI_OK; ssize_t size = 0; + struct stat statbuf; int fd; #ifdef DEBUG @@ -535,8 +535,15 @@ ipp_send_request_with_file(service_t *svc, papi_attribute_t **request, if ((fd = open(file, O_RDONLY)) < 0) { detailed_error(svc, "%s: %s", file, strerror(errno)); return (PAPI_DOCUMENT_ACCESS_ERROR); + } else if (strcmp("standard input", file) != 0) { + stat(file, &statbuf); + if (statbuf.st_size == 0) { + detailed_error(svc, + "Zero byte (empty) file: %s", file); + return (PAPI_BAD_ARGUMENT); + } } else if (svc->transfer_encoding != - TRANSFER_ENCODING_CHUNKED) { + TRANSFER_ENCODING_CHUNKED) { struct stat st; if (fstat(fd, &st) >= 0) @@ -559,7 +566,7 @@ ipp_send_request_with_file(service_t *svc, papi_attribute_t **request, lseek(fd, 0L, SEEK_SET); while ((rc = read(fd, buf, sizeof (buf))) > 0) { if (ipp_request_write(svc, buf, rc) - < rc) { + < rc) { break; } } @@ -595,13 +602,13 @@ ipp_send_request_with_file(service_t *svc, papi_attribute_t **request, /* read the IPP response */ result = ipp_read_message(&ipp_request_read, svc, response, - IPP_TYPE_RESPONSE); + IPP_TYPE_RESPONSE); if (result == PAPI_OK) result = ipp_status_info(svc, *response); #ifdef DEBUG fprintf(stderr, "\nIPP-RESPONSE: (%s) (%s)", (file ? file : ""), - papiStatusString(result)); + papiStatusString(result)); papiAttributeListPrint(stderr, *response, " "); putc('\n', stderr); fflush(stderr); diff --git a/usr/src/lib/print/libpapi-ipp/common/job.c b/usr/src/lib/print/libpapi-ipp/common/job.c index 0ed762cece..0c4aac1af2 100644 --- a/usr/src/lib/print/libpapi-ipp/common/job.c +++ b/usr/src/lib/print/libpapi-ipp/common/job.c @@ -20,14 +20,13 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ /* $Id: job.c 148 2006-04-25 16:54:17Z njacobs $ */ -#pragma ident "%Z%%M% %I% %E% SMI" /*LINTLIBRARY*/ @@ -35,6 +34,9 @@ #include <errno.h> #include <string.h> #include <papi_impl.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> #ifndef OPID_CUPS_MOVE_JOB #define OPID_CUPS_MOVE_JOB 0x400D @@ -84,7 +86,7 @@ papiJobGetPrinterName(papi_job_t job) if (j != NULL) (void) papiAttributeListGetString(j->attributes, NULL, - "printer-name", &result); + "printer-name", &result); return (result); } @@ -97,7 +99,7 @@ papiJobGetId(papi_job_t job) if (j != NULL) (void) papiAttributeListGetInteger(j->attributes, NULL, - "job-id", &result); + "job-id", &result); return (result); } @@ -129,17 +131,17 @@ populate_job_request(service_t *svc, papi_attribute_t ***request, /* split up the attributes into operational and job attributes */ split_and_copy_attributes(operational_names, attributes, - &operational, &job); + &operational, &job); /* add the operational attributes group to the request */ papiAttributeListAddCollection(request, PAPI_ATTR_REPLACE, - "operational-attributes-group", operational); + "operational-attributes-group", operational); papiAttributeListFree(operational); /* add the job attributes group to the request */ if (job != NULL) { papiAttributeListAddCollection(request, PAPI_ATTR_REPLACE, - "job-attributes-group", job); + "job-attributes-group", job); papiAttributeListFree(job); } } @@ -158,11 +160,11 @@ send_document_uri(service_t *svc, char *file, papi_attribute_t **attributes, ipp_initialize_operational_attributes(svc, &op, printer, id); papiAttributeListAddString(&op, PAPI_ATTR_REPLACE, "document-name", - file); + file); papiAttributeListAddBoolean(&op, PAPI_ATTR_REPLACE, "last-document", - (last ? PAPI_TRUE : PAPI_FALSE)); + (last ? PAPI_TRUE : PAPI_FALSE)); papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, - "operational-attributes-group", op); + "operational-attributes-group", op); papiAttributeListFree(op); /* send the IPP request to the server */ @@ -184,6 +186,7 @@ internal_job_submit(papi_service_t handle, char *printer, { papi_status_t result = PAPI_INTERNAL_ERROR; service_t *svc = handle; + struct stat statbuf; job_t *j = NULL; int i; uint16_t req_type = OPID_PRINT_JOB; @@ -221,12 +224,24 @@ internal_job_submit(papi_service_t handle, char *printer, req_type = OPID_VALIDATE_JOB; /* if we have files, validate access to them */ if (files != NULL) { - for (i = 0; files[i] != NULL; i++) + for (i = 0; files[i] != NULL; i++) { if (access(files[i], R_OK) < 0) { detailed_error(svc, "%s: %s", files[i], - strerror(errno)); + strerror(errno)); return (PAPI_DOCUMENT_ACCESS_ERROR); } + + if (strcmp("standard input", files[i]) != 0) { + stat(files[i], &statbuf); + if (statbuf.st_size == 0) { + detailed_error(svc, + "Zero byte (empty) file: " + "%s", + files[i]); + return (PAPI_BAD_ARGUMENT); + } + } + } files = NULL; } break; @@ -246,7 +261,7 @@ internal_job_submit(papi_service_t handle, char *printer, switch (req_type) { case OPID_PRINT_JOB: result = ipp_send_request_with_file(svc, request, &response, - files[0]); + files[0]); break; case OPID_CREATE_JOB: case OPID_VALIDATE_JOB: @@ -261,21 +276,21 @@ internal_job_submit(papi_service_t handle, char *printer, /* retrieve the job attributes */ papiAttributeListGetCollection(response, NULL, - "job-attributes-group", &op); + "job-attributes-group", &op); copy_attributes(&j->attributes, op); if (req_type == OPID_CREATE_JOB) { int32_t id = 0; papiAttributeListGetInteger(j->attributes, NULL, - "job-id", &id); + "job-id", &id); /* send each document */ for (i = 0; ((result == PAPI_OK) && (files[i] != NULL)); - i++) + i++) result = send_document_uri(svc, files[i], - job_attributes, - printer, id, (files[i+1]?0:1), - data_type); + job_attributes, + printer, id, (files[i+1]?0:1), + data_type); } } papiAttributeListFree(response); @@ -289,7 +304,7 @@ papiJobSubmit(papi_service_t handle, char *printer, papi_job_ticket_t *job_ticket, char **files, papi_job_t *job) { return (internal_job_submit(handle, printer, job_attributes, - job_ticket, files, job, _WITH_DATA)); + job_ticket, files, job, _WITH_DATA)); } papi_status_t @@ -298,7 +313,7 @@ papiJobSubmitByReference(papi_service_t handle, char *printer, papi_job_ticket_t *job_ticket, char **files, papi_job_t *job) { return (internal_job_submit(handle, printer, job_attributes, - job_ticket, files, job, _BY_REFERENCE)); + job_ticket, files, job, _BY_REFERENCE)); } papi_status_t @@ -307,7 +322,7 @@ papiJobValidate(papi_service_t handle, char *printer, papi_job_ticket_t *job_ticket, char **files, papi_job_t *job) { return (internal_job_submit(handle, printer, job_attributes, - job_ticket, files, job, _VALIDATE)); + job_ticket, files, job, _VALIDATE)); } papi_status_t @@ -329,7 +344,7 @@ papiJobStreamOpen(papi_service_t handle, char *printer, /* create job request */ populate_job_request(svc, &request, job_attributes, printer, - OPID_PRINT_JOB); + OPID_PRINT_JOB); *stream = svc->connection; @@ -349,7 +364,7 @@ papiJobStreamWrite(papi_service_t handle, #ifdef DEBUG printf("papiJobStreamWrite(0x%8.8x, 0x%8.8x, 0x%8.8x, %d)\n", - handle, stream, buffer, buflen); + handle, stream, buffer, buflen); httpDumpData(stdout, "papiJobStreamWrite:", buffer, buflen); #endif @@ -402,7 +417,7 @@ papiJobStreamClose(papi_service_t handle, /* read the IPP response */ result = ipp_read_message(&ipp_request_read, svc, &response, - IPP_TYPE_RESPONSE); + IPP_TYPE_RESPONSE); if (result == PAPI_OK) result = ipp_status_info(svc, response); @@ -410,7 +425,7 @@ papiJobStreamClose(papi_service_t handle, papi_attribute_t **op = NULL; papiAttributeListGetCollection(response, NULL, - "job-attributes-group", &op); + "job-attributes-group", &op); copy_attributes(&j->attributes, op); } papiAttributeListFree(response); @@ -448,18 +463,18 @@ papiJobQuery(papi_service_t handle, char *printer, int32_t job_id, for (i = 0; requested_attrs[i] != NULL; i++) papiAttributeListAddString(&op, PAPI_ATTR_APPEND, - "requested-attributes", requested_attrs[i]); + "requested-attributes", requested_attrs[i]); } papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, - "operational-attributes-group", op); + "operational-attributes-group", op); papiAttributeListFree(op); result = ipp_send_request(svc, request, &response); papiAttributeListFree(request); op = NULL; papiAttributeListGetCollection(response, NULL, - "job-attributes-group", &op); + "job-attributes-group", &op); copy_attributes(&j->attributes, op); papiAttributeListFree(response); @@ -488,7 +503,7 @@ _job_cancel_hold_release_restart_promote(papi_service_t handle, ipp_initialize_operational_attributes(svc, &op, printer, job_id); papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, - "operational-attributes-group", op); + "operational-attributes-group", op); papiAttributeListFree(op); result = ipp_send_request(svc, request, &response); papiAttributeListFree(request); @@ -501,7 +516,7 @@ papi_status_t papiJobCancel(papi_service_t handle, char *printer, int32_t job_id) { return (_job_cancel_hold_release_restart_promote(handle, printer, - job_id, OPID_CANCEL_JOB)); + job_id, OPID_CANCEL_JOB)); } @@ -509,28 +524,28 @@ papi_status_t papiJobHold(papi_service_t handle, char *printer, int32_t job_id) { return (_job_cancel_hold_release_restart_promote(handle, printer, - job_id, OPID_HOLD_JOB)); + job_id, OPID_HOLD_JOB)); } papi_status_t papiJobRelease(papi_service_t handle, char *printer, int32_t job_id) { return (_job_cancel_hold_release_restart_promote(handle, printer, - job_id, OPID_RELEASE_JOB)); + job_id, OPID_RELEASE_JOB)); } papi_status_t papiJobRestart(papi_service_t handle, char *printer, int32_t job_id) { return (_job_cancel_hold_release_restart_promote(handle, printer, - job_id, OPID_RESTART_JOB)); + job_id, OPID_RESTART_JOB)); } papi_status_t papiJobPromote(papi_service_t handle, char *printer, int32_t job_id) { return (_job_cancel_hold_release_restart_promote(handle, printer, - job_id, OPID_PROMOTE_JOB)); + job_id, OPID_PROMOTE_JOB)); } papi_status_t @@ -555,14 +570,14 @@ papiJobMove(papi_service_t handle, char *printer, int32_t job_id, ipp_initialize_operational_attributes(svc, &op, printer, job_id); papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, - "operational-attributes-group", op); + "operational-attributes-group", op); papiAttributeListFree(op); op = NULL; papiAttributeListAddString(&op, PAPI_ATTR_EXCL, - "job-printer-uri", destination); + "job-printer-uri", destination); papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, - "job-attributes-group", op); + "job-attributes-group", op); papiAttributeListFree(op); result = ipp_send_request(svc, request, &response); @@ -598,16 +613,16 @@ papiJobModify(papi_service_t handle, char *printer, int32_t job_id, ipp_initialize_operational_attributes(svc, &op, printer, job_id); papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, - "operational-attributes-group", op); + "operational-attributes-group", op); papiAttributeListFree(op); papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, - "job-attributes-group", attributes); + "job-attributes-group", attributes); result = ipp_send_request(svc, request, &response); papiAttributeListFree(request); op = NULL; papiAttributeListGetCollection(response, NULL, - "job-attributes-group", &op); + "job-attributes-group", &op); copy_attributes(&j->attributes, op); papiAttributeListFree(response); diff --git a/usr/src/lib/print/libpapi-lpd/common/lpd-job.c b/usr/src/lib/print/libpapi-lpd/common/lpd-job.c index 52dc69d6c4..dd1a0fb24c 100644 --- a/usr/src/lib/print/libpapi-lpd/common/lpd-job.c +++ b/usr/src/lib/print/libpapi-lpd/common/lpd-job.c @@ -20,14 +20,13 @@ */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ /* $Id: lpd-job.c 157 2006-04-26 15:07:55Z ktou $ */ -#pragma ident "%Z%%M% %I% %E% SMI" #define __EXTENSIONS__ /* for strtok_r() */ #include <stdio.h> @@ -173,16 +172,16 @@ lpd_add_rfc1179_attributes(service_t *svc, papi_attribute_t **attributes, gethostname(host, sizeof (host)); add_lpd_control_line(metadata, 'H', host); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "job-originating-host-name", host); + "job-originating-host-name", host); if ((pw = getpwuid(uid)) != NULL) user = pw->pw_name; if (uid == 0) papiAttributeListGetString(svc->attributes, NULL, "username", - &user); + &user); add_lpd_control_line(metadata, 'P', user); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "job-originating-user-name", user); + "job-originating-user-name", user); /* Class for Banner Page */ s = NULL; @@ -190,7 +189,7 @@ lpd_add_rfc1179_attributes(service_t *svc, papi_attribute_t **attributes, if (s != NULL) { add_lpd_control_line(metadata, 'C', s); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "rfc-1179-class", s); + "rfc-1179-class", s); } /* Print Banner Page */ @@ -199,7 +198,7 @@ lpd_add_rfc1179_attributes(service_t *svc, papi_attribute_t **attributes, if ((s != NULL) && (strcmp(s, "standard") == 0)) { add_lpd_control_line(metadata, 'L', user); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "job-sheets", s); + "job-sheets", s); } /* Jobname */ @@ -208,7 +207,7 @@ lpd_add_rfc1179_attributes(service_t *svc, papi_attribute_t **attributes, if (s != NULL) { add_lpd_control_line(metadata, 'J', s); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "job-name", s); + "job-name", s); } /* User to mail when job is done - lpr -m */ @@ -217,7 +216,7 @@ lpd_add_rfc1179_attributes(service_t *svc, papi_attribute_t **attributes, if (bool == PAPI_TRUE) { add_lpd_control_line(metadata, 'M', user); papiAttributeListAddBoolean(used, PAPI_ATTR_EXCL, - "rfc-1179-mail", bool); + "rfc-1179-mail", bool); } /* Title for pr */ @@ -226,7 +225,7 @@ lpd_add_rfc1179_attributes(service_t *svc, papi_attribute_t **attributes, if (s != NULL) { add_lpd_control_line(metadata, 'T', s); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "pr-title", s); + "pr-title", s); } /* Indent - used with pr filter */ @@ -235,7 +234,7 @@ lpd_add_rfc1179_attributes(service_t *svc, papi_attribute_t **attributes, if (integer >= 1) { add_int_control_line(metadata, 'I', integer, LPD_RFC); papiAttributeListAddInteger(used, PAPI_ATTR_EXCL, - "pr-indent", integer); + "pr-indent", integer); } /* Width - used with pr filter */ @@ -244,7 +243,7 @@ lpd_add_rfc1179_attributes(service_t *svc, papi_attribute_t **attributes, if (integer >= 1) { add_int_control_line(metadata, 'W', integer, LPD_RFC); papiAttributeListAddInteger(used, PAPI_ATTR_EXCL, - "pr-width", integer); + "pr-width", integer); } /* file with Times Roman font lpr -1 */ @@ -253,7 +252,7 @@ lpd_add_rfc1179_attributes(service_t *svc, papi_attribute_t **attributes, if (s != NULL) { add_lpd_control_line(metadata, '1', s); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "rfc-1179-font-r", s); + "rfc-1179-font-r", s); } /* file with Times Roman font lpr -2 */ @@ -262,7 +261,7 @@ lpd_add_rfc1179_attributes(service_t *svc, papi_attribute_t **attributes, if (s != NULL) { add_lpd_control_line(metadata, '2', s); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "rfc-1179-font-i", s); + "rfc-1179-font-i", s); } /* file with Times Roman font lpr -3 */ @@ -271,7 +270,7 @@ lpd_add_rfc1179_attributes(service_t *svc, papi_attribute_t **attributes, if (s != NULL) { add_lpd_control_line(metadata, '3', s); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "rfc-1179-font-b", s); + "rfc-1179-font-b", s); } /* file with Times Roman font lpr -4 */ @@ -280,7 +279,7 @@ lpd_add_rfc1179_attributes(service_t *svc, papi_attribute_t **attributes, if (s != NULL) { add_lpd_control_line(metadata, '4', s); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "rfc-1179-font-s", s); + "rfc-1179-font-s", s); } return (status); @@ -316,7 +315,7 @@ unused_attributes(papi_attribute_t **list, papi_attribute_t **used) free(result); result = calloc(1, size); } while (papiAttributeListToString(unused, " ", - result, size) != PAPI_OK); + result, size) != PAPI_OK); papiAttributeListFree(unused); } free(names); @@ -346,7 +345,7 @@ lpd_add_svr4_attributes(service_t *svc, papi_attribute_t **attributes, if (s != NULL) { add_svr4_control_line(metadata, 'f', s); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "media", s); + "media", s); } /* Handling */ @@ -355,15 +354,15 @@ lpd_add_svr4_attributes(service_t *svc, papi_attribute_t **attributes, if ((s != NULL) && (strcmp(s, "indefinite"))) { add_svr4_control_line(metadata, 'H', "hold"); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "job-hold-until", "indefinite"); + "job-hold-until", "indefinite"); } else if ((s != NULL) && (strcmp(s, "no-hold"))) { add_svr4_control_line(metadata, 'H', "immediate"); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "job-hold-until", "no-hold"); + "job-hold-until", "no-hold"); } else if (s != NULL) { add_svr4_control_line(metadata, 'H', s); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "job-hold-until", s); + "job-hold-until", s); } /* Pages */ @@ -377,7 +376,7 @@ lpd_add_svr4_attributes(service_t *svc, papi_attribute_t **attributes, if ((s = strchr(buf, '=')) != NULL) { add_svr4_control_line(metadata, 'P', ++s); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "page-ranges", s); + "page-ranges", s); } } @@ -388,7 +387,7 @@ lpd_add_svr4_attributes(service_t *svc, papi_attribute_t **attributes, integer = 40 - (integer / 2.5); add_int_control_line(metadata, 'q', integer, LPD_SVR4); papiAttributeListAddInteger(used, PAPI_ATTR_EXCL, - "job-priority", integer); + "job-priority", integer); } /* Charset : lp -S */ @@ -397,7 +396,7 @@ lpd_add_svr4_attributes(service_t *svc, papi_attribute_t **attributes, if (s != NULL) { add_svr4_control_line(metadata, 'S', s); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "lp-charset", s); + "lp-charset", s); } /* Type : done when adding file */ @@ -408,7 +407,7 @@ lpd_add_svr4_attributes(service_t *svc, papi_attribute_t **attributes, if (s != NULL) { add_svr4_control_line(metadata, 'y', s); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "lp-modes", s); + "lp-modes", s); } /* Options lp -o are handled elsewhere */ @@ -449,10 +448,10 @@ lpd_job_add_attributes(service_t *svc, papi_attribute_t **attributes, if ((strcasecmp(svc->uri->fragment, "solaris") == 0) || (strcasecmp(svc->uri->fragment, "svr4") == 0)) lpd_add_svr4_attributes(svc, attributes, metadata, - used); + used); else if (strcasecmp(svc->uri->fragment, "hpux") == 0) lpd_add_hpux_attributes(svc, attributes, metadata, - used); + used); /* * others could be added here: * lprng, sco, aix, digital unix, xerox, ... @@ -477,13 +476,13 @@ lpd_job_add_files(service_t *svc, papi_attribute_t **attributes, return (PAPI_BAD_ARGUMENT); papiAttributeListGetString(attributes, NULL, "document-format", - &format); + &format); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "document-format", format); + "document-format", format); if ((rfc_fmt = mime_type_to_rfc1179_type(format)) == '\0') { if ((svc->uri->fragment != NULL) && ((strcasecmp(svc->uri->fragment, "solaris") == 0) || - (strcasecmp(svc->uri->fragment, "svr4") == 0))) + (strcasecmp(svc->uri->fragment, "svr4") == 0))) add_svr4_control_line(metadata, 'T', format); rfc_fmt = 'l'; } @@ -497,15 +496,25 @@ lpd_job_add_files(service_t *svc, papi_attribute_t **attributes, for (i = 0; files[i] != NULL; i++) { char name[BUFSIZ]; + struct stat statbuf; char key; int j; if ((strcmp("standard input", files[i]) != 0) && (access(files[i], R_OK) < 0)) { detailed_error(svc, gettext("aborting request, %s: %s"), - files[i], strerror(errno)); + files[i], strerror(errno)); return (PAPI_NOT_AUTHORIZED); } + if (strcmp("standard input", files[i]) != 0) { + stat(files[i], &statbuf); + if (statbuf.st_size == 0) { + detailed_error(svc, + gettext("Zero byte (empty) file: %s"), + files[i]); + return (PAPI_BAD_ARGUMENT); + } + } if (i < 26) key = 'A' + i; @@ -515,7 +524,7 @@ lpd_job_add_files(service_t *svc, papi_attribute_t **attributes, key = '0' + (i - 52); else { detailed_error(svc, - gettext("too many files, truncated at 62")); + gettext("too many files, truncated at 62")); return (PAPI_OK_SUBST); } @@ -585,7 +594,7 @@ lpd_submit_job(service_t *svc, char *metadata, papi_attribute_t ***attributes, int job_id = 0; read(fd, &job_id, sizeof (job_id)); papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE, - "job-id", job_id); + "job-id", job_id); close(fd); } |
