dovecot-2.2: auth: Code cleanup: Removed unnecessary auth_stream...

dovecot at dovecot.org dovecot at dovecot.org
Wed Jan 30 19:08:08 EET 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/55d20120b348
changeset: 15680:55d20120b348
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Jan 30 18:35:02 2013 +0200
description:
auth: Code cleanup: Removed unnecessary auth_stream_reply usage from auth-worker communication.

diffstat:

 src/auth/auth-request.c       |  52 +++++++++++++++------------
 src/auth/auth-request.h       |   3 +-
 src/auth/auth-stream.c        |   6 +++
 src/auth/auth-stream.h        |   2 +
 src/auth/auth-worker-client.c |  81 +++++++++++++++++-------------------------
 src/auth/auth-worker-server.c |  10 ++--
 src/auth/auth-worker-server.h |   2 +-
 src/auth/passdb-blocking.c    |  44 ++++++++++++-----------
 src/auth/userdb-blocking.c    |  23 +++++------
 9 files changed, 110 insertions(+), 113 deletions(-)

diffs (truncated from 456 to 300 lines):

diff -r 0897fc01fb93 -r 55d20120b348 src/auth/auth-request.c
--- a/src/auth/auth-request.c	Wed Jan 30 18:12:23 2013 +0200
+++ b/src/auth/auth-request.c	Wed Jan 30 18:35:02 2013 +0200
@@ -187,49 +187,55 @@
 		pool_unref(&request->pool);
 }
 
