~ubuntu-branches/ubuntu/natty/freeradius/natty-updates

« back to all changes in this revision

Viewing changes to src/modules/rlm_sql/rlm_sql.c

  • Committer: Bazaar Package Importer
  • Author(s): Paul Hampson
  • Date: 2006-01-15 13:34:13 UTC
  • mto: (3.1.3 dapper) (4.1.3 sid) (1.1.14 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20060115133413-zo1dslttvdoalqym
Tags: upstream-1.1.0
ImportĀ upstreamĀ versionĀ 1.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * rlm_sql.c            SQL Module
3
3
 *              Main SQL module file. Most ICRADIUS code is located in sql.c
4
4
 *
5
 
 * Version:     $Id: rlm_sql.c,v 1.131.2.4 2005/08/31 12:49:52 nbk Exp $
 
5
 * Version:     $Id: rlm_sql.c,v 1.131.2.8.2.1 2005/12/13 14:11:53 nbk Exp $
6
6
 *
7
7
 *   This program is free software; you can redistribute it and/or modify
8
8
 *   it under the terms of the GNU General Public License as published by
24
24
 */
25
25
 
26
26
static const char rcsid[] =
27
 
        "$Id: rlm_sql.c,v 1.131.2.4 2005/08/31 12:49:52 nbk Exp $";
 
27
        "$Id: rlm_sql.c,v 1.131.2.8.2.1 2005/12/13 14:11:53 nbk Exp $";
28
28
 
29
29
#include "autoconf.h"
30
30
 
620
620
                        free(*p);
621
621
                        *p = NULL;
622
622
                }
 
623
                allowed_chars = NULL;
623
624
                free(inst->config);
624
625
                inst->config = NULL;
625
626
        }
755
756
                return RLM_MODULE_INVALID;
756
757
        }
757
758
 
758
 
 
759
 
        /*
760
 
         *  After this point, ALL 'return's MUST release the SQL socket!
761
 
         */
762
 
 
763
 
 
764
 
        /*
765
 
         * Set, escape, and check the user attr here
 
759
        /*
 
760
         *      Set, escape, and check the user attr here.
766
761
         */
767
762
        if (sql_set_user(inst, request, sqlusername, NULL) < 0)
768
763
                return RLM_MODULE_FAIL;
772
767
        if (sqlsocket == NULL) {
773
768
                /* Remove the username we (maybe) added above */
774
769
                pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
775
 
                return(RLM_MODULE_FAIL);
 
770
                return RLM_MODULE_FAIL;
776
771
        }
777
772
 
 
773
        /*
 
774
         *      After this point, ALL 'return's MUST release the SQL socket!
 
775
         */
 
776
 
778
777
        found = sql_getvpdata(inst, sqlsocket, &check_tmp, querystr, PW_VP_USERDATA);
779
778
        /*
780
779
         *      Find the entry for the user.
792
791
                sql_release_socket(inst, sqlsocket);
793
792
                /* Remove the username we (maybe) added above */
794
793
                pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
 
794
                pairfree(&check_tmp);
795
795
                return RLM_MODULE_FAIL;
796
796
 
797
797
        } else {
826
826
                                radlog(L_DBG, "rlm_sql (%s): Checking profile %s",
827
827
                                       inst->config->xlat_name, profile);
828
828
                                if (sql_set_user(inst, request, sqlusername, profile) < 0) {
 
829
                                        sql_release_socket(inst, sqlsocket);
 
830
                                        pairfree(&reply_tmp);
 
831
                                        pairfree(&check_tmp);
829
832
                                        return RLM_MODULE_FAIL;
830
833
                                }
831
834
                                radius_xlat(querystr, sizeof(querystr), inst->config->authorize_group_check_query,
839
842
                        }
840
843
                }
841
844
        }
 
845
 
 
846
        /*
 
847
         *      We don't need the SQL socket anymore.
 
848
         */
 
849
        sql_release_socket(inst, sqlsocket);
 
850
 
842
851
        if (!found) {
843
852
                radlog(L_DBG, "rlm_sql (%s): User not found",
844
853
                       inst->config->xlat_name);
845
 
                sql_release_socket(inst, sqlsocket);
846
854
                /* Remove the username we (maybe) added above */
847
855
                pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
 
856
                pairfree(&reply_tmp);
 
857
                pairfree(&check_tmp);
848
858
                return RLM_MODULE_NOTFOUND;
849
859
        }
850
860
 
865
875
                       inst->config->xlat_name, sqlusername);
866
876
                /* Remove the username we (maybe) added above */
867
877
                pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
868
 
                sql_release_socket(inst, sqlsocket);
869
878
                pairfree(&reply_tmp);
870
879
                pairfree(&check_tmp);
871
880
                return RLM_MODULE_NOTFOUND;
878
887
 
879
888
        /* Remove the username we (maybe) added above */
880
889
        pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
881
 
        sql_release_socket(inst, sqlsocket);
882
890
 
883
891
        return RLM_MODULE_OK;
884
892
}
910
918
        if ((pair = pairfind(request->packet->vps, PW_ACCT_STATUS_TYPE)) != NULL) {
911
919
                acctstatustype = pair->lvalue;
912
920
        } else {
913
 
                radius_xlat(logstr, sizeof(logstr), "rlm_sql: packet has no account status type.  [user '%{User-Name}', nas '%{NAS-IP-Address}']", request, sql_escape_func);
914
 
                radlog(L_ERR, logstr);
 
921
                radius_xlat(logstr, sizeof(logstr), "packet has no accounting status type. [user '%{User-Name}', nas '%{NAS-IP-Address}']", request, NULL);
 
922
                radlog(L_ERR, "rlm_sql (%s) in sql_accounting: %s",
 
923
                       inst->config->xlat_name, logstr);
915
924
                return RLM_MODULE_INVALID;
916
925
        }
917
926
 
1077
1086
                                                if ((pair = pairfind(request->packet->vps, PW_ACCT_SESSION_TIME)) != NULL)
1078
1087
                                                        acctsessiontime = pair->lvalue;
1079
1088
 
1080
 
                                                if (acctsessiontime <= 0) {
1081
 
                                                        radius_xlat(logstr, sizeof(logstr), "rlm_sql: Stop packet with zero session length.  (user '%{User-Name}', nas '%{NAS-IP-Address}')", request, sql_escape_func);
1082
 
                                                        radlog(L_ERR, logstr);
1083
 
                                                        sql_release_socket(inst, sqlsocket);
1084
 
                                                        ret = RLM_MODULE_NOOP;
1085
 
                                                }
 
1089
                                                if (acctsessiontime <= 0) {
 
1090
                                                        radius_xlat(logstr, sizeof(logstr), "stop packet with zero session length. [user '%{User-Name}', nas '%{NAS-IP-Address}']", request, NULL);
 
1091
                                                        radlog(L_ERR, "rlm_sql (%s) in sql_accounting: %s", inst->config->xlat_name, logstr);
 
1092
                                                        sql_release_socket(inst, sqlsocket);
 
1093
                                                        ret = RLM_MODULE_NOOP;
 
1094
                                                }
1086
1095
#endif
1087
1096
 
1088
1097
                                                radius_xlat(querystr, sizeof(querystr), inst->config->accounting_stop_query_alt, request, sql_escape_func);