[Dovecot] [PATCH, RFC 9/13] OTP: add blocking passdb support

Andrey Panin pazke at donpac.ru
Mon Jun 26 15:58:14 EEST 2006


Add set_credentials support to blocking passdb support code.

diff -urdpNX /usr/share/dontdiff -x Makefile dovecot.vanilla/src/auth/auth-worker-client.c dovecot/src/auth/auth-worker-client.c
--- dovecot.vanilla/src/auth/auth-worker-client.c	2006-06-23 13:42:22.123507928 +0400
+++ dovecot/src/auth/auth-worker-client.c	2006-06-23 13:44:31.543833048 +0400
@@ -228,6 +228,72 @@ auth_worker_handle_passl(struct auth_wor
 }
 
 static void
+set_credentials_callback(enum passdb_result result,
+			 struct auth_request *request)
+{
+	struct auth_worker_client *client = request->context;
+
+	string_t *str;
+
+	str = t_str_new(64);
+	str_printfa(str, "%u\t", request->id);
+
+	if (result != PASSDB_RESULT_OK)
+		str_printfa(str, "FAIL\t%d\t", result);
+	else {
+		str_printfa(str, "OK\t%s\t", request->user);
+	}
+	str_append_c(str, '\n');
+	o_stream_send(client->output, str_data(str), str_len(str));
+
+	auth_request_unref(&request);
+	auth_worker_client_check_throttle(client);
+	auth_worker_client_unref(&client);
+}
+
+static void
+auth_worker_handle_passs(struct auth_worker_client *client,
+			 unsigned int id, const char *args)
+{
+	struct auth_request *auth_request;
+	unsigned int passdb_id;
+	const char *data;
+
+	passdb_id = atoi(t_strcut(args, '\t'));
+	args = strchr(args, '\t');
+	if (args == NULL) {
+		i_error("BUG: Auth worker server sent us invalid PASSS");
+		return;
+	}
+	args++;
+
+	data = t_strcut(args, '\t');
+	args = strchr(args, '\t');
+	if (args != NULL) args++;
+
+	auth_request = worker_auth_request_new(client, id, args);
+
+	if (auth_request->user == NULL || auth_request->service == NULL) {
+		i_error("BUG: PASSS had missing parameters");
+		auth_request_unref(&auth_request);
+		return;
+	}
+
+	while (auth_request->passdb->id != passdb_id) {
+		auth_request->passdb = auth_request->passdb->next;
+		if (auth_request->passdb == NULL) {
+			i_error("BUG: PASSS had invalid passdb ID");
+			auth_request_unref(&auth_request);
+			return;
+		}
+	}
+
+	auth_request->passdb->passdb->iface.
+		set_credentials(auth_request,
+				data, set_credentials_callback);
+}
+
+static void
 lookup_user_callback(struct auth_stream_reply *reply,
 		     struct auth_request *auth_request)
 {
@@ -297,6 +363,8 @@ auth_worker_handle_line(struct auth_work
 		auth_worker_handle_passv(client, id, line + 6);
 	else if (strncmp(line, "PASSL\t", 6) == 0)
 		auth_worker_handle_passl(client, id, line + 6);
+	else if (strncmp(line, "PASSS\t", 6) == 0)
+		auth_worker_handle_passs(client, id, line + 6);
 	else if (strncmp(line, "USER\t", 5) == 0)
 		auth_worker_handle_user(client, id, line + 5);
 
diff -urdpNX /usr/share/dontdiff -x Makefile dovecot.vanilla/src/auth/passdb-blocking.c dovecot/src/auth/passdb-blocking.c
--- dovecot.vanilla/src/auth/passdb-blocking.c	2006-06-23 13:42:22.124507776 +0400
+++ dovecot/src/auth/passdb-blocking.c	2006-06-23 13:44:31.543833048 +0400
@@ -157,3 +157,24 @@ void passdb_blocking_lookup_credentials(
 
 	auth_worker_call(request, str_c(str), lookup_credentials_callback);
 }
+
+static void
+set_credentials_callback(struct auth_request *request, const char *reply)
+{
+	enum passdb_result result = check_failure(request, &reply);
+
+	request->private_callback.set_credentials(result, request);
+}
+
+void passdb_blocking_set_credentials(struct auth_request *request,
+				     const char *new_credentials)
+{
+	string_t *str;
+
+	str = t_str_new(64);
+	str_printfa(str, "PASSS\t%u\t%s\t",
+		    request->passdb->id, new_credentials);
+	auth_request_export(request, str);
+
+	auth_worker_call(request, str_c(str), set_credentials_callback);
+}
diff -urdpNX /usr/share/dontdiff -x Makefile dovecot.vanilla/src/auth/passdb-blocking.h dovecot/src/auth/passdb-blocking.h
--- dovecot.vanilla/src/auth/passdb-blocking.h	2006-06-23 13:42:22.124507776 +0400
+++ dovecot/src/auth/passdb-blocking.h	2006-06-23 13:44:31.544832896 +0400
@@ -3,5 +3,7 @@
 
 void passdb_blocking_verify_plain(struct auth_request *request);
 void passdb_blocking_lookup_credentials(struct auth_request *request);
+void passdb_blocking_set_credentials(struct auth_request *request,
+				     const char *new_credentials);
 
 #endif



More information about the dovecot mailing list