Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/auth/auth-master-connection.c @ 9608:f30e6a345d73 HEAD
Added tag 1.2.14 for changeset eb04e2b13e3d
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 24 Aug 2010 18:10:29 +0100 |
parents | 00cd9aacd03c |
children |
rev | line source |
---|---|
9532
00cd9aacd03c
Updated copyright notices to include year 2010.
Timo Sirainen <tss@iki.fi>
parents:
9334
diff
changeset
|
1 /* Copyright (c) 2002-2010 Dovecot authors, see the included COPYING file */ |
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
|
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" |
5558
5c31d0c83258
Log an error and disconnect with unknown commands.
Timo Sirainen <tss@iki.fi>
parents:
5371
diff
changeset
|
8 #include "str-sanitize.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
|
9 #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
|
10 #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
|
11 #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
|
12 #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
|
13 #include "userdb.h" |
3074 | 14 #include "auth-request-handler.h" |
2776
150f8151c971
Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
15 #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
|
16 #include "auth-client-connection.h" |
3308
3f090bcaffcc
Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents:
3307
diff
changeset
|
17 #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
|
18 #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
|
19 |
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
|
20 #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
|
21 #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
|
22 |
2736
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_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
|
24 #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
|
25 |
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 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
|
27 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
|
28 unsigned int id; |
2754
3c3ac12be307
Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
2738
diff
changeset
|
29 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
|
30 }; |
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
|
31 |
7388
08d31d752893
Use auth-stream API to build all TAB-delimited strings to make sure strings
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
32 void auth_master_request_callback(struct auth_stream_reply *reply, |
08d31d752893
Use auth-stream API to build all TAB-delimited strings to make sure strings
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
33 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 | 35 struct auth_master_connection *conn = context; |
36 struct const_iovec iov[2]; | |
7388
08d31d752893
Use auth-stream API to build all TAB-delimited strings to make sure strings
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
37 const char *reply_str; |
08d31d752893
Use auth-stream API to build all TAB-delimited strings to make sure strings
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
38 |
08d31d752893
Use auth-stream API to build all TAB-delimited strings to make sure strings
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
39 reply_str = auth_stream_reply_export(reply); |
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
|
40 |
3308
3f090bcaffcc
Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents:
3307
diff
changeset
|
41 if (conn->listener->auth->verbose_debug) |
7388
08d31d752893
Use auth-stream API to build all TAB-delimited strings to make sure strings
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
42 i_info("master out: %s", reply_str); |
3158
8849f2e380d1
userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents:
3080
diff
changeset
|
43 |
7388
08d31d752893
Use auth-stream API to build all TAB-delimited strings to make sure strings
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
44 iov[0].iov_base = reply_str; |
08d31d752893
Use auth-stream API to build all TAB-delimited strings to make sure strings
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
45 iov[0].iov_len = strlen(reply_str); |
3074 | 46 iov[1].iov_base = "\n"; |
47 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
|
48 |
3074 | 49 (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
|
50 } |
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 |
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
|
52 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
|
53 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
|
54 { |
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 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
|
56 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
|
57 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
|
58 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
59 /* <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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 } |
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
65 |
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
66 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
|
67 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
|
68 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
|
69 |
3308
3f090bcaffcc
Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents:
3307
diff
changeset
|
70 client_conn = auth_client_connection_lookup(conn->listener, client_pid); |
3074 | 71 if (client_conn == NULL) { |
72 i_error("Master requested auth for nonexisting client %u", | |
73 client_pid); | |
74 (void)o_stream_send_str(conn->output, | |
75 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
|
76 } else { |
3074 | 77 auth_request_handler_master_request( |
3308
3f090bcaffcc
Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents:
3307
diff
changeset
|
78 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
|
79 } |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
80 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
|
81 } |
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
82 |
3185
3089083e1d47
Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents:
3183
diff
changeset
|
83 static void |
4880
4ec6a4def05b
We treated internal userdb lookup errors as "user unknown" errors. In such
Timo Sirainen <tss@iki.fi>
parents:
4800
diff
changeset
|
84 user_callback(enum userdb_result result, |
3520 | 85 struct auth_request *auth_request) |
3185
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 struct auth_master_connection *conn = auth_request->context; |
5872
93bd157917ca
Changed userdb callback API. Don't require uid/gid to be returned by userdb.
Timo Sirainen <tss@iki.fi>
parents:
5558
diff
changeset
|
88 struct auth_stream_reply *reply = auth_request->userdb_reply; |
3185
3089083e1d47
Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents:
3183
diff
changeset
|
89 string_t *str; |
3089083e1d47
Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents:
3183
diff
changeset
|
90 |
5872
93bd157917ca
Changed userdb callback API. Don't require uid/gid to be returned by userdb.
Timo Sirainen <tss@iki.fi>
parents:
5558
diff
changeset
|
91 if (auth_request->userdb_lookup_failed) |
93bd157917ca
Changed userdb callback API. Don't require uid/gid to be returned by userdb.
Timo Sirainen <tss@iki.fi>
parents:
5558
diff
changeset
|
92 result = USERDB_RESULT_INTERNAL_FAILURE; |
93bd157917ca
Changed userdb callback API. Don't require uid/gid to be returned by userdb.
Timo Sirainen <tss@iki.fi>
parents:
5558
diff
changeset
|
93 |
3185
3089083e1d47
Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents:
3183
diff
changeset
|
94 str = t_str_new(128); |
4880
4ec6a4def05b
We treated internal userdb lookup errors as "user unknown" errors. In such
Timo Sirainen <tss@iki.fi>
parents:
4800
diff
changeset
|
95 switch (result) { |
4ec6a4def05b
We treated internal userdb lookup errors as "user unknown" errors. In such
Timo Sirainen <tss@iki.fi>
parents:
4800
diff
changeset
|
96 case USERDB_RESULT_INTERNAL_FAILURE: |
4ec6a4def05b
We treated internal userdb lookup errors as "user unknown" errors. In such
Timo Sirainen <tss@iki.fi>
parents:
4800
diff
changeset
|
97 str_printfa(str, "FAIL\t%u", auth_request->id); |
4ec6a4def05b
We treated internal userdb lookup errors as "user unknown" errors. In such
Timo Sirainen <tss@iki.fi>
parents:
4800
diff
changeset
|
98 break; |
4ec6a4def05b
We treated internal userdb lookup errors as "user unknown" errors. In such
Timo Sirainen <tss@iki.fi>
parents:
4800
diff
changeset
|
99 case USERDB_RESULT_USER_UNKNOWN: |
4521
9202ffe3d5c5
Debug: Don't log empty error when writing "master out" debug lines.
Timo Sirainen <tss@iki.fi>
parents:
4070
diff
changeset
|
100 str_printfa(str, "NOTFOUND\t%u", auth_request->id); |
4880
4ec6a4def05b
We treated internal userdb lookup errors as "user unknown" errors. In such
Timo Sirainen <tss@iki.fi>
parents:
4800
diff
changeset
|
101 break; |
4ec6a4def05b
We treated internal userdb lookup errors as "user unknown" errors. In such
Timo Sirainen <tss@iki.fi>
parents:
4800
diff
changeset
|
102 case USERDB_RESULT_OK: |
3185
3089083e1d47
Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents:
3183
diff
changeset
|
103 str_printfa(str, "USER\t%u\t", auth_request->id); |
3520 | 104 str_append(str, auth_stream_reply_export(reply)); |
4880
4ec6a4def05b
We treated internal userdb lookup errors as "user unknown" errors. In such
Timo Sirainen <tss@iki.fi>
parents:
4800
diff
changeset
|
105 break; |
3185
3089083e1d47
Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents:
3183
diff
changeset
|
106 } |
3640
e06617e148fc
Added "master out" debugging also for USER queries from master (ie. from
Timo Sirainen <tss@iki.fi>
parents:
3520
diff
changeset
|
107 |
e06617e148fc
Added "master out" debugging also for USER queries from master (ie. from
Timo Sirainen <tss@iki.fi>
parents:
3520
diff
changeset
|
108 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
|
109 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
|
110 |
4521
9202ffe3d5c5
Debug: Don't log empty error when writing "master out" debug lines.
Timo Sirainen <tss@iki.fi>
parents:
4070
diff
changeset
|
111 str_append_c(str, '\n'); |
3185
3089083e1d47
Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents:
3183
diff
changeset
|
112 (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
|
113 auth_request_unref(&auth_request); |
9161
af28db3176cf
auth: Keep master connection referenced during USER lookups.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
114 auth_master_connection_unref(&conn); |
3185
3089083e1d47
Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents:
3183
diff
changeset
|
115 } |
3089083e1d47
Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents:
3183
diff
changeset
|
116 |
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
|
117 static bool |
3185
3089083e1d47
Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents:
3183
diff
changeset
|
118 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
|
119 { |
3089083e1d47
Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents:
3183
diff
changeset
|
120 struct auth_request *auth_request; |
6220
c14b923977e5
Do username checks and translations with userdb lookups.
Timo Sirainen <tss@iki.fi>
parents:
6162
diff
changeset
|
121 const char *const *list, *name, *arg, *error; |
3185
3089083e1d47
Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents:
3183
diff
changeset
|
122 |
3338
e5ce49c8524a
USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents:
3308
diff
changeset
|
123 /* <id> <userid> [<parameters>] */ |
3185
3089083e1d47
Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents:
3183
diff
changeset
|
124 list = t_strsplit(args, "\t"); |
3089083e1d47
Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents:
3183
diff
changeset
|
125 if (list[0] == NULL || list[1] == NULL) { |
3089083e1d47
Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents:
3183
diff
changeset
|
126 i_error("BUG: Master sent broken USER"); |
3089083e1d47
Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents:
3183
diff
changeset
|
127 return FALSE; |
3089083e1d47
Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents:
3183
diff
changeset
|
128 } |
3089083e1d47
Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents:
3183
diff
changeset
|
129 |
3308
3f090bcaffcc
Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents:
3307
diff
changeset
|
130 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
|
131 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
|
132 auth_request->context = conn; |
9161
af28db3176cf
auth: Keep master connection referenced during USER lookups.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
133 auth_master_connection_ref(conn); |
3338
e5ce49c8524a
USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents:
3308
diff
changeset
|
134 |
6220
c14b923977e5
Do username checks and translations with userdb lookups.
Timo Sirainen <tss@iki.fi>
parents:
6162
diff
changeset
|
135 if (!auth_request_set_username(auth_request, list[1], &error)) { |
c14b923977e5
Do username checks and translations with userdb lookups.
Timo Sirainen <tss@iki.fi>
parents:
6162
diff
changeset
|
136 auth_request_log_info(auth_request, "userdb", "%s", error); |
c14b923977e5
Do username checks and translations with userdb lookups.
Timo Sirainen <tss@iki.fi>
parents:
6162
diff
changeset
|
137 user_callback(USERDB_RESULT_USER_UNKNOWN, auth_request); |
c14b923977e5
Do username checks and translations with userdb lookups.
Timo Sirainen <tss@iki.fi>
parents:
6162
diff
changeset
|
138 return TRUE; |
c14b923977e5
Do username checks and translations with userdb lookups.
Timo Sirainen <tss@iki.fi>
parents:
6162
diff
changeset
|
139 } |
c14b923977e5
Do username checks and translations with userdb lookups.
Timo Sirainen <tss@iki.fi>
parents:
6162
diff
changeset
|
140 |
3338
e5ce49c8524a
USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents:
3308
diff
changeset
|
141 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
|
142 arg = strchr(*list, '='); |
e5ce49c8524a
USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents:
3308
diff
changeset
|
143 if (arg == NULL) { |
e5ce49c8524a
USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents:
3308
diff
changeset
|
144 name = *list; |
e5ce49c8524a
USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents:
3308
diff
changeset
|
145 arg = ""; |
e5ce49c8524a
USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents:
3308
diff
changeset
|
146 } else { |
e5ce49c8524a
USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents:
3308
diff
changeset
|
147 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
|
148 arg++; |
e5ce49c8524a
USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents:
3308
diff
changeset
|
149 } |
e5ce49c8524a
USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents:
3308
diff
changeset
|
150 |
e5ce49c8524a
USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents:
3308
diff
changeset
|
151 (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
|
152 } |
e5ce49c8524a
USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents:
3308
diff
changeset
|
153 |
e5ce49c8524a
USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents:
3308
diff
changeset
|
154 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
|
155 i_error("BUG: Master sent USER request without service"); |
9334
0d0a801a4d1e
auth: Don't leak memory with buggy auth-master clients.
Timo Sirainen <tss@iki.fi>
parents:
9161
diff
changeset
|
156 auth_master_connection_unref(&conn); |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
157 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
|
158 return FALSE; |
e5ce49c8524a
USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents:
3308
diff
changeset
|
159 } |
e5ce49c8524a
USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents:
3308
diff
changeset
|
160 |
5371
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
5038
diff
changeset
|
161 auth_request->state = AUTH_REQUEST_STATE_USERDB; |
3185
3089083e1d47
Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents:
3183
diff
changeset
|
162 auth_request_lookup_user(auth_request, user_callback); |
3089083e1d47
Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents:
3183
diff
changeset
|
163 return TRUE; |
3089083e1d47
Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents:
3183
diff
changeset
|
164 } |
3089083e1d47
Handle USER requests from master connections.
Timo Sirainen <tss@iki.fi>
parents:
3183
diff
changeset
|
165 |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
166 static bool |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
167 auth_master_input_line(struct auth_master_connection *conn, const char *line) |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
168 { |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
169 if (conn->listener->auth->verbose_debug) |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
170 i_info("master in: %s", line); |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
171 |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
172 if (strncmp(line, "REQUEST\t", 8) == 0) |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
173 return master_input_request(conn, line + 8); |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
174 else if (strncmp(line, "USER\t", 5) == 0) |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
175 return master_input_user(conn, line + 5); |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
176 else if (strncmp(line, "CPID\t", 5) == 0) { |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
177 i_error("Authentication client trying to connect to " |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
178 "master socket"); |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
179 return FALSE; |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
180 } else { |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
181 /* ignore unknown command */ |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
182 i_error("BUG: Unknown command in master socket: %s", |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
183 str_sanitize(line, 80)); |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
184 return FALSE; |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
185 } |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
186 } |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
187 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
188 static void master_input(struct auth_master_connection *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
|
189 { |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
190 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
|
191 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
|
192 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
193 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
|
194 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
|
195 return; |
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
196 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
|
197 /* disconnected */ |
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 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
|
201 /* 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
|
202 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
|
203 (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
|
204 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
|
205 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
|
206 } |
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
|
207 |
2776
150f8151c971
Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
208 if (!conn->version_received) { |
150f8151c971
Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
209 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
|
210 if (line == NULL) |
150f8151c971
Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
211 return; |
150f8151c971
Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
212 |
150f8151c971
Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
213 /* make sure the major version matches */ |
150f8151c971
Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
214 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
|
215 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
|
216 AUTH_MASTER_PROTOCOL_MAJOR_VERSION) { |
150f8151c971
Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
217 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
|
218 "(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
|
219 auth_master_connection_destroy(&conn); |
2776
150f8151c971
Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
220 return; |
150f8151c971
Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
221 } |
150f8151c971
Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
222 conn->version_received = TRUE; |
150f8151c971
Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
223 } |
150f8151c971
Added VERSION command and checking to authentication protocol.
Timo Sirainen <tss@iki.fi>
parents:
2754
diff
changeset
|
224 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
225 while ((line = i_stream_next_line(conn->input)) != NULL) { |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
226 T_BEGIN { |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
227 ret = auth_master_input_line(conn, line); |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
228 } T_END; |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
229 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
|
230 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
|
231 return; |
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
232 } |
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
|
233 } |
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
|
234 } |
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
|
235 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
236 static int master_output(struct auth_master_connection *conn) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2267
diff
changeset
|
237 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2267
diff
changeset
|
238 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
|
239 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2267
diff
changeset
|
240 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
|
241 /* 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
|
242 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
|
243 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
|
244 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2267
diff
changeset
|
245 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2267
diff
changeset
|
246 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
|
247 /* 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
|
248 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
|
249 } |
2790
02c0b8d532c2
Changed ostream's flush callback to have return value which can tell if
Timo Sirainen <tss@iki.fi>
parents:
2776
diff
changeset
|
250 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
|
251 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2267
diff
changeset
|
252 |
3308
3f090bcaffcc
Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents:
3307
diff
changeset
|
253 struct auth_master_connection * |
3f090bcaffcc
Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents:
3307
diff
changeset
|
254 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
|
255 { |
3308
3f090bcaffcc
Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents:
3307
diff
changeset
|
256 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
|
257 |
3308
3f090bcaffcc
Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents:
3307
diff
changeset
|
258 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
|
259 conn->listener = listener; |
5038
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
260 conn->refcount = 1; |
3308
3f090bcaffcc
Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents:
3307
diff
changeset
|
261 conn->fd = fd; |
6162
896cc473c1f0
Renamed i_stream_create_file() to i_stream_create_fd().
Timo Sirainen <tss@iki.fi>
parents:
6161
diff
changeset
|
262 conn->input = i_stream_create_fd(fd, MAX_INBUF_SIZE, FALSE); |
6161
c62f7ee79446
Split o_stream_create_file() to _create_fd() and _create_fd_file().
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
263 conn->output = o_stream_create_fd(fd, (size_t)-1, FALSE); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2267
diff
changeset
|
264 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
|
265 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
|
266 |
3308
3f090bcaffcc
Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents:
3307
diff
changeset
|
267 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
|
268 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
|
269 } |
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
|
270 |
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
|
271 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
|
272 { |
3074 | 273 const char *line; |
274 | |
275 if (conn->output == NULL) | |
276 return; | |
277 | |
278 line = t_strdup_printf("VERSION\t%u\t%u\nSPID\t%u\n", | |
279 AUTH_MASTER_PROTOCOL_MAJOR_VERSION, | |
3308
3f090bcaffcc
Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents:
3307
diff
changeset
|
280 AUTH_MASTER_PROTOCOL_MINOR_VERSION, |
3f090bcaffcc
Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents:
3307
diff
changeset
|
281 conn->listener->pid); |
3074 | 282 (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
|
283 } |
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
|
284 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
285 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
|
286 { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
287 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
|
288 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
|
289 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
|
290 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
291 *_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
|
292 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
|
293 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
|
294 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
|
295 |
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
|
296 if (conn->input != NULL) |
5038
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
297 i_stream_close(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
|
298 if (conn->output != NULL) |
5038
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
299 o_stream_close(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
|
300 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
|
301 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
|
302 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
|
303 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
|
304 i_error("close(): %m"); |
5038
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
305 conn->fd = -1; |
3960
aeb424e64f24
Call io_remove() before closing the fd. It's required by kqueue.
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
306 } |
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
|
307 |
3308
3f090bcaffcc
Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents:
3307
diff
changeset
|
308 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
|
309 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
|
310 if (conns[i] == conn) { |
3308
3f090bcaffcc
Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents:
3307
diff
changeset
|
311 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
|
312 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
|
313 } |
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
|
314 } |
3308
3f090bcaffcc
Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents:
3307
diff
changeset
|
315 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
|
316 io_loop_stop(ioloop); |
5038
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
317 |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
318 auth_master_connection_unref(&conn); |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
319 } |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
320 |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
321 void auth_master_connection_ref(struct auth_master_connection *conn) |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
322 { |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
323 i_assert(conn->refcount > 0); |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
324 |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
325 conn->refcount++; |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
326 } |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
327 |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
328 void auth_master_connection_unref(struct auth_master_connection **_conn) |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
329 { |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
330 struct auth_master_connection *conn = *_conn; |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
331 |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
332 *_conn = NULL; |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
333 i_assert(conn->refcount > 0); |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
334 |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
335 if (--conn->refcount > 0) |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
336 return; |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
337 |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
338 if (conn->input != NULL) |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
339 i_stream_unref(&conn->input); |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
340 if (conn->output != NULL) |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
341 o_stream_unref(&conn->output); |
b2921478f94f
Several fixes to handling deinitialization without crashing.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
342 |
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
|
343 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
|
344 } |