0001-auth-Fix-handling-passdbs-with-identical-driver-args.patch 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. From 7bad6a24160e34bce8f10e73dbbf9e5fbbcd1904 Mon Sep 17 00:00:00 2001
  2. From: Timo Sirainen <timo.sirainen@open-xchange.com>
  3. Date: Mon, 9 May 2022 15:23:33 +0300
  4. Subject: [PATCH] auth: Fix handling passdbs with identical driver/args but
  5. different mechanisms/username_filter
  6. The passdb was wrongly deduplicated in this situation, causing wrong
  7. mechanisms or username_filter setting to be used. This would be a rather
  8. unlikely configuration though.
  9. Fixed by moving mechanisms and username_filter from struct passdb_module
  10. to struct auth_passdb, which is where they should have been in the first
  11. place.
  12. Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
  13. ---
  14. src/auth/auth-request.c | 6 +++---
  15. src/auth/auth.c | 18 ++++++++++++++++++
  16. src/auth/auth.h | 5 +++++
  17. src/auth/passdb.c | 15 ++-------------
  18. src/auth/passdb.h | 4 ----
  19. 5 files changed, 28 insertions(+), 20 deletions(-)
  20. diff --git a/src/auth/auth-request.c b/src/auth/auth-request.c
  21. index cd08b1fa02..0ca29f3674 100644
  22. --- a/src/auth/auth-request.c
  23. +++ b/src/auth/auth-request.c
  24. @@ -534,8 +534,8 @@ auth_request_want_skip_passdb(struct auth_request *request,
  25. struct auth_passdb *passdb)
  26. {
  27. /* if mechanism is not supported, skip */
  28. - const char *const *mechs = passdb->passdb->mechanisms;
  29. - const char *const *username_filter = passdb->passdb->username_filter;
  30. + const char *const *mechs = passdb->mechanisms;
  31. + const char *const *username_filter = passdb->username_filter;
  32. const char *username;
  33. username = request->fields.user;
  34. @@ -548,7 +548,7 @@ auth_request_want_skip_passdb(struct auth_request *request,
  35. return TRUE;
  36. }
  37. - if (passdb->passdb->username_filter != NULL &&
  38. + if (passdb->username_filter != NULL &&
  39. !auth_request_username_accepted(username_filter, username)) {
  40. auth_request_log_debug(request,
  41. request->mech != NULL ? AUTH_SUBSYS_MECH
  42. diff --git a/src/auth/auth.c b/src/auth/auth.c
  43. index f2f3fda20c..9f6c4ba60c 100644
  44. --- a/src/auth/auth.c
  45. +++ b/src/auth/auth.c
  46. @@ -99,6 +99,24 @@ auth_passdb_preinit(struct auth *auth, const struct auth_passdb_settings *set,
  47. auth_passdb->override_fields_tmpl =
  48. passdb_template_build(auth->pool, set->override_fields);
  49. + if (*set->mechanisms == '\0') {
  50. + auth_passdb->mechanisms = NULL;
  51. + } else if (strcasecmp(set->mechanisms, "none") == 0) {
  52. + auth_passdb->mechanisms = (const char *const[]){ NULL };
  53. + } else {
  54. + auth_passdb->mechanisms =
  55. + (const char *const *)p_strsplit_spaces(auth->pool,
  56. + set->mechanisms, " ,");
  57. + }
  58. +
  59. + if (*set->username_filter == '\0') {
  60. + auth_passdb->username_filter = NULL;
  61. + } else {
  62. + auth_passdb->username_filter =
  63. + (const char *const *)p_strsplit_spaces(auth->pool,
  64. + set->username_filter, " ,");
  65. + }
  66. +
  67. /* for backwards compatibility: */
  68. if (set->pass)
  69. auth_passdb->result_success = AUTH_DB_RULE_CONTINUE;
  70. diff --git a/src/auth/auth.h b/src/auth/auth.h
  71. index f700e29d5c..460a179765 100644
  72. --- a/src/auth/auth.h
  73. +++ b/src/auth/auth.h
  74. @@ -41,6 +41,11 @@ struct auth_passdb {
  75. struct passdb_template *default_fields_tmpl;
  76. struct passdb_template *override_fields_tmpl;
  77. + /* Supported authentication mechanisms, NULL is all, {NULL} is none */
  78. + const char *const *mechanisms;
  79. + /* Username filter, NULL is no filter */
  80. + const char *const *username_filter;
  81. +
  82. enum auth_passdb_skip skip;
  83. enum auth_db_rule result_success;
  84. enum auth_db_rule result_failure;
  85. diff --git a/src/auth/passdb.c b/src/auth/passdb.c
  86. index eb4ac8ae82..f5eed1af4f 100644
  87. --- a/src/auth/passdb.c
  88. +++ b/src/auth/passdb.c
  89. @@ -224,19 +224,8 @@ passdb_preinit(pool_t pool, const struct auth_passdb_settings *set)
  90. passdb->id = ++auth_passdb_id;
  91. passdb->iface = *iface;
  92. passdb->args = p_strdup(pool, set->args);
  93. - if (*set->mechanisms == '\0') {
  94. - passdb->mechanisms = NULL;
  95. - } else if (strcasecmp(set->mechanisms, "none") == 0) {
  96. - passdb->mechanisms = (const char *const[]){NULL};
  97. - } else {
  98. - passdb->mechanisms = (const char* const*)p_strsplit_spaces(pool, set->mechanisms, " ,");
  99. - }
  100. -
  101. - if (*set->username_filter == '\0') {
  102. - passdb->username_filter = NULL;
  103. - } else {
  104. - passdb->username_filter = (const char* const*)p_strsplit_spaces(pool, set->username_filter, " ,");
  105. - }
  106. + /* NOTE: if anything else than driver & args are added here,
  107. + passdb_find() also needs to be updated. */
  108. array_push_back(&passdb_modules, &passdb);
  109. return passdb;
  110. }
  111. diff --git a/src/auth/passdb.h b/src/auth/passdb.h
  112. index 2e95328e5c..e466a9fdb6 100644
  113. --- a/src/auth/passdb.h
  114. +++ b/src/auth/passdb.h
  115. @@ -63,10 +63,6 @@ struct passdb_module {
  116. /* Default password scheme for this module.
  117. If default_cache_key is set, must not be NULL. */
  118. const char *default_pass_scheme;
  119. - /* Supported authentication mechanisms, NULL is all, [NULL] is none*/
  120. - const char *const *mechanisms;
  121. - /* Username filter, NULL is no filter */
  122. - const char *const *username_filter;
  123. /* If blocking is set to TRUE, use child processes to access
  124. this passdb. */
  125. --
  126. 2.30.2