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*9376SGowtham.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
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,
51*9376SGowtham.Thommandra@Sun.COM 	    gettext("Usage: %s destination ...\n"),
52*9376SGowtham.Thommandra@Sun.COM 	    name);
532264Sjacobs 	exit(1);
542264Sjacobs }
552264Sjacobs 
562264Sjacobs int
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,
88*9376SGowtham.Thommandra@Sun.COM 		    cli_auth_callback, encryption, NULL);
892264Sjacobs 		if (status != PAPI_OK) {
902264Sjacobs 			fprintf(stderr, gettext(
91*9376SGowtham.Thommandra@Sun.COM 			    "Failed to contact service for %s: %s\n"),
92*9376SGowtham.Thommandra@Sun.COM 			    printer, verbose_papi_message(svc, status));
932264Sjacobs 			exit_status = 1;
942264Sjacobs 		}
952264Sjacobs 
962264Sjacobs 		status = papiPrinterPause(svc, printer, reason);
97*9376SGowtham.Thommandra@Sun.COM 		if (status == PAPI_OK) {
98*9376SGowtham.Thommandra@Sun.COM 			printf(gettext(
99*9376SGowtham.Thommandra@Sun.COM 			    "Destination \"%s\" will no longer "
100*9376SGowtham.Thommandra@Sun.COM 			    "accept requests\n"), printer);
101*9376SGowtham.Thommandra@Sun.COM 		} else if (status == PAPI_NOT_ACCEPTING) {
102*9376SGowtham.Thommandra@Sun.COM 			fprintf(stderr, gettext(
103*9376SGowtham.Thommandra@Sun.COM 			    "Destination \"%s\" was already not "
104*9376SGowtham.Thommandra@Sun.COM 			    "accepting requests.\n"), printer);
105*9376SGowtham.Thommandra@Sun.COM 			exit_status = 1;
106*9376SGowtham.Thommandra@Sun.COM 		} else {
1072264Sjacobs 			fprintf(stderr, gettext("reject: %s: %s\n"), printer,
108*9376SGowtham.Thommandra@Sun.COM 			    verbose_papi_message(svc, status));
1092264Sjacobs 			exit_status = 1;
1102264Sjacobs 		}
1112264Sjacobs 
1122264Sjacobs 		papiServiceDestroy(svc);
1132264Sjacobs 	}
1142264Sjacobs 
1152264Sjacobs 	return (exit_status);
1162264Sjacobs }
117