diff options
author | Werner Koch <[email protected]> | 2015-02-26 17:16:45 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2015-02-26 17:16:45 +0000 |
commit | c071be698efadef1ad01fd3d329d1b486a372927 (patch) | |
tree | dcf999a07b3ae48e6f56fdcfee3e9f50756ac620 | |
parent | Remove an unused variable. (diff) | |
download | gnupg-c071be698efadef1ad01fd3d329d1b486a372927.tar.gz gnupg-c071be698efadef1ad01fd3d329d1b486a372927.zip |
gpg: Lowercase mailbox for PKA lookups.
* common/stringhelp.c (ascii_strlwr): New.
* common/mbox-util.c (mailbox_from_userid): Downcase result.
--
Signed-off-by: Werner Koch <[email protected]>
-rw-r--r-- | common/mbox-util.c | 7 | ||||
-rw-r--r-- | common/stringhelp.c | 12 | ||||
-rw-r--r-- | common/stringhelp.h | 1 |
3 files changed, 17 insertions, 3 deletions
diff --git a/common/mbox-util.c b/common/mbox-util.c index 332f62fa8..0885f0e6f 100644 --- a/common/mbox-util.c +++ b/common/mbox-util.c @@ -124,8 +124,9 @@ is_valid_mailbox (const char *name) /* Return the mailbox (local-part@domain) form a standard user id. - Caller must free the result. Returns NULL if no valid mailbox was - found (or we are out of memory). */ + All plain ASCII characters in the result are converted to + lowercase. Caller must free the result. Returns NULL if no valid + mailbox was found (or we are out of memory). */ char * mailbox_from_userid (const char *userid) { @@ -176,7 +177,7 @@ mailbox_from_userid (const char *userid) else errno = EINVAL; - return result; + return result? ascii_strlwr (result): NULL; } diff --git a/common/stringhelp.c b/common/stringhelp.c index 7128de5fc..42e1bcbbb 100644 --- a/common/stringhelp.c +++ b/common/stringhelp.c @@ -804,6 +804,18 @@ ascii_tolower (int c) return c; } +/* Lowercase all ASCII characters in S. */ +char * +ascii_strlwr (char *s) +{ + char *p = s; + + for (p=s; *p; p++ ) + if (isascii (*p) && *p >= 'A' && *p <= 'Z') + *p |= 0x20; + + return s; +} int ascii_strcasecmp( const char *a, const char *b ) diff --git a/common/stringhelp.h b/common/stringhelp.h index d4fe169a7..ffef2d52f 100644 --- a/common/stringhelp.h +++ b/common/stringhelp.h @@ -75,6 +75,7 @@ int ascii_isupper (int c); int ascii_islower (int c); int ascii_toupper (int c); int ascii_tolower (int c); +char *ascii_strlwr (char *s); int ascii_strcasecmp( const char *a, const char *b ); int ascii_strncasecmp (const char *a, const char *b, size_t n); int ascii_memcasecmp( const void *a, const void *b, size_t n ); |