~ubuntu-branches/ubuntu/jaunty/freeradius/jaunty-proposed

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2008-09-22 08:42:02 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20080922084202-eyjprg3z55481ha5
Tags: 2.1.0+dfsg-0ubuntu1
* New upstream release.
* Fixes FTBFS issue with new libtool.
* Fixes listen on random port. (LP: #261809)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  rlm_sqlippool.c     rlm_sqlippool - FreeRADIUS SQL IP Pool Module
3
3
 *
4
 
 * Version:  $Id: rlm_sqlippool.c,v 1.38 2008/04/28 12:25:23 aland Exp $
 
4
 * Version:  $Id$
5
5
 *
6
6
 *   This program is free software; you can redistribute it and/or modify
7
7
 *   it under the terms of the GNU General Public License as published by
23
23
 */
24
24
 
25
25
#include <freeradius-devel/ident.h>
26
 
RCSID("$Id: rlm_sqlippool.c,v 1.38 2008/04/28 12:25:23 aland Exp $")
 
26
RCSID("$Id$")
27
27
 
28
28
#include <freeradius-devel/radiusd.h>
29
29
 
374
374
                strcpy(query, expansion);
375
375
        }
376
376
 
377
 
#if 0
378
 
        DEBUG2("sqlippool_query1: '%s'", query);
379
 
#endif
380
377
        if (rlm_sql_select_query(sqlsocket, data->sql_inst, query)){
381
378
                radlog(L_ERR, "sqlippool_query1: database query error");
382
379
                out[0] = '\0';
392
389
                                        strcpy(out, sqlsocket->row[0]);
393
390
                                        retval = rlen;
394
391
                                } else {
395
 
                                        DEBUG("sqlippool_query1: insufficient string space");
 
392
                                        RDEBUG("insufficient string space");
396
393
                                }
397
394
                        } else {
398
 
                                DEBUG("sqlippool_query1: row[0] returned NULL");
 
395
                                RDEBUG("row[0] returned NULL");
399
396
                        }
400
397
                } else {
401
 
                        DEBUG("sqlippool_query1: SQL query did not return any results");
 
398
                        RDEBUG("SQL query did not return any results");
402
399
                }
403
400
        } else {
404
 
                DEBUG("sqlippool_query1: SQL query did not succeed");
 
401
                RDEBUG("SQL query did not succeed");
405
402
        }
406
403
 
407
404
        (data->sql_inst->module->sql_finish_select_query)(sqlsocket,
536
533
                data->pool_name = strdup("ippool");
537
534
 
538
535
        modinst = find_module_instance(cf_section_find("modules"),
539
 
                                       data->sql_instance_name);
 
536
                                       data->sql_instance_name, 1);
540
537
        if (!modinst) {
541
538
                radlog(L_ERR, "sqlippool_instantiate: failed to find sql instance named %s", data->sql_instance_name);
542
539
                sqlippool_detach(data);
565
562
 */
566
563
static int do_logging(char *str, int retcode)
567
564
{
568
 
        if (strlen(str))
 
565
        if (str && (*str != '\0'))
569
566
                radlog(L_INFO,"%s", str);
570
567
        return retcode;
571
568
}
592
589
                /* We already have a Framed-IP-Address */
593
590
                radius_xlat(logstr, sizeof(logstr), data->log_exists,
594
591
                            request, NULL);
595
 
                DEBUG("rlm_sqlippool: Framed-IP-Address already exists");
 
592
                RDEBUG("Framed-IP-Address already exists");
596
593
 
597
594
                return do_logging(logstr, RLM_MODULE_NOOP);
598
595
        }
599
596
 
600
597
        if (pairfind(request->config_items, PW_POOL_NAME) == NULL) {
601
 
                DEBUG("rlm_sqlippool: No Pool-Name defined.");
 
598
                RDEBUG("No Pool-Name defined.");
602
599
                radius_xlat(logstr, sizeof(logstr), data->log_nopool,
603
600
                            request, NULL);
604
601
 
605
602
                return do_logging(logstr, RLM_MODULE_NOOP);
606
603
        }
607
604
 
608
 
        if (pairfind(request->packet->vps, PW_NAS_IP_ADDRESS) == NULL) {
609
 
                DEBUG("rlm_sqlippool: No NAS-IP-Address in packet.");
610
 
                return RLM_MODULE_NOOP;
611
 
        }
612
 
 
613
605
        sqlsocket = sql_get_socket(data->sql_inst);
614
606
        if (sqlsocket == NULL) {
615
 
                DEBUG("rlm_sqlippool: cannot allocate sql connection");
 
607
                RDEBUG("cannot allocate sql connection");
616
608
                return RLM_MODULE_FAIL;
617
609
        }
618
610
 
670
662
                                 *      that case, we should return
671
663
                                 *      NOTFOUND
672
664
                                 */
673
 
                                DEBUG("rlm_sqlippool: pool appears to be full");
 
665
                                RDEBUG("pool appears to be full");
674
666
                                radius_xlat(logstr, sizeof(logstr), data->log_failed, request, NULL);
675
667
                                return do_logging(logstr, RLM_MODULE_NOTFOUND);
676
668
 
682
674
                         *      sqlippool, so we should just ignore this
683
675
                         *      allocation failure and return NOOP
684
676
                         */
685
 
                        DEBUG("rlm_sqlippool: IP address could not be allocated as no pool exists with that name.");
 
677
                        RDEBUG("IP address could not be allocated as no pool exists with that name.");
686
678
                        return RLM_MODULE_NOOP;
687
679
 
688
680
                }
689
681
 
690
682
                sql_release_socket(data->sql_inst, sqlsocket);
691
683
 
