1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-06-20 20:47:58 +02:00

* g10.c: New options --[no-]mangle-dos-filenames.

* options.h (opt): Added mangle-dos-filenames.
* openfile.c (open_outfile) [USE_ONLY_8DOT3]: Truncate the
filename only when this option is set; this is the default.
This commit is contained in:
Werner Koch 2002-12-05 15:25:16 +00:00
parent 1aec20776c
commit 036fbb22a7
4 changed files with 97 additions and 70 deletions

View File

@ -1,3 +1,10 @@
2002-12-05 Werner Koch <wk@gnupg.org>
* g10.c: New options --[no-]mangle-dos-filenames.
* options.h (opt): Added mangle-dos-filenames.
* openfile.c (open_outfile) [USE_ONLY_8DOT3]: Truncate the
filename only when this option is set; this is the default.
2002-12-04 David Shaw <dshaw@jabberwocky.com> 2002-12-04 David Shaw <dshaw@jabberwocky.com>
* main.h, keyedit.c, keygen.c: Back out previous (2002-12-01) * main.h, keyedit.c, keygen.c: Back out previous (2002-12-01)

View File

@ -310,6 +310,8 @@ enum cmd_and_opt_values { aNull = 0,
oGroup, oGroup,
oStrict, oStrict,
oNoStrict, oNoStrict,
oMangleDosFilenames,
oNoMangleDosFilenames,
aTest }; aTest };
@ -608,6 +610,8 @@ static ARGPARSE_OPTS opts[] = {
{ oGroup, "group", 2, "@" }, { oGroup, "group", 2, "@" },
{ oStrict, "strict", 0, "@" }, { oStrict, "strict", 0, "@" },
{ oNoStrict, "no-strict", 0, "@" }, { oNoStrict, "no-strict", 0, "@" },
{ oMangleDosFilenames, "mangle-dos-filenames", 0, "@" },
{ oNoMangleDosFilenames, "no-mangle-dos-filenames", 0, "@" },
{0} }; {0} };
@ -1154,6 +1158,8 @@ main( int argc, char **argv )
opt.keyserver_options.include_subkeys=1; opt.keyserver_options.include_subkeys=1;
opt.keyserver_options.include_revoked=1; opt.keyserver_options.include_revoked=1;
opt.trust_model=TM_OPENPGP; opt.trust_model=TM_OPENPGP;
opt.mangle_dos_filenames = 1;
#if defined (__MINGW32__) #if defined (__MINGW32__)
set_homedir ( read_w32_registry_string( NULL, set_homedir ( read_w32_registry_string( NULL,
"Software\\GNU\\GnuPG", "HomeDir" )); "Software\\GNU\\GnuPG", "HomeDir" ));
@ -1788,6 +1794,10 @@ main( int argc, char **argv )
case oGroup: add_group(pargs.r.ret_str); break; case oGroup: add_group(pargs.r.ret_str); break;
case oStrict: opt.strict=1; log_set_strict(1); break; case oStrict: opt.strict=1; log_set_strict(1); break;
case oNoStrict: opt.strict=0; log_set_strict(0); break; case oNoStrict: opt.strict=0; log_set_strict(0); break;
case oMangleDosFilenames: opt.mangle_dos_filenames = 1; break;
case oNoMangleDosFilenames: opt.mangle_dos_filenames = 0; break;
default : pargs.err = configfp? 1:2; break; default : pargs.err = configfp? 1:2; break;
} }
} }

View File

