3d912a
Index: nss/lib/sysinit/nsssysinit.c
3d912a
===================================================================
3d912a
--- nss.orig/lib/sysinit/nsssysinit.c
3d912a
+++ nss/lib/sysinit/nsssysinit.c
3d912a
@@ -36,41 +36,9 @@ testdir(char *dir)
3d912a
     return S_ISDIR(buf.st_mode);
3d912a
 }
3d912a
 
3d912a
-/**
3d912a
- * Append given @dir to @path and creates the directory with mode @mode.
3d912a
- * Returns 0 if successful, -1 otherwise.
3d912a
- * Assumes that the allocation for @path has sufficient space for @dir
3d912a
- * to be added.
3d912a
- */
3d912a
-static int
3d912a
-appendDirAndCreate(char *path, char *dir, mode_t mode)
3d912a
-{
3d912a
-    PORT_Strcat(path, dir);
3d912a
-    if (!testdir(path)) {
3d912a
-        if (mkdir(path, mode)) {
3d912a
-            return -1;
3d912a
-        }
3d912a
-    }
3d912a
-    return 0;
3d912a
-}
3d912a
-
3d912a
-#define XDG_NSS_USER_PATH1 "/.local"
3d912a
-#define XDG_NSS_USER_PATH2 "/share"
3d912a
-#define XDG_NSS_USER_PATH3 "/pki"
3d912a
-
3d912a
 #define NSS_USER_PATH1 "/.pki"
3d912a
 #define NSS_USER_PATH2 "/nssdb"
3d912a
-
3d912a
-/**
3d912a
- * Return the path to user's NSS database.
3d912a
- * We search in the following dirs in order:
3d912a
- * (1) $HOME/.pki/nssdb;
3d912a
- * (2) $XDG_DATA_HOME/pki/nssdb if XDG_DATA_HOME is set;
3d912a
- * (3) $HOME/.local/share/pki/nssdb (default XDG_DATA_HOME value).
3d912a
- * If (1) does not exist, then the returned dir will be set to either
3d912a
- * (2) or (3), depending if XDG_DATA_HOME is set.
3d912a
- */
3d912a
-char *
3d912a
+static char *
3d912a
 getUserDB(void)
3d912a
 {
3d912a
     char *userdir = PR_GetEnvSecure("HOME");
3d912a
@@ -81,47 +49,22 @@ getUserDB(void)
3d912a
     }
3d912a
 
3d912a
     nssdir = PORT_Alloc(strlen(userdir) + sizeof(NSS_USER_PATH1) + sizeof(NSS_USER_PATH2));
3d912a
+    if (nssdir == NULL) {
3d912a
+        return NULL;
3d912a
+    }
3d912a
     PORT_Strcpy(nssdir, userdir);
3d912a
-    PORT_Strcat(nssdir, NSS_USER_PATH1 NSS_USER_PATH2);
3d912a
-    if (testdir(nssdir)) {
3d912a
-        /* $HOME/.pki/nssdb exists */
3d912a
-        return nssdir;
3d912a
-    } else {
3d912a
-        /* either $HOME/.pki or $HOME/.pki/nssdb does not exist */
3d912a
+    /* verify it exists */
3d912a
+    if (!testdir(nssdir)) {
3d912a
         PORT_Free(nssdir);
3d912a
-    }
3d912a
-    int size = 0;
3d912a
-    char *xdguserdatadir = PR_GetEnvSecure("XDG_DATA_HOME");
3d912a
-    if (xdguserdatadir) {
3d912a
-        size = strlen(xdguserdatadir);
3d912a
-    } else {
3d912a
-        size = strlen(userdir) + sizeof(XDG_NSS_USER_PATH1) + sizeof(XDG_NSS_USER_PATH2);
3d912a
-    }
3d912a
-    size += sizeof(XDG_NSS_USER_PATH3) + sizeof(NSS_USER_PATH2);
3d912a
-
3d912a
-    nssdir = PORT_Alloc(size);
3d912a
-    if (nssdir == NULL) {
3d912a
         return NULL;
3d912a
     }
3d912a
-
3d912a
-    if (xdguserdatadir) {
3d912a
-        PORT_Strcpy(nssdir, xdguserdatadir);
3d912a
-        if (!testdir(nssdir)) {
3d912a
-            PORT_Free(nssdir);
3d912a
-            return NULL;
3d912a
-        }
3d912a
-
3d912a
-    } else {
3d912a
-        PORT_Strcpy(nssdir, userdir);
3d912a
-        if (appendDirAndCreate(nssdir, XDG_NSS_USER_PATH1, 0755) ||
3d912a
-            appendDirAndCreate(nssdir, XDG_NSS_USER_PATH2, 0755)) {
3d912a
-            PORT_Free(nssdir);
3d912a
-            return NULL;
3d912a
-        }
3d912a
+    PORT_Strcat(nssdir, NSS_USER_PATH1);
3d912a
+    if (!testdir(nssdir) && mkdir(nssdir, 0760)) {
3d912a
+        PORT_Free(nssdir);
3d912a
+        return NULL;
3d912a
     }
3d912a
-    /* ${XDG_DATA_HOME:-$HOME/.local/share}/pki/nssdb */
3d912a
-    if (appendDirAndCreate(nssdir, XDG_NSS_USER_PATH3, 0760) ||
3d912a
-        appendDirAndCreate(nssdir, NSS_USER_PATH2, 0760)) {
3d912a
+    PORT_Strcat(nssdir, NSS_USER_PATH2);
3d912a
+    if (!testdir(nssdir) && mkdir(nssdir, 0760)) {
3d912a
         PORT_Free(nssdir);
3d912a
         return NULL;
3d912a
     }