16185db85Sdougm /*
26185db85Sdougm * CDDL HEADER START
36185db85Sdougm *
46185db85Sdougm * The contents of this file are subject to the terms of the
56185db85Sdougm * Common Development and Distribution License (the "License").
66185db85Sdougm * You may not use this file except in compliance with the License.
76185db85Sdougm *
86185db85Sdougm * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
96185db85Sdougm * or http://www.opensolaris.org/os/licensing.
106185db85Sdougm * See the License for the specific language governing permissions
116185db85Sdougm * and limitations under the License.
126185db85Sdougm *
136185db85Sdougm * When distributing Covered Code, include this CDDL HEADER in each
146185db85Sdougm * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
156185db85Sdougm * If applicable, add the following below this CDDL HEADER, with the
166185db85Sdougm * fields enclosed by brackets "[]" replaced with your own identifying
176185db85Sdougm * information: Portions Copyright [yyyy] [name of copyright owner]
186185db85Sdougm *
196185db85Sdougm * CDDL HEADER END
206185db85Sdougm */
216185db85Sdougm
226185db85Sdougm /*
23*546405c3Sdougm * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
246185db85Sdougm * Use is subject to license terms.
256185db85Sdougm */
266185db85Sdougm
276185db85Sdougm #include <sys/types.h>
286185db85Sdougm #include "sharemgr.h"
296185db85Sdougm #include <stdlib.h>
306185db85Sdougm #include <stdio.h>
316185db85Sdougm #include <string.h>
326185db85Sdougm
336185db85Sdougm /*
346185db85Sdougm * Utility functions shared by sharemgr and sharectl.
356185db85Sdougm */
366185db85Sdougm
376185db85Sdougm /*
386185db85Sdougm * add_opt(optlist, optarg, security?)
396185db85Sdougm * Add a new parsed option to the option list provided.
406185db85Sdougm * If the option is a security option, only add if we are
416185db85Sdougm * processing security options.
426185db85Sdougm */
436185db85Sdougm int
add_opt(struct options ** optlistp,char * optarg,int unset)446185db85Sdougm add_opt(struct options **optlistp, char *optarg, int unset)
456185db85Sdougm {
466185db85Sdougm struct options *newopt, *tmp, *optlist;
47*546405c3Sdougm char *optname;
48*546405c3Sdougm char *optvalue;
496185db85Sdougm
506185db85Sdougm optlist = *optlistp;
516185db85Sdougm newopt = (struct options *)malloc(sizeof (struct options));
52*546405c3Sdougm if (newopt == NULL)
53*546405c3Sdougm return (OPT_ADD_MEMORY);
546185db85Sdougm
55*546405c3Sdougm /* extract property/value pair */
56*546405c3Sdougm optname = optarg;
57*546405c3Sdougm if (!unset) {
58*546405c3Sdougm optvalue = strchr(optname, '=');
59*546405c3Sdougm if (optvalue == NULL) {
606185db85Sdougm free(newopt);
616185db85Sdougm return (OPT_ADD_SYNTAX);
626185db85Sdougm }
63*546405c3Sdougm *optvalue++ = '\0'; /* separate the halves */
64*546405c3Sdougm } else {
65*546405c3Sdougm optvalue = NULL;
66*546405c3Sdougm }
676185db85Sdougm
68*546405c3Sdougm newopt->optname = optname;
69*546405c3Sdougm newopt->optvalue = optvalue;
70*546405c3Sdougm newopt->next = NULL;
71*546405c3Sdougm if (optlist == NULL) {
72*546405c3Sdougm optlist = newopt;
73*546405c3Sdougm } else {
74*546405c3Sdougm for (tmp = optlist; tmp->next != NULL;
75*546405c3Sdougm tmp = tmp->next) {
76*546405c3Sdougm /*
77*546405c3Sdougm * Check to see if this is a duplicate
78*546405c3Sdougm * value. We want to replace the first
79*546405c3Sdougm * instance with the second.
80*546405c3Sdougm */
81*546405c3Sdougm if (strcmp(tmp->optname, optname) == 0) {
82*546405c3Sdougm tmp->optvalue = optvalue;
83*546405c3Sdougm free(newopt);
84*546405c3Sdougm goto done;
856185db85Sdougm }
866185db85Sdougm }
87*546405c3Sdougm tmp->next = newopt;
886185db85Sdougm }
89*546405c3Sdougm done:
90*546405c3Sdougm *optlistp = optlist;
91*546405c3Sdougm return (OPT_ADD_OK);
926185db85Sdougm }
93