Automatic search and replace for pairfind.
[freeradius.git] / src / modules / rlm_radutmp / rlm_radutmp2.c
1 /*
2  * rlm_radutmp.c
3  *
4  * Version:     $Id$
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation; either version 2 of the License, or
9  *   (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with this program; if not, write to the Free Software
18  *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  *
20  * Copyright 2000,2001,2002,2003,2004,2006  The FreeRADIUS server project
21  */
22
23 #include        <freeradius-devel/ident.h>
24 RCSID("$Id$")
25
26 #include        <freeradius-devel/radiusd.h>
27 #include        <freeradius-devel/radutmp.h>
28 #include        <freeradius-devel/modules.h>
29 #include        <freeradius-devel/rad_assert.h>
30
31 #include        <fcntl.h>
32 #include        <limits.h>
33
34 #include "config.h"
35
36 #define LOCK_LEN sizeof(struct radutmp)
37
38 static const char porttypes[] = "ASITX";
39
40 /*
41  *      Used for caching radutmp lookups in the accounting
42  *      component. The session (checksimul) component doesn't use it,
43  *      but probably should, though we're not sure how...
44  *
45  *      The intent here is to keep this structure as small as
46  *      possible, so that it doesn't take up too much memory.
47  */
48 typedef struct nas_port {
49         uint32_t                nas_address;
50         unsigned int            nas_port;
51         off_t                   offset;
52
53         struct nas_port         *next; /* for the free list */
54 } NAS_PORT;
55
56
57 /*
58  *      Per-file information.
59  *
60  *      Hmm... having multiple filenames managed by one instance
61  *      of the module makes it difficult for the module to do
62  *      simultaneous-use checking, without more code edits.
63  */
64 typedef struct radutmp_cache_t {
65         const char      *filename; /* for future reference */
66         time_t          last_used; /* for future reference */
67
68         rbtree_t        *nas_ports;
69         NAS_PORT        *free_offsets;
70         off_t           max_offset;
71         int             cached_file;
72         int             permission;
73 #ifdef HAVE_PTHREAD_H
74         pthread_mutex_t mutex;
75 #endif
76 } radutmp_cache_t;
77
78
79 /*
80  *      We cache the users, too, so that we only have to read radutmp
81  *      once.
82  */
83 typedef struct radutmp_simul_t {
84         char            login[sizeof(((struct radutmp *) NULL)->login) + 1];
85         int             simul_count;
86 } radutmp_simul_t;
87
88
89 /*
90  *      Data we store per module.
91  */
92 typedef struct rlm_radutmp_t {
93         char            *filename;
94         char            *username;
95         int             case_sensitive;
96         int             check_nas;
97         int             permission;
98         int             callerid_ok;
99
100         rbtree_t        *user_tree; /* for simultaneous-use */
101
102         /*
103          *      As the filenames can be dynamically translated,
104          *      we want to keep track of them in a separate data
105          *      structure, so that we can have per-file caches.
106          */
107         radutmp_cache_t cache;
108 } rlm_radutmp_t;
109
110 #ifndef HAVE_PTHREAD_H
111 /*
112  *      This is easier than ifdef's throughout the code.
113  */
114 #define pthread_mutex_init(_x, _y)
115 #define pthread_mutex_destroy(_x)
116 #define pthread_mutex_lock(_x)
117 #define pthread_mutex_unlock(_x)
118 #endif
119
120 static const CONF_PARSER module_config[] = {
121         { "filename", PW_TYPE_STRING_PTR,
122           offsetof(rlm_radutmp_t,filename), NULL,  RADUTMP },
123         { "username", PW_TYPE_STRING_PTR,
124           offsetof(rlm_radutmp_t,username), NULL,  "%{User-Name}"},
125         { "case_sensitive", PW_TYPE_BOOLEAN,
126           offsetof(rlm_radutmp_t,case_sensitive), NULL,  "yes"},
127         { "check_with_nas", PW_TYPE_BOOLEAN,
128           offsetof(rlm_radutmp_t,check_nas), NULL,  "yes"},
129         { "perm",     PW_TYPE_INTEGER,
130           offsetof(rlm_radutmp_t,permission), NULL,  "0644" },
131         { "callerid", PW_TYPE_BOOLEAN,
132           offsetof(rlm_radutmp_t,callerid_ok), NULL, "no" },
133         { NULL, -1, 0, NULL, NULL }             /* end the list */
134 };
135
136
137 /*
138  *      NAS PORT cmp
139  */
140 static int nas_port_cmp(const void *a, const void *b)
141 {
142         const NAS_PORT *one = a;
143         const NAS_PORT *two = b;
144
145         if (one->nas_address < two->nas_address) return -1;
146         if (one->nas_address > two->nas_address) return +1;
147
148         if (one->nas_port < two->nas_port) return -1;
149         if (one->nas_port > two->nas_port) return +1;
150
151         return 0;
152 }
153
154
155 /*
156  *      Compare two user names.
157  */
158 static int user_cmp(const void *a, const void *b)
159 {
160         const radutmp_simul_t *one = a;
161         const radutmp_simul_t *two = b;
162
163         return strcmp(one->login, two->login);
164 }
165
166
167 /*
168  *      Compare two user names, case insensitive.
169  */
170 static int user_case_cmp(const void *a, const void *b)
171 {
172         const radutmp_simul_t *one = a;
173         const radutmp_simul_t *two = b;
174
175         return strcasecmp(one->login, two->login);
176 }
177
178
179 /*
180  *      Detach.
181  */
182 static int radutmp_detach(void *instance)
183 {
184         NAS_PORT        *this, *next;
185         rlm_radutmp_t *inst = instance;
186
187         rbtree_free(inst->cache.nas_ports);
188
189         for (this = inst->cache.free_offsets;
190              this != NULL;
191              this = next) {
192                 next = this->next;
193                 free(this);
194         }
195
196         if (inst->cache.filename) free(inst->cache.filename);
197
198         pthread_mutex_destroy(&(inst->cache.mutex));
199
200
201         rbtree_free(inst->user_tree);
202
203         free(inst);
204         return 0;
205 }
206
207
208 /*
209  *      Instantiate.
210  */
211 static int radutmp_instantiate(CONF_SECTION *conf, void **instance)
212 {
213         rlm_radutmp_t *inst;
214
215         inst = rad_malloc(sizeof(*inst));
216         if (!inst) {
217                 return -1;
218         }
219         memset(inst, 0, sizeof(*inst));
220
221         if (cf_section_parse(conf, inst, module_config)) {
222                 radutmp_detach(inst);
223                 return -1;
224         }
225
226         inst->cache.nas_ports = rbtree_create(nas_port_cmp, free, 0);
227         if (!inst->cache.nas_ports) {
228                 radlog(L_ERR, "rlm_radutmp: Failed to create nas tree");
229                 radutmp_detach(inst);
230                 return -1;
231         }
232
233         pthread_mutex_init(&(inst->cache.mutex), NULL);
234         inst->cache.permission = inst->permission;
235
236         if (inst->case_sensitive) {
237                 inst->user_tree = rbtree_create(user_cmp, free, 0);
238         } else {
239                 inst->user_tree = rbtree_create(user_case_cmp, free, 0);
240         }
241         if (!inst->user_tree) {
242                 radlog(L_ERR, "rlm_radutmp: Failed to create user tree");
243                 radutmp_detach(inst);
244                 return -1;
245         }
246
247         *instance = inst;
248         return 0;
249 }
250
251
252 /*
253  *      Reset the cached entries.
254  */
255 static int cache_reset(rlm_radutmp_t *inst, radutmp_cache_t *cache)
256 {
257         NAS_PORT *this, *next;
258
259         /*
260          *      Cache is already reset, do nothing.
261          */
262         if ((rbtree_num_elements(cache->nas_ports) == 0) &&
263             (cache->free_offsets == NULL)) {
264                 DEBUG2("  rlm_radutmp: Not resetting the cache");
265                 return 1;
266         }
267         DEBUG2("  rlm_radutmp: Resetting the cache");
268
269         pthread_mutex_lock(&cache->mutex);
270
271         rbtree_free(inst->user_tree);
272
273         rbtree_free(cache->nas_ports);
274
275         for (this = cache->free_offsets;
276              this != NULL;
277              this = next) {
278                 next = this->next;
279                 free(this);
280         }
281         cache->free_offsets = NULL;
282
283         /*
284          *      Re-create the caches.
285          */
286         cache->nas_ports = rbtree_create(nas_port_cmp, free, 0);
287         if (!cache->nas_ports) {
288                 pthread_mutex_unlock(&cache->mutex);
289                 radlog(L_ERR, "rlm_radutmp: No memory");
290                 return 0;
291         }
292
293         cache->max_offset = 0;
294
295         cache->cached_file = 1;
296
297         if (inst->case_sensitive) {
298                 inst->user_tree = rbtree_create(user_cmp, free, 0);
299         } else {
300                 inst->user_tree = rbtree_create(user_case_cmp, free, 0);
301         }
302         if (!inst->user_tree) {
303                 pthread_mutex_unlock(&cache->mutex);
304                 radlog(L_ERR, "rlm_radutmp: No memory");
305                 return 0;
306         }
307
308         pthread_mutex_unlock(&cache->mutex);
309
310         return 1;
311 }
312
313
314 /*
315  *      Compare two offsets in a tree.
316  */
317 static int offset_cmp(const void *a, const void *b)
318 {
319         const NAS_PORT *one = a;
320         const NAS_PORT *two = b;
321
322         if (one->offset < two->offset) return -1;
323         if (one->offset > two->offset) return +1;
324
325         return 0;
326 }
327
328
329 /*
330  *      Data structure to use when walking the trees, for zap.
331  */
332 typedef struct offset_walk_t {
333         rlm_radutmp_t   *inst;
334         radutmp_cache_t *cache;
335         rbtree_t        *offset_tree;
336         uint32_t        nas_address;
337         int             fd;
338         time_t          now;
339 } offset_walk_t;
340
341
342 /*
343  *      Walk over the cache, finding entries with the matching NAS IP address.
344  */
345 static int nas_port_walk(void *context, void *data)
346 {
347         offset_walk_t   *walk = context;
348         NAS_PORT        *nas_port = data;
349
350         /*
351          *      Doesn't match, keep going.
352          */
353         if (walk->nas_address != nas_port->nas_address) return 0;
354
355         /*
356          *      Insert it into the offset tree, for later deletion.
357          */
358         if (rbtree_insert(walk->offset_tree, nas_port) != 1) {
359                 DEBUG2("  rlm_radumtp: Insertion failed in nas port walk.");
360                 return 1;
361         }
362
363         return 0;
364 }
365
366
367 /*
368  *      Walk through the offset tree, operating on the cache
369  */
370 static int offset_walk(void *context, void *data)
371 {
372         offset_walk_t   *walk = context;
373         NAS_PORT        *nas_port = data;
374         struct radutmp  utmp;
375         radutmp_simul_t *user, myUser;
376
377         /*
378          *      Seek to the entry, and possibly re-write it.
379          */
380         if (lseek(walk->fd, nas_port->offset, SEEK_SET) < 0) {
381                 rad_assert(0 == 1);
382         }
383
384         if (read(walk->fd, &utmp, sizeof(utmp)) != sizeof(utmp)) {
385                 rad_assert(0 == 1);
386         }
387
388         /*
389          *      If the entry in the file is NEWER than the reboot
390          *      packet, don't re-write it, and don't delete it.
391          */
392         if (utmp.time > walk->now) {
393                 return 0;
394         }
395
396         utmp.type = P_IDLE;
397         utmp.time = walk->now;
398
399         if (lseek(walk->fd, -(off_t)sizeof(utmp), SEEK_CUR) < 0) {
400                 radlog(L_ERR, "rlm_radutmp: offset_walk: failed in lseek: %s",
401                        strerror(errno));
402                 return 1;
403         }
404
405         write(walk->fd, &utmp, sizeof(utmp));
406
407         strlcpy(myUser.login, utmp.login, sizeof(myUser.login));
408         user = rbtree_finddata(walk->inst->user_tree, &myUser);
409         rad_assert(user != NULL);
410         rad_assert(user->simul_count > 0);
411         user->simul_count--;
412         if (user->simul_count == 0) {
413                 rbtree_deletebydata(walk->inst->user_tree, user);
414         }
415
416         if (rbtree_deletebydata(walk->cache->nas_ports, nas_port) == 0) {
417                 radlog(L_ERR, "rlm_radutmp: Failed to delete entry from cache");
418                 return 1;
419         }
420
421         /*
422          *      Insert the entry into the free list.
423          */
424         nas_port->next = walk->cache->free_offsets;
425         walk->cache->free_offsets = nas_port;
426
427         return 0;
428 }
429
430
431 /*
432  *      Zap all users on a NAS from the radutmp file.
433  */
434 static int radutmp_zap(rlm_radutmp_t *inst,
435                        radutmp_cache_t *cache,
436                        uint32_t nas_address,
437                        time_t now)
438 {
439         int             rcode;
440         rbtree_t        *offset_tree;
441         offset_walk_t   walk;
442
443         rad_assert(now != 0);
444
445         /*
446          *      If there's nothing in the file, do nothing,
447          *      but truncate the file, just to be safe.
448          */
449         if (rbtree_num_elements(cache->nas_ports) == 0) {
450                 truncate(cache->filename, (off_t) 0);
451                 DEBUG2("  rlm_radutmp: No entries in file.  Quenching zap.");
452                 return 1;
453         }
454
455         /*
456          *      Create the offset tree, as we want to delete utmp
457          *      entries starting from the start of the file, and we
458          *      can't delete nodes from an rbtree while we're walking
459          *      it.
460          */
461         offset_tree = rbtree_create(offset_cmp, NULL, 0);
462         if (!offset_tree) {
463                 radlog(L_ERR, "rlm_radutmp: Out of memory");
464                 return 0;
465         }
466
467         pthread_mutex_lock(&cache->mutex);
468
469         /*
470          *      Walk through the cache, finding entries for this NAS,
471          *      and add those entries to the offset tree.
472          */
473         memset(&walk, 0, sizeof(walk));
474         walk.inst = inst;
475         walk.offset_tree = offset_tree;
476         walk.nas_address = nas_address;
477         rcode = rbtree_walk(cache->nas_ports, PreOrder, nas_port_walk, &walk);
478         if (rcode != 0) {
479                 pthread_mutex_unlock(&cache->mutex);
480                 rbtree_free(offset_tree);
481                 radlog(L_ERR, "rlm_radutmp: Failed walking the cache.");
482                 return 0;
483         }
484
485         /*
486          *      If both trees have the same number of elements, then
487          *      don't do anything special, as UDP packets may be
488          *      received out of order, by several seconds.  The
489          *      "offset_walk" routine MAY NOT delete the entries, if
490          *      it sees that the entries in the file are newer than
491          *      the reboot packet.
492          */
493
494         /*
495          *      If there's nothing to do, don't do anything.
496          */
497         if (rbtree_num_elements(offset_tree) == 0) {
498                 DEBUG2("  rlm_radutmp: NAS IP %08x has no users recorded in file %s.",
499                        htonl(nas_address), cache->filename);
500                 pthread_mutex_unlock(&cache->mutex);
501                 rbtree_free(offset_tree);
502                 return 1;
503         }
504
505         /*
506          *      Open the file, to re-write only a few of the entries.
507          */
508         walk.fd = open(cache->filename, O_RDWR);
509         if (walk.fd < 0) {
510                 pthread_mutex_unlock(&cache->mutex);
511                 rbtree_free(offset_tree);
512                 radlog(L_ERR, "rlm_radutmp: Error accessing file %s: %s",
513                        cache->filename, strerror(errno));
514                 return 0;
515         }
516
517         /*
518          *      Lock the utmp file, prefer lockf() over flock().
519          *
520          *      FIXME: maybe we want to lock per-record?
521          */
522         rad_lockfd(walk.fd, LOCK_LEN);
523
524         /*
525          *      Walk through the offset tree, from start to finish,
526          *      deleting entries from the NAS tree, adding them to
527          *      the "free offset" cache, and lseek'ing to that offset
528          *      in the file, and clearing out the data.
529          */
530         walk.cache = cache;
531         walk.now = now;
532         rcode = rbtree_walk(offset_tree, InOrder, offset_walk, &walk);
533         rbtree_free(offset_tree);
534         if (rcode != 0) {
535                 radlog(L_ERR, "rlm_radutmp: Failed walking the offsets.");
536                 return 0;
537         }
538
539         close(walk.fd); /* and implicitly release the locks */
540
541         /*
542          *      Just to clean up the file.  If it's empty,
543          *      nuke everything.
544          */
545         if (rbtree_num_elements(cache->nas_ports) == 0) {
546                 NAS_PORT        *this, *next; /* too many copies of code */
547
548                 for (this = inst->cache.free_offsets;
549                      this != NULL;
550                      this = next) {
551                         next = this->next;
552                         free(this);
553                 }
554
555                 truncate(cache->filename, 0);
556                 rad_assert(rbtree_num_elements(inst->user_tree) == 0);
557         }
558
559         pthread_mutex_unlock(&cache->mutex);
560
561         return 1;
562 }
563
564
565 /*
566  *      Read a file, to cache all of its entries.
567  */
568 static int cache_file(rlm_radutmp_t *inst, radutmp_cache_t *cache)
569 {
570         int             fd;
571         int             read_size;
572         struct          stat buf;
573         struct          radutmp utmp;
574         NAS_PORT        **tail;
575
576         rad_assert(cache->max_offset == 0);
577         rad_assert(cache->free_offsets == NULL);
578
579         /*
580          *      Doesn't exist, we're fine.
581          */
582         if (stat(cache->filename, &buf) < 0) {
583                 if (errno == ENOENT) {
584                         cache->cached_file = 1;
585                         return 0;
586                 }
587                 radlog(L_ERR, "rlm_radutmp: Cannot stat %s: %s",
588                        cache->filename, strerror(errno));
589                 return 1;
590         }
591
592         /*
593          *      Nothing's there, we're OK.
594          */
595         if (buf.st_size == 0) {
596                 cache->cached_file = 1;
597                 return 0;
598         }
599
600         /*
601          *      Don't let others much around with our data.
602          */
603         pthread_mutex_lock(&cache->mutex);
604
605         /*
606          *      Read the file and cache it's entries.
607          */
608         fd = open(cache->filename, O_RDONLY, cache->permission);
609         if (fd < 0) {
610                 pthread_mutex_unlock(&cache->mutex);
611                 radlog(L_ERR, "rlm_radutmp: Error opening %s: %s",
612                        cache->filename, strerror(errno));
613                 return 1;
614         }
615
616         /*
617          *      Insert free entries into the tail, so that entries
618          *      get used from the start.
619          */
620         tail = &(cache->free_offsets);
621
622         /*
623          *      Don't lock the file, as we're only reading it.
624          */
625         do {
626                 read_size = read(fd, &utmp, sizeof(utmp));
627
628                 /*
629                  *      Read one record.
630                  */
631                 if (read_size == sizeof(utmp)) {
632                         radutmp_simul_t *user, myUser;
633                         NAS_PORT *nas_port = rad_malloc(sizeof(*nas_port));
634
635                         memset(nas_port, 0, sizeof(nas_port));
636                         nas_port->offset = cache->max_offset;
637                         cache->max_offset += sizeof(utmp);
638
639                         /*
640                          *      Idle.  Add it to the list of free
641                          *      offsets.
642                          */
643                         if (utmp.type == P_IDLE) {
644                                 *tail = nas_port;
645                                 tail = &(nas_port->next);
646                                 continue;
647                         }
648
649                         /*
650                          *      It's a login record,
651                          */
652                         nas_port->nas_address = utmp.nas_address;
653                         nas_port->nas_port = utmp.nas_port;
654
655                         if (!rbtree_insert(cache->nas_ports, nas_port)) {
656                                 rad_assert(0 == 1);
657                         }
658
659                         /*
660                          *      Adds a trailing \0, so myUser.login has
661                          *      an extra char allocated..
662                          */
663                         strlcpy(myUser.login, utmp.login, sizeof(myUser.login));
664                         user = rbtree_finddata(inst->user_tree, &myUser);
665                         if (user) {
666                                 user->simul_count++;
667                         } else {
668                                 /*
669                                  *      Allocate new entry, and add it
670                                  *      to the tree.
671                                  */
672                                 user = rad_malloc(sizeof(user));
673                                 strlcpy(user->login, utmp.login,
674                                         sizeof(user->login));
675                                 user->simul_count = 1;
676
677                                 if (!rbtree_insert(inst->user_tree, user)) {
678                                         rad_assert(0 == 1);
679                                 }
680                         }
681                         continue;
682                 }
683
684                 /*
685                  *      We've read a partial record.  WTF?
686                  */
687                 if (read_size != 0) {
688                         pthread_mutex_unlock(&cache->mutex);
689                         close(fd);
690                         radlog(L_ERR, "rlm_radutmp: Badly formed file %s",
691                                cache->filename);
692                         return 1;
693                 }
694
695                 /*
696                  *      Read nothing, stop.
697                  */
698         } while (read_size != 0);
699
700         pthread_mutex_unlock(&cache->mutex);
701         close(fd);              /* and release the lock. */
702         cache->cached_file = 1;
703
704         return 0;
705 }
706
707
708 /*
709  *      Store logins in the RADIUS utmp file.
710  */
711 static int radutmp_accounting(void *instance, REQUEST *request)
712 {
713         rlm_radutmp_t   *inst = instance;
714         struct radutmp  utmp, u;
715         VALUE_PAIR      *vp;
716         int             status = -1;
717         uint32_t        nas_address = 0;
718         uint32_t        framed_address = 0;
719         int             protocol = -1;
720         int             fd;
721         int             port_seen = 0;
722         char            buffer[256];
723         char            filename[1024];
724         char            ip_name[32]; /* 255.255.255.255 */
725         const char      *nas;
726         NAS_PORT        *nas_port, myPort;
727         radutmp_cache_t *cache;
728         int             read_size;
729         rbnode_t        *node;
730
731         /*
732          *      Which type is this.
733          */
734         if ((vp = pairfind(request->packet->vps, PW_ACCT_STATUS_TYPE, 0)) == NULL) {
735                 radlog(L_ERR, "rlm_radutmp: No Accounting-Status-Type record.");
736                 return RLM_MODULE_NOOP;
737         }
738         status = vp->vp_integer;
739
740         /*
741          *      Look for weird reboot packets.
742          *
743          *      ComOS (up to and including 3.5.1b20) does not send
744          *      standard PW_STATUS_ACCOUNTING_* messages.
745          *
746          *      Check for:  o no Acct-Session-Time, or time of 0
747          *                  o Acct-Session-Id of "00000000".
748          *
749          *      We could also check for NAS-Port, that attribute
750          *      should NOT be present (but we don't right now).
751          */
752         if ((status != PW_STATUS_ACCOUNTING_ON) &&
753             (status != PW_STATUS_ACCOUNTING_OFF)) do {
754                 int check1 = 0;
755                 int check2 = 0;
756
757                 if ((vp = pairfind(request->packet->vps, PW_ACCT_SESSION_TIME, 0))
758                      == NULL || vp->vp_date == 0)
759                         check1 = 1;
760                 if ((vp = pairfind(request->packet->vps, PW_ACCT_SESSION_ID, 0))
761                      != NULL && vp->length == 8 &&
762                      memcmp(vp->vp_strvalue, "00000000", 8) == 0)
763                         check2 = 1;
764                 if (check1 == 0 || check2 == 0) {
765 #if 0 /* Cisco sometimes sends START records without username. */
766                         radlog(L_ERR, "rlm_radutmp: no username in record");
767                         return RLM_MODULE_FAIL;
768 #else
769                         break;
770 #endif
771                 }
772                 radlog(L_INFO, "rlm_radutmp: converting reboot records.");
773                 if (status == PW_STATUS_STOP)
774                         status = PW_STATUS_ACCOUNTING_OFF;
775                 if (status == PW_STATUS_START)
776                         status = PW_STATUS_ACCOUNTING_ON;
777         } while(0);
778
779         memset(&utmp, 0, sizeof(utmp));
780         utmp.porttype = 'A';
781
782         /*
783          *      First, find the interesting attributes.
784          */
785         for (vp = request->packet->vps; vp; vp = vp->next) {
786                 switch (vp->attribute) {
787                         case PW_LOGIN_IP_HOST:
788                         case PW_FRAMED_IP_ADDRESS:
789                                 framed_address = vp->vp_ipaddr;
790                                 utmp.framed_address = vp->vp_ipaddr;
791                                 break;
792                         case PW_FRAMED_PROTOCOL:
793                                 protocol = vp->vp_integer;
794                                 break;
795                         case PW_NAS_IP_ADDRESS:
796                                 nas_address = vp->vp_ipaddr;
797                                 utmp.nas_address = vp->vp_ipaddr;
798                                 break;
799                         case PW_NAS_PORT:
800                                 utmp.nas_port = vp->vp_integer;
801                                 port_seen = 1;
802                                 break;
803                         case PW_ACCT_DELAY_TIME:
804                                 utmp.delay = vp->vp_integer;
805                                 break;
806                         case PW_ACCT_SESSION_ID:
807                                 /*
808                                  *      If it's too big, only use the
809                                  *      last bit.
810                                  */
811                                 if (vp->length > sizeof(utmp.session_id)) {
812                                         int length = vp->length - sizeof(utmp.session_id);
813
814                                         /*
815                                          *      Ascend is br0ken - it
816                                          *      adds a \0 to the end
817                                          *      of any string.
818                                          *      Compensate.
819                                          */
820                                         if (vp->vp_strvalue[vp->length - 1] == 0) {
821                                                 length--;
822                                         }
823
824                                         memcpy(utmp.session_id,
825                                               vp->vp_strvalue + length,
826                                               sizeof(utmp.session_id));
827                                 } else {
828                                         memset(utmp.session_id, 0,
829                                                sizeof(utmp.session_id));
830                                         memcpy(utmp.session_id,
831                                                vp->vp_strvalue,
832                                                vp->length);
833                                 }
834                                 break;
835                         case PW_NAS_PORT_TYPE:
836                                 if (vp->vp_integer <= 4)
837                                         utmp.porttype = porttypes[vp->vp_integer];
838                                 break;
839                         case PW_CALLING_STATION_ID:
840                                 if(inst->callerid_ok)
841                                         strlcpy(utmp.caller_id,
842                                                 (char *)vp->vp_strvalue,
843                                                 sizeof(utmp.caller_id));
844                                 break;
845                 }
846         }
847
848         /*
849          *      If we didn't find out the NAS address, use the
850          *      originator's IP address.
851          */
852         if (nas_address == 0) {
853                 nas_address = request->packet->src_ipaddr;
854                 utmp.nas_address = nas_address;
855                 nas = request->client->shortname;
856
857         } else if (request->packet->src_ipaddr.ipaddr.ip4addr.s_addr == nas_address) {          /* might be a client, might not be. */
858                 nas = request->client->shortname;
859
860         } else {
861                 /*
862                  *      The NAS isn't a client, it's behind
863                  *      a proxy server.  In that case, just
864                  *      get the IP address.
865                  */
866                 nas = ip_ntoa(ip_name, nas_address);
867         }
868
869
870         /*
871          *      Set the protocol field.
872          */
873         if (protocol == PW_PPP)
874                 utmp.proto = 'P';
875         else if (protocol == PW_SLIP)
876                 utmp.proto = 'S';
877         else
878                 utmp.proto = 'T';
879
880         utmp.time = request->timestamp - utmp.delay;
881
882         /*
883          *      Get the utmp filename, via xlat.
884          */
885         radius_xlat(filename, sizeof(filename), inst->filename, request, NULL);
886
887         /*
888          *      Future: look up filename in filename tree, to get
889          *      radutmp_cache_t pointer
890          */
891         cache = &inst->cache;
892
893         /*
894          *      For now, double-check the filename, to be sure it isn't
895          *      changing.
896          */
897         if (!cache->filename) {
898                 cache->filename = strdup(filename);
899                 rad_assert(cache->filename != NULL);
900
901         } else if (strcmp(cache->filename, filename) != 0) {
902                 radlog(L_ERR, "rlm_radutmp: We do not support dynamically named files.");
903                 return RLM_MODULE_FAIL;
904         }
905
906         /*
907          *      If the lookup failed, create a new one, and add it
908          *      to the filename tree, and cache the file, as below.
909          */
910
911         /*
912          *      For aging, in the future.
913          */
914         cache->last_used = request->timestamp;
915
916         /*
917          *      If we haven't already read the file, then read the
918          *      entire file, in order to cache its entries.
919          */
920         if (!cache->cached_file) {
921                 cache_file(inst, cache);
922         }
923
924         /*
925          *      See if this was a reboot.
926          *
927          *      Hmm... we may not want to zap all of the users when
928          *      the NAS comes up, because of issues with receiving
929          *      UDP packets out of order.
930          */
931         if (status == PW_STATUS_ACCOUNTING_ON && nas_address) {
932                 radlog(L_INFO, "rlm_radutmp: NAS %s restarted (Accounting-On packet seen)",
933                        nas);
934                 if (!radutmp_zap(inst, cache, nas_address, utmp.time)) {
935                         rad_assert(0 == 1);
936                 }
937                 return RLM_MODULE_OK;
938         }
939
940         if (status == PW_STATUS_ACCOUNTING_OFF && nas_address) {
941                 radlog(L_INFO, "rlm_radutmp: NAS %s rebooted (Accounting-Off packet seen)",
942                        nas);
943                 if (!radutmp_zap(inst, cache, nas_address, utmp.time)) {
944                         rad_assert(0 == 1);
945                 }
946                 return RLM_MODULE_OK;
947         }
948
949         /*
950          *      If we don't know this type of entry, then pretend we
951          *      succeeded.
952          */
953         if (status != PW_STATUS_START &&
954             status != PW_STATUS_STOP &&
955             status != PW_STATUS_ALIVE) {
956                 radlog(L_ERR, "rlm_radutmp: NAS %s port %u unknown packet type %d, ignoring it.",
957                        nas, utmp.nas_port, status);
958                 return RLM_MODULE_NOOP;
959         }
960
961         /*
962          *      Perhaps we don't want to store this record into
963          *      radutmp. We skip records:
964          *
965          *      - without a NAS-Port (telnet / tcp access)
966          *      - with the username "!root" (console admin login)
967          */
968         if (!port_seen) {
969                 DEBUG2("  rlm_radutmp: No NAS-Port in the packet.  Cannot do anything.");
970                 DEBUG2("  rlm_radumtp: WARNING: checkrad will probably not work!");
971                 return RLM_MODULE_NOOP;
972         }
973
974         /*
975          *      Translate the User-Name attribute, or whatever else
976          *      they told us to use.
977          */
978         *buffer = '\0';
979         radius_xlat(buffer, sizeof(buffer), inst->username, request, NULL);
980
981         /*
982          *      Don't log certain things...
983          */
984         if (strcmp(buffer, "!root") == 0) {
985                 DEBUG2("  rlm_radutmp: Not recording administrative user");
986
987                 return RLM_MODULE_NOOP;
988         }
989         strlcpy(utmp.login, buffer, RUT_NAMESIZE);
990
991         /*
992          *      First, try to open the file.  If it doesn't exist,
993          *      nuke the existing caches, and try to create it.
994          *
995          *      FIXME: Create any intermediate directories, as
996          *      appropriate.  See rlm_detail.
997          */
998         fd = open(cache->filename, O_RDWR, inst->permission);
999         if (fd < 0) {
1000                 if (errno == ENOENT) {
1001                         DEBUG2("  rlm_radutmp: File %s doesn't exist, creating it.", cache->filename);
1002                         if (!cache_reset(inst, cache)) return RLM_MODULE_FAIL;
1003
1004                         /*
1005                          *      Try to create the file.
1006                          */
1007                         fd = open(cache->filename, O_RDWR | O_CREAT,
1008                                   inst->permission);
1009                 }
1010         } else {                /* exists, but may be empty */
1011                 struct stat buf;
1012
1013                 /*
1014                  *      If the file is empty, reset the cache.
1015                  */
1016                 if ((stat(cache->filename, &buf) == 0) &&
1017                     (buf.st_size == 0) &&
1018                     (!cache_reset(inst, cache))) {
1019                         return RLM_MODULE_FAIL;
1020                 }
1021                 DEBUG2("  rlm_radutmp: File %s was truncated.  Resetting cache.",
1022                        cache->filename);
1023         }
1024
1025         /*
1026          *      Error from creation, or error other than ENOENT: die.
1027          */
1028         if (fd < 0) {
1029                 radlog(L_ERR, "rlm_radutmp: Error accessing file %s: %s",
1030                        cache->filename, strerror(errno));
1031                 return RLM_MODULE_FAIL;
1032         }
1033
1034         /*
1035          *      OK.  Now that we've prepared everything we want to do,
1036          *      let's see if we've cached the entry.
1037          */
1038         myPort.nas_address = utmp.nas_address;
1039         myPort.nas_port = utmp.nas_port;
1040
1041         pthread_mutex_lock(&cache->mutex);
1042         node = rbtree_find(cache->nas_ports, &myPort);
1043         pthread_mutex_unlock(&cache->mutex);
1044
1045         if (node) {
1046                 nas_port = rbtree_node2data(cache->nas_ports, node);
1047 #if 0
1048
1049                 /*
1050                  *      stat the file, and get excited if it's been
1051                  *      truncated.
1052                  *
1053                  *      i.e wipe out the cache, and re-read the file.
1054                  */
1055
1056                 /*
1057                  *      Now find the new entry.
1058                  */
1059                 pthread_mutex_lock(&cache->mutex);
1060                 node = rbtree_find(cache->nas_ports, &myPort);
1061                 pthread_mutex_unlock(&cache->mutex);
1062 #endif
1063         }
1064
1065         if (!node) {
1066                 radutmp_simul_t *user;
1067
1068                 /*
1069                  *      Not found in the cache, and we're trying to
1070                  *      delete an existing record: ignore it.
1071                  */
1072                 if (status == PW_STATUS_STOP) {
1073                         DEBUG2("  rlm_radumtp: Logout entry for NAS %s port %u with no Login: ignoring it.",
1074                                nas, utmp.nas_port);
1075                         return RLM_MODULE_NOOP;
1076                 }
1077
1078                 pthread_mutex_lock(&cache->mutex);
1079
1080                 /*
1081                  *      It's a START or ALIVE.  Try to find a free
1082                  *      offset where we can store the new entry, or
1083                  *      create one, if one doesn't already exist.
1084                  */
1085                 if (!cache->free_offsets) {
1086                         cache->free_offsets = rad_malloc(sizeof(NAS_PORT));
1087                         memset(cache->free_offsets, 0,
1088                                sizeof(*(cache->free_offsets)));
1089                         cache->free_offsets->offset = cache->max_offset;
1090                         cache->max_offset += sizeof(u);
1091                 }
1092
1093                 /*
1094                  *      Grab the offset, and put it into the various
1095                  *      caches.
1096                  */
1097                 nas_port = cache->free_offsets;
1098                 cache->free_offsets = nas_port->next;
1099
1100                 nas_port->nas_address = nas_address;
1101                 nas_port->nas_port = utmp.nas_port;
1102
1103                 if (!rbtree_insert(cache->nas_ports, nas_port)) {
1104                         rad_assert(0 == 1);
1105                 }
1106
1107                 /*
1108                  *      Allocate new entry, and add it
1109                  *      to the tree.
1110                  */
1111                 user = rad_malloc(sizeof(user));
1112                 strlcpy(user->login, utmp.login,
1113                         sizeof(user->login));
1114                 user->simul_count = 1;
1115
1116                 if (!rbtree_insert(inst->user_tree, user)) {
1117                         rad_assert(0 == 1);
1118                 }
1119
1120                 pthread_mutex_unlock(&cache->mutex);
1121
1122         }
1123
1124         /*
1125          *      Entry was found, or newly created in the cache.
1126          *      Seek to the place in the file.
1127          */
1128         lseek(fd, nas_port->offset, SEEK_SET);
1129
1130         /*
1131          *      Lock the utmp file, prefer lockf() over flock().
1132          */
1133         rad_lockfd(fd, LOCK_LEN);
1134
1135         /*
1136          *      If it WAS found in the cache, double-check it against
1137          *      what is in the file.
1138          */
1139         if (node) {
1140                 /*
1141                  *      If we didn't read anything, then this entry
1142                  *      doesn't exist.
1143                  *
1144                  *      Similarly, if the entry in the file doesn't
1145                  *      match what we recall, then nuke the cache
1146                  *      entry.
1147                  */
1148                 read_size = read(fd, &u, sizeof(u));
1149                 if ((read_size < 0) ||
1150                     ((read_size > 0) && (read_size  != sizeof(u)))) {
1151                         /*
1152                          *      Bad read, or bad record.
1153                          */
1154                         radlog(L_ERR, "rlm_radutmp: Badly formed file %s",
1155                                cache->filename);
1156                         close(fd);
1157                         return RLM_MODULE_FAIL;
1158                 }
1159
1160                 rad_assert(read_size != 0);
1161
1162                 /*
1163                  *      We've read a record, go poke at it.
1164                  */
1165                 if (read_size > 0) {
1166                         /*
1167                          *      If these aren't true, then
1168                          *
1169                          *      a) we have cached a "logout" entry,
1170                          *         which we don't do.
1171                          *
1172                          *      b) we have cached the wrong NAS address
1173                          *
1174                          *      c) we have cached the wrong NAS port.
1175                          */
1176                         rad_assert(u.type == P_LOGIN);
1177                         rad_assert(u.nas_address == utmp.nas_address);
1178                         rad_assert(u.nas_port == utmp.nas_port);
1179
1180                         /*
1181                          *      An update for the same session.
1182                          */
1183                         if (strncmp(utmp.session_id, u.session_id,
1184                                     sizeof(u.session_id)) == 0) {
1185
1186                                 /*
1187                                  *      It's a duplicate start, so we
1188                                  *      don't bother writing it.
1189                                  */
1190                                 if (status == PW_STATUS_START) {
1191                                         DEBUG2("  rlm_radutmp: Login entry for NAS %s port %u duplicate, ignoring it.",
1192                                                nas, u.nas_port);
1193                                         close(fd);
1194                                         return RLM_MODULE_OK;
1195
1196
1197                                 /*
1198                                  *      ALIVE for this session, keep the
1199                                  *      original login time.
1200                                  */
1201                                 } else if (status == PW_STATUS_ALIVE) {
1202                                         utmp.time = u.time;
1203
1204                                 /*
1205                                  *      Stop: delete it from our cache.
1206                                  */
1207                                 } else if (status == PW_STATUS_STOP) {
1208                                         radutmp_simul_t *user, myUser;
1209
1210                                         pthread_mutex_lock(&cache->mutex);
1211                                         rbtree_deletebydata(cache->nas_ports,
1212                                                             nas_port);
1213
1214                                         strlcpy(myUser.login,
1215                                                 u.login, sizeof(myUser.login));
1216                                         user = rbtree_finddata(inst->user_tree,
1217                                                                &myUser);
1218                                         rad_assert(user != NULL);
1219                                         rad_assert(user->simul_count > 0);
1220
1221                                         user->simul_count--;
1222                                         if (user->simul_count == 0) {
1223                                                 rbtree_deletebydata(inst->user_tree, user);
1224                                         }
1225
1226                                         pthread_mutex_unlock(&cache->mutex);
1227
1228                                 } else {
1229                                         /*
1230                                          *      We don't know how to
1231                                          *      handle this.
1232                                          */
1233                                         rad_assert(0 == 1);
1234                                 }
1235
1236                         } else { /* session ID doesn't match */
1237                                 /*
1238                                  *      STOP for the right NAS & port,
1239                                  *      but the Acct-Session-Id is
1240                                  *      different.  This means that
1241                                  *      we missed the original "stop",
1242                                  *      and a new "start".
1243                                  */
1244                                 if (status == PW_STATUS_STOP) {
1245                                         radlog(L_ERR, "rlm_radutmp: Logout entry for NAS %s port %u has old Acct-Session-ID, ignoring it.",
1246                                                nas, u.nas_port);
1247                                         close(fd);
1248                                         return RLM_MODULE_OK;
1249                                 }
1250                         } /* checked session ID's */
1251                 }  /* else we haven't read anything from the file. */
1252         } /* else the entry wasn't cached, but could have been inserted */
1253
1254         /*
1255          *      Hmm... we may have received a start or alive packet
1256          *      AFTER a stop or nas-down, in that case, we want to
1257          *      discard the new packet.  However, the original code
1258          *      could over-write an idle record with a new login
1259          *      record for another NAS && port, so we won't worry
1260          *      about this case too much.
1261          */
1262
1263         /*
1264          *      Seek to where the entry is, and write it blindly.
1265          */
1266         lseek(fd, nas_port->offset, SEEK_SET); /* FIXME: err */
1267
1268         if (status != PW_STATUS_STOP) {
1269                 utmp.type = P_LOGIN;
1270                 rad_assert(nas_port != NULL); /* it WAS cached */
1271         } else {
1272                 /* FIXME: maybe assert that the entry was deleted... */
1273                 memcpy(&utmp, &u, sizeof(utmp));
1274                 utmp.type = P_IDLE;
1275         }
1276
1277         write(fd, &utmp, sizeof(utmp)); /* FIXME: err */
1278
1279         close(fd);      /* and implicitly release the locks */
1280
1281         return RLM_MODULE_OK;
1282 }
1283
1284 /*
1285  *      See if a user is already logged in. Sets request->simul_count
1286  *      to the current session count for this user and sets
1287  *      request->simul_mpp to 2 if it looks like a multilink attempt
1288  *      based on the requested IP address, otherwise leaves
1289  *      request->simul_mpp alone.
1290  *
1291  *      Check twice. If on the first pass the user exceeds his
1292  *      max. number of logins, do a second pass and validate all
1293  *      logins by querying the terminal server (using eg. SNMP).
1294  */
1295 static int radutmp_checksimul(void *instance, REQUEST *request)
1296 {
1297         struct radutmp  u;
1298         int             fd;
1299         VALUE_PAIR      *vp;
1300         uint32_t        ipno = 0;
1301         char            *call_num = NULL;
1302         int             rcode;
1303         rlm_radutmp_t   *inst = instance;
1304         char            login[256];
1305         char            filename[1024];
1306         radutmp_cache_t *cache;
1307         radutmp_simul_t *user, myUser;
1308
1309         /*
1310          *      Get the filename, via xlat.
1311          */
1312         radius_xlat(filename, sizeof(filename), inst->filename, request, NULL);
1313
1314         /*
1315          *      Future: look up filename in filename tree, to get
1316          *      radutmp_cache_t pointer
1317          */
1318         cache = &inst->cache;
1319
1320         /*
1321          *      For now, double-check the filename, to be sure it isn't
1322          *      changing.
1323          */
1324         if (!cache->filename) {
1325                 cache->filename = strdup(filename);
1326                 rad_assert(cache->filename != NULL);
1327
1328         } else if (strcmp(cache->filename, filename) != 0) {
1329                 radlog(L_ERR, "rlm_radutmp: We do not support dynamically named files.");
1330                 return RLM_MODULE_FAIL;
1331         }
1332
1333         *login = '\0';
1334         radius_xlat(login, sizeof(login), inst->username, request, NULL);
1335         if (!*login) {
1336                 return RLM_MODULE_NOOP;
1337         }
1338
1339         /*
1340          *      WTF?  This is probably wrong... we probably want to
1341          *      be able to check users across multiple session accounting
1342          *      methods.
1343          */
1344         request->simul_count = 0;
1345
1346         strlcpy(myUser.login, login, sizeof(myUser.login));
1347         pthread_mutex_lock(&inst->cache.mutex);
1348         user = rbtree_finddata(inst->user_tree, &myUser);
1349         if (user) request->simul_count = user->simul_count;
1350         user = NULL;            /* someone else may delete it */
1351         pthread_mutex_unlock(&inst->cache.mutex);
1352
1353         /*
1354          *      The number of users logged in is OK,
1355          *      OR, we've been told to not check the NAS.
1356          */
1357         if ((request->simul_count < request->simul_max) ||
1358             !inst->check_nas) {
1359                 return RLM_MODULE_OK;
1360         }
1361
1362         /*
1363          *      The user is logged in at least N times, and
1364          *      we're told to check the NAS.  In that case,
1365          *      we've got to read the file, and check each
1366          *      NAS port by hand.
1367          */
1368         if ((fd = open(cache->filename, O_RDWR)) < 0) {
1369                 /*
1370                  *      If the file doesn't exist, then no users
1371                  *      are logged in.
1372                  */
1373                 if (errno == ENOENT) {
1374                         request->simul_count = 0;
1375                         return RLM_MODULE_OK;
1376                 }
1377
1378                 /*
1379                  *      Error accessing the file.
1380                  */
1381                 radlog(L_ERR, "rlm_radumtp: Error accessing file %s: %s",
1382                        cache->filename, strerror(errno));
1383                 return RLM_MODULE_FAIL;
1384         }
1385
1386         /*
1387          *      Setup some stuff, like for MPP detection.
1388          */
1389         if ((vp = pairfind(request->packet->vps, PW_FRAMED_IP_ADDRESS, 0)) != NULL)
1390                 ipno = vp->vp_ipaddr;
1391         if ((vp = pairfind(request->packet->vps, PW_CALLING_STATION_ID, 0)) != NULL)
1392                 call_num = vp->vp_strvalue;
1393
1394         /*
1395          *      lock the file while reading/writing.
1396          */
1397         rad_lockfd(fd, LOCK_LEN);
1398
1399         /*
1400          *      FIXME: If we get a 'Start' for a user/nas/port which is
1401          *      listed, but for which we did NOT get a 'Stop', then
1402          *      it's not a duplicate session.  This happens with
1403          *      static IP's like DSL.
1404          */
1405         request->simul_count = 0;
1406         while (read(fd, &u, sizeof(u)) == sizeof(u)) {
1407                 if (((strncmp(login, u.login, RUT_NAMESIZE) == 0) ||
1408                      (!inst->case_sensitive &&
1409                       (strncasecmp(login, u.login, RUT_NAMESIZE) == 0))) &&
1410                     (u.type == P_LOGIN)) {
1411                         char session_id[sizeof(u.session_id) + 1];
1412                         char utmp_login[sizeof(u.login) + 1];
1413
1414                         strlcpy(session_id, u.session_id, sizeof(session_id));
1415
1416                         /*
1417                          *      The login name MAY fill the whole field,
1418                          *      and thus won't be zero-filled.
1419                          *
1420                          *      Note that we take the user name from
1421                          *      the utmp file, as that's the canonical
1422                          *      form.  The 'login' variable may contain
1423                          *      a string which is an upper/lowercase
1424                          *      version of u.login.  When we call the
1425                          *      routine to check the terminal server,
1426                          *      the NAS may be case sensitive.
1427                          *
1428                          *      e.g. We ask if "bob" is using a port,
1429                          *      and the NAS says "no", because "BOB"
1430                          *      is using the port.
1431                          */
1432                         strlcpy(utmp_login, u.login, sizeof(u.login));
1433
1434                         /*
1435                          *      rad_check_ts may take seconds
1436                          *      to return, and we don't want
1437                          *      to block everyone else while
1438                          *      that's happening.  */
1439                         rad_unlockfd(fd, LOCK_LEN);
1440                         rcode = rad_check_ts(u.nas_address, u.nas_port,
1441                                              utmp_login, session_id);
1442                         rad_lockfd(fd, LOCK_LEN);
1443
1444                         if (rcode == 0) {
1445                                 /*
1446                                  *      Stale record - zap it.
1447                                  *
1448                                  *      Hmm... this ends up calling
1449                                  *      the accounting section
1450                                  *      recursively...
1451                                  */
1452                                 session_zap(request, u.nas_address,
1453                                             u.nas_port, login, session_id,
1454                                             u.framed_address, u.proto,0);
1455                         }
1456                         else if (rcode == 1) {
1457                                 /*
1458                                  *      User is still logged in.
1459                                  */
1460                                 ++request->simul_count;
1461
1462                                 /*
1463                                  *      Does it look like a MPP attempt?
1464                                  */
1465                                 if (strchr("SCPA", u.proto) &&
1466                                     ipno && u.framed_address == ipno)
1467                                         request->simul_mpp = 2;
1468                                 else if (strchr("SCPA", u.proto) && call_num &&
1469                                         !strncmp(u.caller_id,call_num,16))
1470                                         request->simul_mpp = 2;
1471                         }
1472                         else {
1473                                 /*
1474                                  *      Failed to check the terminal
1475                                  *      server for duplicate logins:
1476                                  *      Return an error.
1477                                  */
1478                                 close(fd);
1479                                 radlog(L_ERR, "rlm_radutmp: Failed to check the terminal server for user '%s'.", utmp_login);
1480                                 return RLM_MODULE_FAIL;
1481                         }
1482                 }
1483         }
1484         close(fd);              /* and implicitly release the locks */
1485
1486         return RLM_MODULE_OK;
1487 }
1488
1489 /* globally exported name */
1490 module_t rlm_radutmp = {
1491   "radutmp",
1492   0,                            /* type: reserved */
1493   NULL,                         /* initialization */
1494   radutmp_instantiate,          /* instantiation */
1495   {
1496           NULL,                 /* authentication */
1497           NULL,                 /* authorization */
1498           NULL,                 /* preaccounting */
1499           radutmp_accounting,   /* accounting */
1500           radutmp_checksimul,   /* checksimul */
1501           NULL,                 /* pre-proxy */
1502           NULL,                 /* post-proxy */
1503           NULL                  /* post-auth */
1504   },
1505   radutmp_detach,               /* detach */
1506   NULL,                         /* destroy */
1507 };
1508