diff options
| -rw-r--r-- | usr/src/cmd/lp/lib/papi/job.c | 168 | ||||
| -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 |
4 files changed, 233 insertions, 184 deletions
diff --git a/usr/src/cmd/lp/lib/papi/job.c b/usr/src/cmd/lp/lib/papi/job.c index f0840d1f4c..c0fc909af6 100644 --- a/usr/src/cmd/lp/lib/papi/job.c +++ b/usr/src/cmd/lp/lib/papi/job.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -95,7 +95,7 @@ papiJobGetPrinterName(papi_job_t job) if (tmp != NULL) papiAttributeListGetString(tmp->attributes, NULL, - "printer-name", &result); + "printer-name", &result); return (result); } @@ -108,7 +108,7 @@ papiJobGetId(papi_job_t job) if (tmp != NULL) papiAttributeListGetInteger(tmp->attributes, NULL, "job-id", - &result); + &result); return (result); } @@ -146,7 +146,7 @@ authorized(service_t *svc, int32_t id) if ((uid == 0) || (uid == 71)) { /* root/lp can forge this */ papi_status_t s; s = papiAttributeListGetString(svc->attributes, NULL, - "user-name", &user); + "user-name", &user); if (s != PAPI_OK) /* true root/lp are almighty */ result = PAPI_OK; } @@ -400,6 +400,7 @@ papiJobSubmit(papi_service_t handle, char *printer, { papi_status_t status; service_t *svc = handle; + struct stat statbuf; job_t *j; int file_no; char *request_id = NULL; @@ -417,13 +418,21 @@ papiJobSubmit(papi_service_t handle, char *printer, return (PAPI_OPERATION_NOT_SUPPORTED); if (files != NULL) - for (file_no = 0; files[file_no] != NULL; file_no++) + for (file_no = 0; files[file_no] != NULL; file_no++) { if (access(files[file_no], R_OK) < 0) { detailed_error(svc, - gettext("Cannot access file: %s: %s"), - files[file_no], strerror(errno)); + gettext("Cannot access file: %s: %s"), + files[file_no], strerror(errno)); return (PAPI_BAD_ARGUMENT); } + stat(files[file_no], &statbuf); + if (statbuf.st_size == 0) { + detailed_error(svc, + gettext("Zero byte (empty) file: %s"), + files[file_no]); + return (PAPI_BAD_ARGUMENT); + } + } if ((*job = j = calloc(1, sizeof (*j))) == NULL) return (PAPI_TEMPORARY_ERROR); @@ -434,17 +443,17 @@ papiJobSubmit(papi_service_t handle, char *printer, return (status); request = create_request(svc, (char *)printer, - (papi_attribute_t **)job_attributes); + (papi_attribute_t **)job_attributes); for (i = 0; files[i] != NULL; i++) { papi_status_t status; snprintf(lpfile, sizeof (lpfile), "%s%s-%d", - "/var/spool/lp/temp/", request_id, i+1); + "/var/spool/lp/temp/", request_id, i+1); status = copy_file(files[i], lpfile); if (status != PAPI_OK) { detailed_error(svc, - gettext("unable to copy: %s -> %s: %s"), - files[i], lpfile, strerror(errno)); + gettext("unable to copy: %s -> %s: %s"), + files[i], lpfile, strerror(errno)); freerequest(request); return (PAPI_DEVICE_ERROR); } @@ -459,11 +468,11 @@ papiJobSubmit(papi_service_t handle, char *printer, * interface script to process them */ snprintf(lpfile, sizeof (lpfile), "%s%s-%s", - "/var/spool/lp/temp/", request_id, LP_PAPIATTRNAME); + "/var/spool/lp/temp/", request_id, LP_PAPIATTRNAME); status = psm_copy_attrsToFile(job_attributes, lpfile); if (status != PAPI_OK) { detailed_error(svc, "unable to copy attributes to file: %s: %s", - lpfile, strerror(errno)); + lpfile, strerror(errno)); return (PAPI_DEVICE_ERROR); } #endif @@ -472,7 +481,7 @@ papiJobSubmit(papi_service_t handle, char *printer, snprintf(lpfile, sizeof (lpfile), "%s-0", request_id); if (putrequest(lpfile, request) < 0) { detailed_error(svc, gettext("unable to save request: %s: %s"), - lpfile, strerror(errno)); + lpfile, strerror(errno)); freerequest(request); return (PAPI_DEVICE_ERROR); } @@ -490,9 +499,9 @@ papiJobSubmit(papi_service_t handle, char *printer, if ((c = strrchr(tmp, '-')) != NULL) c++; papiAttributeListAddInteger(&j->attributes, PAPI_ATTR_REPLACE, - "job-id", atoi(c)); + "job-id", atoi(c)); papiAttributeListAddString(&j->attributes, PAPI_ATTR_REPLACE, - "job-uri", tmp); + "job-uri", tmp); return (PAPI_OK); } @@ -504,6 +513,7 @@ papiJobSubmitByReference(papi_service_t handle, char *printer, char **files, papi_job_t *job) { service_t *svc = handle; + struct stat statbuf; job_t *j; int file_no; short status; @@ -525,26 +535,34 @@ papiJobSubmitByReference(papi_service_t handle, char *printer, for (file_no = 0; files[file_no] != NULL; file_no++) { if (access(files[file_no], R_OK) < 0) { detailed_error(svc, - gettext("Cannot access file: %s: %s"), - files[file_no], strerror(errno)); + gettext("Cannot access file: %s: %s"), + files[file_no], strerror(errno)); return (PAPI_DOCUMENT_ACCESS_ERROR); } + stat(files[file_no], &statbuf); + if (statbuf.st_size == 0) { + detailed_error(svc, + gettext("Zero byte (empty) file: %s"), + files[file_no]); + return (PAPI_BAD_ARGUMENT); + } + if (files[file_no][0] != '/') { char path[MAXPATHLEN]; if (getcwd(path, sizeof (path)) == NULL) { detailed_error(svc, gettext( - "getcwd for file: %s: %s"), - files[file_no], - strerror(errno)); + "getcwd for file: %s: %s"), + files[file_no], + strerror(errno)); return (PAPI_DOCUMENT_ACCESS_ERROR); } strlcat(path, "/", sizeof (path)); if (strlcat(path, files[file_no], sizeof (path)) - >= sizeof (path)) { + >= sizeof (path)) { detailed_error(svc, gettext( - "pathname too long: %s"), - files[file_no]); + "pathname too long: %s"), + files[file_no]); return (PAPI_DOCUMENT_ACCESS_ERROR); } addlist(&file_list, path); @@ -561,7 +579,7 @@ papiJobSubmitByReference(papi_service_t handle, char *printer, return (status); request = create_request(svc, (char *)printer, - (papi_attribute_t **)job_attributes); + (papi_attribute_t **)job_attributes); request->file_list = file_list; #ifdef LP_USE_PAPI_ATTR @@ -572,11 +590,11 @@ papiJobSubmitByReference(papi_service_t handle, char *printer, * interface script to process them */ snprintf(lpfile, sizeof (lpfile), "%s%s-%s", - "/var/spool/lp/temp/", request_id, LP_PAPIATTRNAME); + "/var/spool/lp/temp/", request_id, LP_PAPIATTRNAME); status = psm_copy_attrsToFile(job_attributes, lpfile); if (status != PAPI_OK) { detailed_error(svc, "unable to copy attributes to file: %s: %s", - lpfile, strerror(errno)); + lpfile, strerror(errno)); return (PAPI_DEVICE_ERROR); } #endif @@ -585,7 +603,7 @@ papiJobSubmitByReference(papi_service_t handle, char *printer, snprintf(lpfile, sizeof (lpfile), "%s-0", request_id); if (putrequest(lpfile, request) < 0) { detailed_error(svc, gettext("unable to save request: %s: %s"), - lpfile, strerror(errno)); + lpfile, strerror(errno)); freerequest(request); return (PAPI_DEVICE_ERROR); } @@ -604,9 +622,9 @@ papiJobSubmitByReference(papi_service_t handle, char *printer, if ((c = strrchr(tmp, '-')) != NULL) c++; papiAttributeListAddInteger(&j->attributes, PAPI_ATTR_REPLACE, - "job-id", atoi(c)); + "job-id", atoi(c)); papiAttributeListAddString(&j->attributes, PAPI_ATTR_REPLACE, - "job-uri", tmp); + "job-uri", tmp); return (PAPI_OK); } @@ -622,13 +640,13 @@ papiJobValidate(papi_service_t handle, char *printer, int i; papiAttributeListAddString(&attributes, PAPI_ATTR_REPLACE, - "job-hold-until", "indefinite"); + "job-hold-until", "indefinite"); for (i = 0; job_attributes[i]; i++) list_append(&attributes, job_attributes[i]); status = papiJobSubmitByReference(handle, printer, - (papi_attribute_t **)attributes, - job_ticket, files, job); + (papi_attribute_t **)attributes, + job_ticket, files, job); if (status == PAPI_OK) { int id = papiJobGetId(*job); @@ -668,9 +686,9 @@ papiJobStreamOpen(papi_service_t handle, char *printer, return (status); s->request = create_request(svc, (char *)printer, - (papi_attribute_t **)job_attributes); + (papi_attribute_t **)job_attributes); snprintf(lpfile, sizeof (lpfile), "/var/spool/lp/temp/%s-1", - request_id); + request_id); s->fd = open(lpfile, O_WRONLY); addlist(&(s->request->file_list), lpfile); @@ -682,11 +700,11 @@ papiJobStreamOpen(papi_service_t handle, char *printer, * interface script to process them */ snprintf(lpfile, sizeof (lpfile), "%s%s-%s", - "/var/spool/lp/temp/", request_id, LP_PAPIATTRNAME); + "/var/spool/lp/temp/", request_id, LP_PAPIATTRNAME); status = psm_copy_attrsToFile(job_attributes, lpfile); if (status != PAPI_OK) { detailed_error(svc, "unable to copy attributes to file: %s: %s", - lpfile, strerror(errno)); + lpfile, strerror(errno)); close(s->fd); free(s); return (PAPI_DEVICE_ERROR); @@ -698,7 +716,7 @@ papiJobStreamOpen(papi_service_t handle, char *printer, s->meta_data_file = strdup(lpfile); if (putrequest(lpfile, s->request) < 0) { detailed_error(svc, gettext("unable to save request: %s: %s"), - lpfile, strerror(errno)); + lpfile, strerror(errno)); s->request = NULL; return (PAPI_DEVICE_ERROR); } @@ -750,9 +768,9 @@ papiJobStreamClose(papi_service_t handle, if ((c = strrchr(tmp, '-')) != NULL) c++; papiAttributeListAddInteger(&j->attributes, PAPI_ATTR_REPLACE, - "job-id", atoi(c)); + "job-id", atoi(c)); papiAttributeListAddString(&j->attributes, PAPI_ATTR_REPLACE, - "job-uri", tmp); + "job-uri", tmp); free(s->meta_data_file); } freerequest(s->request); @@ -772,15 +790,15 @@ papiJobQuery(papi_service_t handle, char *printer, int32_t job_id, char req_id[32]; short rc; char *form = NULL, - *request_id = NULL, - *charset = NULL, - *user = NULL, - *slabel = NULL, - *file = NULL; + *request_id = NULL, + *charset = NULL, + *user = NULL, + *slabel = NULL, + *file = NULL; time_t date = 0; size_t size = 0; short rank = 0, - state = 0; + state = 0; if ((handle == NULL) || (printer == NULL) || (job_id < 0)) return (PAPI_BAD_ARGUMENT); @@ -794,10 +812,10 @@ papiJobQuery(papi_service_t handle, char *printer, int32_t job_id, return (PAPI_SERVICE_UNAVAILABLE); if (rcv_msg(svc, R_INQUIRE_REQUEST_RANK, &rc, &request_id, - &user, &slabel, &size, &date, &state, &dest, &form, - &charset, &rank, &file) < 0) { + &user, &slabel, &size, &date, &state, &dest, &form, + &charset, &rank, &file) < 0) { detailed_error(svc, - gettext("failed to read response from scheduler")); + gettext("failed to read response from scheduler")); return (PAPI_DEVICE_ERROR); } @@ -808,7 +826,7 @@ papiJobQuery(papi_service_t handle, char *printer, int32_t job_id, return (PAPI_TEMPORARY_ERROR); job_status_to_attributes(j, request_id, user, slabel, size, date, state, - dest, form, charset, rank, file); + dest, form, charset, rank, file); snprintf(req_id, sizeof (req_id), "%d-0", job_id); lpsched_read_job_configuration(svc, j, req_id); @@ -836,7 +854,7 @@ papiJobMove(papi_service_t handle, char *printer, int32_t job_id, free(queue); if (papiAttributeListGetString(svc->attributes, NULL, "user-name", - &user) == PAPI_OK) { + &user) == PAPI_OK) { REQUEST *r = getrequest(req_id); if ((r != NULL) && (r->user != NULL) && @@ -878,7 +896,7 @@ papiJobCancel(papi_service_t handle, char *printer, int32_t job_id) free(dest); if (papiAttributeListGetString(svc->attributes, NULL, "user-name", - &user) == PAPI_OK) { + &user) == PAPI_OK) { REQUEST *r = getrequest(req_id); if ((r != NULL) && (r->user != NULL) && @@ -936,15 +954,15 @@ hold_release_job(papi_service_t handle, char *printer, } if (putrequest(file, r) < 0) { detailed_error(svc, - gettext("failed to write job: %s: %s"), - file, strerror(errno)); + gettext("failed to write job: %s: %s"), + file, strerror(errno)); freerequest(r); return (PAPI_DEVICE_ERROR); } freerequest(r); } else { detailed_error(svc, gettext("failed to read job: %s: %s"), - file, strerror(errno)); + file, strerror(errno)); return (PAPI_DEVICE_ERROR); } @@ -997,7 +1015,7 @@ papiJobModify(papi_service_t handle, char *printer, int32_t job_id, if ((r = getrequest(file)) != NULL) { job_attributes_to_lpsched_request(handle, r, - (papi_attribute_t **)attributes); + (papi_attribute_t **)attributes); #ifdef LP_USE_PAPI_ATTR /* * store the job attributes in the PAPI job attribute file @@ -1005,26 +1023,26 @@ papiJobModify(papi_service_t handle, char *printer, int32_t job_id, * modify the attributes in the file as per the new attributes */ snprintf(lpfile, sizeof (lpfile), "%s%d-%s", - "/var/spool/lp/temp/", job_id, LP_PAPIATTRNAME); + "/var/spool/lp/temp/", job_id, LP_PAPIATTRNAME); status = psm_modifyAttrsFile(attributes, lpfile); if (status != PAPI_OK) { detailed_error(svc, - "unable to modify the attributes file: %s: %s", - lpfile, strerror(errno)); + "unable to modify the attributes file: %s: %s", + lpfile, strerror(errno)); return (PAPI_DEVICE_ERROR); } #endif if (putrequest(file, r) < 0) { detailed_error(svc, - gettext("failed to write job: %s: %s"), - file, strerror(errno)); + gettext("failed to write job: %s: %s"), + file, strerror(errno)); freerequest(r); return (PAPI_DEVICE_ERROR); } } else { detailed_error(svc, gettext("failed to read job: %s: %s"), - file, strerror(errno)); + file, strerror(errno)); return (PAPI_DEVICE_ERROR); } @@ -1032,7 +1050,7 @@ papiJobModify(papi_service_t handle, char *printer, int32_t job_id, lpsched_request_to_job_attributes(r, j); papiAttributeListAddInteger(&j->attributes, PAPI_ATTR_REPLACE, - "job-id", job_id); + "job-id", job_id); freerequest(r); @@ -1074,7 +1092,7 @@ papiJobCreate(papi_service_t handle, char *printer, /* convert the attributes to an lpsched REQUEST structure */ request = create_request(svc, (char *)printer, - (papi_attribute_t **)job_attributes); + (papi_attribute_t **)job_attributes); if (request == NULL) return (PAPI_TEMPORARY_ERROR); addlist(&request->file_list, DUMMY_FILE); /* add a dummy file */ @@ -1088,11 +1106,11 @@ papiJobCreate(papi_service_t handle, char *printer, * interface script to process them */ snprintf(metadata_file, sizeof (metadata_file), "%s%s-%s", - "/var/spool/lp/temp/", request_id, LP_PAPIATTRNAME); + "/var/spool/lp/temp/", request_id, LP_PAPIATTRNAME); status = psm_copy_attrsToFile(job_attributes, metadata_file); if (status != PAPI_OK) { detailed_error(svc, "unable to copy attributes to file: %s: %s", - metadata_file, strerror(errno)); + metadata_file, strerror(errno)); free(request_id); return (PAPI_DEVICE_ERROR); } @@ -1103,7 +1121,7 @@ papiJobCreate(papi_service_t handle, char *printer, free(request_id); if (putrequest(metadata_file, request) < 0) { detailed_error(svc, gettext("unable to save request: %s: %s"), - metadata_file, strerror(errno)); + metadata_file, strerror(errno)); return (PAPI_DEVICE_ERROR); } @@ -1118,9 +1136,9 @@ papiJobCreate(papi_service_t handle, char *printer, if ((c = strrchr(tmp, '-')) != NULL) c++; papiAttributeListAddInteger(&j->attributes, PAPI_ATTR_REPLACE, - "job-id", atoi(c)); + "job-id", atoi(c)); papiAttributeListAddString(&j->attributes, PAPI_ATTR_REPLACE, - "job-uri", tmp); + "job-uri", tmp); return (PAPI_OK); } @@ -1150,14 +1168,14 @@ papiJobCommit(papi_service_t handle, char *printer, int32_t id) if (putrequest(metadata_file, r) < 0) { detailed_error(svc, - gettext("failed to write job: %s: %s"), - metadata_file, strerror(errno)); + gettext("failed to write job: %s: %s"), + metadata_file, strerror(errno)); freerequest(r); return (PAPI_DEVICE_ERROR); } } else { detailed_error(svc, gettext("failed to read job: %s: %s"), - metadata_file, strerror(errno)); + metadata_file, strerror(errno)); return (PAPI_DEVICE_ERROR); } @@ -1187,7 +1205,7 @@ papiJobStreamAdd(papi_service_t handle, char *printer, int32_t id, snprintf(path, sizeof (path), "/var/spool/lp/temp/%d-XXXXXX", id); if ((s->fd = mkstemp(path)) < 0) { detailed_error(svc, gettext("unable to create sink (%s): %s"), - path, strerror(errno)); + path, strerror(errno)); free(s); return (PAPI_NOT_AUTHORIZED); } @@ -1203,7 +1221,7 @@ papiJobStreamAdd(papi_service_t handle, char *printer, int32_t id, if ((s->request = getrequest(metadata_file)) == NULL) { detailed_error(svc, gettext("unable to load request: %s: %s"), - metadata_file, strerror(errno)); + metadata_file, strerror(errno)); close(s->fd); free(s); unlink(path); @@ -1214,7 +1232,7 @@ papiJobStreamAdd(papi_service_t handle, char *printer, int32_t id, if (putrequest(metadata_file, s->request) < 0) { detailed_error(svc, gettext("unable to save request: %s: %s"), - metadata_file, strerror(errno)); + metadata_file, strerror(errno)); close(s->fd); free(s); unlink(path); 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); } |
