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 /* 23*4062Sjacobs * 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> 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) { 536*4062Sjacobs if (status == PAPI_NOT_FOUND) 537*4062Sjacobs fprintf(stderr, gettext("%s: unknown printer\n"), 538*4062Sjacobs name ? name : "(NULL)"); 539*4062Sjacobs else 540*4062Sjacobs fprintf(stderr, gettext( 541*4062Sjacobs "Failed to contact service for %s: %s\n"), 542*4062Sjacobs name ? name : "(NULL)", 543*4062Sjacobs verbose_papi_message(svc, status)); 5442264Sjacobs papiServiceDestroy(svc); 5452264Sjacobs return (-1); 5462264Sjacobs } 5472264Sjacobs 5482264Sjacobs if (name == NULL) { /* all */ 5492264Sjacobs char **interest = interest_list(svc); 5502264Sjacobs 5512264Sjacobs if (interest != NULL) { 5522264Sjacobs int i; 5532264Sjacobs 5542264Sjacobs for (i = 0; interest[i] != NULL; i++) 5552264Sjacobs result += printer_query(interest[i], report, 5562264Sjacobs encryption, verbose, 5572264Sjacobs description); 5582264Sjacobs } 5592264Sjacobs } else { 5602264Sjacobs papi_printer_t printer = NULL; 5612264Sjacobs char **keys = NULL; 5622264Sjacobs 5632264Sjacobs /* 5642264Sjacobs * Limit the query to only required data to reduce the need 5652264Sjacobs * to go remote for information. 5662264Sjacobs */ 5672264Sjacobs if (report == report_device) 5682264Sjacobs keys = report_device_keys; 5692264Sjacobs else if (report == report_class) 5702264Sjacobs keys = report_class_keys; 5712264Sjacobs else if (report == report_accepting) 5722264Sjacobs keys = report_accepting_keys; 5732264Sjacobs else if ((report == report_printer) && (verbose == 0)) 5742264Sjacobs keys = report_printer_keys; 5752264Sjacobs 5762264Sjacobs status = papiPrinterQuery(svc, name, keys, NULL, &printer); 5772264Sjacobs if (status != PAPI_OK) { 5782264Sjacobs fprintf(stderr, gettext( 5792264Sjacobs "Failed to get printer info for %s: %s\n"), 5802264Sjacobs name, verbose_papi_message(svc, status)); 5812264Sjacobs papiServiceDestroy(svc); 5822264Sjacobs return (-1); 5832264Sjacobs } 5842264Sjacobs 5852264Sjacobs if (printer != NULL) 5862264Sjacobs result = report(svc, name, printer, verbose, 5872264Sjacobs description); 5882264Sjacobs 5892264Sjacobs papiPrinterFree(printer); 5902264Sjacobs } 5912264Sjacobs 5922264Sjacobs papiServiceDestroy(svc); 5932264Sjacobs 5942264Sjacobs return (result); 5952264Sjacobs } 5962264Sjacobs 5972264Sjacobs static int 5982264Sjacobs match_user(char *user, char **list) 5992264Sjacobs { 6002264Sjacobs int i; 6012264Sjacobs 6022264Sjacobs for (i = 0; list[i] != NULL; i++) { 6032264Sjacobs if (strcmp(user, list[i]) == 0) 6042264Sjacobs return (0); 6052264Sjacobs } 6062264Sjacobs 6072264Sjacobs return (-1); 6082264Sjacobs } 6092264Sjacobs 6102264Sjacobs static char **users = NULL; 6112264Sjacobs 6122264Sjacobs static int 6132264Sjacobs report_job(papi_job_t job, int show_rank, int verbose) 6142264Sjacobs { 6152264Sjacobs papi_attribute_t **attrs = papiJobGetAttributeList(job); 6162264Sjacobs time_t clock = 0; 6172264Sjacobs char date[24]; 6182264Sjacobs char request[26]; 6192264Sjacobs char *user = "unknown"; 6202264Sjacobs int32_t size = 0; 6212264Sjacobs int32_t jstate = 0; 6222264Sjacobs 6232264Sjacobs char *destination = "unknown"; 6242264Sjacobs int32_t id = -1; 6252264Sjacobs 6262264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 6272264Sjacobs "job-originating-user-name", &user); 6282264Sjacobs 6292264Sjacobs if ((users != NULL) && (match_user(user, users) < 0)) 6302264Sjacobs return (0); 6312264Sjacobs 6322264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, "job-k-octets", &size); 6332264Sjacobs size *= 1024; /* for the approximate byte size */ 6342264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, "job-octets", &size); 6352264Sjacobs 6362264Sjacobs (void) time(&clock); 6372264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, 6382264Sjacobs "time-at-creation", (int32_t *)&clock); 6392264Sjacobs (void) strftime(date, sizeof (date), "%b %d %R", localtime(&clock)); 6402264Sjacobs 6412264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 6422264Sjacobs "job-printer-uri", &destination); 6432264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 6442264Sjacobs "printer-name", &destination); 6452264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, 6462264Sjacobs "job-id", &id); 6472264Sjacobs snprintf(request, sizeof (request), "%s-%d", destination, id); 6482264Sjacobs 6492264Sjacobs if (show_rank != 0) { 6502264Sjacobs int32_t rank = -1; 6512264Sjacobs 6522264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, 6532264Sjacobs "number-of-intervening-jobs", &rank); 6542264Sjacobs rank++; 6552264Sjacobs 6562264Sjacobs printf("%3d %-21s %-14s %7ld %s", 6572264Sjacobs rank, request, user, size, date); 6582264Sjacobs } else 6592264Sjacobs printf("%-23s %-14s %7ld %s", request, user, size, date); 6602264Sjacobs 6612264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, 6622264Sjacobs "job-state", &jstate); 6632264Sjacobs if (jstate == 0x04) 6642264Sjacobs printf(gettext(", being held")); 6652264Sjacobs else if (jstate == 0x07) 6662264Sjacobs printf(gettext(", cancelled")); 6672264Sjacobs else if (jstate == 0x09) 6682264Sjacobs printf(gettext(", complete")); 6692264Sjacobs 6702264Sjacobs if (verbose == 1) { 6713125Sjacobs char *form = NULL; 6723125Sjacobs 6732264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 6742264Sjacobs "output-device-assigned", &destination); 6752264Sjacobs printf("\n\t assigned %s", destination); 6763127Sjacobs 6773125Sjacobs (void) papiAttributeListGetString(attrs, NULL, "form", &form); 6783125Sjacobs if (form != NULL) 6793125Sjacobs printf(", form %s", form); 6802264Sjacobs } else if (verbose > 1) { 6812264Sjacobs printf("\n"); 6822264Sjacobs papiAttributeListPrint(stdout, attrs, "\t"); 6832264Sjacobs } 6842264Sjacobs 6852264Sjacobs printf("\n"); 6862264Sjacobs 6872264Sjacobs return (0); 6882264Sjacobs } 6892264Sjacobs 6902264Sjacobs static int 6912264Sjacobs job_query(char *request, int (*report)(papi_job_t, int, int), 6922264Sjacobs papi_encryption_t encryption, int show_rank, int verbose) 6932264Sjacobs { 6942264Sjacobs int result = 0; 6952264Sjacobs papi_status_t status; 6962264Sjacobs papi_service_t svc = NULL; 6972264Sjacobs char *printer = NULL; 6982264Sjacobs int32_t id = -1; 6992264Sjacobs 7002264Sjacobs get_printer_id(request, &printer, &id); 7012264Sjacobs 7022264Sjacobs status = papiServiceCreate(&svc, printer, NULL, NULL, cli_auth_callback, 7032264Sjacobs encryption, NULL); 7042264Sjacobs if (status != PAPI_OK) { 7052264Sjacobs fprintf(stderr, gettext( 7062264Sjacobs "Failed to contact service for %s: %s\n"), 7072264Sjacobs (printer ? printer : "all"), 7082264Sjacobs verbose_papi_message(svc, status)); 7092264Sjacobs return (-1); 7102264Sjacobs } 7112264Sjacobs 7122264Sjacobs if (printer == NULL) { /* all */ 7132264Sjacobs char **interest = interest_list(svc); 7142264Sjacobs 7152264Sjacobs if (interest != NULL) { 7162264Sjacobs int i; 7172264Sjacobs 7182264Sjacobs for (i = 0; interest[i] != NULL; i++) 7192264Sjacobs result += job_query(interest[i], report, 7202264Sjacobs encryption, show_rank, verbose); 7212264Sjacobs } 7222264Sjacobs } else if (id == -1) { /* a printer */ 7232264Sjacobs papi_job_t *jobs = NULL; 7242264Sjacobs 7252264Sjacobs status = papiPrinterListJobs(svc, printer, NULL, 0, 0, &jobs); 7262264Sjacobs if (status != PAPI_OK) { 7272264Sjacobs fprintf(stderr, gettext( 7282264Sjacobs "Failed to get job list: %s\n"), 7292264Sjacobs verbose_papi_message(svc, status)); 7302264Sjacobs papiServiceDestroy(svc); 7312264Sjacobs return (-1); 7322264Sjacobs } 7332264Sjacobs 7342264Sjacobs if (jobs != NULL) { 7352264Sjacobs int i; 7362264Sjacobs 7372264Sjacobs for (i = 0; jobs[i] != NULL; i++) 7382264Sjacobs result += report(jobs[i], show_rank, verbose); 7392264Sjacobs } 7402264Sjacobs 7412264Sjacobs papiJobListFree(jobs); 7422264Sjacobs } else { /* a job */ 7432264Sjacobs papi_job_t job = NULL; 7442264Sjacobs 7452264Sjacobs status = papiJobQuery(svc, printer, id, NULL, &job); 7462264Sjacobs if (status != PAPI_OK) { 7472264Sjacobs fprintf(stderr, gettext( 7482264Sjacobs "Failed to get job info for %s: %s\n"), 7492264Sjacobs request, verbose_papi_message(svc, status)); 7502264Sjacobs papiServiceDestroy(svc); 7512264Sjacobs return (-1); 7522264Sjacobs } 7532264Sjacobs 7542264Sjacobs if (job != NULL) 7552264Sjacobs result = report(job, show_rank, verbose); 7562264Sjacobs 7572264Sjacobs papiJobFree(job); 7582264Sjacobs } 7592264Sjacobs 7602264Sjacobs papiServiceDestroy(svc); 7612264Sjacobs 7622264Sjacobs return (result); 7632264Sjacobs } 7642264Sjacobs 7652264Sjacobs static int 7662264Sjacobs report_form(char *name, papi_attribute_t **attrs, int verbose) 7672264Sjacobs { 7682264Sjacobs papi_status_t status; 7692264Sjacobs char *form = NULL; 7702264Sjacobs void *iter = NULL; 7712264Sjacobs 7722264Sjacobs for (status = papiAttributeListGetString(attrs, &iter, 7732264Sjacobs "form-supported", &form); 7742264Sjacobs status == PAPI_OK; 7752264Sjacobs status = papiAttributeListGetString(attrs, &iter, 7762264Sjacobs NULL, &form)) { 7772264Sjacobs if ((name == NULL) || (strcmp(name, form) == 0)) { 7782264Sjacobs printf(gettext("form %s is available to you\n"), form); 7792264Sjacobs if (verbose != 0) { 7802264Sjacobs char *detail = NULL; 7812264Sjacobs status = papiAttributeListGetString(attrs, NULL, 7822264Sjacobs "form-supported-detail", 7832264Sjacobs &detail); 7842264Sjacobs if (status == PAPI_OK) 7852264Sjacobs printf("%s\n", detail); 7862264Sjacobs } 7872264Sjacobs } 7882264Sjacobs } 7892264Sjacobs 7902264Sjacobs return (0); 7912264Sjacobs } 7922264Sjacobs 7932264Sjacobs static int 7942264Sjacobs report_print_wheels(char *name, papi_attribute_t **attrs, int verbose) 7952264Sjacobs { 7962264Sjacobs papi_status_t status; 7972264Sjacobs char *pw = NULL; 7982264Sjacobs void *iter = NULL; 7992264Sjacobs 8002264Sjacobs for (status = papiAttributeListGetString(attrs, &iter, 8012264Sjacobs "pw-supported", &pw); 8022264Sjacobs status == PAPI_OK; 8032264Sjacobs status = papiAttributeListGetString(attrs, &iter, NULL, &pw)) { 8042264Sjacobs if ((name == NULL) || (strcmp(name, pw) == 0)) { 8052264Sjacobs printf(gettext("charset %s is available\n"), pw); 8062264Sjacobs if (verbose != 0) { 8072264Sjacobs char *info = NULL; 8082264Sjacobs status = papiAttributeListGetString(attrs, NULL, 8092264Sjacobs "pw-supported-extra", &info); 8102264Sjacobs if (status == PAPI_OK) 8112264Sjacobs printf("%s\n", info); 8122264Sjacobs } 8132264Sjacobs } 8142264Sjacobs } 8152264Sjacobs 8162264Sjacobs return (0); 8172264Sjacobs } 8182264Sjacobs 8192264Sjacobs static int 8202264Sjacobs service_query(char *name, int (*report)(char *, papi_attribute_t **, int), 8212264Sjacobs papi_encryption_t encryption, int verbose) 8222264Sjacobs { 8232264Sjacobs int result = 0; 8242264Sjacobs papi_status_t status; 8252264Sjacobs papi_service_t svc = NULL; 8262264Sjacobs papi_attribute_t **attrs = NULL; 8272264Sjacobs 8282264Sjacobs status = papiServiceCreate(&svc, name, NULL, NULL, cli_auth_callback, 8292264Sjacobs encryption, NULL); 8302264Sjacobs if (status != PAPI_OK) { 8312264Sjacobs papiServiceDestroy(svc); 8322264Sjacobs return (-1); 8332264Sjacobs } 8342264Sjacobs 8352264Sjacobs attrs = papiServiceGetAttributeList(svc); 8362264Sjacobs if (attrs != NULL) { 8372264Sjacobs result = report(name, attrs, verbose); 8382264Sjacobs 8392264Sjacobs if (verbose > 1) { 8402264Sjacobs printf("\n"); 8412264Sjacobs papiAttributeListPrint(stdout, attrs, "\t"); 8422264Sjacobs printf("\n"); 8432264Sjacobs } 8442264Sjacobs } 8452264Sjacobs 8462264Sjacobs papiServiceDestroy(svc); 8472264Sjacobs 8482264Sjacobs return (result); 8492264Sjacobs } 8502264Sjacobs 8512264Sjacobs int 8522264Sjacobs main(int ac, char *av[]) 8532264Sjacobs { 8542264Sjacobs int exit_code = 0; 8552264Sjacobs papi_encryption_t encryption = PAPI_ENCRYPT_NEVER; 8562264Sjacobs int rank = 0; 8572264Sjacobs int verbose = 0; 8582264Sjacobs int description = 0; 8592264Sjacobs int c; 8602264Sjacobs char **argv; 8612264Sjacobs 8622264Sjacobs (void) setlocale(LC_ALL, ""); 8632264Sjacobs (void) textdomain("SUNW_OST_OSCMD"); 8642264Sjacobs 8652264Sjacobs argv = (char **)calloc((ac + 1), sizeof (char *)); 8662264Sjacobs for (c = 0; c < ac; c++) 8672264Sjacobs argv[c] = av[c]; 8682264Sjacobs argv[c++] = "--"; 8692264Sjacobs ac = c; 8702264Sjacobs 8712264Sjacobs /* preprocess argument list looking for '-l' or '-R' so it can trail */ 8722264Sjacobs while ((c = getopt(ac, argv, "LEDf:S:stc:p:a:drs:v:l:o:R:u:")) != EOF) 8732264Sjacobs switch (c) { 8742264Sjacobs case 'l': 8752264Sjacobs if ((optarg == NULL) || (optarg[0] == '-')) 8762264Sjacobs optarg = "1"; 8772264Sjacobs verbose = atoi(optarg); 8782264Sjacobs break; 8792264Sjacobs case 'D': 8802264Sjacobs description = 1; 8812264Sjacobs break; 8822264Sjacobs case 'R': 8832264Sjacobs rank = 1; 8842264Sjacobs break; 8852264Sjacobs case 'E': 8862264Sjacobs encryption = PAPI_ENCRYPT_REQUIRED; 8872264Sjacobs break; 8882264Sjacobs default: 8892264Sjacobs break; 8902264Sjacobs } 8912264Sjacobs optind = 1; 8922264Sjacobs 8932264Sjacobs /* process command line arguments */ 8942264Sjacobs while ((c = getopt(ac, argv, "LEDf:S:stc:p:a:drs:v:l:o:R:u:")) != EOF) { 8952264Sjacobs switch (c) { /* these may or may not have an option */ 8962264Sjacobs case 'a': 8972264Sjacobs case 'c': 8982264Sjacobs case 'p': 8992264Sjacobs case 'o': 9002264Sjacobs case 'R': 9012264Sjacobs case 'u': 9022264Sjacobs case 'v': 9032264Sjacobs case 'l': 9042264Sjacobs case 'f': 9052264Sjacobs case 'S': 9062264Sjacobs if (optarg[0] == '-') { 9072264Sjacobs /* this check stop a possible infinite loop */ 9082264Sjacobs if ((optind > 1) && (argv[optind-1][1] != c)) 9092264Sjacobs optind--; 9102264Sjacobs optarg = NULL; 9112264Sjacobs } else if (strcmp(optarg, "all") == 0) 9122264Sjacobs optarg = NULL; 9132264Sjacobs } 9142264Sjacobs 9152264Sjacobs switch (c) { 9162264Sjacobs case 'a': 9172264Sjacobs exit_code += printer_query(optarg, report_accepting, 9182264Sjacobs encryption, verbose, 0); 9192264Sjacobs break; 9202264Sjacobs case 'c': 9212264Sjacobs exit_code += printer_query(optarg, report_class, 9222264Sjacobs encryption, verbose, 0); 9232264Sjacobs break; 9242264Sjacobs case 'p': 9252264Sjacobs exit_code += printer_query(optarg, report_printer, 9262264Sjacobs encryption, verbose, 9272264Sjacobs description); 9282264Sjacobs break; 9292264Sjacobs case 'd': 9302264Sjacobs exit_code += lpstat_default_printer(encryption); 9312264Sjacobs break; 9322264Sjacobs case 'r': 9332264Sjacobs exit_code += lpstat_service_status(encryption); 9342264Sjacobs break; 9352264Sjacobs case 'u': 9362264Sjacobs if (optarg != NULL) 9372264Sjacobs users = strsplit(optarg, ", \n"); 9382264Sjacobs exit_code += job_query(NULL, report_job, 9392264Sjacobs encryption, rank, verbose); 9402264Sjacobs if (users != NULL) { 9412264Sjacobs free(users); 9422264Sjacobs users = NULL; 9432264Sjacobs } 9442264Sjacobs break; 9452264Sjacobs case 'v': 9462264Sjacobs exit_code += printer_query(optarg, report_device, 9472264Sjacobs encryption, verbose, 0); 9482264Sjacobs break; 9492264Sjacobs case 'o': 9502264Sjacobs exit_code += job_query(optarg, report_job, 9512264Sjacobs encryption, rank, verbose); 9522264Sjacobs break; 9532264Sjacobs case 'f': 9542264Sjacobs exit_code += service_query(optarg, report_form, 9552264Sjacobs encryption, verbose); 9562264Sjacobs break; 9572264Sjacobs case 'S': 9582264Sjacobs exit_code += service_query(optarg, report_print_wheels, 9592264Sjacobs encryption, verbose); 9602264Sjacobs break; 9612264Sjacobs case 's': 9622264Sjacobs exit_code += lpstat_service_status(encryption); 9632264Sjacobs exit_code += lpstat_default_printer(encryption); 9642264Sjacobs exit_code += printer_query(NULL, report_class, 9652264Sjacobs encryption, verbose, 0); 9662264Sjacobs exit_code += printer_query(NULL, report_device, 9672264Sjacobs encryption, verbose, 0); 9682264Sjacobs exit_code += service_query(optarg, report_form, 9692264Sjacobs encryption, verbose); 9702264Sjacobs exit_code += service_query(optarg, report_print_wheels, 9712264Sjacobs encryption, verbose); 9722264Sjacobs break; 9732264Sjacobs case 't': 9742264Sjacobs exit_code += lpstat_service_status(encryption); 9752264Sjacobs exit_code += lpstat_default_printer(encryption); 9762264Sjacobs exit_code += printer_query(NULL, report_class, 9772264Sjacobs encryption, verbose, 0); 9782264Sjacobs exit_code += printer_query(NULL, report_device, 9792264Sjacobs encryption, verbose, 0); 9802264Sjacobs exit_code += printer_query(NULL, report_accepting, 9812264Sjacobs encryption, verbose, 0); 9822264Sjacobs exit_code += printer_query(NULL, report_printer, 9832264Sjacobs encryption, verbose, 0); 9842264Sjacobs exit_code += service_query(optarg, report_form, 9852264Sjacobs encryption, verbose); 9862264Sjacobs exit_code += service_query(optarg, report_print_wheels, 9872264Sjacobs encryption, verbose); 9882264Sjacobs exit_code += job_query(NULL, report_job, 9892264Sjacobs encryption, rank, verbose); 9902264Sjacobs break; 9912264Sjacobs case 'L': /* local-only, ignored */ 9922264Sjacobs case 'l': /* increased verbose level in first pass */ 9932264Sjacobs case 'D': /* set "description" flag in first pass */ 9942264Sjacobs case 'R': /* set "rank" flag in first pass */ 9952264Sjacobs case 'E': /* set encryption in the first pass */ 9962264Sjacobs break; 9972264Sjacobs default: 9982264Sjacobs usage(av[0]); 9992264Sjacobs } 10002264Sjacobs } 10012264Sjacobs ac--; 10022264Sjacobs 10032264Sjacobs if (ac == 1) { /* report on my jobs */ 10042264Sjacobs struct passwd *pw = getpwuid(getuid()); 10052264Sjacobs 10062264Sjacobs if (pw != NULL) 10072264Sjacobs users = strsplit(pw->pw_name, ""); 10082264Sjacobs exit_code += job_query(NULL, report_job, encryption, 10092264Sjacobs rank, verbose); 10102264Sjacobs if (users != NULL) { 10112264Sjacobs free(users); 10122264Sjacobs users = NULL; 10132264Sjacobs } 10142264Sjacobs } else { 10152264Sjacobs for (c = optind; c < ac; c++) 10162264Sjacobs exit_code += job_query(argv[c], report_job, encryption, 10172264Sjacobs rank, verbose); 10182264Sjacobs } 10192264Sjacobs 10202264Sjacobs 10212264Sjacobs if (exit_code != 0) 10222264Sjacobs exit_code = 1; 10232264Sjacobs 10242264Sjacobs return (exit_code); 10252264Sjacobs } 1026