-void auth_request_export(struct auth_request *request,
-			 struct auth_stream_reply *reply)
+static void
+auth_str_add_keyvalue(string_t *dest, const char *key, const char *value)
 {
-	auth_stream_reply_add(reply, "user", request->user);
-	auth_stream_reply_add(reply, "service", request->service);
+	str_append_c(dest, '\t');
+	str_append(dest, key);
+	str_append_c(dest, '=');
+	str_append_tabescaped(dest, value);
+}
+
+void auth_request_export(struct auth_request *request, string_t *dest)
+{
+	str_append(dest, "user=");
+	str_append_tabescaped(dest, request->user);
+
+	auth_str_add_keyvalue(dest, "service", request->service);
 
         if (request->master_user != NULL) {
-		auth_stream_reply_add(reply, "master_user",
+		auth_str_add_keyvalue(dest, "master_user",
 				      request->master_user);
 	}
-	auth_stream_reply_add(reply, "original_username",
+	auth_str_add_keyvalue(dest, "original_username",
 			      request->original_username);
-	auth_stream_reply_add(reply, "requested_login_user",
+	auth_str_add_keyvalue(dest, "requested_login_user",
 			      request->requested_login_user);
 
 	if (request->local_ip.family != 0) {
-		auth_stream_reply_add(reply, "lip",
+		auth_str_add_keyvalue(dest, "lip",
 				      net_ip2addr(&request->local_ip));
 	}
 	if (request->remote_ip.family != 0) {
-		auth_stream_reply_add(reply, "rip",
+		auth_str_add_keyvalue(dest, "rip",
 				      net_ip2addr(&request->remote_ip));
 	}
-	if (request->local_port != 0) {
-		auth_stream_reply_add(reply, "lport",
-				      dec2str(request->local_port));
-	}
-	if (request->remote_port != 0) {
-		auth_stream_reply_add(reply, "rport",
-				      dec2str(request->remote_port));
-	}
+	if (request->local_port != 0)
+		str_printfa(dest, "\tlport=%u", request->local_port);
+	if (request->remote_port != 0)
+		str_printfa(dest, "\trport=%u", request->remote_port);
 	if (request->secured)
-		auth_stream_reply_add(reply, "secured", "1");
+		str_append(dest, "\tsecured");
 	if (request->skip_password_check)
-		auth_stream_reply_add(reply, "skip_password_check", "1");
+		str_append(dest, "\tskip_password_check");
 	if (request->valid_client_cert)
-		auth_stream_reply_add(reply, "valid-client-cert", "1");
+		str_append(dest, "\tvalid-client-cert");
 	if (request->no_penalty)
-		auth_stream_reply_add(reply, "no-penalty", "1");
+		str_append(dest, "\tno-penalty");
 	if (request->successful)
-		auth_stream_reply_add(reply, "successful", "1");
+		str_append(dest, "\tsuccessful");
 	if (request->mech_name != NULL)
-		auth_stream_reply_add(reply, "mech", request->mech_name);
+		auth_str_add_keyvalue(dest, "mech", request->mech_name);
 }
 
 bool auth_request_import_info(struct auth_request *request,
diff -r 0897fc01fb93 -r 55d20120b348 src/auth/auth-request.h
--- a/src/auth/auth-request.h	Wed Jan 30 18:12:23 2013 +0200
+++ b/src/auth/auth-request.h	Wed Jan 30 18:35:02 2013 +0200
@@ -151,8 +151,7 @@
 void auth_request_fail(struct auth_request *request);
 void auth_request_internal_failure(struct auth_request *request);
 
-void auth_request_export(struct auth_request *request,
-			 struct auth_stream_reply *reply);
+void auth_request_export(struct auth_request *request, string_t *dest);
 bool auth_request_import(struct auth_request *request,
 			 const char *key, const char *value);
 bool auth_request_import_info(struct auth_request *request,
diff -r 0897fc01fb93 -r 55d20120b348 src/auth/auth-stream.c
--- a/src/auth/auth-stream.c	Wed Jan 30 18:12:23 2013 +0200
+++ b/src/auth/auth-stream.c	Wed Jan 30 18:35:02 2013 +0200
@@ -133,6 +133,12 @@
 	return str_c(reply->str);
 }
 
+void auth_stream_reply_append(struct auth_stream_reply *reply,
+			      string_t *dest)
+{
+	str_append_str(dest, reply->str);
+}
+
 bool auth_stream_is_empty(struct auth_stream_reply *reply)
 {
 	return reply == NULL || str_len(reply->str) == 0;
diff -r 0897fc01fb93 -r 55d20120b348 src/auth/auth-stream.h
--- a/src/auth/auth-stream.h	Wed Jan 30 18:12:23 2013 +0200
+++ b/src/auth/auth-stream.h	Wed Jan 30 18:35:02 2013 +0200
@@ -15,6 +15,8 @@
 
 void auth_stream_reply_import(struct auth_stream_reply *reply, const char *str);
 const char *auth_stream_reply_export(struct auth_stream_reply *reply);
+void auth_stream_reply_append(struct auth_stream_reply *reply,
+			      string_t *dest);
 bool auth_stream_is_empty(struct auth_stream_reply *reply);
 
 string_t *auth_stream_reply_get_str(struct auth_stream_reply *reply);
diff -r 0897fc01fb93 -r 55d20120b348 src/auth/auth-worker-client.c
--- a/src/auth/auth-worker-client.c	Wed Jan 30 18:12:23 2013 +0200
+++ b/src/auth/auth-worker-client.c	Wed Jan 30 18:35:02 2013 +0200
@@ -8,6 +8,7 @@
 #include "ostream.h"
 #include "hex-binary.h"
 #include "str.h"
+#include "strescape.h"
 #include "process-title.h"
 #include "master-service.h"
 #include "auth-request.h"
@@ -110,39 +111,33 @@
 				  struct auth_request *request)
 {
 	struct auth_worker_client *client = request->context;
-	struct auth_stream_reply *reply;
 	string_t *str;
 
 	if (request->passdb_failure && result == PASSDB_RESULT_OK)
 		result = PASSDB_RESULT_PASSWORD_MISMATCH;
 
-	reply = auth_stream_reply_init(pool_datastack_create());
-	auth_stream_reply_add(reply, NULL, dec2str(request->id));
+	str = t_str_new(128);
+	str_printfa(str, "%u\t", request->id);
 
 	if (result == PASSDB_RESULT_OK)
-		auth_stream_reply_add(reply, "OK", NULL);
-	else {
-		auth_stream_reply_add(reply, "FAIL", NULL);
-		auth_stream_reply_add(reply, NULL,
-				      t_strdup_printf("%d", result));
-	}
+		str_append(str, "OK");
+	else
+		str_printfa(str, "FAIL\t%d", result);
 	if (result != PASSDB_RESULT_INTERNAL_FAILURE) {
-		auth_stream_reply_add(reply, NULL, request->user);
-		auth_stream_reply_add(reply, NULL,
-				      request->passdb_password == NULL ? "" :
-				      request->passdb_password);
-		if (request->extra_fields != NULL) {
-			const char *fields =
-				auth_stream_reply_export(request->extra_fields);
-			auth_stream_reply_import(reply, fields);
+		str_append_c(str, '\t');
+		str_append_tabescaped(str, request->user);
+		str_append_c(str, '\t');
+		if (request->passdb_password != NULL)
+			str_append_tabescaped(str, request->passdb_password);
+		if (!auth_stream_is_empty(request->extra_fields)) {
+			str_append_c(str, '\t');
+			auth_stream_reply_append(request->extra_fields, str);
 		}
-		if (request->extra_cache_fields != NULL) {
-			const char *fields =
-				auth_stream_reply_export(request->extra_cache_fields);
-			auth_stream_reply_import(reply, fields);
+		if (!auth_stream_is_empty(request->extra_cache_fields)) {
+			str_append_c(str, '\t');
+			auth_stream_reply_append(request->extra_cache_fields, str);
 		}
 	}
-	str = auth_stream_reply_get_str(reply);
 	str_append_c(str, '\n');
 	auth_worker_send_reply(client, str);
 
@@ -207,40 +202,31 @@
 			    struct auth_request *request)
 {
 	struct auth_worker_client *client = request->context;
-	struct auth_stream_reply *reply;
 	string_t *str;
 
 	if (request->passdb_failure && result == PASSDB_RESULT_OK)
 		result = PASSDB_RESULT_PASSWORD_MISMATCH;
 
-	reply = auth_stream_reply_init(pool_datastack_create());
-	auth_stream_reply_add(reply, NULL, dec2str(request->id));
+	str = t_str_new(128);
+	str_printfa(str, "%u\t", request->id);
 
-	if (result != PASSDB_RESULT_OK) {
-		auth_stream_reply_add(reply, "FAIL", NULL);
-		auth_stream_reply_add(reply, NULL,
-				      t_strdup_printf("%d", result));
-	} else {
-		auth_stream_reply_add(reply, "OK", NULL);
-		auth_stream_reply_add(reply, NULL, request->user);
+	if (result != PASSDB_RESULT_OK)
+		str_printfa(str, "FAIL\t%d", result);
+	else {
+		str_append(str, "OK\t");
+		str_append_tabescaped(str, request->user);
+		str_printfa(str, "\t{%s.b64}", request->credentials_scheme);
+		base64_encode(credentials, size, str);
 
-		str = t_str_new(64);
-		str_printfa(str, "{%s.b64}", request->credentials_scheme);
-		base64_encode(credentials, size, str);
-		auth_stream_reply_add(reply, NULL, str_c(str));
-
-		if (request->extra_fields != NULL) {
-			const char *fields =
-				auth_stream_reply_export(request->extra_fields);
-			auth_stream_reply_import(reply, fields);
+		if (!auth_stream_is_empty(request->extra_fields)) {
+			str_append_c(str, '\t');
+			auth_stream_reply_append(request->extra_fields, str);
 		}
-		if (request->extra_cache_fields != NULL) {
-			const char *fields =
-				auth_stream_reply_export(request->extra_cache_fields);
-			auth_stream_reply_import(reply, fields);
+		if (!auth_stream_is_empty(request->extra_cache_fields)) {
+			str_append_c(str, '\t');
+			auth_stream_reply_append(request->extra_cache_fields, str);
 		}
 	}
-	str = auth_stream_reply_get_str(reply);
 	str_append_c(str, '\n');
 	auth_worker_send_reply(client, str);
 
@@ -352,7 +338,6 @@
 		     struct auth_request *auth_request)
 {
 	struct auth_worker_client *client = auth_request->context;
-	struct auth_stream_reply *reply = auth_request->userdb_reply;
 	string_t *str;
 
 	str = t_str_new(128);
@@ -366,7 +351,7 @@
 		break;
 	case USERDB_RESULT_OK:
 		str_append(str, "OK\t");
-		str_append(str, auth_stream_reply_export(reply));
+		auth_stream_reply_append(auth_request->userdb_reply, str);
 		if (auth_request->userdb_lookup_failed)
 			str_append(str, "\ttempfail");
 		break;
diff -r 0897fc01fb93 -r 55d20120b348 src/auth/auth-worker-server.c
--- a/src/auth/auth-worker-server.c	Wed Jan 30 18:12:23 2013 +0200
+++ b/src/auth/auth-worker-server.c	Wed Jan 30 18:35:02 2013 +0200
@@ -25,7 +25,7 @@
 struct auth_worker_request {
 	unsigned int id;
 	time_t created;
-	const char *data_str;
+	const char *data;
 	auth_worker_callback_t *callback;
 	void *context;
 };
@@ -96,8 +96,8 @@
 
 	iov[0].iov_base = t_strdup_printf("%d\t", request->id);
 	iov[0].iov_len = strlen(iov[0].iov_base);
-	iov[1].iov_base = request->data_str;
-	iov[1].iov_len = strlen(request->data_str);
+	iov[1].iov_base = request->data;
+	iov[1].iov_len = strlen(request->data);
 	iov[2].iov_base = "\n";
 	iov[2].iov_len = 1;
 
@@ -387,7 +387,7 @@
 }
 
 struct auth_worker_connection *
-auth_worker_call(pool_t pool, struct auth_stream_reply *data,
+auth_worker_call(pool_t pool, const char *data,
 		 auth_worker_callback_t *callback, void *context)
 {
 	struct auth_worker_connection *conn;
@@ -395,7 +395,7 @@
 
 	request = p_new(pool, struct auth_worker_request, 1);
 	request->created = ioloop_time;
-	request->data_str = p_strdup(pool, auth_stream_reply_export(data));


More information about the dovecot-cvs mailing list