Mercurial > dovecot > core-2.2
annotate src/auth/mech-login.c @ 3071:c7db6b291daa HEAD
API cleanup
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 08 Jan 2005 23:22:52 +0200 |
parents | 131151e25e4b |
children | 289a98ba5d95 |
rev | line source |
---|---|
2346
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1 /* |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 * LOGIN authentication mechanism. |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 * |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 * Copyright (c) 2004 Andrey Panin <pazke@donpac.ru> |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 * |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 * This program is free software; you can redistribute it and/or modify |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 * it under the terms of the GNU Lesser General Public License as published |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 * by the Free Software Foundation; either version 2 of the License, or |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 * (at your option) any later version. |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 */ |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 #include "common.h" |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 #include "mech.h" |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 #include "passdb.h" |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 #include "safe-memset.h" |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 static void verify_callback(enum passdb_result result, |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 struct auth_request *request) |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 { |
3058
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
20 switch (result) { |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
21 case PASSDB_RESULT_OK: |
3064
2d33734b16d5
Split auth_request* functions from mech.c to auth-request.c
Timo Sirainen <tss@iki.fi>
parents:
3058
diff
changeset
|
22 auth_request_success(request, NULL, 0); |
3058
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
23 break; |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
24 case PASSDB_RESULT_INTERNAL_FAILURE: |
3064
2d33734b16d5
Split auth_request* functions from mech.c to auth-request.c
Timo Sirainen <tss@iki.fi>
parents:
3058
diff
changeset
|
25 auth_request_internal_failure(request); |
3058
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
26 break; |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
27 default: |
3064
2d33734b16d5
Split auth_request* functions from mech.c to auth-request.c
Timo Sirainen <tss@iki.fi>
parents:
3058
diff
changeset
|
28 auth_request_fail(request); |
3058
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
29 break; |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
30 } |
2346
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 } |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2522
diff
changeset
|
33 static void |
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2522
diff
changeset
|
34 mech_login_auth_continue(struct auth_request *request, |
3071 | 35 const unsigned char *data, size_t data_size) |
2346
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 { |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 static const char prompt2[] = "Password:"; |
3065
29d83a8bb50d
Reorganized the code to have less global/static variables.
Timo Sirainen <tss@iki.fi>
parents:
3064
diff
changeset
|
38 const char *username, *error; |
2346
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2522
diff
changeset
|
40 if (request->user == NULL) { |
3065
29d83a8bb50d
Reorganized the code to have less global/static variables.
Timo Sirainen <tss@iki.fi>
parents:
3064
diff
changeset
|
41 username = t_strndup(data, data_size); |
2346
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 |
3065
29d83a8bb50d
Reorganized the code to have less global/static variables.
Timo Sirainen <tss@iki.fi>
parents:
3064
diff
changeset
|
43 if (!auth_request_set_username(request, username, &error)) { |
3069 | 44 auth_request_log_info(request, "login", "%s", error); |
3064
2d33734b16d5
Split auth_request* functions from mech.c to auth-request.c
Timo Sirainen <tss@iki.fi>
parents:
3058
diff
changeset
|
45 auth_request_fail(request); |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2522
diff
changeset
|
46 return; |
2346
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 } |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
48 |
3071 | 49 request->callback(request, AUTH_CLIENT_RESULT_CONTINUE, |
50 prompt2, strlen(prompt2)); | |
2346
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 } else { |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 char *pass = p_strndup(unsafe_data_stack_pool, data, data_size); |
3068 | 53 auth_request_verify_plain(request, pass, verify_callback); |
2346
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 safe_memset(pass, 0, strlen(pass)); |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 } |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 } |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2522
diff
changeset
|
58 static void |
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2522
diff
changeset
|
59 mech_login_auth_initial(struct auth_request *request, |
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2522
diff
changeset
|
60 const unsigned char *data __attr_unused__, |
3071 | 61 size_t data_size __attr_unused__) |
2346
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 { |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
63 static const char prompt1[] = "Username:"; |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 |
3071 | 65 request->callback(request, AUTH_CLIENT_RESULT_CONTINUE, |
66 prompt1, strlen(prompt1)); | |
2346
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
67 } |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2522
diff
changeset
|
69 static void mech_login_auth_free(struct auth_request *request) |
2346
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 { |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2522
diff
changeset
|
71 pool_unref(request->pool); |
2346
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 } |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 |
3071 | 74 static struct auth_request *mech_login_auth_new(mech_callback_t *callback) |
2346
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 { |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2522
diff
changeset
|
76 struct auth_request *request; |
2346
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
77 pool_t pool; |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 pool = pool_alloconly_create("login_auth_request", 256); |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2522
diff
changeset
|
80 request = p_new(pool, struct auth_request, 1); |
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2522
diff
changeset
|
81 request->refcount = 1; |
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2522
diff
changeset
|
82 request->pool = pool; |
3071 | 83 request->callback = callback; |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2522
diff
changeset
|
84 return request; |
2346
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
85 } |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
86 |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 const struct mech_module mech_login = { |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
88 "LOGIN", |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
89 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2522
diff
changeset
|
90 MEMBER(flags) MECH_SEC_PLAINTEXT, |
2346
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
91 |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
92 MEMBER(passdb_need_plain) TRUE, |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
93 MEMBER(passdb_need_credentials) FALSE, |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
94 |
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
95 mech_login_auth_new, |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2522
diff
changeset
|
96 mech_login_auth_initial, |
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2522
diff
changeset
|
97 mech_login_auth_continue, |
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2522
diff
changeset
|
98 mech_login_auth_free |
2346
13ed27a24f46
Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
99 }; |