From 7df7d24cac955581398678ed6d1d8196c865090c Mon Sep 17 00:00:00 2001 From: Stephan Bosch <stephan.bosch@open-xchange.com> Date: Wed, 23 Oct 2024 20:21:35 +0200 Subject: [PATCH] lib-sieve: storage: ldap: sieve-ldap-db - Move all from_str() functions to sieve-ldap-storage-settings.c Also make them static. These are only needed there. --- src/lib-sieve/storage/ldap/sieve-ldap-db.c | 47 ------------------- src/lib-sieve/storage/ldap/sieve-ldap-db.h | 7 --- .../ldap/sieve-ldap-storage-settings.c | 47 +++++++++++++++++++ 3 files changed, 47 insertions(+), 54 deletions(-) diff --git a/src/lib-sieve/storage/ldap/sieve-ldap-db.c b/src/lib-sieve/storage/ldap/sieve-ldap-db.c index 0263ce0fd..3f3d90bc1 100644 --- a/src/lib-sieve/storage/ldap/sieve-ldap-db.c +++ b/src/lib-sieve/storage/ldap/sieve-ldap-db.c @@ -60,53 +60,6 @@ static struct ldap_connection *ldap_connections = NULL; static int db_ldap_bind(struct ldap_connection *conn); static void db_ldap_conn_close(struct ldap_connection *conn); -int ldap_deref_from_str(const char *str, int *deref_r) -{ - if (strcasecmp(str, "never") == 0) - *deref_r = LDAP_DEREF_NEVER; - else if (strcasecmp(str, "searching") == 0) - *deref_r = LDAP_DEREF_SEARCHING; - else if (strcasecmp(str, "finding") == 0) - *deref_r = LDAP_DEREF_FINDING; - else if (strcasecmp(str, "always") == 0) - *deref_r = LDAP_DEREF_ALWAYS; - else - return -1; - return 0; -} - -int ldap_scope_from_str(const char *str, int *scope_r) -{ - if (strcasecmp(str, "base") == 0) - *scope_r = LDAP_SCOPE_BASE; - else if (strcasecmp(str, "onelevel") == 0) - *scope_r = LDAP_SCOPE_ONELEVEL; - else if (strcasecmp(str, "subtree") == 0) - *scope_r = LDAP_SCOPE_SUBTREE; - else - return -1; - return 0; -} - -#ifdef OPENLDAP_TLS_OPTIONS -int ldap_tls_require_cert_from_str(const char *str, int *opt_x_tls_r) -{ - if (strcasecmp(str, "never") == 0) - *opt_x_tls_r = LDAP_OPT_X_TLS_NEVER; - else if (strcasecmp(str, "hard") == 0) - *opt_x_tls_r = LDAP_OPT_X_TLS_HARD; - else if (strcasecmp(str, "demand") == 0) - *opt_x_tls_r = LDAP_OPT_X_TLS_DEMAND; - else if (strcasecmp(str, "allow") == 0) - *opt_x_tls_r = LDAP_OPT_X_TLS_ALLOW; - else if (strcasecmp(str, "try") == 0) - *opt_x_tls_r = LDAP_OPT_X_TLS_TRY; - else - return -1; - return 0; -} -#endif - static int ldap_get_errno(struct ldap_connection *conn) { struct sieve_storage *storage = &conn->lstorage->storage; diff --git a/src/lib-sieve/storage/ldap/sieve-ldap-db.h b/src/lib-sieve/storage/ldap/sieve-ldap-db.h index 784084ae2..594aacdc2 100644 --- a/src/lib-sieve/storage/ldap/sieve-ldap-db.h +++ b/src/lib-sieve/storage/ldap/sieve-ldap-db.h @@ -111,13 +111,6 @@ struct ldap_connection { time_t last_reply_stamp; }; - -int ldap_deref_from_str(const char *str, int *deref_r); -int ldap_scope_from_str(const char *str, int *scope_r); -#ifdef OPENLDAP_TLS_OPTIONS -int ldap_tls_require_cert_from_str(const char *str, int *opt_x_tls_r); -#endif - /* Send/queue request */ void db_ldap_request(struct ldap_connection *conn, struct ldap_request *request); diff --git a/src/lib-sieve/storage/ldap/sieve-ldap-storage-settings.c b/src/lib-sieve/storage/ldap/sieve-ldap-storage-settings.c index addec4357..043fd2f35 100644 --- a/src/lib-sieve/storage/ldap/sieve-ldap-storage-settings.c +++ b/src/lib-sieve/storage/ldap/sieve-ldap-storage-settings.c @@ -87,6 +87,53 @@ parse_setting(const char *key, const char *value, &lstorage->set, key, value); } +static int ldap_deref_from_str(const char *str, int *deref_r) +{ + if (strcasecmp(str, "never") == 0) + *deref_r = LDAP_DEREF_NEVER; + else if (strcasecmp(str, "searching") == 0) + *deref_r = LDAP_DEREF_SEARCHING; + else if (strcasecmp(str, "finding") == 0) + *deref_r = LDAP_DEREF_FINDING; + else if (strcasecmp(str, "always") == 0) + *deref_r = LDAP_DEREF_ALWAYS; + else + return -1; + return 0; +} + +static int ldap_scope_from_str(const char *str, int *scope_r) +{ + if (strcasecmp(str, "base") == 0) + *scope_r = LDAP_SCOPE_BASE; + else if (strcasecmp(str, "onelevel") == 0) + *scope_r = LDAP_SCOPE_ONELEVEL; + else if (strcasecmp(str, "subtree") == 0) + *scope_r = LDAP_SCOPE_SUBTREE; + else + return -1; + return 0; +} + +#ifdef OPENLDAP_TLS_OPTIONS +static int ldap_tls_require_cert_from_str(const char *str, int *opt_x_tls_r) +{ + if (strcasecmp(str, "never") == 0) + *opt_x_tls_r = LDAP_OPT_X_TLS_NEVER; + else if (strcasecmp(str, "hard") == 0) + *opt_x_tls_r = LDAP_OPT_X_TLS_HARD; + else if (strcasecmp(str, "demand") == 0) + *opt_x_tls_r = LDAP_OPT_X_TLS_DEMAND; + else if (strcasecmp(str, "allow") == 0) + *opt_x_tls_r = LDAP_OPT_X_TLS_ALLOW; + else if (strcasecmp(str, "try") == 0) + *opt_x_tls_r = LDAP_OPT_X_TLS_TRY; + else + return -1; + return 0; +} +#endif + int sieve_ldap_storage_read_settings(struct sieve_ldap_storage *lstorage, const char *config_path) { -- GitLab