diff options
author | Werner Koch <[email protected]> | 2007-08-24 09:51:58 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2007-08-24 09:51:58 +0000 |
commit | d1a13319bbcca19f8f70a2b873b614e25c9d2a50 (patch) | |
tree | a96bfb8a4173951e8df276f0c73ef4e06bca6526 | |
parent | * ldap.m4: Revert the mozldap change: mozldap has some significant (diff) | |
download | gnupg-d1a13319bbcca19f8f70a2b873b614e25c9d2a50.tar.gz gnupg-d1a13319bbcca19f8f70a2b873b614e25c9d2a50.zip |
Improved detection of ketrings specified several times.
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | g10/ChangeLog | 5 | ||||
-rw-r--r-- | g10/keyring.c | 2 | ||||
-rw-r--r-- | include/ChangeLog | 4 | ||||
-rw-r--r-- | include/util.h | 1 | ||||
-rw-r--r-- | po/de.glo | 2 | ||||
-rw-r--r-- | util/ChangeLog | 6 | ||||
-rw-r--r-- | util/fileutil.c | 112 |
8 files changed, 109 insertions, 26 deletions
@@ -3,8 +3,9 @@ Noteworthy changes in version 1.4.8 (unreleased) * Changed the license to GPLv3. + * Improved detection of keyrings specified multiple times. + * Minor bug fixes. - Noteworthy changes in version 1.4.7 (2007-03-05) ------------------------------------------------ diff --git a/g10/ChangeLog b/g10/ChangeLog index 713dab44f..804d2fce6 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,8 @@ +2007-08-24 Werner Koch <[email protected]> + + * keyring.c (keyring_register_filename): Use same_file_p. + Suggested by Kurt Fitzner. + 2007-07-19 David Shaw <[email protected]> * gpg.c (main): Fix typo. Noted by John Clizbe. diff --git a/g10/keyring.c b/g10/keyring.c index 9ef5b1bd4..5d107319d 100644 --- a/g10/keyring.c +++ b/g10/keyring.c @@ -207,7 +207,7 @@ keyring_register_filename (const char *fname, int secret, void **ptr) for (kr=kr_names; kr; kr = kr->next) { - if ( !compare_filenames (kr->fname, fname) ) + if (same_file_p (kr->fname, fname) ) { *ptr=kr; return 0; /* already registered */ diff --git a/include/ChangeLog b/include/ChangeLog index 0fbabad98..8a96d5008 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,7 @@ +2007-08-24 Werner Koch <[email protected]> + + * util.h (same_file_p): Add prototype. + 2007-06-13 David Shaw <[email protected]> * cipher.h (CIPHER_ALGO_CAMELLIA): Add Camellia define. diff --git a/include/util.h b/include/util.h index 6269bd562..8c48e8c64 100644 --- a/include/util.h +++ b/include/util.h @@ -143,6 +143,7 @@ char * make_basename(const char *filepath, const char *inputpath); char * make_dirname(const char *filepath); char *make_filename( const char *first_part, ... ); int compare_filenames( const char *a, const char *b ); +int same_file_p (const char *name1, const char *name2); const char *print_fname_stdin( const char *s ); const char *print_fname_stdout( const char *s ); int is_file_compressed(const char *s, int *r_status); @@ -143,7 +143,7 @@ ownertrust \"Owner trust\" *Vertrauensw�rdigkeit des Besitzers packet Paket packet type Pakettyp parse -zerlegen -passphrase Mantra +passphrase Passphrase -# Mantra permission [file] Zugriffsrechte Photo-ID Foto-ID policy Richtlinie diff --git a/util/ChangeLog b/util/ChangeLog index f6a916f53..189ab6de3 100644 --- a/util/ChangeLog +++ b/util/ChangeLog @@ -1,3 +1,9 @@ +2007-08-24 Werner Koch <[email protected]> + + * fileutil.c (same_file_p): New. Taken from SVN trunk. + (compare_filenames) [HAVE_DRIVE_LETTERS]: Take drive letters and + backslashes in account. + 2007-04-16 David Shaw <[email protected]> * strgutil.c (ascii_toupper, ascii_tolower, ascii_strcasecmp, diff --git a/util/fileutil.c b/util/fileutil.c index 5834e3d89..dc2722105 100644 --- a/util/fileutil.c +++ b/util/fileutil.c @@ -1,5 +1,5 @@ /* fileutil.c - file utilities - * Copyright (C) 1998, 2003, 2005 Free Software Foundation, Inc. + * Copyright (C) 1998, 2003, 2005, 2007 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -30,6 +30,17 @@ #ifdef HAVE_PWD_H #include <pwd.h> #endif +#include <ctype.h> +#ifdef HAVE_W32_SYSTEM +# define WIN32_LEAN_AND_MEAN +# include <windows.h> +#else /*!HAVE_W32_SYSTEM*/ +# include <sys/types.h> +# include <sys/stat.h> +# include <unistd.h> +#endif /*!HAVE_W32_SYSTEM*/ + + #include "util.h" #include "memory.h" #include "ttyio.h" @@ -194,32 +205,87 @@ make_filename( const char *first_part, ... ) } +/* Compare whether the filenames are identical. This is a + special version of strcmp() taking the semantics of filenames in + account. Note that this function works only on the supplied names + without considereing any context like the current directory. See + also same_file_p(). */ int -compare_filenames( const char *a, const char *b ) +compare_filenames (const char *a, const char *b) { - /* ? check whether this is an absolute filename and - * resolve symlinks? - */ -#ifndef __riscos__ -#ifdef HAVE_DRIVE_LETTERS - return ascii_strcasecmp(a,b); -#else - return strcmp(a,b); +#ifdef __riscos__ + int c = 0; + char *abuf, *bbuf; + + abuf = riscos_gstrans(a); + bbuf = riscos_gstrans(b); + c = ascii_strcasecmp (abuf, bbuf); + xfree(abuf); + xfree(bbuf); + + return c; +#elif defined (HAVE_DRIVE_LETTERS) + for ( ; *a && *b; a++, b++ ) + { + if (*a != *b + && (toupper (*(const unsigned char*)a) + != toupper (*(const unsigned char*)b) ) + && !((*a == '/' && *b == '\\') || (*a == '\\' && *b == '/'))) + break; + } + if ((*a == '/' && *b == '\\') || (*a == '\\' && *b == '/')) + return 0; + else + return (toupper (*(const unsigned char*)a) + - toupper (*(const unsigned char*)b)); +#else /*!HAVE_DRIVE_LETTERS*/ + return strcmp (a,b); #endif -#else /* __riscos__ */ - int c = 0; - char *abuf, *bbuf; - - abuf = riscos_gstrans(a); - bbuf = riscos_gstrans(b); - - c = ascii_strcasecmp (abuf, bbuf); - - xfree(abuf); - xfree(bbuf); +} - return c; -#endif /* __riscos__ */ +/* Check whether the files NAME1 and NAME2 are identical. This is for + example achieved by comparing the inode numbers of the files. */ +int +same_file_p (const char *name1, const char *name2) +{ + int yes; + + /* First try a shortcut. */ + if (!compare_filenames (name1, name2)) + yes = 1; + else + { +#ifdef HAVE_W32_SYSTEM + HANDLE file1, file2; + BY_HANDLE_FILE_INFORMATION info1, info2; + + file1 = CreateFile (name1, 0, 0, NULL, OPEN_EXISTING, 0, NULL); + if (file1 == INVALID_HANDLE_VALUE) + yes = 0; /* If we can't open the file, it is not the same. */ + else + { + file2 = CreateFile (name2, 0, 0, NULL, OPEN_EXISTING, 0, NULL); + if (file1 == INVALID_HANDLE_VALUE) + yes = 0; /* If we can't open the file, it is not the same. */ + else + { + yes = (GetFileInformationByHandle (file1, &info1) + && GetFileInformationByHandle (file2, &info2) + && info1.dwVolumeSerialNumber==info2.dwVolumeSerialNumber + && info1.nFileIndexHigh == info2.nFileIndexHigh + && info1.nFileIndexLow == info2.nFileIndexLow); + CloseHandle (file2); + } + CloseHandle (file1); + } +#else /*!HAVE_W32_SYSTEM*/ + struct stat info1, info2; + + yes = (!stat (name1, &info1) && !stat (name2, &info2) + && info1.st_dev == info2.st_dev && info1.st_ino == info2.st_ino); +#endif /*!HAVE_W32_SYSTEM*/ + } + return yes; } |