*
* 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
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
- * Copyright 2001 The FreeRADIUS server project
+ * Copyright 2001,2006 The FreeRADIUS server project
* Copyright 2000 Mike Machado <mike@innercite.com>
* Copyright 2000 Alan DeKok <aland@ox.org>
* Copyright 2001 Chad Miller <cmiller@surfsouth.com>
*/
-#include "autoconf.h"
+#include <freeradius-devel/ident.h>
+RCSID("$Id$")
+
+#include <freeradius-devel/radiusd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/time.h>
#include <sys/file.h>
-#include <string.h>
#include <sys/stat.h>
-#include <netinet/in.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <netdb.h>
#include <pwd.h>
-#include <time.h>
#include <ctype.h>
-#include <unistd.h>
#include <signal.h>
-#include <errno.h>
#include <sys/wait.h>
-#include "radiusd.h"
-#include "conffile.h"
#include "rlm_sql.h"
#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
#endif
radlog(L_DBG, "rlm_sql (%s): starting %d",
inst->config->xlat_name, i);
- sqlsocket = rad_malloc(sizeof(SQLSOCK));
+ sqlsocket = rad_malloc(sizeof(*sqlsocket));
if (sqlsocket == NULL) {
return -1;
}
+ memset(sqlsocket, 0, sizeof(*sqlsocket));
sqlsocket->conn = NULL;
sqlsocket->id = i;
sqlsocket->state = sockunconnected;
}
/*
+ * Verify the 'op' field
+ */
+ if (row[4] != NULL && row[4][0] != '\0') {
+ ptr = row[4];
+ operator = gettoken(&ptr, buf, sizeof(buf));
+ }
+ if (operator <= T_EOL) {
+ /*
+ * Complain about empty or invalid 'op' field
+ */
+ operator = T_OP_CMP_EQ;
+ radlog(L_ERR, "rlm_sql: The 'op' field for attribute '%s = %s' is NULL, or non-existent.", row[2], row[3]);
+ radlog(L_ERR, "rlm_sql: You MUST FIX THIS if you want the configuration to behave as you expect.");
+ }
+
+ /*
* The 'Value' field may be empty or NULL
*/
value = row[3];
((row[3][0] == '\'') || (row[3][0] == '`') || (row[3][0] == '"')) &&
(row[3][0] == row[3][strlen(row[3])-1])) {
- value = row[3];
token = gettoken(&value, buf, sizeof(buf));
switch (token) {
/*
}
/*
- * Verify the 'op' field
- */
- if (row[4] != NULL && row[4][0] != '\0') {
- ptr = row[4];
- operator = gettoken(&ptr, buf, sizeof(buf));
- }
- if (operator <= T_EOL) {
- /*
- * Complain about empty or invalid 'op' field
- */
- operator = T_OP_CMP_EQ;
- radlog(L_ERR, "rlm_sql: The 'op' field for attribute '%s = %s' is NULL, or non-existent.", row[2], row[3]);
- radlog(L_ERR, "rlm_sql: You MUST FIX THIS if you want the configuration to behave as you expect.");
- }
-
- /*
* Create the pair
*/
pair = pairmake(row[2], value, operator);
}
if (do_xlat) {
pair->flags.do_xlat = 1;
- strNcpy(pair->strvalue, buf, sizeof(pair->strvalue));
+ strlcpy(pair->vp_strvalue, buf, sizeof(pair->vp_strvalue));
pair->length = 0;
}
if (ret == SQL_DOWN) {
/* close the socket that failed */
- (inst->module->sql_close)(sqlsocket, inst->config);
+ if (sqlsocket->state == sockconnected) {
+ (inst->module->sql_close)(sqlsocket, inst->config);
+ }
/* reconnect the socket */
if (connect_single_socket(sqlsocket, inst) < 0) {
if (ret == SQL_DOWN) {
/* close the socket that failed */
- (inst->module->sql_close)(sqlsocket, inst->config);
+ if (sqlsocket->state == sockconnected) {
+ (inst->module->sql_close)(sqlsocket, inst->config);
+ }
/* reconnect the socket */
if (connect_single_socket(sqlsocket, inst) < 0) {