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 #pragma ident "%Z%%M% %I% %E% SMI" 286185db85Sdougm 296185db85Sdougm #include <sys/types.h> 306185db85Sdougm #include "sharemgr.h" 316185db85Sdougm #include <stdlib.h> 326185db85Sdougm #include <stdio.h> 336185db85Sdougm #include <string.h> 346185db85Sdougm 356185db85Sdougm /* 366185db85Sdougm * Utility functions shared by sharemgr and sharectl. 376185db85Sdougm */ 386185db85Sdougm 396185db85Sdougm /* 406185db85Sdougm * add_opt(optlist, optarg, security?) 416185db85Sdougm * Add a new parsed option to the option list provided. 426185db85Sdougm * If the option is a security option, only add if we are 436185db85Sdougm * processing security options. 446185db85Sdougm */ 456185db85Sdougm int 466185db85Sdougm add_opt(struct options **optlistp, char *optarg, int unset) 476185db85Sdougm { 486185db85Sdougm struct options *newopt, *tmp, *optlist; 49*546405c3Sdougm char *optname; 50*546405c3Sdougm char *optvalue; 516185db85Sdougm 526185db85Sdougm optlist = *optlistp; 536185db85Sdougm newopt = (struct options *)malloc(sizeof (struct options)); 54*546405c3Sdougm if (newopt == NULL) 55*546405c3Sdougm return (OPT_ADD_MEMORY); 566185db85Sdougm 576185db85Sdougm /* extract property/value pair */ 586185db85Sdougm optname = optarg; 596185db85Sdougm if (!unset) { 606185db85Sdougm optvalue = strchr(optname, '='); 616185db85Sdougm if (optvalue == NULL) { 626185db85Sdougm free(newopt); 636185db85Sdougm return (OPT_ADD_SYNTAX); 646185db85Sdougm } 656185db85Sdougm *optvalue++ = '\0'; /* separate the halves */ 666185db85Sdougm } else { 676185db85Sdougm optvalue = NULL; 686185db85Sdougm } 696185db85Sdougm 706185db85Sdougm newopt->optname = optname; 716185db85Sdougm newopt->optvalue = optvalue; 726185db85Sdougm newopt->next = NULL; 736185db85Sdougm if (optlist == NULL) { 746185db85Sdougm optlist = newopt; 756185db85Sdougm } else { 766185db85Sdougm for (tmp = optlist; tmp->next != NULL; 776185db85Sdougm tmp = tmp->next) { 78*546405c3Sdougm /* 79*546405c3Sdougm * Check to see if this is a duplicate 80*546405c3Sdougm * value. We want to replace the first 81*546405c3Sdougm * instance with the second. 82*546405c3Sdougm */ 83*546405c3Sdougm if (strcmp(tmp->optname, optname) == 0) { 84*546405c3Sdougm tmp->optvalue = optvalue; 85*546405c3Sdougm free(newopt); 86*546405c3Sdougm goto done; 87*546405c3Sdougm } 886185db85Sdougm } 896185db85Sdougm tmp->next = newopt; 906185db85Sdougm } 91*546405c3Sdougm done: 926185db85Sdougm *optlistp = optlist; 936185db85Sdougm return (OPT_ADD_OK); 946185db85Sdougm } 95