static char * nss_doubleEscape(const char *string) { char *round1 = NULL; char *retValue = NULL; if (string == NULL) { goto done; } round1 = nss_addEscape(string,'\''); if (round1) { retValue = nss_addEscape(round1,'"'); PORT_Free(round1); } done: if (retValue == NULL) { retValue = PORT_Strdup(""); } return retValue; }
SECStatus LoadLoadableRoots(/*optional*/ const char* dir, const char* modNameUTF8) { PR_ASSERT(modNameUTF8); if (!modNameUTF8) { PR_SetError(SEC_ERROR_INVALID_ARGS, 0); return SECFailure; } ScopedPtr<char, PR_FreeLibraryName> fullLibraryPath( PR_GetLibraryName(dir, "nssckbi")); if (!fullLibraryPath) { return SECFailure; } ScopedPtr<char, PORT_Free_string> escaped_fullLibraryPath( nss_addEscape(fullLibraryPath.get(), '\"')); if (!escaped_fullLibraryPath) { return SECFailure; } // If a module exists with the same name, delete it. int modType; SECMOD_DeleteModule(modNameUTF8, &modType); ScopedPtr<char, PR_smprintf_free> pkcs11ModuleSpec( PR_smprintf("name=\"%s\" library=\"%s\"", modNameUTF8, escaped_fullLibraryPath.get())); if (!pkcs11ModuleSpec) { return SECFailure; } ScopedSECMODModule rootsModule(SECMOD_LoadUserModule(pkcs11ModuleSpec.get(), nullptr, false)); if (!rootsModule) { return SECFailure; } if (!rootsModule->loaded) { PR_SetError(PR_INVALID_STATE_ERROR, 0); return SECFailure; } return SECSuccess; }