12264Sjacobs /* 22264Sjacobs * CDDL HEADER START 32264Sjacobs * 42264Sjacobs * The contents of this file are subject to the terms of the 52264Sjacobs * Common Development and Distribution License (the "License"). 62264Sjacobs * You may not use this file except in compliance with the License. 72264Sjacobs * 82264Sjacobs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 92264Sjacobs * or http://www.opensolaris.org/os/licensing. 102264Sjacobs * See the License for the specific language governing permissions 112264Sjacobs * and limitations under the License. 122264Sjacobs * 132264Sjacobs * When distributing Covered Code, include this CDDL HEADER in each 142264Sjacobs * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 152264Sjacobs * If applicable, add the following below this CDDL HEADER, with the 162264Sjacobs * fields enclosed by brackets "[]" replaced with your own identifying 172264Sjacobs * information: Portions Copyright [yyyy] [name of copyright owner] 182264Sjacobs * 192264Sjacobs * CDDL HEADER END 202264Sjacobs */ 212264Sjacobs 222264Sjacobs /* 234062Sjacobs * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 242264Sjacobs * Use is subject to license terms. 252264Sjacobs * 262264Sjacobs */ 272264Sjacobs 282264Sjacobs /* $Id: lpstat.c 173 2006-05-25 04:52:06Z njacobs $ */ 292264Sjacobs 302264Sjacobs #pragma ident "%Z%%M% %I% %E% SMI" 312264Sjacobs 322264Sjacobs #include <stdio.h> 332264Sjacobs #include <stdlib.h> 342264Sjacobs #include <unistd.h> 352264Sjacobs #include <string.h> 362264Sjacobs #include <locale.h> 372264Sjacobs #include <libintl.h> 38*4286Swendyp #include <ctype.h> 392264Sjacobs #include <pwd.h> 402264Sjacobs #include <papi.h> 412264Sjacobs #include <uri.h> 422264Sjacobs #include "common.h" 432264Sjacobs 442264Sjacobs static void 452264Sjacobs usage(char *program) 462264Sjacobs { 472264Sjacobs char *name; 482264Sjacobs 492264Sjacobs if ((name = strrchr(program, '/')) == NULL) 502264Sjacobs name = program; 512264Sjacobs else 522264Sjacobs name++; 532264Sjacobs 542264Sjacobs fprintf(stdout, gettext("Usage: %s [-d] [-r] [-s] [-t] [-a [list]] " 552264Sjacobs "[-c [list]] [-o [list] [-l]] [-R [list] [-l]] " 562264Sjacobs "[-p [list] [-D] [-l]] [-v [list]] [-S [list] [-l]] " 572264Sjacobs "[-f [list] [-l]] [-u list]\n"), 582264Sjacobs name); 592264Sjacobs exit(1); 602264Sjacobs } 612264Sjacobs 622264Sjacobs static char * 632264Sjacobs nctime(time_t *t) 642264Sjacobs { 652264Sjacobs static char buf[64]; 662264Sjacobs struct tm *tm = localtime(t); 672264Sjacobs 682264Sjacobs (void) strftime(buf, sizeof (buf), "%c", tm); 692264Sjacobs 702264Sjacobs return (buf); 712264Sjacobs } 722264Sjacobs 732264Sjacobs static char * 742264Sjacobs printer_name(papi_printer_t printer) 752264Sjacobs { 762264Sjacobs papi_attribute_t **attributes = papiPrinterGetAttributeList(printer); 772264Sjacobs char *result = NULL; 782264Sjacobs 792264Sjacobs if (attributes != NULL) 802264Sjacobs papiAttributeListGetString(attributes, NULL, 812264Sjacobs "printer-name", &result); 822264Sjacobs 832264Sjacobs return (result); 842264Sjacobs } 852264Sjacobs 862264Sjacobs static int 872264Sjacobs lpstat_default_printer(papi_encryption_t encryption) 882264Sjacobs { 892264Sjacobs papi_status_t status; 902264Sjacobs papi_service_t svc = NULL; 912264Sjacobs papi_printer_t p = NULL; 922264Sjacobs char *name = NULL; 932264Sjacobs 942264Sjacobs status = papiServiceCreate(&svc, NULL, NULL, NULL, cli_auth_callback, 952264Sjacobs encryption, NULL); 962264Sjacobs if (status == PAPI_OK) { 972264Sjacobs char *req[] = { "printer-name", NULL }; 982264Sjacobs 992264Sjacobs status = papiPrinterQuery(svc, DEFAULT_DEST, req, NULL, &p); 1002264Sjacobs if (p != NULL) 1012264Sjacobs name = printer_name(p); 1022264Sjacobs } 1032264Sjacobs if (name != NULL) 1042264Sjacobs printf(gettext("system default printer: %s\n"), name); 1052264Sjacobs else 1062264Sjacobs printf(gettext("no system default destination\n")); 1072264Sjacobs papiPrinterFree(p); 1082264Sjacobs papiServiceDestroy(svc); 1092264Sjacobs 1102264Sjacobs return (0); 1112264Sjacobs } 1122264Sjacobs 1132264Sjacobs static int 1142264Sjacobs lpstat_service_status(papi_encryption_t encryption) 1152264Sjacobs { 1162264Sjacobs int result = 0; 1172264Sjacobs papi_status_t status; 1182264Sjacobs papi_service_t svc = NULL; 1192264Sjacobs char *name = NULL; 1202264Sjacobs 1212264Sjacobs if (((name = getenv("PAPI_SERVICE_URI")) == NULL) && 1222264Sjacobs ((name = getenv("IPP_SERVER")) == NULL) && 1232264Sjacobs ((name = getenv("CUPS_SERVER")) == NULL)) 1242264Sjacobs name = DEFAULT_SERVICE_URI; 1252264Sjacobs 1262264Sjacobs status = papiServiceCreate(&svc, name, NULL, NULL, cli_auth_callback, 1272264Sjacobs encryption, NULL); 1282264Sjacobs if (status != PAPI_OK) { 1292264Sjacobs printf(gettext("scheduler is not running\n")); 1302264Sjacobs result = -1; 1312264Sjacobs } else 1322264Sjacobs printf(gettext("scheduler is running\n")); 1332264Sjacobs papiServiceDestroy(svc); 1342264Sjacobs 1352264Sjacobs return (result); 1362264Sjacobs } 1372264Sjacobs 1382264Sjacobs static char * 1392264Sjacobs get_device_uri(papi_service_t svc, char *name) 1402264Sjacobs { 1412264Sjacobs papi_status_t status; 1422264Sjacobs papi_printer_t p = NULL; 1432264Sjacobs char *keys[] = { "device-uri", NULL }; 1442264Sjacobs char *result = NULL; 1452264Sjacobs 1462264Sjacobs status = papiPrinterQuery(svc, name, keys, NULL, &p); 1472264Sjacobs if ((status == PAPI_OK) && (p != NULL)) { 1482264Sjacobs papi_attribute_t **attrs = papiPrinterGetAttributeList(p); 1492264Sjacobs 1502264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 1512264Sjacobs "device-uri", &result); 1522264Sjacobs if (result != NULL) 1532264Sjacobs result = strdup(result); 1542264Sjacobs 1552264Sjacobs papiPrinterFree(p); 1562264Sjacobs } 1572264Sjacobs 1582264Sjacobs return (result); 1592264Sjacobs } 1602264Sjacobs 1612264Sjacobs static char *report_device_keys[] = { "printer-name", "printer-uri-supported", 1622264Sjacobs NULL }; 1632264Sjacobs /* ARGSUSED2 */ 1642264Sjacobs static int 1652264Sjacobs report_device(papi_service_t svc, char *name, papi_printer_t printer, 1662264Sjacobs int verbose, int description) 1672264Sjacobs { 1682264Sjacobs papi_status_t status; 1692264Sjacobs papi_attribute_t **attrs = papiPrinterGetAttributeList(printer); 1702264Sjacobs char *uri = NULL; 1712264Sjacobs char *device = NULL; 1722264Sjacobs uri_t *u = NULL; 1732264Sjacobs 1742264Sjacobs if (name == NULL) { 1752264Sjacobs status = papiAttributeListGetString(attrs, NULL, 1762264Sjacobs "printer-name", &name); 1772264Sjacobs if (status != PAPI_OK) 1782264Sjacobs status = papiAttributeListGetString(attrs, NULL, 1792264Sjacobs "printer-uri-supported", &name); 1802264Sjacobs } 1812264Sjacobs 1822264Sjacobs if (name == NULL) 1832264Sjacobs return (-1); 1842264Sjacobs 1852264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 1862264Sjacobs "printer-uri-supported", &uri); 1872264Sjacobs 1882264Sjacobs if ((uri != NULL) && (uri_from_string(uri, &u) == 0)) { 1892264Sjacobs char *nodename = localhostname(); 1902264Sjacobs 1912264Sjacobs if ((u->host == NULL) || 1922264Sjacobs (strcasecmp(u->host, "localhost") == 0) || 1932264Sjacobs (strcasecmp(u->host, nodename) == 0)) 1942264Sjacobs device = get_device_uri(svc, name); 1952264Sjacobs 1962264Sjacobs if (device != NULL) { 1972264Sjacobs printf(gettext("device for %s: %s\n"), name, device); 1982264Sjacobs return (0); 1992264Sjacobs } else if (uri != NULL) { 2002264Sjacobs printf(gettext("system for %s: %s (as %s)\n"), name, 2012264Sjacobs u->host, uri); 2022264Sjacobs return (0); 2032264Sjacobs } 2042264Sjacobs 2052264Sjacobs uri_free(u); 2062264Sjacobs } 2072264Sjacobs 2082264Sjacobs return (0); 2092264Sjacobs } 2102264Sjacobs 2112264Sjacobs static char *report_accepting_keys[] = { "printer-name", 2122264Sjacobs "printer-uri-supported", "printer-is-accepting-jobs", 2132264Sjacobs "printer-up-time", "printer-state-time", 2142264Sjacobs "lpsched-reject-date", "lpsched-reject-reason", NULL }; 2152264Sjacobs /* ARGSUSED2 */ 2162264Sjacobs static int 2172264Sjacobs report_accepting(papi_service_t svc, char *name, papi_printer_t printer, 2182264Sjacobs int verbose, int description) 2192264Sjacobs { 2202264Sjacobs papi_status_t status; 2212264Sjacobs papi_attribute_t **attrs = papiPrinterGetAttributeList(printer); 2222264Sjacobs time_t curr; 2232264Sjacobs char boolean = PAPI_FALSE; 2242264Sjacobs 2252264Sjacobs if (name == NULL) { 2262264Sjacobs status = papiAttributeListGetString(attrs, NULL, 2272264Sjacobs "printer-name", &name); 2282264Sjacobs if (status != PAPI_OK) 2292264Sjacobs status = papiAttributeListGetString(attrs, NULL, 2302264Sjacobs "printer-uri-supported", &name); 2312264Sjacobs } 2322264Sjacobs if (name == NULL) 2332264Sjacobs return (-1); 2342264Sjacobs 2352264Sjacobs (void) papiAttributeListGetBoolean(attrs, NULL, 2362264Sjacobs "printer-is-accepting-jobs", &boolean); 2372264Sjacobs (void) time(&curr); 2382264Sjacobs (void) papiAttributeListGetDatetime(attrs, NULL, 2392264Sjacobs "printer-up-time", &curr); 2402264Sjacobs (void) papiAttributeListGetDatetime(attrs, NULL, 2412264Sjacobs "printer-state-time", &curr); 2422264Sjacobs (void) papiAttributeListGetDatetime(attrs, NULL, 2432264Sjacobs "lpsched-reject-date", &curr); 2442264Sjacobs 2452264Sjacobs if (boolean == PAPI_TRUE) { 2462264Sjacobs printf(gettext("%s accepting requests since %s\n"), 2472264Sjacobs name, nctime(&curr)); 2482264Sjacobs } else { 2492264Sjacobs char *reason = "unknown reason"; 2502264Sjacobs 2512264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 2522264Sjacobs "lpsched-reject-reason", &reason); 2532264Sjacobs 2542264Sjacobs printf(gettext("%s not accepting requests since %s\n\t%s\n"), 2552264Sjacobs name, nctime(&curr), reason); 2562264Sjacobs } 2572264Sjacobs 2582264Sjacobs return (0); 2592264Sjacobs } 2602264Sjacobs 2612264Sjacobs static char *report_class_keys[] = { "printer-name", "printer-uri-supported", 2622264Sjacobs "member-names", NULL }; 2632264Sjacobs /* ARGSUSED2 */ 2642264Sjacobs static int 2652264Sjacobs report_class(papi_service_t svc, char *name, papi_printer_t printer, 2662264Sjacobs int verbose, int description) 2672264Sjacobs { 2682264Sjacobs papi_status_t status; 2692264Sjacobs papi_attribute_t **attrs = papiPrinterGetAttributeList(printer); 2702264Sjacobs char *member = NULL; 2712264Sjacobs void *iter = NULL; 2722264Sjacobs 2732264Sjacobs status = papiAttributeListGetString(attrs, &iter, 2742264Sjacobs "member-names", &member); 2752264Sjacobs if (status == PAPI_NOT_FOUND) /* it's not a class */ 2762264Sjacobs return (0); 2772264Sjacobs 2782264Sjacobs if (name == NULL) { 2792264Sjacobs status = papiAttributeListGetString(attrs, NULL, 2802264Sjacobs "printer-name", &name); 2812264Sjacobs if (status != PAPI_OK) 2822264Sjacobs status = papiAttributeListGetString(attrs, NULL, 2832264Sjacobs "printer-uri-supported", &name); 2842264Sjacobs } 2852264Sjacobs if (name == NULL) 2862264Sjacobs return (-1); 2872264Sjacobs 2882264Sjacobs printf(gettext("members of class %s:\n\t%s\n"), name, member); 2892264Sjacobs while (papiAttributeListGetString(attrs, &iter, NULL, &member) 2902264Sjacobs == PAPI_OK) 2912264Sjacobs printf("\t%s\n", member); 2922264Sjacobs 2932264Sjacobs return (0); 2942264Sjacobs } 2952264Sjacobs 2962264Sjacobs static char *report_printer_keys[] = { "printer-name", 2972264Sjacobs "printer-uri-supported", "printer-state", 2982264Sjacobs "printer-up-time", "printer-state-time", 2992264Sjacobs "lpsched-disable-date", "printer-state-reasons", 3002264Sjacobs "lpsched-disable-reason", NULL }; 3012264Sjacobs /* ARGSUSED2 */ 3022264Sjacobs static int 3032264Sjacobs report_printer(papi_service_t svc, char *name, papi_printer_t printer, 3042264Sjacobs int verbose, int description) 3052264Sjacobs { 3062264Sjacobs papi_status_t status; 3072264Sjacobs papi_attribute_t **attrs = papiPrinterGetAttributeList(printer); 3082264Sjacobs time_t curr; 3092264Sjacobs int32_t pstat = 0; 3102264Sjacobs char *member = NULL; 3112264Sjacobs 3122264Sjacobs status = papiAttributeListGetString(attrs, NULL, 3132264Sjacobs "member-names", &member); 3142264Sjacobs if (status == PAPI_OK) /* it's a class */ 3152264Sjacobs return (0); 3162264Sjacobs 3172264Sjacobs if (name == NULL) { 3182264Sjacobs status = papiAttributeListGetString(attrs, NULL, 3192264Sjacobs "printer-name", &name); 3202264Sjacobs if (status != PAPI_OK) 3212264Sjacobs status = papiAttributeListGetString(attrs, NULL, 3222264Sjacobs "printer-uri-supported", &name); 3232264Sjacobs } 3242264Sjacobs if (name == NULL) 3252264Sjacobs return (-1); 3262264Sjacobs 3272264Sjacobs printf(gettext("printer %s "), name); 3282264Sjacobs 3292264Sjacobs status = papiAttributeListGetInteger(attrs, NULL, 3302264Sjacobs "printer-state", &pstat); 3312264Sjacobs 3322264Sjacobs switch (pstat) { 3332264Sjacobs case 0x03: /* idle */ 3342264Sjacobs printf(gettext("idle. enabled")); 3352264Sjacobs break; 3362264Sjacobs case 0x04: { /* processing */ 3372264Sjacobs char *requested[] = { "job-id", NULL }; 3382264Sjacobs papi_job_t *j = NULL; 3392264Sjacobs int32_t jobid = 0; 3402264Sjacobs 3412264Sjacobs (void) papiPrinterListJobs(svc, name, requested, 0, 1, &j); 3422264Sjacobs if ((j != NULL) && (j[0] != NULL)) 3432264Sjacobs jobid = papiJobGetId(j[0]); 3442264Sjacobs papiJobListFree(j); 3452264Sjacobs 3462264Sjacobs printf(gettext("now printing %s-%d. enabled"), name, jobid); 3472264Sjacobs } 3482264Sjacobs break; 3492264Sjacobs case 0x05: /* stopped */ 3502264Sjacobs printf(gettext("disabled")); 3512264Sjacobs break; 3522264Sjacobs default: 3532264Sjacobs printf(gettext("unknown state(0x%x)."), pstat); 3542264Sjacobs break; 3552264Sjacobs } 3562264Sjacobs 3572264Sjacobs (void) time(&curr); 3582264Sjacobs (void) papiAttributeListGetDatetime(attrs, NULL, 3592264Sjacobs "printer-up-time", &curr); 3602264Sjacobs (void) papiAttributeListGetDatetime(attrs, NULL, 3612264Sjacobs "printer-state-time", &curr); 3622264Sjacobs (void) papiAttributeListGetDatetime(attrs, NULL, 3632264Sjacobs "lpsched-disable-date", &curr); 3642264Sjacobs printf(gettext(" since %s. available.\n"), nctime(&curr)); 3652264Sjacobs 3662264Sjacobs if (pstat == 0x05) { 3672264Sjacobs char *reason = "unknown reason"; 3682264Sjacobs 3692264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 3702264Sjacobs "printer-state-reasons", &reason); 3712264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 3722264Sjacobs "lpsched-disable-reason", &reason); 3732264Sjacobs printf(gettext("\t%s\n"), reason); 3742264Sjacobs } 3752264Sjacobs 3762264Sjacobs if (verbose == 1) { 3772264Sjacobs void *iter; 3782264Sjacobs char *str; 3792264Sjacobs 3802264Sjacobs str = ""; 3812264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 3822264Sjacobs "form-ready", &str); 3832264Sjacobs printf(gettext("\tForm mounted: %s\n"), str); 3842264Sjacobs 3852264Sjacobs str = ""; 3862264Sjacobs iter = NULL; 3872264Sjacobs (void) papiAttributeListGetString(attrs, &iter, 3882264Sjacobs "document-format-supported", &str); 3892264Sjacobs printf(gettext("\tContent types: %s"), str); 3902264Sjacobs while (papiAttributeListGetString(attrs, &iter, NULL, &str) 3912264Sjacobs == PAPI_OK) 3922264Sjacobs printf(", %s", str); 3932264Sjacobs printf("\n"); 3942264Sjacobs 3952264Sjacobs str = ""; 3962264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 3972264Sjacobs "printer-info", &str); 3982264Sjacobs printf(gettext("\tDescription: %s\n"), str); 3992264Sjacobs 4002264Sjacobs str = ""; 4012264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 4022264Sjacobs "lpsched-dial-info", &str); 4032264Sjacobs printf(gettext("\tConnection: %s\n"), 4042264Sjacobs ((str[0] != '\0') ? gettext("direct") : str)); 4052264Sjacobs 4062264Sjacobs str = ""; 4072264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 4082264Sjacobs "lpsched-interface-script", &str); 4092264Sjacobs printf(gettext("\tInterface: %s\n"), str); 4102264Sjacobs 4112264Sjacobs str = NULL; 4122264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 4132264Sjacobs "ppd-file-uri", &str); 4142264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 4152264Sjacobs "lpsched-ppd-source-path", &str); 4162264Sjacobs if (str != NULL) 4172264Sjacobs printf(gettext("\tPPD: %s\n"), str); 4182264Sjacobs 4192264Sjacobs str = NULL; 4202264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 4212264Sjacobs "lpsched-fault-alert-command", &str); 4222264Sjacobs if (str != NULL) 4232264Sjacobs printf(gettext("\tOn fault: %s\n"), str); 4242264Sjacobs 4252264Sjacobs str = ""; 4262264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 4272264Sjacobs "lpsched-fault-recovery", &str); 4282264Sjacobs printf(gettext("\tAfter fault: %s\n"), 4292264Sjacobs ((str[0] == '\0') ? gettext("continue") : str)); 4302264Sjacobs 4312264Sjacobs str = "(all)"; 4322264Sjacobs iter = NULL; 4332264Sjacobs (void) papiAttributeListGetString(attrs, &iter, 4342264Sjacobs "requesting-user-name-allowed", &str); 4352264Sjacobs printf(gettext("\tUsers allowed:\n\t\t%s\n"), 4362264Sjacobs ((str[0] == '\0') ? gettext("(none)") : str)); 4372264Sjacobs if ((str != NULL) && (str[0] != '\0')) 4382264Sjacobs while (papiAttributeListGetString(attrs, &iter, NULL, 4392264Sjacobs &str) == PAPI_OK) 4402264Sjacobs printf("\t\t%s\n", str); 4412264Sjacobs 4422264Sjacobs str = NULL; 4432264Sjacobs iter = NULL; 4442264Sjacobs (void) papiAttributeListGetString(attrs, &iter, 4452264Sjacobs "requesting-user-name-denied", &str); 4462264Sjacobs if (str != NULL) { 4472264Sjacobs printf(gettext("\tUsers denied:\n\t\t%s\n"), 4482264Sjacobs ((str[0] == '\0') ? gettext("(none)") : str)); 4492264Sjacobs if ((str != NULL) && (str[0] != '\0')) 4502264Sjacobs while (papiAttributeListGetString(attrs, &iter, 4512264Sjacobs NULL, &str) == PAPI_OK) 4522264Sjacobs printf("\t\t%s\n", str); 4532264Sjacobs } 4542264Sjacobs 4552264Sjacobs str = "(none)"; 4562264Sjacobs iter = NULL; 4572264Sjacobs (void) papiAttributeListGetString(attrs, &iter, 4582264Sjacobs "form-supported", &str); 4592264Sjacobs printf(gettext("\tForms allowed:\n\t\t%s\n"), 4602264Sjacobs ((str[0] == '\0') ? gettext("(none)") : str)); 4612264Sjacobs if ((str != NULL) && (str[0] != '\0')) 4622264Sjacobs while (papiAttributeListGetString(attrs, &iter, NULL, 4632264Sjacobs &str) == PAPI_OK) 4642264Sjacobs printf("\t\t%s\n", str); 4652264Sjacobs 4662264Sjacobs str = ""; 4672264Sjacobs iter = NULL; 4682264Sjacobs (void) papiAttributeListGetString(attrs, &iter, 4692264Sjacobs "media-supported", &str); 4702264Sjacobs printf(gettext("\tMedia supported:\n\t\t%s\n"), 4712264Sjacobs ((str[0] == '\0') ? gettext("(none)") : str)); 4722264Sjacobs if ((str != NULL) && (str[0] != '\0')) 4732264Sjacobs while (papiAttributeListGetString(attrs, &iter, NULL, 4742264Sjacobs &str) == PAPI_OK) 4752264Sjacobs printf("\t\t%s\n", str); 4762264Sjacobs 4772264Sjacobs str = ""; 4782264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 4792264Sjacobs "job-sheets-supported", &str); 4802264Sjacobs printf(gettext("\tBanner %s\n"), 4812264Sjacobs (strcasecmp(str, "none") == 0 ? 4822264Sjacobs gettext("not required") : gettext("required"))); 4832264Sjacobs 4842264Sjacobs str = ""; 4852264Sjacobs iter = NULL; 4862264Sjacobs (void) papiAttributeListGetString(attrs, &iter, 4872264Sjacobs "lpsched-print-wheels", &str); 4882264Sjacobs printf(gettext("\tCharacter sets:\n\t\t%s\n"), 4892264Sjacobs ((str[0] == '\0') ? gettext("(none)") : str)); 4902264Sjacobs if ((str != NULL) && (str[0] != '\0')) 4912264Sjacobs while (papiAttributeListGetString(attrs, &iter, NULL, 4922264Sjacobs &str) == PAPI_OK) 4932264Sjacobs printf("\t\t%s\n", str); 4942264Sjacobs 4952264Sjacobs printf(gettext("\tDefault pitch:\n")); 4962264Sjacobs printf(gettext("\tDefault page size:\n")); 4972264Sjacobs printf(gettext("\tDefault port setting:\n")); 4982264Sjacobs 4992264Sjacobs str = ""; 5002264Sjacobs iter = NULL; 5012264Sjacobs (void) papiAttributeListGetString(attrs, &iter, 5022264Sjacobs "lpsched-options", &str); 5032264Sjacobs if (str != NULL) { 5042264Sjacobs printf(gettext("\tOptions: %s"), str); 5052264Sjacobs while (papiAttributeListGetString(attrs, &iter, NULL, 5062264Sjacobs &str) == PAPI_OK) 5072264Sjacobs printf(", %s", str); 5082264Sjacobs printf("\n"); 5092264Sjacobs } 5102264Sjacobs 5112264Sjacobs } else if (description == 1) { 5122264Sjacobs char *str = ""; 5132264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 5142264Sjacobs "printer-description", &str); 5152264Sjacobs printf(gettext("\tDescription: %s\n"), str); 5162264Sjacobs } else if (verbose > 1) 5172264Sjacobs papiAttributeListPrint(stdout, attrs, "\t"); 5182264Sjacobs 5192264Sjacobs if (verbose > 0) 5202264Sjacobs printf("\n"); 5212264Sjacobs 5222264Sjacobs return (0); 5232264Sjacobs } 5242264Sjacobs 5252264Sjacobs static int 5262264Sjacobs printer_query(char *name, int (*report)(papi_service_t, char *, papi_printer_t, 5272264Sjacobs int, int), papi_encryption_t encryption, 5282264Sjacobs int verbose, int description) 5292264Sjacobs { 5302264Sjacobs int result = 0; 5312264Sjacobs papi_status_t status; 5322264Sjacobs papi_service_t svc = NULL; 5332264Sjacobs 5342264Sjacobs status = papiServiceCreate(&svc, name, NULL, NULL, cli_auth_callback, 5352264Sjacobs encryption, NULL); 5362264Sjacobs if (status != PAPI_OK) { 5374062Sjacobs if (status == PAPI_NOT_FOUND) 5384062Sjacobs fprintf(stderr, gettext("%s: unknown printer\n"), 5394062Sjacobs name ? name : "(NULL)"); 5404062Sjacobs else 5414062Sjacobs fprintf(stderr, gettext( 5424062Sjacobs "Failed to contact service for %s: %s\n"), 5434062Sjacobs name ? name : "(NULL)", 5444062Sjacobs verbose_papi_message(svc, status)); 5452264Sjacobs papiServiceDestroy(svc); 5462264Sjacobs return (-1); 5472264Sjacobs } 5482264Sjacobs 5492264Sjacobs if (name == NULL) { /* all */ 5502264Sjacobs char **interest = interest_list(svc); 5512264Sjacobs 5522264Sjacobs if (interest != NULL) { 5532264Sjacobs int i; 5542264Sjacobs 5552264Sjacobs for (i = 0; interest[i] != NULL; i++) 5562264Sjacobs result += printer_query(interest[i], report, 5572264Sjacobs encryption, verbose, 5582264Sjacobs description); 5592264Sjacobs } 5602264Sjacobs } else { 5612264Sjacobs papi_printer_t printer = NULL; 5622264Sjacobs char **keys = NULL; 5632264Sjacobs 5642264Sjacobs /* 5652264Sjacobs * Limit the query to only required data to reduce the need 5662264Sjacobs * to go remote for information. 5672264Sjacobs */ 5682264Sjacobs if (report == report_device) 5692264Sjacobs keys = report_device_keys; 5702264Sjacobs else if (report == report_class) 5712264Sjacobs keys = report_class_keys; 5722264Sjacobs else if (report == report_accepting) 5732264Sjacobs keys = report_accepting_keys; 5742264Sjacobs else if ((report == report_printer) && (verbose == 0)) 5752264Sjacobs keys = report_printer_keys; 5762264Sjacobs 5772264Sjacobs status = papiPrinterQuery(svc, name, keys, NULL, &printer); 5782264Sjacobs if (status != PAPI_OK) { 5792264Sjacobs fprintf(stderr, gettext( 5802264Sjacobs "Failed to get printer info for %s: %s\n"), 5812264Sjacobs name, verbose_papi_message(svc, status)); 5822264Sjacobs papiServiceDestroy(svc); 5832264Sjacobs return (-1); 5842264Sjacobs } 5852264Sjacobs 5862264Sjacobs if (printer != NULL) 5872264Sjacobs result = report(svc, name, printer, verbose, 5882264Sjacobs description); 5892264Sjacobs 5902264Sjacobs papiPrinterFree(printer); 5912264Sjacobs } 5922264Sjacobs 5932264Sjacobs papiServiceDestroy(svc); 5942264Sjacobs 5952264Sjacobs return (result); 5962264Sjacobs } 5972264Sjacobs 5982264Sjacobs static int 5992264Sjacobs match_user(char *user, char **list) 6002264Sjacobs { 6012264Sjacobs int i; 6022264Sjacobs 6032264Sjacobs for (i = 0; list[i] != NULL; i++) { 6042264Sjacobs if (strcmp(user, list[i]) == 0) 6052264Sjacobs return (0); 6062264Sjacobs } 6072264Sjacobs 6082264Sjacobs return (-1); 6092264Sjacobs } 6102264Sjacobs 6112264Sjacobs static char **users = NULL; 6122264Sjacobs 6132264Sjacobs static int 6142264Sjacobs report_job(papi_job_t job, int show_rank, int verbose) 6152264Sjacobs { 6162264Sjacobs papi_attribute_t **attrs = papiJobGetAttributeList(job); 6172264Sjacobs time_t clock = 0; 6182264Sjacobs char date[24]; 6192264Sjacobs char request[26]; 6202264Sjacobs char *user = "unknown"; 6212264Sjacobs int32_t size = 0; 6222264Sjacobs int32_t jstate = 0; 6232264Sjacobs 6242264Sjacobs char *destination = "unknown"; 6252264Sjacobs int32_t id = -1; 6262264Sjacobs 6272264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 6282264Sjacobs "job-originating-user-name", &user); 6292264Sjacobs 6302264Sjacobs if ((users != NULL) && (match_user(user, users) < 0)) 6312264Sjacobs return (0); 6322264Sjacobs 6332264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, "job-k-octets", &size); 6342264Sjacobs size *= 1024; /* for the approximate byte size */ 6352264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, "job-octets", &size); 6362264Sjacobs 6372264Sjacobs (void) time(&clock); 6382264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, 6392264Sjacobs "time-at-creation", (int32_t *)&clock); 6402264Sjacobs (void) strftime(date, sizeof (date), "%b %d %R", localtime(&clock)); 6412264Sjacobs 6422264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 6432264Sjacobs "job-printer-uri", &destination); 6442264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 6452264Sjacobs "printer-name", &destination); 6462264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, 6472264Sjacobs "job-id", &id); 6482264Sjacobs snprintf(request, sizeof (request), "%s-%d", destination, id); 6492264Sjacobs 6502264Sjacobs if (show_rank != 0) { 6512264Sjacobs int32_t rank = -1; 6522264Sjacobs 6532264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, 6542264Sjacobs "number-of-intervening-jobs", &rank); 6552264Sjacobs rank++; 6562264Sjacobs 6572264Sjacobs printf("%3d %-21s %-14s %7ld %s", 6582264Sjacobs rank, request, user, size, date); 6592264Sjacobs } else 6602264Sjacobs printf("%-23s %-14s %7ld %s", request, user, size, date); 6612264Sjacobs 6622264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, 6632264Sjacobs "job-state", &jstate); 6642264Sjacobs if (jstate == 0x04) 6652264Sjacobs printf(gettext(", being held")); 6662264Sjacobs else if (jstate == 0x07) 6672264Sjacobs printf(gettext(", cancelled")); 6682264Sjacobs else if (jstate == 0x09) 6692264Sjacobs printf(gettext(", complete")); 6702264Sjacobs 6712264Sjacobs if (verbose == 1) { 6723125Sjacobs char *form = NULL; 6733125Sjacobs 6742264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 6752264Sjacobs "output-device-assigned", &destination); 6762264Sjacobs printf("\n\t assigned %s", destination); 6773127Sjacobs 6783125Sjacobs (void) papiAttributeListGetString(attrs, NULL, "form", &form); 6793125Sjacobs if (form != NULL) 6803125Sjacobs printf(", form %s", form); 6812264Sjacobs } else if (verbose > 1) { 6822264Sjacobs printf("\n"); 6832264Sjacobs papiAttributeListPrint(stdout, attrs, "\t"); 6842264Sjacobs } 6852264Sjacobs 6862264Sjacobs printf("\n"); 6872264Sjacobs 6882264Sjacobs return (0); 6892264Sjacobs } 6902264Sjacobs 6912264Sjacobs static int 6922264Sjacobs job_query(char *request, int (*report)(papi_job_t, int, int), 6932264Sjacobs papi_encryption_t encryption, int show_rank, int verbose) 6942264Sjacobs { 6952264Sjacobs int result = 0; 6962264Sjacobs papi_status_t status; 6972264Sjacobs papi_service_t svc = NULL; 6982264Sjacobs char *printer = NULL; 6992264Sjacobs int32_t id = -1; 7002264Sjacobs 7012264Sjacobs get_printer_id(request, &printer, &id); 7022264Sjacobs 7032264Sjacobs status = papiServiceCreate(&svc, printer, NULL, NULL, cli_auth_callback, 7042264Sjacobs encryption, NULL); 7052264Sjacobs if (status != PAPI_OK) { 7062264Sjacobs fprintf(stderr, gettext( 7072264Sjacobs "Failed to contact service for %s: %s\n"), 7082264Sjacobs (printer ? printer : "all"), 7092264Sjacobs verbose_papi_message(svc, status)); 7102264Sjacobs return (-1); 7112264Sjacobs } 7122264Sjacobs 7132264Sjacobs if (printer == NULL) { /* all */ 7142264Sjacobs char **interest = interest_list(svc); 7152264Sjacobs 7162264Sjacobs if (interest != NULL) { 7172264Sjacobs int i; 7182264Sjacobs 7192264Sjacobs for (i = 0; interest[i] != NULL; i++) 7202264Sjacobs result += job_query(interest[i], report, 7212264Sjacobs encryption, show_rank, verbose); 7222264Sjacobs } 7232264Sjacobs } else if (id == -1) { /* a printer */ 7242264Sjacobs papi_job_t *jobs = NULL; 7252264Sjacobs 7262264Sjacobs status = papiPrinterListJobs(svc, printer, NULL, 0, 0, &jobs); 7272264Sjacobs if (status != PAPI_OK) { 7282264Sjacobs fprintf(stderr, gettext( 7292264Sjacobs "Failed to get job list: %s\n"), 7302264Sjacobs verbose_papi_message(svc, status)); 7312264Sjacobs papiServiceDestroy(svc); 7322264Sjacobs return (-1); 7332264Sjacobs } 7342264Sjacobs 7352264Sjacobs if (jobs != NULL) { 7362264Sjacobs int i; 7372264Sjacobs 7382264Sjacobs for (i = 0; jobs[i] != NULL; i++) 7392264Sjacobs result += report(jobs[i], show_rank, verbose); 7402264Sjacobs } 7412264Sjacobs 7422264Sjacobs papiJobListFree(jobs); 7432264Sjacobs } else { /* a job */ 7442264Sjacobs papi_job_t job = NULL; 7452264Sjacobs 7462264Sjacobs status = papiJobQuery(svc, printer, id, NULL, &job); 7472264Sjacobs if (status != PAPI_OK) { 7482264Sjacobs fprintf(stderr, gettext( 7492264Sjacobs "Failed to get job info for %s: %s\n"), 7502264Sjacobs request, verbose_papi_message(svc, status)); 7512264Sjacobs papiServiceDestroy(svc); 7522264Sjacobs return (-1); 7532264Sjacobs } 7542264Sjacobs 7552264Sjacobs if (job != NULL) 7562264Sjacobs result = report(job, show_rank, verbose); 7572264Sjacobs 7582264Sjacobs papiJobFree(job); 7592264Sjacobs } 7602264Sjacobs 7612264Sjacobs papiServiceDestroy(svc); 7622264Sjacobs 7632264Sjacobs return (result); 7642264Sjacobs } 7652264Sjacobs 7662264Sjacobs static int 7672264Sjacobs report_form(char *name, papi_attribute_t **attrs, int verbose) 7682264Sjacobs { 7692264Sjacobs papi_status_t status; 7702264Sjacobs char *form = NULL; 7712264Sjacobs void *iter = NULL; 7722264Sjacobs 7732264Sjacobs for (status = papiAttributeListGetString(attrs, &iter, 7742264Sjacobs "form-supported", &form); 7752264Sjacobs status == PAPI_OK; 7762264Sjacobs status = papiAttributeListGetString(attrs, &iter, 7772264Sjacobs NULL, &form)) { 7782264Sjacobs if ((name == NULL) || (strcmp(name, form) == 0)) { 7792264Sjacobs printf(gettext("form %s is available to you\n"), form); 7802264Sjacobs if (verbose != 0) { 7812264Sjacobs char *detail = NULL; 7822264Sjacobs status = papiAttributeListGetString(attrs, NULL, 7832264Sjacobs "form-supported-detail", 7842264Sjacobs &detail); 7852264Sjacobs if (status == PAPI_OK) 7862264Sjacobs printf("%s\n", detail); 7872264Sjacobs } 7882264Sjacobs } 7892264Sjacobs } 7902264Sjacobs 7912264Sjacobs return (0); 7922264Sjacobs } 7932264Sjacobs 7942264Sjacobs static int 7952264Sjacobs report_print_wheels(char *name, papi_attribute_t **attrs, int verbose) 7962264Sjacobs { 7972264Sjacobs papi_status_t status; 7982264Sjacobs char *pw = NULL; 7992264Sjacobs void *iter = NULL; 8002264Sjacobs 8012264Sjacobs for (status = papiAttributeListGetString(attrs, &iter, 8022264Sjacobs "pw-supported", &pw); 8032264Sjacobs status == PAPI_OK; 8042264Sjacobs status = papiAttributeListGetString(attrs, &iter, NULL, &pw)) { 8052264Sjacobs if ((name == NULL) || (strcmp(name, pw) == 0)) { 8062264Sjacobs printf(gettext("charset %s is available\n"), pw); 8072264Sjacobs if (verbose != 0) { 8082264Sjacobs char *info = NULL; 8092264Sjacobs status = papiAttributeListGetString(attrs, NULL, 8102264Sjacobs "pw-supported-extra", &info); 8112264Sjacobs if (status == PAPI_OK) 8122264Sjacobs printf("%s\n", info); 8132264Sjacobs } 8142264Sjacobs } 8152264Sjacobs } 8162264Sjacobs 8172264Sjacobs return (0); 8182264Sjacobs } 8192264Sjacobs 8202264Sjacobs static int 8212264Sjacobs service_query(char *name, int (*report)(char *, papi_attribute_t **, int), 8222264Sjacobs papi_encryption_t encryption, int verbose) 8232264Sjacobs { 8242264Sjacobs int result = 0; 8252264Sjacobs papi_status_t status; 8262264Sjacobs papi_service_t svc = NULL; 8272264Sjacobs papi_attribute_t **attrs = NULL; 8282264Sjacobs 8292264Sjacobs status = papiServiceCreate(&svc, name, NULL, NULL, cli_auth_callback, 8302264Sjacobs encryption, NULL); 8312264Sjacobs if (status != PAPI_OK) { 8322264Sjacobs papiServiceDestroy(svc); 8332264Sjacobs return (-1); 8342264Sjacobs } 8352264Sjacobs 8362264Sjacobs attrs = papiServiceGetAttributeList(svc); 8372264Sjacobs if (attrs != NULL) { 8382264Sjacobs result = report(name, attrs, verbose); 8392264Sjacobs 8402264Sjacobs if (verbose > 1) { 8412264Sjacobs printf("\n"); 8422264Sjacobs papiAttributeListPrint(stdout, attrs, "\t"); 8432264Sjacobs printf("\n"); 8442264Sjacobs } 8452264Sjacobs } 8462264Sjacobs 8472264Sjacobs papiServiceDestroy(svc); 8482264Sjacobs 8492264Sjacobs return (result); 8502264Sjacobs } 8512264Sjacobs 8522264Sjacobs int 8532264Sjacobs main(int ac, char *av[]) 8542264Sjacobs { 8552264Sjacobs int exit_code = 0; 8562264Sjacobs papi_encryption_t encryption = PAPI_ENCRYPT_NEVER; 8572264Sjacobs int rank = 0; 8582264Sjacobs int verbose = 0; 8592264Sjacobs int description = 0; 8602264Sjacobs int c; 8612264Sjacobs char **argv; 8622264Sjacobs 8632264Sjacobs (void) setlocale(LC_ALL, ""); 8642264Sjacobs (void) textdomain("SUNW_OST_OSCMD"); 8652264Sjacobs 8662264Sjacobs argv = (char **)calloc((ac + 1), sizeof (char *)); 867*4286Swendyp for (c = 0; c < ac; c++) { 868*4286Swendyp if ((av[c][0] == '-') && (av[c][1] == 'l') && 869*4286Swendyp (isalpha(av[c][2]) != 0)) { 870*4286Swendyp /* preserve old "-l[po...]" behavior */ 871*4286Swendyp argv[c] = &av[c][1]; 872*4286Swendyp argv[c][0] = '-'; 873*4286Swendyp verbose = 1; 874*4286Swendyp 875*4286Swendyp } else 876*4286Swendyp argv[c] = av[c]; 877*4286Swendyp } 878*4286Swendyp 8792264Sjacobs argv[c++] = "--"; 8802264Sjacobs ac = c; 8812264Sjacobs 8822264Sjacobs /* preprocess argument list looking for '-l' or '-R' so it can trail */ 8832264Sjacobs while ((c = getopt(ac, argv, "LEDf:S:stc:p:a:drs:v:l:o:R:u:")) != EOF) 8842264Sjacobs switch (c) { 8852264Sjacobs case 'l': 8862264Sjacobs if ((optarg == NULL) || (optarg[0] == '-')) 8872264Sjacobs optarg = "1"; 8882264Sjacobs verbose = atoi(optarg); 8892264Sjacobs break; 8902264Sjacobs case 'D': 8912264Sjacobs description = 1; 8922264Sjacobs break; 8932264Sjacobs case 'R': 8942264Sjacobs rank = 1; 8952264Sjacobs break; 8962264Sjacobs case 'E': 8972264Sjacobs encryption = PAPI_ENCRYPT_REQUIRED; 8982264Sjacobs break; 8992264Sjacobs default: 9002264Sjacobs break; 9012264Sjacobs } 9022264Sjacobs optind = 1; 9032264Sjacobs 9042264Sjacobs /* process command line arguments */ 9052264Sjacobs while ((c = getopt(ac, argv, "LEDf:S:stc:p:a:drs:v:l:o:R:u:")) != EOF) { 9062264Sjacobs switch (c) { /* these may or may not have an option */ 9072264Sjacobs case 'a': 9082264Sjacobs case 'c': 9092264Sjacobs case 'p': 9102264Sjacobs case 'o': 9112264Sjacobs case 'R': 9122264Sjacobs case 'u': 9132264Sjacobs case 'v': 9142264Sjacobs case 'l': 9152264Sjacobs case 'f': 9162264Sjacobs case 'S': 9172264Sjacobs if (optarg[0] == '-') { 9182264Sjacobs /* this check stop a possible infinite loop */ 9192264Sjacobs if ((optind > 1) && (argv[optind-1][1] != c)) 9202264Sjacobs optind--; 9212264Sjacobs optarg = NULL; 9222264Sjacobs } else if (strcmp(optarg, "all") == 0) 9232264Sjacobs optarg = NULL; 9242264Sjacobs } 9252264Sjacobs 9262264Sjacobs switch (c) { 9272264Sjacobs case 'a': 9282264Sjacobs exit_code += printer_query(optarg, report_accepting, 9292264Sjacobs encryption, verbose, 0); 9302264Sjacobs break; 9312264Sjacobs case 'c': 9322264Sjacobs exit_code += printer_query(optarg, report_class, 9332264Sjacobs encryption, verbose, 0); 9342264Sjacobs break; 9352264Sjacobs case 'p': 9362264Sjacobs exit_code += printer_query(optarg, report_printer, 9372264Sjacobs encryption, verbose, 9382264Sjacobs description); 9392264Sjacobs break; 9402264Sjacobs case 'd': 9412264Sjacobs exit_code += lpstat_default_printer(encryption); 9422264Sjacobs break; 9432264Sjacobs case 'r': 9442264Sjacobs exit_code += lpstat_service_status(encryption); 9452264Sjacobs break; 9462264Sjacobs case 'u': 9472264Sjacobs if (optarg != NULL) 9482264Sjacobs users = strsplit(optarg, ", \n"); 9492264Sjacobs exit_code += job_query(NULL, report_job, 9502264Sjacobs encryption, rank, verbose); 9512264Sjacobs if (users != NULL) { 9522264Sjacobs free(users); 9532264Sjacobs users = NULL; 9542264Sjacobs } 9552264Sjacobs break; 9562264Sjacobs case 'v': 9572264Sjacobs exit_code += printer_query(optarg, report_device, 9582264Sjacobs encryption, verbose, 0); 9592264Sjacobs break; 9602264Sjacobs case 'o': 9612264Sjacobs exit_code += job_query(optarg, report_job, 9622264Sjacobs encryption, rank, verbose); 9632264Sjacobs break; 9642264Sjacobs case 'f': 9652264Sjacobs exit_code += service_query(optarg, report_form, 9662264Sjacobs encryption, verbose); 9672264Sjacobs break; 9682264Sjacobs case 'S': 9692264Sjacobs exit_code += service_query(optarg, report_print_wheels, 9702264Sjacobs encryption, verbose); 9712264Sjacobs break; 9722264Sjacobs case 's': 9732264Sjacobs exit_code += lpstat_service_status(encryption); 9742264Sjacobs exit_code += lpstat_default_printer(encryption); 9752264Sjacobs exit_code += printer_query(NULL, report_class, 9762264Sjacobs encryption, verbose, 0); 9772264Sjacobs exit_code += printer_query(NULL, report_device, 9782264Sjacobs encryption, verbose, 0); 9792264Sjacobs exit_code += service_query(optarg, report_form, 9802264Sjacobs encryption, verbose); 9812264Sjacobs exit_code += service_query(optarg, report_print_wheels, 9822264Sjacobs encryption, verbose); 9832264Sjacobs break; 9842264Sjacobs case 't': 9852264Sjacobs exit_code += lpstat_service_status(encryption); 9862264Sjacobs exit_code += lpstat_default_printer(encryption); 9872264Sjacobs exit_code += printer_query(NULL, report_class, 9882264Sjacobs encryption, verbose, 0); 9892264Sjacobs exit_code += printer_query(NULL, report_device, 9902264Sjacobs encryption, verbose, 0); 9912264Sjacobs exit_code += printer_query(NULL, report_accepting, 9922264Sjacobs encryption, verbose, 0); 9932264Sjacobs exit_code += printer_query(NULL, report_printer, 9942264Sjacobs encryption, verbose, 0); 9952264Sjacobs exit_code += service_query(optarg, report_form, 9962264Sjacobs encryption, verbose); 9972264Sjacobs exit_code += service_query(optarg, report_print_wheels, 9982264Sjacobs encryption, verbose); 9992264Sjacobs exit_code += job_query(NULL, report_job, 10002264Sjacobs encryption, rank, verbose); 10012264Sjacobs break; 10022264Sjacobs case 'L': /* local-only, ignored */ 10032264Sjacobs case 'l': /* increased verbose level in first pass */ 10042264Sjacobs case 'D': /* set "description" flag in first pass */ 10052264Sjacobs case 'R': /* set "rank" flag in first pass */ 10062264Sjacobs case 'E': /* set encryption in the first pass */ 10072264Sjacobs break; 10082264Sjacobs default: 10092264Sjacobs usage(av[0]); 10102264Sjacobs } 10112264Sjacobs } 10122264Sjacobs ac--; 10132264Sjacobs 10142264Sjacobs if (ac == 1) { /* report on my jobs */ 10152264Sjacobs struct passwd *pw = getpwuid(getuid()); 10162264Sjacobs 10172264Sjacobs if (pw != NULL) 10182264Sjacobs users = strsplit(pw->pw_name, ""); 10192264Sjacobs exit_code += job_query(NULL, report_job, encryption, 10202264Sjacobs rank, verbose); 10212264Sjacobs if (users != NULL) { 10222264Sjacobs free(users); 10232264Sjacobs users = NULL; 10242264Sjacobs } 10252264Sjacobs } else { 10262264Sjacobs for (c = optind; c < ac; c++) 10272264Sjacobs exit_code += job_query(argv[c], report_job, encryption, 10282264Sjacobs rank, verbose); 10292264Sjacobs } 10302264Sjacobs 10312264Sjacobs 10322264Sjacobs if (exit_code != 0) 10332264Sjacobs exit_code = 1; 10342264Sjacobs 10352264Sjacobs return (exit_code); 10362264Sjacobs } 1037