~yolanda.robla/ubuntu/saucy/freeradius/dep-8-tests

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Josip Rodin
  • Date: 2009-11-23 03:57:37 UTC
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: james.westby@ubuntu.com-20091123035737-snauioz5r9tf8sdr
Tags: upstream-2.1.7+dfsg
ImportĀ upstreamĀ versionĀ 2.1.7+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * rlm_ippool.c
3
3
 *
4
 
 * Version:  $Id: rlm_ippool.c,v 1.51 2008/01/06 17:27:41 nbk 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
56
56
 */
57
57
 
58
58
#include <freeradius-devel/ident.h>
59
 
RCSID("$Id: rlm_ippool.c,v 1.51 2008/01/06 17:27:41 nbk Exp $")
 
59
RCSID("$Id$")
60
60
 
61
61
#include <freeradius-devel/radiusd.h>
62
62
#include <freeradius-devel/modules.h>
328
328
        if ((vp = pairfind(request->packet->vps, PW_ACCT_STATUS_TYPE)) != NULL)
329
329
                acctstatustype = vp->vp_integer;
330
330
        else {
331
 
                DEBUG("rlm_ippool: Could not find account status type in packet. Return NOOP.");
 
331
                RDEBUG("Could not find account status type in packet. Return NOOP.");
332
332
                return RLM_MODULE_NOOP;
333
333
        }
334
334
        switch(acctstatustype){
335
335
                case PW_STATUS_STOP:
336
336
                        if (!radius_xlat(xlat_str,MAX_STRING_LEN,data->key, request, NULL)){
337
 
                                DEBUG("rlm_ippool: xlat on the 'key' directive failed");
 
337
                                RDEBUG("xlat on the 'key' directive failed");
338
338
                                return RLM_MODULE_NOOP;
339
339
                        }
340
340
                        fr_MD5Init(&md5_context);
343
343
                        key_str[16] = '\0';
344
344
                        fr_bin2hex(key_str,hex_str,16);
345
345
                        hex_str[32] = '\0';
346
 
                        DEBUG("rlm_ippool: MD5 on 'key' directive maps to: %s",hex_str);
 
346
                        RDEBUG("MD5 on 'key' directive maps to: %s",hex_str);
347
347
                        memcpy(key.key,key_str,16);
348
348
                        break;
349
349
                default:
350
350
                        /* We don't care about any other accounting packet */
351
 
                        DEBUG("rlm_ippool: This is not an Accounting-Stop. Return NOOP.");
 
351
                        RDEBUG("This is not an Accounting-Stop. Return NOOP.");
352
352
 
353
353
                        return RLM_MODULE_NOOP;
354
354
        }
355
355
 
356
 
        DEBUG("rlm_ippool: Searching for an entry for key: '%s'",xlat_str);
 
356
        RDEBUG("Searching for an entry for key: '%s'",xlat_str);
357
357
        key_datum.dptr = (char *) &key;
358
358
        key_datum.dsize = sizeof(ippool_key);
359
359
 
366
366
                 */
367
367
                memcpy(&entry, data_datum.dptr, sizeof(ippool_info));
368
368
                free(data_datum.dptr);
369
 
                DEBUG("rlm_ippool: Deallocated entry for ip: %s",ip_ntoa(str,entry.ipaddr));
 
369
                RDEBUG("Deallocated entry for ip: %s",ip_ntoa(str,entry.ipaddr));
370
370
                entry.active = 0;
371
371
                entry.timestamp = 0;
372
372
                entry.timeout = 0;
399
399
                        free(data_datum.dptr);
400
400
                        if (num >0){
401
401
                                num--;
402
 
                                DEBUG("rlm_ippool: num: %d",num);
 
402
                                RDEBUG("num: %d",num);
403
403
                                data_datum.dptr = (char *) &num;
404
404
                                data_datum.dsize = sizeof(int);
405
405
                                rcode = gdbm_store(data->ip, key_datum, data_datum, GDBM_REPLACE);
423
423
        }
424
424
        else{
425
425
                pthread_mutex_unlock(&data->op_mutex);
426
 
                DEBUG("rlm_ippool: Entry not found");
 
426
                RDEBUG("Entry not found");
427
427
        }
428
428
 
429
429
        return RLM_MODULE_OK;
464
464
                if (data->name == NULL || (strcmp(data->name,vp->vp_strvalue) && strcmp(vp->vp_strvalue,"DEFAULT")))
465
465
                        return RLM_MODULE_NOOP;
466
466
        } else {
467
 
                DEBUG("rlm_ippool: Could not find Pool-Name attribute.");
 
467
                RDEBUG("Could not find Pool-Name attribute.");
468
468
                return RLM_MODULE_NOOP;
469
469
        }
