From a01f737a27ec6f28557ade67e7ec6e91186a3dca Mon Sep 17 00:00:00 2001 From: Aki Tuomi Date: Tue, 17 Sep 2024 09:28:13 +0300 Subject: [PATCH] auth: Change auth_request_var_expand() return value It now returns -1 on error and 0 on success --- src/auth/auth-policy.c | 2 +- src/auth/auth-request-fields.c | 2 +- src/auth/auth-request-var-expand.c | 4 ++-- src/auth/auth-request.c | 2 +- src/auth/db-lua.c | 2 +- src/auth/db-passwd-file.c | 2 +- src/auth/passdb-passwd-file.c | 2 +- src/auth/test-auth-request-var-expand.c | 4 ++-- src/auth/userdb-passwd-file.c | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/auth/auth-policy.c b/src/auth/auth-policy.c index 9cfc6c9027..0499d1ddd1 100644 --- a/src/auth/auth-policy.c +++ b/src/auth/auth-policy.c @@ -549,7 +549,7 @@ auth_policy_create_json(struct policy_lookup_ctx *context, auth_policy_json_template, context->request, var_table, auth_policy_escape_function, - &error) <= 0) { + &error) < 0) { e_error(context->event, "Failed to expand auth policy template: %s", error); } diff --git a/src/auth/auth-request-fields.c b/src/auth/auth-request-fields.c index 73e30b386f..b076efcf34 100644 --- a/src/auth/auth-request-fields.c +++ b/src/auth/auth-request-fields.c @@ -334,7 +334,7 @@ auth_request_fix_username(struct auth_request *request, const char **username, user, &count); if (auth_request_var_expand_with_table(dest, set->username_format, request, - table, NULL, &error) <= 0) { + table, NULL, &error) < 0) { *error_r = t_strdup_printf( "Failed to expand username_format=%s: %s", set->username_format, error); diff --git a/src/auth/auth-request-var-expand.c b/src/auth/auth-request-var-expand.c index 77753ff6ed..f794066144 100644 --- a/src/auth/auth-request-var-expand.c +++ b/src/auth/auth-request-var-expand.c @@ -248,7 +248,7 @@ int auth_request_var_expand_with_table(string_t *dest, const char *str, .event = auth_request->event, }; - return var_expand_new(dest, str, ¶ms, error_r) < 0 ? -1 : 1; + return var_expand_new(dest, str, ¶ms, error_r); } int t_auth_request_var_expand(const char *str, @@ -260,7 +260,7 @@ int t_auth_request_var_expand(const char *str, int ret = auth_request_var_expand(dest, str, auth_request, escape_func, error_r); *value_r = str_c(dest); - return ret < 0 ? ret : 1; + return ret; } static void diff --git a/src/auth/auth-request.c b/src/auth/auth-request.c index cd18337147..9e9bc9c2ac 100644 --- a/src/auth/auth-request.c +++ b/src/auth/auth-request.c @@ -2117,7 +2117,7 @@ auth_request_set_uidgid_file(struct auth_request *request, path = t_str_new(256); if (auth_request_var_expand(path, path_template, request, - NULL, &error) <= 0) { + NULL, &error) < 0) { e_error(authdb_event(request), "Failed to expand uidgid_file=%s: %s", path_template, error); diff --git a/src/auth/db-lua.c b/src/auth/db-lua.c index ffdcf9cbd5..0a0d1b2d09 100644 --- a/src/auth/db-lua.c +++ b/src/auth/db-lua.c @@ -74,7 +74,7 @@ auth_request_lua_do_var_expand(struct auth_request *req, const char *tpl, const char **value_r, const char **error_r) { const char *error; - if (t_auth_request_var_expand(tpl, req, NULL, value_r, &error) <= 0) { + if (t_auth_request_var_expand(tpl, req, NULL, value_r, &error) < 0) { *error_r = t_strdup_printf("var_expand(%s) failed: %s", tpl, error); return -1; diff --git a/src/auth/db-passwd-file.c b/src/auth/db-passwd-file.c index c900958159..dc7219994b 100644 --- a/src/auth/db-passwd-file.c +++ b/src/auth/db-passwd-file.c @@ -503,7 +503,7 @@ int db_passwd_file_lookup(struct db_passwd_file *db, username = t_str_new(256); if (auth_request_var_expand(username, username_format, request, - auth_request_str_escape, &error) <= 0) { + auth_request_str_escape, &error) < 0) { e_error(authdb_event(request), "Failed to expand username_format=%s: %s", username_format, error); diff --git a/src/auth/passdb-passwd-file.c b/src/auth/passdb-passwd-file.c index 897d7ea9f0..0a45f96429 100644 --- a/src/auth/passdb-passwd-file.c +++ b/src/auth/passdb-passwd-file.c @@ -37,7 +37,7 @@ passwd_file_add_extra_fields(struct auth_request *request, key = t_strdup_until(fields[i], value); str_truncate(str, 0); if (auth_request_var_expand_with_table(str, value + 1, - request, table, NULL, &error) <= 0) { + request, table, NULL, &error) < 0) { e_error(authdb_event(request), "Failed to expand extra field %s: %s", fields[i], error); diff --git a/src/auth/test-auth-request-var-expand.c b/src/auth/test-auth-request-var-expand.c index 6a4ba82a70..c49bb7eee9 100644 --- a/src/auth/test-auth-request-var-expand.c +++ b/src/auth/test-auth-request-var-expand.c @@ -233,7 +233,7 @@ static void test_auth_request_var_expand_funcs(void) "%{passdb:pkey2}\n%{passdb:pkey2 | default('default2')}\n" "%{passdb:pkey3|default}\n%{passdb:pkey3 | default('default3')}\n" "%{passdb:ukey1|default}\n%{passdb:ukey1 | default('default4')}\n", - &test_request, test_escape, &value, &error) == 1); + &test_request, test_escape, &value, &error) == 0); test_assert_strcmp(value, "+pval1\n+pval1\n\ndefault2\n\ndefault3\n\ndefault4\n"); test_assert(t_auth_request_var_expand( @@ -241,7 +241,7 @@ static void test_auth_request_var_expand_funcs(void) "%{userdb:ukey2}\n%{userdb:ukey2 | default('default2')}\n" "%{userdb:ukey3|default}\n%{userdb:ukey3 | default('default3')}\n" "%{userdb:pkey1|default}\n%{userdb:pkey1 | default('default4')}\n", - &test_request, test_escape, &value, &error) == 1); + &test_request, test_escape, &value, &error) == 0); test_assert_strcmp(value, "+uval1\n+uval1\n\ndefault2\n\ndefault3\n\ndefault4\n"); pool_unref(&pool); test_end(); diff --git a/src/auth/userdb-passwd-file.c b/src/auth/userdb-passwd-file.c index f6024fa407..94973ba415 100644 --- a/src/auth/userdb-passwd-file.c +++ b/src/auth/userdb-passwd-file.c @@ -49,7 +49,7 @@ passwd_file_add_extra_fields(struct auth_request *request, key = t_strdup_until(key, value); str_truncate(str, 0); if (auth_request_var_expand_with_table(str, value + 1, - request, table, NULL, &error) <= 0) { + request, table, NULL, &error) < 0) { e_error(authdb_event(request), "Failed to expand extra field %s: %s", fields[i], error); -- 2.47.3