mod->cryptokiVersion = info.cryptokiVersion;
SECMOD_LoadPKCS11Module(SECMODModule *mod) {    PRLibrary *library = NULL;    CK_C_GetFunctionList entry = NULL;    char * full_name;    CK_INFO info;    CK_ULONG slotCount = 0;    SECStatus rv;    PRBool alreadyLoaded = PR_FALSE;    if (mod->loaded) return SECSuccess;    /* intenal modules get loaded from their internal list */    if (mod->internal) {	/* internal, statically get the C_GetFunctionList function */	if (mod->isFIPS) {	    entry = (CK_C_GetFunctionList) FC_GetFunctionList;	} else {	    entry = (CK_C_GetFunctionList) NSC_GetFunctionList;	}	if (mod->isModuleDB) {	    mod->moduleDBFunc = (void *) NSC_ModuleDBFunc;	}	if (mod->moduleDBOnly) {	    mod->loaded = PR_TRUE;	    return SECSuccess;	}    } else {	/* Not internal, load the DLL and look up C_GetFunctionList */	if (mod->dllName == NULL) {	    return SECFailure;	}#ifdef notdef	/* look up the library name */	full_name = PR_GetLibraryName(PR_GetLibraryPath(),mod->dllName);	if (full_name == NULL) {	    return SECFailure;	}#else	full_name = PORT_Strdup(mod->dllName);#endif	/* load the library. If this succeeds, then we have to remember to	 * unload the library if anything goes wrong from here on out...	 */	library = PR_LoadLibrary(full_name);	mod->library = (void *)library;	PORT_Free(full_name);	if (library == NULL) {	    return SECFailure;	}	/*	 * now we need to get the entry point to find the function pointers	 */	if (!mod->moduleDBOnly) {	    entry = (CK_C_GetFunctionList)			PR_FindSymbol(library, "C_GetFunctionList");	}	if (mod->isModuleDB) {	    mod->moduleDBFunc = (void *)			PR_FindSymbol(library, "NSS_ReturnModuleSpecData");	}	if (mod->moduleDBFunc == NULL) mod->isModuleDB = PR_FALSE;	if (entry == NULL) {	    if (mod->isModuleDB) {		mod->loaded = PR_TRUE;		mod->moduleDBOnly = PR_TRUE;		return SECSuccess;	    }	    PR_UnloadLibrary(library);	    return SECFailure;	}    }    /*     * We need to get the function list     */    if ((*entry)((CK_FUNCTION_LIST_PTR *)&mod->functionList) != CKR_OK) 								goto fail;#ifdef DEBUG_MODULE    if (PR_TRUE) {	modToDBG = PR_GetEnv("NSS_DEBUG_PKCS11_MODULE");	if (modToDBG && strcmp(mod->commonName, modToDBG) == 0) {	    mod->functionList = (void *)nss_InsertDeviceLog(	                           (CK_FUNCTION_LIST_PTR)mod->functionList);	}    }#endif    mod->isThreadSafe = PR_TRUE;    /* Now we initialize the module */    rv = secmod_ModuleInit(mod, &alreadyLoaded);    if (rv != SECSuccess) {	goto fail;    }    /* check the version number */    if (PK11_GETTAB(mod)->C_GetInfo(&info) != CKR_OK) goto fail2;    if (info.cryptokiVersion.major != 2) goto fail2;    /* all 2.0 are a priori *not* thread safe */    if (info.cryptokiVersion.minor < 1) {        if (!loadSingleThreadedModules) {            PORT_SetError(SEC_ERROR_INCOMPATIBLE_PKCS11);            goto fail2;        } else {            mod->isThreadSafe = PR_FALSE;        }    }    /* If we don't have a common name, get it from the PKCS 11 module */    if ((mod->commonName == NULL) || (mod->commonName[0] == 0)) {	mod->commonName = PK11_MakeString(mod->arena,NULL,	   (char *)info.libraryDescription, sizeof(info.libraryDescription));	if (mod->commonName == NULL) goto fail2;    }        /* initialize the Slots */    if (PK11_GETTAB(mod)->C_GetSlotList(CK_FALSE, NULL, &slotCount) == CKR_OK) {	CK_SLOT_ID *slotIDs;	int i;	CK_RV crv;	mod->slots = (PK11SlotInfo **)PORT_ArenaAlloc(mod->arena,					sizeof(PK11SlotInfo *) * slotCount);	if (mod->slots == NULL) goto fail2;	slotIDs = (CK_SLOT_ID *) PORT_Alloc(sizeof(CK_SLOT_ID)*slotCount);	if (slotIDs == NULL) {	    goto fail2;	}  	crv = PK11_GETTAB(mod)->C_GetSlotList(CK_FALSE, slotIDs, &slotCount);	if (crv != CKR_OK) {	    PORT_Free(slotIDs);	    goto fail2;	}	/* Initialize each slot */	for (i=0; i < (int)slotCount; i++) {	    mod->slots[i] = PK11_NewSlotInfo(mod);	    PK11_InitSlot(mod,slotIDs[i],mod->slots[i]);	    /* look down the slot info table */	    PK11_LoadSlotList(mod->slots[i],mod->slotInfo,mod->slotInfoCount);	    SECMOD_SetRootCerts(mod->slots[i],mod);	}	mod->slotCount = slotCount;	mod->slotInfoCount = 0;	PORT_Free(slotIDs);    }        mod->loaded = PR_TRUE;    mod->moduleID = nextModuleID++;    return SECSuccess;fail2:    if (enforceAlreadyInitializedError || (!alreadyLoaded)) {        PK11_GETTAB(mod)->C_Finalize(NULL);    }fail:    mod->functionList = NULL;    if (library) PR_UnloadLibrary(library);    return SECFailure;}