static const char * w32_commondir (void) { static char *dir; if (!dir) { char path[MAX_PATH]; if (w32_shgetfolderpath (NULL, CSIDL_COMMON_APPDATA, NULL, 0, path) >= 0) { char *tmp = xmalloc (strlen (path) + 4 +1); strcpy (stpcpy (tmp, path), "\\GNU"); dir = tmp; /* No auto create of the directory. Either the installer or the admin has to create these directories. */ } else { /* Ooops: Not defined - probably an old Windows version. Use the installation directory instead. */ dir = xstrdup (w32_rootdir ()); } } return dir; }
/* Return the name of the cache directory. The name is allocated in a static area on the first use. Windows only: If the directory does not exist it is created. */ const char * gnupg_cachedir (void) { #ifdef HAVE_W32_SYSTEM static const char *dir; if (!dir) { char path[MAX_PATH]; const char *s1[] = { "GNU", "cache", "gnupg", NULL }; int s1_len; const char **comp; s1_len = 0; for (comp = s1; *comp; comp++) s1_len += 1 + strlen (*comp); if (w32_shgetfolderpath (NULL, CSIDL_LOCAL_APPDATA|CSIDL_FLAG_CREATE, NULL, 0, path) >= 0) { char *tmp = xmalloc (strlen (path) + s1_len + 1); char *p; p = stpcpy (tmp, path); for (comp = s1; *comp; comp++) { p = stpcpy (p, "\\"); p = stpcpy (p, *comp); if (access (tmp, F_OK)) w32_try_mkdir (tmp); } dir = tmp; } else { dir = "c:\\temp\\cache\\gnupg"; #ifdef HAVE_W32CE_SYSTEM dir += 2; w32_try_mkdir ("\\temp\\cache"); w32_try_mkdir ("\\temp\\cache\\gnupg"); #endif } } return dir; #else /*!HAVE_W32_SYSTEM*/ return GNUPG_LOCALSTATEDIR "/cache/" PACKAGE_NAME; #endif /*!HAVE_W32_SYSTEM*/ }
/* Get the standard home directory. In general this function should not be used as it does not consider a registry value (under W32) or the GNUPGHOME environment variable. It is better to use default_homedir(). */ const char * standard_homedir (void) { #ifdef HAVE_W32_SYSTEM static const char *dir; if (!dir) { const char *rdir; rdir = w32_rootdir (); if (w32_portable_app) { dir = xstrconcat (rdir, DIRSEP_S "home", NULL); } else { char path[MAX_PATH]; /* It might be better to use LOCAL_APPDATA because this is defined as "non roaming" and thus more likely to be kept locally. For private keys this is desired. However, given that many users copy private keys anyway forth and back, using a system roaming services might be better than to let them do it manually. A security conscious user will anyway use the registry entry to have better control. */ if (w32_shgetfolderpath (NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE, NULL, 0, path) >= 0) { char *tmp = xmalloc (strlen (path) + 6 +1); strcpy (stpcpy (tmp, path), "\\gnupg"); dir = tmp; /* Try to create the directory if it does not yet exists. */ if (access (dir, F_OK)) w32_try_mkdir (dir); } else dir = GNUPG_DEFAULT_HOMEDIR; } } return dir; #else/*!HAVE_W32_SYSTEM*/ return GNUPG_DEFAULT_HOMEDIR; #endif /*!HAVE_W32_SYSTEM*/ }
/* Return the system socket name used by DirMngr. */ const char * dirmngr_sys_socket_name (void) { #ifdef HAVE_W32_SYSTEM static char *name; if (!name) { char *p; # ifdef HAVE_W32CE_SYSTEM const char *s1, *s2; s1 = default_homedir (); # else char s1buf[MAX_PATH]; const char *s1, *s2; s1 = default_homedir (); if (!w32_portable_app) { /* We need something akin CSIDL_COMMON_PROGRAMS, but local (non-roaming). This is because the file needs to be on the local machine and makes only sense on that machine. CSIDL_WINDOWS seems to be the only location which guarantees that. */ if (w32_shgetfolderpath (NULL, CSIDL_WINDOWS, NULL, 0, s1buf) < 0) strcpy (s1buf, "C:\\WINDOWS"); s1 = s1buf; } # endif s2 = DIRSEP_S DIRMNGR_SOCK_NAME; name = xmalloc (strlen (s1) + strlen (s2) + 1); strcpy (stpcpy (name, s1), s2); for (p=name; *p; p++) if (*p == '/') *p = '\\'; } return name; #else /*!HAVE_W32_SYSTEM*/ return GNUPG_LOCALSTATEDIR "/run/" PACKAGE_NAME "/"DIRMNGR_SOCK_NAME; #endif /*!HAVE_W32_SYSTEM*/ }
static const char * w32_commondir (void) { static char *dir; if (!dir) { const char *rdir; char path[MAX_PATH]; /* Make sure that w32_rootdir has been called so that we are able to check the portable application flag. The common dir is the identical to the rootdir. In that case there is also no need to strdup its value. */ rdir = w32_rootdir (); if (w32_portable_app) return rdir; if (w32_shgetfolderpath (NULL, CSIDL_COMMON_APPDATA, NULL, 0, path) >= 0) { char *tmp = xmalloc (strlen (path) + 4 +1); strcpy (stpcpy (tmp, path), "\\GNU"); dir = tmp; /* No auto create of the directory. Either the installer or the admin has to create these directories. */ } else { /* Ooops: Not defined - probably an old Windows version. Use the installation directory instead. */ dir = xstrdup (rdir); } } return dir; }
/* Return the default socket name used by DirMngr. */ const char * dirmngr_socket_name (void) { #ifdef HAVE_W32_SYSTEM static char *name; if (!name) { char s1[MAX_PATH]; const char *s2; /* We need something akin CSIDL_COMMON_PROGRAMS, but local (non-roaming). */ if (w32_shgetfolderpath (NULL, CSIDL_WINDOWS, NULL, 0, s1) < 0) strcpy (s1, "C:\\WINDOWS"); s2 = DIRSEP_S "S.dirmngr"; name = xmalloc (strlen (s1) + strlen (s2) + 1); strcpy (stpcpy (name, s1), s2); } return name; #else /*!HAVE_W32_SYSTEM*/ return "/var/run/dirmngr/socket"; #endif /*!HAVE_W32_SYSTEM*/ }