static int service_query(char *name, int (*report)(char *, papi_attribute_t **, int), papi_encryption_t encryption, int verbose) { int result = 0; papi_status_t status; papi_service_t svc = NULL; papi_attribute_t **attrs = NULL; status = papiServiceCreate(&svc, name, NULL, NULL, cli_auth_callback, encryption, NULL); if (status != PAPI_OK) { papiServiceDestroy(svc); return (-1); } attrs = papiServiceGetAttributeList(svc); if (attrs != NULL) { result = report(name, attrs, verbose); if (verbose > 1) { printf("\n"); papiAttributeListPrint(stdout, attrs, "\t"); printf("\n"); } } papiServiceDestroy(svc); return (result); }
static int lpstat_default_printer(papi_encryption_t encryption) { papi_status_t status; papi_service_t svc = NULL; papi_printer_t p = NULL; char *name = NULL; status = papiServiceCreate(&svc, NULL, NULL, NULL, cli_auth_callback, encryption, NULL); if (status == PAPI_OK) { char *req[] = { "printer-name", NULL }; status = papiPrinterQuery(svc, DEFAULT_DEST, req, NULL, &p); if (p != NULL) name = printer_name(p); } if (name != NULL) printf(gettext("system default printer: %s\n"), name); else printf(gettext("no system default destination\n")); papiPrinterFree(p); papiServiceDestroy(svc); return (0); }
int main(int ac, char *av[]) { papi_status_t status; papi_service_t svc = NULL; papi_encryption_t encryption = PAPI_ENCRYPT_NEVER; char *printer = NULL; int c; (void) setlocale(LC_ALL, ""); (void) textdomain("SUNW_OST_OSCMD"); while ((c = getopt(ac, av, "EP:")) != EOF) switch (c) { case 'E': encryption = PAPI_ENCRYPT_REQUIRED; break; case 'P': printer = optarg; break; default: usage(av[0]); } if ((printer == NULL) && ((printer = getenv("PRINTER")) == NULL) && ((printer = getenv("LPDEST")) == NULL)) printer = DEFAULT_DEST; 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)); papiServiceDestroy(svc); return (1); } berkeley_cancel_request(svc, stdout, printer, ac - optind, &av[optind]); papiServiceDestroy(svc); return (0); }
int cancel_jobs_for_user(char *user, papi_encryption_t encryption, char *pname) { papi_status_t status; papi_service_t svc = NULL; char **printers = NULL; int i, exit_code; if (pname == NULL) { status = papiServiceCreate(&svc, NULL, NULL, NULL, cli_auth_callback, encryption, NULL); printers = interest_list(svc); papiServiceDestroy(svc); } else { list_append(&printers, strdup(pname)); } if (printers == NULL) exit(0); for (i = 0; printers[i] != NULL; i++) { char *printer = printers[i]; 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); } exit_code = berkeley_cancel_request(svc, stdout, printer, 1, &user); papiServiceDestroy(svc); if (exit_code != 0) break; } free(printers); return (exit_code); }
int main(int ac, char *av[]) { papi_status_t status; papi_service_t svc = NULL; papi_encryption_t encryption = PAPI_ENCRYPT_NEVER; char *reason = NULL; int exit_status = 0; int c = 1; (void) setlocale(LC_ALL, ""); (void) textdomain("SUNW_OST_OSCMD"); while ((c = getopt(ac, av, "Er:")) != EOF) switch (c) { case 'r': /* reason */ reason = optarg; break; case 'E': encryption = PAPI_ENCRYPT_ALWAYS; break; default: usage(av[0]); } if (ac <= optind) usage(av[0]); while (optind < ac) { char *printer = av[optind++]; 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_status = 1; } status = papiPrinterPause(svc, printer, reason); if (status != PAPI_OK) { fprintf(stderr, gettext("reject: %s: %s\n"), printer, verbose_papi_message(svc, status)); exit_status = 1; } papiServiceDestroy(svc); } return (exit_status); }
papi_status_t ipp_process_request(papi_attribute_t **request, papi_attribute_t ***response, ipp_reader_t iread, void *fd) { papi_status_t result = PAPI_OK; ipp_initialize_response(request, response); #ifdef DEBUG fprintf(stderr, "REQUEST:"); papiAttributeListPrint(stderr, request, " %d ", getpid()); fprintf(stderr, "\n"); #endif /* verify that the request is "well-formed" */ if ((result = ipp_validate_request(request, response)) == PAPI_OK) { papi_service_t svc = NULL; ipp_handler_t *handler; result = print_service_connect(&svc, request, response); handler = ipp_operation_handler(request, response); /* process the request */ if ((result == PAPI_OK) && (handler != NULL)) result = (handler)(svc, request, response, iread, fd); #ifdef DEBUG fprintf(stderr, "RESULT: %s\n", papiStatusString(result)); #endif papiServiceDestroy(svc); } (void) papiAttributeListAddInteger(response, PAPI_ATTR_EXCL, "status-code", result); massage_response(request, *response); #ifdef DEBUG fprintf(stderr, "RESPONSE:"); papiAttributeListPrint(stderr, *response, " %d ", getpid()); fprintf(stderr, "\n"); #endif return (result); }
static int lpstat_service_status(papi_encryption_t encryption) { int result = 0; papi_status_t status; papi_service_t svc = NULL; char *name = NULL; if (((name = getenv("PAPI_SERVICE_URI")) == NULL) && ((name = getenv("IPP_SERVER")) == NULL) && ((name = getenv("CUPS_SERVER")) == NULL)) name = DEFAULT_SERVICE_URI; status = papiServiceCreate(&svc, name, NULL, NULL, cli_auth_callback, encryption, NULL); if (status != PAPI_OK) { printf(gettext("scheduler is not running\n")); result = -1; } else printf(gettext("scheduler is running\n")); papiServiceDestroy(svc); return (result); }
int main(int ac, char *av[]) { papi_status_t status; papi_service_t svc = NULL; papi_encryption_t encryption = PAPI_ENCRYPT_NEVER; char *reason = NULL; int exit_status = 0; int c = 1; (void) setlocale(LC_ALL, ""); (void) textdomain("SUNW_OST_OSCMD"); while ((c = getopt(ac, av, "Er:")) != EOF) switch (c) { case 'r': /* reason */ reason = optarg; break; case 'E': encryption = PAPI_ENCRYPT_ALWAYS; break; default: usage(av[0]); } if (ac <= optind) usage(av[0]); while (optind < ac) { char *printer = av[optind++]; 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_status = 1; } status = papiPrinterPause(svc, printer, reason); if (status == PAPI_OK) { printf(gettext( "Destination \"%s\" will no longer " "accept requests\n"), printer); } else if (status == PAPI_NOT_ACCEPTING) { fprintf(stderr, gettext( "Destination \"%s\" was already not " "accepting requests.\n"), printer); exit_status = 1; } else { /* The operation is not supported in lpd protocol */ if (status == PAPI_OPERATION_NOT_SUPPORTED) { fprintf(stderr, verbose_papi_message(svc, status)); } else { fprintf(stderr, gettext("reject: %s: %s\n"), printer, verbose_papi_message(svc, status)); } exit_status = 1; } papiServiceDestroy(svc); } return (exit_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 job_query(char *request, int (*report)(papi_job_t, int, int), papi_encryption_t encryption, int show_rank, int verbose) { int result = 0; papi_status_t status; papi_service_t svc = NULL; char *printer = NULL; int32_t id = -1; get_printer_id(request, &printer, &id); 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 ? printer : "all"), verbose_papi_message(svc, status)); return (-1); } if (printer == NULL) { /* all */ char **interest = interest_list(svc); if (interest != NULL) { int i; for (i = 0; interest[i] != NULL; i++) result += job_query(interest[i], report, encryption, show_rank, verbose); } } else if (id == -1) { /* a printer */ papi_job_t *jobs = NULL; status = papiPrinterListJobs(svc, printer, NULL, 0, 0, &jobs); if (status != PAPI_OK) { fprintf(stderr, gettext( "Failed to get job list: %s\n"), verbose_papi_message(svc, status)); papiServiceDestroy(svc); return (-1); } if (jobs != NULL) { int i; for (i = 0; jobs[i] != NULL; i++) result += report(jobs[i], show_rank, verbose); } papiJobListFree(jobs); } else { /* a job */ papi_job_t job = NULL; status = papiJobQuery(svc, printer, id, NULL, &job); if (status != PAPI_OK) { fprintf(stderr, gettext( "Failed to get job info for %s: %s\n"), request, verbose_papi_message(svc, status)); papiServiceDestroy(svc); return (-1); } if (job != NULL) result = report(job, show_rank, verbose); papiJobFree(job); } papiServiceDestroy(svc); return (result); }
static int printer_query(char *name, int (*report)(papi_service_t, char *, papi_printer_t, int, int), papi_encryption_t encryption, int verbose, int description) { int result = 0; papi_status_t status; papi_service_t svc = NULL; status = papiServiceCreate(&svc, name, NULL, NULL, cli_auth_callback, encryption, NULL); if (status != PAPI_OK) { fprintf(stderr, gettext( "Failed to contact service for %s: %s\n"), name ? name : "(NULL)", verbose_papi_message(svc, status)); papiServiceDestroy(svc); return (-1); } if (name == NULL) { /* all */ char **interest = interest_list(svc); if (interest != NULL) { int i; for (i = 0; interest[i] != NULL; i++) result += printer_query(interest[i], report, encryption, verbose, description); } } else { papi_printer_t printer = NULL; char **keys = NULL; /* * Limit the query to only required data to reduce the need * to go remote for information. */ if (report == report_device) keys = report_device_keys; else if (report == report_class) keys = report_class_keys; else if (report == report_accepting) keys = report_accepting_keys; else if ((report == report_printer) && (verbose == 0)) keys = report_printer_keys; status = papiPrinterQuery(svc, name, keys, NULL, &printer); if (status != PAPI_OK) { fprintf(stderr, gettext( "Failed to get printer info for %s: %s\n"), name, verbose_papi_message(svc, status)); papiServiceDestroy(svc); return (-1); } if (printer != NULL) result = report(svc, name, printer, verbose, description); papiPrinterFree(printer); } papiServiceDestroy(svc); return (result); }
int main(int ac, char *av[]) { int exit_code = 0; char *user = NULL; papi_encryption_t encryption = PAPI_ENCRYPT_NEVER; int c; int32_t rid = -1; int first_dest = 0; (void) setlocale(LC_ALL, ""); (void) textdomain("SUNW_OST_OSCMD"); if (ac == 1) usage(av[0]); while ((c = getopt(ac, av, "Eu:")) != EOF) switch (c) { case 'E': encryption = PAPI_ENCRYPT_REQUIRED; break; case 'u': user = optarg; break; default: usage(av[0]); } for (c = optind; c < ac; c++) { papi_status_t status; papi_service_t svc = NULL; papi_job_t *jobs = NULL; char *printer = NULL; int32_t id = -1; status = papiServiceCreate(&svc, av[c], NULL, NULL, cli_auth_callback, encryption, NULL); if (status != PAPI_OK) { if (first_dest == 0) { (void) get_printer_id(av[c], &printer, &id); 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); } } else { first_dest = 1; printer = av[c]; } #define OUT ((status == PAPI_OK) ? stdout : stderr) if (id != -1) { /* it's a job */ char *mesg = gettext("cancelled"); /* * Check if the job-id is job-id-requested * or job-id. If it is job-id-requested then find * corresponding job-id and send it to cancel */ rid = job_to_be_queried(svc, printer, id); if (rid < 0) { /* * Either it is a remote job which cannot be * cancelled based on job-id or job-id is * not found */ exit_code = 1; fprintf(OUT, "%s-%d: %s\n", printer, id, gettext("not-found")); } else { status = papiJobCancel(svc, printer, rid); if (status == PAPI_NOT_AUTHORIZED) { mesg = papiStatusString(status); exit_code = 1; } else if (status != PAPI_OK) { mesg = gettext( verbose_papi_message( svc, status)); exit_code = 1; } fprintf(OUT, "%s-%d: %s\n", printer, id, mesg); } } else { /* it's a printer */ if (user == NULL) { /* Remove first job from printer */ status = papiPrinterListJobs(svc, printer, NULL, NULL, 0, &jobs); if (status != PAPI_OK) { fprintf(stderr, gettext( "ListJobs %s: %s\n"), printer, verbose_papi_message(svc, status)); exit_code = 1; } if (jobs != NULL && *jobs != NULL) { char *mesg = gettext("cancelled"); id = papiJobGetId(*jobs); status = papiJobCancel(svc, printer, id); if (status == PAPI_NOT_AUTHORIZED) { mesg = papiStatusString(status); exit_code = 1; } else if (status != PAPI_OK) { mesg = gettext( verbose_papi_message( svc, status)); exit_code = 1; } /* * If job-id-requested exists for this * job-id then that should be displayed */ rid = get_job_id_requested(*jobs); if (rid >= 0) fprintf(OUT, "%s-%d: %s\n", printer, rid, mesg); else fprintf(OUT, "%s-%d: %s\n", printer, id, mesg); } papiJobListFree(jobs); } else { /* Purging user's print jobs */ exit_code = cancel_jobs_for_user(user, encryption, printer); } } papiServiceDestroy(svc); } if (optind == ac) exit_code = cancel_jobs_for_user(user, encryption, NULL); return (exit_code); }