don't process VMPS packets twice
[freeradius.git] / src / modules / proto_vmps / vmps.c
1 /*
2  * vmps.c       Handle VMPS traffic.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  *
20  * Copyright 2007  The FreeRADIUS server project
21  * Copyright 2007  Alan DeKok <aland@deployingradius.com>
22  */
23
24 RCSID("$Id$")
25
26 #include <freeradius-devel/radiusd.h>
27 #include <freeradius-devel/protocol.h>
28 #include <freeradius-devel/process.h>
29 #include <freeradius-devel/modules.h>
30 #include <freeradius-devel/rad_assert.h>
31
32 #include "vqp.h"
33
34 static int vmps_process(REQUEST *request)
35 {
36         DEBUG2("Doing VMPS");
37         process_post_auth(0, request);
38         DEBUG2("Done VMPS");
39
40         request->packet->code = 0; /* hack for VMPS */
41         request->reply->code = PW_CODE_ACCESS_ACCEPT;
42
43         return 0;
44 }
45
46 /*
47  *      Check if an incoming request is "ok"
48  *
49  *      It takes packets, not requests.  It sees if the packet looks
50  *      OK.  If so, it does a number of sanity checks on it.
51  */
52 static int vqp_socket_recv(rad_listen_t *listener)
53 {
54         RADIUS_PACKET   *packet;
55         RAD_REQUEST_FUNP fun = NULL;
56         RADCLIENT       *client;
57
58         packet = vqp_recv(listener->fd);
59         if (!packet) {
60                 ERROR("%s", fr_strerror());
61                 return 0;
62         }
63
64         if ((client = client_listener_find(listener,
65                                            &packet->src_ipaddr,
66                                            packet->src_port)) == NULL) {
67                 rad_free(&packet);
68                 return 0;
69         }
70
71         /*
72          *      Do new stuff.
73          */
74         fun = vmps_process;
75
76         if (!request_receive(NULL, listener, packet, client, fun)) {
77                 rad_free(&packet);
78                 return 0;
79         }
80
81         return 1;
82 }
83
84
85 /*
86  *      Send an authentication response packet
87  */
88 static int vqp_socket_send(rad_listen_t *listener, REQUEST *request)
89 {
90         rad_assert(request->listener == listener);
91         rad_assert(listener->send == vqp_socket_send);
92
93         if (vqp_encode(request->reply, request->packet) < 0) {
94                 DEBUG2("Failed encoding packet: %s\n", fr_strerror());
95                 return -1;
96         }
97
98         return vqp_send(request->reply);
99 }
100
101
102 static int vqp_socket_encode(UNUSED rad_listen_t *listener, REQUEST *request)
103 {
104         return vqp_encode(request->reply, request->packet);
105 }
106
107
108 static int vqp_socket_decode(UNUSED rad_listen_t *listener, REQUEST *request)
109 {
110         return vqp_decode(request->packet);
111 }
112
113 extern fr_protocol_t proto_vmps;
114 fr_protocol_t proto_vmps = {
115         .magic          = RLM_MODULE_INIT,
116         .name           = "vmps",
117         .inst_size      = sizeof(listen_socket_t),
118         .parse          = common_socket_parse,
119         .recv           = vqp_socket_recv,
120         .send           = vqp_socket_send,
121         .print          = common_socket_print,
122         .encode         = vqp_socket_encode,
123         .decode         = vqp_socket_decode
124 };