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: enable.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 int exit_status = 0; 632264Sjacobs int c; 642264Sjacobs 652264Sjacobs (void) setlocale(LC_ALL, ""); 662264Sjacobs (void) textdomain("SUNW_OST_OSCMD"); 672264Sjacobs 682264Sjacobs while ((c = getopt(ac, av, "E")) != EOF) 692264Sjacobs switch (c) { 702264Sjacobs case 'E': 712264Sjacobs encryption = PAPI_ENCRYPT_ALWAYS; 722264Sjacobs break; 732264Sjacobs default: 742264Sjacobs usage(av[0]); 752264Sjacobs } 762264Sjacobs 772264Sjacobs if (ac == optind) 782264Sjacobs usage(av[0]); 792264Sjacobs 802264Sjacobs for (c = optind; c < ac; c++) { 812264Sjacobs char *printer = av[c]; 822264Sjacobs 832264Sjacobs status = papiServiceCreate(&svc, printer, NULL, NULL, 84*9376SGowtham.Thommandra@Sun.COM cli_auth_callback, encryption, NULL); 852264Sjacobs if (status != PAPI_OK) { 862264Sjacobs fprintf(stderr, gettext( 87*9376SGowtham.Thommandra@Sun.COM "Failed to contact service for %s: %s\n"), 88*9376SGowtham.Thommandra@Sun.COM printer, verbose_papi_message(svc, status)); 892264Sjacobs exit_status = 1; 902264Sjacobs } 912264Sjacobs 922264Sjacobs status = papiPrinterEnable(svc, printer); 93*9376SGowtham.Thommandra@Sun.COM if (status == PAPI_OK) { 94*9376SGowtham.Thommandra@Sun.COM printf(gettext("printer \"%s\" now enabled\n"), 95*9376SGowtham.Thommandra@Sun.COM printer); 96*9376SGowtham.Thommandra@Sun.COM } else if (status == PAPI_NOT_ACCEPTING) { 97*9376SGowtham.Thommandra@Sun.COM fprintf(stderr, gettext( 98*9376SGowtham.Thommandra@Sun.COM "Destination \"%s\" was already enabled.\n"), 99*9376SGowtham.Thommandra@Sun.COM printer); 100*9376SGowtham.Thommandra@Sun.COM exit_status = 1; 101*9376SGowtham.Thommandra@Sun.COM } else { 1022264Sjacobs fprintf(stderr, gettext("enable: %s: %s\n"), printer, 103*9376SGowtham.Thommandra@Sun.COM verbose_papi_message(svc, status)); 1042264Sjacobs exit_status = 1; 1052264Sjacobs } 1062264Sjacobs 1072264Sjacobs papiServiceDestroy(svc); 1082264Sjacobs } 1092264Sjacobs 1102264Sjacobs return (exit_status); 1112264Sjacobs } 112