annotate src/director/login-connection.c @ 11714:1683324ac632 HEAD

director: Added support for LMTP proxying.
author Timo Sirainen <tss@iki.fi>
date Fri, 02 Jul 2010 18:47:43 +0100
parents c82a7922fca9
children 447bce266022
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 /* Copyright (c) 2010 Dovecot authors, see the included COPYING file */
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "ioloop.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "network.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "ostream.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "llist.h"
11430
c82a7922fca9 director: Update connection counts also on login connection deinit.
Timo Sirainen <tss@iki.fi>
parents: 11326
diff changeset
8 #include "master-service.h"
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "director.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #include "director-request.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include "auth-connection.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 #include "login-connection.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 #include <unistd.h>
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 struct login_connection {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 struct login_connection *prev, *next;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 int refcount;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 int fd;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 struct io *io;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23 struct ostream *output;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 struct auth_connection *auth;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 struct director *dir;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 unsigned int destroyed:1;
11714
1683324ac632 director: Added support for LMTP proxying.
Timo Sirainen <tss@iki.fi>
parents: 11430
diff changeset
28 unsigned int userdb:1;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29 };
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31 struct login_host_request {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 struct login_connection *conn;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 char *line;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 };
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 static struct login_connection *login_connections;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38 static void login_connection_unref(struct login_connection **_conn);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40 static void login_connection_input(struct login_connection *conn)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 unsigned char buf[4096];
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43 ssize_t ret;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45 ret = read(conn->fd, buf, sizeof(buf));
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46 if (ret <= 0) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 if (ret < 0) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48 if (errno == EAGAIN)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 return;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50 i_error("read(login connection) failed: %m");
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52 login_connection_deinit(&conn);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53 return;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 auth_connection_send(conn->auth, buf, ret);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58 static void
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59 login_connection_send_line(struct login_connection *conn, const char *line)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 struct const_iovec iov[2];
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 if (conn->destroyed)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 return;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66 iov[0].iov_base = line;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 iov[0].iov_len = strlen(line);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 iov[1].iov_base = "\n";
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 iov[1].iov_len = 1;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 (void)o_stream_sendv(conn->output, iov, N_ELEMENTS(iov));
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73 static void login_host_callback(const struct ip_addr *ip, void *context)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 struct login_host_request *request = context;
11325
2a5336ad86cd director: Tell login proxy to notify director of open connections every director_user_expire/2 secs.
Timo Sirainen <tss@iki.fi>
parents: 11321
diff changeset
76 struct director *dir = request->conn->dir;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 const char *line;
11325
2a5336ad86cd director: Tell login proxy to notify director of open connections every director_user_expire/2 secs.
Timo Sirainen <tss@iki.fi>
parents: 11321
diff changeset
78 unsigned int secs;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
79
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80 T_BEGIN {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81 if (ip != NULL) {
11325
2a5336ad86cd director: Tell login proxy to notify director of open connections every director_user_expire/2 secs.
Timo Sirainen <tss@iki.fi>
parents: 11321
diff changeset
82 secs = dir->set->director_user_expire / 2;
2a5336ad86cd director: Tell login proxy to notify director of open connections every director_user_expire/2 secs.
Timo Sirainen <tss@iki.fi>
parents: 11321
diff changeset
83 line = t_strdup_printf("%s\thost=%s\tproxy_refresh=%u",
2a5336ad86cd director: Tell login proxy to notify director of open connections every director_user_expire/2 secs.
Timo Sirainen <tss@iki.fi>
parents: 11321
diff changeset
84 request->line, net_ip2addr(ip),
2a5336ad86cd director: Tell login proxy to notify director of open connections every director_user_expire/2 secs.
Timo Sirainen <tss@iki.fi>
parents: 11321
diff changeset
85 secs);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 } else {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87 i_assert(strncmp(request->line, "OK\t", 3) == 0);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88 line = t_strconcat("FAIL\t",
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89 t_strcut(request->line + 3, '\t'),
11326
fc94106ca7e9 director: If we need to send a failure reply to login process, make it a temp failure.
Timo Sirainen <tss@iki.fi>
parents: 11325
diff changeset
90 "\ttemp", NULL);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92 login_connection_send_line(request->conn, line);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93 } T_END;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 login_connection_unref(&request->conn);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
96 i_free(request->line);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97 i_free(request);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
100 static void auth_input_line(const char *line, void *context)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
101 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
102 struct login_connection *conn = context;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
103 struct login_host_request *request;
11714
1683324ac632 director: Added support for LMTP proxying.
Timo Sirainen <tss@iki.fi>
parents: 11430
diff changeset
104 const char *const *args, *line_params, *username = NULL;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
105 bool proxy = FALSE, host = FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107 if (line == NULL) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108 /* auth connection died -> kill also this login connection */
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
109 login_connection_deinit(&conn);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
110 return;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111 }
11714
1683324ac632 director: Added support for LMTP proxying.
Timo Sirainen <tss@iki.fi>
parents: 11430
diff changeset
112 if (!conn->userdb && strncmp(line, "OK\t", 3) == 0)
1683324ac632 director: Added support for LMTP proxying.
Timo Sirainen <tss@iki.fi>
parents: 11430
diff changeset
113 line_params = line + 3;
1683324ac632 director: Added support for LMTP proxying.
Timo Sirainen <tss@iki.fi>
parents: 11430
diff changeset
114 else if (conn->userdb && strncmp(line, "PASS\t", 5) == 0)
1683324ac632 director: Added support for LMTP proxying.
Timo Sirainen <tss@iki.fi>
parents: 11430
diff changeset
115 line_params = line + 5;
1683324ac632 director: Added support for LMTP proxying.
Timo Sirainen <tss@iki.fi>
parents: 11430
diff changeset
116 else {
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
117 login_connection_send_line(conn, line);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
118 return;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
119 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
120
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
121 /* OK <id> [<parameters>] */
11714
1683324ac632 director: Added support for LMTP proxying.
Timo Sirainen <tss@iki.fi>
parents: 11430
diff changeset
122 args = t_strsplit(line_params, "\t");
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
123 if (*args != NULL) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
124 /* we should always get here, but in case we don't just
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
125 forward as-is and let login process handle the error. */
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
126 args++;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
127 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
128
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
129 for (; *args != NULL; args++) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
130 if (strncmp(*args, "proxy", 5) == 0 &&
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
131 ((*args)[5] == '=' || (*args)[5] == '\0'))
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
132 proxy = TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
133 else if (strncmp(*args, "host=", 5) == 0)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
134 host = TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
135 else if (strncmp(*args, "destuser=", 9) == 0)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
136 username = *args + 9;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
137 else if (strncmp(*args, "user=", 5) == 0) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
138 if (username == NULL)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
139 username = *args + 5;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
140 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
141 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
142 if (*conn->dir->set->master_user_separator != '\0') {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
143 /* with master user logins we still want to use only the
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
144 login username */
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
145 username = t_strcut(username,
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
146 *conn->dir->set->master_user_separator);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
147 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
148
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
149 if (!proxy || host || username == NULL) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
150 login_connection_send_line(conn, line);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
151 return;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
152 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
153
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
154 /* we need to add the host. the lookup might be asynchronous */
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
155 request = i_new(struct login_host_request, 1);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
156 request->conn = conn;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
157 request->line = i_strdup(line);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
158
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
159 conn->refcount++;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
160 director_request(conn->dir, username, login_host_callback, request);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
161 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
162
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
163 struct login_connection *
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
164 login_connection_init(struct director *dir, int fd,
11714
1683324ac632 director: Added support for LMTP proxying.
Timo Sirainen <tss@iki.fi>
parents: 11430
diff changeset
165 struct auth_connection *auth, bool userdb)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
166 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
167 struct login_connection *conn;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
168
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
169 conn = i_new(struct login_connection, 1);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
170 conn->refcount = 1;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
171 conn->fd = fd;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
172 conn->auth = auth;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
173 conn->dir = dir;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
174 conn->output = o_stream_create_fd(conn->fd, (size_t)-1, FALSE);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
175 conn->io = io_add(conn->fd, IO_READ, login_connection_input, conn);
11714
1683324ac632 director: Added support for LMTP proxying.
Timo Sirainen <tss@iki.fi>
parents: 11430
diff changeset
176 conn->userdb = userdb;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
177
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
178 auth_connection_set_callback(conn->auth, auth_input_line, conn);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
179 DLLIST_PREPEND(&login_connections, conn);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180 return conn;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
181 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
182
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
183 void login_connection_deinit(struct login_connection **_conn)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
184 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
185 struct login_connection *conn = *_conn;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
186
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
187 *_conn = NULL;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
188
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
189 if (conn->destroyed)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
190 return;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
191 conn->destroyed = TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
192
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
193 DLLIST_REMOVE(&login_connections, conn);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
194 io_remove(&conn->io);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
195 o_stream_unref(&conn->output);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
196 if (close(conn->fd) < 0)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
197 i_error("close(login connection) failed: %m");
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
198 conn->fd = -1;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
199
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
200 auth_connection_deinit(&conn->auth);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
201 login_connection_unref(&conn);
11430
c82a7922fca9 director: Update connection counts also on login connection deinit.
Timo Sirainen <tss@iki.fi>
parents: 11326
diff changeset
202
c82a7922fca9 director: Update connection counts also on login connection deinit.
Timo Sirainen <tss@iki.fi>
parents: 11326
diff changeset
203 master_service_client_connection_destroyed(master_service);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
204 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
205
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
206 static void login_connection_unref(struct login_connection **_conn)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
207 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
208 struct login_connection *conn = *_conn;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
209
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
210 *_conn = NULL;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
211
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
212 i_assert(conn->refcount > 0);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
213 if (--conn->refcount == 0)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
214 i_free(conn);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
215 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
216
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
217 void login_connections_deinit(void)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
218 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
219 while (login_connections != NULL) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
220 struct login_connection *conn = login_connections;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
221
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
222 login_connection_deinit(&conn);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
223 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
224 }