/*
- * rlm_sqlippool.c
+ * rlm_sqlippool.c rlm_sqlippool - FreeRADIUS SQL IP Pool Module
*
- * Version: $Id$
+ * Version: $Id$
*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
* Copyright 2002 Globe.Net Communications Limited
+ * Copyright 2006 The FreeRADIUS server project
+ * Copyright 2006 Suntel Communications
*/
-#include "autoconf.h"
-#include "libradius.h"
+#include <freeradius-devel/autoconf.h>
+#include <freeradius-devel/libradius.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <netinet/in.h>
-#include "radiusd.h"
-#include "modules.h"
-#include "conffile.h"
-#include "modpriv.h"
+#include <freeradius-devel/radiusd.h>
+#include <freeradius-devel/modules.h>
++#include <freeradius-devel/conffile.h>
+#include <freeradius-devel/modpriv.h>
- #include "rlm_sql.h"
- #include "ip_set.h"
+ #include <rlm_sql.h>
static const char rcsid[] = "$Id$";
else
data->pool_name = strdup("ippool");
- data->sql_inst = (SQL_INST *)(find_module_instance(cf_section_find("modules"), data->sql_instance_name))->insthandle;
- if (data->sql_inst == NULL) {
- if ( !(data->sql_inst = (SQL_INST *) (find_module_instance(data->sql_instance_name))->insthandle) )
++ if ( !(data->sql_inst = (SQL_INST *) (find_module_instance(NULL, data->sql_instance_name))->insthandle) )
+ {
radlog(L_ERR, "sqlippool_instantiate: failed to find sql instance named %s", data->sql_instance_name);
free(data);
exit(0);
uint32_t ip_allocation;
VALUE_PAIR * vp;
SQLSOCK * sqlsocket;
- long self = (long) pthread_self();
++ lrad_ipaddr_t ipaddr;
/*
* If there is a Framed-IP-Address attribute in the reply do nothing
return RLM_MODULE_NOOP;
}
- /*
- * Check if Pool-Name attribute exists. If it exists check our name and
- * run only if they match
- */
if ((vp = pairfind(request->config_items, PW_POOL_NAME)) != NULL) {
- if (data->pool_name == NULL || strcmp(data->pool_name, vp->vp_strvalue) != 0) {
- DEBUG("rlm_sqlippool: pool_name does not match");
- return RLM_MODULE_NOOP;
- }
- DEBUG("Value Of the Pool-Name is [%s] and its [%i] Chars \n", vp->strvalue, vp->length);
++ DEBUG("Value Of the Pool-Name is [%s] and its [%i] Chars \n", vp->vp_strvalue, vp->length);
+ pthread_mutex_lock(&data->dlock);
- strNcpy(data->pool_name, vp->strvalue, (vp->length + 1));
++ strNcpy(data->pool_name, vp->vp_strvalue, (vp->length + 1));
+ pthread_mutex_unlock(&data->dlock);
}
else {
DEBUG("rlm_sqlippool: missing pool_name");
return RLM_MODULE_NOOP;
}
- if (ip_hton(allocation, AF_INET, &ipaddr) < 0)
- ip_allocation = ip_addr(allocation);
- if (ip_allocation == INADDR_NONE)
++
++ if ((ip_hton(allocation, AF_INET, &ipaddr) < 0) ||
++ ((ip_allocation = ipaddr.ipaddr.ip4addr.s_addr) == INADDR_NONE))
{
/*
- * Invalid IP number - run INIT-DELETE and complain
- */
-
- /*
- * INIT_DELETE
- */
- sqlippool_command(data->init_delete, sqlsocket, instance, NULL,
- allocation, allocation_len);
-
- /*
* COMMIT
*/
sqlippool_command(data->allocate_commit, sqlsocket, instance, request,
* is single-threaded.
*/
module_t rlm_sqlippool = {
- "sqlippool",
+ RLM_MODULE_INIT,
+ "SQL IP Pool",
RLM_TYPE_THREAD_SAFE, /* type */
- NULL, /* initialization */
sqlippool_instantiate, /* instantiation */
+ sqlippool_detach, /* detach */
{
NULL, /* authentication */
NULL, /* authorization */
NULL, /* pre-proxy */
NULL, /* post-proxy */
sqlippool_postauth /* post-auth */
- }
+ },
- sqlippool_detach, /* detach */
- NULL, /* destroy */
};