xref: /titanic_52/usr/src/cmd/dfs.cmds/sharemgr/shareutil.c (revision 6185db853e024a486ff8837e6784dd290d866112)
1*6185db85Sdougm /*
2*6185db85Sdougm  * CDDL HEADER START
3*6185db85Sdougm  *
4*6185db85Sdougm  * The contents of this file are subject to the terms of the
5*6185db85Sdougm  * Common Development and Distribution License (the "License").
6*6185db85Sdougm  * You may not use this file except in compliance with the License.
7*6185db85Sdougm  *
8*6185db85Sdougm  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*6185db85Sdougm  * or http://www.opensolaris.org/os/licensing.
10*6185db85Sdougm  * See the License for the specific language governing permissions
11*6185db85Sdougm  * and limitations under the License.
12*6185db85Sdougm  *
13*6185db85Sdougm  * When distributing Covered Code, include this CDDL HEADER in each
14*6185db85Sdougm  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*6185db85Sdougm  * If applicable, add the following below this CDDL HEADER, with the
16*6185db85Sdougm  * fields enclosed by brackets "[]" replaced with your own identifying
17*6185db85Sdougm  * information: Portions Copyright [yyyy] [name of copyright owner]
18*6185db85Sdougm  *
19*6185db85Sdougm  * CDDL HEADER END
20*6185db85Sdougm  */
21*6185db85Sdougm 
22*6185db85Sdougm /*
23*6185db85Sdougm  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24*6185db85Sdougm  * Use is subject to license terms.
25*6185db85Sdougm  */
26*6185db85Sdougm 
27*6185db85Sdougm #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*6185db85Sdougm 
29*6185db85Sdougm #include <sys/types.h>
30*6185db85Sdougm #include "sharemgr.h"
31*6185db85Sdougm #include <stdlib.h>
32*6185db85Sdougm #include <stdio.h>
33*6185db85Sdougm #include <string.h>
34*6185db85Sdougm 
35*6185db85Sdougm /*
36*6185db85Sdougm  * Utility functions shared by sharemgr and sharectl.
37*6185db85Sdougm  */
38*6185db85Sdougm 
39*6185db85Sdougm /*
40*6185db85Sdougm  * add_opt(optlist, optarg, security?)
41*6185db85Sdougm  *	Add a new parsed option to the option list provided.
42*6185db85Sdougm  *	If the option is a security option, only add if we are
43*6185db85Sdougm  *	processing security options.
44*6185db85Sdougm  */
45*6185db85Sdougm int
46*6185db85Sdougm add_opt(struct options **optlistp, char *optarg, int unset)
47*6185db85Sdougm {
48*6185db85Sdougm 	struct options *newopt, *tmp, *optlist;
49*6185db85Sdougm 
50*6185db85Sdougm 	optlist = *optlistp;
51*6185db85Sdougm 	newopt = (struct options *)malloc(sizeof (struct options));
52*6185db85Sdougm 	if (newopt != NULL) {
53*6185db85Sdougm 		char *optname;
54*6185db85Sdougm 		char *optvalue;
55*6185db85Sdougm 
56*6185db85Sdougm 		/* extract property/value pair */
57*6185db85Sdougm 		optname = optarg;
58*6185db85Sdougm 		if (!unset) {
59*6185db85Sdougm 		    optvalue = strchr(optname, '=');
60*6185db85Sdougm 		    if (optvalue == NULL) {
61*6185db85Sdougm 			free(newopt);
62*6185db85Sdougm 			return (OPT_ADD_SYNTAX);
63*6185db85Sdougm 		    }
64*6185db85Sdougm 		    *optvalue++ = '\0'; /* separate the halves */
65*6185db85Sdougm 		} else {
66*6185db85Sdougm 		    optvalue = NULL;
67*6185db85Sdougm 		}
68*6185db85Sdougm 
69*6185db85Sdougm 		newopt->optname = optname;
70*6185db85Sdougm 		newopt->optvalue = optvalue;
71*6185db85Sdougm 		newopt->next = NULL;
72*6185db85Sdougm 		if (optlist == NULL) {
73*6185db85Sdougm 			optlist = newopt;
74*6185db85Sdougm 		} else {
75*6185db85Sdougm 			for (tmp = optlist; tmp->next != NULL;
76*6185db85Sdougm 			    tmp = tmp->next) {
77*6185db85Sdougm 			}
78*6185db85Sdougm 			tmp->next = newopt;
79*6185db85Sdougm 		}
80*6185db85Sdougm 		*optlistp = optlist;
81*6185db85Sdougm 		return (OPT_ADD_OK);
82*6185db85Sdougm 	}
83*6185db85Sdougm 	return (OPT_ADD_MEMORY);
84*6185db85Sdougm }
85