Updates from redhat
[freeradius.git] / src / main / 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 #include <freeradius-devel/ident.h>
25 RCSID("$Id$")
26
27 #include <freeradius-devel/radiusd.h>
28 #include <freeradius-devel/modules.h>
29 #include <freeradius-devel/vqp.h>
30 #include <freeradius-devel/vmps.h>
31 #include <freeradius-devel/rad_assert.h>
32
33 #ifdef WITH_VMPS
34 /*
35  *      Check if an incoming request is "ok"
36  *
37  *      It takes packets, not requests.  It sees if the packet looks
38  *      OK.  If so, it does a number of sanity checks on it.
39  */
40 int vqp_socket_recv(rad_listen_t *listener,
41                     RAD_REQUEST_FUNP *pfun, REQUEST **prequest)
42 {
43         RADIUS_PACKET   *packet;
44         RAD_REQUEST_FUNP fun = NULL;
45         RADCLIENT       *client;
46
47         packet = vqp_recv(listener->fd);
48         if (!packet) {
49                 radlog(L_ERR, "%s", fr_strerror());
50                 return 0;
51         }
52
53         if ((client = client_listener_find(listener,
54                                            &packet->src_ipaddr,
55                                            packet->src_port)) == NULL) {
56                 rad_free(&packet);
57                 return 0;
58         }
59
60         /*
61          *      Do new stuff.
62          */
63         fun = vmps_process;
64
65         if (!received_request(listener, packet, prequest, client)) {
66                 rad_free(&packet);
67                 return 0;
68         }
69
70         *pfun = fun;
71
72         return 1;
73 }
74
75
76 /*
77  *      Send an authentication response packet
78  */
79 int vqp_socket_send(rad_listen_t *listener, REQUEST *request)
80 {
81         rad_assert(request->listener == listener);
82         rad_assert(listener->send == vqp_socket_send);
83
84         if (vqp_encode(request->reply, request->packet) < 0) {
85                 DEBUG2("Failed encoding packet: %s\n", fr_strerror());
86                 return -1;
87         }
88
89         return vqp_send(request->reply);
90 }
91
92
93 int vqp_socket_encode(UNUSED rad_listen_t *listener, REQUEST *request)
94 {
95         return vqp_encode(request->reply, request->packet);
96 }
97
98
99 int vqp_socket_decode(UNUSED rad_listen_t *listener, REQUEST *request)
100 {
101         return vqp_decode(request->packet);
102 }
103
104
105 int vmps_process(REQUEST *request)
106 {
107         DEBUG2("Doing VMPS");
108         module_post_auth(0, request);
109         DEBUG2("Done VMPS");
110
111         request->reply->code = PW_AUTHENTICATION_ACK;
112
113         return 0;
114 }
115 #endif