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_SHAREALL_CMD "/usr/sbin/shareall"
32 #define FSTYPE_FLAG "-F"
33 #define SPACE " "
34
35 /*
36 * Public methods
37 */
38 char *
cmdgen_shareall(CCIMPropertyList * paramList,int * errp)39 cmdgen_shareall(CCIMPropertyList *paramList, int *errp) {
40
41 CCIMPropertyList *tmpParamList;
42 CCIMProperty *fstype;
43 CCIMProperty *filename;
44 char *cmd = NULL;
45 int cmdLen;
46
47 /*
48 * In parameters are as follows:
49 * 1. String fstype,
50 * 2. String filename
51 *
52 * They are expected to always be in this order in the property list.
53 */
54 if (paramList == NULL) {
55 *errp = EINVAL;
56 } else {
57 /*
58 * Check if a file system type and/or a filename was
59 * passed in. These we will be used in forming the
60 * command.
61 */
62 tmpParamList = paramList;
63 fstype = tmpParamList->mDataObject;
64 tmpParamList = tmpParamList->mNext;
65 filename = tmpParamList->mDataObject;
66 if (fstype != NULL && fstype->mValue != NULL &&
67 strlen(fstype->mValue) != 0) {
68 cmdLen = strlen(NFS_SHAREALL_CMD) +
69 strlen(fstype->mValue) + 5;
70 /*
71 * Added two bytes for spaces, two bytes
72 * for the "-F" filesystem type flag, and
73 * a byte for the string terminator.
74 */
75 cmd = malloc((size_t)(cmdLen * sizeof (char)));
76 if (cmd == NULL) {
77 *errp = errno;
78 return (NULL);
79 }
80 (void) snprintf(cmd, cmdLen, "%s %s %s",
81 NFS_SHAREALL_CMD, FSTYPE_FLAG,
82 fstype->mValue);
83 }
84
85 if (filename != NULL && filename->mValue != NULL &&
86 strlen(filename->mValue) != 0) {
87 cmdLen = strlen(NFS_SHAREALL_CMD) +
88 strlen(filename->mValue) + 2;
89 /*
90 * Added one byte for a space and one for
91 * the string terminator.
92 */
93 cmd = malloc((size_t)(cmdLen * sizeof (char)));
94 if (cmd == NULL) {
95 *errp = errno;
96 return (NULL);
97 }
98 (void) snprintf(cmd, cmdLen, "%s %s",
99 cmd, filename->mValue);
100 } else {
101 cmd = strdup(NFS_SHAREALL_CMD);
102 if (cmd == NULL) {
103 *errp = errno;
104 }
105 }
106 }
107 return (cmd);
108 } /* cmdgen_shareall */
109