@ -161,7 +161,6 @@ ask_outfile_name( const char *name, size_t namelen )
} }
/**************** /****************
* Make an output filename for the inputfile INAME. * Make an output filename for the inputfile INAME.
* Returns an IOBUF and an errorcode * Returns an IOBUF and an errorcode
@ -184,7 +183,7 @@ open_outfile( const char *iname, int mode, IOBUF *a )
log_info(_("writing to stdout\n")); log_info(_("writing to stdout\n"));
} }
else { else {
char *buf=NULL; char *buf = NULL;
const char *name; const char *name;
if( opt.dry_run ) if( opt.dry_run )
@ -192,7 +191,9 @@ open_outfile( const char *iname, int mode, IOBUF *a )
else if( opt.outfile ) else if( opt.outfile )
name = opt.outfile; name = opt.outfile;
else { else {
#ifdef USE_ONLY_8DOT3 #ifdef USE_ONLY_8DOT3
if (opt.mangle_dos_filenames)
{
/* It is quite common DOS system to have only one dot in a /* It is quite common DOS system to have only one dot in a
* a filename So if we have something like this, we simple * a filename So if we have something like this, we simple
* replace the suffix execpt in cases where the suffix is * replace the suffix execpt in cases where the suffix is
@ -207,26 +208,32 @@ open_outfile( const char *iname, int mode, IOBUF *a )
buf = m_alloc(strlen(iname)+4+1); buf = m_alloc(strlen(iname)+4+1);
strcpy(buf,iname); strcpy(buf,iname);
dot = strchr(buf, '.' ); dot = strchr(buf, '.' );
if( dot && dot > buf && dot[1] && strlen(dot) <= 4 if ( dot && dot > buf && dot[1] && strlen(dot) <= 4
&& CMP_FILENAME(newsfx, dot) ) { && CMP_FILENAME(newsfx, dot) )
{
strcpy(dot, newsfx ); strcpy(dot, newsfx );
} }
else if( dot && !dot[1] ) /* don't duplicate a dot */ else if ( dot && !dot[1] ) /* don't duplicate a dot */
strcpy( dot, newsfx+1 ); strcpy( dot, newsfx+1 );
else else
strcat( buf, newsfx ); strcat ( buf, newsfx );
#else }
if (!buf)
#endif /* USE_ONLY_8DOT3 */
{
buf = m_alloc(strlen(iname)+4+1); buf = m_alloc(strlen(iname)+4+1);
strcpy(stpcpy(buf,iname), mode==1 ? EXTSEP_S "asc" : strcpy(stpcpy(buf,iname), mode==1 ? EXTSEP_S "asc" :
mode==2 ? EXTSEP_S "sig" : EXTSEP_S "gpg"); mode==2 ? EXTSEP_S "sig" : EXTSEP_S "gpg");
#endif }
name = buf; name = buf;
} }
rc = 0; rc = 0;
while( !overwrite_filep (name) ) { while( !overwrite_filep (name) )
{
char *tmp = ask_outfile_name (NULL, 0); char *tmp = ask_outfile_name (NULL, 0);
if ( !tmp || !*tmp ) { if ( !tmp || !*tmp )
{
m_free (tmp); m_free (tmp);
rc = G10ERR_FILE_EXISTS; rc = G10ERR_FILE_EXISTS;
break; break;
@ -235,8 +242,10 @@ open_outfile( const char *iname, int mode, IOBUF *a )
name = buf = tmp; name = buf = tmp;
} }
if( !rc ) { if( !rc )
if( !(*a = iobuf_create( name )) ) { {
if( !(*a = iobuf_create( name )) )
{
log_error(_("%s: can't create: %s\n"), name, strerror(errno) ); log_error(_("%s: can't create: %s\n"), name, strerror(errno) );
rc = G10ERR_CREATE_FILE; rc = G10ERR_CREATE_FILE;
} }
@ -245,11 +254,11 @@ open_outfile( const char *iname, int mode, IOBUF *a )
} }
m_free(buf); m_free(buf);
} }
return rc; return rc;
} }
/**************** /****************
* Try to open a file without the extension ".sig" or ".asc" * Try to open a file without the extension ".sig" or ".asc"
* Return NULL if such a file is not available. * Return NULL if such a file is not available.

View File

@ -179,6 +179,7 @@ struct {
int show_keyring; int show_keyring;
struct groupitem *grouplist; struct groupitem *grouplist;
int strict; int strict;
int mangle_dos_names;
} opt; } opt;