srptsvc.c revision 1bdd6c0e3710e91cb1f31aa78de33cb638494480
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson/*
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson * CDDL HEADER START
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson *
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson * The contents of this file are subject to the terms of the
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson * Common Development and Distribution License (the "License").
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson * You may not use this file except in compliance with the License.
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson *
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson * or http://www.opensolaris.org/os/licensing.
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson * See the License for the specific language governing permissions
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson * and limitations under the License.
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson *
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson * When distributing Covered Code, include this CDDL HEADER in each
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson * If applicable, add the following below this CDDL HEADER, with the
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson * fields enclosed by brackets "[]" replaced with your own identifying
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson * information: Portions Copyright [yyyy] [name of copyright owner]
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson *
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson * CDDL HEADER END
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson */
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson/*
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson * Use is subject to license terms.
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson */
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson#include <stdio.h>
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson#include <libintl.h>
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson#include <sys/types.h>
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson#include <sys/stat.h>
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson#include <fcntl.h>
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson#include <locale.h>
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson#include <errno.h>
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson#include <unistd.h>
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson#include <strings.h>
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson#include <srpt_ioctl.h>
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson/* Globals */
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleesonchar cmdName[] = "svc-srpt";
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleesonint
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleesonmain(int argc, char *argv[])
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson{
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson int ret;
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson boolean_t do_enable = B_FALSE;
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson int srpt_ioctl;
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson int fd = -1;
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson int saverr;
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson char *txt;
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson (void) setlocale(LC_ALL, "");
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson if (argc < 2 || argc > 2) {
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson goto usage;
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson }
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson if (strcasecmp(argv[1], "start") == 0) {
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson do_enable = B_TRUE;
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson srpt_ioctl = SRPT_IOC_ENABLE_SVC;
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson } else if (strcasecmp(argv[1], "stop") == 0) {
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson srpt_ioctl = SRPT_IOC_DISABLE_SVC;
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson } else {
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson goto usage;
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson }
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson fd = open(SRPT_NODE, O_RDONLY);
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson if (fd < 0) {
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson saverr = errno;
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson (void) fprintf(stderr, "%s: %s", cmdName,
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson gettext("Could not open SRP Target pseudodevice."));
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson if (saverr == ENOENT) {
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson (void) fprintf(stderr,
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson gettext(" Driver may not be loaded."));
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson } else {
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson (void) fprintf(stderr, gettext(" error = %d"), saverr);
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson }
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson (void) fprintf(stderr, "\n");
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson return (1);
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson }
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson ret = ioctl(fd, srpt_ioctl, NULL);
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson if (ret != 0) {
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson if (do_enable) {
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson txt = gettext("Could not enable SRP Target");
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson } else {
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson txt = gettext("Could not disable SRP Target");
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson }
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson (void) fprintf(stderr, "%s: %d", txt, ret);
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson ret = 1;
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson }
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson (void) close(fd);
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson return (ret);
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleesonusage:
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson (void) fprintf(stderr, gettext("Usage: %s start|stop"), cmdName);
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson (void) fprintf(stderr, "\n");
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson return (1);
1bdd6c0e3710e91cb1f31aa78de33cb638494480Sue Gleeson}