From: Stephan Bosch Date: Mon, 26 Sep 2022 23:19:45 +0000 (+0200) Subject: auth: mech-scram - Move scram_unescape_username() to auth-scram-server.c. X-Git-Tag: 2.4.0~3147 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=30637483672563208d2eb941204e9cb2920eb18e;p=thirdparty%2Fdovecot%2Fcore.git auth: mech-scram - Move scram_unescape_username() to auth-scram-server.c. --- diff --git a/src/auth/auth-scram-server.c b/src/auth/auth-scram-server.c new file mode 100644 index 0000000000..debf345796 --- /dev/null +++ b/src/auth/auth-scram-server.c @@ -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); +} diff --git a/src/auth/mech-scram.c b/src/auth/mech-scram.c index dd9db252e8..9a695c0ca1 100644 --- a/src/auth/mech-scram.c +++ b/src/auth/mech-scram.c @@ -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,