static papi_status_t ipp_write_message_header(ipp_writer_t iwrite, void *fd, papi_attribute_t **message) { int tmp; int8_t c; uint16_t s; int32_t i; /* write the version */ papiAttributeListGetInteger(message, NULL, "version-major", &tmp); c = tmp; if (iwrite(fd, &c, 1) != 1) return (PAPI_DEVICE_ERROR); papiAttributeListGetInteger(message, NULL, "version-minor", &tmp); c = tmp; if (iwrite(fd, &c, 1) != 1) return (PAPI_DEVICE_ERROR); /* write the request/status code */ papiAttributeListGetInteger(message, NULL, "status-code", &tmp); papiAttributeListGetInteger(message, NULL, "operation-id", &tmp); s = (uint16_t)htons(tmp); if (iwrite(fd, &s, 2) != 2) return (PAPI_DEVICE_ERROR); /* write the request id */ papiAttributeListGetInteger(message, NULL, "request-id", &tmp); i = (uint32_t)htonl(tmp); if (iwrite(fd, &i, 4) != 4) return (PAPI_DEVICE_ERROR); return (PAPI_OK); }
static ipp_handler_t * ipp_operation_handler(papi_attribute_t **request, papi_attribute_t ***response) { int id = 0; int index; papi_attribute_t **ops = NULL; papi_status_t status; char configured = PAPI_FALSE; /* get the operation from the request */ status = papiAttributeListGetInteger(request, NULL, "operation-id", &id); if (status != PAPI_OK) { ipp_set_status(response, PAPI_BAD_ARGUMENT, "no operation specified in request"); return (default_handler); } /* find the operation in the handler table */ index = ipp_operation_id_to_index(id); #ifdef DEBUG if (index == -1) fprintf(stderr, "Operation: 0x%4.4x\n", id); else fprintf(stderr, "Operation: 0x%4.4x(%s)\n", id, handlers[index].name); fflush(stderr); #endif if ((index == -1) || (handlers[index].function == NULL)) { ipp_set_status(response, PAPI_OPERATION_NOT_SUPPORTED, "operation (0x%4.4x) not implemented by server", id); return (default_handler); } /* find the configured operations */ status = papiAttributeListGetCollection(request, NULL, "operations", &ops); if (status != PAPI_OK) { /* this should not be possible */ ipp_set_status(response, PAPI_INTERNAL_ERROR, "sofware error, no operations configured"); return (default_handler); } /* check if the requested operation is configured */ status = papiAttributeListGetBoolean(ops, NULL, handlers[index].name, &configured); if ((status != PAPI_OK) || (configured != PAPI_TRUE)) { ipp_set_status(response, PAPI_OPERATION_NOT_SUPPORTED, "operation (%s 0x%4.4x) not enabled on server", handlers[index].name, id); return (default_handler); } return (handlers[index].function); }
static int32_t get_job_id_requested(papi_job_t job) { int32_t rid = -1; papi_attribute_t **list = papiJobGetAttributeList(job); papiAttributeListGetInteger(list, NULL, "job-id-requested", &rid); return (rid); }
int32_t papiJobGetId(papi_job_t job) { job_t *tmp = (job_t *)job; int result = -1; if (tmp != NULL) papiAttributeListGetInteger(tmp->attributes, NULL, "job-id", &result); return (result); }
/* ARGSUSED0 */ static papi_status_t default_handler(papi_service_t svc, papi_attribute_t **request, papi_attribute_t ***response, ipp_reader_t iread, void *fd) { int result = (int)PAPI_INTERNAL_ERROR; if (response != NULL) (void) papiAttributeListGetInteger(*response, NULL, "status-code", &result); return ((papi_status_t)result); }
papi_encryption_t papiServiceGetEncryption(papi_service_t handle) { service_t *svc = handle; papi_encryption_t result = PAPI_ENCRYPT_NEVER; if (svc != NULL) papiAttributeListGetInteger(svc->attributes, NULL, "encryption", (int *)&result); return (result); }
static papi_status_t ipp_initialize_response(papi_attribute_t **request, papi_attribute_t ***response) { papi_attribute_t **operational = NULL; int i; if ((request == NULL) || (response == NULL)) return (PAPI_BAD_ARGUMENT); /* If the response was initialized, start over */ if (*response != NULL) { papiAttributeListFree(*response); *response = NULL; } /* Add the basic ipp header information to the response */ (void) papiAttributeListGetInteger(request, NULL, "version-major", &i); (void) papiAttributeListAddInteger(response, PAPI_ATTR_REPLACE, "version-major", i); (void) papiAttributeListGetInteger(request, NULL, "version-minor", &i); (void) papiAttributeListAddInteger(response, PAPI_ATTR_REPLACE, "version-minor", i); (void) papiAttributeListGetInteger(request, NULL, "request-id", &i); (void) papiAttributeListAddInteger(response, PAPI_ATTR_REPLACE, "request-id", i); /* Add a default operational attributes group to the response */ (void) papiAttributeListAddString(&operational, PAPI_ATTR_EXCL, "attributes-charset", "utf-8"); (void) papiAttributeListAddString(&operational, PAPI_ATTR_EXCL, "attributes-natural-language", "en-us"); (void) papiAttributeListAddCollection(response, PAPI_ATTR_REPLACE, "operational-attributes-group", operational); papiAttributeListFree(operational); return (PAPI_OK); }
static papi_status_t print_service_connect(papi_service_t *svc, papi_attribute_t **request, papi_attribute_t ***response) { papi_status_t status; papi_attribute_t **operational = NULL; char *printer_uri = NULL; char *svc_name = NULL; char *user = NULL; /* Get the operational attributes group from the request */ (void) papiAttributeListGetCollection(request, NULL, "operational-attributes-group", &operational); /* get the user name */ (void) papiAttributeListGetString(request, NULL, "default-user", &user); (void) papiAttributeListGetString(operational, NULL, "requesting-user-name", &user); /* get the printer or service name */ (void) papiAttributeListGetString(request, NULL, "default-service", &svc_name); get_printer_id(operational, &svc_name, NULL); status = papiServiceCreate(svc, svc_name, user, NULL, NULL, PAPI_ENCRYPT_NEVER, NULL); if (status != PAPI_OK) { ipp_set_status(response, status, "print service: %s", papiStatusString(status)); return (status); } /* * Trusted Solaris can't be trusting of intermediaries. Pass * the socket connection to the print service to retrieve the * sensativity label off of a multi-level port. */ { int fd = -1; (void) papiAttributeListGetInteger(request, NULL, "peer-socket", &fd); if (fd != -1) papiServiceSetPeer(*svc, fd); } return (status); }
int main(int ac, char *av[]) { papi_status_t status; papi_service_t svc = NULL; papi_attribute_t **list = NULL; papi_encryption_t encryption = PAPI_ENCRYPT_NEVER; papi_job_t job = NULL; char prefetch[3]; int prefetch_len = sizeof (prefetch); char *printer = NULL; char b = PAPI_TRUE; int copy = 0; int silent = 0; int dump = 0; int validate = 0; int modify = -1; int c; uid_t ruid; struct passwd *pw; (void) setlocale(LC_ALL, ""); (void) textdomain("SUNW_OST_OSCMD"); ruid = getuid(); if ((pw = getpwuid(ruid)) != NULL) (void) initgroups(pw->pw_name, pw->pw_gid); (void) setuid(ruid); while ((c = getopt(ac, av, "DEH:P:S:T:cd:f:i:mn:o:pq:rst:Vwy:")) != EOF) switch (c) { case 'H': /* handling */ if (strcasecmp(optarg, "hold") == 0) papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "job-hold-until", "indefinite"); else if (strcasecmp(optarg, "immediate") == 0) papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "job-hold-until", "no-hold"); else papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "job-hold-until", optarg); break; case 'P': { /* page list */ char buf[BUFSIZ]; snprintf(buf, sizeof (buf), "page-ranges=%s", optarg); papiAttributeListFromString(&list, PAPI_ATTR_EXCL, buf); } break; case 'S': /* charset */ papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "lp-charset", optarg); break; case 'T': /* type */ papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "document-format", lp_type_to_mime_type(optarg)); break; case 'D': /* dump */ dump = 1; break; case 'c': /* copy */ copy = 1; break; case 'd': /* destination */ printer = optarg; break; case 'f': /* form */ papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "form", optarg); break; case 'i': /* modify job */ if ((get_printer_id(optarg, &printer, &modify) < 0) || (modify < 0)) { fprintf(stderr, gettext("invalid request id: %s\n"), optarg); exit(1); } break; case 'm': /* mail when complete */ papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL, "rfc-1179-mail", 1); break; case 'n': /* copies */ papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, "copies", atoi(optarg)); break; case 'o': /* lp "options" */ papiAttributeListFromString(&list, PAPI_ATTR_REPLACE, optarg); break; case 'p': /* Solaris - notification */ papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL, "rfc-1179-mail", 1); break; case 'q': { /* priority */ int i = atoi(optarg); i = 100 - (i * 2.5); if ((i < 1) || (i > 100)) { fprintf(stderr, gettext("UX:lp: ")); fprintf(stderr, gettext("ERROR: ")); fprintf(stderr, gettext("Bad priority" " value \"%s\"."), optarg); fprintf(stderr, gettext("\n ")); fprintf(stderr, gettext("TO FIX")); fprintf(stderr, gettext(": ")); fprintf(stderr, gettext("Use an integer value" " from 0 to 39.")); fprintf(stderr, gettext("\n")); exit(1); } papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, "job-priority", i); } break; case 'r': /* "raw" mode */ papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "document-format", "application/octet-stream"); papiAttributeListAddString(&list, PAPI_ATTR_APPEND, "stty", "raw"); break; case 's': /* suppress message */ silent = 1; break; case 't': /* title */ papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "job-name", optarg); break; case 'V': /* validate */ validate = 1; break; case 'w': papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL, "rfc-1179-mail", 1); break; case 'y': /* lp "modes" */ papiAttributeListAddString(&list, PAPI_ATTR_APPEND, "lp-modes", optarg); break; case 'E': encryption = PAPI_ENCRYPT_REQUIRED; break; default: usage(av[0]); } /* convert "banner", "nobanner" to "job-sheet" */ if (papiAttributeListGetBoolean(list, NULL, "banner", &b) == PAPI_OK) { (void) papiAttributeListDelete(&list, "banner"); if (b == PAPI_FALSE) papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "job-sheets", "none"); } if ((printer == NULL) && ((printer = getenv("PRINTER")) == NULL) && ((printer = getenv("LPDEST")) == NULL)) printer = DEFAULT_DEST; if (((optind + 1) == ac) && (strcmp(av[optind], "-") == 0)) optind = ac; if (modify == -1) { char *document_format = "text/plain"; if (optind != ac) { /* get the mime type of the file data */ #ifdef MAGIC_MIME magic_t ms = NULL; if ((ms = magic_open(MAGIC_MIME)) != NULL) { document_format = magic_file(ms, av[optind]); magic_close(ms); } #else if (is_postscript(av[optind]) == 1) document_format = "application/postscript"; #endif } else { if (is_postscript_stream(0, prefetch, &prefetch_len) == 1) document_format = "application/postscript"; } papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, "copies", 1); papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "document-format", document_format); papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "job-sheets", "standard"); } status = papiServiceCreate(&svc, printer, NULL, NULL, cli_auth_callback, encryption, NULL); if (status != PAPI_OK) { fprintf(stderr, gettext( "Failed to contact service for %s: %s\n"), printer, verbose_papi_message(svc, status)); exit(1); } if (dump != 0) { printf("requesting attributes:\n"); papiAttributeListPrint(stdout, list, "\t"); printf("\n"); } if (modify != -1) status = papiJobModify(svc, printer, modify, list, &job); else if (optind == ac) /* no file list, use stdin */ status = jobSubmitSTDIN(svc, printer, prefetch, prefetch_len, list, &job); else if (validate == 1) /* validate the request can be processed */ status = papiJobValidate(svc, printer, list, NULL, &av[optind], &job); else if (copy == 0) /* reference the files in the job, default */ status = papiJobSubmitByReference(svc, printer, list, NULL, &av[optind], &job); else /* copy the files before return, -c */ status = papiJobSubmit(svc, printer, list, NULL, &av[optind], &job); papiAttributeListFree(list); if (status != PAPI_OK) { fprintf(stderr, gettext("%s: %s\n"), printer, verbose_papi_message(svc, status)); papiJobFree(job); papiServiceDestroy(svc); exit(1); } if (((silent == 0) || (dump != 0)) && ((list = papiJobGetAttributeList(job)) != NULL)) { int32_t id = -1; if (printer == NULL) papiAttributeListGetString(list, NULL, "printer-name", &printer); papiAttributeListGetInteger(list, NULL, "job-id-requested", &id); if (id == -1) { papiAttributeListGetInteger(list, NULL, "job-id", &id); } printf(gettext("request id is %s-%d "), printer, id); if (ac != optind) printf("(%d file(s))\n", ac - optind); else printf("(standard input)\n"); if (dump != 0) { printf("job attributes:\n"); papiAttributeListPrint(stdout, list, "\t"); printf("\n"); } } papiJobFree(job); papiServiceDestroy(svc); return (0); }
static int report_job(papi_job_t job, int show_rank, int verbose) { papi_attribute_t **attrs = papiJobGetAttributeList(job); time_t clock = 0; char date[24]; char request[26]; char *user = "******"; int32_t size = 0; int32_t jstate = 0; char *destination = "unknown"; int32_t id = -1; (void) papiAttributeListGetString(attrs, NULL, "job-originating-user-name", &user); if ((users != NULL) && (match_user(user, users) < 0)) return (0); (void) papiAttributeListGetInteger(attrs, NULL, "job-k-octets", &size); size *= 1024; /* for the approximate byte size */ (void) papiAttributeListGetInteger(attrs, NULL, "job-octets", &size); (void) time(&clock); (void) papiAttributeListGetInteger(attrs, NULL, "time-at-creation", (int32_t *)&clock); (void) strftime(date, sizeof (date), "%b %d %R", localtime(&clock)); (void) papiAttributeListGetString(attrs, NULL, "job-printer-uri", &destination); (void) papiAttributeListGetString(attrs, NULL, "printer-name", &destination); (void) papiAttributeListGetInteger(attrs, NULL, "job-id", &id); snprintf(request, sizeof (request), "%s-%d", destination, id); if (show_rank != 0) { int32_t rank = -1; (void) papiAttributeListGetInteger(attrs, NULL, "number-of-intervening-jobs", &rank); rank++; printf("%3d %-21s %-14s %7ld %s", rank, request, user, size, date); } else printf("%-23s %-14s %7ld %s", request, user, size, date); (void) papiAttributeListGetInteger(attrs, NULL, "job-state", &jstate); if (jstate == 0x04) printf(gettext(", being held")); else if (jstate == 0x07) printf(gettext(", cancelled")); else if (jstate == 0x09) printf(gettext(", complete")); if (verbose == 1) { (void) papiAttributeListGetString(attrs, NULL, "output-device-assigned", &destination); printf("\n\t assigned %s", destination); } else if (verbose > 1) { printf("\n"); papiAttributeListPrint(stdout, attrs, "\t"); } printf("\n"); return (0); }
/* ARGSUSED2 */ static int report_printer(papi_service_t svc, char *name, papi_printer_t printer, int verbose, int description) { papi_status_t status; papi_attribute_t **attrs = papiPrinterGetAttributeList(printer); time_t curr; int32_t pstat = 0; char *member = NULL; status = papiAttributeListGetString(attrs, NULL, "member-names", &member); if (status == PAPI_OK) /* it's a class */ return (0); if (name == NULL) { status = papiAttributeListGetString(attrs, NULL, "printer-name", &name); if (status != PAPI_OK) status = papiAttributeListGetString(attrs, NULL, "printer-uri-supported", &name); } if (name == NULL) return (-1); printf(gettext("printer %s "), name); status = papiAttributeListGetInteger(attrs, NULL, "printer-state", &pstat); switch (pstat) { case 0x03: /* idle */ printf(gettext("idle. enabled")); break; case 0x04: { /* processing */ char *requested[] = { "job-id", NULL }; papi_job_t *j = NULL; int32_t jobid = 0; (void) papiPrinterListJobs(svc, name, requested, 0, 1, &j); if ((j != NULL) && (j[0] != NULL)) jobid = papiJobGetId(j[0]); papiJobListFree(j); printf(gettext("now printing %s-%d. enabled"), name, jobid); } break; case 0x05: /* stopped */ printf(gettext("disabled")); break; default: printf(gettext("unknown state(0x%x)."), pstat); break; } (void) time(&curr); (void) papiAttributeListGetDatetime(attrs, NULL, "printer-up-time", &curr); (void) papiAttributeListGetDatetime(attrs, NULL, "printer-state-time", &curr); (void) papiAttributeListGetDatetime(attrs, NULL, "lpsched-disable-date", &curr); printf(gettext(" since %s. available.\n"), nctime(&curr)); if (pstat == 0x05) { char *reason = "unknown reason"; (void) papiAttributeListGetString(attrs, NULL, "printer-state-reasons", &reason); (void) papiAttributeListGetString(attrs, NULL, "lpsched-disable-reason", &reason); printf(gettext("\t%s\n"), reason); } if (verbose == 1) { void *iter; char *str; str = ""; (void) papiAttributeListGetString(attrs, NULL, "form-ready", &str); printf(gettext("\tForm mounted: %s\n"), str); str = ""; iter = NULL; (void) papiAttributeListGetString(attrs, &iter, "document-format-supported", &str); printf(gettext("\tContent types: %s"), str); while (papiAttributeListGetString(attrs, &iter, NULL, &str) == PAPI_OK) printf(", %s", str); printf("\n"); str = ""; (void) papiAttributeListGetString(attrs, NULL, "printer-info", &str); printf(gettext("\tDescription: %s\n"), str); str = ""; (void) papiAttributeListGetString(attrs, NULL, "lpsched-dial-info", &str); printf(gettext("\tConnection: %s\n"), ((str[0] != '\0') ? gettext("direct") : str)); str = ""; (void) papiAttributeListGetString(attrs, NULL, "lpsched-interface-script", &str); printf(gettext("\tInterface: %s\n"), str); str = NULL; (void) papiAttributeListGetString(attrs, NULL, "ppd-file-uri", &str); (void) papiAttributeListGetString(attrs, NULL, "lpsched-ppd-source-path", &str); if (str != NULL) printf(gettext("\tPPD: %s\n"), str); str = NULL; (void) papiAttributeListGetString(attrs, NULL, "lpsched-fault-alert-command", &str); if (str != NULL) printf(gettext("\tOn fault: %s\n"), str); str = ""; (void) papiAttributeListGetString(attrs, NULL, "lpsched-fault-recovery", &str); printf(gettext("\tAfter fault: %s\n"), ((str[0] == '\0') ? gettext("continue") : str)); str = "(all)"; iter = NULL; (void) papiAttributeListGetString(attrs, &iter, "requesting-user-name-allowed", &str); printf(gettext("\tUsers allowed:\n\t\t%s\n"), ((str[0] == '\0') ? gettext("(none)") : str)); if ((str != NULL) && (str[0] != '\0')) while (papiAttributeListGetString(attrs, &iter, NULL, &str) == PAPI_OK) printf("\t\t%s\n", str); str = NULL; iter = NULL; (void) papiAttributeListGetString(attrs, &iter, "requesting-user-name-denied", &str); if (str != NULL) { printf(gettext("\tUsers denied:\n\t\t%s\n"), ((str[0] == '\0') ? gettext("(none)") : str)); if ((str != NULL) && (str[0] != '\0')) while (papiAttributeListGetString(attrs, &iter, NULL, &str) == PAPI_OK) printf("\t\t%s\n", str); } str = "(none)"; iter = NULL; (void) papiAttributeListGetString(attrs, &iter, "form-supported", &str); printf(gettext("\tForms allowed:\n\t\t%s\n"), ((str[0] == '\0') ? gettext("(none)") : str)); if ((str != NULL) && (str[0] != '\0')) while (papiAttributeListGetString(attrs, &iter, NULL, &str) == PAPI_OK) printf("\t\t%s\n", str); str = ""; iter = NULL; (void) papiAttributeListGetString(attrs, &iter, "media-supported", &str); printf(gettext("\tMedia supported:\n\t\t%s\n"), ((str[0] == '\0') ? gettext("(none)") : str)); if ((str != NULL) && (str[0] != '\0')) while (papiAttributeListGetString(attrs, &iter, NULL, &str) == PAPI_OK) printf("\t\t%s\n", str); str = ""; (void) papiAttributeListGetString(attrs, NULL, "job-sheets-supported", &str); printf(gettext("\tBanner %s\n"), (strcasecmp(str, "none") == 0 ? gettext("not required") : gettext("required"))); str = ""; iter = NULL; (void) papiAttributeListGetString(attrs, &iter, "lpsched-print-wheels", &str); printf(gettext("\tCharacter sets:\n\t\t%s\n"), ((str[0] == '\0') ? gettext("(none)") : str)); if ((str != NULL) && (str[0] != '\0')) while (papiAttributeListGetString(attrs, &iter, NULL, &str) == PAPI_OK) printf("\t\t%s\n", str); printf(gettext("\tDefault pitch:\n")); printf(gettext("\tDefault page size:\n")); printf(gettext("\tDefault port setting:\n")); str = ""; iter = NULL; (void) papiAttributeListGetString(attrs, &iter, "lpsched-options", &str); if (str != NULL) { printf(gettext("\tOptions: %s"), str); while (papiAttributeListGetString(attrs, &iter, NULL, &str) == PAPI_OK) printf(", %s", str); printf("\n"); } } else if (description == 1) { char *str = ""; (void) papiAttributeListGetString(attrs, NULL, "printer-description", &str); printf(gettext("\tDescription: %s\n"), str); } else if (verbose > 1) papiAttributeListPrint(stdout, attrs, "\t"); if (verbose > 0) printf("\n"); return (0); }