1 |
/** |
2 |
* plain.C: PLAIN mechanism provider |
3 |
* |
4 |
* Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team |
5 |
* Rights to this code are as documented in COPYING. |
6 |
* |
7 |
* |
8 |
* Portions of this file were derived from sources bearing the following license: |
9 |
* Copyright © 2006 Atheme Development Group |
10 |
* Rights to this code are as documented in doc/pod/license.pod. |
11 |
* |
12 |
* $Id: plain.C,v 1.6 2007-09-16 18:54:44 pippijn Exp $ |
13 |
*/ |
14 |
|
15 |
#include "atheme.h" |
16 |
#include <ermyth/module.h> |
17 |
#include <account/myuser.h> |
18 |
#include <sasl.h> |
19 |
|
20 |
static char const rcsid[] = "$Id: plain.C,v 1.6 2007-09-16 18:54:44 pippijn Exp $"; |
21 |
|
22 |
REGISTER_MODULE ("saslserv/plain", false, "The Ermyth Team <http://ermyth.xinutec.org>"); |
23 |
|
24 |
E list_t sasl_mechanisms; |
25 |
static node_t *mnode; |
26 |
static int mech_start (sasl_session_t *p, char **out, int *out_len); |
27 |
static int mech_step (sasl_session_t *p, char *message, int len, char **out, int *out_len); |
28 |
static void mech_finish (sasl_session_t *p); |
29 |
static sasl_mechanism_t mech ("PLAIN", &mech_start, &mech_step, &mech_finish); |
30 |
|
31 |
bool |
32 |
_modinit (module *m) |
33 |
{ |
34 |
mnode = node_create (); |
35 |
node_add (&mech, mnode, &sasl_mechanisms); |
36 |
|
37 |
return true; |
38 |
} |
39 |
|
40 |
void |
41 |
_moddeinit () |
42 |
{ |
43 |
node_del (mnode, &sasl_mechanisms); |
44 |
} |
45 |
|
46 |
static int |
47 |
mech_start (sasl_session_t *p, char **out, int *out_len) |
48 |
{ |
49 |
return ASASL_MORE; |
50 |
} |
51 |
|
52 |
static int |
53 |
mech_step (sasl_session_t *p, char *message, int len, char **out, int *out_len) |
54 |
{ |
55 |
char auth[256]; |
56 |
char pass[256]; |
57 |
myuser_t *mu; |
58 |
|
59 |
/* Skip the authzid entirely */ |
60 |
len -= strlen (message) + 1; |
61 |
if (len <= 0) |
62 |
return ASASL_FAIL; |
63 |
message += strlen (message) + 1; |
64 |
|
65 |
/* Copy the authcid */ |
66 |
if (strlen (message) > 255) |
67 |
return ASASL_FAIL; |
68 |
len -= strlen (message) + 1; |
69 |
if (len <= 0) |
70 |
return ASASL_FAIL; |
71 |
strcpy (auth, message); |
72 |
message += strlen (message) + 1; |
73 |
|
74 |
/* Copy the password */ |
75 |
if (strlen (message) > 255) |
76 |
return ASASL_FAIL; |
77 |
strlcpy (pass, message, len + 1); |
78 |
|
79 |
/* Done dissecting, now check. */ |
80 |
if (!(mu = myuser_t::find (auth))) |
81 |
return ASASL_FAIL; |
82 |
|
83 |
p->username = strdup (auth); |
84 |
return mu->verify_password (pass) ? ASASL_DONE : ASASL_FAIL; |
85 |
} |
86 |
|
87 |
static void |
88 |
mech_finish (sasl_session_t *p) |
89 |
{ |
90 |
} |