xref: /illumos-gate/usr/src/cmd/print/bsd-sysv-commands/reject.c (revision 948f2876ce2a3010558f4f6937e16086ebcd36f2)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  *
26  */
27 
28 /* $Id: reject.c 146 2006-03-24 00:26:54Z njacobs $ */
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <unistd.h>
35 #include <string.h>
36 #include <locale.h>
37 #include <libintl.h>
38 #include <papi.h>
39 #include "common.h"
40 
41 static void
42 usage(char *program)
43 {
44 	char *name;
45 
46 	if ((name = strrchr(program, '/')) == NULL)
47 		name = program;
48 	else
49 		name++;
50 
51 	fprintf(stdout,
52 		gettext("Usage: %s destination ...\n"),
53 		name);
54 	exit(1);
55 }
56 
57 int
58 main(int ac, char *av[])
59 {
60 	papi_status_t status;
61 	papi_service_t svc = NULL;
62 	papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
63 	char *reason = NULL;
64 	int exit_status = 0;
65 	int c = 1;
66 
67 	(void) setlocale(LC_ALL, "");
68 	(void) textdomain("SUNW_OST_OSCMD");
69 
70 	while ((c = getopt(ac, av, "Er:")) != EOF)
71 		switch (c) {
72 		case 'r':	/* reason */
73 			reason = optarg;
74 			break;
75 		case 'E':
76 			encryption = PAPI_ENCRYPT_ALWAYS;
77 			break;
78 		default:
79 			usage(av[0]);
80 		}
81 
82 	if (ac <= optind)
83 		usage(av[0]);
84 
85 	while (optind < ac) {
86 		char *printer = av[optind++];
87 
88 		status = papiServiceCreate(&svc, printer, NULL, NULL,
89 					cli_auth_callback, encryption, NULL);
90 		if (status != PAPI_OK) {
91 			fprintf(stderr, gettext(
92 				"Failed to contact service for %s: %s\n"),
93 				printer, verbose_papi_message(svc, status));
94 			exit_status = 1;
95 		}
96 
97 		status = papiPrinterPause(svc, printer, reason);
98 		if (status != PAPI_OK) {
99 			fprintf(stderr, gettext("reject: %s: %s\n"), printer,
100 				verbose_papi_message(svc, status));
101 			exit_status = 1;
102 		}
103 
104 		papiServiceDestroy(svc);
105 	}
106 
107 	return (exit_status);
108 }
109