annotate src/auth/auth-master-connection.c @ 4800:f24a1e1c8310 HEAD

Removed "DIE" command from auth protocol. It wasn't implemented, and I'm not sure if it's such a good idea anyway.
author Timo Sirainen <tss@iki.fi>
date Sun, 12 Nov 2006 21:54:26 +0200
parents 9202ffe3d5c5
children 4ec6a4def05b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 /* Copyright (C) 2002 Timo Sirainen */
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "common.h"
3470
346a494c2feb Moved array declaration to array-decl.h and include it in lib.h. So array.h
Timo Sirainen <tss@iki.fi>
parents: 3386
diff changeset
4 #include "array.h"
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "buffer.h"
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "hash.h"
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
7 #include "str.h"
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "ioloop.h"
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
9 #include "istream.h"
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #include "ostream.h"
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include "network.h"
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 #include "userdb.h"
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
13 #include "auth-request-handler.h"
2776
150f8151c971 Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents: 2754
diff changeset
14 #include "auth-master-interface.h"
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 #include "auth-client-connection.h"
3308
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3307
diff changeset
16 #include "auth-master-listener.h"
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 #include "auth-master-connection.h"
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18
2075
5138b14889a6 dovecot-auth can now be run by itself, it listens in UNIX sockets specified
Timo Sirainen <tss@iki.fi>
parents: 2057
diff changeset
19 #include <unistd.h>
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
20 #include <stdlib.h>
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
22 #define MAX_INBUF_SIZE 1024
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
23 #define MAX_OUTBUF_SIZE (1024*50)
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 struct master_userdb_request {
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26 struct auth_master_connection *conn;
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
27 unsigned int id;
2754
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents: 2738
diff changeset
28 struct auth_request *auth_request;
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29 };
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30
2790
02c0b8d532c2 Changed ostream's flush callback to have return value which can tell if
Timo Sirainen <tss@iki.fi>
parents: 2776
diff changeset
31 static int master_output(void *context);
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
33 void auth_master_request_callback(const char *reply, void *context)
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 {
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
35 struct auth_master_connection *conn = context;
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
36 struct const_iovec iov[2];
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37
3308
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3307
diff changeset
38 if (conn->listener->auth->verbose_debug)
3158
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3080
diff changeset
39 i_info("master out: %s", reply);
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3080
diff changeset
40
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
41 iov[0].iov_base = reply;
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
42 iov[0].iov_len = strlen(reply);
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
43 iov[1].iov_base = "\n";
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
44 iov[1].iov_len = 1;
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
46 (void)o_stream_sendv(conn->output, iov, 2);
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 }
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3640
diff changeset
49 static bool
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
50 master_input_request(struct auth_master_connection *conn, const char *args)
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 {
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52 struct auth_client_connection *client_conn;
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
53 const char *const *list;
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
54 unsigned int id, client_pid, client_id;
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
56 /* <id> <client-pid> <client-id> */
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
57 list = t_strsplit(args, "\t");
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
58 if (list[0] == NULL || list[1] == NULL || list[2] == NULL) {
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
59 i_error("BUG: Master sent broken REQUEST");
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
60 return FALSE;
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
61 }
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
62
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
63 id = (unsigned int)strtoul(list[0], NULL, 10);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
64 client_pid = (unsigned int)strtoul(list[1], NULL, 10);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
65 client_id = (unsigned int)strtoul(list[2], NULL, 10);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
66
3308
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3307
diff changeset
67 client_conn = auth_client_connection_lookup(conn->listener, client_pid);
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
68 if (client_conn == NULL) {
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
69 i_error("Master requested auth for nonexisting client %u",
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
70 client_pid);
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
71 (void)o_stream_send_str(conn->output,
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
72 t_strdup_printf("NOTFOUND\t%u\n", id));
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73 } else {
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
74 auth_request_handler_master_request(
3308
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3307
diff changeset
75 client_conn->request_handler, conn, id, client_id);
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76 }
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
77 return TRUE;
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
78 }
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
79
3185
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
80 static void
3520
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3470
diff changeset
81 user_callback(struct auth_stream_reply *reply,
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3470
diff changeset
82 struct auth_request *auth_request)
3185
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
83 {
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
84 struct auth_master_connection *conn = auth_request->context;
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
85 string_t *str;
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
86
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
87 str = t_str_new(128);
3520
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3470
diff changeset
88 if (reply == NULL)
4521
9202ffe3d5c5 Debug: Don't log empty error when writing "master out" debug lines.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
89 str_printfa(str, "NOTFOUND\t%u", auth_request->id);
3185
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
90 else {
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
91 str_printfa(str, "USER\t%u\t", auth_request->id);
3520
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3470
diff changeset
92 str_append(str, auth_stream_reply_export(reply));
3185
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
93 }
3640
e06617e148fc Added "master out" debugging also for USER queries from master (ie. from
Timo Sirainen <tss@iki.fi>
parents: 3520
diff changeset
94
e06617e148fc Added "master out" debugging also for USER queries from master (ie. from
Timo Sirainen <tss@iki.fi>
parents: 3520
diff changeset
95 if (conn->listener->auth->verbose_debug)
e06617e148fc Added "master out" debugging also for USER queries from master (ie. from
Timo Sirainen <tss@iki.fi>
parents: 3520
diff changeset
96 i_info("master out: %s", str_c(str));
e06617e148fc Added "master out" debugging also for USER queries from master (ie. from
Timo Sirainen <tss@iki.fi>
parents: 3520
diff changeset
97
4521
9202ffe3d5c5 Debug: Don't log empty error when writing "master out" debug lines.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
98 str_append_c(str, '\n');
3185
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
99 (void)o_stream_send(conn->output, str_data(str), str_len(str));
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
100 auth_request_unref(&auth_request);
3185
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
101 }
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
102
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3640
diff changeset
103 static bool
3185
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
104 master_input_user(struct auth_master_connection *conn, const char *args)
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
105 {
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
106 struct auth_request *auth_request;
3338
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
107 const char *const *list, *name, *arg;
3185
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
108
3338
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
109 /* <id> <userid> [<parameters>] */
3185
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
110 list = t_strsplit(args, "\t");
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
111 if (list[0] == NULL || list[1] == NULL) {
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
112 i_error("BUG: Master sent broken USER");
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
113 return FALSE;
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
114 }
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
115
3308
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3307
diff changeset
116 auth_request = auth_request_new_dummy(conn->listener->auth);
3185
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
117 auth_request->id = (unsigned int)strtoul(list[0], NULL, 10);
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
118 auth_request->user = p_strdup(auth_request->pool, list[1]);
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
119 auth_request->context = conn;
3338
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
120
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
121 for (list += 2; *list != NULL; list++) {
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
122 arg = strchr(*list, '=');
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
123 if (arg == NULL) {
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
124 name = *list;
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
125 arg = "";
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
126 } else {
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
127 name = t_strdup_until(*list, arg);
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
128 arg++;
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
129 }
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
130
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
131 (void)auth_request_import(auth_request, name, arg);
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
132 }
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
133
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
134 if (auth_request->service == NULL) {
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
135 i_error("BUG: Master sent USER request without service");
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
136 auth_request_unref(&auth_request);
3338
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
137 return FALSE;
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
138 }
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
139
3185
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
140 auth_request_lookup_user(auth_request, user_callback);
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
141 return TRUE;
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
142 }
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
143
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
144 static void master_input(void *context)
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
145 {
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
146 struct auth_master_connection *conn = context;
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
147 char *line;
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3640
diff changeset
148 bool ret;
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
149
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
150 switch (i_stream_read(conn->input)) {
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
151 case 0:
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
152 return;
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
153 case -1:
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
154 /* disconnected */
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
155 auth_master_connection_destroy(&conn);
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
156 return;
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
157 case -2:
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
158 /* buffer full */
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
159 i_error("BUG: Master sent us more than %d bytes",
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
160 (int)MAX_INBUF_SIZE);
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
161 auth_master_connection_destroy(&conn);
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
162 return;
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
163 }
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
164
2776
150f8151c971 Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents: 2754
diff changeset
165 if (!conn->version_received) {
150f8151c971 Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents: 2754
diff changeset
166 line = i_stream_next_line(conn->input);
150f8151c971 Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents: 2754
diff changeset
167 if (line == NULL)
150f8151c971 Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents: 2754
diff changeset
168 return;
150f8151c971 Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents: 2754
diff changeset
169
150f8151c971 Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents: 2754
diff changeset
170 /* make sure the major version matches */
150f8151c971 Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents: 2754
diff changeset
171 if (strncmp(line, "VERSION\t", 8) != 0 ||
2809
0b1bef51f207 Separate major/minor version with TAB instead of dot in VERSION.
Timo Sirainen <tss@iki.fi>
parents: 2791
diff changeset
172 atoi(t_strcut(line + 8, '\t')) !=
2776
150f8151c971 Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents: 2754
diff changeset
173 AUTH_MASTER_PROTOCOL_MAJOR_VERSION) {
150f8151c971 Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents: 2754
diff changeset
174 i_error("Master not compatible with this server "
150f8151c971 Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents: 2754
diff changeset
175 "(mixed old and new binaries?)");
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
176 auth_master_connection_destroy(&conn);
2776
150f8151c971 Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents: 2754
diff changeset
177 return;
150f8151c971 Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents: 2754
diff changeset
178 }
150f8151c971 Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents: 2754
diff changeset
179 conn->version_received = TRUE;
150f8151c971 Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents: 2754
diff changeset
180 }
150f8151c971 Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents: 2754
diff changeset
181
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
182 while ((line = i_stream_next_line(conn->input)) != NULL) {
3308
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3307
diff changeset
183 if (conn->listener->auth->verbose_debug)
3158
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3080
diff changeset
184 i_info("master in: %s", line);
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3080
diff changeset
185
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
186 t_push();
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
187 if (strncmp(line, "REQUEST\t", 8) == 0)
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
188 ret = master_input_request(conn, line + 8);
3185
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
189 else if (strncmp(line, "USER\t", 5) == 0)
3089083e1d47 Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents: 3183
diff changeset
190 ret = master_input_user(conn, line + 5);
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
191 else {
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
192 /* ignore unknown command */
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
193 ret = TRUE;
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
194 }
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
195 t_pop();
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
196
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
197 if (!ret) {
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
198 auth_master_connection_destroy(&conn);
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
199 return;
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
200 }
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
201 }
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
202 }
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
203
2790
02c0b8d532c2 Changed ostream's flush callback to have return value which can tell if
Timo Sirainen <tss@iki.fi>
parents: 2776
diff changeset
204 static int master_output(void *context)
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2267
diff changeset
205 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2267
diff changeset
206 struct auth_master_connection *conn = context;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2267
diff changeset
207 int ret;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2267
diff changeset
208
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2267
diff changeset
209 if ((ret = o_stream_flush(conn->output)) < 0) {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2267
diff changeset
210 /* transmit error, probably master died */
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
211 auth_master_connection_destroy(&conn);
2790
02c0b8d532c2 Changed ostream's flush callback to have return value which can tell if
Timo Sirainen <tss@iki.fi>
parents: 2776
diff changeset
212 return 1;
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2267
diff changeset
213 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2267
diff changeset
214
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2267
diff changeset
215 if (o_stream_get_buffer_used_size(conn->output) <= MAX_OUTBUF_SIZE/2) {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2267
diff changeset
216 /* allow input again */
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2267
diff changeset
217 conn->io = io_add(conn->fd, IO_READ, master_input, conn);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2267
diff changeset
218 }
2790
02c0b8d532c2 Changed ostream's flush callback to have return value which can tell if
Timo Sirainen <tss@iki.fi>
parents: 2776
diff changeset
219 return 1;
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2267
diff changeset
220 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2267
diff changeset
221
3308
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3307
diff changeset
222 struct auth_master_connection *
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3307
diff changeset
223 auth_master_connection_create(struct auth_master_listener *listener, int fd)
2236
43b82a35888d Dovecot can now connect to externally running dovecot-auth.
Timo Sirainen <tss@iki.fi>
parents: 2077
diff changeset
224 {
3308
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3307
diff changeset
225 struct auth_master_connection *conn;
2236
43b82a35888d Dovecot can now connect to externally running dovecot-auth.
Timo Sirainen <tss@iki.fi>
parents: 2077
diff changeset
226
3308
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3307
diff changeset
227 conn = i_new(struct auth_master_connection, 1);
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3307
diff changeset
228 conn->listener = listener;
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3307
diff changeset
229 conn->fd = fd;
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
230 conn->input = i_stream_create_file(fd, default_pool,
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
231 MAX_INBUF_SIZE, FALSE);
2236
43b82a35888d Dovecot can now connect to externally running dovecot-auth.
Timo Sirainen <tss@iki.fi>
parents: 2077
diff changeset
232 conn->output = o_stream_create_file(fd, default_pool,
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2267
diff changeset
233 (size_t)-1, FALSE);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2267
diff changeset
234 o_stream_set_flush_callback(conn->output, master_output, conn);
2236
43b82a35888d Dovecot can now connect to externally running dovecot-auth.
Timo Sirainen <tss@iki.fi>
parents: 2077
diff changeset
235 conn->io = io_add(fd, IO_READ, master_input, conn);
43b82a35888d Dovecot can now connect to externally running dovecot-auth.
Timo Sirainen <tss@iki.fi>
parents: 2077
diff changeset
236
3308
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3307
diff changeset
237 array_append(&listener->masters, &conn, 1);
2075
5138b14889a6 dovecot-auth can now be run by itself, it listens in UNIX sockets specified
Timo Sirainen <tss@iki.fi>
parents: 2057
diff changeset
238 return conn;
5138b14889a6 dovecot-auth can now be run by itself, it listens in UNIX sockets specified
Timo Sirainen <tss@iki.fi>
parents: 2057
diff changeset
239 }
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
240
2075
5138b14889a6 dovecot-auth can now be run by itself, it listens in UNIX sockets specified
Timo Sirainen <tss@iki.fi>
parents: 2057
diff changeset
241 void auth_master_connection_send_handshake(struct auth_master_connection *conn)
5138b14889a6 dovecot-auth can now be run by itself, it listens in UNIX sockets specified
Timo Sirainen <tss@iki.fi>
parents: 2057
diff changeset
242 {
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
243 const char *line;
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
244
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
245 if (conn->output == NULL)
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
246 return;
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
247
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
248 line = t_strdup_printf("VERSION\t%u\t%u\nSPID\t%u\n",
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
249 AUTH_MASTER_PROTOCOL_MAJOR_VERSION,
3308
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3307
diff changeset
250 AUTH_MASTER_PROTOCOL_MINOR_VERSION,
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3307
diff changeset
251 conn->listener->pid);
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents: 3069
diff changeset
252 (void)o_stream_send_str(conn->output, line);
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
253 }
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
254
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
255 void auth_master_connection_destroy(struct auth_master_connection **_conn)
2236
43b82a35888d Dovecot can now connect to externally running dovecot-auth.
Timo Sirainen <tss@iki.fi>
parents: 2077
diff changeset
256 {
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
257 struct auth_master_connection *conn = *_conn;
3307
38754475d3b6 Exit only if all master connections are lost, not only if one of them is.
Timo Sirainen <tss@iki.fi>
parents: 3185
diff changeset
258 struct auth_master_connection *const *conns;
38754475d3b6 Exit only if all master connections are lost, not only if one of them is.
Timo Sirainen <tss@iki.fi>
parents: 3185
diff changeset
259 unsigned int i, count;
2075
5138b14889a6 dovecot-auth can now be run by itself, it listens in UNIX sockets specified
Timo Sirainen <tss@iki.fi>
parents: 2057
diff changeset
260
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
261 *_conn = NULL;
2075
5138b14889a6 dovecot-auth can now be run by itself, it listens in UNIX sockets specified
Timo Sirainen <tss@iki.fi>
parents: 2057
diff changeset
262 if (conn->destroyed)
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
263 return;
2075
5138b14889a6 dovecot-auth can now be run by itself, it listens in UNIX sockets specified
Timo Sirainen <tss@iki.fi>
parents: 2057
diff changeset
264 conn->destroyed = TRUE;
5138b14889a6 dovecot-auth can now be run by itself, it listens in UNIX sockets specified
Timo Sirainen <tss@iki.fi>
parents: 2057
diff changeset
265
3307
38754475d3b6 Exit only if all master connections are lost, not only if one of them is.
Timo Sirainen <tss@iki.fi>
parents: 3185
diff changeset
266 if (conn->input != NULL)
4070
71b8faa84ec6 Added i_stream_destroy() and o_stream_destroy() and used them instead of
Timo Sirainen <tss@iki.fi>
parents: 3960
diff changeset
267 i_stream_destroy(&conn->input);
3307
38754475d3b6 Exit only if all master connections are lost, not only if one of them is.
Timo Sirainen <tss@iki.fi>
parents: 3185
diff changeset
268 if (conn->output != NULL)
4070
71b8faa84ec6 Added i_stream_destroy() and o_stream_destroy() and used them instead of
Timo Sirainen <tss@iki.fi>
parents: 3960
diff changeset
269 o_stream_destroy(&conn->output);
3307
38754475d3b6 Exit only if all master connections are lost, not only if one of them is.
Timo Sirainen <tss@iki.fi>
parents: 3185
diff changeset
270 if (conn->io != NULL)
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
271 io_remove(&conn->io);
3960
aeb424e64f24 Call io_remove() before closing the fd. It's required by kqueue.
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
272 if (conn->fd != -1) {
aeb424e64f24 Call io_remove() before closing the fd. It's required by kqueue.
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
273 if (close(conn->fd) < 0)
aeb424e64f24 Call io_remove() before closing the fd. It's required by kqueue.
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
274 i_error("close(): %m");
aeb424e64f24 Call io_remove() before closing the fd. It's required by kqueue.
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
275 }
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
276
3308
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3307
diff changeset
277 conns = array_get(&conn->listener->masters, &count);
3307
38754475d3b6 Exit only if all master connections are lost, not only if one of them is.
Timo Sirainen <tss@iki.fi>
parents: 3185
diff changeset
278 for (i = 0; i < count; i++) {
38754475d3b6 Exit only if all master connections are lost, not only if one of them is.
Timo Sirainen <tss@iki.fi>
parents: 3185
diff changeset
279 if (conns[i] == conn) {
3308
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3307
diff changeset
280 array_delete(&conn->listener->masters, i, 1);
3307
38754475d3b6 Exit only if all master connections are lost, not only if one of them is.
Timo Sirainen <tss@iki.fi>
parents: 3185
diff changeset
281 break;
38754475d3b6 Exit only if all master connections are lost, not only if one of them is.
Timo Sirainen <tss@iki.fi>
parents: 3185
diff changeset
282 }
38754475d3b6 Exit only if all master connections are lost, not only if one of them is.
Timo Sirainen <tss@iki.fi>
parents: 3185
diff changeset
283 }
3308
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3307
diff changeset
284 if (!standalone && auth_master_listeners_masters_left() == 0)
3307
38754475d3b6 Exit only if all master connections are lost, not only if one of them is.
Timo Sirainen <tss@iki.fi>
parents: 3185
diff changeset
285 io_loop_stop(ioloop);
38754475d3b6 Exit only if all master connections are lost, not only if one of them is.
Timo Sirainen <tss@iki.fi>
parents: 3185
diff changeset
286
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
287 i_free(conn);
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
288 }