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 "Solaris_HostedShare.h"
30 #include "nfs_keys.h"
31 #include "nfs_providers_msgstrings.h"
32 #include "messageStrings.h"
33 #include "nfs_provider_names.h"
34 #include "util.h"
35 #include "libfsmgt.h"
36 #include "common_functions.h"
37 #include "createprop_methods.h"
38 
39 /*
40  * Private method declarations
41  */
42 static CIMBool		does_share_exist(char *dir);
43 static CCIMObjectPath*	get_Antecedent();
44 
45 /*
46  * Public methods
47  */
48 
49 /*
50  * Instance provider methods
51  */
52 
53 /*
54  * Method: cp_createInstance_Solaris_HostedShare
55  *
56  * Description: This method is not supported.  It is not supported because in
57  * order for a Solaris_HostedShare association to exist a corresponding
58  * Solaris_NFSShare and Solaris_ComputerSystem must exist.
59  *
60  * Parameters:
61  *	- CCIMObjectPath *hostedShareOP - An object path containing the name of
62  *	the class of which to create an instance of.
63  *	- CCIMInstance *hostedShareInst - Not used.
64  *
65  * Returns:
66  *	- Always returns NULL because the method is not supported.
67  */
68 /* ARGSUSED */
69 CCIMObjectPath *
cp_createInstance_Solaris_HostedShare(CCIMObjectPath * hostedShareOP,CCIMInstance * hostedShareInst)70 cp_createInstance_Solaris_HostedShare(CCIMObjectPath *hostedShareOP,
71 	CCIMInstance *hostedShareInst) {
72 
73 	int	err = 0;
74 
75 	util_handleError("SOLARIS_HOSTEDSHARE::CREATE_INSTANCE",
76 		CIM_ERR_NOT_SUPPORTED, NULL, NULL, &err);
77 
78 	return ((CCIMObjectPath *)NULL);
79 } /* cp_createInstance_Solaris_HostedShare */
80 
81 /*
82  * Method: cp_deleteInstance_Solaris_HostedShare
83  *
84  * Description: This method is not supported.  It is not supported because in
85  * order for it to be actually deleted the corresponding Solaris_NFSShare would
86  * need to be deleted.  That action is not appropriate for this provider.
87  *
88  * Parameters:
89  *	- CCIMObjectPath *hostedShareOP - An object path containing the
90  *	information about the class of which to delete the instance of.
91  *
92  * Returns:
93  *	- Always returns cim_false because the method is not supported.
94  */
95 /* ARGSUSED */
96 CIMBool
cp_deleteInstance_Solaris_HostedShare(CCIMObjectPath * hostedShareOP)97 cp_deleteInstance_Solaris_HostedShare(CCIMObjectPath *hostedShareOP) {
98 	int	err = 0;
99 
100 	util_handleError("SOLARIS_HOSTEDSHARE::DELETE_INSTANCE",
101 		CIM_ERR_NOT_SUPPORTED, NULL, NULL, &err);
102 
103 	return (cim_false);
104 } /* cp_deleteInstance_Solaris_HostedShare */
105 
106 /*
107  * Method: cp_enumInstances_Solaris_HostedShare
108  *
109  * Description: Enumerates the instances of Solaris_HostedShare on a host.
110  * An instance of Solaris_HostedShare is an association that links a share to
111  * the hosting machine.
112  *
113  * Parameters:
114  *	- CCIMObjectPath *hostedShareOP - An object path containing the name of
115  *	the class of which to enumerate the instances of.
116  *
117  * Returns:
118  *	- A pointer to a list of Solaris_HostedShare instances.
119  *	- NULL if an error occurred or if there are no instances of
120  *	Solaris_HostedShare on the host.  In the case of an error, the error
121  *	will be logged.
122  */
123 CCIMInstanceList *
cp_enumInstances_Solaris_HostedShare(CCIMObjectPath * hostedShareOP)124 cp_enumInstances_Solaris_HostedShare(CCIMObjectPath* hostedShareOP) {
125 	CCIMInstanceList	*hostedShareInstList;
126 	CCIMObjectPath		*nfsShareOP;
127 	CCIMObjectPathList	*nfsShareOPList, *currentShareOP;
128 	CCIMObjectPath		*antOP;
129 	CCIMException		*ex;
130 	int			err = 0;
131 
132 	/*
133 	 * The Antecedent property is a Solaris_ComputerSystem reference.
134 	 * The Dependent property is a Solaris_NFSShare reference.
135 	 */
136 	if (hostedShareOP == NULL) {
137 		util_handleError("SOLARIS_HOSTEDSHARE::ENUM_INSTANCES",
138 			CIM_ERR_INVALID_PARAMETER, NULL, NULL, &err);
139 		return ((CCIMInstanceList *)NULL);
140 	}
141 
142 	nfsShareOP = cim_createEmptyObjectPath(SOLARIS_NFSSHARE);
143 	if (nfsShareOP == NULL) {
144 		ex = cim_getLastError();
145 		util_handleError("SOLARIS_HOSTEDSHARE::ENUM_INSTANCES",
146 			CIM_ERR_FAILED, CREATE_EMPTY_OBJPATH_FAILURE, ex, &err);
147 		return ((CCIMInstanceList *)NULL);
148 	}
149 
150 	/*
151 	 * Enumerate all of the Solaris_NFSShare object paths on the system.
152 	 */
153 	nfsShareOPList = cimom_enumerateInstanceNames(nfsShareOP, cim_false);
154 
155 	/*
156 	 * A NULL return value indicates an error, an empty list does not.
157 	 */
158 	if (nfsShareOPList == NULL) {
159 		cim_logDebug("cp_enumInstances_Solaris_HostedShare",
160 			"nfsShareOPList = NULL");
161 		ex = cim_getLastError();
162 		util_handleError("SOLARIS_HOSTEDSHARE::ENUM_INSTANCES",
163 			CIM_ERR_FAILED, CIMOM_ENUM_INSTNAMES_FAILURE, ex, &err);
164 		cim_freeObjectPath(nfsShareOP);
165 		return ((CCIMInstanceList *)NULL);
166 
167 	}
168 
169 	cim_freeObjectPath(nfsShareOP);
170 
171 	if (nfsShareOPList->mDataObject == NULL) {
172 		return ((CCIMInstanceList *)NULL);
173 	}
174 
175 	antOP = get_Antecedent();
176 	if (antOP == NULL) {
177 		/*
178 		 * The error was logged in get_Antecedent.
179 		 */
180 		cim_freeObjectPathList(nfsShareOPList);
181 		return ((CCIMInstanceList *)NULL);
182 	}
183 
184 	hostedShareInstList = cim_createInstanceList();
185 	if (hostedShareInstList == NULL) {
186 		ex = cim_getLastError();
187 		util_handleError("SOLARIS_HOSTEDSHARE::ENUM_INSTANCES",
188 			CIM_ERR_FAILED, CREATE_INSTANCE_LIST_FAILURE, ex, &err);
189 		cim_freeObjectPathList(nfsShareOPList);
190 		cim_freeObjectPath(antOP);
191 		return ((CCIMInstanceList *)NULL);
192 	}
193 
194 	/*
195 	 * Each share on the system will be associated with the same
196 	 * Solaris_ComputerSystem object path.
197 	 */
198 	for (currentShareOP = nfsShareOPList; currentShareOP != NULL;
199 		currentShareOP = currentShareOP->mNext) {
200 
201 		CCIMInstance	*hostedShareInst;
202 		cimchar		*propValue;
203 
204 		hostedShareInst = cim_createInstance(SOLARIS_HOSTEDSHARE);
205 		if (hostedShareInst == NULL) {
206 			ex = cim_getLastError();
207 			util_handleError("SOLARIS_HOSTEDSHARE::ENUM_INSTANCES",
208 				CIM_ERR_FAILED, CREATE_INSTANCE_FAILURE, ex,
209 				&err);
210 			cim_freeInstanceList(hostedShareInstList);
211 			cim_freeObjectPath(antOP);
212 			cim_freeObjectPathList(nfsShareOPList);
213 			return ((CCIMInstanceList *)NULL);
214 		}
215 
216 		propValue = NULL;
217 		if (add_property_to_instance(
218 			hostedShareProps[ANT].name, hostedShareProps[ANT].type,
219 			propValue, antOP, hostedShareProps[ANT].isKey,
220 			hostedShareInst) == cim_false) {
221 
222 			cim_freeInstance(hostedShareInst);
223 			cim_freeInstanceList(hostedShareInstList);
224 			cim_freeObjectPathList(nfsShareOPList);
225 			cim_freeObjectPath(antOP);
226 			return ((CCIMInstanceList *)NULL);
227 		}
228 
229 		if (add_property_to_instance(hostedShareProps[DEP].name,
230 			hostedShareProps[DEP].type, propValue,
231 			currentShareOP->mDataObject,
232 			hostedShareProps[DEP].isKey, hostedShareInst)
233 			== cim_false) {
234 
235 			cim_freeInstance(hostedShareInst);
236 			cim_freeInstanceList(hostedShareInstList);
237 			cim_freeObjectPathList(nfsShareOPList);
238 			cim_freeObjectPath(antOP);
239 			return ((CCIMInstanceList *)NULL);
240 		}
241 
242 		hostedShareInstList = cim_addInstance(hostedShareInstList,
243 			hostedShareInst);
244 		if (hostedShareInstList == NULL) {
245 			ex = cim_getLastError();
246 			util_handleError("SOLARIS_HOSTEDSHARE::ENUM_INSTANCES",
247 				CIM_ERR_FAILED, ADD_INSTANCE_FAILURE, ex, &err);
248 			cim_freeInstance(hostedShareInst);
249 			cim_freeObjectPathList(nfsShareOPList);
250 			cim_freeObjectPath(antOP);
251 			return ((CCIMInstanceList *)NULL);
252 		}
253 	}
254 
255 	cim_freeObjectPath(antOP);
256 	cim_freeObjectPathList(nfsShareOPList);
257 
258 	return (hostedShareInstList);
259 } /* cp_enumInstances_Solaris_HostedShare */
260 
261 /*
262  * Method: cp_enumInstanceNames_Solaris_HostedShare
263  *
264  * Description: Enumerates the instances of Solaris_HostedShare on the host.
265  *
266  * Parameters:
267  *	- CCIMObjectPath *hostedShareOP - An object path containing the name of
268  *	the class of which to enumerate the instance names of.
269  *
270  * Returns:
271  *	- A list of object paths corresponding to the instances of
272  *	Solaris_HostedShare on the host.
273  *	- NULL if an error occurred or if there are no instances of
274  *	Solaris_HostedShare on the host.  In the case of an error, the error
275  *	will be logged.
276  */
277 CCIMObjectPathList *
cp_enumInstanceNames_Solaris_HostedShare(CCIMObjectPath * hostedShareOP)278 cp_enumInstanceNames_Solaris_HostedShare(CCIMObjectPath *hostedShareOP) {
279 	CCIMInstanceList	*hostedShareInstList;
280 	CCIMObjectPathList	*hostedShareOPList;
281 	int			err = 0;
282 
283 	if (hostedShareOP == NULL) {
284 		util_handleError("SOLARIS_HOSTEDSHARE::ENUM_INSTANCENAMES",
285 			CIM_ERR_INVALID_PARAMETER, NULL, NULL, &err);
286 		return ((CCIMObjectPathList *)NULL);
287 	}
288 
289 	hostedShareInstList =
290 		cp_enumInstances_Solaris_HostedShare(hostedShareOP);
291 	if (hostedShareInstList == NULL) {
292 		/*
293 		 * An error occurred in enumInstances or there are simply
294 		 * no Solaris_HostedShare instances to enumerate.  In the case,
295 		 * of an error, the error would have been handled in the
296 		 * cp_enumInstances_Solaris_HostedShare function.
297 		 */
298 		return ((CCIMObjectPathList *)NULL);
299 	}
300 
301 	hostedShareOPList = cim_createObjectPathList(hostedShareInstList);
302 
303 	cim_freeInstanceList(hostedShareInstList);
304 	/*
305 	 * If an error occurred it will be handled in cim_createObjectPathList.
306 	 */
307 	return (hostedShareOPList);
308 } /* cp_enumInstanceNames_Solaris_HostedShare */
309 
310 /*
311  * Method: cp_execQuery_Solaris_HostedShare
312  *
313  * Description: Queries the host to find those Solaris_HostedShare instances
314  * that meet the search criteria.
315  *
316  * Parameters:
317  *	- CCIMObjectPath *hostedShareOP - An object path containing the name of
318  *	the class of which to query.
319  *	- char *selectClause - Not used.
320  *	- char *nonJoinExp - Not used.
321  *	- char *queryExp - Not used.
322  *	- char *queryLang - Not used.
323  *
324  * Returns:
325  *      - A pointer to a list of Solaris_HostedShare instances that match the
326  *      criteria.
327  *      - NULL if an error occurred or if there are no Solaris_HostedShare
328  *      instances that match the criteria.  In the case of an error, the error
329  *      will be logged.
330  *
331  * NOTE: Currently, there is no WQL parser for the C providers. As a result,
332  * what is returned to the CIMOM is a list of instances with
333  * a NULL value at the beginning of the list. This NULL value indicates
334  * to the CIMOM that it must do the filtering for the client.
335  */
336 /* ARGSUSED */
337 CCIMInstanceList *
cp_execQuery_Solaris_HostedShare(CCIMObjectPath * hostedShareOP,char * selectClause,char * nonJoinExp,char * queryExp,char * queryLang)338 cp_execQuery_Solaris_HostedShare(CCIMObjectPath *hostedShareOP,
339 	char *selectClause, char *nonJoinExp, char *queryExp, char *queryLang) {
340 
341 	CCIMInstance		*emptyInst;
342 	CCIMInstanceList	*hostedShareInstList;
343 	CCIMException		*ex;
344 	int			err = 0;
345 
346 	if (hostedShareOP == NULL) {
347 		util_handleError("SOLARIS_HOSTEDSHARE::EXEC_QUERY",
348 			CIM_ERR_INVALID_PARAMETER, NULL, NULL, &err);
349 		return ((CCIMInstanceList *)NULL);
350 	}
351 
352 	hostedShareInstList = cp_enumInstances_Solaris_HostedShare(
353 		hostedShareOP);
354 	if (hostedShareInstList == NULL) {
355 		return ((CCIMInstanceList *)NULL);
356 	}
357 
358 	emptyInst = cim_createInstance("");
359 	if (emptyInst == NULL) {
360 		ex = cim_getLastError();
361 		util_handleError("SOLARIS_HOSTEDSHARE::EXEC_QUERY",
362 			CIM_ERR_FAILED, CREATE_INSTANCE_FAILURE, ex, &err);
363 		cim_freeInstanceList(hostedShareInstList);
364 		return ((CCIMInstanceList *)NULL);
365 	}
366 
367 	hostedShareInstList = cim_prependInstance(hostedShareInstList,
368 		emptyInst);
369 
370 	if (hostedShareInstList == NULL) {
371 		ex = cim_getLastError();
372 		util_handleError("SOLARIS_HOSTEDSHARE::EXEC_QUERY",
373 			CIM_ERR_FAILED, PREPEND_INSTANCE_FAILURE, ex, &err);
374 		cim_freeInstance(emptyInst);
375 		return ((CCIMInstanceList *)NULL);
376 	}
377 
378 	return (hostedShareInstList);
379 } /* cp_execQuery_Solaris_HostedShare */
380 
381 /*
382  * Method: cp_getInstance_Solaris_HostedShare
383  *
384  * Description: Gets the instance corresponding to the passed in object path.
385  *
386  * Parameters:
387  *	- CCIMObjectPath *hostedShareOP - The object path containing all the
388  *	keys of the instance that is supposed to be returned.
389  *
390  * Returns:
391  *	- A pointer to the instance of Solaris_HostedShare corresponding to
392  *	hostedShareOP.
393  *	- NULL if an error occurred or if the instance doesn't exist on the
394  *	host.  In the case of an error, the error will be logged.
395  */
396 CCIMInstance *
cp_getInstance_Solaris_HostedShare(CCIMObjectPath * hostedShareOP)397 cp_getInstance_Solaris_HostedShare(CCIMObjectPath *hostedShareOP) {
398 	CCIMInstance		*inst;
399 	CCIMInstanceList	*instList;
400 	CCIMPropertyList	*hsPropList;
401 	CCIMObjectPath		*depOP;
402 	CCIMObjectPath		*antOP;
403 	int			err = 0;
404 
405 	if (hostedShareOP == NULL || hostedShareOP->mKeyProperties == NULL) {
406 		util_handleError("SOLARIS_HOSTEDSHARE::GET_INSTANCE",
407 			CIM_ERR_INVALID_PARAMETER, NULL, NULL, &err);
408 		return ((CCIMInstance *)NULL);
409 	}
410 
411 	/*
412 	 * Get the Dependent and Antecedent properties.
413 	 */
414 	hsPropList = hostedShareOP->mKeyProperties;
415 	depOP = util_getKeyValue(hsPropList, hostedShareProps[DEP].type,
416 		hostedShareProps[DEP].name, &err);
417 	antOP = util_getKeyValue(hsPropList, hostedShareProps[ANT].type,
418 		hostedShareProps[ANT].name, &err);
419 
420 	/*
421 	 * Check if we have the Antecedent and Dependent properties.
422 	 */
423 	if (depOP == NULL || antOP == NULL ||
424 		depOP->mKeyProperties == NULL ||
425 		antOP->mKeyProperties == NULL) {
426 		util_handleError("SOLARIS_HOSTEDSHARE::GET_INSTANCE",
427 			CIM_ERR_INVALID_PARAMETER, NULL, NULL, &err);
428 		return ((CCIMInstance *)NULL);
429 	}
430 
431 	instList = cp_enumInstances_Solaris_HostedShare(hostedShareOP);
432 	if (instList == NULL) {
433 		return ((CCIMInstance *)NULL);
434 	}
435 
436 	inst = cim_getInstance(instList, hostedShareOP);
437 
438 	cim_freeInstanceList(instList);
439 	return (inst);
440 } /* cp_getInstance_Solaris_HostedShare */
441 
442 /*
443  * Method: cp_setInstance_Solaris_HostedShare
444  *
445  * Description: This method is not supported.  It is not supported because in
446  * order to change a Solaris_HostedShare instance the underlying share and
447  * computer system must be modified.  Those actions must be done on the
448  * appropriate share and computer system objects, not here.
449  *
450  * Parameters:
451  *	- CCIMObjectPath *pOP - An object path containing the name of the class
452  *	of which to set the instance.
453  *	- CCIMInstance *pInst - Not used.
454  *
455  * Returns:
456  *	- Always returns cim_false, because the method is not supported.
457  */
458 /* ARGSUSED */
459 CIMBool
cp_setInstance_Solaris_HostedShare(CCIMObjectPath * pOP,CCIMInstance * pInst)460 cp_setInstance_Solaris_HostedShare(CCIMObjectPath *pOP, CCIMInstance *pInst) {
461 
462 	int	err = 0;
463 
464 	util_handleError("SOLARIS_HOSTEDSHARE::SET_INSTANCE",
465 		CIM_ERR_NOT_SUPPORTED, NULL, NULL, &err);
466 
467 	return (cim_false);
468 } /* cp_setInstance_Solaris_HostedShare */
469 
470 /*
471  * Method: cp_setInstanceWithList_Solaris_HostedShare
472  *
473  * Description: This method is not supported.  It is not supported because in
474  * order to change a Solaris_HostedShare instance the underlying share and
475  * computer system must be modified.  Those actions must be done on the
476  * appropriate share and computer system objects, not here.
477  *
478  * Parameters:
479  *	- CCIMObjectPath *hostedShareOP - The object path containing the name
480  *	of the class of which to set the instance.
481  *	- CCIMInstance *hostedShareInst - Not used.
482  *	- char **props - Not used.
483  *	- int num_props - Not used.
484  *
485  * Returns:
486  *      - Always returns cim_false, because the method is not supported.
487  */
488 /* ARGSUSED */
489 CIMBool
cp_setInstanceWithList_Solaris_HostedShare(CCIMObjectPath * hostedShareOP,CCIMInstance * hostedShareInst,char ** props,int num_props)490 cp_setInstanceWithList_Solaris_HostedShare(CCIMObjectPath *hostedShareOP,
491 	CCIMInstance *hostedShareInst, char **props, int num_props) {
492 
493 	int	err = 0;
494 
495 	util_handleError("SOLARIS_HOSTEDSHARE::SET_INSTANCE",
496 		CIM_ERR_NOT_SUPPORTED, NULL, NULL, &err);
497 
498 	return (cim_false);
499 } /* cp_setInstanceWithList_Solaris_HostedShare */
500 
501 /*
502  * Association provider methods
503  */
504 
505 /*
506  * Method: cp_associators_Solaris_HostedShare
507  *
508  * Description: Returns the instances associated, via the Solaris_HostedShare
509  * association, to the pObjectName parameter.
510  *
511  * Parameters:
512  *	- CCIMObjectPath *pAssocName - An object path containing the name of
513  *	the association that the caller is trying to reach.
514  *	- CCIMObjectPath *pObjectName - The object path containing information
515  *	(Class Name, Key Properties) about the object whose associated objects
516  *	are to be returned.
517  *	- char *pResultClass - If specified, only return instances that are of
518  *	this class type.
519  *	- char *pRole - If specified, this is the role of the pObjectName
520  *	object path passed in.  If this is not valid, NULL is returned.
521  *	- char *pResultRole - If specified, only return instances that are
522  *	playing this role in the association.
523  *
524  * Returns:
525  *	- A list of Solaris_NFSShare (if pRole == Antecedent && pObjectName is
526  *	a Solaris_ComputerSystem object path) or Solaris_ComputerSystem (if
527  *	pRole == Dependent && pObjectName is a Solaris_NFSShare object path)
528  *	instances which are associated to the pObjectName parameter.
529  *	- NULL if an error occurred or if there are no instances associated to
530  *	the pObjectName passed in.  In the case of an error, the error will be
531  *	logged.
532  */
533 /* ARGSUSED */
534 CCIMInstanceList *
cp_associators_Solaris_HostedShare(CCIMObjectPath * pAssocName,CCIMObjectPath * pObjectName,char * pResultClass,char * pRole,char * pResultRole)535 cp_associators_Solaris_HostedShare(CCIMObjectPath *pAssocName,
536 	CCIMObjectPath *pObjectName, char *pResultClass, char *pRole,
537 	char *pResultRole) {
538 
539 	CCIMInstanceList	*returnInstList = NULL;
540 	CCIMPropertyList	*propList;
541 	CCIMObjectPath		*resultOP;
542 	CCIMException		*ex;
543 	CIMBool			pDeep, pLocalOnly, pIncludeQualifiers,
544 				pIncludeClassOrigin, pUseInternal;
545 	cimchar			*resultClassName;
546 	char			*name;
547 	char			**pPropertyList;
548 	unsigned int		pNumProps;
549 	int			err = 0;
550 	/*
551 	 * Check if the needed parameters are NULL.
552 	 */
553 	if (pObjectName == NULL || pObjectName->mKeyProperties == NULL) {
554 		util_handleError("SOLARIS_HOSTEDSHARE::ASSOCIATORS",
555 			CIM_ERR_INVALID_PARAMETER, NULL, NULL, &err);
556 		return ((CCIMInstanceList *)NULL);
557 	}
558 
559 	/*
560 	 * The Name key property is the defining property for each the
561 	 * Antecedent (Solaris_ComputerSystem) and the Dependent
562 	 * (Solaris_NFSShare) so retrieve that property.
563 	 */
564 	propList = pObjectName->mKeyProperties;
565 	name = (cimchar *)util_getKeyValue(propList, string, NAME, &err);
566 
567 	if (name == NULL || err != 0) {
568 		/*
569 		 * We don't have the appropriate information.
570 		 */
571 		util_handleError("SOLARIS_HOSTEDSHARE::ASSOCIATORS",
572 			CIM_ERR_INVALID_PARAMETER, NULL, NULL, &err);
573 		return ((CCIMInstanceList *)NULL);
574 	}
575 
576 	/*
577 	 * Determine whether the pObjectName is the Antecedent or the Dependent
578 	 * of the association.  Antecedent == Solaris_ComputerSystem,
579 	 * Dependent == Solaris_NFSShare
580 	 */
581 	if ((strcasecmp(pObjectName->mName, COMPUTER_SYSTEM) == 0)) {
582 		char	*hostname;
583 
584 		resultClassName = SOLARIS_NFSSHARE;
585 
586 		/*
587 		 * If a value was passed in with pRole and it does not match
588 		 * the role that pObjectName actually is then log an invalid
589 		 * param error.
590 		 */
591 		if (pRole != NULL && (strcasecmp(pRole, ANTECEDENT) != 0)) {
592 			util_handleError("SOLARIS_NFSMOUNT::ASSOCIATORS",
593 				CIM_ERR_INVALID_PARAMETER, NULL, NULL, &err);
594 			return ((CCIMInstanceList *)NULL);
595 		}
596 
597 		/*
598 		 * Get the current host name and compare it to the name
599 		 * property of the passed in pObjectName.
600 		 */
601 		hostname = sys_get_hostname(&err);
602 		if (hostname == NULL) {
603 			util_handleError("SOLARIS_HOSTEDSHARE::ASSOCIATORS",
604 				CIM_ERR_FAILED, GET_HOSTNAME_FAILURE, NULL,
605 				&err);
606 			return ((CCIMInstanceList *)NULL);
607 		}
608 
609 		if ((strcmp(name, hostname) != 0)) {
610 			/*
611 			 * We can only determine shares on the current host.
612 			 * The providers are not distributed.
613 			 */
614 			util_handleError("SOLARIS_HOSTEDSHARE::ASSOCIATORS",
615 				CIM_ERR_INVALID_PARAMETER, NULL, NULL, &err);
616 			free(hostname);
617 			return ((CCIMInstanceList *)NULL);
618 		}
619 		free(hostname);
620 	} else if ((strcasecmp(pObjectName->mName, SOLARIS_NFSSHARE) == 0)) {
621 		CIMBool	shareExists;
622 
623 		resultClassName = COMPUTER_SYSTEM;
624 
625 		/*
626 		 * pObjectName is the Dependent (Solaris_NFSShare) so determine
627 		 * if the share actually exists by comparing the Name property
628 		 * of pObjectName, which is populated with the shared directory,
629 		 * to existing nfs shares on the system.
630 		 */
631 		shareExists = does_share_exist(name);
632 		if (shareExists == cim_false) {
633 			return ((CCIMInstanceList *)NULL);
634 		}
635 	} else {
636 		util_handleError("SOLARIS_HOSTEDSHARE::ASSOCIATORS",
637 			CIM_ERR_INVALID_PARAMETER, NULL, NULL, &err);
638 		return ((CCIMInstanceList *)NULL);
639 	}
640 
641 	resultOP = cim_createEmptyObjectPath(resultClassName);
642 	if (resultOP == NULL) {
643 		ex = cim_getLastError();
644 		util_handleError("SOLARIS_HOSTEDSHARE::ASSOCIATORS",
645 			CIM_ERR_FAILED, CREATE_EMPTY_OBJPATH_FAILURE,
646 			ex, &err);
647 		return ((CCIMInstanceList *)NULL);
648 	}
649 
650 	pDeep = cim_false;
651 	pLocalOnly = cim_false;
652 	pIncludeQualifiers = cim_false;
653 	pIncludeClassOrigin = cim_false;
654 	pUseInternal = cim_false;
655 	pPropertyList = NULL;
656 	pNumProps = 0;
657 	returnInstList = cimom_enumerateInstances(resultOP, pDeep,
658 		pLocalOnly, pIncludeQualifiers, pIncludeClassOrigin,
659 		pUseInternal, pPropertyList, pNumProps);
660 	/*
661 	 * A NULL return value indicates an error, an empty list
662 	 * doesn't.
663 	 */
664 	if (returnInstList == NULL) {
665 		ex = cim_getLastError();
666 		util_handleError("SOLARIS_HOSTEDSHARE::ASSOCIATORS",
667 			CIM_ERR_FAILED, CIMOM_ENUM_INST_FAILURE, ex,
668 			&err);
669 		cim_freeObjectPath(resultOP);
670 		return ((CCIMInstanceList *)NULL);
671 	}
672 
673 	cim_freeObjectPath(resultOP);
674 
675 	if (returnInstList->mDataObject == NULL) {
676 		return ((CCIMInstanceList *)NULL);
677 	}
678 
679 	return (returnInstList);
680 } /* cp_associators_Solaris_HostedShare */
681 
682 /*
683  * Method: cp_associatorNames_Solaris_HostedShare
684  *
685  * Description: Returns the object paths of the instances on the other side of
686  * the association which are associated via the Solaris_HostedShare association
687  * and having the passed in parameter, pObjectName, as the opposite key.
688  *
689  * Parameters:
690  *	- CCIMObjectPath *pAssocName - An object path containing information
691  *	about the association that the caller is trying to reach.
692  *	- CCIMObjectPath *pObjectName - The object path which contains the
693  *	information on whose associated objects are to be returned.
694  *	- char *pResultClass - If specified, only return instances that are of
695  *	this class type.
696  *	- char *pRole - If specified, this is the role of the pObjectName
697  *	object path passed in.  If this is not valid, NULL is returned.
698  *	- char *pResultRole - If specified, only return instances that are
699  *	playing this role in the association.
700  *
701  * Returns:
702  *	- A list of Solaris_NFSShare (if pRole == Antecedent && pObjectName is
703  *      a Solaris_ComputerSystem object path) or Solaris_ComputerSystem (if
704  *      pRole == Dependent && pObjectName is a Solaris_NFSShare object path)
705  *      object paths which are associated to the pObjectName parameter.
706  *      - NULL if an error occurred or if there are no instances associated to
707  *      the pObjectName passed in.  In the case of an error, the error will be
708  *      logged.
709  */
710 CCIMObjectPathList *
cp_associatorNames_Solaris_HostedShare(CCIMObjectPath * pAssocName,CCIMObjectPath * pObjectName,char * pResultClass,char * pRole,char * pResultRole)711 cp_associatorNames_Solaris_HostedShare(CCIMObjectPath *pAssocName,
712 	CCIMObjectPath *pObjectName, char *pResultClass, char *pRole,
713 	char *pResultRole) {
714 
715 	CCIMInstanceList	*instList;
716 	CCIMObjectPathList	*objPathList = NULL;
717 	int			err = 0;
718 
719 	if (pObjectName == NULL || pObjectName->mKeyProperties == NULL) {
720 		util_handleError("SOLARIS_HOSTEDSHARE::ASSOCIATOR_NAMES",
721 			CIM_ERR_INVALID_PARAMETER, NULL, NULL, &err);
722 		return ((CCIMObjectPathList *)NULL);
723 	}
724 
725 	instList = cp_associators_Solaris_HostedShare(pAssocName, pObjectName,
726 		pResultClass, pRole, pResultRole);
727 	if (instList == NULL) {
728 		return ((CCIMObjectPathList *)NULL);
729 	}
730 
731 	objPathList = cim_createObjectPathList(instList);
732 	cim_freeInstanceList(instList);
733 
734 	return (objPathList);
735 } /* cp_associatorNames_Solaris_HostedShare */
736 
737 /*
738  * Method: cp_references_Solaris_HostedShare
739  *
740  * Description: Returns the Solaris_HostedShare instances that have the passed
741  * in parameter, pObjectName, as one of it's keys.
742  *
743  * Parameters:
744  *	- CCIMObjectPath *pAssocName - An object path containing information
745  *      about the association that the caller is trying to reach.
746  *	- CCIMObjectPath *pObjectName - The object path which contains the
747  *	information on whose associated objects are to be returned.
748  *	- char *pRole - If specified, this is the role of the pObjectName
749  *	object path passed in.  If this is not valid, NULL is returned.
750  *
751  * Returns:
752  *	- A pointer to a list of Solaris_HostedShare instances.
753  *	- NULL if an error occurred or if there are no Solaris_HostedShare
754  *	instances having pObjectName as one of it's keys.
755  */
756 CCIMInstanceList *
cp_references_Solaris_HostedShare(CCIMObjectPath * pAssocName,CCIMObjectPath * pObjectName,char * pRole)757 cp_references_Solaris_HostedShare(CCIMObjectPath *pAssocName,
758 	CCIMObjectPath *pObjectName, char *pRole) {
759 
760 	CCIMInstanceList	*instList;
761 	CCIMObjectPathList	*objPathList;
762 	char			*pObjectNameRole;
763 	char			*objPathListRole;
764 	int			err = 0;
765 
766 	if (pObjectName == NULL || pObjectName->mKeyProperties == NULL) {
767 		util_handleError("SOLARIS_HOSTEDSHARE::REFERENCES",
768 			CIM_ERR_INVALID_PARAMETER, NULL, NULL, &err);
769 		return ((CCIMInstanceList *)NULL);
770 	}
771 
772 	/*
773 	 * Get everything that is related to the pObjectName passed in.
774 	 */
775 	objPathList = cp_associatorNames_Solaris_HostedShare(pAssocName,
776 		pObjectName, NULL, pRole, NULL);
777 	if (objPathList == NULL) {
778 		return ((CCIMInstanceList *)NULL);
779 	}
780 
781 	/*
782 	 * Now use the object paths in the object path list and the pObjectName
783 	 * variable to create the association instances.
784 	 */
785 	if ((strcasecmp(pObjectName->mName, SOLARIS_NFSSHARE) == 0)) {
786 		/*
787 		 * pObjectName is the Dependent.
788 		 */
789 		pObjectNameRole = DEPENDENT;
790 		objPathListRole = ANTECEDENT;
791 		instList = create_association_instList(SOLARIS_HOSTEDSHARE,
792 			pObjectName, pObjectNameRole, objPathList,
793 			objPathListRole, &err);
794 	} else {
795 		/*
796 		 * pObjectName is the Antecedent.
797 		 */
798 		pObjectNameRole = ANTECEDENT;
799 		objPathListRole = DEPENDENT;
800 		instList = create_association_instList(SOLARIS_HOSTEDSHARE,
801 			pObjectName, pObjectNameRole, objPathList,
802 			objPathListRole, &err);
803 	}
804 	cim_freeObjectPathList(objPathList);
805 
806 	return (instList);
807 } /* cp_references_Solaris_HostedShare */
808 
809 /*
810  * Method: cp_referenceNames_Solaris_HostedShare
811  *
812  * Description: Returns the Solaris_HostedShare object paths of the instances
813  * that have the passed in parameter, pObjectName, as one of it's keys.
814  *
815  * Parameters:
816  *	- CCIMObjectPath *pAssocName - An object path containing information
817  *	about the association that the caller is trying to reach.
818  *	- CCIMObjectPath *pObjectName - The object path which contains the
819  *	information on whose associated objects are to be returned.
820  *	- char *pRole - If specified, this is the role of the pObjectName
821  *	object path passed in.  If this is not valid, NULL is returned.
822  *
823  * Returns:
824  *	- A pointer to a list of Solaris_HostedShare object paths.
825  *	- NULL if an error occurred or if there are no Solaris_HostedShare
826  *	instances having pObjectName as one of it's keys.
827  */
828 CCIMObjectPathList *
cp_referenceNames_Solaris_HostedShare(CCIMObjectPath * pAssocName,CCIMObjectPath * pObjectName,char * pRole)829 cp_referenceNames_Solaris_HostedShare(CCIMObjectPath *pAssocName,
830 	CCIMObjectPath *pObjectName, char *pRole) {
831 
832 	CCIMInstanceList	*hostedShareInstList;
833 	CCIMObjectPathList	*hostedShareOPList;
834 	int			err = 0;
835 
836 	if (pObjectName == NULL || pObjectName->mKeyProperties == NULL) {
837 		util_handleError("SOLARIS_HOSTEDSHARE::REFERENCE_NAMES",
838 			CIM_ERR_INVALID_PARAMETER, NULL, NULL, &err);
839 		return ((CCIMObjectPathList *)NULL);
840 	}
841 
842 	hostedShareInstList = cp_references_Solaris_HostedShare(pAssocName,
843 		pObjectName, pRole);
844 
845 	if (hostedShareInstList == NULL) {
846 		return ((CCIMObjectPathList *)NULL);
847 	}
848 
849 	hostedShareOPList = cim_createObjectPathList(hostedShareInstList);
850 
851 	cim_freeInstanceList(hostedShareInstList);
852 	/*
853 	 * If an error occurred it will be handled in cim_createObjectPathList.
854 	 */
855 	return (hostedShareOPList);
856 } /* cp_referenceNames_Solaris_HostedShare */
857 
858 /*
859  * Property provider methods
860  */
861 
862 /*
863  * Method: cp_getProperty_Solaris_HostedShare
864  *
865  * Description: Retrieves a certain property from the instance of
866  * Solaris_HostedShare on the host that is described by the parameter
867  * hostedShareOP.
868  *
869  * Parameters:
870  *	- CCIMObjectPath *hostedShareOP - The object path containing all the
871  *	information needed to find the instance in which the property is to
872  *	be returned.
873  *	- cimchar *pPropName - The name of the property to be found.
874  *
875  * Returns:
876  *	- A pointer to the property corresponding to the name passed in with
877  *	pPropName.
878  *	- NULL if an error occurred or if the property doesn't exist.  In the
879  *	case of an error, the error will be logged.
880  */
881 CCIMProperty *
cp_getProperty_Solaris_HostedShare(CCIMObjectPath * hostedShareOP,cimchar * pPropName)882 cp_getProperty_Solaris_HostedShare(CCIMObjectPath *hostedShareOP,
883 	cimchar *pPropName) {
884 
885 	CCIMInstance	*hostedShareInst;
886 	CCIMProperty	*hostedShareProp;
887 	int		err = 0;
888 
889 	if (hostedShareOP == NULL) {
890 		util_handleError("SOLARIS_HOSTEDSHARE::GET_PROPERTY",
891 			CIM_ERR_INVALID_PARAMETER, NULL, NULL, &err);
892 		return ((CCIMProperty *)NULL);
893 	}
894 
895 	hostedShareInst = cp_getInstance_Solaris_HostedShare(hostedShareOP);
896 	if (hostedShareInst == NULL) {
897 		return ((CCIMProperty *)NULL);
898 	}
899 
900 	hostedShareProp = cim_getProperty(hostedShareInst, pPropName);
901 	cim_freeInstance(hostedShareInst);
902 
903 	return (hostedShareProp);
904 
905 } /* cp_getProperty_Solaris_HostedShare */
906 
907 /*
908  * Method: cp_setProperty_Solaris_HostedShare
909  *
910  * Description: This method is not supported.  It is not supported because in
911  * order to change the properties of a Solaris_HostedShare instance, the
912  * underlying classes being associated must be changed.  This provider isn't
913  * the appropriate place to be changing other things on the host.
914  *
915  * Parameters:
916  *      - CCIMObjectPath *hostedShareOP - Not used.
917  *      - CCIMProperty *pProp - Not used.
918  *
919  * Returns:
920  *	- Always returns cim_false because the method is not supported.
921  */
922 /* ARGSUSED */
923 CIMBool
cp_setProperty_Solaris_HostedShare(CCIMObjectPath * hostedShareOP,CCIMProperty * pProp)924 cp_setProperty_Solaris_HostedShare(CCIMObjectPath *hostedShareOP,
925 	CCIMProperty *pProp) {
926 
927 	int	err = 0;
928 
929 	util_handleError("SOLARIS_HOSTEDSHARE::SET_PROPERTY",
930 		CIM_ERR_NOT_SUPPORTED, NULL, NULL, &err);
931 
932 	return (cim_false);
933 } /* cp_setProperty_Solaris_HostedShare */
934 
935 /*
936  * Method provider methods
937  */
938 
939 /*
940  * Method: cp_invokeMethod_Solaris_HostedShare
941  *
942  * Description: This method is not supported because the provider doesn't have
943  * any methods.
944  *
945  * Parameters:
946  *	- CCIMObjectPath* op - Not used.
947  *	- cimchar* methodName - Not used.
948  *	- CCIMPropertyList* inParams - Not used.
949  *	- CCIMPropertyList* outParams - Not used.
950  *
951  * Returns:
952  *	- Always returns null because the method is not supported.
953  */
954 /* ARGSUSED */
955 CCIMProperty *
cp_invokeMethod_Solaris_HostedShare(CCIMObjectPath * op,cimchar * methodName,CCIMPropertyList * inParams,CCIMPropertyList * outParams)956 cp_invokeMethod_Solaris_HostedShare(CCIMObjectPath* op, cimchar* methodName,
957 	CCIMPropertyList* inParams, CCIMPropertyList* outParams) {
958 
959 	return ((CCIMProperty *)NULL);
960 } /* cp_invokeMethod_Solaris_HostedShare */
961 
962 /*
963  * Private methods
964  */
965 
966 /*
967  * Method: does_share_exist
968  *
969  * Description: Determines if a given share exists on the host.
970  *
971  * Parameters:
972  *	- char *dir - The name of the directory to see if it is shared.
973  *
974  * Returns:
975  *	- An integer corresponding to the existence of the share on the system.
976  *	1 is returned if the share exists, 0 is returned if the share does not
977  *	exist.
978  */
979 static CIMBool
does_share_exist(char * dir)980 does_share_exist(char *dir) {
981 	fs_sharelist_t	*share_list;
982 	fs_sharelist_t	*currentShare;
983 	CIMBool		return_val = cim_false;
984 	int		err = 0;
985 
986 	share_list = fs_get_share_list(&err);
987 	if (share_list == NULL) {
988 		/*
989 		 * Either there was an error or there are no shares on the
990 		 * system.  If there was an error err should be a non-zero
991 		 * value.
992 		 */
993 		if (err != 0) {
994 			util_handleError("SOLARIS_HOSTEDSHARE::SHARE_EXISTS",
995 				CIM_ERR_FAILED, FS_GET_SHARE_FAILURE, NULL,
996 				&err);
997 		}
998 
999 		return (return_val);
1000 	}
1001 
1002 	currentShare = share_list;
1003 	while (currentShare != NULL && return_val == cim_false) {
1004 		if ((strcmp(currentShare->path, dir) == 0)) {
1005 			return_val = cim_true;
1006 		}
1007 
1008 		currentShare = currentShare->next;
1009 	}
1010 
1011 	fs_free_share_list(share_list);
1012 	return (return_val);
1013 
1014 } /* does_share_exist */
1015 
1016 /*
1017  * Method: get_Antecedent
1018  *
1019  * Description: Retrieves a reference property of the host's
1020  * Solaris_ComputerSystem class.
1021  *
1022  * Parameters:
1023  *	- NONE
1024  * Returns:
1025  *	- A pointer to a property which is a reference property of the host's
1026  *	Solaris_ComputerSystem instance.
1027  *	- Upon error, NULL is returned and the error is logged.
1028  */
1029 static CCIMObjectPath *
get_Antecedent()1030 get_Antecedent() {
1031 	CCIMInstance	*compSysInst;
1032 	CCIMObjectPath	*compSysOP;
1033 	CCIMException	*ex;
1034 	char		*hostname;
1035 	int		err = 0;
1036 
1037 	compSysInst = cim_createInstance(COMPUTER_SYSTEM);
1038 	if (compSysInst == NULL) {
1039 		ex = cim_getLastError();
1040 		util_handleError("SOLARIS_HOSTEDSHARE::GET_ANT",
1041 			CIM_ERR_FAILED, CREATE_INSTANCE_FAILURE, ex, &err);
1042 		return ((CCIMObjectPath *)NULL);
1043 	}
1044 
1045 	/*
1046 	 * Create the key properties on the Solaris_ComputerSystem instance.
1047 	 *
1048 	 * The Solaris_ComputerSystem keys are as follows:
1049 	 * CreationClassName = "Solaris_ComputerSystem"
1050 	 * Name = < host name >
1051 	 */
1052 	if (add_property_to_instance(CREATION_CLASS, string, COMPUTER_SYSTEM,
1053 		NULL, cim_true, compSysInst) == cim_false) {
1054 
1055 		cim_freeInstance(compSysInst);
1056 		return ((CCIMObjectPath *)NULL);
1057 	}
1058 
1059 	hostname = sys_get_hostname(&err);
1060 	if (hostname == NULL) {
1061 		util_handleError("SOLARIS_HOSTEDSHARE::GET_ANT",
1062 			CIM_ERR_FAILED, GET_HOSTNAME_FAILURE, NULL, &err);
1063 		return ((CCIMObjectPath *)NULL);
1064 	}
1065 
1066 	if (add_property_to_instance(NAME, string, hostname, NULL,
1067 		cim_true, compSysInst) == cim_false) {
1068 
1069 		free(hostname);
1070 		cim_freeInstance(compSysInst);
1071 		return ((CCIMObjectPath *)NULL);
1072 	}
1073 	free(hostname);
1074 
1075 	compSysOP = cim_createObjectPath(compSysInst);
1076 	if (compSysOP == NULL) {
1077 		ex = cim_getLastError();
1078 		util_handleError("SOLARIS_HOSTEDSHARE::GET_ANT",
1079 			CIM_ERR_FAILED, CREATE_OBJECT_PATH_FAILURE,
1080 			ex, &err);
1081 		cim_freeInstance(compSysInst);
1082 		return ((CCIMObjectPath *)NULL);
1083 	}
1084 
1085 	return (compSysOP);
1086 } /* get_Antecedent */
1087