Cleanups & security fixes
[freeradius.git] / src / modules / rlm_eap / types / rlm_eap_md5 / rlm_eap_md5.c
1 /*
2  * rlm_eap_md5.c    Handles that are called from eap
3  *
4  * Version:     $Id$
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation; either version 2 of the License, or
9  *   (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with this program; if not, write to the Free Software
18  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  * Copyright 2000,2001  The FreeRADIUS server project
21  * Copyright 2001  hereUare Communications, Inc. <raghud@hereuare.com>
22  */
23
24 #include "autoconf.h"
25
26 #include <stdio.h>
27 #include <stdlib.h>
28
29 #include "eap_md5.h"
30
31
32 static int md5_attach(CONF_SECTION *conf, void **arg)
33 {
34         return 0;
35 }
36
37 /*
38  * send an initial eap-md5 request
39  * ie access challenge to the user/peer.
40
41  * Frame eap reply packet.
42  * len = header + type + md5_typedata
43  * md5_typedata = value_size + value
44  */
45 static int md5_initiate(void *type_arg, EAP_HANDLER *handler)
46 {
47         MD5_PACKET      *reply;
48
49         reply = eapmd5_initiate(handler->eap_ds);
50         if (reply == NULL)
51                 return 0;
52
53         eapmd5_compose(handler->eap_ds, reply);
54
55         eapmd5_free(&reply);
56         return 1;
57 }
58
59 static int md5_authenticate(void *arg, EAP_HANDLER *handler)
60 {
61         MD5_PACKET      *packet;
62         MD5_PACKET      *reply;
63         md5_packet_t    *request;
64         char*           username;
65         VALUE_PAIR      *password;
66         EAP_DS          *temp;
67
68         /*
69          * Password is never sent over the wire.
70          * Always get the configured password, for each user.
71          */
72         password = pairfind(handler->configured, PW_PASSWORD);
73         if (password == NULL) {
74                 radlog(L_INFO, "rlm_eap_md5: No password configured for this user");
75                 return 0;
76         }
77
78         /*
79          *      Allocate memory AFTER doing sanity checks.
80          */
81         if (!(packet = eapmd5_extract(handler->eap_ds)))
82                 return 0;
83
84         username = (char *)handler->username->strvalue;
85
86         temp = (EAP_DS *)handler->prev_eapds;
87         request = temp?(md5_packet_t *)(temp->request->type.data):NULL;
88         reply = eapmd5_process(packet, handler->eap_ds->request->id,
89                          handler->username, password, request);
90         if (!reply) {
91                 eapmd5_free(&packet);
92                 return 0;
93         }
94
95         eapmd5_compose(handler->eap_ds, reply);
96
97         eapmd5_free(&reply);
98         eapmd5_free(&packet);
99         return 1;
100 }
101
102 static int md5_detach(void **arg)
103 {
104         return 0;
105 }
106
107 /*
108  *      The module name should be the only globally exported symbol.
109  *      That is, everything else should be 'static'.
110  */
111 EAP_TYPE rlm_eap_md5 = {
112         "eap_md5",
113         md5_attach,                     /* attach */
114         md5_initiate,                   /* Start the initial request, after Identity */
115         md5_authenticate,               /* authentication */
116         md5_detach                      /* detach */
117 };