diff options
Diffstat (limited to 'common/homedir.c')
-rw-r--r-- | common/homedir.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/common/homedir.c b/common/homedir.c index d64b74427..85e09c46a 100644 --- a/common/homedir.c +++ b/common/homedir.c @@ -61,6 +61,7 @@ #include "util.h" #include "sysutils.h" +#include "i18n.h" #include "zb32.h" /* The GnuPG homedir. This is only accessed by the functions @@ -489,6 +490,38 @@ gnupg_set_homedir (const char *newdir) } +/* Create the homedir directory only if the supplied directory name is + * the same as the default one. This way we avoid to create arbitrary + * directories when a non-default home directory is used. To cope + * with HOME, we do compare only the suffix if we see that the default + * homedir does start with a tilde. If the mkdir fails the function + * terminates the process. If QUIET is set not diagnostic is printed + * on homedir creation. */ +void +gnupg_maybe_make_homedir (const char *fname, int quiet) +{ + const char *defhome = standard_homedir (); + + if ( +#ifdef HAVE_W32_SYSTEM + ( !compare_filenames (fname, defhome) ) +#else + ( *defhome == '~' + && (strlen(fname) >= strlen (defhome+1) + && !strcmp(fname+strlen(fname)-strlen(defhome+1), defhome+1 ) )) + || (*defhome != '~' && !compare_filenames( fname, defhome ) ) +#endif + ) + { + if (gnupg_mkdir (fname, "-rwx")) + log_fatal ( _("can't create directory '%s': %s\n"), + fname, strerror(errno) ); + else if (!quiet ) + log_info ( _("directory '%s' created\n"), fname ); + } +} + + /* Return the homedir. The returned string is valid until another * gnupg-set-homedir call. This is always an absolute directory name. * The function replaces the former global var opt.homedir. */ |