dovecot-2.0: auth: Removed unnecessary auth_request callback and...

dovecot at dovecot.org dovecot at dovecot.org
Tue Jun 8 21:34:19 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/94f78f415811
changeset: 11497:94f78f415811
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Jun 08 18:47:24 2010 +0100
description:
auth: Removed unnecessary auth_request callback and context uses.

diffstat:

 src/auth/auth-request-handler.c |  32 ++++++++++++++++++++------------
 src/auth/auth-request-handler.h |  11 +++++++++++
 src/auth/auth-request.c         |  12 +++++-------
 src/auth/auth-request.h         |  10 +++++-----
 src/auth/mech-cram-md5.c        |   4 ++--
 src/auth/mech-digest-md5.c      |  11 +++++------
 src/auth/mech-gssapi.c          |  14 ++++++--------
 src/auth/mech-login.c           |   8 ++++----
 src/auth/mech-ntlm.c            |   5 ++---
 src/auth/mech-otp.c             |   5 ++---
 src/auth/mech-rpa.c             |   9 ++++-----
 src/auth/mech-skey.c            |   5 ++---
 src/auth/mech-winbind.c         |   5 ++---
 src/auth/mech.c                 |   3 +--
 src/auth/mech.h                 |  11 +----------
 15 files changed, 72 insertions(+), 73 deletions(-)

diffs (truncated from 438 to 300 lines):

diff -r 2d6cf78982dc -r 94f78f415811 src/auth/auth-request-handler.c
--- a/src/auth/auth-request-handler.c	Mon Jun 07 21:02:00 2010 +0100
+++ b/src/auth/auth-request-handler.c	Tue Jun 08 18:47:24 2010 +0100
@@ -185,7 +185,7 @@
 auth_request_handle_failure(struct auth_request *request,
 			    struct auth_stream_reply *reply)
 {
-        struct auth_request_handler *handler = request->context;
+        struct auth_request_handler *handler = request->handler;
 
 	if (request->delayed_failure) {
 		/* we came here from flush_failures() */
@@ -222,11 +222,11 @@
 	}
 }
 
-static void auth_callback(struct auth_request *request,
-			  enum auth_client_result result,
-			  const void *auth_reply, size_t reply_size)
+void auth_request_handler_reply(struct auth_request *request,
+				enum auth_client_result result,
+				const void *auth_reply, size_t reply_size)
 {
-        struct auth_request_handler *handler = request->context;
+        struct auth_request_handler *handler = request->handler;
 	struct auth_stream_reply *reply;
 	string_t *str;
 
@@ -294,6 +294,13 @@
         auth_request_handler_unref(&handler);
 }
 
+void auth_request_handler_reply_continue(struct auth_request *request,
+					 const void *reply, size_t reply_size)
+{
+	auth_request_handler_reply(request, AUTH_CLIENT_RESULT_CONTINUE,
+				   reply, reply_size);
+}
+
 static void auth_request_handler_auth_fail(struct auth_request_handler *handler,
 					   struct auth_request *request,
 					   const char *reason)
@@ -381,7 +388,7 @@
 		return FALSE;
 	}
 
-	request = auth_request_new(mech, auth_callback, handler);
+	request = auth_request_new(mech);
 	request->handler = handler;
 	request->connect_uid = handler->connect_uid;
 	request->client_pid = handler->client_pid;
@@ -458,7 +465,8 @@
 		request->initial_response_len = buf->used;
 	}
 
-	/* handler is referenced until auth_callback is called. */
+	/* handler is referenced until auth_request_handler_reply()
+	   is called. */
 	handler->refcount++;
 
 	/* before we start authenticating, see if we need to wait first */
@@ -513,7 +521,8 @@
 		return TRUE;
 	}
 
-	/* handler is referenced until auth_callback is called. */
+	/* handler is referenced until auth_request_handler_reply()
+	   is called. */
 	handler->refcount++;
 	auth_request_continue(request, buf->data, buf->used);
 	return TRUE;
