From: Stephan Bosch Date: Mon, 18 May 2020 21:46:54 +0000 (+0200) Subject: lib-auth-client: auth-master - Split off auth_master_pass_lookup_finished() from... X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=392adbc833217563974576fcf9f8c6eabeaaafdb;p=thirdparty%2Fdovecot%2Fcore.git lib-auth-client: auth-master - Split off auth_master_pass_lookup_finished() from auth_master_pass_lookup() --- diff --git a/src/lib-auth-client/auth-master.c b/src/lib-auth-client/auth-master.c index 28d1488e6e..d57f738f26 100644 --- a/src/lib-auth-client/auth-master.c +++ b/src/lib-auth-client/auth-master.c @@ -921,6 +921,26 @@ auth_lookup_reply_callback(const struct auth_master_reply *reply, /* PASS */ +struct auth_master_pass_lookup_ctx { + pool_t pool; + + int result; + const char *const *fields; +}; + +static void +auth_master_pass_lookup_callback(struct auth_master_pass_lookup_ctx *ctx, + int result, const char *const *fields) +{ + ctx->result = result; + ctx->fields = p_strarray_dup(ctx->pool, fields); +} + +static void +auth_master_pass_lookup_finished(struct auth_master_lookup *_lookup, + int result, const char *const *fields, + struct auth_master_pass_lookup_ctx *ctx); + int auth_master_pass_lookup(struct auth_master_connection *conn, const char *user, const struct auth_user_info *info, pool_t pool, const char *const **fields_r) @@ -939,6 +959,11 @@ int auth_master_pass_lookup(struct auth_master_connection *conn, return -1; } + struct auth_master_pass_lookup_ctx ctx = { + .pool = pool, + .result = -1, + }; + i_zero(&lookup); lookup.conn = conn; lookup.return_value = -1; @@ -965,31 +990,42 @@ int auth_master_pass_lookup(struct auth_master_connection *conn, auth_master_request_set_event(req, lookup.event); (void)auth_master_request_wait(req); - *fields_r = lookup.fields != NULL ? lookup.fields : + auth_master_pass_lookup_finished(&lookup, lookup.return_value, + lookup.fields, &ctx); + event_unref(&lookup.event); + + *fields_r = ctx.fields != NULL ? ctx.fields : p_new(pool, const char *, 1); + return ctx.result; + +} - if (lookup.return_value <= 0) { +static void +auth_master_pass_lookup_finished(struct auth_master_lookup *_lookup, + int result, const char *const *fields, + struct auth_master_pass_lookup_ctx *ctx) +{ + if (result <= 0) { struct event_passthrough *e = - event_create_passthrough(lookup.event)-> + event_create_passthrough(_lookup->event)-> set_name("auth_client_passdb_lookup_finished"); - if ((*fields_r)[0] == NULL) { + if (fields == NULL || fields[0] == NULL) { e->add_str("error", "Lookup failed"); e_debug(e->event(), "Passdb lookup failed"); } else { - e->add_str("error", (*fields_r)[0]); + e->add_str("error", fields[0]); e_debug(e->event(), "Passdb lookup failed: %s", - (*fields_r)[0]); + fields[0]); } } else { struct event_passthrough *e = - event_create_passthrough(lookup.event)-> + event_create_passthrough(_lookup->event)-> set_name("auth_client_passdb_lookup_finished"); e_debug(e->event(), "Finished passdb lookup (%s)", - t_strarray_join(*fields_r, " ")); + (fields == NULL ? "" : t_strarray_join(fields, " "))); } - event_unref(&lookup.event); - return lookup.return_value; + auth_master_pass_lookup_callback(ctx, result, fields); } /*