From: Aki Tuomi Date: Mon, 8 Jan 2018 12:52:10 +0000 (+0200) Subject: auth-worker: Add auth_worker_auth_request_new X-Git-Tag: 2.2.35~114 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e5f934e76ae1c9c53b42aed16c76e44a795c70ae;p=thirdparty%2Fdovecot%2Fcore.git auth-worker: Add auth_worker_auth_request_new Replaces worker_auth_request_new, moves in check for username and service. Simplifies code. --- diff --git a/src/auth/auth-worker-client.c b/src/auth/auth-worker-client.c index c520bba5cf..a99b3d0343 100644 --- a/src/auth/auth-worker-client.c +++ b/src/auth/auth-worker-client.c @@ -76,9 +76,8 @@ auth_worker_client_check_throttle(struct auth_worker_client *client) } } -static struct auth_request * -worker_auth_request_new(struct auth_worker_client *client, unsigned int id, - const char *const *args) +bool auth_worker_auth_request_new(struct auth_worker_client *client, unsigned int id, + const char *const *args, struct auth_request **request_r) { struct auth_request *auth_request; const char *key, *value; @@ -98,6 +97,11 @@ worker_auth_request_new(struct auth_worker_client *client, unsigned int id, (void)auth_request_import(auth_request, key, value); } } + if (auth_request->user == NULL || auth_request->service == NULL) { + auth_request_unref(&auth_request); + return FALSE; + } + /* reset changed-fields, so we'll export only the ones that were changed by this lookup. */ auth_fields_snapshot(auth_request->extra_fields); @@ -105,7 +109,9 @@ worker_auth_request_new(struct auth_worker_client *client, unsigned int id, auth_fields_snapshot(auth_request->userdb_reply); auth_request_init(auth_request); - return auth_request; + *request_r = auth_request; + + return TRUE; } static void auth_worker_send_reply(struct auth_worker_client *client, @@ -202,15 +208,12 @@ auth_worker_handle_passv(struct auth_worker_client *client, } password = args[1]; - auth_request = worker_auth_request_new(client, id, args + 2); - auth_request->mech_password = - p_strdup(auth_request->pool, password); - - if (auth_request->user == NULL || auth_request->service == NULL) { - i_error("BUG: PASSV had missing parameters"); - auth_request_unref(&auth_request); + if (!auth_worker_auth_request_new(client, id, args + 2, &auth_request)) { + i_error("BUG: Auth worker server sent us invalid PASSV"); return FALSE; } + auth_request->mech_password = + p_strdup(auth_request->pool, password); passdb = auth_request->passdb; while (passdb != NULL && passdb->passdb->id != passdb_id) @@ -291,14 +294,11 @@ auth_worker_handle_passl(struct auth_worker_client *client, } scheme = args[1]; - auth_request = worker_auth_request_new(client, id, args + 2); - auth_request->credentials_scheme = p_strdup(auth_request->pool, scheme); - - if (auth_request->user == NULL || auth_request->service == NULL) { + if (!auth_worker_auth_request_new(client, id, args + 2, &auth_request)) { i_error("BUG: PASSL had missing parameters"); - auth_request_unref(&auth_request); return FALSE; } + auth_request->credentials_scheme = p_strdup(auth_request->pool, scheme); while (auth_request->passdb->passdb->id != passdb_id) { auth_request->passdb = auth_request->passdb->next; @@ -352,10 +352,8 @@ auth_worker_handle_setcred(struct auth_worker_client *client, } creds = args[1]; - auth_request = worker_auth_request_new(client, id, args + 2); - if (auth_request->user == NULL || auth_request->service == NULL) { + if (!auth_worker_auth_request_new(client, id, args + 2, &auth_request)) { i_error("BUG: SETCRED had missing parameters"); - auth_request_unref(&auth_request); return FALSE; } @@ -437,10 +435,8 @@ auth_worker_handle_user(struct auth_worker_client *client, return FALSE; } - auth_request = worker_auth_request_new(client, id, args + 1); - if (auth_request->user == NULL || auth_request->service == NULL) { + if (!auth_worker_auth_request_new(client, id, args + 1, &auth_request)) { i_error("BUG: USER had missing parameters"); - auth_request_unref(&auth_request); return FALSE; } @@ -593,15 +589,12 @@ auth_worker_handle_list(struct auth_worker_client *client, ctx = i_new(struct auth_worker_list_context, 1); ctx->client = client; - ctx->auth_request = worker_auth_request_new(client, id, args + 1); - ctx->auth_request->userdb = userdb; - if (ctx->auth_request->user == NULL || - ctx->auth_request->service == NULL) { + if (!auth_worker_auth_request_new(client, id, args + 1, &ctx->auth_request)) { i_error("BUG: LIST had missing parameters"); - auth_request_unref(&ctx->auth_request); i_free(ctx); return FALSE; } + ctx->auth_request->userdb = userdb; io_remove(&ctx->client->io); if (ctx->client->to_idle != NULL) diff --git a/src/auth/auth-worker-client.h b/src/auth/auth-worker-client.h index 4d6f1fcf40..513c960f74 100644 --- a/src/auth/auth-worker-client.h +++ b/src/auth/auth-worker-client.h @@ -8,6 +8,8 @@ extern struct auth_worker_client *auth_worker_client; struct auth_worker_client *auth_worker_client_create(struct auth *auth, int fd); +bool auth_worker_auth_request_new(struct auth_worker_client *client, unsigned int id, + const char *const *args, struct auth_request **request_r); void auth_worker_client_destroy(struct auth_worker_client **client); void auth_worker_client_unref(struct auth_worker_client **client);