6185db853e024a486ff8837e6784dd290d866112dougm/*
6185db853e024a486ff8837e6784dd290d866112dougm * CDDL HEADER START
6185db853e024a486ff8837e6784dd290d866112dougm *
6185db853e024a486ff8837e6784dd290d866112dougm * The contents of this file are subject to the terms of the
6185db853e024a486ff8837e6784dd290d866112dougm * Common Development and Distribution License (the "License").
6185db853e024a486ff8837e6784dd290d866112dougm * You may not use this file except in compliance with the License.
6185db853e024a486ff8837e6784dd290d866112dougm *
6185db853e024a486ff8837e6784dd290d866112dougm * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
6185db853e024a486ff8837e6784dd290d866112dougm * or http://www.opensolaris.org/os/licensing.
6185db853e024a486ff8837e6784dd290d866112dougm * See the License for the specific language governing permissions
6185db853e024a486ff8837e6784dd290d866112dougm * and limitations under the License.
6185db853e024a486ff8837e6784dd290d866112dougm *
6185db853e024a486ff8837e6784dd290d866112dougm * When distributing Covered Code, include this CDDL HEADER in each
6185db853e024a486ff8837e6784dd290d866112dougm * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
6185db853e024a486ff8837e6784dd290d866112dougm * If applicable, add the following below this CDDL HEADER, with the
6185db853e024a486ff8837e6784dd290d866112dougm * fields enclosed by brackets "[]" replaced with your own identifying
6185db853e024a486ff8837e6784dd290d866112dougm * information: Portions Copyright [yyyy] [name of copyright owner]
6185db853e024a486ff8837e6784dd290d866112dougm *
6185db853e024a486ff8837e6784dd290d866112dougm * CDDL HEADER END
6185db853e024a486ff8837e6784dd290d866112dougm */
6185db853e024a486ff8837e6784dd290d866112dougm
6185db853e024a486ff8837e6784dd290d866112dougm/*
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
6185db853e024a486ff8837e6784dd290d866112dougm * Use is subject to license terms.
6185db853e024a486ff8837e6784dd290d866112dougm */
6185db853e024a486ff8837e6784dd290d866112dougm
6185db853e024a486ff8837e6784dd290d866112dougm#pragma ident "%Z%%M% %I% %E% SMI"
6185db853e024a486ff8837e6784dd290d866112dougm
6185db853e024a486ff8837e6784dd290d866112dougm#include <sys/types.h>
6185db853e024a486ff8837e6784dd290d866112dougm#include "sharemgr.h"
6185db853e024a486ff8837e6784dd290d866112dougm#include <stdlib.h>
6185db853e024a486ff8837e6784dd290d866112dougm#include <stdio.h>
6185db853e024a486ff8837e6784dd290d866112dougm#include <string.h>
6185db853e024a486ff8837e6784dd290d866112dougm
6185db853e024a486ff8837e6784dd290d866112dougm/*
6185db853e024a486ff8837e6784dd290d866112dougm * Utility functions shared by sharemgr and sharectl.
6185db853e024a486ff8837e6784dd290d866112dougm */
6185db853e024a486ff8837e6784dd290d866112dougm
6185db853e024a486ff8837e6784dd290d866112dougm/*
6185db853e024a486ff8837e6784dd290d866112dougm * add_opt(optlist, optarg, security?)
6185db853e024a486ff8837e6784dd290d866112dougm * Add a new parsed option to the option list provided.
6185db853e024a486ff8837e6784dd290d866112dougm * If the option is a security option, only add if we are
6185db853e024a486ff8837e6784dd290d866112dougm * processing security options.
6185db853e024a486ff8837e6784dd290d866112dougm */
6185db853e024a486ff8837e6784dd290d866112dougmint
6185db853e024a486ff8837e6784dd290d866112dougmadd_opt(struct options **optlistp, char *optarg, int unset)
6185db853e024a486ff8837e6784dd290d866112dougm{
6185db853e024a486ff8837e6784dd290d866112dougm struct options *newopt, *tmp, *optlist;
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm char *optname;
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm char *optvalue;
6185db853e024a486ff8837e6784dd290d866112dougm
6185db853e024a486ff8837e6784dd290d866112dougm optlist = *optlistp;
6185db853e024a486ff8837e6784dd290d866112dougm newopt = (struct options *)malloc(sizeof (struct options));
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm if (newopt == NULL)
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm return (OPT_ADD_MEMORY);
6185db853e024a486ff8837e6784dd290d866112dougm
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm /* extract property/value pair */
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm optname = optarg;
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm if (!unset) {
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm optvalue = strchr(optname, '=');
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm if (optvalue == NULL) {
6185db853e024a486ff8837e6784dd290d866112dougm free(newopt);
6185db853e024a486ff8837e6784dd290d866112dougm return (OPT_ADD_SYNTAX);
6185db853e024a486ff8837e6784dd290d866112dougm }
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm *optvalue++ = '\0'; /* separate the halves */
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm } else {
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm optvalue = NULL;
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm }
6185db853e024a486ff8837e6784dd290d866112dougm
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm newopt->optname = optname;
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm newopt->optvalue = optvalue;
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm newopt->next = NULL;
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm if (optlist == NULL) {
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm optlist = newopt;
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm } else {
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm for (tmp = optlist; tmp->next != NULL;
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm tmp = tmp->next) {
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm /*
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm * Check to see if this is a duplicate
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm * value. We want to replace the first
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm * instance with the second.
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm */
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm if (strcmp(tmp->optname, optname) == 0) {
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm tmp->optvalue = optvalue;
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm free(newopt);
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm goto done;
6185db853e024a486ff8837e6784dd290d866112dougm }
6185db853e024a486ff8837e6784dd290d866112dougm }
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm tmp->next = newopt;
6185db853e024a486ff8837e6784dd290d866112dougm }
546405c3c5a146c88705b0b02a469d1bd57f2b53dougmdone:
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm *optlistp = optlist;
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm return (OPT_ADD_OK);
6185db853e024a486ff8837e6784dd290d866112dougm}