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 /*
239376SGowtham.Thommandra@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
242264Sjacobs * Use is subject to license terms.
252264Sjacobs *
262264Sjacobs */
272264Sjacobs
282264Sjacobs /* $Id: reject.c 146 2006-03-24 00:26:54Z njacobs $ */
292264Sjacobs
302264Sjacobs
312264Sjacobs #include <stdio.h>
322264Sjacobs #include <stdlib.h>
332264Sjacobs #include <unistd.h>
342264Sjacobs #include <string.h>
352264Sjacobs #include <locale.h>
362264Sjacobs #include <libintl.h>
372264Sjacobs #include <papi.h>
382264Sjacobs #include "common.h"
392264Sjacobs
402264Sjacobs static void
usage(char * program)412264Sjacobs usage(char *program)
422264Sjacobs {
432264Sjacobs char *name;
442264Sjacobs
452264Sjacobs if ((name = strrchr(program, '/')) == NULL)
462264Sjacobs name = program;
472264Sjacobs else
482264Sjacobs name++;
492264Sjacobs
502264Sjacobs fprintf(stdout,
519376SGowtham.Thommandra@Sun.COM gettext("Usage: %s destination ...\n"),
529376SGowtham.Thommandra@Sun.COM name);
532264Sjacobs exit(1);
542264Sjacobs }
552264Sjacobs
562264Sjacobs int
main(int ac,char * av[])572264Sjacobs main(int ac, char *av[])
582264Sjacobs {
592264Sjacobs papi_status_t status;
602264Sjacobs papi_service_t svc = NULL;
612264Sjacobs papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
622264Sjacobs char *reason = NULL;
632264Sjacobs int exit_status = 0;
642264Sjacobs int c = 1;
652264Sjacobs
662264Sjacobs (void) setlocale(LC_ALL, "");
672264Sjacobs (void) textdomain("SUNW_OST_OSCMD");
682264Sjacobs
692264Sjacobs while ((c = getopt(ac, av, "Er:")) != EOF)
702264Sjacobs switch (c) {
712264Sjacobs case 'r': /* reason */
722264Sjacobs reason = optarg;
732264Sjacobs break;
742264Sjacobs case 'E':
752264Sjacobs encryption = PAPI_ENCRYPT_ALWAYS;
762264Sjacobs break;
772264Sjacobs default:
782264Sjacobs usage(av[0]);
792264Sjacobs }
802264Sjacobs
812264Sjacobs if (ac <= optind)
822264Sjacobs usage(av[0]);
832264Sjacobs
842264Sjacobs while (optind < ac) {
852264Sjacobs char *printer = av[optind++];
862264Sjacobs
872264Sjacobs status = papiServiceCreate(&svc, printer, NULL, NULL,
889376SGowtham.Thommandra@Sun.COM cli_auth_callback, encryption, NULL);
892264Sjacobs if (status != PAPI_OK) {
902264Sjacobs fprintf(stderr, gettext(
919376SGowtham.Thommandra@Sun.COM "Failed to contact service for %s: %s\n"),
929376SGowtham.Thommandra@Sun.COM printer, verbose_papi_message(svc, status));
932264Sjacobs exit_status = 1;
942264Sjacobs }
952264Sjacobs
962264Sjacobs status = papiPrinterPause(svc, printer, reason);
979376SGowtham.Thommandra@Sun.COM if (status == PAPI_OK) {
989376SGowtham.Thommandra@Sun.COM printf(gettext(
999376SGowtham.Thommandra@Sun.COM "Destination \"%s\" will no longer "
1009376SGowtham.Thommandra@Sun.COM "accept requests\n"), printer);
1019376SGowtham.Thommandra@Sun.COM } else if (status == PAPI_NOT_ACCEPTING) {
1029376SGowtham.Thommandra@Sun.COM fprintf(stderr, gettext(
1039376SGowtham.Thommandra@Sun.COM "Destination \"%s\" was already not "
1049376SGowtham.Thommandra@Sun.COM "accepting requests.\n"), printer);
1059376SGowtham.Thommandra@Sun.COM exit_status = 1;
1069376SGowtham.Thommandra@Sun.COM } else {
107*9855SNagaraj.Yedathore@Sun.COM /* The operation is not supported in lpd protocol */
108*9855SNagaraj.Yedathore@Sun.COM if (status == PAPI_OPERATION_NOT_SUPPORTED) {
109*9855SNagaraj.Yedathore@Sun.COM fprintf(stderr,
110*9855SNagaraj.Yedathore@Sun.COM verbose_papi_message(svc, status));
111*9855SNagaraj.Yedathore@Sun.COM } else {
112*9855SNagaraj.Yedathore@Sun.COM fprintf(stderr, gettext("reject: %s: %s\n"),
113*9855SNagaraj.Yedathore@Sun.COM printer, verbose_papi_message(svc, status));
114*9855SNagaraj.Yedathore@Sun.COM }
1152264Sjacobs exit_status = 1;
1162264Sjacobs }
1172264Sjacobs
1182264Sjacobs papiServiceDestroy(svc);
1192264Sjacobs }
1202264Sjacobs
1212264Sjacobs return (exit_status);
1222264Sjacobs }
123