13034Sdougm /*
23034Sdougm * CDDL HEADER START
33034Sdougm *
43034Sdougm * The contents of this file are subject to the terms of the
53034Sdougm * Common Development and Distribution License (the "License").
63034Sdougm * You may not use this file except in compliance with the License.
73034Sdougm *
83034Sdougm * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
93034Sdougm * or http://www.opensolaris.org/os/licensing.
103034Sdougm * See the License for the specific language governing permissions
113034Sdougm * and limitations under the License.
123034Sdougm *
133034Sdougm * When distributing Covered Code, include this CDDL HEADER in each
143034Sdougm * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
153034Sdougm * If applicable, add the following below this CDDL HEADER, with the
163034Sdougm * fields enclosed by brackets "[]" replaced with your own identifying
173034Sdougm * information: Portions Copyright [yyyy] [name of copyright owner]
183034Sdougm *
193034Sdougm * CDDL HEADER END
203034Sdougm */
213034Sdougm
223034Sdougm /*
23*4524Sdougm * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
243034Sdougm * Use is subject to license terms.
253034Sdougm */
263034Sdougm
273034Sdougm #pragma ident "%Z%%M% %I% %E% SMI"
283034Sdougm
293034Sdougm #include <sys/types.h>
303034Sdougm #include "sharemgr.h"
313034Sdougm #include <stdlib.h>
323034Sdougm #include <stdio.h>
333034Sdougm #include <string.h>
343034Sdougm
353034Sdougm /*
363034Sdougm * Utility functions shared by sharemgr and sharectl.
373034Sdougm */
383034Sdougm
393034Sdougm /*
403034Sdougm * add_opt(optlist, optarg, security?)
413034Sdougm * Add a new parsed option to the option list provided.
423034Sdougm * If the option is a security option, only add if we are
433034Sdougm * processing security options.
443034Sdougm */
453034Sdougm int
add_opt(struct options ** optlistp,char * optarg,int unset)463034Sdougm add_opt(struct options **optlistp, char *optarg, int unset)
473034Sdougm {
483034Sdougm struct options *newopt, *tmp, *optlist;
49*4524Sdougm char *optname;
50*4524Sdougm char *optvalue;
513034Sdougm
523034Sdougm optlist = *optlistp;
533034Sdougm newopt = (struct options *)malloc(sizeof (struct options));
54*4524Sdougm if (newopt == NULL)
55*4524Sdougm return (OPT_ADD_MEMORY);
563034Sdougm
57*4524Sdougm /* extract property/value pair */
58*4524Sdougm optname = optarg;
59*4524Sdougm if (!unset) {
60*4524Sdougm optvalue = strchr(optname, '=');
61*4524Sdougm if (optvalue == NULL) {
623034Sdougm free(newopt);
633034Sdougm return (OPT_ADD_SYNTAX);
643034Sdougm }
65*4524Sdougm *optvalue++ = '\0'; /* separate the halves */
66*4524Sdougm } else {
67*4524Sdougm optvalue = NULL;
68*4524Sdougm }
693034Sdougm
70*4524Sdougm newopt->optname = optname;
71*4524Sdougm newopt->optvalue = optvalue;
72*4524Sdougm newopt->next = NULL;
73*4524Sdougm if (optlist == NULL) {
74*4524Sdougm optlist = newopt;
75*4524Sdougm } else {
76*4524Sdougm for (tmp = optlist; tmp->next != NULL;
77*4524Sdougm tmp = tmp->next) {
78*4524Sdougm /*
79*4524Sdougm * Check to see if this is a duplicate
80*4524Sdougm * value. We want to replace the first
81*4524Sdougm * instance with the second.
82*4524Sdougm */
83*4524Sdougm if (strcmp(tmp->optname, optname) == 0) {
84*4524Sdougm tmp->optvalue = optvalue;
85*4524Sdougm free(newopt);
86*4524Sdougm goto done;
873034Sdougm }
883034Sdougm }
89*4524Sdougm tmp->next = newopt;
903034Sdougm }
91*4524Sdougm done:
92*4524Sdougm *optlistp = optlist;
93*4524Sdougm return (OPT_ADD_OK);
943034Sdougm }
95