@@ -522,7 +531,7 @@
 static void userdb_callback(enum userdb_result result,
 			    struct auth_request *request)
 {
-        struct auth_request_handler *handler = request->context;
+        struct auth_request_handler *handler = request->handler;
 	struct auth_stream_reply *reply;
 	const char *value;
 
@@ -607,7 +616,6 @@
 		   old client_id with master's id. */
 		auth_request_set_state(request, AUTH_REQUEST_STATE_USERDB);
 		request->id = id;
-		request->context = handler;
 		request->master = master;
 
 		/* master and handler are referenced until userdb_callback i
@@ -655,8 +663,8 @@
 		aqueue_delete_tail(auth_failures);
 
 		i_assert(auth_request->state == AUTH_REQUEST_STATE_FINISHED);
-		auth_request->callback(auth_request,
-				       AUTH_CLIENT_RESULT_FAILURE, NULL, 0);
+		auth_request_handler_reply(auth_request,
+					   AUTH_CLIENT_RESULT_FAILURE, NULL, 0);
 		auth_request_unref(&auth_request);
 	}
 }
diff -r 2d6cf78982dc -r 94f78f415811 src/auth/auth-request-handler.h
--- a/src/auth/auth-request-handler.h	Mon Jun 07 21:02:00 2010 +0100
+++ b/src/auth/auth-request-handler.h	Tue Jun 08 18:47:24 2010 +0100
@@ -5,6 +5,12 @@
 struct auth_master_connection;
 struct auth_stream_reply;
 
+enum auth_client_result {
+	AUTH_CLIENT_RESULT_CONTINUE = 1,
+	AUTH_CLIENT_RESULT_SUCCESS,
+	AUTH_CLIENT_RESULT_FAILURE
+};
+
 typedef void
 auth_request_callback_t(struct auth_stream_reply *reply, void *context);
 
@@ -33,6 +39,11 @@
 				     const char *args);
 bool auth_request_handler_auth_continue(struct auth_request_handler *handler,
 					const char *args);
+void auth_request_handler_reply(struct auth_request *request,
+				enum auth_client_result result,
+				const void *reply, size_t reply_size);
+void auth_request_handler_reply_continue(struct auth_request *request,
+					 const void *reply, size_t reply_size);
 bool auth_request_handler_master_request(struct auth_request_handler *handler,
 					 struct auth_master_connection *master,
 					 unsigned int id,
diff -r 2d6cf78982dc -r 94f78f415811 src/auth/auth-request.c
--- a/src/auth/auth-request.c	Mon Jun 07 21:02:00 2010 +0100
+++ b/src/auth/auth-request.c	Tue Jun 08 18:47:24 2010 +0100
@@ -34,8 +34,7 @@
 static void auth_request_userdb_reply_update_user(struct auth_request *request);
 
 struct auth_request *
-auth_request_new(const struct mech_module *mech,
-		 mech_callback_t *callback, void *context)
+auth_request_new(const struct mech_module *mech)
 {
 	struct auth_request *request;
 
@@ -50,8 +49,6 @@
 	request->set = global_auth_settings;
 	request->mech = mech;
 	request->mech_name = mech == NULL ? NULL : mech->mech_name;
-	request->callback = callback;
-	request->context = context;
 	return request;
 }
 
@@ -116,8 +113,8 @@
 	auth_request_set_state(request, AUTH_REQUEST_STATE_FINISHED);
 	request->successful = TRUE;
 	auth_request_refresh_last_access(request);
-	request->callback(request, AUTH_CLIENT_RESULT_SUCCESS,
-			  data, data_size);
+	auth_request_handler_reply(request, AUTH_CLIENT_RESULT_SUCCESS,
+				   data, data_size);
 }
 
 void auth_request_fail(struct auth_request *request)
@@ -126,7 +123,8 @@
 
 	auth_request_set_state(request, AUTH_REQUEST_STATE_FINISHED);
 	auth_request_refresh_last_access(request);
-	request->callback(request, AUTH_CLIENT_RESULT_FAILURE, NULL, 0);
+	auth_request_handler_reply(request, AUTH_CLIENT_RESULT_FAILURE,
+				   NULL, 0);
 }
 
 void auth_request_internal_failure(struct auth_request *request)
diff -r 2d6cf78982dc -r 94f78f415811 src/auth/auth-request.h
--- a/src/auth/auth-request.h	Mon Jun 07 21:02:00 2010 +0100
+++ b/src/auth/auth-request.h	Tue Jun 08 18:47:24 2010 +0100
@@ -57,11 +57,14 @@
 	struct auth_stream_reply *userdb_reply;
 
 	const struct mech_module *mech;
-	struct auth_request_handler *handler;
 	const struct auth_settings *set;
         struct auth_passdb *passdb;
         struct auth_userdb *userdb;
 
+	/* passdb lookups have a handler, userdb lookups don't */
+	struct auth_request_handler *handler;
+        struct auth_master_connection *master;
+
 	unsigned int connect_uid;
 	unsigned int client_pid;
 	unsigned int id;
@@ -84,9 +87,7 @@
 	} private_callback;
         const char *credentials_scheme;
 
-	mech_callback_t *callback;
 	void *context;
-        struct auth_master_connection *master;
 
 	unsigned int successful:1;
 	unsigned int passdb_failure:1;
@@ -116,8 +117,7 @@
 extern unsigned int auth_request_state_count[AUTH_REQUEST_STATE_MAX];
 
 struct auth_request *
