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