/* * find a slot by it's slot number or label. If slot number is '0' any * slot is ok. */ int find_slot_by_number_and_label(pkcs11_handle_t *h, int wanted_slot_id, const char *wanted_token_label, unsigned int *slot_num) { int rv; const char *token_label = NULL; PK11SlotInfo *slot = NULL; /* we want a specific slot id, or we don't kare about the label */ if ((wanted_token_label == NULL) || (wanted_slot_id != 0)) { rv = find_slot_by_number(h, wanted_slot_id, slot_num); /* if we don't care about the label, or we failed, we're done */ if ((wanted_token_label == NULL) || (rv != 0)) { return rv; } /* verify it's the label we want */ token_label = PK11_GetTokenName(h->slot); if ((token_label != NULL) && (strcmp (wanted_token_label, token_label) == 0)) { return 0; } return -1; } /* we want a specific slot by label only */ slot = PK11_FindSlotByName(wanted_token_label); if (!slot) { return -1; } /* make sure it's in the right module */ if (h->module) { if (h->module != PK11_GetModule(slot)) { PK11_FreeSlot(slot); return -1; } } else { /* no module was specified, use the one slot came in */ h->module = SECMOD_ReferenceModule(PK11_GetModule(slot)); } h->slot = slot; /* Adopt the reference */ *slot_num = PK11_GetSlotID(h->slot); return 0; }
NSS_IMPLEMENT PRStatus nssToken_GetTrustOrder(NSSToken *tok) { PK11SlotInfo *slot; SECMODModule *module; slot = tok->pk11slot; module = PK11_GetModule(slot); return module->trustOrder; }
int find_slot_by_number(pkcs11_handle_t *h, unsigned int slot_num, unsigned int *slotID) { SECMODModule *module = h->module; int i; /* if module is null, * any of the PKCS #11 modules specified in the system config * is available, find one */ if (module == NULL) { PK11SlotList *list; PK11SlotListElement *le; PK11SlotInfo *slot = NULL; /* find a slot, we haven't specifically selected a module, * so find an appropriate one. */ /* get them all */ list = PK11_GetAllTokens(CKM_INVALID_MECHANISM, PR_FALSE, PR_TRUE, NULL); if (list == NULL) { return -1; } for (le = list->head; le; le = le->next) { CK_SLOT_INFO slInfo; SECStatus rv; slInfo.flags = 0; rv = PK11_GetSlotInfo(le->slot, &slInfo); if (rv == SECSuccess && (slInfo.flags & CKF_REMOVABLE_DEVICE)) { slot = PK11_ReferenceSlot(le->slot); module = SECMOD_ReferenceModule(PK11_GetModule(le->slot)); break; } } PK11_FreeSlotList(list); if (slot == NULL) { return -1; } h->slot = slot; h->module = module; *slotID = PK11_GetSlotID(slot); return 0; } /* * we're configured with a specific module, look for a present slot * on that module. */ if (slot_num == 0) { /* threaded applications should also acquire the * DefaultModuleListLock */ for (i=0; i < module->slotCount; i++) { if (module->slots[i] && PK11_IsPresent(module->slots[i])) { h->slot = PK11_ReferenceSlot(module->slots[i]); *slotID = PK11_GetSlotID(h->slot); return 0; } } } /* we're configured for a specific module and token, see if it's present */ slot_num--; if (slot_num < module->slotCount && module->slots && module->slots[slot_num] && PK11_IsPresent(module->slots[slot_num])) { h->slot = PK11_ReferenceSlot(module->slots[slot_num]); *slotID = PK11_GetSlotID(h->slot); return 0; } return -1; }