Mercurial > dovecot > core-2.2
comparison src/lib-master/master-login-auth.c @ 11018:2e08ce368bc0 HEAD
Added support for userdb lookup to fail with a reason (many API changes).
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 31 Mar 2010 19:21:09 +0300 |
parents | cab5f2e7b806 |
children | 260e190306b0 |
comparison
equal
deleted
inserted
replaced
11017:ce7ed594d99e | 11018:2e08ce368bc0 |
---|---|
57 void *key, *value; | 57 void *key, *value; |
58 | 58 |
59 iter = hash_table_iterate_init(auth->requests); | 59 iter = hash_table_iterate_init(auth->requests); |
60 while (hash_table_iterate(iter, &key, &value)) { | 60 while (hash_table_iterate(iter, &key, &value)) { |
61 struct master_login_auth_request *request = value; | 61 struct master_login_auth_request *request = value; |
62 request->callback(NULL, request->context); | 62 request->callback(NULL, MASTER_AUTH_ERRMSG_INTERNAL_FAILURE, |
63 request->context); | |
63 i_free(request); | 64 i_free(request); |
64 } | 65 } |
65 hash_table_iterate_deinit(&iter); | 66 hash_table_iterate_deinit(&iter); |
66 hash_table_clear(auth->requests, FALSE); | 67 hash_table_clear(auth->requests, FALSE); |
67 | 68 |
133 } | 134 } |
134 id = (unsigned int)strtoul(list[0], NULL, 10); | 135 id = (unsigned int)strtoul(list[0], NULL, 10); |
135 | 136 |
136 request = master_login_auth_lookup_request(auth, id); | 137 request = master_login_auth_lookup_request(auth, id); |
137 if (request != NULL) { | 138 if (request != NULL) { |
138 request->callback(list + 1, request->context); | 139 request->callback(list + 1, NULL, request->context); |
139 i_free(request); | 140 i_free(request); |
140 } | 141 } |
141 return TRUE; | 142 return TRUE; |
142 } | 143 } |
143 | 144 |
150 | 151 |
151 id = (unsigned int)strtoul(args, NULL, 10); | 152 id = (unsigned int)strtoul(args, NULL, 10); |
152 request = master_login_auth_lookup_request(auth, id); | 153 request = master_login_auth_lookup_request(auth, id); |
153 if (request != NULL) { | 154 if (request != NULL) { |
154 i_error("Authenticated user not found from userdb"); | 155 i_error("Authenticated user not found from userdb"); |
155 request->callback(NULL, request->context); | 156 request->callback(NULL, MASTER_AUTH_ERRMSG_INTERNAL_FAILURE, |
157 request->context); | |
156 i_free(request); | 158 i_free(request); |
157 } | 159 } |
158 return TRUE; | 160 return TRUE; |
159 } | 161 } |
160 | 162 |
161 static bool | 163 static bool |
162 master_login_auth_input_fail(struct master_login_auth *auth, const char *args) | 164 master_login_auth_input_fail(struct master_login_auth *auth, |
165 const char *args_line) | |
163 { | 166 { |
164 struct master_login_auth_request *request; | 167 struct master_login_auth_request *request; |
165 const char *error; | 168 const char *const *args, *error = NULL; |
166 unsigned int id; | 169 unsigned int i, id; |
167 | 170 |
168 error = strchr(args, '\t'); | 171 args = t_strsplit(args_line, "\t"); |
169 if (error != NULL) | 172 if (args[0] == NULL) { |
170 error++; | 173 i_error("Auth server sent broken FAIL line"); |
171 | 174 return FALSE; |
172 id = (unsigned int)strtoul(args, NULL, 10); | 175 } |
176 for (i = 1; args[i] != NULL; i++) { | |
177 if (strncmp(args[i], "reason=", 7) == 0) | |
178 error = args[i] + 7; | |
179 } | |
180 | |
181 id = (unsigned int)strtoul(args[0], NULL, 10); | |
173 request = master_login_auth_lookup_request(auth, id); | 182 request = master_login_auth_lookup_request(auth, id); |
174 if (request != NULL) { | 183 if (request != NULL) { |
175 i_error("Internal auth failure"); | 184 if (error != NULL) |
176 request->callback(NULL, request->context); | 185 i_error("Internal auth failure"); |
186 request->callback(NULL, error != NULL ? error : | |
187 MASTER_AUTH_ERRMSG_INTERNAL_FAILURE, | |
188 request->context); | |
177 i_free(request); | 189 i_free(request); |
178 } | 190 } |
179 return TRUE; | 191 return TRUE; |
180 } | 192 } |
181 | 193 |
264 string_t *str; | 276 string_t *str; |
265 | 277 |
266 str = t_str_new(128); | 278 str = t_str_new(128); |
267 if (auth->fd == -1) { | 279 if (auth->fd == -1) { |
268 if (master_login_auth_connect(auth) < 0) { | 280 if (master_login_auth_connect(auth) < 0) { |
269 callback(NULL, context); | 281 callback(NULL, MASTER_AUTH_ERRMSG_INTERNAL_FAILURE, |
282 context); | |
270 return; | 283 return; |
271 } | 284 } |
272 str_printfa(str, "VERSION\t%u\t%u\n", | 285 str_printfa(str, "VERSION\t%u\t%u\n", |
273 AUTH_MASTER_PROTOCOL_MAJOR_VERSION, | 286 AUTH_MASTER_PROTOCOL_MAJOR_VERSION, |
274 AUTH_MASTER_PROTOCOL_MINOR_VERSION); | 287 AUTH_MASTER_PROTOCOL_MINOR_VERSION); |