summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakub Jelen <jjelen@redhat.com>2020-04-16 18:56:39 +0200
committerFrediano Ziglio <freddy77@gmail.com>2020-04-17 08:59:06 +0100
commita9fb4177973ad99d3ec030d30a4388c26149a759 (patch)
tree97b4ee2b4730feca3807b87cc9d588d327362e59 /src
parent177d55dfcc373b3c466fba26b3930c7a3ec38cd1 (diff)
vcard_emul_nss: Use NSS_{Init,Shutdown}Context() functions to avoid messing with not owned contexts
As recommended by the NSS wiki: https://wiki.mozilla.org/NSS_Library_Init Signed-off-by: Jakub Jelen <jjelen@redhat.com> Acked-by: Frediano Ziglio <fziglio@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/vcard_emul_nss.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/vcard_emul_nss.c b/src/vcard_emul_nss.c
index f2bc8cf..e2e237f 100644
--- a/src/vcard_emul_nss.c
+++ b/src/vcard_emul_nss.c
@@ -944,11 +944,11 @@ vcard_emul_force_card_insert(VReader *vreader)
* vcards can be created (indicates error with certificates provided
* or db), or if any other higher level error (NSS error, missing coolkey). */
static int vcard_emul_init_called;
+static NSSInitContext *nss_ctx = NULL;
VCardEmulError
vcard_emul_init(const VCardEmulOptions *options)
{
- SECStatus rv;
PRBool has_readers = PR_FALSE;
VReader *vreader;
VReaderEmul *vreader_emul;
@@ -990,9 +990,9 @@ vcard_emul_init(const VCardEmulOptions *options)
/* first initialize NSS */
if (options->nss_db) {
- rv = NSS_Init(options->nss_db);
- if (rv != SECSuccess) {
- g_debug("%s: NSS_Init failed. Does the DB directory '%s' exist?", __func__, options->nss_db);
+ nss_ctx = NSS_InitContext(options->nss_db, "", "", "", NULL, NSS_INIT_READONLY);
+ if (nss_ctx == NULL) {
+ g_debug("%s: NSS_InitContext failed. Does the DB directory '%s' exist?", __func__, options->nss_db);
return VCARD_EMUL_FAIL;
}
} else {
@@ -1009,9 +1009,9 @@ vcard_emul_init(const VCardEmulOptions *options)
g_get_system_config_dirs()[0], "pki", "nssdb", NULL);
#endif
- rv = NSS_Init(path);
- if (rv != SECSuccess) {
- g_debug("%s: NSS_Init failed. Does the DB directory '%s' exist?", __func__, path);
+ nss_ctx = NSS_InitContext(path, "", "", "", NULL, NSS_INIT_READONLY);
+ if (nss_ctx == NULL) {
+ g_debug("%s: NSS_InitContext failed. Does the DB directory '%s' exist?", __func__, path);
g_free(path);
return VCARD_EMUL_FAIL;
}
@@ -1172,11 +1172,12 @@ vcard_emul_finalize(void)
{
SECStatus rv;
- rv = NSS_Shutdown();
+ rv = NSS_ShutdownContext(nss_ctx);
if (rv != SECSuccess) {
- g_debug("%s: NSS_Shutdown failed.", __func__);
+ g_debug("%s: NSS_ShutdownContext failed.", __func__);
return VCARD_EMUL_FAIL;
}
+ nss_ctx = NULL;
return VCARD_EMUL_OK;
}