annotate src/auth/mech-login.c @ 3064:2d33734b16d5 HEAD

Split auth_request* functions from mech.c to auth-request.c
author Timo Sirainen <tss@iki.fi>
date Fri, 07 Jan 2005 20:51:10 +0200
parents 052f3a5743af
children 29d83a8bb50d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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,
2346
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 const unsigned char *data, size_t data_size,
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 mech_callback_t *callback)
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37 {
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38 static const char prompt2[] = "Password:";
2522
a07fb16b9a24 Changed "invalid username" error message.
Timo Sirainen <tss@iki.fi>
parents: 2510
diff changeset
39 const char *error;
2346
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2522
diff changeset
41 request->callback = callback;
2346
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2522
diff changeset
43 if (request->user == NULL) {
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2522
diff changeset
44 request->user = p_strndup(request->pool, data, data_size);
2346
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45
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 if (!mech_fix_username(request->user, &error)) {
2346
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 if (verbose) {
2522
a07fb16b9a24 Changed "invalid username" error message.
Timo Sirainen <tss@iki.fi>
parents: 2510
diff changeset
48 i_info("login(%s): %s",
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2522
diff changeset
49 get_log_prefix(request), error);
2346
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50 }
3064
2d33734b16d5 Split auth_request* functions from mech.c to auth-request.c
Timo Sirainen <tss@iki.fi>
parents: 3058
diff changeset
51 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
52 return;
2346
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53 }
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2522
diff changeset
55 callback(request, AUTH_CLIENT_RESULT_CONTINUE,
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2522
diff changeset
56 prompt2, strlen(prompt2));
2346
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 } else {
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58 char *pass = p_strndup(unsafe_data_stack_pool, data, data_size);
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2522
diff changeset
59 passdb->verify_plain(request, pass, verify_callback);
2346
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60 safe_memset(pass, 0, strlen(pass));
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 }
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
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2522
diff changeset
64 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
65 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
66 const unsigned char *data __attr_unused__,
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2522
diff changeset
67 size_t data_size __attr_unused__,
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2522
diff changeset
68 mech_callback_t *callback)
2346
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 {
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 static const char prompt1[] = "Username:";
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2522
diff changeset
72 callback(request, AUTH_CLIENT_RESULT_CONTINUE,
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2522
diff changeset
73 prompt1, strlen(prompt1));
2346
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 }
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 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
77 {
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2522
diff changeset
78 pool_unref(request->pool);
2346
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
79 }
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81 static struct auth_request *mech_login_auth_new(void)
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82 {
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2522
diff changeset
83 struct auth_request *request;
2346
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
84 pool_t pool;
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 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
87 request = p_new(pool, struct auth_request, 1);
2346
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2522
diff changeset
89 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
90 request->pool = pool;
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2522
diff changeset
91 return request;
2346
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92 }
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94 const struct mech_module mech_login = {
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 "LOGIN",
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
96
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2522
diff changeset
97 MEMBER(flags) MECH_SEC_PLAINTEXT,
2346
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99 MEMBER(passdb_need_plain) TRUE,
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
100 MEMBER(passdb_need_credentials) FALSE,
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
101
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
102 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
103 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
104 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
105 mech_login_auth_free
2346
13ed27a24f46 Added LOGIN SASL mechanism. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106 };