Patchwork [v3,05/28] libcacard: use system config directory for nss db on win32

login
register
mail settings
Submitter Alon Levy
Date April 22, 2013, 3:04 p.m.
Message ID <1366643098-2566-6-git-send-email-alevy@redhat.com>
Download mbox | patch
Permalink /patch/238568/
State New
Headers show

Comments

Alon Levy - April 22, 2013, 3:04 p.m.
From: Marc-André Lureau <marcandre.lureau@gmail.com>

It's a bit nicer to look for default database under
CSIDL_COMMON_APPDATA\pki\nss rather that /etc/pki/nss.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 libcacard/vcard_emul_nss.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

Patch

diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c
index df79476..21d4689 100644
--- a/libcacard/vcard_emul_nss.c
+++ b/libcacard/vcard_emul_nss.c
@@ -893,7 +893,23 @@  vcard_emul_init(const VCardEmulOptions *options)
     if (options->nss_db) {
         rv = NSS_Init(options->nss_db);
     } else {
-        rv = NSS_Init("sql:/etc/pki/nssdb");
+        gchar *path, *db;
+#ifndef _WIN32
+        path = g_strdup("/etc/pki/nssdb");
+#else
+        if (g_get_system_config_dirs() == NULL ||
+            g_get_system_config_dirs()[0] == NULL) {
+            return VCARD_EMUL_FAIL;
+        }
+
+        path = g_build_filename(
+            g_get_system_config_dirs()[0], "pki", "nssdb", NULL);
+#endif
+        db = g_strdup_printf("sql:%s", path);
+
+        rv = NSS_Init(db);
+        g_free(db);
+        g_free(path);
     }
     if (rv != SECSuccess) {
         return VCARD_EMUL_FAIL;