470
470
 
477
477
 
478
478
 
479
479
        if (!radius_xlat(xlat_str,MAX_STRING_LEN,data->key, request, NULL)){
480
 
                DEBUG("rlm_ippool: xlat on the 'key' directive failed");
 
480
                RDEBUG("xlat on the 'key' directive failed");
481
481
                return RLM_MODULE_NOOP;
482
482
        }
483
483
        fr_MD5Init(&md5_context);
486
486
        key_str[16] = '\0';
487
487
        fr_bin2hex(key_str,hex_str,16);
488
488
        hex_str[32] = '\0';
489
 
        DEBUG("rlm_ippool: MD5 on 'key' directive maps to: %s",hex_str);
 
489
        RDEBUG("MD5 on 'key' directive maps to: %s",hex_str);
490
490
        memcpy(key.key,key_str,16);
491
491
 
492
 
        DEBUG("rlm_ippool: Searching for an entry for key: '%s'",hex_str);
 
492
        RDEBUG("Searching for an entry for key: '%s'",hex_str);
493
493
        key_datum.dptr = (char *) &key;
494
494
        key_datum.dsize = sizeof(ippool_key);
495
495
 
504
504
                memcpy(&entry, data_datum.dptr, sizeof(ippool_info));
505
505
                free(data_datum.dptr);
506
506
                if (entry.active){
507
 
                        DEBUG("rlm_ippool: Found a stale entry for ip: %s",ip_ntoa(str,entry.ipaddr));
 
507
                        RDEBUG("Found a stale entry for ip: %s",ip_ntoa(str,entry.ipaddr));
508
508
                        entry.active = 0;
509
509
                        entry.timestamp = 0;
510
510
                        entry.timeout = 0;
535
535
                                free(data_datum.dptr);
536
536
                                if (num >0){
537
537
                                        num--;
538
 
                                        DEBUG("rlm_ippool: num: %d",num);
 
538
                                        RDEBUG("num: %d",num);
539
539
                                        data_datum.dptr = (char *) &num;
540
540
                                        data_datum.dsize = sizeof(int);
541
541
                                        rcode = gdbm_store(data->ip, key_datum, data_datum, GDBM_REPLACE);
564
564
         * If there is a Framed-IP-Address attribute in the reply, check for override
565
565
         */
566
566
        if (pairfind(request->reply->vps, PW_FRAMED_IP_ADDRESS) != NULL) {
567
 
                DEBUG("rlm_ippool: Found Framed-IP-Address attribute in reply attribute list.");
 
567
                RDEBUG("Found Framed-IP-Address attribute in reply attribute list.");
568
568
                if (data->override)
569
569
                {
570
570
                        /* Override supplied Framed-IP-Address */
571
 
                        DEBUG("rlm_ippool: override is set to yes. Override the existing Framed-IP-Address attribute.");
 
571
                        RDEBUG("override is set to yes. Override the existing Framed-IP-Address attribute.");
572
572
                        pairdelete(&request->reply->vps, PW_FRAMED_IP_ADDRESS);
573
573
                } else {
574
574
                        /* Abort */
575
 
                        DEBUG("rlm_ippool: override is set to no. Return NOOP.");
 
575
                        RDEBUG("override is set to no. Return NOOP.");
576
576
                        return RLM_MODULE_NOOP;
577
577
                }
578
578
        }
760
760
                } else
761
761
                        num = 0;
762
762
                num++;
763
 
                DEBUG("rlm_ippool: num: %d",num);
 
763
                RDEBUG("num: %d",num);
764
764
                data_datum.dptr = (char *) &num;
765
765
                data_datum.dsize = sizeof(int);
766
766
                rcode = gdbm_store(data->ip, key_datum, data_datum, GDBM_REPLACE);
773
773
                pthread_mutex_unlock(&data->op_mutex);
774
774
 
775
775
 
776
 
                DEBUG("rlm_ippool: Allocated ip %s to client key: %s",ip_ntoa(str,entry.ipaddr),hex_str);
 
776
                RDEBUG("Allocated ip %s to client key: %s",ip_ntoa(str,entry.ipaddr),hex_str);
777
777
                vp = radius_paircreate(request, &request->reply->vps,
778
778
                                       PW_FRAMED_IP_ADDRESS, PW_TYPE_IPADDR);
779
779
                vp->vp_ipaddr = entry.ipaddr;
792
792
        }
793
793
        else{
794
794
                pthread_mutex_unlock(&data->op_mutex);
795
 
                DEBUG("rlm_ippool: No available ip addresses in pool.");
 
795
                RDEBUG("No available ip addresses in pool.");
796
796
                return RLM_MODULE_NOTFOUND;
797
797
        }
798
798