annotate src/auth/auth-request-handler.c @ 4451:1a35d53c18fc HEAD

Array API redesigned to work using unions. It now provides type safety without having to enable DEBUG, as long as the compiler supports typeof(). Its API changed a bit. It now allows directly accessing the array contents, although that's not necessarily recommended. Changed existing array usage to be type safe in a bit more places. Removed array_t completely. Also did s/modifyable/modifiable/.
author Timo Sirainen <tss@iki.fi>
date Wed, 28 Jun 2006 16:10:25 +0300
parents 10cdcfe98cfc
children d83f2a6e1f45
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 /* Copyright (C) 2005 Timo Sirainen */
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "common.h"
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
4 #include "ioloop.h"
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
5 #include "buffer.h"
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
6 #include "base64.h"
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
7 #include "hash.h"
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
8 #include "str.h"
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
9 #include "str-sanitize.h"
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
10 #include "auth-request.h"
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include "auth-request-handler.h"
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
12
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
13 #include <stdlib.h>
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
14
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
15 struct auth_request_handler {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
16 int refcount;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
17 pool_t pool;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
18 struct hash_table *requests;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
19
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
20 struct auth *auth;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
21 unsigned int connect_uid, client_pid;
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
23 auth_request_callback_t *callback;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
24 void *context;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
25
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
26 auth_request_callback_t *master_callback;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
27 };
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
28
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
29 static buffer_t *auth_failures_buf;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
30 static struct timeout *to_auth_failures;
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 struct auth_request_handler *
3518
c444e76648e8 Removed unused code
Timo Sirainen <tss@iki.fi>
parents: 3432
diff changeset
33 auth_request_handler_create(struct auth *auth,
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 auth_request_callback_t *callback, void *context,
3308
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3171
diff changeset
35 auth_request_callback_t *master_callback)
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 {
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
37 struct auth_request_handler *handler;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
38 pool_t pool;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
39
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
40 pool = pool_alloconly_create("auth request handler", 4096);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
41
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
42 handler = p_new(pool, struct auth_request_handler, 1);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
43 handler->refcount = 1;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
44 handler->pool = pool;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
45 handler->requests = hash_create(default_pool, pool, 0, NULL, NULL);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
46 handler->auth = auth;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
47 handler->callback = callback;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
48 handler->context = context;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
49 handler->master_callback = master_callback;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
50 return handler;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
51 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
52
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
53 void auth_request_handler_unref(struct auth_request_handler **_handler)
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
54 {
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
55 struct auth_request_handler *handler = *_handler;
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
56 struct hash_iterate_context *iter;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
57 void *key, *value;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
58
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
59 *_handler = NULL;
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
60 i_assert(handler->refcount > 0);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
61 if (--handler->refcount > 0)
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
62 return;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
63
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
64 iter = hash_iterate_init(handler->requests);
3952
d7a0354861b8 If authentication client disconnects while it still has pending requests,
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
65 while (hash_iterate(iter, &key, &value)) {
d7a0354861b8 If authentication client disconnects while it still has pending requests,
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
66 struct auth_request *auth_request = value;
d7a0354861b8 If authentication client disconnects while it still has pending requests,
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
67
d7a0354861b8 If authentication client disconnects while it still has pending requests,
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
68 auth_request_unref(&auth_request);
d7a0354861b8 If authentication client disconnects while it still has pending requests,
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
69 }
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
70 hash_iterate_deinit(iter);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
71
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
72 /* notify parent that we're done with all requests */
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
73 handler->callback(NULL, handler->context);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
74
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
75 hash_destroy(handler->requests);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
76 pool_unref(handler->pool);
3077
eb46a5dee02d Changed the way multiple auth processes are handled. It no longer uses a pid
Timo Sirainen <tss@iki.fi>
parents: 3074
diff changeset
77 }
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78
3077
eb46a5dee02d Changed the way multiple auth processes are handled. It no longer uses a pid
Timo Sirainen <tss@iki.fi>
parents: 3074
diff changeset
79 void auth_request_handler_set(struct auth_request_handler *handler,
eb46a5dee02d Changed the way multiple auth processes are handled. It no longer uses a pid
Timo Sirainen <tss@iki.fi>
parents: 3074
diff changeset
80 unsigned int connect_uid,
eb46a5dee02d Changed the way multiple auth processes are handled. It no longer uses a pid
Timo Sirainen <tss@iki.fi>
parents: 3074
diff changeset
81 unsigned int client_pid)
eb46a5dee02d Changed the way multiple auth processes are handled. It no longer uses a pid
Timo Sirainen <tss@iki.fi>
parents: 3074
diff changeset
82 {
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
83 handler->connect_uid = connect_uid;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
84 handler->client_pid = client_pid;
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85 }
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
87 static void auth_request_handler_remove(struct auth_request_handler *handler,
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
88 struct auth_request *request)
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89 {
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
90 hash_remove(handler->requests, POINTER_CAST(request->id));
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
91 auth_request_unref(&request);
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92 }
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94 void auth_request_handler_check_timeouts(struct auth_request_handler *handler)
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 {
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
96 struct hash_iterate_context *iter;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
97 void *key, *value;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
98
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
99 iter = hash_iterate_init(handler->requests);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
100 while (hash_iterate(iter, &key, &value)) {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
101 struct auth_request *request = value;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
102
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
103 if (request->created + AUTH_REQUEST_TIMEOUT < ioloop_time)
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
104 auth_request_handler_remove(handler, request);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
105 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
106 hash_iterate_deinit(iter);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
107 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
108
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
109 static const char *get_client_extra_fields(struct auth_request *request)
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
110 {
3432
079ec5c2d665 Last change caused user-given passwords to be cached, and later the password
Timo Sirainen <tss@iki.fi>
parents: 3338
diff changeset
111 string_t *str;
3520
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3518
diff changeset
112 const char **fields, *extra_fields;
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
113 unsigned int src, dest;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
114
3520
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3518
diff changeset
115 extra_fields = request->extra_fields == NULL ? NULL :
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3518
diff changeset
116 auth_stream_reply_export(request->extra_fields);
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3518
diff changeset
117
3432
079ec5c2d665 Last change caused user-given passwords to be cached, and later the password
Timo Sirainen <tss@iki.fi>
parents: 3338
diff changeset
118 if (!request->proxy) {
3520
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3518
diff changeset
119 if (extra_fields == NULL)
3432
079ec5c2d665 Last change caused user-given passwords to be cached, and later the password
Timo Sirainen <tss@iki.fi>
parents: 3338
diff changeset
120 return NULL;
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
121
3432
079ec5c2d665 Last change caused user-given passwords to be cached, and later the password
Timo Sirainen <tss@iki.fi>
parents: 3338
diff changeset
122 /* we only wish to remove all fields prefixed with "userdb_" */
3520
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3518
diff changeset
123 if (strstr(extra_fields, "userdb_") == NULL)
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3518
diff changeset
124 return extra_fields;
3432
079ec5c2d665 Last change caused user-given passwords to be cached, and later the password
Timo Sirainen <tss@iki.fi>
parents: 3338
diff changeset
125 }
079ec5c2d665 Last change caused user-given passwords to be cached, and later the password
Timo Sirainen <tss@iki.fi>
parents: 3338
diff changeset
126
079ec5c2d665 Last change caused user-given passwords to be cached, and later the password
Timo Sirainen <tss@iki.fi>
parents: 3338
diff changeset
127 str = t_str_new(128);
079ec5c2d665 Last change caused user-given passwords to be cached, and later the password
Timo Sirainen <tss@iki.fi>
parents: 3338
diff changeset
128 if (request->proxy) {
079ec5c2d665 Last change caused user-given passwords to be cached, and later the password
Timo Sirainen <tss@iki.fi>
parents: 3338
diff changeset
129 /* we're proxying - send back the password that was
079ec5c2d665 Last change caused user-given passwords to be cached, and later the password
Timo Sirainen <tss@iki.fi>
parents: 3338
diff changeset
130 sent by user (not the password in passdb). */
079ec5c2d665 Last change caused user-given passwords to be cached, and later the password
Timo Sirainen <tss@iki.fi>
parents: 3338
diff changeset
131 str_printfa(str, "pass=%s", request->mech_password);
079ec5c2d665 Last change caused user-given passwords to be cached, and later the password
Timo Sirainen <tss@iki.fi>
parents: 3338
diff changeset
132 }
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
133
3520
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3518
diff changeset
134 fields = t_strsplit(extra_fields, "\t");
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
135 for (src = dest = 0; fields[src] != NULL; src++) {
3432
079ec5c2d665 Last change caused user-given passwords to be cached, and later the password
Timo Sirainen <tss@iki.fi>
parents: 3338
diff changeset
136 if (strncmp(fields[src], "userdb_", 7) != 0) {
079ec5c2d665 Last change caused user-given passwords to be cached, and later the password
Timo Sirainen <tss@iki.fi>
parents: 3338
diff changeset
137 if (str_len(str) > 0)
079ec5c2d665 Last change caused user-given passwords to be cached, and later the password
Timo Sirainen <tss@iki.fi>
parents: 3338
diff changeset
138 str_append_c(str, '\t');
079ec5c2d665 Last change caused user-given passwords to be cached, and later the password
Timo Sirainen <tss@iki.fi>
parents: 3338
diff changeset
139 str_append(str, fields[src]);
079ec5c2d665 Last change caused user-given passwords to be cached, and later the password
Timo Sirainen <tss@iki.fi>
parents: 3338
diff changeset
140 }
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
141 }
3432
079ec5c2d665 Last change caused user-given passwords to be cached, and later the password
Timo Sirainen <tss@iki.fi>
parents: 3338
diff changeset
142 return str_c(str);
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
143 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
144
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
145 static void auth_callback(struct auth_request *request,
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
146 enum auth_client_result result,
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
147 const void *reply, size_t reply_size)
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
148 {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
149 struct auth_request_handler *handler = request->context;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
150 string_t *str;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
151 const char *fields;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
152
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
153 t_push();
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
154
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
155 str = t_str_new(128 + MAX_BASE64_ENCODED_SIZE(reply_size));
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
156 switch (result) {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
157 case AUTH_CLIENT_RESULT_CONTINUE:
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
158 str_printfa(str, "CONT\t%u\t", request->id);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
159 base64_encode(reply, reply_size, str);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
160 request->accept_input = TRUE;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
161 handler->callback(str_c(str), handler->context);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
162 break;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
163 case AUTH_CLIENT_RESULT_SUCCESS:
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
164 str_printfa(str, "OK\t%u\tuser=%s", request->id, request->user);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
165 if (reply_size > 0) {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
166 str_append(str, "\tresp=");
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
167 base64_encode(reply, reply_size, str);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
168 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
169 fields = get_client_extra_fields(request);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
170 if (fields != NULL) {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
171 str_append_c(str, '\t');
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
172 str_append(str, fields);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
173 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
174
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
175 if (request->no_login || handler->master_callback == NULL) {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
176 /* this request doesn't have to wait for master
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
177 process to pick it up. delete it */
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
178 auth_request_handler_remove(handler, request);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
179 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
180 handler->callback(str_c(str), handler->context);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
181 break;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
182 case AUTH_CLIENT_RESULT_FAILURE:
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
183 str_printfa(str, "FAIL\t%u", request->id);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
184 if (request->user != NULL)
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
185 str_printfa(str, "\tuser=%s", request->user);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
186 if (request->internal_failure)
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
187 str_append(str, "\ttemp");
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
188 fields = get_client_extra_fields(request);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
189 if (fields != NULL) {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
190 str_append_c(str, '\t');
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
191 str_append(str, fields);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
192 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
193
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
194 if (request->delayed_failure) {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
195 /* we came here from flush_failures() */
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
196 handler->callback(str_c(str), handler->context);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
197 break;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
198 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
199
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
200 /* remove the request from requests-list */
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
201 auth_request_ref(request);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
202 auth_request_handler_remove(handler, request);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
203
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
204 if (request->no_failure_delay) {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
205 /* passdb specifically requested not to delay the
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
206 reply. */
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
207 handler->callback(str_c(str), handler->context);
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
208 auth_request_unref(&request);
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
209 } else {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
210 /* failure. don't announce it immediately to avoid
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
211 a) timing attacks, b) flooding */
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
212 request->delayed_failure = TRUE;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
213 handler->refcount++;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
214 buffer_append(auth_failures_buf,
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
215 &request, sizeof(request));
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
216 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
217 break;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
218 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
219 /* NOTE: request may be destroyed now */
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
220
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
221 auth_request_handler_unref(&handler);
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
222
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
223 t_pop();
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
224 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
225
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
226 static void auth_request_handler_auth_fail(struct auth_request_handler *handler,
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
227 struct auth_request *request,
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
228 const char *reason)
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
229 {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
230 string_t *reply = t_str_new(64);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
231
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
232 auth_request_log_info(request, request->mech->mech_name, "%s", reason);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
233
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
234 str_printfa(reply, "FAIL\t%u\treason=%s", request->id, reason);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
235 handler->callback(str_c(reply), handler->context);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
236
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
237 auth_request_handler_remove(handler, request);
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
238 }
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
239
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3520
diff changeset
240 bool auth_request_handler_auth_begin(struct auth_request_handler *handler,
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3520
diff changeset
241 const char *args)
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
242 {
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
243 struct mech_module *mech;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
244 struct auth_request *request;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
245 const char *const *list, *name, *arg, *initial_resp;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
246 const void *initial_resp_data;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
247 size_t initial_resp_len;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
248 unsigned int id;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
249 buffer_t *buf;
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3520
diff changeset
250 bool valid_client_cert;
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
251
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
252 /* <id> <mechanism> [...] */
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
253 list = t_strsplit(args, "\t");
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
254 if (list[0] == NULL || list[1] == NULL) {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
255 i_error("BUG: Authentication client %u "
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
256 "sent broken AUTH request", handler->client_pid);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
257 return FALSE;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
258 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
259
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
260 id = (unsigned int)strtoul(list[0], NULL, 10);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
261
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
262 mech = mech_module_find(list[1]);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
263 if (mech == NULL) {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
264 /* unsupported mechanism */
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
265 i_error("BUG: Authentication client %u requested unsupported "
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
266 "authentication mechanism %s", handler->client_pid,
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
267 str_sanitize(list[1], MAX_MECH_NAME_LEN));
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
268 return FALSE;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
269 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
270
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
271 request = auth_request_new(handler->auth, mech, auth_callback, handler);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
272 request->connect_uid = handler->connect_uid;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
273 request->client_pid = handler->client_pid;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
274 request->id = id;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
275
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
276 /* parse optional parameters */
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
277 initial_resp = NULL;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
278 valid_client_cert = FALSE;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
279 for (list += 2; *list != NULL; list++) {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
280 arg = strchr(*list, '=');
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
281 if (arg == NULL) {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
282 name = *list;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
283 arg = "";
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
284 } else {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
285 name = t_strdup_until(*list, arg);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
286 arg++;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
287 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
288
3338
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
289 if (auth_request_import(request, name, arg))
e5ce49c8524a USER auth command requires now service parameter and supports also others
Timo Sirainen <tss@iki.fi>
parents: 3308
diff changeset
290 ;
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
291 else if (strcmp(name, "resp") == 0)
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
292 initial_resp = arg;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
293 else if (strcmp(name, "valid-client-cert") == 0)
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
294 valid_client_cert = TRUE;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
295 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
296
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
297 if (request->service == NULL) {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
298 i_error("BUG: Authentication client %u "
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
299 "didn't specify service in request",
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
300 handler->client_pid);
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
301 auth_request_unref(&request);
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
302 return FALSE;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
303 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
304
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
305 hash_insert(handler->requests, POINTER_CAST(id), request);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
306
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
307 if (request->auth->ssl_require_client_cert && !valid_client_cert) {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
308 /* we fail without valid certificate */
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
309 auth_request_handler_auth_fail(handler, request,
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
310 "Client didn't present valid SSL certificate");
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
311 return TRUE;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
312 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
313
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
314 if (initial_resp == NULL) {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
315 initial_resp_data = NULL;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
316 initial_resp_len = 0;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
317 } else {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
318 size_t len = strlen(initial_resp);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
319 buf = buffer_create_dynamic(pool_datastack_create(),
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
320 MAX_BASE64_DECODED_SIZE(len));
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
321 if (base64_decode(initial_resp, len, NULL, buf) < 0) {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
322 auth_request_handler_auth_fail(handler, request,
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
323 "Invalid base64 data in initial response");
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
324 return TRUE;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
325 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
326 initial_resp_data = buf->data;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
327 initial_resp_len = buf->used;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
328 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
329
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
330 /* handler is referenced until auth_callback is called. */
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
331 handler->refcount++;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
332 auth_request_initial(request, initial_resp_data, initial_resp_len);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
333 return TRUE;
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
334 }
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
335
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3520
diff changeset
336 bool auth_request_handler_auth_continue(struct auth_request_handler *handler,
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3520
diff changeset
337 const char *args)
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
338 {
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
339 struct auth_request *request;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
340 const char *data;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
341 size_t data_len;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
342 buffer_t *buf;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
343 unsigned int id;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
344
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
345 data = strchr(args, '\t');
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
346 if (data++ == NULL) {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
347 i_error("BUG: Authentication client sent broken CONT request");
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
348 return FALSE;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
349 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
350
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
351 id = (unsigned int)strtoul(args, NULL, 10);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
352
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
353 request = hash_lookup(handler->requests, POINTER_CAST(id));
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
354 if (request == NULL) {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
355 string_t *reply = t_str_new(64);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
356
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
357 str_printfa(reply, "FAIL\t%u\treason=Timeouted", id);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
358 handler->callback(str_c(reply), handler->context);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
359 return TRUE;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
360 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
361
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
362 /* accept input only once after mechanism has sent a CONT reply */
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
363 if (!request->accept_input) {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
364 auth_request_handler_auth_fail(handler, request,
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
365 "Unexpected continuation");
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
366 return TRUE;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
367 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
368 request->accept_input = FALSE;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
369
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
370 data_len = strlen(data);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
371 buf = buffer_create_dynamic(pool_datastack_create(),
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
372 MAX_BASE64_DECODED_SIZE(data_len));
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
373 if (base64_decode(data, data_len, NULL, buf) < 0) {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
374 auth_request_handler_auth_fail(handler, request,
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
375 "Invalid base64 data in continued response");
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
376 return TRUE;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
377 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
378
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
379 /* handler is referenced until auth_callback is called. */
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
380 handler->refcount++;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
381 auth_request_continue(request, buf->data, buf->used);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
382 return TRUE;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
383 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
384
3520
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3518
diff changeset
385 static void userdb_callback(struct auth_stream_reply *reply,
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3518
diff changeset
386 struct auth_request *request)
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
387 {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
388 struct auth_request_handler *handler = request->context;
3520
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3518
diff changeset
389 string_t *str;
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
390
3171
8a3b57385eca Added state variable for auth_request and several assertions to make sure
Timo Sirainen <tss@iki.fi>
parents: 3166
diff changeset
391 i_assert(request->state == AUTH_REQUEST_STATE_USERDB);
8a3b57385eca Added state variable for auth_request and several assertions to make sure
Timo Sirainen <tss@iki.fi>
parents: 3166
diff changeset
392
8a3b57385eca Added state variable for auth_request and several assertions to make sure
Timo Sirainen <tss@iki.fi>
parents: 3166
diff changeset
393 request->state = AUTH_REQUEST_STATE_FINISHED;
8a3b57385eca Added state variable for auth_request and several assertions to make sure
Timo Sirainen <tss@iki.fi>
parents: 3166
diff changeset
394
3520
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3518
diff changeset
395 str = t_str_new(256);
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3518
diff changeset
396 if (reply == NULL)
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3518
diff changeset
397 str_printfa(str, "NOTFOUND\t%u", request->id);
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
398 else {
3520
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3518
diff changeset
399 str_printfa(str, "USER\t%u\t", request->id);
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3518
diff changeset
400 str_append(str, auth_stream_reply_export(reply));
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
401 }
3520
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3518
diff changeset
402 handler->master_callback(str_c(str), request->master);
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
403
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
404 auth_request_unref(&request);
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
405 auth_request_handler_unref(&handler);
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
406 }
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
407
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
408 void auth_request_handler_master_request(struct auth_request_handler *handler,
3308
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3171
diff changeset
409 struct auth_master_connection *master,
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
410 unsigned int id,
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
411 unsigned int client_id)
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
412 {
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
413 struct auth_request *request;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
414 string_t *reply;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
415
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
416 reply = t_str_new(64);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
417
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
418 request = hash_lookup(handler->requests, POINTER_CAST(client_id));
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
419 if (request == NULL) {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
420 i_error("Master request %u.%u not found",
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
421 handler->client_pid, client_id);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
422 str_printfa(reply, "NOTFOUND\t%u", id);
3308
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3171
diff changeset
423 handler->master_callback(str_c(reply), master);
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
424 return;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
425 }
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
426
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
427 auth_request_ref(request);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
428 auth_request_handler_remove(handler, request);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
429
3171
8a3b57385eca Added state variable for auth_request and several assertions to make sure
Timo Sirainen <tss@iki.fi>
parents: 3166
diff changeset
430 if (request->state != AUTH_REQUEST_STATE_FINISHED ||
8a3b57385eca Added state variable for auth_request and several assertions to make sure
Timo Sirainen <tss@iki.fi>
parents: 3166
diff changeset
431 !request->successful) {
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
432 i_error("Master requested unfinished authentication request "
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
433 "%u.%u", handler->client_pid, client_id);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
434 str_printfa(reply, "NOTFOUND\t%u", id);
3308
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3171
diff changeset
435 handler->master_callback(str_c(reply), master);
4401
10cdcfe98cfc Fixed memory leak in error handling.
Timo Sirainen <tss@iki.fi>
parents: 3952
diff changeset
436 auth_request_unref(&request);
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
437 } else {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
438 /* the request isn't being referenced anywhere anymore,
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
439 so we can do a bit of kludging.. replace the request's
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
440 old client_id with master's id. */
3171
8a3b57385eca Added state variable for auth_request and several assertions to make sure
Timo Sirainen <tss@iki.fi>
parents: 3166
diff changeset
441 request->state = AUTH_REQUEST_STATE_USERDB;
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
442 request->id = id;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
443 request->context = handler;
3308
3f090bcaffcc Allow multiple master connections for a single listener.
Timo Sirainen <tss@iki.fi>
parents: 3171
diff changeset
444 request->master = master;
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
445
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
446 /* handler is referenced until userdb_callback is called. */
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
447 handler->refcount++;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
448 auth_request_lookup_user(request, userdb_callback);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
449 }
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
450 }
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
451
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
452 void auth_request_handler_flush_failures(void)
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
453 {
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
454 struct auth_request **auth_request;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
455 size_t i, size;
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
456
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4401
diff changeset
457 auth_request = buffer_get_modifiable_data(auth_failures_buf, &size);
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
458 size /= sizeof(*auth_request);
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
459
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
460 for (i = 0; i < size; i++) {
3171
8a3b57385eca Added state variable for auth_request and several assertions to make sure
Timo Sirainen <tss@iki.fi>
parents: 3166
diff changeset
461 i_assert(auth_request[i]->state == AUTH_REQUEST_STATE_FINISHED);
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
462 auth_request[i]->callback(auth_request[i],
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
463 AUTH_CLIENT_RESULT_FAILURE, NULL, 0);
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
464 auth_request_unref(&auth_request[i]);
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
465 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
466 buffer_set_used_size(auth_failures_buf, 0);
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
467 }
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
468
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
469 static void auth_failure_timeout(void *context __attr_unused__)
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
470 {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
471 auth_request_handler_flush_failures();
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
472 }
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
473
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
474 void auth_request_handler_init(void)
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
475 {
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
476 auth_failures_buf = buffer_create_dynamic(default_pool, 1024);
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
477 to_auth_failures = timeout_add(2000, auth_failure_timeout, NULL);
3074
3feb38ff17f5 Moving code around.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
478 }
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
479
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
480 void auth_request_handler_deinit(void)
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
481 {
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
482 buffer_free(auth_failures_buf);
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
483 timeout_remove(&to_auth_failures);
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3077
diff changeset
484 }