692
 
                DEBUG("rlm_sqlippool: IP address could not be allocated.");
 
684
                RDEBUG("IP address could not be allocated.");
693
685
                radius_xlat(logstr, sizeof(logstr), data->log_failed,
694
686
                            request, NULL);
695
687
 
708
700
                sqlippool_command(data->allocate_commit, sqlsocket, instance,
709
701
                                  request, (char *) NULL, 0);
710
702
 
711
 
                DEBUG("rlm_sqlippool: Invalid IP number [%s] returned from database query.", allocation);
 
703
                RDEBUG("Invalid IP number [%s] returned from database query.", allocation);
712
704
                sql_release_socket(data->sql_inst, sqlsocket);
713
705
                radius_xlat(logstr, sizeof(logstr), data->log_failed,
714
706
                            request, NULL);
722
714
        sqlippool_command(data->allocate_update, sqlsocket, instance, request,
723
715
                          allocation, allocation_len);
724
716
 
725
 
        DEBUG("rlm_sqlippool: Allocated IP %s [%08x]",
726
 
              allocation, ip_allocation);
 
717
        RDEBUG("Allocated IP %s [%08x]", allocation, ip_allocation);
727
718
 
728
719
        vp = radius_paircreate(request, &request->reply->vps,
729
720
                               PW_FRAMED_IP_ADDRESS, PW_TYPE_IPADDR);
746
737
        rlm_sqlippool_t * data = (rlm_sqlippool_t *) instance;
747
738
        SQLSOCK * sqlsocket;
748
739
 
749
 
        if (pairfind(request->packet->vps, PW_NAS_IP_ADDRESS) == NULL) {
750
 
                DEBUG("rlm_ippool: Could not find nas information in packet.");
751
 
                return RLM_MODULE_NOOP;
752
 
        }
753
 
 
754
740
        sqlsocket = sql_get_socket(data->sql_inst);
755
741
        if (sqlsocket == NULL) {
756
 
                DEBUG("rlm_sqlippool: cannot allocate sql connection");
 
742
                RDEBUG("cannot allocate sql connection");
757
743
                return RLM_MODULE_NOOP;
758
744
        }
759
745
 
785
771
        rlm_sqlippool_t * data = (rlm_sqlippool_t *) instance;
786
772
        SQLSOCK * sqlsocket;
787
773
 
788
 
        if (pairfind(request->packet->vps, PW_NAS_IP_ADDRESS) == NULL) {
789
 
                DEBUG("rlm_ippool: Could not find nas information in packet.");
790
 
                return RLM_MODULE_NOOP;
791
 
        }
792
 
 
793
774
        sqlsocket = sql_get_socket(data->sql_inst);
794
775
        if (sqlsocket == NULL) {
795
 
                DEBUG("rlm_sqlippool: cannot allocate sql connection");
 
776
                RDEBUG("cannot allocate sql connection");
796
777
                return RLM_MODULE_NOOP;
797
778
        }
798
779
 
826
807
        rlm_sqlippool_t * data = (rlm_sqlippool_t *) instance;
827
808
        SQLSOCK * sqlsocket;
828
809
 
829
 
        if (pairfind(request->packet->vps, PW_NAS_IP_ADDRESS) == NULL) {
830
 
                DEBUG("rlm_ippool: Could not find nas information in packet.");
831
 
                return RLM_MODULE_NOOP;
832
 
        }
833
 
 
834
810
        sqlsocket = sql_get_socket(data->sql_inst);
835
811
        if (sqlsocket == NULL) {
836
 
                DEBUG("rlm_sqlippool: cannot allocate sql connection");
 
812
                RDEBUG("cannot allocate sql connection");
837
813
                return RLM_MODULE_NOOP;
838
814
        }
839
815
 
866
842
        rlm_sqlippool_t * data = (rlm_sqlippool_t *) instance;
867
843
        SQLSOCK * sqlsocket;
868
844
 
869
 
        if (pairfind(request->packet->vps, PW_NAS_IP_ADDRESS) == NULL) {
870
 
                DEBUG("rlm_ippool: Could not find nas information in packet.");
871
 
                return RLM_MODULE_NOOP;
872
 
        }
873
 
 
874
845
        sqlsocket = sql_get_socket(data->sql_inst);
875
846
        if (sqlsocket == NULL) {
876
 
                DEBUG("rlm_sqlippool: cannot allocate sql connection");
 
847
                RDEBUG("cannot allocate sql connection");
877
848
                return RLM_MODULE_NOOP;
878
849
        }
879
850
 
905
876
        rlm_sqlippool_t * data = (rlm_sqlippool_t *) instance;
906
877
        SQLSOCK * sqlsocket;
907
878
 
908
 
        if (pairfind(request->packet->vps, PW_NAS_IP_ADDRESS) == NULL) {
909
 
                DEBUG("rlm_ippool: Could not find nas information in packet.");
910
 
                return RLM_MODULE_NOOP;
911
 
        }
912
 
 
913
879
        sqlsocket = sql_get_socket(data->sql_inst);
914
880
        if (sqlsocket == NULL) {
915
 
                DEBUG("rlm_sqlippool: cannot allocate sql connection");
 
881
                RDEBUG("cannot allocate sql connection");
916
882
                return RLM_MODULE_NOOP;
917
883
        }
918
884
 
951
917
 
952
918
        vp = pairfind(request->packet->vps, PW_ACCT_STATUS_TYPE);
953
919
        if (!vp) {
954
 
                DEBUG("rlm_sqlippool: Could not find account status type in packet.");
 
920
                RDEBUG("Could not find account status type in packet.");
955
921
                return RLM_MODULE_NOOP;
956
922
        }
957
923
        acct_status_type = vp->vp_integer;