summaryrefslogtreecommitdiffstats
path: root/src/auths/xtextdecode.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 00:47:26 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 00:47:26 +0000
commit96b619cc129afed52411b9fad3407037a1cb7207 (patch)
treee453a74cc9ae39fbfcb3ac55a347e880413e4a06 /src/auths/xtextdecode.c
parentInitial commit. (diff)
downloadexim4-upstream.tar.xz
exim4-upstream.zip
Adding upstream version 4.92.upstream/4.92upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/auths/xtextdecode.c')
-rw-r--r--src/auths/xtextdecode.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/auths/xtextdecode.c b/src/auths/xtextdecode.c
new file mode 100644
index 0000000..5312acf
--- /dev/null
+++ b/src/auths/xtextdecode.c
@@ -0,0 +1,57 @@
+/*************************************************
+* Exim - an Internet mail transport agent *
+*************************************************/
+
+/* Copyright (c) University of Cambridge 1995 - 2009 */
+/* See the file NOTICE for conditions of use and distribution. */
+
+#include "../exim.h"
+
+
+/*************************************************
+* Decode byte-string in xtext *
+*************************************************/
+
+/* This function decodes a string in xtextformat as defined in RFC 1891 and
+required by the SMTP AUTH extension (RFC 2554). We put the result in a piece of
+store of equal length - it cannot be longer than this. Although in general the
+result of decoding an xtext may be binary, in the context in which it is used
+by Exim (for decoding the value of AUTH on a MAIL command), the result is
+expected to be an addr-spec. We therefore add on a terminating zero, for
+convenience.
+
+Arguments:
+ code points to the coded string, zero-terminated
+ ptr where to put the pointer to the result, which is in
+ dynamic store
+
+Returns: the number of bytes in the result, excluding the final zero;
+ -1 if the input is malformed
+*/
+
+int
+auth_xtextdecode(uschar *code, uschar **ptr)
+{
+register int x;
+uschar *result = store_get(Ustrlen(code) + 1);
+*ptr = result;
+
+while ((x = (*code++)) != 0)
+ {
+ if (x < 33 || x > 127 || x == '=') return -1;
+ if (x == '+')
+ {
+ register int y;
+ if (!isxdigit((x = (*code++)))) return -1;
+ y = ((isdigit(x))? x - '0' : (tolower(x) - 'a' + 10)) << 4;
+ if (!isxdigit((x = (*code++)))) return -1;
+ *result++ = y | ((isdigit(x))? x - '0' : (tolower(x) - 'a' + 10));
+ }
+ else *result++ = x;
+ }
+
+*result = 0;
+return result - *ptr;
+}
+
+/* End of xtextdecode.c */