From c071be698efadef1ad01fd3d329d1b486a372927 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 26 Feb 2015 18:16:45 +0100 Subject: [PATCH] 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 --- common/mbox-util.c | 7 ++++--- common/stringhelp.c | 12 ++++++++++++ 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 );