diff options
author | Frediano Ziglio <freddy77@gmail.com> | 2020-04-17 10:00:25 +0100 |
---|---|---|
committer | Frediano Ziglio <freddy77@gmail.com> | 2020-04-17 13:12:28 +0100 |
commit | 358e2d8bb045d80803190534ec1986c4242d10fc (patch) | |
tree | 1a7481746cf48f2c04bb2880ac1ba8481c3f2f91 /src | |
parent | 936519e55c24314a28faed6caf34fbac120bb89a (diff) |
Avoids some code duplication
Call NSS_InitContext and handle its result once.
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Jakub Jelen <jjelen@redhat.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/vcard_emul_nss.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/vcard_emul_nss.c b/src/vcard_emul_nss.c index f7a286f..d74edd4 100644 --- a/src/vcard_emul_nss.c +++ b/src/vcard_emul_nss.c @@ -956,6 +956,8 @@ vcard_emul_init(const VCardEmulOptions *options) SECMODModuleList *module_list; SECMODModuleList *mlp; int i; + gchar *path = NULL; + const gchar *nss_db; g_debug("%s: called", __func__); @@ -989,16 +991,10 @@ vcard_emul_init(const VCardEmulOptions *options) #endif /* first initialize NSS */ - if (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 { - gchar *path; + nss_db = options->nss_db; + if (nss_db == NULL) { #ifndef _WIN32 - path = g_strdup("/etc/pki/nssdb"); + nss_db = "/etc/pki/nssdb"; #else const gchar * const *config_dirs = g_get_system_config_dirs(); if (config_dirs == NULL || config_dirs[0] == NULL) { @@ -1006,16 +1002,20 @@ vcard_emul_init(const VCardEmulOptions *options) } path = g_build_filename(config_dirs[0], "pki", "nssdb", NULL); + nss_db = path; #endif + } - 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; - } + nss_ctx = NSS_InitContext(nss_db, "", "", "", NULL, NSS_INIT_READONLY); + if (nss_ctx == NULL) { + g_debug("%s: NSS_InitContext failed. Does the DB directory '%s' exist?", + __func__, nss_db); g_free(path); + return VCARD_EMUL_FAIL; } + g_free(path); + path = NULL; + /* Set password callback function */ PK11_SetPasswordFunc(vcard_emul_get_password); |