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