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 <pthread.h>
30
31 #include "master.h"
32 #include "util.h"
33 #include "providerNames.h"
34 #include "messageStrings.h"
35
36 /* local function declarations */
37 static int FindClassEntry(char *className);
38 static int FindAssocClassEntry(char *className);
39
40
41 /*
42 * Encodes the CIM schema and provider version
43 * into an unsigned long, use
44 * getProviderVersion & getCimVersion to decode
45 */
46
47 unsigned long
cp_getVersion()48 cp_getVersion()
49 {
50 return (MAKEVERSION(1.0, 2.3));
51 }
52
53
54 /*
55 * The function will take CCIMObjectPath
56 * and search the classNameTable[]
57 * for a className match, and then
58 * call the corresponding cp_enumInstance
59 * for that provider
60 */
61
62 CCIMInstanceList*
cp_enumInstances(CCIMObjectPath * pOP)63 cp_enumInstances(CCIMObjectPath* pOP)
64 {
65 CCIMInstanceList *instList = NULL;
66 int index = 0;
67 int error;
68
69 cim_logDebug("cp_enumInstances", "In libDispatch");
70 /* Check if ObjectPath is NULL before continuing */
71 if (pOP == NULL) {
72 /* Set error exception with localized message */
73 util_handleError(ENUM_INSTANCES, CIM_ERR_INVALID_PARAMETER,
74 NULL, NULL, &error);
75 return (NULL);
76 }
77
78 /* Object path is NOT NULL, so find the entry in the table */
79 index = FindClassEntry(pOP->mName);
80
81 /* check for error (-1) */
82 if (index < 0) {
83 util_handleError(ENUM_INSTANCES, CIM_ERR_INVALID_CLASS,
84 NULL, NULL, &error);
85 return (NULL);
86 }
87
88 /* OK, Find enumInstance */
89 instList = (*enumInstanceTable[index])(pOP);
90 return ((CCIMInstanceList*)instList);
91
92 } /* cp_enumInstances */
93
94 /* creates an instance */
95
96 /*
97 * The function will take CCIMObjectPath & CCIMInstance
98 * and search the classNameTable[]
99 * for a className match, and then
100 * call the corresponding cp_createInstance
101 * for that provider
102 */
103
104 CCIMObjectPath*
cp_createInstance(CCIMObjectPath * pOP,CCIMInstance * pInst)105 cp_createInstance(CCIMObjectPath* pOP, CCIMInstance* pInst)
106 {
107 CCIMObjectPath *objPath = NULL;
108 int index = 0;
109 int error;
110
111 /* check if NULL before finding the Instance to create */
112 if (pInst == NULL) {
113 util_handleError(CREATE_INSTANCE,
114 CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
115 return (NULL);
116 }
117
118 /* find entry in the table */
119 index = FindClassEntry(pInst->mClassName);
120
121 /* check for error (-1) */
122 if (index < 0) {
123 util_handleError(CREATE_INSTANCE,
124 CIM_ERR_INVALID_CLASS, NULL, NULL, &error);
125 return (NULL);
126 }
127
128 objPath = (*createInstanceTable[index])(pOP, pInst);
129
130 return ((CCIMObjectPath*) objPath);
131
132 } /* cp_createInstances */
133
134
135 /*
136 * returns an array of CCIMObjectPaths for the class
137 * params:
138 * char* - the classname to enum
139 */
140
141 CCIMObjectPathList*
cp_enumInstanceNames(CCIMObjectPath * pOP)142 cp_enumInstanceNames(CCIMObjectPath* pOP)
143 {
144 CCIMObjectPathList *objList = NULL;
145 CCIMInstanceList *instList = NULL;
146 int error = 0;
147
148 /*
149 * create an instance list which contains all of the
150 * instances this provider will produce First check
151 * for valid ObjectPath
152 */
153 if (pOP == NULL) {
154 util_handleError(ENUM_INSTANCENAMES,
155 CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
156 return (NULL);
157 }
158
159 instList = cp_enumInstances(pOP);
160
161 if (instList == NULL) {
162 return ((CCIMObjectPathList *)NULL);
163 }
164
165 objList = cim_createObjectPathList(instList);
166
167 /*
168 * we no longer need the instList so free
169 * the memory allocated for it
170 */
171
172 cim_freeInstanceList(instList);
173 return (objList);
174 }
175
176 /* get an instance */
177
178 CCIMInstance*
cp_getInstance(CCIMObjectPath * pOP)179 cp_getInstance(CCIMObjectPath* pOP)
180 {
181 CCIMInstance* inst = NULL;
182 int index = 0;
183 int error;
184
185 /* Check if ObjectPath is NULL before continuing */
186 if (pOP == NULL) {
187 util_handleError(GET_INSTANCE, CIM_ERR_INVALID_PARAMETER,
188 NULL, NULL, &error);
189 return (NULL);
190 }
191
192 /* Object path is NOT NULL, so find the entry in the table */
193 index = FindClassEntry(pOP->mName);
194
195 /* check for error (-1) */
196 if (index < 0) {
197 util_handleError(GET_INSTANCE, CIM_ERR_INVALID_CLASS, NULL,
198 NULL, &error);
199 return (NULL);
200 }
201
202 inst = (*getInstanceTable[index])(pOP);
203 return ((CCIMInstance *)inst);
204 }
205
206 /*
207 * returns the specified property,
208 * should return NULL if not found
209 *
210 * params:
211 * CCIMObjectPath* - ObjectPath to get the property from
212 * char* - The property name to get
213 *
214 */
215
216 CCIMProperty*
cp_getProperty(CCIMObjectPath * pOP,char * pPropName)217 cp_getProperty(CCIMObjectPath *pOP, char *pPropName)
218 {
219 CCIMProperty* prop = NULL;
220 CCIMInstance* inst = NULL;
221 int error;
222
223 /* See if ObjectPath is OK */
224 if (pOP == NULL) {
225 util_handleError(GET_PROPERTY, CIM_ERR_INVALID_PARAMETER,
226 NULL, NULL, &error);
227 return (NULL);
228 }
229
230 /* Make sure property name isn't NULL */
231 if (pPropName == NULL) {
232 util_handleError(GET_PROPERTY, CIM_ERR_INVALID_CLASS,
233 NULL, NULL, &error);
234 return (NULL);
235 }
236
237 /* see if we have any instances which match the obj path */
238 inst = cp_getInstance(pOP);
239
240 /* check for valid instance */
241 if (inst == NULL) {
242 util_handleError(GET_PROPERTY, CIM_ERR_FAILED,
243 NULL, NULL, &error);
244 return (NULL);
245 }
246
247 /* see if it has the specified property */
248 prop = cim_getProperty(inst, pPropName);
249
250 /* free memory allocated for the instance */
251 cim_freeInstance(inst);
252
253 /* return the property */
254 return ((CCIMProperty *)prop);
255 }
256
257 /*
258 * Sets the property in the passed in
259 * instance to the new values of the
260 * passed in property
261 *
262 * params:
263 * CCIMObjectPath* - the Object Path in which the property should be changed
264 * CCIMProperty* - a property structure which contains the new values
265 *
266 * return:
267 * cim_true if property was updated otherwise cim_false
268 *
269 *
270 * The function will take CCIMObjectPath & CCIMProperty
271 * and search the classNameTable[]
272 * for a className match, and then
273 * call the corresponding setProperty
274 * for that provider
275 */
276
277 CIMBool
cp_setProperty(CCIMObjectPath * pObjPath,CCIMProperty * pProp)278 cp_setProperty(CCIMObjectPath* pObjPath, CCIMProperty* pProp)
279 {
280 CIMBool retVal;
281 int index = 0;
282 int error;
283
284 if (pObjPath == NULL) {
285 util_handleError(SET_PROPERTY, CIM_ERR_INVALID_PARAMETER,
286 NULL, NULL, &error);
287 return (NULL);
288 }
289
290 index = FindClassEntry(pObjPath->mName);
291
292 /* check for error (-1) */
293 if (index < 0) {
294 util_handleError(SET_PROPERTY, CIM_ERR_INVALID_CLASS,
295 NULL, NULL, &error);
296 return (NULL);
297 }
298
299 retVal = (*setPropertyTable[index])(pObjPath, pProp);
300 return ((CIMBool)retVal);
301 }
302
303
304 /* sets an instance */
305
306 /*
307 * The function will take CCIMObjectPath & CCIMInstance
308 * and search the classNameTable[]
309 * for a className match, and then
310 * call the corresponding cp_setInstance
311 * for that provider
312 */
313
314 CIMBool
cp_setInstance(CCIMObjectPath * pOP,CCIMInstance * pInst)315 cp_setInstance(CCIMObjectPath* pOP, CCIMInstance* pInst)
316 {
317 CIMBool retVal;
318 int index = 0;
319 int error;
320
321 if (pOP == NULL) {
322 util_handleError(SET_INSTANCE, CIM_ERR_INVALID_PARAMETER,
323 NULL, NULL, &error);
324 return (NULL);
325 }
326
327 if (pInst == NULL) {
328 util_handleError(SET_INSTANCE, CIM_ERR_INVALID_CLASS,
329 NULL, NULL, &error);
330 return (NULL);
331 }
332
333 /* get the index into the table */
334 index = FindClassEntry(pInst->mClassName);
335
336 /* check for error (-1) */
337 if (index < 0) {
338 util_handleError(SET_INSTANCE, CIM_ERR_INVALID_CLASS,
339 NULL, NULL, &error);
340 return (NULL);
341 }
342
343 retVal = (*setInstanceTable[index])(pOP, pInst);
344 return ((CIMBool)retVal);
345 }
346
347
348 /*
349 * deletes an instance
350 *
351 * The function will take CCIMObjectPath
352 * and search the classNameTable[]
353 * for a className match, and then
354 * call the corresponding cp_deleteInstance
355 * for that provider
356 */
357
358 CIMBool
cp_deleteInstance(CCIMObjectPath * pOP)359 cp_deleteInstance(CCIMObjectPath* pOP)
360 {
361 CIMBool retVal;
362 int index = 0;
363 int error;
364
365 /* Verify ObjectPath is NOT NULL */
366 if (pOP == NULL) {
367 util_handleError(DELETE_INSTANCE, CIM_ERR_INVALID_PARAMETER,
368 NULL, NULL, &error);
369 return (NULL);
370 }
371
372 /* find Entry in table */
373 index = FindClassEntry(pOP->mName);
374
375 /* check for error (-1) */
376 if (index < 0) {
377 util_handleError(DELETE_INSTANCE, CIM_ERR_INVALID_CLASS,
378 NULL, NULL, &error);
379 return (NULL);
380 }
381
382 retVal = (*deleteInstanceTable[index])(pOP);
383 return ((CIMBool)retVal);
384 }
385
386 /*
387 * Invokes the method and returns the results
388 * The caller is responsible for freeing the
389 * memory allocated for the returned object
390 *
391 * params:
392 * CCIMObjectPath* - An object path of the instance
393 * to invoke the function on
394 * char* - name of the method to invoke
395 * CCIMPropertyList* - input parameters to the function
396 * CCIMPropertyList* - input/output parameters to the function
397 *
398 * returns:
399 * NULL if it failed otherwise a CCIMProperty*
400 * which represents the return value of the function
401 */
402
403 CCIMProperty*
cp_invokeMethod(CCIMObjectPath * pOP,cimchar * pName,CCIMPropertyList * pInParams,CCIMPropertyList * pInOutParams)404 cp_invokeMethod(CCIMObjectPath* pOP, cimchar* pName,
405 CCIMPropertyList* pInParams, CCIMPropertyList* pInOutParams)
406 {
407 CCIMProperty *prop;
408 int index = 0;
409 int error;
410
411 /* First check for valid ObjectPath */
412 if (pOP == NULL) {
413 util_handleError(INVOKE_METHOD, CIM_ERR_INVALID_PARAMETER,
414 NULL, NULL, &error);
415 return (NULL);
416 }
417
418 /* find entry in the table */
419 index = FindClassEntry(pOP->mName);
420
421 /* check for error (-1) */
422 if (index < 0) {
423 util_handleError(INVOKE_METHOD, CIM_ERR_INVALID_CLASS,
424 NULL, NULL, &error);
425 return (NULL);
426 }
427
428 prop = (*cpInvokeMethodTable[index])
429 (pOP, pName, pInParams, pInOutParams);
430
431 return ((CCIMProperty*)prop);
432 }
433
434 /*
435 * cp_execQuery
436 */
437
438 CCIMInstanceList*
cp_execQuery(CCIMObjectPath * pOP,char * selectList,char * nonJoinExp,char * queryExp,char * queryType)439 cp_execQuery(CCIMObjectPath *pOP, char *selectList,
440 char *nonJoinExp, char *queryExp, char *queryType)
441 {
442 CCIMInstanceList *instList = NULL;
443 int index = 0;
444 int error = 0;
445
446
447 /* First check for valid ObjectPath */
448 if (pOP == NULL) {
449 util_handleError(EXEC_QUERY, CIM_ERR_INVALID_PARAMETER, NULL, NULL,
450 &error);
451 return ((CCIMInstanceList *)NULL);
452 }
453
454 /* find entry in the table */
455 index = FindClassEntry(pOP->mName);
456
457 /* check for error (-1) */
458 if (index < 0) {
459 /* Set error exception with localized message */
460 util_handleError(EXEC_QUERY, CIM_ERR_INVALID_CLASS, NULL,
461 NULL, &error);
462 return ((CCIMInstanceList *)NULL);
463 }
464 instList = (*execQueryTable[index])(pOP, selectList, nonJoinExp,
465 queryExp, queryType);
466
467 return (instList);
468 }
469
470 /*
471 * cp_associators
472 */
473
474 CCIMInstanceList*
cp_associators(CCIMObjectPath * pAssocName,CCIMObjectPath * pObjectName,char * pResultClass,char * pRole,char * pResultRole)475 cp_associators(CCIMObjectPath *pAssocName, CCIMObjectPath *pObjectName,
476 char *pResultClass, char *pRole, char *pResultRole)
477 {
478 CCIMInstanceList *instList;
479 int index = 0;
480 int error = 0;
481
482 /* First check for valid ObjectPath */
483 if (pAssocName == NULL) {
484 /* Set error exception with localized message */
485 util_handleError(ASSOCIATORS, CIM_ERR_INVALID_PARAMETER, NULL,
486 NULL, &error);
487 return ((CCIMInstanceList *)NULL);
488 }
489
490 /* find entry in the table */
491 index = FindAssocClassEntry(pAssocName->mName);
492
493 /* check for error (-1) */
494 if (index < 0) {
495 /* Set error exception with localized message */
496 util_handleError(ASSOCIATORS, CIM_ERR_INVALID_CLASS, NULL,
497 NULL, &error);
498 return ((CCIMInstanceList *)NULL);
499 }
500
501 /*
502 * Call the appropriate associator function. Let the specific function
503 * in the c provider handle the checking for correctness of the
504 * other parameters.
505 */
506
507 instList = (*associatorsTable[index])(pAssocName, pObjectName,
508 pResultClass, pRole, pResultRole);
509 return ((CCIMInstanceList *)instList);
510 }
511
512 /*
513 * cp_associatorNames
514 */
515
516 CCIMObjectPathList*
cp_associatorNames(CCIMObjectPath * pAssocName,CCIMObjectPath * pObjectName,char * pResultClass,char * pRole,char * pResultRole)517 cp_associatorNames(CCIMObjectPath *pAssocName, CCIMObjectPath *pObjectName,
518 char *pResultClass, char *pRole, char *pResultRole)
519 {
520 CCIMObjectPathList *objList;
521 int index = 0;
522 int error = 0;
523
524 /* First check for valid ObjectPath */
525 if (pAssocName == NULL) {
526 /* Set error exception with localized message */
527 util_handleError(ASSOCIATORS, CIM_ERR_INVALID_PARAMETER, NULL,
528 NULL, &error);
529 return ((CCIMObjectPathList *)NULL);
530 }
531
532 /* find entry in the table */
533 index = FindAssocClassEntry(pAssocName->mName);
534
535 /* check for error (-1) */
536 if (index < 0) {
537 /* Set error exception with localized message */
538 util_handleError(ASSOCIATORS, CIM_ERR_INVALID_CLASS, NULL,
539 NULL, &error);
540 return ((CCIMObjectPathList *)NULL);
541 }
542
543 /*
544 * Call the appropriate associatorName function. Let the specific
545 * function in the c provider handle the checking for correctness of
546 * the other parameters.
547 */
548
549 objList = (*associatorNamesTable[index])(pAssocName, pObjectName,
550 pResultClass, pRole, pResultRole);
551 return ((CCIMObjectPathList *)objList);
552 }
553
554 /*
555 * cp_references
556 */
557
558 CCIMInstanceList*
cp_references(CCIMObjectPath * pAssocName,CCIMObjectPath * pObjectName,char * pRole)559 cp_references(CCIMObjectPath *pAssocName, CCIMObjectPath *pObjectName,
560 char *pRole)
561 {
562 CCIMInstanceList *instList;
563 int index = 0;
564 int error = 0;
565
566 /* First check for valid ObjectPath */
567 if (pAssocName == NULL) {
568 /* Set error exception with localized message */
569 util_handleError(REFERENCES, CIM_ERR_INVALID_PARAMETER, NULL,
570 NULL, &error);
571 return ((CCIMInstanceList *)NULL);
572 }
573
574 /* find entry in the table */
575 index = FindAssocClassEntry(pAssocName->mName);
576
577 /* check for error (-1) */
578 if (index < 0) {
579 /* Set error exception with localized message */
580 util_handleError(REFERENCES, CIM_ERR_INVALID_CLASS, NULL,
581 NULL, &error);
582 return ((CCIMInstanceList *)NULL);
583 }
584
585 /*
586 * Call the appropriate references function. Let the specific function
587 * in the c provider handle the checking for correctness of the
588 * other parameters.
589 */
590
591 instList = (*referencesTable[index])(pAssocName, pObjectName, pRole);
592 return ((CCIMInstanceList *)instList);
593 }
594
595 /*
596 * InParam: Class Name
597 * Returns: Index into Name Table
598 * If it hit libWBEMnfs, then we
599 * have hit bottom, return err (-1)
600 */
601
602 static int
FindClassEntry(char * className)603 FindClassEntry(char *className)
604 {
605 int i = 0;
606
607 while (strcasecmp(className, classNameTable[i])) {
608 if (!strcasecmp(classNameTable[i], "libWBEMnfs")) {
609 i = -1;
610 break;
611 }
612 i++;
613 }
614
615 return (i);
616 }
617 /*
618 * InParam: Class Name
619 * Returns: Index into Name Table
620 * If it hit libWBEMnfs, then we
621 * have hit bottom, return err (-1)
622 */
623
624 static int
FindAssocClassEntry(char * className)625 FindAssocClassEntry(char *className)
626 {
627 int i = 0;
628
629 while (strcasecmp(className, assocclassNameTable[i])) {
630 if (!strcasecmp(assocclassNameTable[i], "libWBEMnfs")) {
631 i = -1;
632 break;
633 }
634 i++;
635 }
636
637 return (i);
638 }
639
640 /*
641 * cp_referenceNames
642 */
643
644 CCIMObjectPathList*
cp_referenceNames(CCIMObjectPath * pAssocName,CCIMObjectPath * pObjectName,char * pRole)645 cp_referenceNames(CCIMObjectPath *pAssocName, CCIMObjectPath *pObjectName,
646 char *pRole)
647 {
648 CCIMObjectPathList *objList;
649 int index = 0;
650 int error = 0;
651
652 /* First check for valid ObjectPath */
653 if (pAssocName == NULL) {
654 /* Set error exception with localized message */
655 util_handleError(REFERENCE_NAMES, CIM_ERR_INVALID_PARAMETER,
656 NULL, NULL, &error);
657 return ((CCIMObjectPathList *)NULL);
658 }
659
660 /* find entry in the table */
661 index = FindAssocClassEntry(pAssocName->mName);
662
663 /* check for error (-1) */
664 if (index < 0) {
665 /* Set error exception with localized message */
666 util_handleError(REFERENCE_NAMES, CIM_ERR_INVALID_CLASS,
667 NULL, NULL, &error);
668 return ((CCIMObjectPathList *)NULL);
669 }
670
671 /*
672 * Call the appropriate referenceName function. Let the specific
673 * function in the c provider handle the checking for correctness of
674 * the other parameters.
675 */
676
677 objList = (*referenceNamesTable[index])(pAssocName, pObjectName, pRole);
678 return ((CCIMObjectPathList *)objList);
679 }
680
681 CIMBool
cp_isAssociatorProvider(CCIMObjectPath * pOp)682 cp_isAssociatorProvider(CCIMObjectPath *pOp)
683 {
684
685 int index = 0;
686 int error = 0;
687
688 /*
689 * If the object path coming in matches any in the associator table,
690 * return true, otherwise, return false.
691 */
692
693 /* First check for valid ObjectPath */
694 if (pOp == NULL) {
695 /* Set error exception with localized message */
696 util_handleError(REFERENCE_NAMES, CIM_ERR_INVALID_PARAMETER,
697 NULL, NULL, &error);
698 return (cim_false);
699 }
700
701 /* find entry in the table */
702 index = FindAssocClassEntry(pOp->mName);
703
704 if (index < 0) {
705 return (cim_false);
706 }
707 return (cim_true);
708 }
709