From: Timo Sirainen Date: Fri, 14 Feb 2025 08:12:04 +0000 (+0200) Subject: auth: Remove unused passdb/userdb-template.[ch] X-Git-Tag: 2.4.1~183 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0def117e86c189a13b01564c7313cb03bfa0af8f;p=thirdparty%2Fdovecot%2Fcore.git auth: Remove unused passdb/userdb-template.[ch] --- diff --git a/src/auth/Makefile.am b/src/auth/Makefile.am index f8a0d153bc..7c185ee0e8 100644 --- a/src/auth/Makefile.am +++ b/src/auth/Makefile.am @@ -120,7 +120,6 @@ auth_common_sources = \ passdb-pam.c \ passdb-sql.c \ passdb-static.c \ - passdb-template.c \ userdb.c \ userdb-blocking.c \ userdb-passwd.c \ @@ -128,7 +127,6 @@ auth_common_sources = \ userdb-prefetch.c \ userdb-static.c \ userdb-sql.c \ - userdb-template.c \ $(ldap_sources) \ $(lua_sources) @@ -162,10 +160,8 @@ headers = \ passdb.h \ passdb-blocking.h \ passdb-cache.h \ - passdb-template.h \ userdb.h \ - userdb-blocking.h \ - userdb-template.h + userdb-blocking.h if GSSAPI_PLUGIN libmech_gssapi_la_LDFLAGS = -module -avoid-version diff --git a/src/auth/auth-request-fields.c b/src/auth/auth-request-fields.c index bd545462fb..b7bfb00b1c 100644 --- a/src/auth/auth-request-fields.c +++ b/src/auth/auth-request-fields.c @@ -8,7 +8,6 @@ #include "str-sanitize.h" #include "base64.h" #include "auth-request.h" -#include "userdb-template.h" void auth_request_fields_init(struct auth_request *request) { diff --git a/src/auth/auth-request.c b/src/auth/auth-request.c index c20a35cad7..b81e65b4b8 100644 --- a/src/auth/auth-request.c +++ b/src/auth/auth-request.c @@ -25,9 +25,7 @@ #include "passdb.h" #include "passdb-blocking.h" #include "passdb-cache.h" -#include "passdb-template.h" #include "userdb-blocking.h" -#include "userdb-template.h" #include "password-scheme.h" #include "wildcard-match.h" diff --git a/src/auth/auth-worker-server.c b/src/auth/auth-worker-server.c index 8faac69058..ffeaca43a8 100644 --- a/src/auth/auth-worker-server.c +++ b/src/auth/auth-worker-server.c @@ -13,7 +13,6 @@ #include "process-title.h" #include "master-service.h" #include "auth-request.h" -#include "userdb-template.h" #include "auth-worker-server.h" #include "db-oauth2.h" diff --git a/src/auth/auth.c b/src/auth/auth.c index a8fbab3d77..d1c3a99d5a 100644 --- a/src/auth/auth.c +++ b/src/auth/auth.c @@ -6,8 +6,6 @@ #include "mech.h" #include "userdb.h" #include "passdb.h" -#include "passdb-template.h" -#include "userdb-template.h" #include "auth.h" #include "dns-lookup.h" diff --git a/src/auth/passdb-static.c b/src/auth/passdb-static.c index 78843f056a..ae3441818a 100644 --- a/src/auth/passdb-static.c +++ b/src/auth/passdb-static.c @@ -2,7 +2,6 @@ #include "auth-common.h" #include "passdb.h" -#include "passdb-template.h" #include "password-scheme.h" #include "settings.h" #include "auth-settings.h" diff --git a/src/auth/passdb-template.c b/src/auth/passdb-template.c deleted file mode 100644 index 2f3da8a0dc..0000000000 --- a/src/auth/passdb-template.c +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright (c) 2003-2018 Dovecot authors, see the included COPYING file */ - -#include "auth-common.h" -#include "array.h" -#include "str.h" -#include "passdb.h" -#include "passdb-template.h" - -struct passdb_template_arg { - const char *key; - struct var_expand_program *program; -}; - -struct passdb_template { - ARRAY(struct passdb_template_arg) args; - ARRAY_TYPE(const_string) keys; -}; - -struct passdb_template *passdb_template_build(pool_t pool, const char *args) -{ - struct passdb_template *tmpl; - const char *const *tmp; - - tmpl = p_new(pool, struct passdb_template, 1); - - tmp = t_strsplit_spaces(args, " "); - - p_array_init(&tmpl->args, pool, str_array_length(tmp) / 2); - p_array_init(&tmpl->keys, pool, str_array_length(tmp) / 2); - - for (; *tmp != NULL; tmp++) { - const char *p = strchr(*tmp, '='); - const char *kp; - const char *error; - - if (p == NULL) - kp = *tmp; - else - kp = t_strdup_until(*tmp, p++); - - if (*kp == '\0') - i_fatal("Invalid passdb template %s - key must not be empty", - args); - - char *key = p_strdup(pool, kp); - struct var_expand_program *prog; - if (var_expand_program_create(p, &prog, &error) < 0) - i_fatal("Invalid passdb template value %s: %s", p, error); - - struct passdb_template_arg *arg = array_append_space(&tmpl->args); - arg->key = key; - arg->program = prog; - array_push_back(&tmpl->keys, &arg->key); - } - - return tmpl; -} - -int passdb_template_export(struct passdb_template *tmpl, - struct auth_request *auth_request, - const char **error_r) -{ - string_t *str; - const struct passdb_template_arg *arg; - int ret = 0; - - if (passdb_template_is_empty(tmpl)) - return 0; - - const struct var_expand_params params = { - .table = auth_request_get_var_expand_table(auth_request), - .providers = auth_request_var_expand_providers, - .context = auth_request, - }; - - str = t_str_new(256); - - array_foreach(&tmpl->args, arg) { - str_truncate(str, 0); - ret = var_expand_program_execute(str, arg->program, ¶ms, - error_r); - if (ret < 0) - break; - auth_request_set_field(auth_request, arg->key, str_c(str), - STATIC_PASS_SCHEME); - } - - return ret; -} - -bool passdb_template_is_empty(struct passdb_template *tmpl) -{ - return array_is_empty(&tmpl->args); -} - -const char *const *passdb_template_get_args(struct passdb_template *tmpl, - unsigned int *count_r) -{ - return array_get(&tmpl->keys, count_r); -} - -void passdb_template_free(struct passdb_template **_tmpl) -{ - struct passdb_template *tmpl = *_tmpl; - if (tmpl == NULL) - return; - *_tmpl = NULL; - - struct passdb_template_arg *arg; - - array_foreach_modifiable(&tmpl->args, arg) - var_expand_program_free(&arg->program); -} diff --git a/src/auth/passdb-template.h b/src/auth/passdb-template.h deleted file mode 100644 index 6bcdbc7297..0000000000 --- a/src/auth/passdb-template.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef PASSDB_TEMPLATE_H -#define PASSDB_TEMPLATE_H - -struct passdb_template *passdb_template_build(pool_t pool, const char *args); -int passdb_template_export(struct passdb_template *tmpl, - struct auth_request *auth_request, - const char **error_r); -bool passdb_template_is_empty(struct passdb_template *tmpl); - -void passdb_template_free(struct passdb_template **_tmpl); - -const char *const *passdb_template_get_args(struct passdb_template *tmpl, unsigned int *count_r); - -#endif diff --git a/src/auth/userdb-static.c b/src/auth/userdb-static.c index d95089eac8..3f19ca222a 100644 --- a/src/auth/userdb-static.c +++ b/src/auth/userdb-static.c @@ -5,7 +5,6 @@ #include "array.h" #include "str.h" #include "userdb.h" -#include "userdb-template.h" #include "settings.h" diff --git a/src/auth/userdb-template.c b/src/auth/userdb-template.c deleted file mode 100644 index c95eaf8c40..0000000000 --- a/src/auth/userdb-template.c +++ /dev/null @@ -1,133 +0,0 @@ -/* Copyright (c) 2003-2018 Dovecot authors, see the included COPYING file */ - -#include "auth-common.h" -#include "array.h" -#include "str.h" -#include "userdb.h" -#include "userdb-template.h" - -struct userdb_template_arg { - const char *key; - struct var_expand_program *program; -}; - -struct userdb_template { - ARRAY(struct userdb_template_arg) args; - ARRAY_TYPE(const_string) keys; -}; - -struct userdb_template * -userdb_template_build(pool_t pool, const char *userdb_name, const char *args) -{ - struct userdb_template *tmpl; - const char *const *tmp; - uid_t uid; - gid_t gid; - - tmpl = p_new(pool, struct userdb_template, 1); - - tmp = t_strsplit_spaces(args, " "); - p_array_init(&tmpl->args, pool, str_array_length(tmp) / 2); - p_array_init(&tmpl->keys, pool, str_array_length(tmp) / 2); - - for (; *tmp != NULL; tmp++) { - const char *p = strchr(*tmp, '='); - const char *kp; - const char *error; - - if (p == NULL) - kp = *tmp; - else - kp = t_strdup_until(*tmp, p++); - - if (*kp == '\0') - i_fatal("Invalid userdb template %s - key must not be empty", - args); - - char *key = p_strdup(pool, kp); - const char *nonull_value = p == NULL ? "" : p; - if (strcasecmp(key, "uid") == 0) { - uid = userdb_parse_uid(NULL, nonull_value); - if (uid == (uid_t)-1) { - i_fatal("%s userdb: Invalid uid: %s", - userdb_name, nonull_value); - } - p = dec2str(uid); - } else if (strcasecmp(key, "gid") == 0) { - gid = userdb_parse_gid(NULL, nonull_value); - if (gid == (gid_t)-1) { - i_fatal("%s userdb: Invalid gid: %s", - userdb_name, nonull_value); - } - p = dec2str(gid); - } else if (*kp == '\0') { - i_fatal("%s userdb: Empty key (=%s)", - userdb_name, nonull_value); - } - struct var_expand_program *prog; - if (var_expand_program_create(p, &prog, &error) < 0) - i_fatal("Invalid userdb template value %s: %s", p, error); - - struct userdb_template_arg *arg = array_append_space(&tmpl->args); - arg->key = key; - arg->program = prog; - array_push_back(&tmpl->keys, &arg->key); - } - - return tmpl; -} - -int userdb_template_export(struct userdb_template *tmpl, - struct auth_request *auth_request, - const char **error_r) -{ - const struct userdb_template_arg *arg; - string_t *str; - int ret = 0; - - if (userdb_template_is_empty(tmpl)) - return 0; - - const struct var_expand_params params = { - .table = auth_request_get_var_expand_table(auth_request), - .providers = auth_request_var_expand_providers, - .context = auth_request, - }; - - str = t_str_new(256); - - array_foreach(&tmpl->args, arg) { - str_truncate(str, 0); - ret = var_expand_program_execute(str, arg->program, ¶ms, - error_r); - if (ret < 0) - break; - auth_request_set_userdb_field(auth_request, arg->key, str_c(str)); - } - - return ret; -} - -bool userdb_template_is_empty(struct userdb_template *tmpl) -{ - return array_is_empty(&tmpl->args); -} - -const char *const *userdb_template_get_args(struct userdb_template *tmpl, - unsigned int *count_r) -{ - return array_get(&tmpl->keys, count_r); -} - -void userdb_template_free(struct userdb_template **_tmpl) -{ - struct userdb_template *tmpl = *_tmpl; - if (tmpl == NULL) - return; - *_tmpl = NULL; - - struct userdb_template_arg *arg; - - array_foreach_modifiable(&tmpl->args, arg) - var_expand_program_free(&arg->program); -} diff --git a/src/auth/userdb-template.h b/src/auth/userdb-template.h deleted file mode 100644 index 26f3613ca6..0000000000 --- a/src/auth/userdb-template.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef USERDB_TEMPLATE_H -#define USERDB_TEMPLATE_H - -struct userdb_template * -userdb_template_build(pool_t pool, const char *userdb_name, const char *args); -int userdb_template_export(struct userdb_template *tmpl, - struct auth_request *auth_request, - const char **error_r); -bool userdb_template_remove(struct userdb_template *tmpl, - const char *key, const char **value_r); -bool userdb_template_is_empty(struct userdb_template *tmpl); -const char *const *userdb_template_get_args(struct userdb_template *tmpl, - unsigned int *count_r); -void userdb_template_free(struct userdb_template **_tmpl); - -#endif