1355b4669Sjacobs /*
2355b4669Sjacobs  * CDDL HEADER START
3355b4669Sjacobs  *
4355b4669Sjacobs  * The contents of this file are subject to the terms of the
5355b4669Sjacobs  * Common Development and Distribution License (the "License").
6355b4669Sjacobs  * You may not use this file except in compliance with the License.
7355b4669Sjacobs  *
8355b4669Sjacobs  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9355b4669Sjacobs  * or http://www.opensolaris.org/os/licensing.
10355b4669Sjacobs  * See the License for the specific language governing permissions
11355b4669Sjacobs  * and limitations under the License.
12355b4669Sjacobs  *
13355b4669Sjacobs  * When distributing Covered Code, include this CDDL HEADER in each
14355b4669Sjacobs  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15355b4669Sjacobs  * If applicable, add the following below this CDDL HEADER, with the
16355b4669Sjacobs  * fields enclosed by brackets "[]" replaced with your own identifying
17355b4669Sjacobs  * information: Portions Copyright [yyyy] [name of copyright owner]
18355b4669Sjacobs  *
19355b4669Sjacobs  * CDDL HEADER END
20355b4669Sjacobs  */
21355b4669Sjacobs 
22355b4669Sjacobs /*
2398f04078SGowtham Thommandra  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24355b4669Sjacobs  * Use is subject to license terms.
25355b4669Sjacobs  *
26355b4669Sjacobs  */
27355b4669Sjacobs 
28355b4669Sjacobs /* $Id: reject.c 146 2006-03-24 00:26:54Z njacobs $ */
29355b4669Sjacobs 
30355b4669Sjacobs 
31355b4669Sjacobs #include <stdio.h>
32355b4669Sjacobs #include <stdlib.h>
33355b4669Sjacobs #include <unistd.h>
34355b4669Sjacobs #include <string.h>
35355b4669Sjacobs #include <locale.h>
36355b4669Sjacobs #include <libintl.h>
37355b4669Sjacobs #include <papi.h>
38355b4669Sjacobs #include "common.h"
39355b4669Sjacobs 
40355b4669Sjacobs static void
usage(char * program)41355b4669Sjacobs usage(char *program)
42355b4669Sjacobs {
43355b4669Sjacobs 	char *name;
44355b4669Sjacobs 
45355b4669Sjacobs 	if ((name = strrchr(program, '/')) == NULL)
46355b4669Sjacobs 		name = program;
47355b4669Sjacobs 	else
48355b4669Sjacobs 		name++;
49355b4669Sjacobs 
50355b4669Sjacobs 	fprintf(stdout,
5198f04078SGowtham Thommandra 	    gettext("Usage: %s destination ...\n"),
5298f04078SGowtham Thommandra 	    name);
53355b4669Sjacobs 	exit(1);
54355b4669Sjacobs }
55355b4669Sjacobs 
56355b4669Sjacobs int
main(int ac,char * av[])57355b4669Sjacobs main(int ac, char *av[])
58355b4669Sjacobs {
59355b4669Sjacobs 	papi_status_t status;
60355b4669Sjacobs 	papi_service_t svc = NULL;
61355b4669Sjacobs 	papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
62355b4669Sjacobs 	char *reason = NULL;
63355b4669Sjacobs 	int exit_status = 0;
64355b4669Sjacobs 	int c = 1;
65355b4669Sjacobs 
66355b4669Sjacobs 	(void) setlocale(LC_ALL, "");
67355b4669Sjacobs 	(void) textdomain("SUNW_OST_OSCMD");
68355b4669Sjacobs 
69355b4669Sjacobs 	while ((c = getopt(ac, av, "Er:")) != EOF)
70355b4669Sjacobs 		switch (c) {
71355b4669Sjacobs 		case 'r':	/* reason */
72355b4669Sjacobs 			reason = optarg;
73355b4669Sjacobs 			break;
74355b4669Sjacobs 		case 'E':
75355b4669Sjacobs 			encryption = PAPI_ENCRYPT_ALWAYS;
76355b4669Sjacobs 			break;
77355b4669Sjacobs 		default:
78355b4669Sjacobs 			usage(av[0]);
79355b4669Sjacobs 		}
80355b4669Sjacobs 
81355b4669Sjacobs 	if (ac <= optind)
82355b4669Sjacobs 		usage(av[0]);
83355b4669Sjacobs 
84355b4669Sjacobs 	while (optind < ac) {
85355b4669Sjacobs 		char *printer = av[optind++];
86355b4669Sjacobs 
87355b4669Sjacobs 		status = papiServiceCreate(&svc, printer, NULL, NULL,
8898f04078SGowtham Thommandra 		    cli_auth_callback, encryption, NULL);
89355b4669Sjacobs 		if (status != PAPI_OK) {
90355b4669Sjacobs 			fprintf(stderr, gettext(
9198f04078SGowtham Thommandra 			    "Failed to contact service for %s: %s\n"),
9298f04078SGowtham Thommandra 			    printer, verbose_papi_message(svc, status));
93355b4669Sjacobs 			exit_status = 1;
94355b4669Sjacobs 		}
95355b4669Sjacobs 
96355b4669Sjacobs 		status = papiPrinterPause(svc, printer, reason);
9798f04078SGowtham Thommandra 		if (status == PAPI_OK) {
9898f04078SGowtham Thommandra 			printf(gettext(
9998f04078SGowtham Thommandra 			    "Destination \"%s\" will no longer "
10098f04078SGowtham Thommandra 			    "accept requests\n"), printer);
10198f04078SGowtham Thommandra 		} else if (status == PAPI_NOT_ACCEPTING) {
10298f04078SGowtham Thommandra 			fprintf(stderr, gettext(
10398f04078SGowtham Thommandra 			    "Destination \"%s\" was already not "
10498f04078SGowtham Thommandra 			    "accepting requests.\n"), printer);
10598f04078SGowtham Thommandra 			exit_status = 1;
10698f04078SGowtham Thommandra 		} else {
107*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 			/* The operation is not supported in lpd protocol */
108*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 			if (status == PAPI_OPERATION_NOT_SUPPORTED) {
109*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 				fprintf(stderr,
110*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 				    verbose_papi_message(svc, status));
111*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 			} else {
112*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 				fprintf(stderr, gettext("reject: %s: %s\n"),
113*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 				    printer, verbose_papi_message(svc, status));
114*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 			}
115355b4669Sjacobs 			exit_status = 1;
116355b4669Sjacobs 		}
117355b4669Sjacobs 
118355b4669Sjacobs 		papiServiceDestroy(svc);
119355b4669Sjacobs 	}
120355b4669Sjacobs 
121355b4669Sjacobs 	return (exit_status);
122355b4669Sjacobs }
123