-auth_request_new(const struct mech_module *mech,
-		 mech_callback_t *callback, void *context);
+auth_request_new(const struct mech_module *mech);
 struct auth_request *auth_request_new_dummy(void);
 void auth_request_init(struct auth_request *request);
 struct auth *auth_request_get_auth(struct auth_request *request);
diff -r 2d6cf78982dc -r 94f78f415811 src/auth/mech-cram-md5.c
--- a/src/auth/mech-cram-md5.c	Mon Jun 07 21:02:00 2010 +0100
+++ b/src/auth/mech-cram-md5.c	Tue Jun 08 18:47:24 2010 +0100
@@ -161,8 +161,8 @@
 		(struct cram_auth_request *)auth_request;
 
 	request->challenge = p_strdup(request->pool, get_cram_challenge());
-	auth_request->callback(auth_request, AUTH_CLIENT_RESULT_CONTINUE,
-			       request->challenge, strlen(request->challenge));
+	auth_request_handler_reply_continue(auth_request,  request->challenge,
+					    strlen(request->challenge));
 }
 
 static struct auth_request *mech_cram_md5_auth_new(void)
diff -r 2d6cf78982dc -r 94f78f415811 src/auth/mech-digest-md5.c
--- a/src/auth/mech-digest-md5.c	Mon Jun 07 21:02:00 2010 +0100
+++ b/src/auth/mech-digest-md5.c	Tue Jun 08 18:47:24 2010 +0100
@@ -506,10 +506,9 @@
 		}
 
 		request->authenticated = TRUE;
-		auth_request->callback(auth_request,
-				       AUTH_CLIENT_RESULT_CONTINUE,
-				       request->rspauth,
-				       strlen(request->rspauth));
+		auth_request_handler_reply_continue(auth_request,
+						    request->rspauth,
+						    strlen(request->rspauth));
 		break;
 	case PASSDB_RESULT_INTERNAL_FAILURE:
 		auth_request_internal_failure(auth_request);
@@ -570,8 +569,8 @@
 	/* FIXME: there's no support for subsequent authentication */
 
 	challenge = get_digest_challenge(request);
-	auth_request->callback(auth_request, AUTH_CLIENT_RESULT_CONTINUE,
-			       str_data(challenge), str_len(challenge));
+	auth_request_handler_reply_continue(auth_request, str_data(challenge),
+					    str_len(challenge));
 }
 
 static struct auth_request *mech_digest_md5_auth_new(void)
diff -r 2d6cf78982dc -r 94f78f415811 src/auth/mech-gssapi.c
--- a/src/auth/mech-gssapi.c	Mon Jun 07 21:02:00 2010 +0100
+++ b/src/auth/mech-gssapi.c	Tue Jun 08 18:47:24 2010 +0100
@@ -328,9 +328,9 @@
 	}
 
 	if (ret == 0) {
-		auth_request->callback(auth_request,
-				       AUTH_CLIENT_RESULT_CONTINUE,
-				       output_token.value, output_token.length);
+		auth_request_handler_reply_continue(auth_request,
+						    output_token.value,
+						    output_token.length);
 	}
 	(void)gss_release_buffer(&minor_status, &output_token);
 	return ret;
@@ -370,9 +370,8 @@
 	auth_request_log_debug(&request->auth_request, "gssapi",
 			       "Negotiated security layer");
 
-	request->auth_request.callback(&request->auth_request,
-				       AUTH_CLIENT_RESULT_CONTINUE,
-				       outbuf.value, outbuf.length);
+	auth_request_handler_reply_continue(&request->auth_request,
+					    outbuf.value, outbuf.length);
 
 	(void)gss_release_buffer(&minor_status, &outbuf);
 	request->sasl_gssapi_state = GSS_STATE_UNWRAP;
@@ -597,8 +596,7 @@
 
 	if (data_size == 0) {
 		/* The client should go first */
-		request->callback(request, AUTH_CLIENT_RESULT_CONTINUE,
-				  NULL, 0);
+		auth_request_handler_reply_continue(request, NULL, 0);
 	} else {
 		mech_gssapi_auth_continue(request, data, data_size);
 	}
diff -r 2d6cf78982dc -r 94f78f415811 src/auth/mech-login.c
--- a/src/auth/mech-login.c	Mon Jun 07 21:02:00 2010 +0100
+++ b/src/auth/mech-login.c	Tue Jun 08 18:47:24 2010 +0100
@@ -29,8 +29,8 @@
 			return;
 		}
 
-		request->callback(request, AUTH_CLIENT_RESULT_CONTINUE,
-				  prompt2, strlen(prompt2));
+		auth_request_handler_reply_continue(request, prompt2,
+						    strlen(prompt2));


More information about the dovecot-cvs mailing list