ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/saslserv/plain.C
Revision: 1.7
Committed: Sat Sep 22 14:27:30 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +3 -3 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# User Rev Content
1 pippijn 1.6 /**
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 pippijn 1.4 * Copyright © 2006 Atheme Development Group
10 pippijn 1.2 * Rights to this code are as documented in doc/pod/license.pod.
11 pippijn 1.1 *
12 pippijn 1.7 * $Id: plain.C,v 1.6 2007-09-16 18:54:44 pippijn Exp $
13 pippijn 1.1 */
14    
15     #include "atheme.h"
16 pippijn 1.4 #include <ermyth/module.h>
17 pippijn 1.1 #include <account/myuser.h>
18 pippijn 1.4 #include <sasl.h>
19 pippijn 1.1
20 pippijn 1.7 static char const rcsid[] = "$Id: plain.C,v 1.6 2007-09-16 18:54:44 pippijn Exp $";
21 pippijn 1.1
22 pippijn 1.7 REGISTER_MODULE ("saslserv/plain", false, "The Ermyth Team <http://ermyth.xinutec.org>");
23 pippijn 1.1
24 pippijn 1.4 E list_t sasl_mechanisms;
25     static node_t *mnode;
26 pippijn 1.1 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 pippijn 1.4 static sasl_mechanism_t mech ("PLAIN", &mech_start, &mech_step, &mech_finish);
30 pippijn 1.1
31 pippijn 1.4 bool
32     _modinit (module *m)
33 pippijn 1.1 {
34     mnode = node_create ();
35 pippijn 1.4 node_add (&mech, mnode, &sasl_mechanisms);
36    
37     return true;
38 pippijn 1.1 }
39    
40     void
41     _moddeinit ()
42     {
43 pippijn 1.4 node_del (mnode, &sasl_mechanisms);
44 pippijn 1.1 }
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 pippijn 1.5 if (!(mu = myuser_t::find (auth)))
81 pippijn 1.1 return ASASL_FAIL;
82    
83     p->username = strdup (auth);
84 pippijn 1.4 return mu->verify_password (pass) ? ASASL_DONE : ASASL_FAIL;
85 pippijn 1.1 }
86    
87     static void
88     mech_finish (sasl_session_t *p)
89     {
90     }