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 2002 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 <unistd.h>
30 #include <netdb.h>
31 #include <errno.h>
32 
33 #include "util.h"
34 #include "cimKeys.h"
35 #include "ctrl_descriptors.h"
36 #include "providerNames.h"
37 #include "messageStrings.h"
38 #include "Solaris_GenericController.h"
39 
40 #define	GENERIC_GETINSTANCE		"GENERIC_CONTROLLER,GET_INSTANCE"
41 #define	GENERIC_ENUMINSTANCES		"GENERIC_CONTROLLER,ENUM_INSTANCES"
42 #define	GENERIC_ENUMINSTANCENAMES	"GENERIC_CONTROLLER,ENUM_INSTANCENAMES"
43 #define	GENERIC_CREATEINSTANCE		"GENERIC_CONTROLLER,CREATE_INSTANCE"
44 #define	GENERIC_DELETEINSTANCE		"GENERIC_CONTROLLER,DELETE_INSTANCE"
45 #define	GENERIC_SETINSTANCE		"GENERIC_CONTROLLER,SET_INSTANCE"
46 #define	GENERIC_GETPROPERTY		"GENERIC_CONTROLLER,GET_PROPERTY"
47 #define	GENERIC_SETPROPERTY		"GENERIC_CONTROLLER,SET_PROPERTY"
48 #define	GENERIC_INVOKEMETHOD		"GENERIC_CONTROLLER,INVOKE_METHOD"
49 #define	GENERIC_EXECQUERY		"GENERIC_CONTROLLER,EXEC_QUERY"
50 
51 /*
52  * Solaris_GenericController provider
53  *
54  * It is important to note that all memory allocated by these functions
55  * and passed to the CIMOM, is freed by the CIMOM as the caller.
56  */
57 
58 
59 /*
60  * Name: cp_getInstance_Solaris_GenericController
61  *
62  * Description: Returns an instance which matches the passed in object path
63  * if found.
64  *
65  * Parameters:
66  *      pOP - An CCIMObjectPath * which contains the information on
67  *      the class for which to find the instance.
68  * Returns:
69  *      CCIMInstance * if matched instance is found. Otherwise, NULL.
70  */
71 
72 /* ARGSUSED */
73 CCIMInstance*
cp_getInstance_Solaris_GenericController(CCIMObjectPath * pOP)74 cp_getInstance_Solaris_GenericController(CCIMObjectPath* pOP)
75 {
76 	CCIMInstance		*inst = NULL;
77 	CCIMPropertyList	*pCurPropList;
78 	dm_descriptor_t		uctrl_descriptor;
79 	char			*name;
80 	int			error;
81 
82 	if (pOP == NULL ||
83 	    pOP->mKeyProperties == NULL) {
84 	    util_handleError(GENERIC_GETINSTANCE, CIM_ERR_INVALID_PARAMETER,
85 		NULL, NULL, &error);
86 	    return ((CCIMInstance *)NULL);
87 	}
88 
89 	pCurPropList = pOP->mKeyProperties;
90 	name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
91 	    &error);
92 
93 	if (error != 0 || name == NULL) {
94 	    util_handleError(GENERIC_GETINSTANCE, CIM_ERR_INVALID_PARAMETER,
95 		NULL, NULL, &error);
96 	    return ((CCIMInstance*)NULL);
97 	}
98 
99 	uctrl_descriptor =
100 	    dm_get_descriptor_by_name(DM_CONTROLLER, name, &error);
101 	/*
102 	 * Not found. Return a null instance.
103 	 */
104 
105 	if (error == ENODEV) {
106 	    return ((CCIMInstance *)NULL);
107 	}
108 
109 	if (error != 0) {
110 	    util_handleError(GENERIC_GETINSTANCE, CIM_ERR_FAILED,
111 		DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
112 	    return ((CCIMInstance*)NULL);
113 	}
114 
115 	/* Turn this descriptor in to a generic controller instance */
116 
117 	inst = ctrl_descriptor_toCCIMInstance(
118 	    hostName, uctrl_descriptor, GENERIC_CONTROLLER, &error);
119 	dm_free_descriptor(uctrl_descriptor);
120 
121 	if (error != 0) {
122 	    util_handleError(GENERIC_GETINSTANCE, CIM_ERR_FAILED,
123 		UCTRL_DESC_TO_INSTANCE_FAILURE, NULL,
124 		    &error);
125 	    return ((CCIMInstance*)NULL);
126 	}
127 
128 	return (inst);
129 }
130 
131 /*
132  * Name: cp_enumInstances_Solaris_GenericController
133  *
134  * Description: Returns an instance list of Unknown controllers, if any found.
135  *
136  * Parameters:
137  *      pOP - An CCIMObjectPath * which contains the information on
138  *      the class for which to find the instances.
139  * Returns:
140  *      CCIMInstanceList * if matches are found. Otherwise, NULL.
141  */
142 
143 /* ARGSUSED */
144 CCIMInstanceList*
cp_enumInstances_Solaris_GenericController(CCIMObjectPath * pOP)145 cp_enumInstances_Solaris_GenericController(CCIMObjectPath* pOP)
146 {
147 	CCIMInstanceList	*instList = NULL;
148 	dm_descriptor_t		*uctrl_descriptorp;
149 	int			error;
150 	int			filter[1];
151 
152 	filter[0] = DM_FILTER_END;
153 
154 	uctrl_descriptorp = dm_get_descriptors(DM_CONTROLLER, filter,
155 	    &error);
156 
157 	if (uctrl_descriptorp == NULL ||
158 	    uctrl_descriptorp[0] == NULL) {
159 	    return ((CCIMInstanceList *)NULL);
160 	}
161 	if (error != 0) {
162 	    util_handleError(GENERIC_ENUMINSTANCES, CIM_ERR_FAILED,
163 		DM_GET_DESCRIPTORS, NULL, &error);
164 	    return ((CCIMInstanceList *)NULL);
165 	}
166 
167 	/* convert controller to CCIMInstanceList */
168 	instList = ctrl_descriptors_toCCIMInstanceList(GENERIC_CONTROLLER,
169 	    uctrl_descriptorp, &error, 1, "unknown");
170 	dm_free_descriptors(uctrl_descriptorp);
171 
172 	if (error != 0) {
173 	    util_handleError(GENERIC_ENUMINSTANCES, CIM_ERR_FAILED,
174 		UCTRL_DESC_TO_INSTANCE_FAILURE, NULL, &error);
175 	    return ((CCIMInstanceList *)NULL);
176 	}
177 
178 	return (instList);
179 }
180 
181 /*
182  * Name: cp_enumInstanceNames_Solaris_GenericController
183  *
184  * Description: Returns an objectPath list of GENERIC controllers, if any found.
185  *
186  * Parameters:
187  *      pOP - An CCIMObjectPath * which contains the information on
188  *      the class for which to find the instances.
189  * Returns:
190  *      CCIMObjectPathList * if matched instances are found. Otherwise, NULL.
191  */
192 
193 /* ARGSUSED */
194 CCIMObjectPathList*
cp_enumInstanceNames_Solaris_GenericController(CCIMObjectPath * pOP)195 cp_enumInstanceNames_Solaris_GenericController(CCIMObjectPath * pOP) {
196 
197 	CCIMInstanceList	*instList;
198 	CCIMObjectPathList	*objList = NULL;
199 	int			error;
200 
201 	if (pOP == NULL) {
202 	    util_handleError(GENERIC_ENUMINSTANCENAMES,
203 		CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
204 	    return ((CCIMObjectPathList *)NULL);
205 	}
206 
207 	/*
208 	 * Call into enumInstances and then convert the instance list in
209 	 * to an object list.
210 	 */
211 
212 	instList = cp_enumInstances_Solaris_GenericController(pOP);
213 
214 	if (instList != NULL) {
215 	    objList = cim_createObjectPathList(instList);
216 	    cim_freeInstanceList(instList);
217 	}
218 
219 	return (objList);
220 }
221 
222 /*
223  * Creating an instance of a Solaris_GenericController is not supported.
224  */
225 
226 /* ARGSUSED */
227 CCIMObjectPath*
cp_createInstance_Solaris_GenericController(CCIMObjectPath * pOP,CCIMInstance * pInst)228 cp_createInstance_Solaris_GenericController(
229     CCIMObjectPath* pOP, CCIMInstance* pInst)
230 {
231 	int	error;
232 
233 	util_handleError(GENERIC_CREATEINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL,
234 	    NULL, &error);
235 	return ((CCIMObjectPath*)NULL);
236 }
237 
238 /*
239  * Deleting an instance of a Solaris_GenericController is not supported.
240  */
241 
242 /* ARGSUSED */
243 CIMBool
cp_deleteInstance_Solaris_GenericController(CCIMObjectPath * pInst)244 cp_deleteInstance_Solaris_GenericController(CCIMObjectPath* pInst)
245 {
246 	int	error;
247 
248 	util_handleError(GENERIC_DELETEINSTANCE,
249 	    CIM_ERR_NOT_SUPPORTED, NULL, NULL, &error);
250 	return (cim_false);
251 }
252 
253 /*
254  * Name: cp_getProperty_Solaris_GenericController
255  *
256  * Description: Returns the property requested, if found.
257  *
258  * Parameters:
259  *	pOP - An CCIMObjectPath * which contains the information on
260  *	the class for which to find the instances.
261  * Returns:
262  *	CCIMProperty * if found.
263  */
264 
265 /* ARGSUSED */
266 CCIMProperty	*
cp_getProperty_Solaris_GenericController(CCIMObjectPath * pOP,char * pPropName)267 cp_getProperty_Solaris_GenericController(CCIMObjectPath *pOP,
268     char *pPropName)
269 {
270 
271 	CCIMProperty	*prop = NULL;
272 	CCIMInstance	*inst = NULL;
273 	int		error = 0;
274 
275 	if (pOP == NULL) {
276 	    util_handleError(GENERIC_GETPROPERTY, CIM_ERR_INVALID_PARAMETER,
277 		NULL, NULL, &error);
278 	    return ((CCIMProperty *)NULL);
279 	}
280 
281 	inst = cp_getInstance_Solaris_GenericController(pOP);
282 	if (inst == NULL) {
283 	    return ((CCIMProperty *)NULL);
284 	}
285 
286 	prop = cim_getProperty(inst, pPropName);
287 	cim_freeInstance(inst);
288 	return (prop);
289 }
290 /*
291  * Setting an instance of a Solaris_GenericController is not supported.
292  */
293 
294 /* ARGSUSED */
295 CIMBool
cp_setInstance_Solaris_GenericController(CCIMObjectPath * pOP,CCIMInstance * pInst)296 cp_setInstance_Solaris_GenericController(CCIMObjectPath* pOP,
297     CCIMInstance* pInst)
298 {
299 
300 	int	error;
301 
302 	util_handleError(GENERIC_SETINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL,
303 	    NULL, &error);
304 	return (cim_false);
305 }
306 
307 /*
308  * Setting a property on an instance of a Solaris_GenericController is not
309  * supported.
310  */
311 /* ARGSUSED */
312 CIMBool
cp_setProperty_Solaris_GenericController(CCIMObjectPath * pOP,CCIMProperty * pProp)313 cp_setProperty_Solaris_GenericController(CCIMObjectPath* pOP,
314     CCIMProperty* pProp)
315 {
316 
317 	int	error;
318 
319 	util_handleError(GENERIC_SETPROPERTY, CIM_ERR_NOT_SUPPORTED, NULL,
320 	    NULL, &error);
321 	return (cim_false);
322 }
323 
324 /*
325  * No methods available on an instance of a Solaris_GenericController
326  */
327 
328 /* ARGSUSED */
329 CCIMProperty*
cp_invokeMethod_Solaris_GenericController(CCIMObjectPath * op,cimchar * methodName,CCIMPropertyList * inParams,CCIMPropertyList * outParams)330 cp_invokeMethod_Solaris_GenericController(CCIMObjectPath* op,
331     cimchar* methodName, CCIMPropertyList* inParams,
332 	CCIMPropertyList* outParams)
333 {
334 	CCIMProperty	*retVal = (CCIMProperty*)NULL;
335 	return (retVal);
336 }
337 
338 /*
339  * Name: cp_execQuery_Solaris_GenericController
340  *
341  * Description:
342  * Returns an instance list which matches the query if any are found.
343  *
344  * Parameters:
345  *      CCIMObjectPath *op - An CCIMObjectPath * which contains the
346  *      information on the class for which to find the instances.
347  *
348  *      selectList - Not used
349  *      nonJoinExp - Not used
350  *
351  * Returns:
352  *      CCIMInstanceList * if matched instances are found. Otherwise, NULL.
353  */
354 /*
355  * Currently, there is no WQL parser for the C providers. As a result,
356  * what is returned to the CIMOM is a list of instances with
357  * a NULL value at the beginning of the list. This NULL value indicates
358  * to the CIMOM that it must do the filtering for the client.
359  */
360 
361 /* ARGSUSED */
362 CCIMInstanceList*
cp_execQuery_Solaris_GenericController(CCIMObjectPath * op,cimchar * selectList,cimchar * nonJoinExp,cimchar * queryExp,int queryType)363 cp_execQuery_Solaris_GenericController(CCIMObjectPath *op, cimchar *selectList,
364     cimchar *nonJoinExp, cimchar *queryExp, int queryType)
365 {
366 	CCIMInstanceList	*instList = NULL;
367 	CCIMInstanceList	*result;
368 	CCIMInstance		*emptyInst;
369 	CCIMException		*ex;
370 	int			error;
371 
372 	if (op == NULL) {
373 	    util_handleError(GENERIC_EXECQUERY, CIM_ERR_INVALID_PARAMETER, NULL,
374 		NULL, &error);
375 	    return ((CCIMInstanceList *)NULL);
376 	}
377 
378 	instList = cp_enumInstances_Solaris_GenericController(op);
379 
380 	if (instList == NULL) {
381 	    return ((CCIMInstanceList *)NULL);
382 	}
383 	/*
384 	 * Create a null instance and add it to the beginning
385 	 * of the list to indicate to the CIMOM that no filtering
386 	 * was done.
387 	 */
388 
389 	emptyInst = cim_createInstance("");
390 	if (emptyInst == NULL) {
391 	    ex = cim_getLastError();
392 	    util_handleError(GENERIC_EXECQUERY, CIM_ERR_FAILED,
393 		CREATE_INSTANCE_FAILURE, ex, &error);
394 	    cim_freeInstanceList(instList);
395 	    return ((CCIMInstanceList *)NULL);
396 	}
397 
398 	result = cim_createInstanceList();
399 	if (result == NULL) {
400 	    ex = cim_getLastError();
401 	    util_handleError(GENERIC_EXECQUERY, CIM_ERR_FAILED,
402 		CREATE_INSTANCE_LIST_FAILURE, ex, &error);
403 	    cim_freeInstance(emptyInst);
404 	    cim_freeInstanceList(instList);
405 	    return ((CCIMInstanceList *)NULL);
406 	}
407 
408 	result = cim_addInstance(result, emptyInst);
409 	if (result == NULL) {
410 	    ex = cim_getLastError();
411 	    util_handleError(GENERIC_EXECQUERY, CIM_ERR_FAILED,
412 		ADD_INSTANCE_FAILURE, ex, &error);
413 	    cim_freeInstanceList(instList);
414 	    return ((CCIMInstanceList *)NULL);
415 	}
416 
417 	/*
418 	 * Since copying the original list to the new list will
419 	 * leave no way to free the original list, manually
420 	 * concatenate the original list to the new one.
421 	 */
422 
423 	result->mNext = instList;
424 	return (result);
425 }
426