Massively cleaned up #include's, so they're in a consistent
[freeradius.git] / src / modules / rlm_sql / sql.c
index e71f81a..72c164b 100644 (file)
  *
  *   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
 
 
@@ -407,7 +396,7 @@ int sql_userparse(VALUE_PAIR ** first_pair, SQL_ROW row)
        }
        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;
        }
 
@@ -483,7 +472,9 @@ int rlm_sql_query(SQLSOCK *sqlsocket, SQL_INST *inst, char *query)
 
        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) {
@@ -526,7 +517,9 @@ int rlm_sql_select_query(SQLSOCK *sqlsocket, SQL_INST *inst, char *query)
 
        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) {