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