src/share/native/sun/security/pkcs11/j2secmod.c
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -68,10 +68,59 @@
if (configDir != NULL) {
(*env)->ReleaseStringUTFChars(env, jConfigDir, configDir);
}
dprintf1("-res: %d\n", res);
+ return (res == 0) ? JNI_TRUE : JNI_FALSE;
+}
+
+JNIEXPORT jboolean JNICALL Java_sun_security_pkcs11_Secmod_nssInitWithOptions
+ (JNIEnv *env, jclass thisClass, jstring jFunctionName, jlong jHandle, jstring jConfigDir, jboolean jNssUseOptimizeSpace)
+{
+ const char *functionName =
+ (*env)->GetStringUTFChars(env, jFunctionName, NULL);
+ const char *configDir = (jConfigDir == NULL)
+ ? NULL : (*env)->GetStringUTFChars(env, jConfigDir, NULL);
+ FPTR_Initialize initialize =
+ (FPTR_Initialize)findFunction(env, jHandle, "NSS_Initialize");
+ int res;
+ unsigned int flags = 0x00;
+
+ if (jNssUseOptimizeSpace == JNI_TRUE) {
+ flags = 0x20; // NSS_INIT_OPTIMIZESPACE flag
+ }
+
+ /*
+ * If the NSS_Init function is requested then call NSS_Initialize with
+ * the NSS_INIT_READONLY flag set and the NSS_INIT_OPTIMIZESPACE flag.
+ */
+ if (strcmp("NSS_Init", functionName) == 0) {
+ if (initialize == NULL) {
+ res = 1;
+ } else {
+ flags = flags | 0x01; // NSS_INIT_READONLY flag
+ res = initialize(configDir, "", "", "secmod.db", flags);
+ }
+ /*
+ * If the NSS_InitReadWrite function is requested then call
+ * NSS_InitReadWrite with the NSS_INIT_OPTIMIZESPACE flag.
+ */
+ } else if (strcmp("NSS_InitReadWrite", functionName) == 0) {
+ if (initialize == NULL) {
+ res = 2;
+ } else {
+ res = initialize(configDir, "", "", "secmod.db", flags);
+ }
+ } else {
+ res = 3;
+ }
+ (*env)->ReleaseStringUTFChars(env, jFunctionName, functionName);
+ if (configDir != NULL) {
+ (*env)->ReleaseStringUTFChars(env, jConfigDir, configDir);
+ }
+ dprintf1("-res: %d\n", res);
+
return (res == 0) ? JNI_TRUE : JNI_FALSE;
}
JNIEXPORT jobject JNICALL Java_sun_security_pkcs11_Secmod_nssGetModuleList
(JNIEnv *env, jclass thisClass, jlong jHandle, jstring jLibDir)