1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License").  You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
23 * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#pragma ident	"%Z%%M%	%I%	%E% SMI"
28
29#include "cmdgen_include.h"
30
31#define	NFS_UNSHAREALL_CMD	"/usr/sbin/unshareall"
32#define	FSTYPE_FLAG		"-F"
33#define	SPACE			" "
34
35/*
36 * Public methods
37 */
38char *
39cmdgen_unshareall(CCIMPropertyList *paramList, int *errp) {
40	CCIMPropertyList	*currentParam;
41	CCIMProperty		*fstype;
42	char			*cmd;
43	int			cmdLen;
44
45	if (paramList == NULL) {
46		*errp = EINVAL;
47		return (NULL);
48	}
49
50	/*
51	 * In parameters are as follows:
52	 * 1. String fstype
53	 */
54	/*
55	 * If a filesystem type was passed in, add it to
56	 * the command line.
57	 */
58	currentParam = paramList;
59	fstype = currentParam->mDataObject;
60	if (fstype != NULL && fstype->mValue != NULL &&
61	    strlen(fstype->mValue) != 0) {
62		/*
63		 * Add two bytes for spaces, two bytes for
64		 * the "-F" filesystem type flag, and a
65		 * byte for the string terminator.
66		 */
67		cmdLen = strlen(NFS_UNSHAREALL_CMD) +
68		    strlen(fstype->mValue) + 5;
69		cmd = (char *)malloc((size_t)(cmdLen * sizeof (char)));
70		if (cmd == NULL) {
71			*errp = ENOMEM;
72		}
73		(void) snprintf(cmd, cmdLen, "%s %s %s", NFS_UNSHAREALL_CMD,
74		    FSTYPE_FLAG, fstype->mValue);
75	} else {
76		cmd = strdup(NFS_UNSHAREALL_CMD);
77		if (cmd == NULL) {
78			*errp = ENOMEM;
79		}
80	}
81	return (cmd);
82} /* cmdgen_unshareall */
83