annotate src/lib-auth/auth-client.c @ 9638:9a50a9dc905f HEAD

dotlocks: Refresh current time after having waited for a lock.
author Timo Sirainen <tss@iki.fi>
date Thu, 20 Jan 2011 23:17:05 +0200
parents 00cd9aacd03c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9532
00cd9aacd03c Updated copyright notices to include year 2010.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
1 /* Copyright (c) 2003-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 "lib.h"
2077
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
4 #include "buffer.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 "ioloop.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"
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
7 #include "auth-client.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
8 #include "auth-server-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
9
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #include <dirent.h>
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include <sys/stat.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
4966
5df66ce64c0c If no auth sockets are found in 10 seconds, kill ourself.
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
13 #define AUTH_CLIENT_SOCKET_MAX_WAIT_TIME 10
5df66ce64c0c If no auth sockets are found in 10 seconds, kill ourself.
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
14
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 struct auth_client *auth_client_new(unsigned int client_pid)
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 {
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 struct auth_client *client;
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
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 client = i_new(struct auth_client, 1);
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
20 client->pid = client_pid;
2708
f1e9f3ec8135 Buffer API change: we no longer support limited sized buffers where
Timo Sirainen <tss@iki.fi>
parents: 2267
diff changeset
21 client->available_auth_mechs = buffer_create_dynamic(default_pool, 128);
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
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
23 auth_client_connect_missing_servers(client);
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 return client;
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
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
27 void auth_client_free(struct auth_client **_client)
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
28 {
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
29 struct auth_client *client = *_client;
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 struct auth_server_connection *next;
2077
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
31 struct auth_mech_desc *mech;
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
32 size_t i, size;
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
33
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
34 *_client = NULL;
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
35
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 3928
diff changeset
36 mech = buffer_get_modifiable_data(client->available_auth_mechs, &size);
2077
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
37 size /= sizeof(*mech);
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
38 for (i = 0; i < size; i++)
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
39 i_free(mech[i].name);
6414
a6a49d5efc59 Changed buffer_free() and buffer_free_without_data() APIs to take ** pointer
Timo Sirainen <tss@iki.fi>
parents: 5364
diff changeset
40 buffer_free(&client->available_auth_mechs);
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
41
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
42 while (client->connections != NULL) {
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
43 next = client->connections->next;
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
44 auth_server_connection_destroy(&client->connections, FALSE);
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45 client->connections = next;
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
46 }
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48 if (client->to_reconnect != NULL)
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
49 timeout_remove(&client->to_reconnect);
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 i_free(client);
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 }
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52
5364
8e2d0438d4ac Call auth_client_reconnect() when the last client has disconnected to make
Timo Sirainen <tss@iki.fi>
parents: 4966
diff changeset
53 void auth_client_reconnect(struct auth_client *client)
8e2d0438d4ac Call auth_client_reconnect() when the last client has disconnected to make
Timo Sirainen <tss@iki.fi>
parents: 4966
diff changeset
54 {
8e2d0438d4ac Call auth_client_reconnect() when the last client has disconnected to make
Timo Sirainen <tss@iki.fi>
parents: 4966
diff changeset
55 struct auth_server_connection *next;
8e2d0438d4ac Call auth_client_reconnect() when the last client has disconnected to make
Timo Sirainen <tss@iki.fi>
parents: 4966
diff changeset
56
8e2d0438d4ac Call auth_client_reconnect() when the last client has disconnected to make
Timo Sirainen <tss@iki.fi>
parents: 4966
diff changeset
57 while (client->connections != NULL) {
8e2d0438d4ac Call auth_client_reconnect() when the last client has disconnected to make
Timo Sirainen <tss@iki.fi>
parents: 4966
diff changeset
58 next = client->connections->next;
8e2d0438d4ac Call auth_client_reconnect() when the last client has disconnected to make
Timo Sirainen <tss@iki.fi>
parents: 4966
diff changeset
59 auth_server_connection_destroy(&client->connections, FALSE);
8e2d0438d4ac Call auth_client_reconnect() when the last client has disconnected to make
Timo Sirainen <tss@iki.fi>
parents: 4966
diff changeset
60 client->connections = next;
8e2d0438d4ac Call auth_client_reconnect() when the last client has disconnected to make
Timo Sirainen <tss@iki.fi>
parents: 4966
diff changeset
61 }
8e2d0438d4ac Call auth_client_reconnect() when the last client has disconnected to make
Timo Sirainen <tss@iki.fi>
parents: 4966
diff changeset
62
8e2d0438d4ac Call auth_client_reconnect() when the last client has disconnected to make
Timo Sirainen <tss@iki.fi>
parents: 4966
diff changeset
63 auth_client_connect_missing_servers(client);
8e2d0438d4ac Call auth_client_reconnect() when the last client has disconnected to make
Timo Sirainen <tss@iki.fi>
parents: 4966
diff changeset
64 }
8e2d0438d4ac Call auth_client_reconnect() when the last client has disconnected to make
Timo Sirainen <tss@iki.fi>
parents: 4966
diff changeset
65
2077
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
66 const struct auth_mech_desc *
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
67 auth_client_get_available_mechs(struct auth_client *client,
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
68 unsigned int *mech_count)
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
69 {
2077
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
70 const struct auth_mech_desc *mechs;
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
71 size_t size;
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
72
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
73 mechs = buffer_get_data(client->available_auth_mechs, &size);
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
74 *mech_count = size / sizeof(*mechs);
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
75 return mechs;
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
76 }
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
77
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
78 const struct auth_mech_desc *
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
79 auth_client_find_mech(struct auth_client *client, const char *name)
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
80 {
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
81 const struct auth_mech_desc *mech;
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
82 size_t i, size;
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
83
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
84 mech = buffer_get_data(client->available_auth_mechs, &size);
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
85 size /= sizeof(*mech);
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
86 for (i = 0; i < size; i++) {
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
87 if (strcasecmp(mech[i].name, name) == 0)
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
88 return &mech[i];
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
89 }
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
90
d5b20d679b8a Removed hardcoded mechanism lists. It's now possible to add them
Timo Sirainen <tss@iki.fi>
parents: 1705
diff changeset
91 return NULL;
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
92 }
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
93
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
94 bool auth_client_reserve_connection(struct auth_client *client,
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
95 const char *mech,
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
96 struct auth_connect_id *id_r)
2267
d2e186f716d8 Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2082
diff changeset
97 {
d2e186f716d8 Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2082
diff changeset
98 struct auth_server_connection *conn;
d2e186f716d8 Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2082
diff changeset
99 const char *error;
d2e186f716d8 Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2082
diff changeset
100
d2e186f716d8 Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2082
diff changeset
101 conn = auth_server_connection_find_mech(client, mech, &error);
d2e186f716d8 Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2082
diff changeset
102 if (conn == NULL)
d2e186f716d8 Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2082
diff changeset
103 return FALSE;
d2e186f716d8 Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2082
diff changeset
104
d2e186f716d8 Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2082
diff changeset
105 id_r->server_pid = conn->server_pid;
d2e186f716d8 Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2082
diff changeset
106 id_r->connect_uid = conn->connect_uid;
d2e186f716d8 Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2082
diff changeset
107
d2e186f716d8 Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2082
diff changeset
108 return TRUE;
d2e186f716d8 Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2082
diff changeset
109 }
d2e186f716d8 Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2082
diff changeset
110
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
111 bool auth_client_is_connected(struct auth_client *client)
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
112 {
2082
e22e3827a5f3 Allow using more easily outside dovecot.
Timo Sirainen <tss@iki.fi>
parents: 2077
diff changeset
113 return !client->reconnect &&
3927
b7da6fac35a3 If we don't have any auth sockets, don't say we're connected to it.
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
114 client->conn_waiting_handshake_count == 0 &&
b7da6fac35a3 If we don't have any auth sockets, don't say we're connected to it.
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
115 client->connections != NULL;
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
116 }
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
117
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
118 void auth_client_set_connect_notify(struct auth_client *client,
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
119 auth_connect_notify_callback_t *callback,
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
120 void *context)
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
121 {
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
122 client->connect_notify_callback = callback;
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
123 client->connect_notify_context = context;
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
124 }
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
125
4907
5b4c9b20eba0 Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents: 4906
diff changeset
126 static void reconnect_timeout(struct auth_client *client)
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
127 {
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
128 auth_client_connect_missing_servers(client);
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
129 }
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
130
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
131 void auth_client_connect_missing_servers(struct auth_client *client)
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
132 {
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
133 DIR *dirp;
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
134 struct dirent *dp;
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
135 struct stat st;
2082
e22e3827a5f3 Allow using more easily outside dovecot.
Timo Sirainen <tss@iki.fi>
parents: 2077
diff changeset
136
4904
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
137 /* we're chrooted */
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
138 dirp = opendir(".");
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
139 if (dirp == NULL) {
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
140 i_fatal("opendir(.) failed when trying to get list of "
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
141 "authentication servers: %m");
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
142 }
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
143
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
144 client->reconnect = FALSE;
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
145 while ((dp = readdir(dirp)) != NULL) {
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
146 const char *name = dp->d_name;
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
147
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
148 if (name[0] == '.')
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
149 continue;
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
150
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
151 if (auth_server_connection_find_path(client, name) != NULL) {
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
152 /* already connected */
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
153 continue;
2082
e22e3827a5f3 Allow using more easily outside dovecot.
Timo Sirainen <tss@iki.fi>
parents: 2077
diff changeset
154 }
e22e3827a5f3 Allow using more easily outside dovecot.
Timo Sirainen <tss@iki.fi>
parents: 2077
diff changeset
155
4904
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
156 /* Normally they're sockets, but in UnixWare they're
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
157 created as fifos. */
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
158 if (stat(name, &st) == 0 &&
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
159 (S_ISSOCK(st.st_mode) || S_ISFIFO(st.st_mode))) {
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
160 if (auth_server_connection_new(client, name) == NULL)
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
161 client->reconnect = TRUE;
2082
e22e3827a5f3 Allow using more easily outside dovecot.
Timo Sirainen <tss@iki.fi>
parents: 2077
diff changeset
162 }
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
163 }
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
164
4966
5df66ce64c0c If no auth sockets are found in 10 seconds, kill ourself.
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
165 if (client->connections == NULL && !client->reconnect) {
5df66ce64c0c If no auth sockets are found in 10 seconds, kill ourself.
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
166 if (client->missing_sockets_start_time == 0)
5df66ce64c0c If no auth sockets are found in 10 seconds, kill ourself.
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
167 client->missing_sockets_start_time = ioloop_time;
5df66ce64c0c If no auth sockets are found in 10 seconds, kill ourself.
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
168 else if (ioloop_time - client->missing_sockets_start_time >
5df66ce64c0c If no auth sockets are found in 10 seconds, kill ourself.
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
169 AUTH_CLIENT_SOCKET_MAX_WAIT_TIME)
5df66ce64c0c If no auth sockets are found in 10 seconds, kill ourself.
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
170 i_fatal("No authentication sockets found");
5df66ce64c0c If no auth sockets are found in 10 seconds, kill ourself.
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
171 }
5df66ce64c0c If no auth sockets are found in 10 seconds, kill ourself.
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
172
4904
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
173 if (closedir(dirp) < 0)
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
174 i_error("closedir() failed: %m");
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
175
2082
e22e3827a5f3 Allow using more easily outside dovecot.
Timo Sirainen <tss@iki.fi>
parents: 2077
diff changeset
176 if (client->reconnect || client->connections == NULL) {
4904
f98ee68ab23f Removed support for external I/O loop. The point was originally that this
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
177 if (client->to_reconnect == NULL) {
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
178 client->to_reconnect =
4966
5df66ce64c0c If no auth sockets are found in 10 seconds, kill ourself.
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
179 timeout_add(1000, reconnect_timeout, client);
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
180 }
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
181 } else if (client->to_reconnect != NULL)
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
182 timeout_remove(&client->to_reconnect);
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
183
1705
5121567de516 bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1702
diff changeset
184 if (client->connect_notify_callback != NULL) {
5121567de516 bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1702
diff changeset
185 client->connect_notify_callback(client,
5121567de516 bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1702
diff changeset
186 auth_client_is_connected(client),
5121567de516 bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1702
diff changeset
187 client->connect_notify_context);
5121567de516 bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1702
diff changeset
188 }
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 }