2003-06-05 09:14:21 +02:00
|
|
|
/* openfile.c
|
2010-03-08 19:19:21 +01:00
|
|
|
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009,
|
|
|
|
* 2010 Free Software Foundation, Inc.
|
2003-06-05 09:14:21 +02:00
|
|
|
*
|
|
|
|
* This file is part of GnuPG.
|
|
|
|
*
|
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-07-04 21:49:40 +02:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-06-05 09:14:21 +02:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-07-04 21:49:40 +02:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2003-06-05 09:14:21 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2003-06-18 21:56:13 +02:00
|
|
|
|
|
|
|
#include "gpg.h"
|
2003-06-05 09:14:21 +02:00
|
|
|
#include "util.h"
|
|
|
|
#include "ttyio.h"
|
|
|
|
#include "options.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "status.h"
|
|
|
|
#include "i18n.h"
|
|
|
|
|
|
|
|
#ifdef USE_ONLY_8DOT3
|
|
|
|
#define SKELEXT ".skl"
|
|
|
|
#else
|
|
|
|
#define SKELEXT EXTSEP_S "skel"
|
|
|
|
#endif
|
|
|
|
|
2009-09-30 17:28:38 +02:00
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
#define NAME_OF_DEV_NULL "nul"
|
|
|
|
#else
|
|
|
|
#define NAME_OF_DEV_NULL "/dev/null"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
#if defined (HAVE_DRIVE_LETTERS) || defined (__riscos__)
|
|
|
|
#define CMP_FILENAME(a,b) ascii_strcasecmp( (a), (b) )
|
|
|
|
#else
|
|
|
|
#define CMP_FILENAME(a,b) strcmp( (a), (b) )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* FIXME: Implement opt.interactive. */
|
|
|
|
|
|
|
|
/****************
|
|
|
|
* Check whether FNAME exists and ask if it's okay to overwrite an
|
|
|
|
* existing one.
|
|
|
|
* Returns: True: it's okay to overwrite or the file does not exist
|
|
|
|
* False: Do not overwrite
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
overwrite_filep( const char *fname )
|
|
|
|
{
|
2009-09-30 17:28:38 +02:00
|
|
|
if ( iobuf_is_pipe_filename (fname) )
|
|
|
|
return 1; /* Writing to stdout is always okay. */
|
2011-02-04 12:57:53 +01:00
|
|
|
|
2009-09-30 17:28:38 +02:00
|
|
|
if ( access( fname, F_OK ) )
|
|
|
|
return 1; /* Does not exist. */
|
2011-02-04 12:57:53 +01:00
|
|
|
|
2009-09-30 17:28:38 +02:00
|
|
|
if ( !compare_filenames (fname, NAME_OF_DEV_NULL) )
|
|
|
|
return 1; /* Does not do any harm. */
|
2003-06-05 09:14:21 +02:00
|
|
|
|
2009-09-30 17:28:38 +02:00
|
|
|
if (opt.answer_yes)
|
|
|
|
return 1;
|
|
|
|
if (opt.answer_no || opt.batch)
|
|
|
|
return 0; /* Do not overwrite. */
|
2003-06-05 09:14:21 +02:00
|
|
|
|
2009-09-30 17:28:38 +02:00
|
|
|
tty_printf (_("File `%s' exists. "), fname);
|
|
|
|
if (cpr_enabled ())
|
|
|
|
tty_printf ("\n");
|
|
|
|
if (cpr_get_answer_is_yes ("openfile.overwrite.okay",
|
|
|
|
_("Overwrite? (y/N) ")) )
|
|
|
|
return 1;
|
|
|
|
return 0;
|
2003-06-05 09:14:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************
|
2006-11-27 17:41:32 +01:00
|
|
|
* Strip known extensions from iname and return a newly allocated
|
2003-06-05 09:14:21 +02:00
|
|
|
* filename. Return NULL if we can't do that.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
make_outfile_name( const char *iname )
|
|
|
|
{
|
|
|
|
size_t n;
|
|
|
|
|
2006-04-19 13:26:11 +02:00
|
|
|
if ( iobuf_is_pipe_filename (iname) )
|
|
|
|
return xstrdup("-");
|
2003-06-05 09:14:21 +02:00
|
|
|
|
|
|
|
n = strlen(iname);
|
|
|
|
if( n > 4 && ( !CMP_FILENAME(iname+n-4, EXTSEP_S "gpg")
|
|
|
|
|| !CMP_FILENAME(iname+n-4, EXTSEP_S "pgp")
|
|
|
|
|| !CMP_FILENAME(iname+n-4, EXTSEP_S "sig")
|
|
|
|
|| !CMP_FILENAME(iname+n-4, EXTSEP_S "asc") ) ) {
|
2006-04-19 13:26:11 +02:00
|
|
|
char *buf = xstrdup( iname );
|
2003-06-05 09:14:21 +02:00
|
|
|
buf[n-4] = 0;
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
else if( n > 5 && !CMP_FILENAME(iname+n-5, EXTSEP_S "sign") ) {
|
2006-04-19 13:26:11 +02:00
|
|
|
char *buf = xstrdup( iname );
|
2003-06-05 09:14:21 +02:00
|
|
|
buf[n-5] = 0;
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
log_info(_("%s: unknown suffix\n"), iname );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-27 17:41:32 +01:00
|
|
|
/* Ask for an output filename; use the given one as default. Return
|
|
|
|
NULL if no file has been given or if it is not possible to ask the
|
|
|
|
user. NAME is the template len which might conatin enbedded Nuls.
|
|
|
|
NAMELEN is its actual length.
|
2003-06-05 09:14:21 +02:00
|
|
|
*/
|
|
|
|
char *
|
|
|
|
ask_outfile_name( const char *name, size_t namelen )
|
|
|
|
{
|
2006-11-27 17:41:32 +01:00
|
|
|
size_t n;
|
|
|
|
const char *s;
|
|
|
|
char *prompt;
|
|
|
|
char *fname;
|
|
|
|
char *defname;
|
|
|
|
|
|
|
|
if ( opt.batch )
|
|
|
|
return NULL;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
2006-11-27 17:41:32 +01:00
|
|
|
defname = name && namelen? make_printable_string (name, namelen, 0) : NULL;
|
|
|
|
|
|
|
|
s = _("Enter new filename");
|
|
|
|
n = strlen(s) + (defname?strlen (defname):0) + 10;
|
|
|
|
prompt = xmalloc (n);
|
|
|
|
if (defname)
|
|
|
|
snprintf (prompt, n-1, "%s [%s]: ", s, defname );
|
|
|
|
else
|
|
|
|
snprintf (prompt, n-1, "%s: ", s );
|
|
|
|
tty_enable_completion(NULL);
|
|
|
|
fname = cpr_get ("openfile.askoutname", prompt );
|
|
|
|
cpr_kill_prompt ();
|
|
|
|
tty_disable_completion ();
|
|
|
|
xfree (prompt);
|
2011-02-04 12:57:53 +01:00
|
|
|
if ( !*fname )
|
2006-11-27 17:41:32 +01:00
|
|
|
{
|
2011-02-04 12:57:53 +01:00
|
|
|
xfree (fname);
|
2006-11-27 17:41:32 +01:00
|
|
|
fname = defname;
|
|
|
|
defname = NULL;
|
2003-06-05 09:14:21 +02:00
|
|
|
}
|
2006-11-27 17:41:32 +01:00
|
|
|
xfree (defname);
|
|
|
|
if (fname)
|
|
|
|
trim_spaces (fname);
|
|
|
|
return fname;
|
2003-06-05 09:14:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************
|
|
|
|
* Make an output filename for the inputfile INAME.
|
2006-04-19 13:26:11 +02:00
|
|
|
* Returns an IOBUF and an errorcode
|
2003-06-05 09:14:21 +02:00
|
|
|
* Mode 0 = use ".gpg"
|
|
|
|
* 1 = use ".asc"
|
|
|
|
* 2 = use ".sig"
|
2009-10-02 16:57:55 +02:00
|
|
|
*
|
|
|
|
* If INP_FD is not -1 the function simply creates an IOBUF for that
|
|
|
|
* file descriptor and ignorea INAME and MODE. Note that INP_FD won't
|
|
|
|
* be closed if the returned IOBUF is closed.
|
2003-06-05 09:14:21 +02:00
|
|
|
*/
|
|
|
|
int
|
2009-10-02 16:57:55 +02:00
|
|
|
open_outfile (int inp_fd, const char *iname, int mode, iobuf_t *a)
|
2003-06-05 09:14:21 +02:00
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
*a = NULL;
|
2009-10-02 16:57:55 +02:00
|
|
|
if (inp_fd != -1)
|
2009-09-30 17:28:38 +02:00
|
|
|
{
|
|
|
|
char xname[64];
|
2011-02-04 12:57:53 +01:00
|
|
|
|
2010-03-08 19:19:21 +01:00
|
|
|
*a = iobuf_fdopen_nc (inp_fd, "wb");
|
2009-09-30 17:28:38 +02:00
|
|
|
if (!*a)
|
|
|
|
{
|
|
|
|
rc = gpg_error_from_syserror ();
|
|
|
|
snprintf (xname, sizeof xname, "[fd %d]", inp_fd);
|
|
|
|
log_error (_("can't open `%s': %s\n"), xname, gpg_strerror (rc));
|
|
|
|
}
|
|
|
|
else if (opt.verbose)
|
|
|
|
{
|
|
|
|
snprintf (xname, sizeof xname, "[fd %d]", inp_fd);
|
|
|
|
log_info (_("writing to `%s'\n"), xname);
|
|
|
|
}
|
|
|
|
}
|
2011-02-04 12:57:53 +01:00
|
|
|
else if (iobuf_is_pipe_filename (iname) && !opt.outfile)
|
2009-09-30 17:28:38 +02:00
|
|
|
{
|
|
|
|
*a = iobuf_create(NULL);
|
|
|
|
if ( !*a )
|
|
|
|
{
|
|
|
|
rc = gpg_error_from_syserror ();
|
|
|
|
log_error (_("can't open `%s': %s\n"), "[stdout]", strerror(errno) );
|
|
|
|
}
|
|
|
|
else if ( opt.verbose )
|
|
|
|
log_info (_("writing to stdout\n"));
|
2003-06-05 09:14:21 +02:00
|
|
|
}
|
2009-09-30 17:28:38 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
char *buf = NULL;
|
|
|
|
const char *name;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
2009-09-30 17:28:38 +02:00
|
|
|
if (opt.dry_run)
|
|
|
|
name = NAME_OF_DEV_NULL;
|
|
|
|
else if (opt.outfile)
|
|
|
|
name = opt.outfile;
|
2011-02-04 12:57:53 +01:00
|
|
|
else
|
2003-06-05 09:14:21 +02:00
|
|
|
{
|
2009-09-30 17:28:38 +02:00
|
|
|
#ifdef USE_ONLY_8DOT3
|
|
|
|
if (opt.mangle_dos_filenames)
|
|
|
|
{
|
|
|
|
/* It is quite common for DOS systems to have only one
|
|
|
|
dot in a filename. If we have something like this,
|
|
|
|
we simple replace the suffix except in cases where
|
|
|
|
the suffix is larger than 3 characters and not the
|
|
|
|
same as the new one. We don't map the filenames to
|
|
|
|
8.3 because this is a duty of the file system. */
|
|
|
|
char *dot;
|
|
|
|
const char *newsfx;
|
|
|
|
|
|
|
|
newsfx = (mode==1 ? ".asc" :
|
|
|
|
mode==2 ? ".sig" : ".gpg");
|
2011-02-04 12:57:53 +01:00
|
|
|
|
2009-09-30 17:28:38 +02:00
|
|
|
buf = xmalloc (strlen(iname)+4+1);
|
|
|
|
strcpy (buf, iname);
|
|
|
|
dot = strchr (buf, '.' );
|
|
|
|
if ( dot && dot > buf && dot[1] && strlen(dot) <= 4
|
|
|
|
&& CMP_FILENAME (newsfx, dot) )
|
|
|
|
strcpy (dot, newsfx);
|
|
|
|
else if (dot && !dot[1]) /* Do not duplicate a dot. */
|
|
|
|
strcpy (dot, newsfx+1);
|
|
|
|
else
|
|
|
|
strcat (buf, newsfx);
|
|
|
|
}
|
|
|
|
if (!buf)
|
|
|
|
#endif /* USE_ONLY_8DOT3 */
|
2003-06-05 09:14:21 +02:00
|
|
|
{
|
2011-02-04 12:57:53 +01:00
|
|
|
buf = xstrconcat (iname,
|
2009-09-30 17:28:38 +02:00
|
|
|
(mode==1 ? EXTSEP_S "asc" :
|
|
|
|
mode==2 ? EXTSEP_S "sig" : EXTSEP_S "gpg"),
|
|
|
|
NULL);
|
2003-06-05 09:14:21 +02:00
|
|
|
}
|
2009-09-30 17:28:38 +02:00
|
|
|
name = buf;
|
2003-06-05 09:14:21 +02:00
|
|
|
}
|
2011-02-04 12:57:53 +01:00
|
|
|
|
2009-09-30 17:28:38 +02:00
|
|
|
rc = 0;
|
|
|
|
while ( !overwrite_filep (name) )
|
|
|
|
{
|
|
|
|
char *tmp = ask_outfile_name (NULL, 0);
|
|
|
|
if ( !tmp || !*tmp )
|
|
|
|
{
|
|
|
|
xfree (tmp);
|
|
|
|
rc = gpg_error (GPG_ERR_EEXIST);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
xfree (buf);
|
|
|
|
name = buf = tmp;
|
|
|
|
}
|
2011-02-04 12:57:53 +01:00
|
|
|
|
2009-09-30 17:28:38 +02:00
|
|
|
if ( !rc )
|
2003-06-05 09:14:21 +02:00
|
|
|
{
|
2009-09-30 17:28:38 +02:00
|
|
|
if (is_secured_filename (name) )
|
|
|
|
{
|
|
|
|
*a = NULL;
|
2010-04-01 15:24:55 +02:00
|
|
|
gpg_err_set_errno (EPERM);
|
2009-09-30 17:28:38 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
*a = iobuf_create (name);
|
|
|
|
if (!*a)
|
|
|
|
{
|
|
|
|
rc = gpg_error_from_syserror ();
|
|
|
|
log_error(_("can't create `%s': %s\n"), name, strerror(errno) );
|
|
|
|
}
|
|
|
|
else if( opt.verbose )
|
|
|
|
log_info (_("writing to `%s'\n"), name );
|
2003-06-05 09:14:21 +02:00
|
|
|
}
|
2009-09-30 17:28:38 +02:00
|
|
|
xfree(buf);
|
2003-06-05 09:14:21 +02:00
|
|
|
}
|
2011-02-04 12:57:53 +01:00
|
|
|
|
2006-04-19 13:26:11 +02:00
|
|
|
if (*a)
|
2010-03-08 18:05:37 +01:00
|
|
|
iobuf_ioctl (*a, IOBUF_IOCTL_NO_CACHE, 1, NULL);
|
2006-04-19 13:26:11 +02:00
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************
|
|
|
|
* Try to open a file without the extension ".sig" or ".asc"
|
|
|
|
* Return NULL if such a file is not available.
|
|
|
|
*/
|
2006-04-19 13:26:11 +02:00
|
|
|
IOBUF
|
2003-06-05 09:14:21 +02:00
|
|
|
open_sigfile( const char *iname, progress_filter_context_t *pfx )
|
|
|
|
{
|
2006-04-19 13:26:11 +02:00
|
|
|
IOBUF a = NULL;
|
2003-06-05 09:14:21 +02:00
|
|
|
size_t len;
|
|
|
|
|
2006-04-19 13:26:11 +02:00
|
|
|
if( !iobuf_is_pipe_filename (iname) ) {
|
2003-06-05 09:14:21 +02:00
|
|
|
len = strlen(iname);
|
|
|
|
if( len > 4 && ( !strcmp(iname + len - 4, EXTSEP_S "sig")
|
|
|
|
|| ( len > 5 && !strcmp(iname + len - 5, EXTSEP_S "sign") )
|
|
|
|
|| !strcmp(iname + len - 4, EXTSEP_S "asc")) ) {
|
|
|
|
char *buf;
|
2006-04-19 13:26:11 +02:00
|
|
|
buf = xstrdup(iname);
|
2003-06-05 09:14:21 +02:00
|
|
|
buf[len-(buf[len-1]=='n'?5:4)] = 0 ;
|
|
|
|
a = iobuf_open( buf );
|
2006-04-19 13:26:11 +02:00
|
|
|
if (a && is_secured_file (iobuf_get_fd (a)))
|
|
|
|
{
|
|
|
|
iobuf_close (a);
|
|
|
|
a = NULL;
|
2010-04-01 15:24:55 +02:00
|
|
|
gpg_err_set_errno (EPERM);
|
2006-04-19 13:26:11 +02:00
|
|
|
}
|
2003-06-05 09:14:21 +02:00
|
|
|
if( a && opt.verbose )
|
|
|
|
log_info(_("assuming signed data in `%s'\n"), buf );
|
|
|
|
if (a && pfx)
|
|
|
|
handle_progress (pfx, a, buf);
|
2006-04-19 13:26:11 +02:00
|
|
|
xfree(buf);
|
2003-06-05 09:14:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************
|
|
|
|
* Copy the option file skeleton to the given directory.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
copy_options_file( const char *destdir )
|
|
|
|
{
|
2007-06-14 19:05:07 +02:00
|
|
|
const char *datadir = gnupg_datadir ();
|
2003-06-05 09:14:21 +02:00
|
|
|
char *fname;
|
|
|
|
FILE *src, *dst;
|
|
|
|
int linefeeds=0;
|
|
|
|
int c;
|
|
|
|
mode_t oldmask;
|
|
|
|
int esc = 0;
|
|
|
|
int any_option = 0;
|
|
|
|
|
|
|
|
if( opt.dry_run )
|
|
|
|
return;
|
|
|
|
|
2006-04-19 13:26:11 +02:00
|
|
|
fname = xmalloc( strlen(datadir) + strlen(destdir) + 15 );
|
2004-08-31 09:57:33 +02:00
|
|
|
strcpy(stpcpy(fname, datadir), DIRSEP_S "gpg-conf" SKELEXT );
|
2003-06-05 09:14:21 +02:00
|
|
|
src = fopen( fname, "r" );
|
2006-04-19 13:26:11 +02:00
|
|
|
if (src && is_secured_file (fileno (src)))
|
|
|
|
{
|
|
|
|
fclose (src);
|
|
|
|
src = NULL;
|
2010-04-01 15:24:55 +02:00
|
|
|
gpg_err_set_errno (EPERM);
|
2006-04-19 13:26:11 +02:00
|
|
|
}
|
2003-06-05 09:14:21 +02:00
|
|
|
if( !src ) {
|
2006-12-08 12:30:13 +01:00
|
|
|
log_info (_("can't open `%s': %s\n"), fname, strerror(errno) );
|
2006-04-19 13:26:11 +02:00
|
|
|
xfree(fname);
|
2003-06-05 09:14:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
strcpy(stpcpy(fname, destdir), DIRSEP_S "gpg" EXTSEP_S "conf" );
|
|
|
|
oldmask=umask(077);
|
2006-04-19 13:26:11 +02:00
|
|
|
if ( is_secured_filename (fname) )
|
|
|
|
{
|
|
|
|
dst = NULL;
|
2010-04-01 15:24:55 +02:00
|
|
|
gpg_err_set_errno (EPERM);
|
2006-04-19 13:26:11 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
dst = fopen( fname, "w" );
|
2003-06-05 09:14:21 +02:00
|
|
|
umask(oldmask);
|
|
|
|
if( !dst ) {
|
2006-12-08 12:30:13 +01:00
|
|
|
log_info (_("can't create `%s': %s\n"), fname, strerror(errno) );
|
2003-06-05 09:14:21 +02:00
|
|
|
fclose( src );
|
2006-04-19 13:26:11 +02:00
|
|
|
xfree(fname);
|
2003-06-05 09:14:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while( (c=getc(src)) != EOF ) {
|
|
|
|
if( linefeeds < 3 ) {
|
|
|
|
if( c == '\n' )
|
|
|
|
linefeeds++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
putc( c, dst );
|
|
|
|
if (c== '\n')
|
|
|
|
esc = 1;
|
|
|
|
else if (esc == 1) {
|
|
|
|
if (c == ' ' || c == '\t')
|
|
|
|
;
|
|
|
|
else if (c == '#')
|
|
|
|
esc = 2;
|
2011-02-04 12:57:53 +01:00
|
|
|
else
|
2003-06-05 09:14:21 +02:00
|
|
|
any_option = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose( dst );
|
|
|
|
fclose( src );
|
|
|
|
log_info(_("new configuration file `%s' created\n"), fname );
|
|
|
|
if (any_option)
|
|
|
|
log_info (_("WARNING: options in `%s'"
|
|
|
|
" are not yet active during this run\n"),
|
|
|
|
fname);
|
2006-04-19 13:26:11 +02:00
|
|
|
xfree(fname);
|
2003-06-05 09:14:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2007-06-26 15:48:44 +02:00
|
|
|
try_make_homedir (const char *fname)
|
2003-06-05 09:14:21 +02:00
|
|
|
{
|
2007-06-26 15:48:44 +02:00
|
|
|
const char *defhome = standard_homedir ();
|
2003-06-05 09:14:21 +02:00
|
|
|
|
2007-06-26 15:48:44 +02:00
|
|
|
/* Create the 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 ( opt.dry_run || opt.no_homedir_creation )
|
|
|
|
return;
|
2003-06-05 09:14:21 +02:00
|
|
|
|
2007-06-26 15:48:44 +02:00
|
|
|
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
|
|
|
|
)
|
|
|
|
{
|
2010-04-14 13:24:02 +02:00
|
|
|
if (gnupg_mkdir (fname, "-rwx"))
|
2007-06-26 15:48:44 +02:00
|
|
|
log_fatal ( _("can't create directory `%s': %s\n"),
|
|
|
|
fname, strerror(errno) );
|
|
|
|
else if (!opt.quiet )
|
|
|
|
log_info ( _("directory `%s' created\n"), fname );
|
|
|
|
copy_options_file( fname );
|
2003-06-05 09:14:21 +02:00
|
|
|
}
|
|
|
|
}
|