/** @ingroup n8_sks_daemon * @brief Initialize an instance of the SKS management interface API. * * The current system file entries must be read, and if they exist, the * descriptor tables created for the calling application. * * @param targetSKS RO: the SKS unit desc. table to initialize * @param alloc_map RW: descriptor table buffer to initialize * * These and all other SKS interface calls should be considered * DESTRUCTIVE with respect to the contents of the SKS PROM. * * @par Externals: * None. * * @return * N8_STATUS_OK indicates that the API has been initialixed, or that all * intialization proceeded without errors. * N8_FILE_ERROR indicates that either an SKS entry could not be * read, or that the descriptor tables could not be created. * *****************************************************************************/ N8_Status_t n8_daemon_sks_init(N8_Unit_t targetSKS, N8_Buffer_t *alloc_map) { char sks_entry[N8_DAEMON_MAX_PATH_LEN]; char sks_entry_name[N8_SKS_ENTRY_NAME_MAX_LENGTH]; DIR *dir_p = NULL; struct dirent *dirent_p; N8_Status_t ret = N8_STATUS_OK; N8_SKSKeyHandle_t keyHandle; DBG(("n8_daemon_sks_init\n")); do { /* Initialize the discriptor mapping to zero */ memset(&alloc_map[0], SKS_FREE, SKS_ALLOC_UNITS_PER_PROM * sizeof(N8_Buffer_t)); /* Open the SKS entry directory. Read all the key files and * allocate descriptor space for them. */ sprintf(sks_entry_name, "%s%i/", SKS_KEY_NODE_PATH, targetSKS); DBG(("Target sks dev node is '%s'.\n\n", sks_entry_name)); if ((dir_p = opendir(sks_entry_name)) == NULL) { /* this just means that no key has been allocated * to this target SKS, so just return OK * (the allocation map we return has already been * initialized) */ return ret; } /* read the entries */ DBG(("Reading sks entries in '%s'.\n\n", sks_entry_name)); while ((dirent_p = readdir(dir_p)) && (dirent_p->d_name != NULL)) { if ((strcmp(dirent_p->d_name, ".") != 0) && (strcmp(dirent_p->d_name, "..") != 0)) { sprintf(sks_entry, "%s%s", sks_entry_name, dirent_p->d_name); ret = n8_daemon_sks_read(&keyHandle, sks_entry); CHECK_RETURN(ret); DBG(("Allocating descriptor space for key entry %s.\n", dirent_p->d_name)); printSKSKeyHandle(&keyHandle); ret = n8_setStatus(&keyHandle, SKS_INUSE, alloc_map); CHECK_RETURN(ret); } } } while (FALSE); /* cleanup */ closedir(dir_p); return ret; } /* n8_daemon_sks_init */
/** @ingroup n8_sks * @brief Reads a key handle data from a named key entry for an SKS PROM. * * @param systemKeyNode RW: A char pointer, the named key entry. * @param keyHandle_p WO: A N8_SKSKeyHandle_t pointer. * * @par Externals: * SKS_initialized_g RW: A boolean value that indicates whether the SKS * admin interface API has been initialized. * @return * N8_STATUS_OK indicates the key read successfully completed. * N8_UNEXPECTED_ERROR indicates an error reading the SKS key entry or that * the API was not or could not be initialized. * *****************************************************************************/ N8_Status_t N8_SKSGetKeyHandle(const N8_Buffer_t* keyEntryName, N8_SKSKeyHandle_t* keyHandle_p) { N8_Status_t ret = N8_STATUS_OK; char fullFileName[1024]; int numberSKS; int i; int found; DBG(("Get KeyHandle : \n")); ret = N8_preamble(); if (ret != N8_STATUS_OK) { return ret; } if ((keyEntryName == NULL) || (keyHandle_p == NULL)) { return N8_INVALID_OBJECT; } /* get the number of units */ numberSKS = n8_getNumUnits(); /* check to see if we can have a buffer overrun. the +4 is for the trailing * '/' and for the size of the unitID -- assuming the number of units is no * more than 999. */ if ((strlen(SKS_KEY_NODE_PATH) + strlen(keyEntryName) + 4) >= sizeof(fullFileName)) { return N8_UNEXPECTED_ERROR; } found = -1; for (i = 0; i < numberSKS; i++) { sprintf(fullFileName, "%s%d/%s", SKS_KEY_NODE_PATH, i, keyEntryName); /* request N8 userspace daemon to read from the specfied key * handle file */ ret = n8_daemon_sks_read(keyHandle_p, fullFileName); if (ret == N8_STATUS_OK) { found = i; /* n8_daemon_sks_read does not set the entry name */ strcpy(keyHandle_p->entry_name, keyEntryName); #if N8_SKS_ROUND_ROBIN keyHandle_p->unitID = N8_ANY_UNIT; #endif /* N8_SKS_ROUND_ROBIN */ break; } } if (found == -1) { ret = N8_INVALID_KEY; } return ret; } /* N8_SKSGetKeyHandle */