changeset 3185:3089083e1d47 HEAD

Handle USER requests from master connections.
author Timo Sirainen <tss@iki.fi>
date Mon, 07 Mar 2005 22:21:52 +0200
parents c59506c04088
children 31313e1fe036
files src/auth/auth-master-connection.c src/auth/auth-request.c src/auth/auth-request.h src/auth/auth-worker-client.c
diffstat 4 files changed, 67 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/auth/auth-master-connection.c	Mon Mar 07 21:16:15 2005 +0200
+++ b/src/auth/auth-master-connection.c	Mon Mar 07 22:21:52 2005 +0200
@@ -86,6 +86,44 @@
 	return TRUE;
 }
 
+static void
+user_callback(const char *result, struct auth_request *auth_request)
+{
+	struct auth_master_connection *conn = auth_request->context;
+	string_t *str;
+
+	str = t_str_new(128);
+	if (result == NULL)
+		str_printfa(str, "NOTFOUND\t%u\n", auth_request->id);
+	else {
+		str_printfa(str, "USER\t%u\t", auth_request->id);
+		str_append(str, result);
+		str_append_c(str, '\n');
+	}
+	(void)o_stream_send(conn->output, str_data(str), str_len(str));
+}
+
+static int
+master_input_user(struct auth_master_connection *conn, const char *args)
+{
+	struct auth_request *auth_request;
+	const char *const *list;
+
+	/* <id> <userid> */
+	list = t_strsplit(args, "\t");
+	if (list[0] == NULL || list[1] == NULL) {
+		i_error("BUG: Master sent broken USER");
+		return FALSE;
+	}
+
+	auth_request = auth_request_new_dummy(conn->auth);
+	auth_request->id = (unsigned int)strtoul(list[0], NULL, 10);
+	auth_request->user = p_strdup(auth_request->pool, list[1]);
+	auth_request->context = conn;
+	auth_request_lookup_user(auth_request, user_callback);
+	return TRUE;
+}
+
 static int
 master_input_die(struct auth_master_connection *conn)
 {
@@ -137,6 +175,8 @@
 		t_push();
 		if (strncmp(line, "REQUEST\t", 8) == 0)
 			ret = master_input_request(conn, line + 8);
+		else if (strncmp(line, "USER\t", 5) == 0)
+			ret = master_input_user(conn, line + 5);
 		else if (strcmp(line, "DIE") == 0)
 			ret = master_input_die(conn);
 		else {
--- a/src/auth/auth-request.c	Mon Mar 07 21:16:15 2005 +0200
+++ b/src/auth/auth-request.c	Mon Mar 07 22:21:52 2005 +0200
@@ -37,6 +37,24 @@
 	return request;
 }
 
+struct auth_request *auth_request_new_dummy(struct auth *auth)
+{
+	struct auth_request *auth_request;
+	pool_t pool;
+
+	pool = pool_alloconly_create("auth_request", 256);
+	auth_request = p_new(pool, struct auth_request, 1);
+	auth_request->pool = pool;
+
+	auth_request->refcount = 1;
+	auth_request->created = ioloop_time;
+	auth_request->auth = auth;
+	auth_request->passdb = auth->passdbs;
+	auth_request->userdb = auth->userdbs;
+
+	return auth_request;
+}
+
 void auth_request_success(struct auth_request *request,
 			  const void *data, size_t data_size)
 {
--- a/src/auth/auth-request.h	Mon Mar 07 21:16:15 2005 +0200
+++ b/src/auth/auth-request.h	Mon Mar 07 22:21:52 2005 +0200
@@ -62,6 +62,7 @@
 struct auth_request *
 auth_request_new(struct auth *auth, struct mech_module *mech,
 		 mech_callback_t *callback, void *context);
+struct auth_request *auth_request_new_dummy(struct auth *auth);
 void auth_request_ref(struct auth_request *request);
 int auth_request_unref(struct auth_request *request);
 
--- a/src/auth/auth-worker-client.c	Mon Mar 07 21:16:15 2005 +0200
+++ b/src/auth/auth-worker-client.c	Mon Mar 07 22:21:52 2005 +0200
@@ -45,17 +45,8 @@
 {
 	struct auth_request *auth_request;
 	const char *key, *value, *const *tmp;
-	pool_t pool;
 
-	pool = pool_alloconly_create("auth_request", 256);
-	auth_request = p_new(pool, struct auth_request, 1);
-	auth_request->pool = pool;
-
-	auth_request->refcount = 1;
-	auth_request->created = ioloop_time;
-	auth_request->auth = client->auth;
-	auth_request->passdb = client->auth->passdbs;
-	auth_request->userdb = client->auth->userdbs;
+	auth_request = auth_request_new_dummy(client->auth);
 
 	client->refcount++;
 	auth_request->context = client;
@@ -70,11 +61,13 @@
 		key = t_strdup_until(*tmp, value);
 		value++;
 
-		if (strcmp(key, "user") == 0)
-			auth_request->user = p_strdup(pool, value);
-		else if (strcmp(key, "service") == 0)
-			auth_request->service = p_strdup(pool, value);
-		else if (strcmp(key, "lip") == 0)
+		if (strcmp(key, "user") == 0) {
+			auth_request->user =
+				p_strdup(auth_request->pool, value);
+		} else if (strcmp(key, "service") == 0) {
+			auth_request->service =
+				p_strdup(auth_request->pool, value);
+		} else if (strcmp(key, "lip") == 0)
 			net_addr2ip(value, &auth_request->local_ip);
 		else if (strcmp(key, "rip") == 0)
 			net_addr2ip(value, &auth_request->remote_ip);