Mercurial > dovecot > original-hg > dovecot-1.2
comparison src/auth/auth-plain.c @ 0:3b1985cbc908 HEAD
Initial revision
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 09 Aug 2002 12:15:38 +0300 |
parents | |
children | 82b7de533f98 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3b1985cbc908 |
---|---|
1 /* Copyright (C) 2002 Timo Sirainen */ | |
2 | |
3 #include "common.h" | |
4 #include "auth.h" | |
5 #include "cookie.h" | |
6 #include "userinfo.h" | |
7 | |
8 static void auth_plain_continue(CookieData *cookie, | |
9 AuthContinuedRequestData *request, | |
10 const unsigned char *data, | |
11 AuthCallback callback, void *user_data) | |
12 { | |
13 AuthCookieReplyData *cookie_reply = cookie->user_data; | |
14 AuthReplyData reply; | |
15 const char *user, *pass; | |
16 unsigned int i, count; | |
17 | |
18 /* initialize reply */ | |
19 memset(&reply, 0, sizeof(reply)); | |
20 reply.id = request->id; | |
21 reply.result = AUTH_RESULT_FAILURE; | |
22 memcpy(reply.cookie, cookie->cookie, AUTH_COOKIE_SIZE); | |
23 | |
24 /* data should contain user\0...\0pass */ | |
25 user = (const char *) data; | |
26 pass = NULL; | |
27 count = 0; | |
28 for (i = 0; i < request->data_size; i++) { | |
29 if (data[i] == '\0') { | |
30 if (++count == 2) { | |
31 pass = i+1 == request->data_size ? "" : | |
32 t_strndup((const char *) data + i + 1, | |
33 request->data_size - i - 1); | |
34 break; | |
35 } | |
36 } | |
37 } | |
38 | |
39 if (pass != NULL) { | |
40 if (userinfo->verify_plain(user, pass, cookie_reply)) { | |
41 cookie_reply->success = TRUE; | |
42 reply.result = AUTH_RESULT_SUCCESS; | |
43 } | |
44 } | |
45 | |
46 callback(&reply, NULL, user_data); | |
47 | |
48 if (!cookie_reply->success) { | |
49 /* failed, we don't need the cookie anymore */ | |
50 cookie_remove(cookie->cookie); | |
51 } | |
52 } | |
53 | |
54 static int auth_plain_fill_reply(CookieData *cookie, AuthCookieReplyData *reply) | |
55 { | |
56 AuthCookieReplyData *cookie_reply; | |
57 | |
58 cookie_reply = cookie->user_data; | |
59 if (!cookie_reply->success) | |
60 return FALSE; | |
61 | |
62 memcpy(reply, cookie_reply, sizeof(AuthCookieReplyData)); | |
63 return TRUE; | |
64 } | |
65 | |
66 static void auth_plain_free(CookieData *cookie) | |
67 { | |
68 i_free(cookie->user_data); | |
69 i_free(cookie); | |
70 } | |
71 | |
72 static void auth_plain_init(AuthInitRequestData *request, | |
73 AuthCallback callback, void *user_data) | |
74 { | |
75 CookieData *cookie; | |
76 AuthReplyData reply; | |
77 | |
78 cookie = i_new(CookieData, 1); | |
79 cookie->auth_fill_reply = auth_plain_fill_reply; | |
80 cookie->auth_continue = auth_plain_continue; | |
81 cookie->free = auth_plain_free; | |
82 cookie->user_data = i_new(AuthCookieReplyData, 1); | |
83 | |
84 cookie_add(cookie); | |
85 | |
86 /* initialize reply */ | |
87 memset(&reply, 0, sizeof(reply)); | |
88 reply.id = request->id; | |
89 reply.result = AUTH_RESULT_CONTINUE; | |
90 memcpy(reply.cookie, cookie->cookie, AUTH_COOKIE_SIZE); | |
91 | |
92 callback(&reply, NULL, user_data); | |
93 } | |
94 | |
95 AuthModule auth_plain = { | |
96 AUTH_METHOD_PLAIN, | |
97 auth_plain_init | |
98 }; |