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 MNTALL_CMD "/usr/sbin/mountall"
32 #define FSTYPE_FLAG "-F"
33 #define LOCAL_FLAG "-l"
34 #define REMOTE_FLAG "-r"
35 #define SPACE " "
36
37 /*
38 * Public methods
39 */
40 /*
41 * The -g flag is a project-private interface for pxfs and is not documented in
42 * the mountall man page. Therefore, we will not support it with this public
43 * interface.
44 */
45 /*
46 * Method: cmdgen_mountall
47 *
48 * Description: Forms the mountall command with the options given.
49 *
50 * Parameters:
51 * - CCIMPropertyList *paramList - The property list containing the
52 * options to form the mountall command.
53 * - int *errp - The error indicator. Upon error, this will be set to a
54 * value != 0.
55 *
56 * Returns:
57 * - char * - The mountall command.
58 * - NULL if an error occurred.
59 */
60 char *
cmdgen_mountall(CCIMPropertyList * paramList,int * errp)61 cmdgen_mountall(CCIMPropertyList *paramList, int *errp) {
62 CCIMPropertyList *currentParam;
63 CCIMProperty *fstypeProp = NULL;
64 CCIMProperty *onlyLocalProp = NULL;
65 CCIMProperty *onlyRemoteProp = NULL;
66 CCIMProperty *fileProp = NULL;
67 char *cmd = NULL;
68 int cmdLen;
69
70 *errp = 0;
71 cmd = strdup(MNTALL_CMD);
72 if (cmd == NULL) {
73 *errp = errno;
74 return (NULL);
75 }
76
77 cim_logDebug("cmdgen_mountall", "Set command to: %s", cmd);
78 /*
79 * In parameters are as follows:
80 * 1. String fstype,
81 * 2. Boolean onlyLocalFileSystems,
82 * 3. Boolean onlyRemoteFileSystems,
83 * 4. String fstable
84 *
85 * They are expected to always be in this order in the property list.
86 */
87 /*
88 * Check if a file system type was passed in. If one was we will
89 * use this in forming the command.
90 */
91 currentParam = paramList;
92 fstypeProp = currentParam->mDataObject;
93 if (fstypeProp != NULL && fstypeProp->mValue != NULL &&
94 strlen(fstypeProp->mValue) != 0) {
95
96 cim_logDebug("cmdgen_mountall", "Adding the -F flag");
97 /*
98 * Add -F <fstype> to the command
99 */
100 cmdLen = strlen(cmd) + strlen(SPACE) + strlen(FSTYPE_FLAG) +
101 strlen(SPACE) + strlen(fstypeProp->mValue) + 1;
102 cmd = realloc(cmd, (size_t)(cmdLen * sizeof (char)));
103 if (cmd == NULL) {
104 *errp = errno;
105 return (NULL);
106 }
107 (void) snprintf(cmd, cmdLen, "%s%s%s%s%s", cmd, SPACE,
108 FSTYPE_FLAG, SPACE, fstypeProp->mValue);
109 }
110
111 currentParam = currentParam->mNext;
112 onlyLocalProp = currentParam->mDataObject;
113
114 if (onlyLocalProp != NULL && onlyLocalProp->mValue != NULL) {
115 if (strcmp(onlyLocalProp->mValue, "1") == 0 ||
116 strcasecmp(onlyLocalProp->mValue, "true") == 0) {
117
118 cim_logDebug("cmdgen_mountall", "Adding the -l flag");
119 /*
120 * Add the -l flag to the command.
121 */
122 cmdLen = strlen(cmd) + strlen(SPACE) +
123 strlen(LOCAL_FLAG) + 1;
124
125 cmd = realloc(cmd, (size_t)(cmdLen * sizeof (char)));
126 if (cmd == NULL) {
127 *errp = errno;
128 return (NULL);
129 }
130 (void) snprintf(cmd, cmdLen, "%s%s%s", cmd,
131 SPACE, LOCAL_FLAG);
132 }
133 }
134
135 currentParam = currentParam->mNext;
136 onlyRemoteProp = currentParam->mDataObject;
137
138 cim_logDebug("cmdgen_mountall", "Checking onlyRemoteProp");
139 if (onlyRemoteProp != NULL && onlyRemoteProp->mValue != NULL) {
140 if (strcmp(onlyRemoteProp->mValue, "1") == 0 ||
141 strcasecmp(onlyRemoteProp->mValue, "true") == 0) {
142
143 cim_logDebug("cmdgen_mountall", "Adding the -r flag");
144
145 /*
146 * Add the -r flag to the command.
147 */
148 cmdLen = strlen(cmd) + strlen(SPACE) +
149 strlen(REMOTE_FLAG) + 1;
150 cmd = realloc(cmd, (size_t)(cmdLen * sizeof (char)));
151 if (cmd == NULL) {
152 *errp = errno;
153 return (NULL);
154 }
155 (void) snprintf(cmd, cmdLen, "%s%s%s", cmd, SPACE,
156 REMOTE_FLAG);
157 }
158 }
159
160 currentParam = currentParam->mNext;
161 fileProp = currentParam->mDataObject;
162
163 if (fileProp != NULL && fileProp->mValue != NULL &&
164 strlen(fileProp->mValue) != 0) {
165
166 cim_logDebug("cmdgen_mountall", "Adding the fstable");
167 /*
168 * Add the file to the command.
169 */
170 cmdLen = strlen(cmd) + strlen(SPACE) +
171 strlen(fileProp->mValue) + 1;
172 cmd = realloc(cmd, (size_t)(cmdLen * sizeof (char)));
173 if (cmd == NULL) {
174 *errp = errno;
175 return (NULL);
176 }
177 (void) snprintf(cmd, cmdLen, "%s%s%s", cmd, SPACE,
178 fileProp->mValue);
179 }
180
181 /*
182 * The caller must free the memory allocated to the return value
183 * using free().
184 */
185 cim_logDebug("cmdgen_mountall", "The return command is: %s", cmd);
186 return (cmd);
187 } /* cmdgen_mountall */
188