]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: mech-scram - Move scram_unescape_username() to auth-scram-server.c.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Mon, 26 Sep 2022 23:19:45 +0000 (01:19 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 27 Jan 2023 09:34:54 +0000 (09:34 +0000)
src/auth/auth-scram-server.c [new file with mode: 0644]
src/auth/mech-scram.c

diff --git a/src/auth/auth-scram-server.c b/src/auth/auth-scram-server.c
new file mode 100644 (file)
index 0000000..debf345
--- /dev/null
@@ -0,0 +1,30 @@
+static const char *scram_unescape_username(const char *in)
+{
+       string_t *out;
+
+       /* RFC 5802, Section 5.1:
+
+          The characters ',' or '=' in usernames are sent as '=2C' and '=3D'
+          respectively.  If the server receives a username that contains '='
+          not followed by either '2C' or '3D', then the server MUST fail the
+          authentication.
+        */
+
+       out = t_str_new(64);
+       for (; *in != '\0'; in++) {
+               i_assert(in[0] != ','); /* strsplit should have caught this */
+
+               if (in[0] == '=') {
+                       if (in[1] == '2' && in[2] == 'C')
+                               str_append_c(out, ',');
+                       else if (in[1] == '3' && in[2] == 'D')
+                               str_append_c(out, '=');
+                       else
+                               return NULL;
+                       in += 2;
+               } else {
+                       str_append_c(out, *in);
+               }
+       }
+       return str_c(out);
+}
index dd9db252e8f1e3f9ccac53d12765edd223e429ae..9a695c0ca186646944de297d4c392ad180939fa2 100644 (file)
@@ -127,36 +127,7 @@ static const char *get_scram_server_final(struct scram_auth_request *request)
        return str_c(str);
 }
 
-static const char *scram_unescape_username(const char *in)
-{
-       string_t *out;
-
-       /* RFC 5802, Section 5.1:
-
-          The characters ',' or '=' in usernames are sent as '=2C' and '=3D'
-          respectively.  If the server receives a username that contains '='
-          not followed by either '2C' or '3D', then the server MUST fail the
-          authentication.
-        */
-
-       out = t_str_new(64);
-       for (; *in != '\0'; in++) {
-               i_assert(in[0] != ','); /* strsplit should have caught this */
-
-               if (in[0] == '=') {
-                       if (in[1] == '2' && in[2] == 'C')
-                               str_append_c(out, ',');
-                       else if (in[1] == '3' && in[2] == 'D')
-                               str_append_c(out, '=');
-                       else
-                               return NULL;
-                       in += 2;
-               } else {
-                       str_append_c(out, *in);
-               }
-       }
-       return str_c(out);
-}
+#include "auth-scram-server.c"
 
 static bool
 parse_scram_client_first(struct scram_auth_request *request,