From 6894cb956465bfb921abc7872a48e90c1b632a7e Mon Sep 17 00:00:00 2001 From: Aki Tuomi Date: Fri, 28 Jul 2017 12:35:07 +0300 Subject: [PATCH] auth: Do not use strcasecmp to compare mechanisms This is optimization since strcasecmp is slow --- src/auth/mech.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/auth/mech.c b/src/auth/mech.c index 47fcdb9a35..f8c7122195 100644 --- a/src/auth/mech.c +++ b/src/auth/mech.c @@ -4,6 +4,7 @@ #include "ioloop.h" #include "mech.h" #include "str.h" +#include "strfuncs.h" #include "passdb.h" #include @@ -13,6 +14,7 @@ static struct mech_module_list *mech_modules; void mech_register_module(const struct mech_module *module) { struct mech_module_list *list; + i_assert(strcmp(module->mech_name, t_str_ucase(module->mech_name)) == 0); list = i_new(struct mech_module_list, 1); list->module = *module; @@ -38,9 +40,10 @@ void mech_unregister_module(const struct mech_module *module) const struct mech_module *mech_module_find(const char *name) { struct mech_module_list *list; + name = t_str_ucase(name); for (list = mech_modules; list != NULL; list = list->next) { - if (strcasecmp(list->module.mech_name, name) == 0) + if (strcmp(list->module.mech_name, name) == 0) return &list->module; } return NULL; @@ -144,9 +147,9 @@ mech_register_init(const struct auth_settings *set) mechanisms = t_strsplit_spaces(set->mechanisms, " "); for (; *mechanisms != NULL; mechanisms++) { - const char *name = *mechanisms; + const char *name = t_str_ucase(*mechanisms); - if (strcasecmp(name, "ANONYMOUS") == 0) { + if (strcmp(name, "ANONYMOUS") == 0) { if (*set->anonymous_username == '\0') { i_fatal("ANONYMOUS listed in mechanisms, " "but anonymous_username not set"); @@ -180,9 +183,10 @@ const struct mech_module * mech_register_find(const struct mechanisms_register *reg, const char *name) { const struct mech_module_list *list; + name = t_str_ucase(name); for (list = reg->modules; list != NULL; list = list->next) { - if (strcasecmp(list->module.mech_name, name) == 0) + if (strcmp(list->module.mech_name, name) == 0) return &list->module; } return NULL; -- 2.47.3