355b4669e025ff377602b6fc7caaf30dbc218371jacobs/*
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * CDDL HEADER START
355b4669e025ff377602b6fc7caaf30dbc218371jacobs *
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * The contents of this file are subject to the terms of the
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * Common Development and Distribution License (the "License").
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * You may not use this file except in compliance with the License.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs *
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * or http://www.opensolaris.org/os/licensing.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * See the License for the specific language governing permissions
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * and limitations under the License.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs *
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * When distributing Covered Code, include this CDDL HEADER in each
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * If applicable, add the following below this CDDL HEADER, with the
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * fields enclosed by brackets "[]" replaced with your own identifying
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * information: Portions Copyright [yyyy] [name of copyright owner]
355b4669e025ff377602b6fc7caaf30dbc218371jacobs *
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * CDDL HEADER END
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/*
98f04078d5fc5800e80b21e0b18abe0024af1cbeGowtham Thommandra * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * Use is subject to license terms.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs *
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/* $Id: enable.c 146 2006-03-24 00:26:54Z njacobs $ */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <stdio.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <stdlib.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <unistd.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <string.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <locale.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <libintl.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <papi.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include "common.h"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic void
355b4669e025ff377602b6fc7caaf30dbc218371jacobsusage(char *program)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs char *name;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if ((name = strrchr(program, '/')) == NULL)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs name = program;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs else
355b4669e025ff377602b6fc7caaf30dbc218371jacobs name++;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs fprintf(stdout,
98f04078d5fc5800e80b21e0b18abe0024af1cbeGowtham Thommandra gettext("Usage: %s destination ...\n"),
98f04078d5fc5800e80b21e0b18abe0024af1cbeGowtham Thommandra name);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs exit(1);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobsint
355b4669e025ff377602b6fc7caaf30dbc218371jacobsmain(int ac, char *av[])
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papi_status_t status;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papi_service_t svc = NULL;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs int exit_status = 0;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs int c;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) setlocale(LC_ALL, "");
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) textdomain("SUNW_OST_OSCMD");
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs while ((c = getopt(ac, av, "E")) != EOF)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs switch (c) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs case 'E':
355b4669e025ff377602b6fc7caaf30dbc218371jacobs encryption = PAPI_ENCRYPT_ALWAYS;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs break;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs default:
355b4669e025ff377602b6fc7caaf30dbc218371jacobs usage(av[0]);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (ac == optind)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs usage(av[0]);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs for (c = optind; c < ac; c++) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs char *printer = av[c];
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs status = papiServiceCreate(&svc, printer, NULL, NULL,
98f04078d5fc5800e80b21e0b18abe0024af1cbeGowtham Thommandra cli_auth_callback, encryption, NULL);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (status != PAPI_OK) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs fprintf(stderr, gettext(
98f04078d5fc5800e80b21e0b18abe0024af1cbeGowtham Thommandra "Failed to contact service for %s: %s\n"),
98f04078d5fc5800e80b21e0b18abe0024af1cbeGowtham Thommandra printer, verbose_papi_message(svc, status));
355b4669e025ff377602b6fc7caaf30dbc218371jacobs exit_status = 1;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs status = papiPrinterEnable(svc, printer);
98f04078d5fc5800e80b21e0b18abe0024af1cbeGowtham Thommandra if (status == PAPI_OK) {
98f04078d5fc5800e80b21e0b18abe0024af1cbeGowtham Thommandra printf(gettext("printer \"%s\" now enabled\n"),
98f04078d5fc5800e80b21e0b18abe0024af1cbeGowtham Thommandra printer);
98f04078d5fc5800e80b21e0b18abe0024af1cbeGowtham Thommandra } else if (status == PAPI_NOT_ACCEPTING) {
98f04078d5fc5800e80b21e0b18abe0024af1cbeGowtham Thommandra fprintf(stderr, gettext(
98f04078d5fc5800e80b21e0b18abe0024af1cbeGowtham Thommandra "Destination \"%s\" was already enabled.\n"),
98f04078d5fc5800e80b21e0b18abe0024af1cbeGowtham Thommandra printer);
98f04078d5fc5800e80b21e0b18abe0024af1cbeGowtham Thommandra exit_status = 1;
98f04078d5fc5800e80b21e0b18abe0024af1cbeGowtham Thommandra } else {
999637b1fd707bd54b1bd63fa6979a3673826bd0"Nagaraj Yedathore - Sun Microsystems - Bangalore India" /* The operation is not supported in lpd protocol */
999637b1fd707bd54b1bd63fa6979a3673826bd0"Nagaraj Yedathore - Sun Microsystems - Bangalore India" if (status == PAPI_OPERATION_NOT_SUPPORTED) {
999637b1fd707bd54b1bd63fa6979a3673826bd0"Nagaraj Yedathore - Sun Microsystems - Bangalore India" fprintf(stderr,
999637b1fd707bd54b1bd63fa6979a3673826bd0"Nagaraj Yedathore - Sun Microsystems - Bangalore India" verbose_papi_message(svc, status));
999637b1fd707bd54b1bd63fa6979a3673826bd0"Nagaraj Yedathore - Sun Microsystems - Bangalore India" } else {
999637b1fd707bd54b1bd63fa6979a3673826bd0"Nagaraj Yedathore - Sun Microsystems - Bangalore India" fprintf(stderr, gettext("enable: %s: %s\n"),
999637b1fd707bd54b1bd63fa6979a3673826bd0"Nagaraj Yedathore - Sun Microsystems - Bangalore India" printer, verbose_papi_message(svc, status));
999637b1fd707bd54b1bd63fa6979a3673826bd0"Nagaraj Yedathore - Sun Microsystems - Bangalore India" }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs exit_status = 1;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papiServiceDestroy(svc);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (exit_status);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}