xref: /illumos-gate/usr/src/lib/libima/common/ima-lib.c (revision df9cdf10)
1 /*
2  * Description
3  * ImaLib.c - Implements a sample common IMA library
4  *
5  * License:
6  * The contents of this file are subject to the SNIA Public License
7  * Version 1.0(the "License"); you may not use this file except in
8  *  compliance with the License. You may obtain a copy of the License at
9  *
10  * /http://www.snia.org/English/Resources/Code/OpenSource.html
11  *
12  *  Software distributed under the License is distributed on an "AS IS"
13  *  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14  *  the License for the specific language governing rights and limitations
15  *  under the License.
16  *
17  * The Original Code is  SNIA HBA API and IMA general header file
18  *
19  * The Initial Developer of the Original Code is:
20  * Benjamin F. Kuo, Troika Networks, Inc. (benk@troikanetworks.com)
21  * David Dillard       VERITAS Software        david.dillard@veritas.com
22  *
23  * Contributor(s):
24  * Jeff Ding, Adaptec, Inc. (jding@corp.adaptec.com)
25  *
26  *   Changes:
27  *  09/24/2003 Initial Draft
28  *  (for other changes... see the CVS logs)
29  *
30  *  12/15/2003 corrected the defined parameter in IMA_SetPhbaIsnsDiscovery().
31  *  lower case the computer name as iscsi name in IMA_GenerateNodeName().
32  *
33  *  01/21/2005 Updated to support IMA 1.1.3.
34  */
35 
36 #ifdef WIN32
37 #include <windows.h>
38 #else
39 #include <sys/sem.h>
40 #include <dlfcn.h>
41 #include <stdarg.h>
42 #endif
43 
44 #include <string.h>
45 #include <strings.h>
46 #include <stdlib.h>
47 // #include <sys/sem.h>
48 #include <unistd.h>
49 #include <time.h>
50 #include <stdio.h>
51 #include <sys/types.h>
52 // #include <sys/ipc.h>
53 #include <netdb.h>
54 
55 #include "libsun_ima.h"
56 #include "ima.h"
57 #include "ima-plugin.h"
58 
59 
60 #define	LIBRARY_PROPERTY_SUPPORTED_IMA_VERSION 1
61 #define	LIBRARY_PROPERTY_IMPLEMENTATION_VERSION L"1.0.2"
62 #define	LIBRARY_PROPERTY_VENDOR L"QLogic, Inc."
63 #define	DEFAULT_NODE_NAME_FORMAT "iqn.1986-03.com.sun.central.%s"
64 
65 /* Linux only */
66 #define	LIBRARY_FILE_NAME L"libima.so"
67 
68 #define	EUOS_ERROR IMA_ERROR_UNEXPECTED_OS_ERROR
69 
70 IMA_PLUGIN_INFO  plugintable[IMA_MAX_NUM_PLUGINS];
71 int number_of_plugins = -1;
72 static IMA_NODE_NAME    sharedNodeName;
73 static IMA_NODE_ALIAS   sharedNodeAlias;
74 
75 #ifdef WIN32
76 static HANDLE libMutex = NULL;
77 #else
78 int libMutex = -1;
79 #endif
80 
81 void InitLibrary();
82 void ExitLibrary();
83 
libSwprintf(wchar_t * wcs,const wchar_t * lpszFormat,...)84 static void libSwprintf(wchar_t *wcs, const wchar_t *lpszFormat, ...) {
85 	va_list args;
86 	va_start(args, lpszFormat);
87 
88 #ifdef WIN32
89 	vswprintf(wcs, lpszFormat, args);
90 #else
91 	vswprintf(wcs, 255, lpszFormat, args);
92 #endif
93 	va_end(args);
94 }
95 
96 
97 #ifdef WIN32
98 /* Begin implementation */
DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)99 BOOL APIENTRY DllMain(HANDLE hModule,
100     DWORD  ul_reason_for_call,
101     LPVOID lpReserved) {
102 	switch (ul_reason_for_call) {
103 
104 	case DLL_PROCESS_ATTACH:
105 		// InitLibrary();
106 		break;
107 	case DLL_PROCESS_DETACH:
108 		ExitLibrary();
109 		break;
110 	case DLL_THREAD_ATTACH:
111 	case DLL_THREAD_DETACH:
112 		break;
113 	}
114 	return (TRUE);
115 }
116 #elif defined(SOLARIS)
117 
118 void so_init(void);
119 void so_fini(void);
120 static int os_createmutex(int *semid);
121 static void os_obtainmutex(int semid);
122 static void os_releasemutex(int semid);
123 static void os_destroymutex(int semid);
124 static IMA_STATUS getSolarisNodeProps(IMA_NODE_PROPERTIES *nodeProps);
125 static IMA_STATUS getSolarisSharedNodeName(IMA_NODE_NAME name);
126 static IMA_STATUS getSolarisSharedNodeAlias(IMA_NODE_ALIAS alias);
127 static IMA_STATUS setSolarisSharedNodeName(const IMA_NODE_NAME name);
128 static IMA_STATUS setSolarisSharedNodeAlias(const IMA_NODE_ALIAS alias);
129 
130 #pragma init(so_init)
131 #pragma fini(so_fini)
132 
so_init()133 void so_init() {
134 	InitLibrary();
135 }
so_fini()136 void so_fini() {
137 	ExitLibrary();
138 }
139 
getSolarisNodeProps(IMA_NODE_PROPERTIES * nodeProps)140 static IMA_STATUS getSolarisNodeProps(IMA_NODE_PROPERTIES *nodeProps) {
141 	int ret;
142 	int i;
143 	IMA_STATUS status = IMA_ERROR_UNKNOWN_ERROR;
144 	IMA_GetNodePropertiesFn PassFunc;
145 	IMA_OID nodeOid;
146 
147 	if (number_of_plugins == -1)
148 		InitLibrary();
149 
150 	os_obtainmutex(libMutex);
151 	status = IMA_ERROR_OBJECT_NOT_FOUND;
152 
153 	for (i = 0; i < number_of_plugins; i++) {
154 		if (strstr(plugintable[i].PluginPath,
155 		    "libsun_ima.so") == NULL) {
156 			continue;
157 		}
158 		status = IMA_ERROR_UNEXPECTED_OS_ERROR;
159 		if (plugintable[i].hPlugin != NULL) {
160 			os_obtainmutex(plugintable[i].pluginMutex);
161 			PassFunc =
162 			    (IMA_GetNodePropertiesFn) dlsym(
163 			    plugintable[i].hPlugin,
164 			    "IMA_GetNodeProperties");
165 			if (PassFunc != NULL) {
166 				status = PassFunc(nodeOid, nodeProps);
167 			}
168 			os_releasemutex(plugintable[i].pluginMutex);
169 		}
170 		break;
171 	}
172 
173 	os_releasemutex(libMutex);
174 	return (status);
175 }
176 
getSolarisSharedNodeName(IMA_NODE_NAME name)177 static IMA_STATUS getSolarisSharedNodeName(IMA_NODE_NAME name) {
178 	IMA_STATUS status = IMA_ERROR_UNKNOWN_ERROR;
179 	IMA_NODE_PROPERTIES nodeProps;
180 
181 	status = getSolarisNodeProps(&nodeProps);
182 	if (status != IMA_STATUS_SUCCESS) {
183 		return (status);
184 	}
185 	bcopy(&nodeProps.name, name, sizeof (IMA_NODE_NAME));
186 	return (status);
187 }
188 
getSolarisSharedNodeAlias(IMA_NODE_ALIAS alias)189 static IMA_STATUS getSolarisSharedNodeAlias(IMA_NODE_ALIAS alias) {
190 	IMA_STATUS status = IMA_ERROR_UNKNOWN_ERROR;
191 	IMA_NODE_PROPERTIES nodeProps;
192 
193 	status = getSolarisNodeProps(&nodeProps);
194 	if (status != IMA_STATUS_SUCCESS) {
195 		return (status);
196 	}
197 	bcopy(&nodeProps.alias, alias, sizeof (IMA_NODE_ALIAS));
198 	return (status);
199 }
200 
setSolarisSharedNodeName(const IMA_NODE_NAME name)201 static IMA_STATUS setSolarisSharedNodeName(const IMA_NODE_NAME name) {
202 	int ret;
203 	int i;
204 	IMA_STATUS status = IMA_ERROR_UNKNOWN_ERROR;
205 	IMA_NODE_PROPERTIES nodeProps;
206 	IMA_SetNodeNameFn PassFunc;
207 	IMA_OID nodeOid;
208 
209 	if (number_of_plugins == -1)
210 		InitLibrary();
211 
212 	os_obtainmutex(libMutex);
213 	status = IMA_ERROR_OBJECT_NOT_FOUND;
214 
215 	for (i = 0; i < number_of_plugins; i++) {
216 		if (strstr(plugintable[i].PluginPath,
217 		    "libsun_ima.so") == NULL) {
218 			continue;
219 		}
220 		status = IMA_ERROR_UNEXPECTED_OS_ERROR;
221 		if (plugintable[i].hPlugin != NULL) {
222 			os_obtainmutex(plugintable[i].pluginMutex);
223 			PassFunc =
224 			    (IMA_SetNodeNameFn) dlsym(plugintable[i].hPlugin,
225 			    "IMA_SetNodeName");
226 			if (PassFunc != NULL) {
227 				status = PassFunc(nodeOid, name);
228 			}
229 			os_releasemutex(plugintable[i].pluginMutex);
230 		}
231 		break;
232 	}
233 
234 	os_releasemutex(libMutex);
235 	return (status);
236 }
237 
setSolarisSharedNodeAlias(const IMA_NODE_ALIAS alias)238 static IMA_STATUS setSolarisSharedNodeAlias(const IMA_NODE_ALIAS alias) {
239 	int ret;
240 	int i;
241 	IMA_STATUS status = IMA_ERROR_UNKNOWN_ERROR;
242 	IMA_NODE_PROPERTIES nodeProps;
243 	IMA_SetNodeAliasFn PassFunc;
244 	IMA_OID nodeOid;
245 
246 	if (number_of_plugins == -1)
247 		InitLibrary();
248 
249 	os_obtainmutex(libMutex);
250 	status = IMA_ERROR_OBJECT_NOT_FOUND;
251 
252 	for (i = 0; i < number_of_plugins; i++) {
253 		if (strstr(plugintable[i].PluginPath,
254 		    "libsun_ima.so") == NULL) {
255 			continue;
256 		}
257 		status = IMA_ERROR_UNEXPECTED_OS_ERROR;
258 		if (plugintable[i].hPlugin != NULL) {
259 			os_obtainmutex(plugintable[i].pluginMutex);
260 			PassFunc =
261 			    (IMA_SetNodeAliasFn) dlsym(plugintable[i].hPlugin,
262 			    "IMA_SetNodeAlias");
263 			if (PassFunc != NULL) {
264 				status = PassFunc(nodeOid, alias);
265 			}
266 			os_releasemutex(plugintable[i].pluginMutex);
267 		}
268 		break;
269 	}
270 
271 	os_releasemutex(libMutex);
272 	return (status);
273 }
274 
275 #else
276 /*
277  * add code in .init and .fini,
278  * "__attribute__ ((constructor))" and "__attribute__ ((destructor))"
279  * are used with gcc
280  */
init()281 __attribute__((constructor)) void init()
282 {
283 	InitLibrary();
284 }
285 
fini()286 __attribute__((destructor)) void fini()
287 {
288 	ExitLibrary();
289 }
290 
291 #endif
292 
293 
294 #ifdef WIN32
295 
os_createmutex(HANDLE Mutex)296 static BOOL os_createmutex(HANDLE Mutex) {
297 	Mutex = CreateMutex(NULL, FALSE, NULL);
298 
299 	if (Mutex == NULL) {
300 		return (FALSE);
301 	}
302 
303 	return (TRUE);
304 }
305 
os_destroymutex(HANDLE Mutex)306 static void os_destroymutex(HANDLE Mutex) {
307 	if (Mutex != NULL) {
308 		CloseHandle(Mutex);
309 	}
310 }
311 
312 
os_obtainmutex(HANDLE Mutex)313 static void os_obtainmutex(HANDLE Mutex) {
314 	WaitForSingleObject(Mutex, INFINITE);
315 }
316 
os_releasemutex(HANDLE Mutex)317 static void os_releasemutex(HANDLE Mutex) {
318 	ReleaseMutex(Mutex);
319 }
320 
321 #else
322 #if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
323 /* <sys/sem.h> */
324 #else
325 union semun {
326 	int val; /* value for SETVAL */
327 	struct semid_ds *bf; /* buffer for IPC_STAT, IPC_SET */
328 	unsigned short int *array; /* array for GETALL, SETALL */
329 	struct seminfo *__buf; /* buffer for IPC_INFO */
330 };
331 #endif
332 
333 /* Create the semaphore.  Return 1 if successful, 0 otherwise */
os_createmutex(int * semid)334 static int os_createmutex(int *semid) {
335 	int retVal;
336 	union semun sem_union;
337 
338 	if (semid == NULL) {
339 		return (0);
340 	}
341 
342 	retVal = semget(IPC_PRIVATE, 1, IPC_CREAT);
343 	if (retVal == -1) {
344 		return (0);
345 	}
346 
347 	*semid = retVal; /* save key of created semaphore */
348 	sem_union.val = 1; /* start semaphore off signaled */
349 	retVal = semctl(*semid, 0, SETVAL, sem_union);
350 	if (retVal == -1) {
351 		return (0);
352 	}
353 
354 	return (1);
355 }
356 
357 static void
os_obtainmutex(int semid)358 os_obtainmutex(int semid)
359 {
360 	struct sembuf sem_b;
361 
362 	sem_b.sem_num = 0;
363 	sem_b.sem_op = -1;
364 	sem_b.sem_flg = SEM_UNDO;
365 	(void) semop(semid, &sem_b, 1);
366 }
367 
368 static void
os_releasemutex(int semid)369 os_releasemutex(int semid)
370 {
371 	struct sembuf sem_b;
372 
373 	sem_b.sem_num = 0;
374 	sem_b.sem_op = 1;
375 	sem_b.sem_flg = SEM_UNDO;
376 	(void) semop(semid, &sem_b, 1);
377 }
378 
379 /* Destroy the SNMP semaphore. */
380 static void
os_destroymutex(int semid)381 os_destroymutex(int semid)
382 {
383 	union semun sem_union;
384 
385 	(void) semctl(semid, 0, IPC_RMID, sem_union);
386 }
387 #endif
388 
389 
InitLibrary()390 void InitLibrary() {
391 
392 	FILE *imaconf;
393 	char fullline[512]; /* Full line read in from IMA.conf */
394 	char pluginname[64]; /* Read in from file IMA.conf */
395 	char pluginpath[256]; /* Read in from file IMA.conf */
396 	char imaConfFilePath[256];
397 	char systemPath[256];
398 	char *charPtr;
399 	IMA_UINT i = 0;
400 
401 	if (number_of_plugins != -1)
402 		return;
403 
404 	number_of_plugins = 0;
405 
406 	if (os_createmutex(&libMutex) == 0) {
407 		return;
408 	}
409 	os_obtainmutex(libMutex);
410 
411 	sharedNodeAlias[0] = 0;
412 
413 	/* Open configuration file from known location */
414 #ifdef WIN32
415 	if (GetSystemDirectory(systemPath, sizeof (systemPath)))
416 		sprintf(imaConfFilePath, "%s\\drivers\\etc\\ima.conf",
417 		    systemPath);
418 	else
419 		strcpy(imaConfFilePath, "ima.conf");
420 #else
421 	strcpy(imaConfFilePath, "/etc/ima.conf");
422 #endif
423 
424 	if ((imaconf = fopen(imaConfFilePath, "r")) == NULL) {
425 		os_releasemutex(libMutex);
426 		return;
427 	}
428 	/* Read in each line and load library */
429 	while ((imaconf != NULL) &&
430 	    (fgets(fullline, sizeof (fullline), imaconf))) {
431 		if ((fullline[0] != '#') && (fullline[0] != '\n')) {
432 			/* Take out the '\n' */
433 			if ((charPtr = (char *)strchr(fullline, '\n')) != NULL)
434 				*charPtr = '\0';
435 
436 			/* look for the first tab */
437 			if ((charPtr = (char *)strchr(fullline, '\t')) == NULL)
438 				charPtr = (char *)strchr(fullline, ' ');
439 
440 			/* Set Null termination for library name if found */
441 			if (charPtr != NULL) {
442 				*charPtr++ = '\0';
443 				/*
444 				 * Skip spaces and tabs until
445 				 * the next character found
446 				 */
447 				while ((*charPtr == ' ') || (*charPtr == '\t'))
448 					charPtr++;
449 			}
450 			else
451 				continue; /* May be invalid entry */
452 
453 			/* Copy library name and path */
454 			strcpy(pluginname, fullline);
455 			strcpy(pluginpath, charPtr);
456 
457 			/*
458 			 * Continue to the next line if library name or
459 			 * path is invalid
460 			 */
461 			if ((strlen(pluginname) == 0) ||
462 			    (strlen(pluginpath) == 0))
463 				continue;
464 
465 #ifdef WIN32
466 			/* Load the DLL now */
467 			plugintable[i].hPlugin = LoadLibrary(pluginpath);
468 #else
469 			/* Load the DLL now */
470 			plugintable[i].hPlugin = dlopen(pluginpath, RTLD_LAZY);
471 #endif
472 			if (plugintable[i].hPlugin != NULL) {
473 				typedef int (*InitializeFn)();
474 				InitializeFn PassFunc;
475 
476 				memcpy((char *)&plugintable[i].PluginName,
477 				    (char *)&pluginname, 64);
478 				memcpy((char *)
479 				    &plugintable[i].PluginPath,
480 				    (char *)&pluginpath, 256);
481 				plugintable[i].ownerId = i + 1;
482 
483 #ifdef WIN32
484 				PassFunc = (InitializeFn)
485 				    GetProcAddress(
486 				    plugintable[i].hPlugin, "Initialize");
487 #else
488 				PassFunc = (InitializeFn)
489 				    dlsym(
490 				    plugintable[i].hPlugin, "Initialize");
491 #endif
492 				if (PassFunc != NULL) {
493 					(void) PassFunc(plugintable[i].ownerId);
494 				}
495 
496 				plugintable[i].number_of_vbcallbacks = 0;
497 				plugintable[i].number_of_pccallbacks = 0;
498 				os_createmutex(&(plugintable[i].pluginMutex));
499 				i++;
500 			}
501 		}
502 	}
503 	number_of_plugins = i;
504 	os_releasemutex(libMutex);
505 }
506 
507 
ExitLibrary()508 void ExitLibrary() {
509 	IMA_UINT j;
510 	IMA_UINT i;
511 
512 	if (number_of_plugins == -1)
513 		return;
514 
515 	os_obtainmutex(libMutex);
516 	for (i = 0; i < number_of_plugins; i++) {
517 		if (plugintable[i].hPlugin != NULL) {
518 			TerminateFn ExitPassFunc;
519 
520 			os_obtainmutex(plugintable[i].pluginMutex);
521 			for (j = 0; j < plugintable[i].number_of_vbcallbacks;
522 			    j++) {
523 #define	IMA_DFOBC_STR "IMA_DeregisterForObjectVisibilityChangesFn"
524 				IMA_DeregisterForObjectVisibilityChangesFn
525 				    PassFunc;
526 #ifdef WIN32
527 				PassFunc =
528 				    (IMA_DeregisterForObjectVisibilityChangesFn)
529 				    GetProcAddress(plugintable[i].hPlugin,
530 				    IMA_DFOBC_STR);
531 #else
532 				PassFunc =
533 				    (IMA_DeregisterForObjectVisibilityChangesFn)
534 				    dlsym(plugintable[i].hPlugin,
535 				    IMA_DFOBC_STR);
536 #endif
537 				if (PassFunc != NULL) {
538 					PassFunc(plugintable[i].vbcallback[j]);
539 				}
540 #undef IMA_DFOBC_STR
541 			}
542 			plugintable[i].number_of_vbcallbacks = 0;
543 
544 			for (j = 0; j < plugintable[i].number_of_pccallbacks;
545 			    j++) {
546 				IMA_DeregisterForObjectPropertyChangesFn
547 				    PassFunc;
548 #ifdef WIN32
549 				PassFunc =
550 				    (IMA_DeregisterForObjectPropertyChangesFn)
551 				    GetProcAddress(plugintable[i].hPlugin,
552 				    "IMA_DeregisterForObjectPropertyChangesFn");
553 #else
554 				PassFunc =
555 				    (IMA_DeregisterForObjectPropertyChangesFn)
556 				    dlsym(plugintable[i].hPlugin,
557 				    "IMA_DeregisterForObjectPropertyChangesFn");
558 #endif
559 				if (PassFunc != NULL) {
560 					PassFunc(plugintable[i].pccallback[j]);
561 				}
562 			}
563 			plugintable[i].number_of_pccallbacks = 0;
564 
565 #ifdef WIN32
566 			ExitPassFunc =
567 			    (TerminateFn) GetProcAddress
568 			    (plugintable[i].hPlugin, "Terminate");
569 #else
570 			ExitPassFunc = (TerminateFn)
571 			    dlsym(plugintable[i].hPlugin, "Terminate");
572 #endif
573 			if (ExitPassFunc != NULL) {
574 				ExitPassFunc();
575 			}
576 #ifdef WIN32
577 			/* Unload DLL from memory */
578 			FreeLibrary(plugintable[i].hPlugin);
579 #else
580 			/* Unload DLL from memory */
581 			dlclose(plugintable[i].hPlugin);
582 #endif
583 			os_releasemutex(plugintable[i].pluginMutex);
584 			os_destroymutex(plugintable[i].pluginMutex);
585 		}
586 	}
587 	number_of_plugins = -1;
588 	os_releasemutex(libMutex);
589 	os_destroymutex(libMutex);
590 }
591 
592 
VisibilityCallback(IMA_BOOL becomingVisible,IMA_OID objectId)593 static void VisibilityCallback(
594     IMA_BOOL becomingVisible,
595     IMA_OID objectId) {
596 	IMA_UINT i, j;
597 	os_obtainmutex(libMutex);
598 	for (i = 0; i < number_of_plugins; i++) {
599 		if ((plugintable[i].hPlugin != NULL) &&
600 		    (objectId.ownerId == plugintable[i].ownerId)) {
601 			os_obtainmutex(plugintable[i].pluginMutex);
602 			for (j = 0;
603 			    j < plugintable[i].number_of_vbcallbacks;
604 			    j++) {
605 				(plugintable[i].vbcallback[j])
606 				    (becomingVisible, objectId);
607 			}
608 			os_releasemutex(plugintable[i].pluginMutex);
609 		}
610 	}
611 	os_releasemutex(libMutex);
612 
613 }
614 
PropertyCallback(IMA_OID objectId)615 static void PropertyCallback(
616     IMA_OID objectId) {
617 	IMA_UINT i, j;
618 
619 	os_obtainmutex(libMutex);
620 	for (i = 0; i < number_of_plugins; i++) {
621 		if ((plugintable[i].hPlugin != NULL) &&
622 		    (objectId.ownerId == plugintable[i].ownerId)) {
623 			os_obtainmutex(plugintable[i].pluginMutex);
624 			for (j = 0;
625 			    j < plugintable[i].number_of_pccallbacks;
626 			    j++) {
627 				(plugintable[i].pccallback[j])(objectId);
628 			}
629 			os_releasemutex(plugintable[i].pluginMutex);
630 		}
631 	}
632 	os_releasemutex(libMutex);
633 }
634 
635 /*
636  * Gets the date and time, in the form of an IMA_DATETIME, from the build
637  * script when compiled.
638  */
GetBuildTime(IMA_DATETIME * pdatetime)639 static void GetBuildTime(IMA_DATETIME* pdatetime) {
640 
641 #ifdef WIN32
642 	char *dayToken[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
643 	char *monthToken[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
644 	    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
645 	char monthString[4];
646 	char dayString[4];
647 	int  i;
648 
649 	sscanf(__TIME__, "%u:%u:%u", &pdatetime->tm_hour,
650 	    &pdatetime->tm_min, &pdatetime->tm_sec);
651 	sscanf(__DATE__, "%s %u %u", monthString,
652 	    &pdatetime->tm_mday, &pdatetime->tm_year);
653 	sscanf(__TIMESTAMP__, "%s", dayString);
654 
655 	pdatetime->tm_year -= 1900;
656 	pdatetime->tm_isdst = -1;
657 
658 	pdatetime->tm_wday = 0;
659 	for (i = 0;  i < 7;  i++) {
660 		if (strcmp(dayToken[i], dayString) == 0) {
661 			pdatetime->tm_wday = i;
662 			break;
663 		}
664 	}
665 
666 	pdatetime->tm_mon = 0;
667 	for (i = 0; i < 12; i++) {
668 		if (strcmp(monthToken[i], monthString) == 0) {
669 			pdatetime->tm_mon = i;
670 			break;
671 		}
672 	}
673 
674 #else
675 #if defined(BUILD_DATE)
676 	if (strptime(BUILD_DATE, "%Y/%m/%d %T %Z", pdatetime) == NULL) {
677 		memset(pdatetime, 0, sizeof (IMA_DATETIME));
678 	}
679 #else
680 	memset(pdatetime, 0, sizeof (IMA_DATETIME));
681 #endif
682 #endif
683 
684 }
685 
686 
687 
688 /*
689  * Gets the properties of the IMA library that is being used.
690  *
691  * @param pProps A pointer to an @ref IMA_LIBRARY_PROPERTIES structure
692  *    allocated by the caller.  On successful return this structure will
693  *    contain the properties of the IMA library.
694  * @return An IMA_STATUS indicating if the operation was successful or if
695  *     an error occurred.
696  * @retval IMA_SUCCESS Returned if the library properties were successfully
697  *    returned.
698  * @retval IMA_ERROR_INVALID_PARAMETER Returned if @a pProps is NULL or
699  *    specifies a memory area to which data cannot be written.
700  */
IMA_GetLibraryProperties(IMA_LIBRARY_PROPERTIES * pProps)701 IMA_API IMA_STATUS IMA_GetLibraryProperties(
702     IMA_LIBRARY_PROPERTIES *pProps) {
703 
704 	char imaPath[256];
705 #ifdef WIN32
706 	HMODULE imaHandle;
707 #endif
708 
709 	if (number_of_plugins == -1)
710 		InitLibrary();
711 
712 	if (pProps == NULL)
713 		return (IMA_ERROR_INVALID_PARAMETER);
714 
715 	// Fill in the library properties.
716 	GetBuildTime(&pProps->buildTime);
717 	pProps->supportedImaVersion = LIBRARY_PROPERTY_SUPPORTED_IMA_VERSION;
718 	libSwprintf(pProps->implementationVersion, L"%ls",
719 	    LIBRARY_PROPERTY_IMPLEMENTATION_VERSION);
720 	libSwprintf(pProps->vendor, L"%ls", LIBRARY_PROPERTY_VENDOR);
721 
722 
723 #ifdef WIN32
724 	imaHandle = GetModuleHandleA("ima");
725 	imaPath[0] = 0;
726 	if (imaHandle != NULL) {
727 		GetModuleFileNameA(imaHandle, imaPath, 256);
728 	}
729 	MultiByteToWideChar(CP_ACP, 0, imaPath, -1,
730 	pProps->fileName, 256);
731 #else
732 	libSwprintf(pProps->fileName, LIBRARY_FILE_NAME);
733 
734 	//  mbstowcs(pProps->fileName, imaPath, 256);
735 #endif
736 
737 	return (IMA_STATUS_SUCCESS);
738 }
739 
740 
741 /*
742  * Gets a list of the object IDs of all currently loaded plugins.
743  *
744  * @param ppList A pointer to a pointer to an @ref IMA_OID_LIST.
745  *    On successful return this will contain a pointer to an @ref
746  *    IMA_OID_LIST which contains the object IDs of all of the plugins
747  *    currently loaded by the library.
748  * @return An IMA_STATUS indicating if the operation was successful
749  *    or if an error occurred.
750  * @retval IMA_SUCCESS Returned if the plugin ID list was successfully
751  *    returned.
752  * @retval IMA_ERROR_INVALID_PARAMETER Returned if @a ppList is NULL or
753  *    specifies a memory area to which data cannot be written.
754  */
IMA_GetPluginOidList(IMA_OID_LIST ** ppList)755 IMA_API IMA_STATUS IMA_GetPluginOidList(
756     IMA_OID_LIST **ppList) {
757 	IMA_UINT i;
758 
759 
760 	if (number_of_plugins == -1)
761 		InitLibrary();
762 
763 	if (ppList == NULL)
764 		return (IMA_ERROR_INVALID_PARAMETER);
765 
766 	os_obtainmutex(libMutex);
767 
768 	*ppList = (IMA_OID_LIST*)calloc(1, sizeof (IMA_OID_LIST) +
769 	    (number_of_plugins - 1) * sizeof (IMA_OID));
770 
771 	if ((*ppList) == NULL)
772 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
773 
774 	(*ppList)->oidCount = number_of_plugins;
775 
776 	for (i = 0; i < number_of_plugins; i++) {
777 
778 		(*ppList)->oids[i].objectType = IMA_OBJECT_TYPE_PLUGIN;
779 		(*ppList)->oids[i].ownerId = plugintable[i].ownerId;
780 		(*ppList)->oids[i].objectSequenceNumber = 0;
781 
782 	}
783 	os_releasemutex(libMutex);
784 	return (IMA_STATUS_SUCCESS);
785 }
786 
787 
788 
789 
790 /*
791  * Gets the properties of the specified vendor plugin.
792  *
793  * @param pluginId The ID of the plugin whose properties are being retrieved.
794  * @param pProps A pointer to an @ref IMA_PLUGIN_PROPERTIES structure
795  *    allocated by the caller.  On successful return this will contain the
796  *    properties of the plugin specified by pluginId.
797  * @return An IMA_STATUS indicating if the operation was successful or if
798  *    an error occurred.
799  * @retval IMA_SUCCESS Returned if the plugin properties were successfully
800  *    returned.
801  * @retval IMA_ERROR_INVALID_OBJECT_TYPE Returned if @a pluginId does not
802  *    specify any valid object type.
803  * @retval IMA_ERROR_INCORRECT_OBJECT_TYPE Returned if @a pluginId does not
804  *    specify a plugin object.
805  * @retval IMA_ERROR_OBJECT_NOT_FOUND Returned if @a pluginId refers to a
806  *     plugin, but not one that is currently loaded.
807  * @retval IMA_ERROR_INVALID_PARAMETER Returned if @a pProps is NULL or
808  *    specify a memory area to which data cannot be written.
809  */
IMA_GetPluginProperties(IMA_OID pluginOid,IMA_PLUGIN_PROPERTIES * pProps)810 IMA_API IMA_STATUS IMA_GetPluginProperties(
811     IMA_OID pluginOid,
812     IMA_PLUGIN_PROPERTIES *pProps) {
813 	IMA_GetPluginPropertiesFn PassFunc;
814 	IMA_UINT i;
815 	IMA_STATUS status;
816 
817 	if (number_of_plugins == -1)
818 		InitLibrary();
819 
820 	if (pProps == NULL)
821 		return (IMA_ERROR_INVALID_PARAMETER);
822 
823 	if ((pluginOid.objectType != IMA_OBJECT_TYPE_PLUGIN) ||
824 	    (pluginOid.objectSequenceNumber != 0))
825 		return (IMA_ERROR_INVALID_PARAMETER);
826 
827 	os_obtainmutex(libMutex);
828 	status = IMA_ERROR_OBJECT_NOT_FOUND;
829 
830 	for (i = 0; i < number_of_plugins; i++) {
831 		if (plugintable[i].ownerId == pluginOid.ownerId) {
832 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
833 			if (plugintable[i].hPlugin != NULL) {
834 				os_obtainmutex(plugintable[i].pluginMutex);
835 #ifdef WIN32
836 				PassFunc = (IMA_GetPluginPropertiesFn)
837 				    GetProcAddress(plugintable[i].hPlugin,
838 				    "IMA_GetPluginProperties");
839 #else
840 				PassFunc = (IMA_GetPluginPropertiesFn)
841 				    dlsym(plugintable[i].hPlugin,
842 				    "IMA_GetPluginProperties");
843 #endif
844 				if (PassFunc != NULL) {
845 					status = PassFunc(pluginOid, pProps);
846 				}
847 				os_releasemutex(plugintable[i].pluginMutex);
848 			}
849 
850 			break;
851 		}
852 	}
853 	os_releasemutex(libMutex);
854 	return (status);
855 
856 }
857 
858 
859 
860 
861 /*
862  * Gets the object ID for the plugin associated with the specified object ID.
863  *
864  * @param objectId The object ID of an object that has been received from
865  *    a previous library call.
866  * @param pPluginId A pointer to an @ref IMA_OID structure allocated by the
867  *    caller.  On successful return this will contain the object ID of the
868  *    plugin associated with the object specified by @a objectId.  This
869  *    can then be used to work with the plugin, e.g., to get the
870  *    properties of the plugin or the send the plugin an IOCtl.
871  * @return An IMA_STATUS indicating if the operation was successful or if
872  *    an error occurred.
873  * @retval IMA_SUCCESS Returned if the associated plugin ID was
874  *    successfully returned.
875  * @retval IMA_ERROR_INVALID_PARAMETER Returned if @a pPluginId is NULL
876  *    or specifes a memory area to which data cannot be written.
877  * @retval IMA_ERROR_INVALID_PARAMETER Returned if @a objectId specifies
878  *    an object not owned by a plugin, but instead one that is owned by
879  *    the library.
880  * @retval IMA_ERROR_INVALID_OBJECT_TYPE Returned if @a objectId specifies
881  *    an object with an invalid type.
882  */
IMA_GetAssociatedPluginOid(IMA_OID objectId,IMA_OID * pPluginId)883 IMA_API IMA_STATUS IMA_GetAssociatedPluginOid(
884     IMA_OID objectId,
885     IMA_OID *pPluginId) {
886 	IMA_UINT i;
887 	IMA_STATUS status;
888 
889 
890 	if (number_of_plugins == -1)
891 		InitLibrary();
892 
893 	if (pPluginId == NULL || objectId.ownerId == RL_LIBRARY_SEQNUM)
894 		return (IMA_ERROR_INVALID_PARAMETER);
895 
896 	if (objectId.objectType != IMA_OBJECT_TYPE_UNKNOWN &&
897 	    objectId.objectType != IMA_OBJECT_TYPE_PLUGIN &&
898 	    objectId.objectType != IMA_OBJECT_TYPE_NODE &&
899 	    objectId.objectType != IMA_OBJECT_TYPE_LHBA &&
900 	    objectId.objectType != IMA_OBJECT_TYPE_PHBA &&
901 	    objectId.objectType != IMA_OBJECT_TYPE_NETWORK_PORTAL &&
902 	    objectId.objectType != IMA_OBJECT_TYPE_PORTAL_GROUP &&
903 	    objectId.objectType != IMA_OBJECT_TYPE_LNP &&
904 	    objectId.objectType != IMA_OBJECT_TYPE_PNP &&
905 	    objectId.objectType != IMA_OBJECT_TYPE_TARGET &&
906 	    objectId.objectType != IMA_OBJECT_TYPE_LU &&
907 	    objectId.objectType != IMA_OBJECT_TYPE_DISCOVERY_ADDRESS &&
908 	    objectId.objectType != IMA_OBJECT_TYPE_STATIC_DISCOVERY_TARGET)
909 		return (IMA_ERROR_INVALID_OBJECT_TYPE);
910 
911 	os_obtainmutex(libMutex);
912 
913 	status = IMA_ERROR_OBJECT_NOT_FOUND;
914 	for (i = 0; i < number_of_plugins; i++) {
915 		if (objectId.ownerId == plugintable[i].ownerId) {
916 			pPluginId->objectType = IMA_OBJECT_TYPE_PLUGIN;
917 			pPluginId->ownerId = plugintable[i].ownerId;
918 			pPluginId->objectSequenceNumber = 0;
919 			status = IMA_STATUS_SUCCESS;
920 		}
921 
922 	}
923 	os_releasemutex(libMutex);
924 	return (status);
925 }
926 
927 
928 
929 
930 /*
931  * Gets the object ID of the shared node.
932  *
933  * @param pSharedNodeId A pointer to an @ref IMA_OID structure allocated by
934  *    the caller.  On successful return it will contain the object ID of the
935  *    shared node of the currently executing system is placed.
936  * @return An IMA_STATUS indicating if the operation was successful or if
937  *    an error occurred.
938  * @retval IMA_SUCCESS Returned if the shared node ID has been successfully
939  *    retrieved.
940  * @retval IMA_ERROR_INVALID_PARAMETER Returned if @a pSharedNodeId is NULL
941  *    or specifies a memory area to which data cannot be written.
942  */
IMA_GetSharedNodeOid(IMA_OID * pSharedNodeId)943 IMA_API IMA_STATUS IMA_GetSharedNodeOid(
944     IMA_OID *pSharedNodeId) {
945 	if (pSharedNodeId == NULL)
946 		return (IMA_ERROR_INVALID_PARAMETER);
947 
948 	pSharedNodeId->objectType = IMA_OBJECT_TYPE_NODE;
949 	pSharedNodeId->ownerId = RL_LIBRARY_SEQNUM;
950 	pSharedNodeId->objectSequenceNumber = RL_SHARED_NODE_SEQNUM;
951 	return (IMA_STATUS_SUCCESS);
952 }
953 
954 
IMA_GetObjectType(IMA_OID oid,IMA_OBJECT_TYPE * pObjectType)955 IMA_API IMA_STATUS IMA_GetObjectType(
956     IMA_OID oid,
957     IMA_OBJECT_TYPE *pObjectType) {
958 	IMA_STATUS status;
959 	IMA_UINT i;
960 
961 	if (pObjectType == NULL)
962 		return (IMA_ERROR_INVALID_PARAMETER);
963 
964 	if (oid.objectType != IMA_OBJECT_TYPE_UNKNOWN &&
965 	    oid.objectType != IMA_OBJECT_TYPE_PLUGIN &&
966 	    oid.objectType != IMA_OBJECT_TYPE_NODE &&
967 	    oid.objectType != IMA_OBJECT_TYPE_LHBA &&
968 	    oid.objectType != IMA_OBJECT_TYPE_PHBA &&
969 	    oid.objectType != IMA_OBJECT_TYPE_NETWORK_PORTAL &&
970 	    oid.objectType != IMA_OBJECT_TYPE_PORTAL_GROUP &&
971 	    oid.objectType != IMA_OBJECT_TYPE_LNP &&
972 	    oid.objectType != IMA_OBJECT_TYPE_PNP &&
973 	    oid.objectType != IMA_OBJECT_TYPE_TARGET &&
974 	    oid.objectType != IMA_OBJECT_TYPE_LU &&
975 	    oid.objectType != IMA_OBJECT_TYPE_DISCOVERY_ADDRESS &&
976 	    oid.objectType != IMA_OBJECT_TYPE_STATIC_DISCOVERY_TARGET)
977 		return (IMA_ERROR_INVALID_OBJECT_TYPE);
978 
979 	os_obtainmutex(libMutex);
980 	status = IMA_ERROR_OBJECT_NOT_FOUND;
981 
982 	for (i = 0; i < number_of_plugins; i++) {
983 		if (plugintable[i].ownerId == oid.ownerId) {
984 			*pObjectType = oid.objectType;
985 			status = IMA_STATUS_SUCCESS;
986 		}
987 	}
988 	os_releasemutex(libMutex);
989 	return (status);
990 }
991 
992 
993 
994 /*
995  * Gets the properties of the specified iSCSI node.
996  * @param nodeId The ID of the node to get the properties of.
997  * @param pProps A pointer to an @ref IMA_NODE_PROPERTIES structure
998  *    which on successfully return
999  *    will contain the properties of the specified node.
1000  * @return An IMA_STATUS indicating if the operation was successful or
1001  *    if an error occurred.
1002  * @retval IMA_SUCCESS Returned if the node properties have been
1003  *    successfully retrieved.
1004  * @retval IMA_ERROR_INVALID_PARAMETER Returned if @a pProps is NULL
1005  *    or specifies a memory area to which data cannot be written.
1006  * @retval IMA_ERROR_INVALID_OBJECT_TYPE Returned if @a nodeId does
1007  *     not specify any valid object type.
1008  * @retval IMA_ERROR_INCORRECT_OBJECT_TYPE Returned if @a nodeId does
1009  *    not specify a node object.
1010  * @retval IMA_ERROR_OBJECT_NOT_FOUND Returned if @a nodeId does not
1011  *    specify a node which is currently known to the system.
1012  */
IMA_GetNodeProperties(IMA_OID nodeOid,IMA_NODE_PROPERTIES * pProps)1013 IMA_API IMA_STATUS IMA_GetNodeProperties(
1014     IMA_OID nodeOid,
1015     IMA_NODE_PROPERTIES *pProps) {
1016 	IMA_GetNodePropertiesFn PassFunc;
1017 	IMA_UINT i;
1018 	IMA_STATUS status;
1019 	char fullline[512]; /* Full line read in from IMA.conf */
1020 	char nodename[MAXHOSTNAMELEN];
1021 
1022 #if defined(_WINDOWS)
1023 	IMA_UINT dwStrLength;
1024 #endif
1025 
1026 	if (number_of_plugins == -1)
1027 		InitLibrary();
1028 
1029 	if (pProps == NULL)
1030 		return (IMA_ERROR_INVALID_PARAMETER);
1031 
1032 	if (nodeOid.objectType != IMA_OBJECT_TYPE_NODE)
1033 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
1034 
1035 	if ((nodeOid.ownerId == RL_LIBRARY_SEQNUM) &&
1036 	    (nodeOid.objectSequenceNumber == RL_SHARED_NODE_SEQNUM)) {
1037 		pProps->runningInInitiatorMode = IMA_TRUE;
1038 		pProps->runningInTargetMode = IMA_TRUE;
1039 		pProps->nameAndAliasSettable = IMA_TRUE;
1040 
1041 		if (sharedNodeName[0] == 0) {
1042 #if defined(_WINDOWS)
1043 			GetComputerName((char *)fullline,
1044 			    (LPDWORD)&dwStrLength);
1045 			sprintf(nodename, DEFAULT_NODE_NAME_FORMAT, fullline);
1046 			MultiByteToWideChar(CP_ACP, 0, nodename, -1,
1047 			    sharedNodeName, 256);
1048 #elif defined(SOLARIS)
1049 
1050 			if (getSolarisSharedNodeName(sharedNodeName) !=
1051 			    IMA_STATUS_SUCCESS) {
1052 				gethostname((char *)fullline,
1053 				    sizeof (fullline));
1054 				sprintf(nodename,
1055 				    DEFAULT_NODE_NAME_FORMAT, fullline);
1056 				mbstowcs(sharedNodeName, nodename, 256);
1057 			}
1058 #else
1059 			gethostname((char *)fullline, sizeof (fullline));
1060 			sprintf(nodename, DEFAULT_NODE_NAME_FORMAT, fullline);
1061 			mbstowcs(sharedNodeName, nodename, 256);
1062 #endif
1063 		}
1064 
1065 		if (sharedNodeName[0] != 0) {
1066 			libSwprintf(pProps->name, L"%ls", sharedNodeName);
1067 			pProps->nameValid = IMA_TRUE;
1068 		}
1069 		else
1070 			pProps->nameValid = IMA_FALSE;
1071 
1072 #if defined(SOLARIS)
1073 		if (sharedNodeAlias[0] == 0) {
1074 			getSolarisSharedNodeAlias(sharedNodeAlias);
1075 		}
1076 #endif
1077 
1078 		if (sharedNodeAlias[0] != 0) {
1079 			libSwprintf(pProps->alias, L"%ls", sharedNodeAlias);
1080 			pProps->aliasValid = IMA_TRUE;
1081 		}
1082 		else
1083 			pProps->aliasValid = IMA_FALSE;
1084 
1085 		return (IMA_STATUS_SUCCESS);
1086 	}
1087 
1088 	os_obtainmutex(libMutex);
1089 	status = IMA_ERROR_OBJECT_NOT_FOUND;
1090 
1091 	for (i = 0; i < number_of_plugins; i++) {
1092 		if (plugintable[i].ownerId == nodeOid.ownerId) {
1093 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
1094 			if (plugintable[i].hPlugin != NULL) {
1095 				os_obtainmutex(plugintable[i].pluginMutex);
1096 #ifdef WIN32
1097 				PassFunc = (IMA_GetNodePropertiesFn)
1098 				    GetProcAddress(plugintable[i].hPlugin,
1099 				    "IMA_GetNodeProperties");
1100 #else
1101 				PassFunc = (IMA_GetNodePropertiesFn)
1102 				    dlsym(plugintable[i].hPlugin,
1103 				    "IMA_GetNodeProperties");
1104 #endif
1105 
1106 				if (PassFunc != NULL) {
1107 					status = PassFunc(nodeOid, pProps);
1108 				}
1109 				os_releasemutex(plugintable[i].pluginMutex);
1110 			}
1111 
1112 			break;
1113 		}
1114 	}
1115 	os_releasemutex(libMutex);
1116 	return (status);
1117 
1118 }
1119 
1120 
1121 
1122 
1123 /*
1124  * Sets the name of the specified node.
1125  *
1126  * @param nodeId The object ID of the node whose name is being set.
1127  * @param newName The new name of the node.
1128  * @return An IMA_STATUS indicating if the operation was successful or if
1129  *    an error occurred.
1130  * @retval IMA_SUCCESS Returned if the node name was successfully changed.
1131  * @retval IMA_STATUS_REBOOT_NECESSARY Returned if a reboot is necessary
1132  *    before the setting of the name actually takes affect.
1133  * @retval IMA_ERROR_INVALID_PARAMETER Returned if @a newname is NULL, or
1134  *    specifies a memory area to which data cannot be written, or has a
1135  *    length of 0.
1136  * @retval IMA_ERROR_INVALID_OBJECT_TYPE Returned if @a nodeId does not
1137  *    specify any valid object type.
1138  * @retval IMA_ERROR_INCORRECT_OBJECT_TYPE Returned if @a nodeId does not
1139  *    specify a node object.
1140  * @retval IMA_ERROR_OBJECT_NOT_FOUND Returned if @a nodeId does not specify a
1141  *    node which is currently known to the system.
1142  * @retval IMA_ERROR_NAME_TOO_LONG Returned if @a newName contains too many
1143  *    characters.
1144  */
IMA_SetNodeName(IMA_OID nodeOid,const IMA_NODE_NAME newName)1145 IMA_API IMA_STATUS IMA_SetNodeName(
1146     IMA_OID nodeOid,
1147     const IMA_NODE_NAME newName) {
1148 	IMA_SetNodeNameFn PassFunc;
1149 	IMA_UINT i;
1150 	IMA_STATUS status;
1151 
1152 	if (number_of_plugins == -1)
1153 		InitLibrary();
1154 
1155 	if (newName == NULL || wcslen(newName) == 0)
1156 		return (IMA_ERROR_INVALID_PARAMETER);
1157 
1158 	if (wcslen(newName) > IMA_NODE_NAME_LEN - 1)
1159 		return (IMA_ERROR_NAME_TOO_LONG);
1160 
1161 	if (nodeOid.objectType != IMA_OBJECT_TYPE_NODE)
1162 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
1163 
1164 	if ((nodeOid.ownerId == RL_LIBRARY_SEQNUM) &&
1165 	    (nodeOid.objectSequenceNumber == RL_SHARED_NODE_SEQNUM)) {
1166 #if defined(SOLARIS)
1167 		if (setSolarisSharedNodeName(newName) != IMA_STATUS_SUCCESS) {
1168 			return (IMA_ERROR_UNKNOWN_ERROR);
1169 		}
1170 #endif
1171 		os_obtainmutex(libMutex);
1172 		libSwprintf(sharedNodeName, L"%ls", newName);
1173 		os_releasemutex(libMutex);
1174 		return (IMA_STATUS_SUCCESS);
1175 	}
1176 
1177 	os_obtainmutex(libMutex);
1178 	status = IMA_ERROR_OBJECT_NOT_FOUND;
1179 
1180 	for (i = 0; i < number_of_plugins; i++) {
1181 		if (plugintable[i].ownerId == nodeOid.ownerId) {
1182 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
1183 			if (plugintable[i].hPlugin != NULL) {
1184 				os_obtainmutex(plugintable[i].pluginMutex);
1185 #ifdef WIN32
1186 				PassFunc = (IMA_SetNodeNameFn)
1187 				    GetProcAddress(plugintable[i].hPlugin,
1188 				    "IMA_SetNodeName");
1189 #else
1190 				PassFunc = (IMA_SetNodeNameFn)
1191 				    dlsym(plugintable[i].hPlugin,
1192 				    "IMA_SetNodeName");
1193 #endif
1194 
1195 				if (PassFunc != NULL) {
1196 					status = PassFunc(nodeOid, newName);
1197 				}
1198 				os_releasemutex(plugintable[i].pluginMutex);
1199 			}
1200 
1201 			break;
1202 		}
1203 	}
1204 	os_releasemutex(libMutex);
1205 	return (status);
1206 
1207 }
1208 
1209 
1210 
1211 
1212 /*
1213  * Generates an unique node name for the currently running system.
1214  *
1215  * @param generatedname On successful return contains the generated node
1216  *    name.
1217  * @return An IMA_STATUS indicating if the operation was successful or if
1218  *    an error occurred.
1219  * @retval IMA_ERROR_INVALID_PARAMETER Returned if @a generatedname is NULL
1220  *    or specifies a memory area to which data cannot be written.
1221  */
IMA_GenerateNodeName(IMA_NODE_NAME generatedname)1222 IMA_API IMA_STATUS IMA_GenerateNodeName(
1223     IMA_NODE_NAME generatedname) {
1224 	char computername[256];
1225 	char nodename[MAXHOSTNAMELEN];
1226 
1227 #if defined(_WINDOWS)
1228 	IMA_UINT dwStrLength = 255;
1229 #endif
1230 
1231 #ifndef _WINDOWS
1232 #ifndef SOLARIS
1233 	int i;
1234 #endif
1235 #endif
1236 
1237 	if (generatedname == NULL)
1238 		return (IMA_ERROR_INVALID_PARAMETER);
1239 
1240 #if defined(_WINDOWS)
1241 	GetComputerName((char *)computername, (LPDWORD)&dwStrLength);
1242 	_strlwr(computername);
1243 	_snprintf(nodename, 256, DEFAULT_NODE_NAME_FORMAT, computername);
1244 	MultiByteToWideChar(CP_ACP, 0, nodename, -1,
1245 	generatedname, 256);
1246 #elif defined(SOLARIS)
1247 	if (getSolarisSharedNodeName(generatedname) != IMA_STATUS_SUCCESS) {
1248 		gethostname(computername, sizeof (computername));
1249 		sprintf(nodename, DEFAULT_NODE_NAME_FORMAT, generatedname);
1250 		mbstowcs(generatedname, nodename, 256);
1251 	}
1252 #else
1253 	gethostname((char *)computername, sizeof (computername));
1254 	i = 0;
1255 	while (computername[i] != '\0') {
1256 		computername[i] = tolower(computername[i]);
1257 		i++;
1258 	}
1259 	snprintf(nodename, 256, DEFAULT_NODE_NAME_FORMAT, computername);
1260 	mbstowcs(generatedname, nodename, 256);
1261 #endif
1262 
1263 	return (IMA_STATUS_SUCCESS);
1264 }
1265 
1266 
1267 /*
1268  * Sets the alias of the specified node.
1269  *
1270  * @param nodeId The object ID of the node whose alias is being set.
1271  * @param newAlias A pointer to a Unicode string which contains the new node
1272  *    alias.If this parameter is NULL then the current alias is deleted, in
1273  *    which case the specified node no longer has an alias.
1274  * @return An IMA_STATUS indicating if the operation was successful or if
1275  *    an error occurred.
1276  * @retval IMA_SUCCESS Returned if the node's alias has been successfully set.
1277  * @retval IMA_STATUS_REBOOT_NECESSARY A reboot is necessary before
1278  *    the setting of the
1279  *    alias actually takes affect.
1280  * @retval IMA_ERROR_INVALID_OBJECT_TYPE Returned if @a nodeId does not
1281  *    specify any valid object type.
1282  * @retval IMA_ERROR_INCORRECT_OBJECT_TYPE Returned if @a nodeId does not
1283  *    specify a node object.
1284  * @retval IMA_ERROR_OBJECT_NOT_FOUND Returned if @a nodeId does not specify
1285  *    a node which is currently known to the system.
1286  * @retval IMA_ERROR_NAME_TOO_LONG Returned if @a newAlias contains too many
1287  *               characters.
1288  */
IMA_SetNodeAlias(IMA_OID nodeOid,const IMA_NODE_ALIAS newAlias)1289 IMA_API IMA_STATUS IMA_SetNodeAlias(
1290     IMA_OID nodeOid,
1291     const IMA_NODE_ALIAS newAlias) {
1292 	IMA_SetNodeAliasFn PassFunc;
1293 	IMA_UINT i;
1294 	IMA_STATUS status;
1295 
1296 	if (number_of_plugins == -1)
1297 		InitLibrary();
1298 
1299 	if (newAlias == NULL)
1300 		return (IMA_ERROR_INVALID_PARAMETER);
1301 
1302 	if (wcslen(newAlias) > IMA_NODE_ALIAS_LEN - 1)
1303 		return (IMA_ERROR_NAME_TOO_LONG);
1304 
1305 	if (nodeOid.objectType != IMA_OBJECT_TYPE_NODE)
1306 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
1307 
1308 	if ((nodeOid.ownerId == RL_LIBRARY_SEQNUM) &&
1309 	    (nodeOid.objectSequenceNumber == RL_SHARED_NODE_SEQNUM)) {
1310 #if defined(SOLARIS)
1311 		if (setSolarisSharedNodeAlias(newAlias) != IMA_STATUS_SUCCESS) {
1312 			return (IMA_ERROR_UNKNOWN_ERROR);
1313 		}
1314 #endif
1315 		os_obtainmutex(libMutex);
1316 		if (wcslen(newAlias) > 0 && newAlias != NULL)
1317 			libSwprintf(sharedNodeAlias, L"%ls", newAlias);
1318 		else
1319 			libSwprintf(sharedNodeAlias, L"%ls", "");
1320 
1321 		os_releasemutex(libMutex);
1322 		return (IMA_STATUS_SUCCESS);
1323 	}
1324 
1325 	os_obtainmutex(libMutex);
1326 	status = IMA_ERROR_OBJECT_NOT_FOUND;
1327 
1328 	for (i = 0; i < number_of_plugins; i++) {
1329 		if (plugintable[i].ownerId == nodeOid.ownerId) {
1330 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
1331 			if (plugintable[i].hPlugin != NULL) {
1332 				os_obtainmutex(plugintable[i].pluginMutex);
1333 #ifdef WIN32
1334 				PassFunc = (IMA_SetNodeAliasFn)
1335 				    GetProcAddress(plugintable[i].hPlugin,
1336 				    "IMA_SetNodeAlias");
1337 #else
1338 				PassFunc = (IMA_SetNodeAliasFn)
1339 				    dlsym(
1340 				    plugintable[i].hPlugin,
1341 				    "IMA_SetNodeAlias");
1342 #endif
1343 
1344 				if (PassFunc != NULL) {
1345 					status = PassFunc(nodeOid, newAlias);
1346 				}
1347 				os_releasemutex(plugintable[i].pluginMutex);
1348 			}
1349 
1350 			break;
1351 		}
1352 	}
1353 	os_releasemutex(libMutex);
1354 	return (status);
1355 }
1356 
1357 
1358 
1359 
1360 /*
1361  * Gets a list of the object IDs of all the logical HBAs in the system.
1362  *
1363  * @param ppList A pointer to a pointer to an @ref IMA_OID_LIST structure.
1364  *    on successful return this will contain a pointer to an
1365  *    @ref IMA_OID_LIST which contains the object IDs of all of the
1366  *    LHBAs currently in the system.
1367  * @return An IMA_STATUS indicating if the operation was successful or if
1368  *    an error occurred.
1369  * @retval IMA_SUCCESS Returned if the LHBA ID list has been successfully
1370  *    returned.
1371  * @retval IMA_ERROR_INVALID_PARAMETER Returned if @a ppList is NULL or
1372  *   specifies a
1373  *   memory area to which data cannot be written.
1374  */
IMA_GetLhbaOidList(IMA_OID_LIST ** ppList)1375 IMA_API IMA_STATUS IMA_GetLhbaOidList(
1376     IMA_OID_LIST **ppList) {
1377 	IMA_GetLhbaOidListFn PassFunc;
1378 	IMA_FreeMemoryFn FreeFunc;
1379 
1380 	IMA_UINT i;
1381 	IMA_UINT j;
1382 	IMA_UINT totalIdCount;
1383 	IMA_STATUS status;
1384 
1385 	if (number_of_plugins == -1)
1386 		InitLibrary();
1387 
1388 	if (ppList == NULL)
1389 		return (IMA_ERROR_INVALID_PARAMETER);
1390 
1391 	os_obtainmutex(libMutex);
1392 	// Get total id count first
1393 	totalIdCount = 0;
1394 
1395 	for (i = 0; i < number_of_plugins; i++) {
1396 		status = IMA_ERROR_UNEXPECTED_OS_ERROR;
1397 		if (plugintable[i].hPlugin != NULL) {
1398 			os_obtainmutex(plugintable[i].pluginMutex);
1399 #ifdef WIN32
1400 			PassFunc = (IMA_GetLhbaOidListFn)
1401 			    GetProcAddress(plugintable[i].hPlugin,
1402 			    "IMA_GetLhbaOidList");
1403 #else
1404 			PassFunc = (IMA_GetLhbaOidListFn)
1405 			    dlsym(plugintable[i].hPlugin,
1406 			    "IMA_GetLhbaOidList");
1407 #endif
1408 			if (PassFunc != NULL) {
1409 				IMA_OID_LIST *ppOidList;
1410 				status = PassFunc(&ppOidList);
1411 				if (status == IMA_STATUS_SUCCESS) {
1412 					totalIdCount += ppOidList->oidCount;
1413 #ifdef WIN32
1414 					FreeFunc = (IMA_FreeMemoryFn)
1415 					    GetProcAddress(
1416 					    plugintable[i].hPlugin,
1417 					    "IMA_FreeMemory");
1418 #else
1419 					FreeFunc = (IMA_FreeMemoryFn)
1420 					    dlsym(plugintable[i].hPlugin,
1421 					    "IMA_FreeMemory");
1422 #endif
1423 					if (FreeFunc != NULL) {
1424 						FreeFunc(ppOidList);
1425 					}
1426 				}
1427 
1428 			}
1429 			os_releasemutex(plugintable[i].pluginMutex);
1430 		}
1431 		if (status != IMA_STATUS_SUCCESS) {
1432 			break;
1433 		}
1434 	}
1435 
1436 
1437 	*ppList = (IMA_OID_LIST*)calloc(1, sizeof (IMA_OID_LIST) +
1438 	    (totalIdCount - 1) * sizeof (IMA_OID));
1439 
1440 	if ((*ppList) == NULL) {
1441 		os_releasemutex(libMutex);
1442 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1443 	}
1444 	(*ppList)->oidCount = totalIdCount;
1445 
1446 	// 2nd pass to copy the id lists
1447 	totalIdCount = 0;
1448 	status = IMA_STATUS_SUCCESS;
1449 	for (i = 0; i < number_of_plugins; i++) {
1450 		status = IMA_ERROR_UNEXPECTED_OS_ERROR;
1451 		if (plugintable[i].hPlugin != NULL) {
1452 			os_obtainmutex(plugintable[i].pluginMutex);
1453 #ifdef WIN32
1454 			PassFunc = (IMA_GetLhbaOidListFn)
1455 			    GetProcAddress(plugintable[i].hPlugin,
1456 			    "IMA_GetLhbaOidList");
1457 #else
1458 			PassFunc = (IMA_GetLhbaOidListFn)
1459 			    dlsym(plugintable[i].hPlugin,
1460 			    "IMA_GetLhbaOidList");
1461 #endif
1462 			if (PassFunc != NULL) {
1463 				IMA_OID_LIST *ppOidList;
1464 				status = PassFunc(&ppOidList);
1465 				if (status == IMA_STATUS_SUCCESS) {
1466 					for (j = 0;
1467 					    (j < ppOidList->oidCount) &&
1468 					    (totalIdCount <
1469 					    (*ppList)->oidCount);
1470 					    j++) {
1471 						(*ppList)->oids[totalIdCount].
1472 						    objectType
1473 						    = ppOidList->oids[j].
1474 						    objectType;
1475 						(*ppList)->oids[totalIdCount].
1476 						    objectSequenceNumber =
1477 						    ppOidList->oids[j].
1478 						    objectSequenceNumber;
1479 						(*ppList)->oids[totalIdCount].
1480 						    ownerId =
1481 						    ppOidList->oids[j].ownerId;
1482 						totalIdCount++;
1483 					}
1484 #ifdef WIN32
1485 					FreeFunc = (IMA_FreeMemoryFn)
1486 					    GetProcAddress(
1487 					    plugintable[i].hPlugin,
1488 					    "IMA_FreeMemory");
1489 #else
1490 					FreeFunc = (IMA_FreeMemoryFn)
1491 					    dlsym(plugintable[i].hPlugin,
1492 					    "IMA_FreeMemory");
1493 #endif
1494 					if (FreeFunc != NULL) {
1495 						FreeFunc(ppOidList);
1496 					}
1497 				}
1498 			}
1499 			os_releasemutex(plugintable[i].pluginMutex);
1500 		}
1501 		if (status != IMA_STATUS_SUCCESS) {
1502 			free(*ppList);
1503 			break;
1504 		}
1505 
1506 	}
1507 	os_releasemutex(libMutex);
1508 	return (status);
1509 }
1510 
1511 
1512 
1513 
1514 /*
1515  * Gets the properties of the specified logical HBA.
1516  *
1517  * @param lhbaId The object ID of the LHBA whose properties are being
1518  *    retrieved.
1519  * @param pProps A pointer to an @ref IMA_LHBA_PROPERTIES structure.
1520  *    On successful
1521  *    return this will contain the properties of the LHBA specified by
1522  *    @a lhbaId.
1523  * @return An IMA_STATUS indicating if the operation was successful or if
1524  *    an error occurred.
1525  * @retval IMA_SUCCESS Returned if the properties of the specified LHBA
1526  *    have been successfully retrieved.
1527  * @retval IMA_ERROR_INVALID_PARAMETER Returned if @a pProps is NULL or
1528  *    specify a memory area to which data cannot be written.
1529  * @retval IMA_ERROR_INVALID_OBJECT_TYPE Returned if @a lhbaId does not
1530  *    specify any valid object type.
1531  * @retval IMA_ERROR_INCORRECT_OBJECT_TYPE Returned if @a lhbaId does not
1532  *    specify a LHBA.
1533  * @retval IMA_ERROR_OBJECT_NOT_FOUND Returned if @a lhbaId does not
1534  *    specify a LHBA which is currently known to the system.
1535  */
IMA_GetLhbaProperties(IMA_OID lhbaId,IMA_LHBA_PROPERTIES * pProps)1536 IMA_API IMA_STATUS IMA_GetLhbaProperties(
1537     IMA_OID lhbaId,
1538     IMA_LHBA_PROPERTIES *pProps) {
1539 	IMA_GetLhbaPropertiesFn PassFunc;
1540 	IMA_UINT i;
1541 	IMA_STATUS status;
1542 
1543 	if (number_of_plugins == -1)
1544 		InitLibrary();
1545 
1546 	if (pProps == NULL)
1547 		return (IMA_ERROR_INVALID_PARAMETER);
1548 
1549 	if (lhbaId.objectType != IMA_OBJECT_TYPE_LHBA)
1550 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
1551 
1552 	os_obtainmutex(libMutex);
1553 	status = IMA_ERROR_OBJECT_NOT_FOUND;
1554 
1555 	for (i = 0; i < number_of_plugins; i++) {
1556 		if (plugintable[i].ownerId == lhbaId.ownerId) {
1557 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
1558 			if (plugintable[i].hPlugin != NULL) {
1559 				os_obtainmutex(plugintable[i].pluginMutex);
1560 #ifdef WIN32
1561 				PassFunc = (IMA_GetLhbaPropertiesFn)
1562 				    GetProcAddress(plugintable[i].hPlugin,
1563 				    "IMA_GetLhbaProperties");
1564 #else
1565 				PassFunc = (IMA_GetLhbaPropertiesFn)
1566 				    dlsym(plugintable[i].hPlugin,
1567 				    "IMA_GetLhbaProperties");
1568 #endif
1569 
1570 				if (PassFunc != NULL) {
1571 					status = PassFunc(lhbaId, pProps);
1572 				}
1573 				os_releasemutex(plugintable[i].pluginMutex);
1574 			}
1575 
1576 			break;
1577 		}
1578 	}
1579 	os_releasemutex(libMutex);
1580 	return (status);
1581 }
1582 
1583 
1584 
1585 
1586 /*
1587  * Gets a list of the object IDs of all the physical HBAs in the system.
1588  *
1589  * @param ppList A pointer to a pointer to an @ref IMA_OID_LIST structure.
1590  *    on successful return this will contain a pointer to an
1591  *    @ref IMA_OID_LIST which contains the object IDs of all of the
1592  *    PHBAs currently in the system.
1593  * @return An IMA_STATUS indicating if the operation was successful or if
1594  *    an error occurred.
1595  * @retval IMA_SUCCESS Returned if the PHBA ID list has been successfully
1596  *    returned.
1597  * @retval IMA_ERROR_INVALID_PARAMETER Returned if @a ppList is NULL or
1598  *    specify a memory area to which data cannot be written.
1599  * @retval IMA_SUCCESS Returned if the properties of the specified PHBA
1600  *    have been successfully retrieved.
1601  * @retval IMA_ERROR_OBJECT_NOT_FOUND Returned if @a phbaId does not
1602  *    specify a PHBA which is currently known to the system.
1603  * @retval IMA_ERROR_INVALID_PARAMETER Returned if @a ppList is NULL or
1604  *    specify a memory area to which data cannot be written.
1605  */
IMA_GetPhbaOidList(IMA_OID_LIST ** ppList)1606 IMA_API IMA_STATUS IMA_GetPhbaOidList(
1607     IMA_OID_LIST **ppList) {
1608 	IMA_GetPhbaOidListFn PassFunc;
1609 	IMA_FreeMemoryFn FreeFunc;
1610 
1611 	IMA_UINT i;
1612 	IMA_UINT j;
1613 	IMA_UINT totalIdCount;
1614 	IMA_STATUS status;
1615 
1616 	if (number_of_plugins == -1)
1617 		InitLibrary();
1618 
1619 	if (ppList == NULL)
1620 		return (IMA_ERROR_INVALID_PARAMETER);
1621 
1622 	os_obtainmutex(libMutex);
1623 	// Get total id count first
1624 	totalIdCount = 0;
1625 
1626 	for (i = 0; i < number_of_plugins; i++) {
1627 		status = IMA_ERROR_UNEXPECTED_OS_ERROR;
1628 		if (plugintable[i].hPlugin != NULL) {
1629 			os_obtainmutex(plugintable[i].pluginMutex);
1630 #ifdef WIN32
1631 			PassFunc = (IMA_GetPhbaOidListFn)
1632 			    GetProcAddress(plugintable[i].hPlugin,
1633 			    "IMA_GetPhbaOidList");
1634 #else
1635 			PassFunc = (IMA_GetPhbaOidListFn)
1636 			    dlsym(plugintable[i].hPlugin,
1637 			    "IMA_GetPhbaOidList");
1638 #endif
1639 			if (PassFunc != NULL) {
1640 				IMA_OID_LIST *ppOidList;
1641 				status = PassFunc(&ppOidList);
1642 				if (status == IMA_STATUS_SUCCESS) {
1643 					totalIdCount += ppOidList->oidCount;
1644 #ifdef WIN32
1645 					FreeFunc = (IMA_FreeMemoryFn)
1646 					    GetProcAddress(
1647 					    plugintable[i].hPlugin,
1648 					    "IMA_FreeMemory");
1649 #else
1650 					FreeFunc = (IMA_FreeMemoryFn)
1651 					    dlsym(plugintable[i].hPlugin,
1652 					    "IMA_FreeMemory");
1653 #endif
1654 					if (FreeFunc != NULL) {
1655 						FreeFunc(ppOidList);
1656 					}
1657 				}
1658 			}
1659 			os_releasemutex(plugintable[i].pluginMutex);
1660 		}
1661 		if (status != IMA_STATUS_SUCCESS) {
1662 			break;
1663 		}
1664 
1665 	}
1666 
1667 
1668 	*ppList = (IMA_OID_LIST*)calloc(1, sizeof (IMA_OID_LIST) +
1669 	    (totalIdCount - 1) * sizeof (IMA_OID));
1670 
1671 	if ((*ppList) == NULL) {
1672 		os_releasemutex(libMutex);
1673 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1674 	}
1675 
1676 	(*ppList)->oidCount = totalIdCount;
1677 
1678 	// 2nd pass to copy the id lists
1679 	totalIdCount = 0;
1680 	status = IMA_STATUS_SUCCESS;
1681 	for (i = 0; i < number_of_plugins; i++) {
1682 		status = IMA_ERROR_UNEXPECTED_OS_ERROR;
1683 		if (plugintable[i].hPlugin != NULL) {
1684 			os_obtainmutex(plugintable[i].pluginMutex);
1685 #ifdef WIN32
1686 			PassFunc = (IMA_GetPhbaOidListFn)
1687 			    GetProcAddress(plugintable[i].hPlugin,
1688 			    "IMA_GetPhbaOidList");
1689 #else
1690 			PassFunc = (IMA_GetPhbaOidListFn)
1691 			    dlsym(plugintable[i].hPlugin,
1692 			    "IMA_GetPhbaOidList");
1693 #endif
1694 			if (PassFunc != NULL) {
1695 				IMA_OID_LIST *ppOidList;
1696 				status = PassFunc(&ppOidList);
1697 				if (status == IMA_STATUS_SUCCESS) {
1698 					for (j = 0;
1699 					    (j < ppOidList->oidCount) &&
1700 					    (totalIdCount <
1701 					    (*ppList)->oidCount);
1702 					    j++) {
1703 						(*ppList)->oids[totalIdCount].
1704 						    objectType =
1705 						    ppOidList->oids[j].
1706 						    objectType;
1707 						(*ppList)->oids[totalIdCount].
1708 						    objectSequenceNumber =
1709 						    ppOidList->oids[j].
1710 						    objectSequenceNumber;
1711 						(*ppList)->oids[totalIdCount].
1712 						    ownerId =
1713 						    ppOidList->oids[j].ownerId;
1714 						totalIdCount++;
1715 					}
1716 #ifdef WIN32
1717 					FreeFunc = (IMA_FreeMemoryFn)
1718 					    GetProcAddress
1719 					    (plugintable[i].hPlugin,
1720 					    "IMA_FreeMemory");
1721 #else
1722 					FreeFunc = (IMA_FreeMemoryFn)
1723 					    dlsym(plugintable[i].hPlugin,
1724 					    "IMA_FreeMemory");
1725 #endif
1726 					if (FreeFunc != NULL) {
1727 						FreeFunc(ppOidList);
1728 					}
1729 				}
1730 			}
1731 			os_releasemutex(plugintable[i].pluginMutex);
1732 		}
1733 		if (status != IMA_STATUS_SUCCESS) {
1734 			free(*ppList);
1735 			break;
1736 		}
1737 	}
1738 	os_releasemutex(libMutex);
1739 	return (status);
1740 }
1741 
1742 
1743 /*
1744  * Gets the general properties of a physical HBA.
1745  *
1746  * @param phbaId The object ID of the PHBA whose
1747  *    properties are being queried.
1748  * @param pProps A pointer to an @ref
1749  *    IMA_PHBA_PROPERTIES structure.  On successful
1750  *    return this will contain the properties of
1751  *    the PHBA specified by @a phbaId.
1752  * @return An IMA_STATUS indicating if the
1753  *    operation was successful or if an error
1754  *    occurred.
1755  * @retval IMA_SUCCESS Returned if the properties
1756  *    of the specified PHBA have been
1757  *    successfully retrieved.
1758  * @retval IMA_ERROR_INVALID_PARAMETER Returned
1759  *    if @a pProps is NULL or specifies a
1760  *    memory area to which data cannot be written.
1761  * @retval IMA_ERROR_INVALID_OBJECT_TYPE Returned
1762  *    if @a phbaId does not specify any
1763  *    valid object type.
1764  * @retval IMA_ERROR_INCORRECT_OBJECT_TYPE Returned
1765  *    if @a phbaId does not specify a
1766  *    PHBA.
1767  * @retval IMA_ERROR_OBJECT_NOT_FOUND Returned
1768  *    if @a phbaId does not specify a PHBA
1769  *    which is currently known to the system.
1770  */
IMA_GetPhbaProperties(IMA_OID phbaId,IMA_PHBA_PROPERTIES * pProps)1771 IMA_API IMA_STATUS IMA_GetPhbaProperties(
1772     IMA_OID phbaId,
1773     IMA_PHBA_PROPERTIES *pProps) {
1774 	IMA_GetPhbaPropertiesFn PassFunc;
1775 	IMA_UINT i;
1776 	IMA_STATUS status;
1777 
1778 	if (number_of_plugins == -1)
1779 		InitLibrary();
1780 
1781 	if (pProps == NULL)
1782 		return (IMA_ERROR_INVALID_PARAMETER);
1783 
1784 	if (phbaId.objectType != IMA_OBJECT_TYPE_PHBA)
1785 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
1786 
1787 	os_obtainmutex(libMutex);
1788 	status = IMA_ERROR_OBJECT_NOT_FOUND;
1789 
1790 	for (i = 0; i < number_of_plugins; i++) {
1791 		if (plugintable[i].ownerId == phbaId.ownerId) {
1792 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
1793 			if (plugintable[i].hPlugin != NULL) {
1794 				os_obtainmutex(plugintable[i].pluginMutex);
1795 #ifdef WIN32
1796 				PassFunc = (IMA_GetPhbaPropertiesFn)
1797 				    GetProcAddress(plugintable[i].hPlugin,
1798 				    "IMA_GetPhbaProperties");
1799 #else
1800 				PassFunc = (IMA_GetPhbaPropertiesFn)
1801 				    dlsym(plugintable[i].hPlugin,
1802 				    "IMA_GetPhbaProperties");
1803 #endif
1804 
1805 				if (PassFunc != NULL) {
1806 					status = PassFunc(phbaId, pProps);
1807 				}
1808 				os_releasemutex(plugintable[i].pluginMutex);
1809 			}
1810 
1811 			break;
1812 		}
1813 	}
1814 	os_releasemutex(libMutex);
1815 	return (status);
1816 }
1817 
1818 /*
1819  * Frees a previously allocated IMA_OID_LIST structure.
1820  *
1821  * @param pList A pointer to an @ref IMA_OID_LIST
1822  *    structure allocated by the
1823  *    library.  On successful return the memory
1824  *    allocated by the list is freed.
1825  * @return An IMA_STATUS indicating if the operation
1826  *    was successful or if an error occurred.
1827  * @retval IMA_SUCCESS Returned if the specified object
1828  *    ID list was successfully freed.
1829  * @retval IMA_ERROR_INVALID_PARAMETER Returned
1830  *    if @a pList is NULL or specifies a
1831  *    memory area from which data cannot be read.
1832  */
IMA_FreeMemory(void * pMemory)1833 IMA_API IMA_STATUS IMA_FreeMemory(
1834     void *pMemory) {
1835 	if (pMemory == NULL)
1836 		return (IMA_ERROR_INVALID_PARAMETER);
1837 	free(pMemory);
1838 	return (IMA_STATUS_SUCCESS);
1839 }
1840 
1841 
1842 
1843 
IMA_GetNonSharedNodeOidList(IMA_OID_LIST ** ppList)1844 IMA_API IMA_STATUS IMA_GetNonSharedNodeOidList(
1845     IMA_OID_LIST **ppList) {
1846 	IMA_GetNonSharedNodeOidListFn PassFunc;
1847 	IMA_FreeMemoryFn FreeFunc;
1848 
1849 	IMA_UINT i;
1850 	IMA_UINT j;
1851 	IMA_UINT totalIdCount;
1852 	IMA_STATUS status;
1853 
1854 	if (number_of_plugins == -1)
1855 		InitLibrary();
1856 
1857 	if (ppList == NULL)
1858 		return (IMA_ERROR_INVALID_PARAMETER);
1859 
1860 	os_obtainmutex(libMutex);
1861 	// Get total id count first
1862 	totalIdCount = 0;
1863 
1864 	for (i = 0; i < number_of_plugins; i++) {
1865 		status = IMA_ERROR_UNEXPECTED_OS_ERROR;
1866 		if (plugintable[i].hPlugin != NULL) {
1867 			os_obtainmutex(plugintable[i].pluginMutex);
1868 #ifdef WIN32
1869 			PassFunc = (IMA_GetNonSharedNodeOidListFn)
1870 			    GetProcAddress(plugintable[i].hPlugin,
1871 			    "IMA_GetNonSharedNodeOidList");
1872 #else
1873 			PassFunc = (IMA_GetNonSharedNodeOidListFn)
1874 			    dlsym(plugintable[i].hPlugin,
1875 			    "IMA_GetNonSharedNodeOidList");
1876 #endif
1877 			if (PassFunc != NULL) {
1878 				IMA_OID_LIST *ppOidList;
1879 				status = PassFunc(&ppOidList);
1880 				if (status == IMA_STATUS_SUCCESS) {
1881 					totalIdCount += ppOidList->oidCount;
1882 #ifdef WIN32
1883 					FreeFunc = (IMA_FreeMemoryFn)
1884 					    GetProcAddress(
1885 					    plugintable[i].hPlugin,
1886 					    "IMA_FreeMemory");
1887 #else
1888 					FreeFunc = (IMA_FreeMemoryFn)
1889 					    dlsym(plugintable[i].hPlugin,
1890 					    "IMA_FreeMemory");
1891 #endif
1892 					if (FreeFunc != NULL) {
1893 						FreeFunc(ppOidList);
1894 					}
1895 				}
1896 			}
1897 			os_releasemutex(plugintable[i].pluginMutex);
1898 		}
1899 		if (status != IMA_STATUS_SUCCESS) {
1900 			break;
1901 		}
1902 
1903 	}
1904 
1905 	*ppList = (IMA_OID_LIST*)calloc(1, sizeof (IMA_OID_LIST) +
1906 	    (totalIdCount - 1) * sizeof (IMA_OID));
1907 
1908 	if ((*ppList) == NULL) {
1909 		os_releasemutex(libMutex);
1910 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1911 	}
1912 
1913 	(*ppList)->oidCount = totalIdCount;
1914 
1915 	// 2nd pass to copy the id lists
1916 	totalIdCount = 0;
1917 	status = IMA_STATUS_SUCCESS;
1918 	for (i = 0; i < number_of_plugins; i++) {
1919 		status = IMA_ERROR_UNEXPECTED_OS_ERROR;
1920 		if (plugintable[i].hPlugin != NULL) {
1921 			os_obtainmutex(plugintable[i].pluginMutex);
1922 #ifdef WIN32
1923 			PassFunc = (IMA_GetNonSharedNodeOidListFn)
1924 			    GetProcAddress(plugintable[i].hPlugin,
1925 			    "IMA_GetNonSharedNodeOidList");
1926 #else
1927 			PassFunc = (IMA_GetNonSharedNodeOidListFn)
1928 			    dlsym(plugintable[i].hPlugin,
1929 			    "IMA_GetNonSharedNodeOidList");
1930 #endif
1931 			if (PassFunc != NULL) {
1932 				IMA_OID_LIST *ppOidList;
1933 				status = PassFunc(&ppOidList);
1934 				if (status == IMA_STATUS_SUCCESS) {
1935 					for (j = 0;
1936 					    (j < ppOidList->oidCount) &&
1937 					    (totalIdCount < (
1938 					    *ppList)->oidCount);
1939 					    j++) {
1940 						(*ppList)->oids[
1941 						    totalIdCount].objectType =
1942 						    ppOidList->oids[j].
1943 						    objectType;
1944 						(*ppList)->oids[totalIdCount].
1945 						    objectSequenceNumber =
1946 						    ppOidList->oids[j].
1947 						    objectSequenceNumber;
1948 						(*ppList)->oids[
1949 						    totalIdCount].
1950 						    ownerId =
1951 						    ppOidList->oids[j].
1952 						    ownerId;
1953 						totalIdCount++;
1954 					}
1955 #ifdef WIN32
1956 					FreeFunc = (IMA_FreeMemoryFn)
1957 					    GetProcAddress(
1958 					    plugintable[i].hPlugin,
1959 					    "IMA_FreeMemory");
1960 #else
1961 					FreeFunc = (IMA_FreeMemoryFn)
1962 					    dlsym(plugintable[i].hPlugin,
1963 					    "IMA_FreeMemory");
1964 #endif
1965 					if (FreeFunc != NULL) {
1966 						FreeFunc(ppOidList);
1967 					}
1968 				}
1969 			}
1970 			os_releasemutex(plugintable[i].pluginMutex);
1971 		}
1972 		if (status != IMA_STATUS_SUCCESS) {
1973 			free(*ppList);
1974 			break;
1975 		}
1976 	}
1977 	os_releasemutex(libMutex);
1978 	return (status);
1979 }
1980 
1981 
1982 
1983 /*
1984  * Gets the first burst length properties of
1985  * the specified logical HBA.
1986  *
1987  * @param lhbaId The object ID of the logical HBA
1988  *    to get the first burst length
1989  *    properties of.
1990  * @param pProps A pointer to a min/max values
1991  *    structure.
1992  * @return An IMA_STATUS indicating if the operation
1993  *    was successful or if an error
1994  *    occurred.
1995  * @retval IMA_SUCCESS Returned if the first burst
1996  *    length properties have been
1997  *    successfully retrieved.
1998  * @retval IMA_ERROR_INVALID_PARAMETER Returned
1999  *    if @a pProps is NULL or specifies a
2000  *    memory area to which data cannot be written.
2001  * @retval IMA_ERROR_INVALID_OBJECT_TYPE Returned
2002  *    if @a lhbaId does not specify any
2003  *    valid object type.
2004  * @retval IMA_ERROR_INCORRECT_OBJECT_TYPE Returned
2005  *    if @a lhbaId does not specify a LHBA.
2006  * @retval IMA_ERROR_OBJECT_NOT_FOUND Returned
2007  *    @a lhbaId does not specify a LHBA
2008  *    which is currently known to the system.
2009  */
IMA_GetFirstBurstLengthProperties(IMA_OID Oid,IMA_MIN_MAX_VALUE * pProps)2010 IMA_API IMA_STATUS IMA_GetFirstBurstLengthProperties(
2011     IMA_OID Oid,
2012     IMA_MIN_MAX_VALUE *pProps) {
2013 	IMA_GetFirstBurstLengthPropertiesFn PassFunc;
2014 	IMA_UINT i;
2015 	IMA_STATUS status;
2016 
2017 	if (number_of_plugins == -1)
2018 		InitLibrary();
2019 
2020 	if (pProps == NULL)
2021 		return (IMA_ERROR_INVALID_PARAMETER);
2022 
2023 	if (Oid.objectType != IMA_OBJECT_TYPE_LHBA &&
2024 	    Oid.objectType != IMA_OBJECT_TYPE_TARGET)
2025 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
2026 
2027 	os_obtainmutex(libMutex);
2028 	status = IMA_ERROR_OBJECT_NOT_FOUND;
2029 
2030 	for (i = 0; i < number_of_plugins; i++) {
2031 		if (plugintable[i].ownerId == Oid.ownerId) {
2032 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
2033 			if (plugintable[i].hPlugin != NULL) {
2034 				os_obtainmutex(plugintable[i].pluginMutex);
2035 #ifdef WIN32
2036 				PassFunc =
2037 				    (IMA_GetFirstBurstLengthPropertiesFn)
2038 				    GetProcAddress(plugintable[i].hPlugin,
2039 				    "IMA_GetFirstBurstLengthProperties");
2040 #else
2041 				PassFunc =
2042 				    (IMA_GetFirstBurstLengthPropertiesFn)
2043 				    dlsym(plugintable[i].hPlugin,
2044 				    "IMA_GetFirstBurstLengthProperties");
2045 #endif
2046 
2047 				if (PassFunc != NULL) {
2048 					status = PassFunc(Oid, pProps);
2049 				}
2050 				os_releasemutex(plugintable[i].pluginMutex);
2051 			}
2052 
2053 			break;
2054 		}
2055 	}
2056 	os_releasemutex(libMutex);
2057 	return (status);
2058 }
2059 
2060 /*
2061  * Gets the max burst length properties of the
2062  * specified logical HBA.
2063  *
2064  * @param lhbaId The object ID of the logical HBA to
2065  * get the max burst length properties of.
2066  * @param pProps A pointer to an @ref IMA_MIN_MAX_VALUE
2067  *    structure allocated by the
2068  *    caller.  On successful return this structure
2069  *    will contain the max
2070  *    burst length properties of this LHBA.
2071  * @return An IMA_STATUS indicating if the operation
2072  *    was successful or if an error occurred.
2073  * @retval IMA_SUCCESS Returned if the max burst
2074  *    length properties have been
2075  *    successfully retrieved.
2076  * @retval IMA_ERROR_INVALID_PARAMETER Returned
2077  *    if @a pProps is NULL or specifies a
2078  *    memory area to which data cannot be written.
2079  * @retval IMA_ERROR_INVALID_OBJECT_TYPE Returned
2080  *    if @a lhbaId does not specify any
2081  *    valid object type.
2082  * @retval IMA_ERROR_INCORRECT_OBJECT_TYPE Returned
2083  *    if @a lhbaId does not specify a HBA.
2084  * @retval IMA_ERROR_OBJECT_NOT_FOUND Returned
2085  *    if @a lhbaId does not specify a LHBA
2086  *    which is currently known to the system.
2087  */
IMA_GetMaxBurstLengthProperties(IMA_OID Oid,IMA_MIN_MAX_VALUE * pProps)2088 IMA_API IMA_STATUS IMA_GetMaxBurstLengthProperties(
2089     IMA_OID Oid,
2090     IMA_MIN_MAX_VALUE *pProps) {
2091 	IMA_GetMaxBurstLengthPropertiesFn PassFunc;
2092 	IMA_UINT i;
2093 	IMA_STATUS status;
2094 
2095 	if (number_of_plugins == -1)
2096 		InitLibrary();
2097 
2098 	if (pProps == NULL)
2099 		return (IMA_ERROR_INVALID_PARAMETER);
2100 
2101 	if (Oid.objectType != IMA_OBJECT_TYPE_LHBA &&
2102 	    Oid.objectType != IMA_OBJECT_TYPE_TARGET)
2103 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
2104 
2105 	os_obtainmutex(libMutex);
2106 	status = IMA_ERROR_OBJECT_NOT_FOUND;
2107 
2108 	for (i = 0; i < number_of_plugins; i++) {
2109 		if (plugintable[i].ownerId == Oid.ownerId) {
2110 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
2111 			if (plugintable[i].hPlugin != NULL) {
2112 				os_obtainmutex(plugintable[i].pluginMutex);
2113 #ifdef WIN32
2114 				PassFunc =
2115 				    (IMA_GetMaxBurstLengthPropertiesFn)
2116 				    GetProcAddress(plugintable[i].hPlugin,
2117 				    "IMA_GetMaxBurstLengthProperties");
2118 #else
2119 				PassFunc =
2120 				    (IMA_GetMaxBurstLengthPropertiesFn)
2121 				    dlsym(plugintable[i].hPlugin,
2122 				    "IMA_GetMaxBurstLengthProperties");
2123 #endif
2124 				if (PassFunc != NULL) {
2125 					status = PassFunc(Oid, pProps);
2126 				}
2127 				os_releasemutex(plugintable[i].pluginMutex);
2128 			}
2129 
2130 			break;
2131 		}
2132 	}
2133 	os_releasemutex(libMutex);
2134 	return (status);
2135 }
2136 
2137 
2138 /*
2139  * Gets the maximum receive data segment length properties
2140  * of the specified logical HBA.
2141  *
2142  * @param lhbaId The object ID of the logical HBA to
2143  *    get the max receive data
2144  *    segment length properties of.
2145  * @param pProps A pointer to an @ref IMA_MIN_MAX_VALUE
2146  *    structure allocated by the caller.
2147  *    On successful return this structure will contain the max
2148  *    receive data segment length properties of this LHBA.
2149  * @return An IMA_STATUS indicating if the operation
2150  *    was successful or if an error occurred.
2151  * @retval IMA_SUCCESS Returned if the max receive
2152  *    data segment length properties
2153  *    have been successfully retrieved.
2154  * @retval IMA_ERROR_INVALID_PARAMETER Returned if
2155  *    @a pProps is NULL or specifies a
2156  *    memory area to which data cannot be written.
2157  * @retval IMA_ERROR_INVALID_OBJECT_TYPE Returned if
2158  *    @a lhbaId does not specify any
2159  *    valid object type.
2160  * @retval IMA_ERROR_INCORRECT_OBJECT_TYPE Returned if
2161  *    a lhbaId does not specify a LHBA.
2162  * @retval IMA_ERROR_OBJECT_NOT_FOUND Returned if @a
2163  *    lhbaId does not specify a LHBA
2164  *    which is currently known to the system.
2165  */
IMA_GetMaxRecvDataSegmentLengthProperties(IMA_OID Oid,IMA_MIN_MAX_VALUE * pProps)2166 IMA_API IMA_STATUS IMA_GetMaxRecvDataSegmentLengthProperties(
2167     IMA_OID Oid,
2168     IMA_MIN_MAX_VALUE *pProps) {
2169 	IMA_GetMaxRecvDataSegmentLengthPropertiesFn PassFunc;
2170 	IMA_UINT i;
2171 	IMA_STATUS status;
2172 #define	IMA_GMRDSLPFN IMA_GetMaxRecvDataSegmentLengthPropertiesFn
2173 #define	IMA_GMRDSLP "IMA_GetMaxRecvDataSegmentLengthProperties"
2174 
2175 	if (number_of_plugins == -1)
2176 		InitLibrary();
2177 
2178 	if (pProps == NULL)
2179 		return (IMA_ERROR_INVALID_PARAMETER);
2180 
2181 	if (Oid.objectType != IMA_OBJECT_TYPE_LHBA &&
2182 	    Oid.objectType != IMA_OBJECT_TYPE_TARGET)
2183 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
2184 
2185 	os_obtainmutex(libMutex);
2186 	status = IMA_ERROR_OBJECT_NOT_FOUND;
2187 
2188 	for (i = 0; i < number_of_plugins; i++) {
2189 		if (plugintable[i].ownerId == Oid.ownerId) {
2190 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
2191 			if (plugintable[i].hPlugin != NULL) {
2192 				os_obtainmutex(plugintable[i].pluginMutex);
2193 #ifdef WIN32
2194 				PassFunc =
2195 				    (IMA_GMRDSLPFN)
2196 				    GetProcAddress(plugintable[i].hPlugin,
2197 				    IMA_GMRDSLP);
2198 #else
2199 				PassFunc =
2200 				    (IMA_GMRDSLPFN)
2201 				    dlsym(plugintable[i].hPlugin,
2202 				    IMA_GMRDSLP);
2203 #endif
2204 
2205 				if (PassFunc != NULL) {
2206 					status = PassFunc(Oid, pProps);
2207 				}
2208 				os_releasemutex(plugintable[i].pluginMutex);
2209 			}
2210 
2211 			break;
2212 		}
2213 	}
2214 	os_releasemutex(libMutex);
2215 #undef IMA_GMRDSLPFN
2216 #undef IMA_GMRDSLP
2217 	return (status);
2218 }
2219 
2220 
2221 
2222 /* --------------------------------------------- */
IMA_PluginIOCtl(IMA_OID pluginOid,IMA_UINT command,const void * pInputBuffer,IMA_UINT inputBufferLength,void * pOutputBuffer,IMA_UINT * pOutputBufferLength)2223 IMA_API IMA_STATUS IMA_PluginIOCtl(
2224     IMA_OID pluginOid,
2225     IMA_UINT command,
2226     const void *pInputBuffer,
2227     IMA_UINT inputBufferLength,
2228     void *pOutputBuffer,
2229     IMA_UINT *pOutputBufferLength) {
2230 	IMA_PluginIOCtlFn PassFunc;
2231 	IMA_UINT i;
2232 	IMA_STATUS status;
2233 
2234 	if (number_of_plugins == -1)
2235 		InitLibrary();
2236 
2237 	if (pInputBuffer == NULL || inputBufferLength == 0 ||
2238 	    pOutputBuffer == NULL || pOutputBufferLength == NULL ||
2239 	    *pOutputBufferLength == 0)
2240 		return (IMA_ERROR_INVALID_PARAMETER);
2241 
2242 	if (pluginOid.objectType != IMA_OBJECT_TYPE_PLUGIN)
2243 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
2244 
2245 	os_obtainmutex(libMutex);
2246 	status = IMA_ERROR_OBJECT_NOT_FOUND;
2247 
2248 	for (i = 0; i < number_of_plugins; i++) {
2249 		if (plugintable[i].ownerId == pluginOid.ownerId) {
2250 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
2251 			if (plugintable[i].hPlugin != NULL) {
2252 				os_obtainmutex(plugintable[i].pluginMutex);
2253 #ifdef WIN32
2254 				PassFunc = (IMA_PluginIOCtlFn)
2255 				    GetProcAddress(plugintable[i].hPlugin,
2256 				    "IMA_PluginIOCtl");
2257 #else
2258 				PassFunc = (IMA_PluginIOCtlFn)
2259 				    dlsym(plugintable[i].hPlugin,
2260 				    "IMA_PluginIOCtl");
2261 #endif
2262 
2263 				if (PassFunc != NULL) {
2264 					status = PassFunc(
2265 					    pluginOid, command,
2266 					    pInputBuffer, inputBufferLength,
2267 					    pOutputBuffer, pOutputBufferLength);
2268 				}
2269 				os_releasemutex(plugintable[i].pluginMutex);
2270 			}
2271 
2272 			break;
2273 		}
2274 	}
2275 	os_releasemutex(libMutex);
2276 	return (status);
2277 }
2278 
2279 
2280 
2281 
IMA_GetNetworkPortalOidList(IMA_OID lnpId,IMA_OID_LIST ** ppList)2282 IMA_API IMA_STATUS IMA_GetNetworkPortalOidList(
2283     IMA_OID lnpId,
2284     IMA_OID_LIST **ppList) {
2285 	IMA_GetNetworkPortalOidListFn PassFunc;
2286 	IMA_FreeMemoryFn FreeFunc;
2287 	IMA_UINT i;
2288 	IMA_STATUS status;
2289 
2290 	if (number_of_plugins == -1)
2291 		InitLibrary();
2292 
2293 	if (ppList == NULL)
2294 		return (IMA_ERROR_INVALID_PARAMETER);
2295 
2296 	if (lnpId.objectType != IMA_OBJECT_TYPE_LNP)
2297 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
2298 
2299 	os_obtainmutex(libMutex);
2300 	status = IMA_ERROR_OBJECT_NOT_FOUND;
2301 
2302 	for (i = 0; i < number_of_plugins; i++) {
2303 		if (plugintable[i].ownerId == lnpId.ownerId) {
2304 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
2305 			if (plugintable[i].hPlugin != NULL) {
2306 				os_obtainmutex(plugintable[i].pluginMutex);
2307 #ifdef WIN32
2308 				PassFunc = (IMA_GetNetworkPortalOidListFn)
2309 				    GetProcAddress(plugintable[i].hPlugin,
2310 				    "IMA_GetNetworkPortalOidList");
2311 #else
2312 				PassFunc = (IMA_GetNetworkPortalOidListFn)
2313 				    dlsym(plugintable[i].hPlugin,
2314 				    "IMA_GetNetworkPortalOidList");
2315 #endif
2316 
2317 				if (PassFunc != NULL) {
2318 					IMA_OID_LIST *ppOidList;
2319 					IMA_UINT listSize;
2320 					listSize = sizeof (IMA_OID_LIST);
2321 					status = PassFunc(lnpId, &ppOidList);
2322 					if (IMA_SUCCESS(status)) {
2323 
2324 						*ppList = (IMA_OID_LIST*)
2325 						    calloc(1,
2326 						    sizeof (IMA_OID_LIST)
2327 						    + (ppOidList->
2328 						    oidCount - 1)*
2329 						    sizeof (IMA_OID));
2330 
2331 						if ((*ppList) == NULL) {
2332 							return (EUOS_ERROR);
2333 						}
2334 						else
2335 							memcpy((*ppList),
2336 							    ppOidList,
2337 							    listSize
2338 							    + (ppOidList->
2339 							    oidCount - 1)*
2340 							    sizeof (IMA_OID));
2341 #ifdef WIN32
2342 						FreeFunc = (IMA_FreeMemoryFn)
2343 						    GetProcAddress(
2344 						    plugintable[i].hPlugin,
2345 						    "IMA_FreeMemory");
2346 #else
2347 						FreeFunc = (IMA_FreeMemoryFn)
2348 						    dlsym(
2349 						    plugintable[i].hPlugin,
2350 						    "IMA_FreeMemory");
2351 #endif
2352 						if (FreeFunc != NULL) {
2353 							FreeFunc(ppOidList);
2354 						}
2355 					}
2356 				}
2357 				os_releasemutex(plugintable[i].pluginMutex);
2358 			}
2359 
2360 			break;
2361 		}
2362 	}
2363 	os_releasemutex(libMutex);
2364 	return (status);
2365 }
2366 
2367 
IMA_SetFirstBurstLength(IMA_OID lhbaId,IMA_UINT firstBurstLength)2368 IMA_API IMA_STATUS IMA_SetFirstBurstLength(
2369     IMA_OID lhbaId,
2370     IMA_UINT firstBurstLength) {
2371 	IMA_SetFirstBurstLengthFn PassFunc;
2372 	IMA_UINT i;
2373 	IMA_STATUS status;
2374 
2375 	if (number_of_plugins == -1)
2376 		InitLibrary();
2377 
2378 	if (lhbaId.objectType != IMA_OBJECT_TYPE_LHBA &&
2379 	    lhbaId.objectType != IMA_OBJECT_TYPE_TARGET)
2380 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
2381 
2382 	os_obtainmutex(libMutex);
2383 	status = IMA_ERROR_OBJECT_NOT_FOUND;
2384 
2385 	for (i = 0; i < number_of_plugins; i++) {
2386 		if (plugintable[i].ownerId == lhbaId.ownerId) {
2387 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
2388 			if (plugintable[i].hPlugin != NULL) {
2389 				os_obtainmutex(plugintable[i].pluginMutex);
2390 #ifdef WIN32
2391 				PassFunc = (IMA_SetFirstBurstLengthFn)
2392 				    GetProcAddress(plugintable[i].hPlugin,
2393 				    "IMA_SetFirstBurstLength");
2394 #else
2395 				PassFunc = (IMA_SetFirstBurstLengthFn)
2396 				    dlsym(
2397 				    plugintable[i].hPlugin,
2398 				    "IMA_SetFirstBurstLength");
2399 #endif
2400 
2401 				if (PassFunc != NULL) {
2402 					status = PassFunc(
2403 					    lhbaId, firstBurstLength);
2404 				}
2405 				os_releasemutex(plugintable[i].pluginMutex);
2406 			}
2407 
2408 			break;
2409 		}
2410 	}
2411 	os_releasemutex(libMutex);
2412 	return (status);
2413 }
2414 
2415 
IMA_SetMaxBurstLength(IMA_OID lhbaId,IMA_UINT maxBurstLength)2416 IMA_API IMA_STATUS IMA_SetMaxBurstLength(
2417     IMA_OID lhbaId,
2418     IMA_UINT maxBurstLength) {
2419 	IMA_SetMaxBurstLengthFn PassFunc;
2420 	IMA_UINT i;
2421 	IMA_STATUS status;
2422 
2423 	if (number_of_plugins == -1)
2424 		InitLibrary();
2425 
2426 	if (lhbaId.objectType != IMA_OBJECT_TYPE_LHBA &&
2427 	    lhbaId.objectType != IMA_OBJECT_TYPE_TARGET)
2428 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
2429 
2430 	os_obtainmutex(libMutex);
2431 	status = IMA_ERROR_OBJECT_NOT_FOUND;
2432 
2433 	for (i = 0; i < number_of_plugins; i++) {
2434 		if (plugintable[i].ownerId == lhbaId.ownerId) {
2435 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
2436 			if (plugintable[i].hPlugin != NULL) {
2437 				os_obtainmutex(plugintable[i].pluginMutex);
2438 #ifdef WIN32
2439 				PassFunc = (IMA_SetMaxBurstLengthFn)
2440 				    GetProcAddress(plugintable[i].hPlugin,
2441 				    "IMA_SetMaxBurstLength");
2442 #else
2443 				PassFunc = (IMA_SetMaxBurstLengthFn)
2444 				    dlsym(plugintable[i].hPlugin,
2445 				    "IMA_SetMaxBurstLength");
2446 #endif
2447 
2448 				if (PassFunc != NULL) {
2449 					status = PassFunc(
2450 					    lhbaId, maxBurstLength);
2451 				}
2452 				os_releasemutex(plugintable[i].pluginMutex);
2453 			}
2454 
2455 			break;
2456 		}
2457 	}
2458 	os_releasemutex(libMutex);
2459 	return (status);
2460 }
2461 
2462 
IMA_SetMaxRecvDataSegmentLength(IMA_OID lhbaId,IMA_UINT maxRecvDataSegmentLength)2463 IMA_API IMA_STATUS IMA_SetMaxRecvDataSegmentLength(
2464     IMA_OID lhbaId,
2465     IMA_UINT maxRecvDataSegmentLength) {
2466 	IMA_SetMaxRecvDataSegmentLengthFn PassFunc;
2467 	IMA_UINT i;
2468 	IMA_STATUS status;
2469 
2470 	if (number_of_plugins == -1)
2471 		InitLibrary();
2472 
2473 	if (lhbaId.objectType != IMA_OBJECT_TYPE_LHBA &&
2474 	lhbaId.objectType != IMA_OBJECT_TYPE_TARGET)
2475 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
2476 
2477 	os_obtainmutex(libMutex);
2478 	status = IMA_ERROR_OBJECT_NOT_FOUND;
2479 
2480 	for (i = 0; i < number_of_plugins; i++) {
2481 		if (plugintable[i].ownerId == lhbaId.ownerId) {
2482 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
2483 			if (plugintable[i].hPlugin != NULL) {
2484 				os_obtainmutex(plugintable[i].pluginMutex);
2485 #ifdef WIN32
2486 				PassFunc =
2487 				    (IMA_SetMaxRecvDataSegmentLengthFn)
2488 				    GetProcAddress(plugintable[i].hPlugin,
2489 				    "IMA_SetMaxRecvDataSegmentLength");
2490 #else
2491 				PassFunc =
2492 				    (IMA_SetMaxRecvDataSegmentLengthFn)
2493 				    dlsym(plugintable[i].hPlugin,
2494 				    "IMA_SetMaxRecvDataSegmentLength");
2495 #endif
2496 
2497 				if (PassFunc != NULL) {
2498 					status = PassFunc(
2499 					    lhbaId,
2500 					    maxRecvDataSegmentLength);
2501 				}
2502 				os_releasemutex(plugintable[i].pluginMutex);
2503 			}
2504 
2505 			break;
2506 		}
2507 	}
2508 	os_releasemutex(libMutex);
2509 	return (status);
2510 }
2511 
2512 
IMA_GetMaxConnectionsProperties(IMA_OID Oid,IMA_MIN_MAX_VALUE * pProps)2513 IMA_API IMA_STATUS IMA_GetMaxConnectionsProperties(
2514     IMA_OID Oid,
2515     IMA_MIN_MAX_VALUE *pProps) {
2516 	IMA_GetMaxConnectionsPropertiesFn PassFunc;
2517 	IMA_UINT i;
2518 	IMA_STATUS status;
2519 
2520 	if (number_of_plugins == -1)
2521 		InitLibrary();
2522 
2523 	if (pProps == NULL)
2524 		return (IMA_ERROR_INVALID_PARAMETER);
2525 
2526 	if (Oid.objectType != IMA_OBJECT_TYPE_LHBA &&
2527 	    Oid.objectType != IMA_OBJECT_TYPE_TARGET)
2528 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
2529 
2530 	os_obtainmutex(libMutex);
2531 	status = IMA_ERROR_OBJECT_NOT_FOUND;
2532 
2533 	for (i = 0; i < number_of_plugins; i++) {
2534 		if (plugintable[i].ownerId == Oid.ownerId) {
2535 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
2536 			if (plugintable[i].hPlugin != NULL) {
2537 				os_obtainmutex(plugintable[i].pluginMutex);
2538 #ifdef WIN32
2539 				PassFunc =
2540 				    (IMA_GetMaxConnectionsPropertiesFn)
2541 				    GetProcAddress(plugintable[i].hPlugin,
2542 				    "IMA_GetMaxConnectionsProperties");
2543 #else
2544 				PassFunc =
2545 				    (IMA_GetMaxConnectionsPropertiesFn)
2546 				    dlsym(plugintable[i].hPlugin,
2547 				    "IMA_GetMaxConnectionsProperties");
2548 #endif
2549 
2550 				if (PassFunc != NULL) {
2551 					status = PassFunc(Oid, pProps);
2552 				}
2553 				os_releasemutex(plugintable[i].pluginMutex);
2554 			}
2555 
2556 			break;
2557 		}
2558 	}
2559 	os_releasemutex(libMutex);
2560 	return (status);
2561 }
2562 
2563 
IMA_SetMaxConnections(IMA_OID lhbaId,IMA_UINT maxConnections)2564 IMA_API IMA_STATUS IMA_SetMaxConnections(
2565     IMA_OID lhbaId,
2566     IMA_UINT maxConnections) {
2567 	IMA_SetMaxConnectionsFn PassFunc;
2568 	IMA_UINT i;
2569 	IMA_STATUS status;
2570 
2571 	if (number_of_plugins == -1)
2572 		InitLibrary();
2573 
2574 	if (lhbaId.objectType != IMA_OBJECT_TYPE_LHBA &&
2575 	    lhbaId.objectType != IMA_OBJECT_TYPE_TARGET)
2576 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
2577 
2578 	os_obtainmutex(libMutex);
2579 	status = IMA_ERROR_OBJECT_NOT_FOUND;
2580 
2581 	for (i = 0; i < number_of_plugins; i++) {
2582 		if (plugintable[i].ownerId == lhbaId.ownerId) {
2583 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
2584 			if (plugintable[i].hPlugin != NULL) {
2585 				os_obtainmutex(plugintable[i].pluginMutex);
2586 #ifdef WIN32
2587 				PassFunc = (IMA_SetMaxConnectionsFn)
2588 				    GetProcAddress(plugintable[i].hPlugin,
2589 				    "IMA_SetMaxConnections");
2590 #else
2591 				PassFunc = (IMA_SetMaxConnectionsFn)
2592 				    dlsym(plugintable[i].hPlugin,
2593 				    "IMA_SetMaxConnections");
2594 #endif
2595 
2596 				if (PassFunc != NULL) {
2597 					status = PassFunc(
2598 					    lhbaId, maxConnections);
2599 				}
2600 				os_releasemutex(plugintable[i].pluginMutex);
2601 			}
2602 
2603 			break;
2604 		}
2605 	}
2606 	os_releasemutex(libMutex);
2607 	return (status);
2608 }
2609 
2610 
IMA_GetDefaultTime2RetainProperties(IMA_OID lhbaId,IMA_MIN_MAX_VALUE * pProps)2611 IMA_API IMA_STATUS IMA_GetDefaultTime2RetainProperties(
2612     IMA_OID lhbaId,
2613     IMA_MIN_MAX_VALUE *pProps) {
2614 	IMA_GetDefaultTime2RetainPropertiesFn PassFunc;
2615 	IMA_UINT i;
2616 	IMA_STATUS status;
2617 
2618 	if (number_of_plugins == -1)
2619 		InitLibrary();
2620 
2621 	if (pProps == NULL)
2622 		return (IMA_ERROR_INVALID_PARAMETER);
2623 
2624 	if (lhbaId.objectType != IMA_OBJECT_TYPE_LHBA &&
2625 	    lhbaId.objectType != IMA_OBJECT_TYPE_TARGET)
2626 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
2627 
2628 	os_obtainmutex(libMutex);
2629 	status = IMA_ERROR_OBJECT_NOT_FOUND;
2630 
2631 	for (i = 0; i < number_of_plugins; i++) {
2632 		if (plugintable[i].ownerId == lhbaId.ownerId) {
2633 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
2634 			if (plugintable[i].hPlugin != NULL) {
2635 				os_obtainmutex(plugintable[i].pluginMutex);
2636 #ifdef WIN32
2637 				PassFunc =
2638 				    (IMA_GetDefaultTime2RetainPropertiesFn)
2639 				    GetProcAddress(plugintable[i].hPlugin,
2640 				    "IMA_GetDefaultTime2RetainProperties");
2641 #else
2642 				PassFunc =
2643 				    (IMA_GetDefaultTime2RetainPropertiesFn)
2644 				    dlsym(plugintable[i].hPlugin,
2645 				    "IMA_GetDefaultTime2RetainProperties");
2646 #endif
2647 
2648 				if (PassFunc != NULL) {
2649 					status = PassFunc(lhbaId, pProps);
2650 				}
2651 				os_releasemutex(plugintable[i].pluginMutex);
2652 			}
2653 
2654 			break;
2655 		}
2656 	}
2657 	os_releasemutex(libMutex);
2658 	return (status);
2659 }
2660 
2661 
IMA_SetDefaultTime2Retain(IMA_OID lhbaId,IMA_UINT defaultTime2Retain)2662 IMA_API IMA_STATUS IMA_SetDefaultTime2Retain(
2663     IMA_OID lhbaId,
2664     IMA_UINT defaultTime2Retain) {
2665 	IMA_SetDefaultTime2RetainFn PassFunc;
2666 	IMA_UINT i;
2667 	IMA_STATUS status;
2668 
2669 	if (number_of_plugins == -1)
2670 		InitLibrary();
2671 
2672 	if (lhbaId.objectType != IMA_OBJECT_TYPE_LHBA &&
2673 	    lhbaId.objectType != IMA_OBJECT_TYPE_TARGET)
2674 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
2675 
2676 	os_obtainmutex(libMutex);
2677 	status = IMA_ERROR_OBJECT_NOT_FOUND;
2678 
2679 	for (i = 0; i < number_of_plugins; i++) {
2680 		if (plugintable[i].ownerId == lhbaId.ownerId) {
2681 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
2682 			if (plugintable[i].hPlugin != NULL) {
2683 				os_obtainmutex(plugintable[i].pluginMutex);
2684 #ifdef WIN32
2685 				PassFunc =
2686 				    (IMA_SetDefaultTime2RetainFn)
2687 				    GetProcAddress(plugintable[i].hPlugin,
2688 				    "IMA_SetDefaultTime2Retain");
2689 #else
2690 				PassFunc =
2691 				    (IMA_SetDefaultTime2RetainFn)
2692 				    dlsym(plugintable[i].hPlugin,
2693 				    "IMA_SetDefaultTime2Retain");
2694 #endif
2695 
2696 				if (PassFunc != NULL) {
2697 					status = PassFunc(
2698 					    lhbaId, defaultTime2Retain);
2699 				}
2700 				os_releasemutex(plugintable[i].pluginMutex);
2701 			}
2702 
2703 			break;
2704 		}
2705 	}
2706 	os_releasemutex(libMutex);
2707 	return (status);
2708 }
2709 
2710 
IMA_GetDefaultTime2WaitProperties(IMA_OID lhbaId,IMA_MIN_MAX_VALUE * pProps)2711 IMA_API IMA_STATUS IMA_GetDefaultTime2WaitProperties(
2712     IMA_OID lhbaId,
2713     IMA_MIN_MAX_VALUE *pProps) {
2714 	IMA_GetDefaultTime2WaitPropertiesFn PassFunc;
2715 	IMA_UINT i;
2716 	IMA_STATUS status;
2717 
2718 	if (number_of_plugins == -1)
2719 		InitLibrary();
2720 
2721 	if (pProps == NULL)
2722 		return (IMA_ERROR_INVALID_PARAMETER);
2723 
2724 	if (lhbaId.objectType != IMA_OBJECT_TYPE_LHBA &&
2725 	    lhbaId.objectType != IMA_OBJECT_TYPE_TARGET)
2726 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
2727 
2728 	os_obtainmutex(libMutex);
2729 	status = IMA_ERROR_OBJECT_NOT_FOUND;
2730 
2731 	for (i = 0; i < number_of_plugins; i++) {
2732 		if (plugintable[i].ownerId == lhbaId.ownerId) {
2733 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
2734 			if (plugintable[i].hPlugin != NULL) {
2735 				os_obtainmutex(plugintable[i].pluginMutex);
2736 #ifdef WIN32
2737 				PassFunc =
2738 				    (IMA_GetDefaultTime2WaitPropertiesFn)
2739 				    GetProcAddress(plugintable[i].hPlugin,
2740 				    "IMA_GetDefaultTime2WaitProperties");
2741 #else
2742 				PassFunc =
2743 				    (IMA_GetDefaultTime2WaitPropertiesFn)
2744 				    dlsym(plugintable[i].hPlugin,
2745 				    "IMA_GetDefaultTime2WaitProperties");
2746 #endif
2747 
2748 				if (PassFunc != NULL) {
2749 					status = PassFunc(lhbaId, pProps);
2750 				}
2751 				os_releasemutex(plugintable[i].pluginMutex);
2752 			}
2753 
2754 			break;
2755 		}
2756 	}
2757 	os_releasemutex(libMutex);
2758 	return (status);
2759 }
2760 
2761 
IMA_SetDefaultTime2Wait(IMA_OID lhbaId,IMA_UINT defaultTime2Wait)2762 IMA_API IMA_STATUS IMA_SetDefaultTime2Wait(
2763     IMA_OID lhbaId,
2764     IMA_UINT defaultTime2Wait) {
2765 	IMA_SetDefaultTime2WaitFn PassFunc;
2766 	IMA_UINT i;
2767 	IMA_STATUS status;
2768 
2769 	if (number_of_plugins == -1)
2770 		InitLibrary();
2771 
2772 	if (lhbaId.objectType != IMA_OBJECT_TYPE_LHBA &&
2773 	    lhbaId.objectType != IMA_OBJECT_TYPE_TARGET)
2774 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
2775 
2776 	os_obtainmutex(libMutex);
2777 	status = IMA_ERROR_OBJECT_NOT_FOUND;
2778 
2779 	for (i = 0; i < number_of_plugins; i++) {
2780 		if (plugintable[i].ownerId == lhbaId.ownerId) {
2781 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
2782 			if (plugintable[i].hPlugin != NULL) {
2783 				os_obtainmutex(plugintable[i].pluginMutex);
2784 #ifdef WIN32
2785 				PassFunc =
2786 				    (IMA_SetDefaultTime2WaitFn)
2787 				    GetProcAddress(plugintable[i].hPlugin,
2788 				    "IMA_SetDefaultTime2Wait");
2789 #else
2790 				PassFunc =
2791 				    (IMA_SetDefaultTime2WaitFn)
2792 				    dlsym(plugintable[i].hPlugin,
2793 				    "IMA_SetDefaultTime2Wait");
2794 #endif
2795 
2796 				if (PassFunc != NULL) {
2797 					status = PassFunc(
2798 					    lhbaId, defaultTime2Wait);
2799 				}
2800 				os_releasemutex(plugintable[i].pluginMutex);
2801 			}
2802 
2803 			break;
2804 		}
2805 	}
2806 	os_releasemutex(libMutex);
2807 	return (status);
2808 }
2809 
2810 
IMA_GetMaxOutstandingR2TProperties(IMA_OID Oid,IMA_MIN_MAX_VALUE * pProps)2811 IMA_API IMA_STATUS IMA_GetMaxOutstandingR2TProperties(
2812     IMA_OID Oid,
2813     IMA_MIN_MAX_VALUE *pProps) {
2814 	IMA_GetMaxOutstandingR2TPropertiesFn PassFunc;
2815 	IMA_UINT i;
2816 	IMA_STATUS status;
2817 
2818 	if (number_of_plugins == -1)
2819 		InitLibrary();
2820 
2821 	if (pProps == NULL)
2822 		return (IMA_ERROR_INVALID_PARAMETER);
2823 
2824 	if (Oid.objectType != IMA_OBJECT_TYPE_LHBA &&
2825 	    Oid.objectType != IMA_OBJECT_TYPE_TARGET)
2826 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
2827 
2828 	os_obtainmutex(libMutex);
2829 	status = IMA_ERROR_OBJECT_NOT_FOUND;
2830 
2831 	for (i = 0; i < number_of_plugins; i++) {
2832 		if (plugintable[i].ownerId == Oid.ownerId) {
2833 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
2834 			if (plugintable[i].hPlugin != NULL) {
2835 				os_obtainmutex(plugintable[i].pluginMutex);
2836 #ifdef WIN32
2837 				PassFunc =
2838 				    (IMA_GetMaxOutstandingR2TPropertiesFn)
2839 				    GetProcAddress(plugintable[i].hPlugin,
2840 				    "IMA_GetMaxOutstandingR2TProperties");
2841 #else
2842 				PassFunc =
2843 				    (IMA_GetMaxOutstandingR2TPropertiesFn)
2844 				    dlsym(plugintable[i].hPlugin,
2845 				    "IMA_GetMaxOutstandingR2TProperties");
2846 #endif
2847 
2848 				if (PassFunc != NULL) {
2849 					status = PassFunc(Oid, pProps);
2850 				}
2851 				os_releasemutex(plugintable[i].pluginMutex);
2852 			}
2853 
2854 			break;
2855 		}
2856 	}
2857 	os_releasemutex(libMutex);
2858 	return (status);
2859 }
2860 
2861 
IMA_SetMaxOutstandingR2T(IMA_OID lhbaId,IMA_UINT maxOutstandingR2T)2862 IMA_API IMA_STATUS IMA_SetMaxOutstandingR2T(
2863     IMA_OID lhbaId,
2864     IMA_UINT maxOutstandingR2T) {
2865 	IMA_SetMaxOutstandingR2TFn PassFunc;
2866 	IMA_UINT i;
2867 	IMA_STATUS status;
2868 
2869 	if (number_of_plugins == -1)
2870 		InitLibrary();
2871 
2872 	if (lhbaId.objectType != IMA_OBJECT_TYPE_LHBA &&
2873 	    lhbaId.objectType != IMA_OBJECT_TYPE_TARGET)
2874 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
2875 
2876 	os_obtainmutex(libMutex);
2877 	status = IMA_ERROR_OBJECT_NOT_FOUND;
2878 
2879 	for (i = 0; i < number_of_plugins; i++) {
2880 		if (plugintable[i].ownerId == lhbaId.ownerId) {
2881 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
2882 			if (plugintable[i].hPlugin != NULL) {
2883 				os_obtainmutex(plugintable[i].pluginMutex);
2884 #ifdef WIN32
2885 				PassFunc =
2886 				    (IMA_SetMaxOutstandingR2TFn)
2887 				    GetProcAddress(plugintable[i].hPlugin,
2888 				    "IMA_SetMaxOutstandingR2T");
2889 #else
2890 				PassFunc =
2891 				    (IMA_SetMaxOutstandingR2TFn)
2892 				    dlsym(plugintable[i].hPlugin,
2893 				    "IMA_SetMaxOutstandingR2T");
2894 #endif
2895 
2896 				if (PassFunc != NULL) {
2897 					status = PassFunc(
2898 					    lhbaId, maxOutstandingR2T);
2899 				}
2900 				os_releasemutex(plugintable[i].pluginMutex);
2901 			}
2902 
2903 			break;
2904 		}
2905 	}
2906 	os_releasemutex(libMutex);
2907 	return (status);
2908 }
2909 
2910 
IMA_GetErrorRecoveryLevelProperties(IMA_OID Oid,IMA_MIN_MAX_VALUE * pProps)2911 IMA_API IMA_STATUS IMA_GetErrorRecoveryLevelProperties(
2912     IMA_OID Oid,
2913     IMA_MIN_MAX_VALUE *pProps) {
2914 	IMA_GetMaxOutstandingR2TPropertiesFn PassFunc;
2915 	IMA_UINT i;
2916 	IMA_STATUS status;
2917 
2918 	if (number_of_plugins == -1)
2919 		InitLibrary();
2920 
2921 	if (pProps == NULL)
2922 		return (IMA_ERROR_INVALID_PARAMETER);
2923 
2924 	if (Oid.objectType != IMA_OBJECT_TYPE_LHBA &&
2925 	    Oid.objectType != IMA_OBJECT_TYPE_TARGET)
2926 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
2927 
2928 	os_obtainmutex(libMutex);
2929 	status = IMA_ERROR_OBJECT_NOT_FOUND;
2930 
2931 	for (i = 0; i < number_of_plugins; i++) {
2932 		if (plugintable[i].ownerId == Oid.ownerId) {
2933 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
2934 			if (plugintable[i].hPlugin != NULL) {
2935 				os_obtainmutex(plugintable[i].pluginMutex);
2936 #ifdef WIN32
2937 				PassFunc =
2938 				    (IMA_GetErrorRecoveryLevelPropertiesFn)
2939 				    GetProcAddress(plugintable[i].hPlugin,
2940 				    "IMA_GetErrorRecoveryLevelProperties");
2941 #else
2942 				PassFunc =
2943 				    (IMA_GetErrorRecoveryLevelPropertiesFn)
2944 				    dlsym(plugintable[i].hPlugin,
2945 				    "IMA_GetErrorRecoveryLevelProperties");
2946 #endif
2947 
2948 				if (PassFunc != NULL) {
2949 					status = PassFunc(Oid, pProps);
2950 				}
2951 				os_releasemutex(plugintable[i].pluginMutex);
2952 			}
2953 
2954 			break;
2955 		}
2956 	}
2957 	os_releasemutex(libMutex);
2958 	return (status);
2959 }
2960 
2961 
IMA_SetErrorRecoveryLevel(IMA_OID Oid,IMA_UINT errorRecoveryLevel)2962 IMA_API IMA_STATUS IMA_SetErrorRecoveryLevel(
2963     IMA_OID Oid,
2964     IMA_UINT errorRecoveryLevel) {
2965 	IMA_SetErrorRecoveryLevelFn PassFunc;
2966 	IMA_UINT i;
2967 	IMA_STATUS status;
2968 
2969 	if (number_of_plugins == -1)
2970 		InitLibrary();
2971 
2972 	if (Oid.objectType != IMA_OBJECT_TYPE_LHBA &&
2973 	    Oid.objectType != IMA_OBJECT_TYPE_TARGET)
2974 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
2975 
2976 	os_obtainmutex(libMutex);
2977 	status = IMA_ERROR_OBJECT_NOT_FOUND;
2978 
2979 	for (i = 0; i < number_of_plugins; i++) {
2980 		if (plugintable[i].ownerId == Oid.ownerId) {
2981 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
2982 			if (plugintable[i].hPlugin != NULL) {
2983 				os_obtainmutex(plugintable[i].pluginMutex);
2984 #ifdef WIN32
2985 				PassFunc =
2986 				    (IMA_SetErrorRecoveryLevelFn)
2987 				    GetProcAddress(plugintable[i].hPlugin,
2988 				    "IMA_SetErrorRecoveryLevel");
2989 #else
2990 				PassFunc =
2991 				    (IMA_SetErrorRecoveryLevelFn)
2992 				    dlsym(plugintable[i].hPlugin,
2993 				    "IMA_SetErrorRecoveryLevel");
2994 #endif
2995 
2996 				if (PassFunc != NULL) {
2997 					status = PassFunc(
2998 					    Oid, errorRecoveryLevel);
2999 				}
3000 				os_releasemutex(plugintable[i].pluginMutex);
3001 			}
3002 
3003 			break;
3004 		}
3005 	}
3006 	os_releasemutex(libMutex);
3007 	return (status);
3008 }
3009 
3010 
IMA_GetInitialR2TProperties(IMA_OID Oid,IMA_BOOL_VALUE * pProps)3011 IMA_API IMA_STATUS IMA_GetInitialR2TProperties(
3012     IMA_OID Oid,
3013     IMA_BOOL_VALUE *pProps) {
3014 	IMA_GetInitialR2TPropertiesFn PassFunc;
3015 	IMA_UINT i;
3016 	IMA_STATUS status;
3017 
3018 	if (number_of_plugins == -1)
3019 		InitLibrary();
3020 
3021 	if (pProps == NULL)
3022 		return (IMA_ERROR_INVALID_PARAMETER);
3023 
3024 	if (Oid.objectType != IMA_OBJECT_TYPE_LHBA &&
3025 	    Oid.objectType != IMA_OBJECT_TYPE_TARGET)
3026 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
3027 
3028 	os_obtainmutex(libMutex);
3029 	status = IMA_ERROR_OBJECT_NOT_FOUND;
3030 
3031 	for (i = 0; i < number_of_plugins; i++) {
3032 		if (plugintable[i].ownerId == Oid.ownerId) {
3033 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
3034 			if (plugintable[i].hPlugin != NULL) {
3035 				os_obtainmutex(plugintable[i].pluginMutex);
3036 #ifdef WIN32
3037 				PassFunc =
3038 				    (IMA_GetInitialR2TPropertiesFn)
3039 				    GetProcAddress(plugintable[i].hPlugin,
3040 				    "IMA_GetInitialR2TProperties");
3041 #else
3042 				PassFunc =
3043 				    (IMA_GetInitialR2TPropertiesFn)
3044 				    dlsym(plugintable[i].hPlugin,
3045 				    "IMA_GetInitialR2TProperties");
3046 #endif
3047 
3048 				if (PassFunc != NULL) {
3049 					status = PassFunc(Oid, pProps);
3050 				}
3051 				os_releasemutex(plugintable[i].pluginMutex);
3052 			}
3053 
3054 			break;
3055 		}
3056 	}
3057 	os_releasemutex(libMutex);
3058 	return (status);
3059 }
3060 
3061 
IMA_SetInitialR2T(IMA_OID Oid,IMA_BOOL initialR2T)3062 IMA_API IMA_STATUS IMA_SetInitialR2T(
3063     IMA_OID Oid,
3064     IMA_BOOL initialR2T)
3065 {
3066 	IMA_SetInitialR2TFn PassFunc;
3067 	IMA_UINT i;
3068 	IMA_STATUS status;
3069 
3070 	if (number_of_plugins == -1)
3071 		InitLibrary();
3072 
3073 	if (initialR2T != IMA_TRUE &&
3074 	    initialR2T != IMA_FALSE)
3075 		return (IMA_ERROR_INVALID_PARAMETER);
3076 
3077 	if (Oid.objectType != IMA_OBJECT_TYPE_LHBA &&
3078 	    Oid.objectType != IMA_OBJECT_TYPE_TARGET)
3079 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
3080 
3081 	os_obtainmutex(libMutex);
3082 	status = IMA_ERROR_OBJECT_NOT_FOUND;
3083 
3084 	for (i = 0; i < number_of_plugins; i++) {
3085 		if (plugintable[i].ownerId == Oid.ownerId) {
3086 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
3087 			if (plugintable[i].hPlugin != NULL) {
3088 				os_obtainmutex(plugintable[i].pluginMutex);
3089 #ifdef WIN32
3090 				PassFunc =
3091 				    (IMA_SetInitialR2TFn) GetProcAddress(
3092 				    plugintable[i].hPlugin,
3093 				    "IMA_SetInitialR2T");
3094 #else
3095 				PassFunc =
3096 				    (IMA_SetInitialR2TFn)
3097 				    dlsym(plugintable[i].hPlugin,
3098 				    "IMA_SetInitialR2T");
3099 #endif
3100 
3101 				if (PassFunc != NULL) {
3102 					status = PassFunc(Oid, initialR2T);
3103 				}
3104 				os_releasemutex(plugintable[i].pluginMutex);
3105 			}
3106 
3107 			break;
3108 		}
3109 	}
3110 	os_releasemutex(libMutex);
3111 	return (status);
3112 }
3113 
3114 
IMA_GetImmediateDataProperties(IMA_OID Oid,IMA_BOOL_VALUE * pProps)3115 IMA_API IMA_STATUS IMA_GetImmediateDataProperties(
3116     IMA_OID Oid,
3117     IMA_BOOL_VALUE *pProps) {
3118 	IMA_GetImmediateDataPropertiesFn PassFunc;
3119 	IMA_UINT i;
3120 	IMA_STATUS status;
3121 
3122 	if (number_of_plugins == -1)
3123 		InitLibrary();
3124 
3125 	if (pProps == NULL)
3126 		return (IMA_ERROR_INVALID_PARAMETER);
3127 
3128 	if (Oid.objectType != IMA_OBJECT_TYPE_LHBA &&
3129 	    Oid.objectType != IMA_OBJECT_TYPE_TARGET)
3130 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
3131 
3132 	os_obtainmutex(libMutex);
3133 	status = IMA_ERROR_OBJECT_NOT_FOUND;
3134 
3135 	for (i = 0; i < number_of_plugins; i++) {
3136 		if (plugintable[i].ownerId == Oid.ownerId) {
3137 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
3138 			if (plugintable[i].hPlugin != NULL) {
3139 				os_obtainmutex(plugintable[i].pluginMutex);
3140 #ifdef WIN32
3141 				PassFunc =
3142 				    (IMA_GetImmediateDataPropertiesFn)
3143 				    GetProcAddress(plugintable[i].hPlugin,
3144 				    "IMA_GetImmediateDataProperties");
3145 #else
3146 				PassFunc =
3147 				    (IMA_GetImmediateDataPropertiesFn)
3148 				    dlsym(plugintable[i].hPlugin,
3149 				    "IMA_GetImmediateDataProperties");
3150 #endif
3151 
3152 				if (PassFunc != NULL) {
3153 					status = PassFunc(Oid, pProps);
3154 				}
3155 				os_releasemutex(plugintable[i].pluginMutex);
3156 			}
3157 
3158 			break;
3159 		}
3160 	}
3161 	os_releasemutex(libMutex);
3162 	return (status);
3163 }
3164 
3165 
IMA_SetImmediateData(IMA_OID Oid,IMA_BOOL immediateData)3166 IMA_API IMA_STATUS IMA_SetImmediateData(
3167     IMA_OID Oid,
3168     IMA_BOOL immediateData) {
3169 	IMA_SetImmediateDataFn PassFunc;
3170 	IMA_UINT i;
3171 	IMA_STATUS status;
3172 
3173 	if (number_of_plugins == -1)
3174 		InitLibrary();
3175 
3176 	if (immediateData != IMA_TRUE &&
3177 	    immediateData != IMA_FALSE)
3178 		return (IMA_ERROR_INVALID_PARAMETER);
3179 
3180 	if (Oid.objectType != IMA_OBJECT_TYPE_LHBA &&
3181 	    Oid.objectType != IMA_OBJECT_TYPE_TARGET)
3182 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
3183 
3184 	os_obtainmutex(libMutex);
3185 	status = IMA_ERROR_OBJECT_NOT_FOUND;
3186 
3187 	for (i = 0; i < number_of_plugins; i++) {
3188 		if (plugintable[i].ownerId == Oid.ownerId) {
3189 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
3190 			if (plugintable[i].hPlugin != NULL) {
3191 				os_obtainmutex(plugintable[i].pluginMutex);
3192 #ifdef WIN32
3193 				PassFunc =
3194 				    (IMA_SetImmediateDataFn)
3195 				    GetProcAddress(plugintable[i].hPlugin,
3196 				    "IMA_SetImmediateData");
3197 #else
3198 				PassFunc =
3199 				    (IMA_SetImmediateDataFn)
3200 				    dlsym(plugintable[i].hPlugin,
3201 				    "IMA_SetImmediateData");
3202 #endif
3203 
3204 				if (PassFunc != NULL) {
3205 					status = PassFunc(Oid, immediateData);
3206 				}
3207 				os_releasemutex(plugintable[i].pluginMutex);
3208 			}
3209 
3210 			break;
3211 		}
3212 	}
3213 	os_releasemutex(libMutex);
3214 	return (status);
3215 }
3216 
3217 
IMA_GetDataPduInOrderProperties(IMA_OID Oid,IMA_BOOL_VALUE * pProps)3218 IMA_API IMA_STATUS IMA_GetDataPduInOrderProperties(
3219     IMA_OID Oid,
3220     IMA_BOOL_VALUE *pProps) {
3221 	IMA_GetDataPduInOrderPropertiesFn PassFunc;
3222 	IMA_UINT i;
3223 	IMA_STATUS status;
3224 
3225 	if (number_of_plugins == -1)
3226 		InitLibrary();
3227 
3228 	if (pProps == NULL)
3229 		return (IMA_ERROR_INVALID_PARAMETER);
3230 
3231 	if (Oid.objectType != IMA_OBJECT_TYPE_LHBA &&
3232 	    Oid.objectType != IMA_OBJECT_TYPE_TARGET)
3233 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
3234 
3235 	os_obtainmutex(libMutex);
3236 	status = IMA_ERROR_OBJECT_NOT_FOUND;
3237 
3238 	for (i = 0; i < number_of_plugins; i++) {
3239 		if (plugintable[i].ownerId == Oid.ownerId) {
3240 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
3241 			if (plugintable[i].hPlugin != NULL) {
3242 				os_obtainmutex(plugintable[i].pluginMutex);
3243 #ifdef WIN32
3244 				PassFunc =
3245 				    (IMA_GetDataPduInOrderPropertiesFn)
3246 				    GetProcAddress(plugintable[i].hPlugin,
3247 				    "IMA_GetDataPduInOrderProperties");
3248 #else
3249 				PassFunc =
3250 				    (IMA_GetDataPduInOrderPropertiesFn)
3251 				    dlsym(plugintable[i].hPlugin,
3252 				    "IMA_GetDataPduInOrderProperties");
3253 #endif
3254 
3255 				if (PassFunc != NULL) {
3256 					status = PassFunc(Oid, pProps);
3257 				}
3258 				os_releasemutex(plugintable[i].pluginMutex);
3259 			}
3260 
3261 			break;
3262 		}
3263 	}
3264 	os_releasemutex(libMutex);
3265 	return (status);
3266 }
3267 
3268 
IMA_SetDataPduInOrder(IMA_OID Oid,IMA_BOOL dataPduInOrder)3269 IMA_API IMA_STATUS IMA_SetDataPduInOrder(
3270     IMA_OID Oid,
3271     IMA_BOOL dataPduInOrder) {
3272 	IMA_SetDataPduInOrderFn PassFunc;
3273 	IMA_UINT i;
3274 	IMA_STATUS status;
3275 
3276 	if (number_of_plugins == -1)
3277 		InitLibrary();
3278 
3279 	if (dataPduInOrder != IMA_TRUE &&
3280 	    dataPduInOrder != IMA_FALSE)
3281 		return (IMA_ERROR_INVALID_PARAMETER);
3282 
3283 	if (Oid.objectType != IMA_OBJECT_TYPE_LHBA &&
3284 	    Oid.objectType != IMA_OBJECT_TYPE_TARGET)
3285 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
3286 
3287 	os_obtainmutex(libMutex);
3288 	status = IMA_ERROR_OBJECT_NOT_FOUND;
3289 
3290 	for (i = 0; i < number_of_plugins; i++) {
3291 		if (plugintable[i].ownerId == Oid.ownerId) {
3292 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
3293 			if (plugintable[i].hPlugin != NULL) {
3294 				os_obtainmutex(plugintable[i].pluginMutex);
3295 #ifdef WIN32
3296 				PassFunc =
3297 				    (IMA_SetDataPduInOrderFn)
3298 				    GetProcAddress(plugintable[i].hPlugin,
3299 				    "IMA_SetDataPduInOrder");
3300 #else
3301 				PassFunc =
3302 				    (IMA_SetDataPduInOrderFn)
3303 				    dlsym(plugintable[i].hPlugin,
3304 				    "IMA_SetDataPduInOrder");
3305 #endif
3306 
3307 				if (PassFunc != NULL) {
3308 					status = PassFunc(Oid, dataPduInOrder);
3309 				}
3310 				os_releasemutex(plugintable[i].pluginMutex);
3311 			}
3312 
3313 			break;
3314 		}
3315 	}
3316 	os_releasemutex(libMutex);
3317 	return (status);
3318 }
3319 
3320 
IMA_GetDataSequenceInOrderProperties(IMA_OID Oid,IMA_BOOL_VALUE * pProps)3321 IMA_API IMA_STATUS IMA_GetDataSequenceInOrderProperties(
3322     IMA_OID Oid,
3323     IMA_BOOL_VALUE *pProps) {
3324 	IMA_GetDataSequenceInOrderPropertiesFn PassFunc;
3325 	IMA_UINT i;
3326 	IMA_STATUS status;
3327 
3328 	if (number_of_plugins == -1)
3329 		InitLibrary();
3330 
3331 	if (pProps == NULL)
3332 		return (IMA_ERROR_INVALID_PARAMETER);
3333 
3334 	if (Oid.objectType != IMA_OBJECT_TYPE_LHBA &&
3335 	    Oid.objectType != IMA_OBJECT_TYPE_TARGET)
3336 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
3337 
3338 	os_obtainmutex(libMutex);
3339 	status = IMA_ERROR_OBJECT_NOT_FOUND;
3340 
3341 	for (i = 0; i < number_of_plugins; i++) {
3342 		if (plugintable[i].ownerId == Oid.ownerId) {
3343 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
3344 			if (plugintable[i].hPlugin != NULL) {
3345 				os_obtainmutex(plugintable[i].pluginMutex);
3346 #ifdef WIN32
3347 				PassFunc =
3348 				    (IMA_GetDataSequenceInOrderPropertiesFn)
3349 				    GetProcAddress(plugintable[i].hPlugin,
3350 				    "IMA_GetDataSequenceInOrderProperties");
3351 #else
3352 				PassFunc =
3353 				    (IMA_GetDataSequenceInOrderPropertiesFn)
3354 				    dlsym(plugintable[i].hPlugin,
3355 				    "IMA_GetDataSequenceInOrderProperties");
3356 #endif
3357 
3358 				if (PassFunc != NULL) {
3359 					status = PassFunc(Oid, pProps);
3360 				}
3361 				os_releasemutex(plugintable[i].pluginMutex);
3362 			}
3363 
3364 			break;
3365 		}
3366 	}
3367 	os_releasemutex(libMutex);
3368 	return (status);
3369 }
3370 
3371 
IMA_SetDataSequenceInOrder(IMA_OID Oid,IMA_BOOL dataSequenceInOrder)3372 IMA_API IMA_STATUS IMA_SetDataSequenceInOrder(
3373     IMA_OID Oid,
3374     IMA_BOOL dataSequenceInOrder) {
3375 	IMA_SetDataSequenceInOrderFn PassFunc;
3376 	IMA_UINT i;
3377 	IMA_STATUS status;
3378 
3379 	if (number_of_plugins == -1)
3380 		InitLibrary();
3381 
3382 	if (dataSequenceInOrder != IMA_TRUE &&
3383 	    dataSequenceInOrder != IMA_FALSE)
3384 		return (IMA_ERROR_INVALID_PARAMETER);
3385 
3386 	if (Oid.objectType != IMA_OBJECT_TYPE_LHBA &&
3387 	    Oid.objectType != IMA_OBJECT_TYPE_TARGET)
3388 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
3389 
3390 	os_obtainmutex(libMutex);
3391 	status = IMA_ERROR_OBJECT_NOT_FOUND;
3392 
3393 	for (i = 0; i < number_of_plugins; i++) {
3394 		if (plugintable[i].ownerId == Oid.ownerId) {
3395 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
3396 			if (plugintable[i].hPlugin != NULL) {
3397 				os_obtainmutex(plugintable[i].pluginMutex);
3398 #ifdef WIN32
3399 				PassFunc =
3400 				    (IMA_SetDataSequenceInOrderFn)
3401 				    GetProcAddress(plugintable[i].hPlugin,
3402 				    "IMA_SetDataSequenceInOrder");
3403 #else
3404 				PassFunc =
3405 				    (IMA_SetDataSequenceInOrderFn)
3406 				    dlsym(plugintable[i].hPlugin,
3407 				    "IMA_SetDataSequenceInOrder");
3408 #endif
3409 
3410 				if (PassFunc != NULL) {
3411 					status = PassFunc(
3412 					    Oid, dataSequenceInOrder);
3413 				}
3414 				os_releasemutex(plugintable[i].pluginMutex);
3415 			}
3416 
3417 			break;
3418 		}
3419 	}
3420 	os_releasemutex(libMutex);
3421 	return (status);
3422 }
3423 
3424 
IMA_SetStatisticsCollection(IMA_OID Oid,IMA_BOOL enableStatisticsCollection)3425 IMA_API IMA_STATUS IMA_SetStatisticsCollection(
3426     IMA_OID Oid,
3427     IMA_BOOL enableStatisticsCollection) {
3428 	IMA_SetStatisticsCollectionFn PassFunc;
3429 	IMA_UINT i;
3430 	IMA_STATUS status;
3431 
3432 	if (number_of_plugins == -1)
3433 		InitLibrary();
3434 
3435 	if (enableStatisticsCollection != IMA_TRUE &&
3436 	    enableStatisticsCollection != IMA_FALSE)
3437 		return (IMA_ERROR_INVALID_PARAMETER);
3438 
3439 	if (Oid.objectType != IMA_OBJECT_TYPE_PHBA &&
3440 	    Oid.objectType != IMA_OBJECT_TYPE_TARGET)
3441 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
3442 
3443 	os_obtainmutex(libMutex);
3444 	status = IMA_ERROR_OBJECT_NOT_FOUND;
3445 
3446 	for (i = 0; i < number_of_plugins; i++) {
3447 		if (plugintable[i].ownerId == Oid.ownerId) {
3448 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
3449 			if (plugintable[i].hPlugin != NULL) {
3450 				os_obtainmutex(plugintable[i].pluginMutex);
3451 #ifdef WIN32
3452 				PassFunc =
3453 				    (IMA_SetStatisticsCollectionFn)
3454 				    GetProcAddress(plugintable[i].hPlugin,
3455 				    "IMA_SetStatisticsCollection");
3456 #else
3457 				PassFunc =
3458 				    (IMA_SetStatisticsCollectionFn)
3459 				    dlsym(plugintable[i].hPlugin,
3460 				    "IMA_SetStatisticsCollection");
3461 #endif
3462 
3463 				if (PassFunc != NULL) {
3464 					status = PassFunc(
3465 					Oid, enableStatisticsCollection);
3466 				}
3467 				os_releasemutex(plugintable[i].pluginMutex);
3468 			}
3469 
3470 			break;
3471 		}
3472 	}
3473 	os_releasemutex(libMutex);
3474 	return (status);
3475 }
3476 
3477 
IMA_GetNetworkPortStatus(IMA_OID portOid,IMA_NETWORK_PORT_STATUS * pStatus)3478 IMA_API IMA_STATUS IMA_GetNetworkPortStatus(
3479     IMA_OID portOid,
3480     IMA_NETWORK_PORT_STATUS *pStatus) {
3481 	IMA_GetNetworkPortStatusFn PassFunc;
3482 	IMA_UINT i;
3483 	IMA_STATUS status;
3484 
3485 	if (number_of_plugins == -1)
3486 		InitLibrary();
3487 
3488 	if (pStatus == NULL)
3489 		return (IMA_ERROR_INVALID_PARAMETER);
3490 
3491 	if (portOid.objectType != IMA_OBJECT_TYPE_PNP &&
3492 	    portOid.objectType != IMA_OBJECT_TYPE_LNP)
3493 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
3494 
3495 	os_obtainmutex(libMutex);
3496 	status = IMA_ERROR_OBJECT_NOT_FOUND;
3497 
3498 	for (i = 0; i < number_of_plugins; i++) {
3499 		if (plugintable[i].ownerId == portOid.ownerId) {
3500 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
3501 			if (plugintable[i].hPlugin != NULL) {
3502 				os_obtainmutex(plugintable[i].pluginMutex);
3503 #ifdef WIN32
3504 				PassFunc =
3505 				    (IMA_GetNetworkPortStatusFn)
3506 				    GetProcAddress(plugintable[i].hPlugin,
3507 				    "IMA_GetNetworkPortStatus");
3508 #else
3509 				PassFunc =
3510 				    (IMA_GetNetworkPortStatusFn)
3511 				    dlsym(plugintable[i].hPlugin,
3512 				    "IMA_GetNetworkPortStatus");
3513 #endif
3514 
3515 				if (PassFunc != NULL) {
3516 					status = PassFunc(portOid, pStatus);
3517 				}
3518 				os_releasemutex(plugintable[i].pluginMutex);
3519 			}
3520 
3521 			break;
3522 		}
3523 	}
3524 	os_releasemutex(libMutex);
3525 	return (status);
3526 }
3527 
3528 
IMA_GetTargetOidList(IMA_OID Oid,IMA_OID_LIST ** ppList)3529 IMA_API IMA_STATUS IMA_GetTargetOidList(
3530     IMA_OID Oid,
3531     IMA_OID_LIST **ppList) {
3532 	IMA_GetTargetOidListFn PassFunc;
3533 	IMA_FreeMemoryFn FreeFunc;
3534 	IMA_UINT i;
3535 	IMA_STATUS status;
3536 
3537 	if (number_of_plugins == -1)
3538 		InitLibrary();
3539 
3540 	if (ppList == NULL)
3541 		return (IMA_ERROR_INVALID_PARAMETER);
3542 
3543 	if (Oid.objectType != IMA_OBJECT_TYPE_LHBA &&
3544 	    Oid.objectType != IMA_OBJECT_TYPE_LNP)
3545 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
3546 
3547 	os_obtainmutex(libMutex);
3548 	status = IMA_ERROR_OBJECT_NOT_FOUND;
3549 
3550 	for (i = 0; i < number_of_plugins; i++) {
3551 		if (plugintable[i].ownerId == Oid.ownerId) {
3552 			status = IMA_ERROR_UNEXPECTED_OS_ERROR;
3553 			if (plugintable[i].hPlugin != NULL) {
3554 				os_obtainmutex(plugintable[i].pluginMutex);
3555 #ifdef WIN32
3556 				PassFunc =
3557 				    (IMA_GetTargetOidListFn)
3558 				    GetProcAddress(plugintable[i].hPlugin,
3559 				    "IMA_GetTargetOidList");
3560 #else
3561 				PassFunc =
3562 				    (IMA_GetTargetOidListFn)
3563 				    dlsym(plugintable[i].hPlugin,
3564 				    "IMA_GetTargetOidList");
3565 #endif