10 static const char rcsid[] = "$Id$";
13 * Define a structure for our module configuration.
15 * These variables do not need to be in a structure, but it's
16 * a lot cleaner to do so, and a pointer to the structure can
17 * be used as the instance handle.
19 typedef struct example_config_t {
27 * A temporary holding area for config values to be extracted
28 * into, before they are copied into the instance data
30 static example_config_t config;
33 * A mapping of configuration file names to internal variables.
35 * Note that the string is dynamically allocated, so it MUST
36 * be freed. When the configuration file parse re-reads the string,
37 * it free's the old one, and strdup's the new one, placing the pointer
38 * to the strdup'd string into 'config.string'. This gets around
41 static CONF_PARSER module_config[] = {
42 { "integer", PW_TYPE_INTEGER, &config.value, "1" },
43 { "boolean", PW_TYPE_BOOLEAN, &config.boolean, "no" },
44 { "string", PW_TYPE_STRING_PTR, &config.string, NULL },
45 { "ipaddr", PW_TYPE_IPADDR, &config.ipaddr, "*" },
47 { NULL, -1, NULL, NULL } /* end the list */
51 * Do any per-module initialization. e.g. set up connections
52 * to external databases, read configuration files, set up
53 * dictionary entries, etc.
55 * Try to avoid putting too much stuff in here - it's better to
56 * do it in instantiate() where it is not global.
58 static int radius_init(void)
61 * Everything's OK, return without an error.
67 * Do any per-module initialization that is separate to each
68 * configured instance of the module. e.g. set up connections
69 * to external databases, read configuration files, set up
70 * dictionary entries, etc.
72 * If configuration information is given in the config section
73 * that must be referenced in later calls, store a handle to it
74 * in *instance otherwise put a null pointer there.
76 static int radius_instantiate(CONF_SECTION *conf, void **instance)
79 * Set up a storage area for instance data
81 *instance = malloc(sizeof(struct example_config_t));
87 * If the configuration parameters can't be parsed, then
90 if (cf_section_parse(conf, module_config) < 0) {
96 * Copy the configuration into the instance data
98 #define inst ((struct example_config_t *)*instance)
99 inst->boolean = config.boolean;
100 inst->value = config.value;
101 inst->string = config.string;
102 inst->ipaddr = config.ipaddr;
104 config.string = 0; /* So cf_section_parse won't free it next time */
110 * Find the named user in this modules database. Create the set
111 * of attribute-value pairs to check and reply with for this user
112 * from the database. The authentication code only needs to check
113 * the password, the rest is done here.
115 static int radius_authorize(void *instance, REQUEST *request)
117 /* quiet the compiler */
121 return RLM_MODULE_OK;
125 * Authenticate the user with the given password.
127 static int radius_authenticate(void *instance, REQUEST *request)
129 /* quiet the compiler */
133 return RLM_MODULE_OK;
137 * Massage the request before recording it or proxying it
139 static int radius_preacct(void *instance, REQUEST *request)
141 /* quiet the compiler */
145 return RLM_MODULE_OK;
149 * Write accounting information to this modules database.
151 static int radius_accounting(void *instance, REQUEST *request)
153 /* quiet the compiler */
157 return RLM_MODULE_OK;
160 static int radius_detach(void *instance)
162 free(((struct example_config_t *)instance)->string);
167 /* globally exported name */
168 module_t rlm_example = {
170 0, /* type: reserved */
171 radius_init, /* initialization */
172 radius_instantiate, /* instantiation */
173 radius_authorize, /* authorization */
174 radius_authenticate, /* authentication */
175 radius_preacct, /* preaccounting */
176 radius_accounting, /* accounting */
177 radius_detach, /* detach */