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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Josip Rodin
  • Date: 2009-11-23 03:57:37 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20091123035737-zsgtzhfych8hir68
Tags: 2.1.7+dfsg-1
* Adopting the package, closes: #536623.
* New upstream version, closes: #513484.
  + Fixes the blooper in unlang evaluation logic, closes: #526175.
* Used quilt (and added README.source), and moved upstream file patching
  into debian/patches/. The source is no longer in collab-maint git
  (to make it simpler for me to finally get this out the door), but
  kept the .gitignore should we need that again.
* Dropped the dialup_admin/bin/backup_radacct patch (integrated upstream).
* Dropped the raddb/Makefile patch (problem no longer exists upstream).
* Dropped the lib/packet.c lib/radius.c main/listen.c patches (was from
  upstream 2.0.5 anyway).
* Dropped references to otp.conf, it no longer exists upstream.
  Keep removing the conffile statoverride in prerm.
* Dropped references to snmp.conf, it no longer exists upstream.
  Keep removing the conffile statoverride in prerm.
* Ship /etc/freeradius/modules/* in the freeradius package.
* Stop shipping sites-enabled symlinks in the package and instead create
  them only on initial install, thanks to Matej Vela, closes: #533396.
* Add export PATH="${PATH:+$PATH:}/usr/sbin:/sbin" to the init script
  at the request of John Morrissey, closes: #550143.
* Stop installing /var/run/freeradius in the package to silence Lintian.
  The init script already recreates it at will.
* Remove executable bit from example.pl to silence Lintian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * rlm_radutmp.c
3
3
 *
4
 
 * Version:     $Id: rlm_radutmp.c,v 1.45 2008/01/06 17:28:54 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
22
22
 */
23
23
 
24
24
#include        <freeradius-devel/ident.h>
25
 
RCSID("$Id: rlm_radutmp.c,v 1.45 2008/01/06 17:28:54 nbk Exp $")
 
25
RCSID("$Id$")
26
26
 
27
27
#include        <freeradius-devel/radiusd.h>
28
28
#include        <freeradius-devel/radutmp.h>
183
183
        struct radutmp  ut, u;
184
184
        VALUE_PAIR      *vp;
185
185
        int             status = -1;
186
 
        uint32_t        nas_address = 0;
187
 
        uint32_t        framed_address = 0;
188
186
        int             protocol = -1;
189
187
        time_t          t;
190
188
        int             fd;
191
 
        int             just_an_update = 0;
192
189
        int             port_seen = 0;
193
 
        int             nas_port_type = 0;
194
190
        int             off;
195
191
        rlm_radutmp_t   *inst = instance;
196
192
        char            buffer[256];
256
252
        time(&t);
257
253
        memset(&ut, 0, sizeof(ut));
258
254
        ut.porttype = 'A';
 
255
        ut.nas_address = htonl(INADDR_NONE);
259
256
 
260
257
        /*
261
258
         *      First, find the interesting attributes.
264
261
                switch (vp->attribute) {
265
262
                        case PW_LOGIN_IP_HOST:
266
263
                        case PW_FRAMED_IP_ADDRESS:
267
 
                                framed_address = vp->vp_ipaddr;
268
264
                                ut.framed_address = vp->vp_ipaddr;
269
265
                                break;
270
266
                        case PW_FRAMED_PROTOCOL:
271
267
                                protocol = vp->vp_integer;
272
268
                                break;
273
269
                        case PW_NAS_IP_ADDRESS:
274
 
                                nas_address = vp->vp_ipaddr;
275
270
                                ut.nas_address = vp->vp_ipaddr;
276
271
                                break;
277
272
                        case PW_NAS_PORT:
302
297
                        case PW_NAS_PORT_TYPE:
303
298
                                if (vp->vp_integer <= 4)
304
299
                                        ut.porttype = porttypes[vp->vp_integer];
305
 
                                nas_port_type = vp->vp_integer;
306
300
                                break;
307
301
                        case PW_CALLING_STATION_ID:
308
302
                                if(inst->callerid_ok)
317
311
         *      If we didn't find out the NAS address, use the
318
312
         *      originator's IP address.
319
313
         */
320
 
        if (nas_address == 0) {
321
 
                nas_address = request->packet->src_ipaddr.ipaddr.ip4addr.s_addr;
322
 
                ut.nas_address = nas_address;
 
314
        if (ut.nas_address == htonl(INADDR_NONE)) {
 
315
                ut.nas_address = request->packet->src_ipaddr.ipaddr.ip4addr.s_addr;
323
316
                nas = request->client->shortname;
324
317
 
325
 
        } else if (request->packet->src_ipaddr.ipaddr.ip4addr.s_addr == nas_address) {          /* might be a client, might not be. */
 
318
        } else if (request->packet->src_ipaddr.ipaddr.ip4addr.s_addr == ut.nas_address) {               /* might be a client, might not be. */
326
319
                nas = request->client->shortname;
327
320
 
328
321
        } else {
331
324
                 *      a proxy server.  In that case, just
332
325
                 *      get the IP address.
333
326
                 */
334
 
                nas = ip_ntoa(ip_name, nas_address);
 
327
                nas = ip_ntoa(ip_name, ut.nas_address);
335
328
        }
336
329
 
337
330
        /*
357
350
         *      the NAS comes up, because of issues with receiving
358
351
         *      UDP packets out of order.
359
352
         */
360
 
        if (status == PW_STATUS_ACCOUNTING_ON && nas_address) {
 
353
        if (status == PW_STATUS_ACCOUNTING_ON &&
 
354
            (ut.nas_address != htonl(INADDR_NONE))) {
361
355
                radlog(L_INFO, "rlm_radutmp: NAS %s restarted (Accounting-On packet seen)",
362
356
                       nas);
363
 
                radutmp_zap(inst, filename, nas_address, ut.time);
 
357
                radutmp_zap(inst, filename, ut.nas_address, ut.time);
364
358
                return RLM_MODULE_OK;
365
359
        }
366
360
 
367
 
        if (status == PW_STATUS_ACCOUNTING_OFF && nas_address) {
 
361
        if (status == PW_STATUS_ACCOUNTING_OFF &&
 
362
            (ut.nas_address != htonl(INADDR_NONE))) {
368
363
                radlog(L_INFO, "rlm_radutmp: NAS %s rebooted (Accounting-Off packet seen)",
369
364
                       nas);
370
 
                radutmp_zap(inst, filename, nas_address, ut.time);
 
365
                radutmp_zap(inst, filename, ut.nas_address, ut.time);
371
366
                return RLM_MODULE_OK;
372
367
        }
373
368
 
496
491
                         *      Keep the original login time.
497
492
                         */
498
493
                        ut.time = u.time;
499
 
                        if (u.login[0] != 0)
500
 
                                just_an_update = 1;
501
494
                }
502
495
 
503
496
                if (lseek(fd, -(off_t)sizeof(u), SEEK_CUR) < 0) {
546
539
                } else if (r == 0) {
547
540
                        radlog(L_ERR, "rlm_radutmp: Logout for NAS %s port %u, but no Login record",
548
541
                               nas, ut.nas_port);
549
 
                        r = -1;
550
542
                }
551
543
        }
552
544
        close(fd);      /* and implicitely release the locks */