summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Woodhouse <David.Woodhouse@intel.com>2010-07-02 10:58:11 +0100
committerDavid Woodhouse <David.Woodhouse@intel.com>2010-07-02 11:06:12 +0100
commit1ca0f0d2db265fcded9c74954d3651e1ba2b40b1 (patch)
treed7e81479f6380fb091494217fd672a3e516521a0
parent186c5cc577d58087a6ad9eba87807d7f6d089ae4 (diff)
downloadevolution-data-server-1ca0f0d2db265fcded9c74954d3651e1ba2b40b1.tar.gz
Make NSS database initialisation more robust, handle errors better
Since commit 9116943e we only attempt to open the new SQL database, but some users are reporting issues. Be more careful about reporting errors when that happens, and also fall back to the old DBM database if the SQL database fails to initialise. (cherry picked from commit fe84f63ac7b0eb51356451e5aafe02e27a03d4e4)
-rw-r--r--camel/camel.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/camel/camel.c b/camel/camel.c
index de3885f61..f53bb7aad 100644
--- a/camel/camel.c
+++ b/camel/camel.c
@@ -32,6 +32,7 @@
#include <prthread.h>
#include "nss.h" /* Don't use <> here or it will include the system nss.h instead */
#include <ssl.h>
+#include <errno.h>
#endif /* HAVE_NSS */
#include <glib.h>
@@ -104,7 +105,7 @@ camel_init (const gchar *configdir, gboolean nss_init)
if (nss_init) {
gchar *nss_configdir = NULL;
gchar *nss_sql_configdir = NULL;
- SECStatus status;
+ SECStatus status = SECFailure;
PRUint16 indx;
if (nss_initlock == NULL) {
@@ -138,7 +139,9 @@ camel_init (const gchar *configdir, gboolean nss_init)
#else
gchar *user_nss_dir = g_build_filename ( g_get_home_dir (),
".pki/nssdb", NULL );
- g_mkdir_with_parents (user_nss_dir, 0700);
+ if (g_mkdir_with_parents (user_nss_dir, 0700))
+ g_warning("Failed to create SQL database directory %s: %s\n",
+ user_nss_dir, strerror(errno));
nss_sql_configdir = g_strconcat ("sql:", user_nss_dir, NULL);
g_free(user_nss_dir);
@@ -160,15 +163,14 @@ camel_init (const gchar *configdir, gboolean nss_init)
0); /* flags */
if (status == SECFailure) {
- g_free (nss_configdir);
- g_free (nss_sql_configdir);
- g_warning ("Failed to initialize NSS");
- PR_Unlock (nss_initlock);
- return -1;
+ g_warning ("Failed to initialize NSS SQL database in %s: NSS error %d",
+ nss_sql_configdir, PORT_GetError());
+ /* Fall back to opening the old DBM database */
}
-#else
+#endif
/* Support old versions of libnss, pre-sqlite support. */
- status = NSS_InitReadWrite (nss_configdir);
+ if (status == SECFailure)
+ status = NSS_InitReadWrite (nss_configdir);
if (status == SECFailure) {
/* Fall back to using volatile dbs? */
status = NSS_NoDB_Init (nss_configdir);
@@ -180,7 +182,6 @@ camel_init (const gchar *configdir, gboolean nss_init)
return -1;
}
}
-#endif
nss_initialized = TRUE;
skip_nss_init: