New build path variable
[freeradius.git] / src / modules / rlm_copy_packet / rlm_copy_packet.c
1 /*
2  * rlm_copy_packet.c
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 2004,2006  The FreeRADIUS server project
21  * Copyright 2004  Alan DeKok <aland@cladju.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
30 /*
31  *      Define a structure for our module configuration.
32  *
33  *      It doesn't take any configuration right now...
34  */
35 typedef struct rlm_packet_t {
36         char            *string;
37 } rlm_packet_t;
38
39
40 /*
41  *      A mapping of configuration file names to internal variables.
42  *
43  *      Note that the string is dynamically allocated, so it MUST
44  *      be freed.  When the configuration file parse re-reads the string,
45  *      it free's the old one, and strdup's the new one, placing the pointer
46  *      to the strdup'd string into 'config.string'.  This gets around
47  *      buffer over-flows.
48  */
49 static const CONF_PARSER module_config[] = {
50   { "string",  PW_TYPE_STRING_PTR, offsetof(rlm_packet_t,string), NULL,  NULL},
51
52   { NULL, -1, 0, NULL, NULL }           /* end the list */
53 };
54
55
56 static int packet_detach(void *instance)
57 {
58         free(instance);
59         return 0;
60 }
61
62
63 /*
64  *      Do any per-module initialization that is separate to each
65  *      configured instance of the module.  e.g. set up connections
66  *      to external databases, read configuration files, set up
67  *      dictionary entries, etc.
68  *
69  *      If configuration information is given in the config section
70  *      that must be referenced in later calls, store a handle to it
71  *      in *instance otherwise put a null pointer there.
72  */
73 static int packet_instantiate(CONF_SECTION *conf, void **instance)
74 {
75         rlm_packet_t *inst;
76
77         /*
78          *      Set up a storage area for instance data
79          */
80         inst = rad_malloc(sizeof(*inst));
81         if (!inst) {
82                 return -1;
83         }
84         memset(inst, 0, sizeof(*inst));
85
86         /*
87          *      If the configuration parameters can't be parsed, then
88          *      fail.
89          */
90         if (cf_section_parse(conf, inst, module_config) < 0) {
91                 packet_detach(inst);
92                 return -1;
93         }
94
95         *instance = inst;
96
97         return 0;
98 }
99
100
101 /*
102  *      Initialize the reply with the request.
103  */
104 static int packet_authorize(void *instance, REQUEST *request)
105 {
106         VALUE_PAIR      *vps;
107
108         instance = instance;    /* -Wunused */
109
110         vps = paircopy(request->packet->vps);
111         pairadd(&(request->reply->vps), vps);
112         return RLM_MODULE_UPDATED;
113 }
114
115
116 /*
117  *      The module name should be the only globally exported symbol.
118  *      That is, everything else should be 'static'.
119  *
120  *      If the module needs to temporarily modify it's instantiation
121  *      data, the type should be changed to RLM_TYPE_THREAD_UNSAFE.
122  *      The server will then take care of ensuring that the module
123  *      is single-threaded.
124  */
125 module_t rlm_copy_packet = {
126          RLM_MODULE_INIT,
127         "copy_packet",
128         RLM_TYPE_THREAD_SAFE,           /* type */
129         packet_instantiate,             /* instantiation */
130         packet_detach,                  /* detach */
131         {
132                 NULL,                   /* authentication */
133                 packet_authorize,       /* authorization */
134                 NULL,                   /* preaccounting */
135                 NULL,                   /* accounting */
136                 NULL,                   /* checksimul */
137                 NULL,                   /* pre-proxy */
138                 NULL,                   /* post-proxy */
139                 NULL                    /* post-auth */
140         },
141 };