* Use syslog-compatible logging levels in lprintf(); the loglevel chosen
[citadel.git] / citadel / serv_expire.c
1 /*
2  * $Id$
3  *
4  * This module handles the expiry of old messages and the purging of old users.
5  *
6  */
7
8
9 /*
10  * A brief technical discussion:
11  *
12  * Several of the purge operations found in this module operate in two
13  * stages: the first stage generates a linked list of objects to be deleted,
14  * then the second stage deletes all listed objects from the database.
15  *
16  * At first glance this may seem cumbersome and unnecessary.  The reason it is
17  * implemented in this way is because Berkeley DB, and possibly other backends
18  * we may hook into in the future, explicitly do _not_ support the deletion of
19  * records from a file while the file is being traversed.  The delete operation
20  * will succeed, but the traversal is not guaranteed to visit every object if
21  * this is done.  Therefore we utilize the two-stage purge.
22  *
23  * When using Berkeley DB, there's another reason for the two-phase purge: we
24  * don't want the entire thing being done as one huge transaction.
25  */
26
27
28 #include "sysdep.h"
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <stdio.h>
32 #include <fcntl.h>
33 #include <signal.h>
34 #include <pwd.h>
35 #include <errno.h>
36 #include <sys/types.h>
37
38 #if TIME_WITH_SYS_TIME
39 # include <sys/time.h>
40 # include <time.h>
41 #else
42 # if HAVE_SYS_TIME_H
43 #  include <sys/time.h>
44 # else
45 #  include <time.h>
46 # endif
47 #endif
48
49 #include <sys/wait.h>
50 #include <string.h>
51 #include <limits.h>
52 #include "citadel.h"
53 #include "server.h"
54 #include "sysdep_decls.h"
55 #include "citserver.h"
56 #include "support.h"
57 #include "config.h"
58 #include "serv_extensions.h"
59 #include "room_ops.h"
60 #include "policy.h"
61 #include "database.h"
62 #include "msgbase.h"
63 #include "user_ops.h"
64 #include "control.h"
65 #include "serv_network.h"
66 #include "tools.h"
67
68
69 struct PurgeList {
70         struct PurgeList *next;
71         char name[ROOMNAMELEN]; /* use the larger of username or roomname */
72 };
73
74 struct VPurgeList {
75         struct VPurgeList *next;
76         long vp_roomnum;
77         long vp_roomgen;
78         long vp_usernum;
79 };
80
81 struct ValidRoom {
82         struct ValidRoom *next;
83         long vr_roomnum;
84         long vr_roomgen;
85 };
86
87 struct ValidUser {
88         struct ValidUser *next;
89         long vu_usernum;
90 };
91
92
93 struct ctdlroomref {
94         struct ctdlroomref *next;
95         long msgnum;
96 };
97
98 struct UPurgeList {
99         struct UPurgeList *next;
100         char up_key[SIZ];
101 };
102
103
104 struct PurgeList *UserPurgeList = NULL;
105 struct PurgeList *RoomPurgeList = NULL;
106 struct ValidRoom *ValidRoomList = NULL;
107 struct ValidUser *ValidUserList = NULL;
108 int messages_purged;
109
110 struct ctdlroomref *rr = NULL;
111
112 extern struct CitContext *ContextList;
113
114
115 /*
116  * First phase of message purge -- gather the locations of messages which
117  * qualify for purging and write them to a temp file.
118  */
119 void GatherPurgeMessages(struct ctdlroom *qrbuf, void *data) {
120         struct ExpirePolicy epbuf;
121         long delnum;
122         time_t xtime, now;
123         struct CtdlMessage *msg;
124         int a;
125         struct cdbdata *cdbfr;
126         long *msglist = NULL;
127         int num_msgs = 0;
128         FILE *purgelist;
129
130         purgelist = (FILE *)data;
131         fprintf(purgelist, "r=%s\n", qrbuf->QRname);
132
133         time(&now);
134         GetExpirePolicy(&epbuf, qrbuf);
135
136         /* If the room is set to never expire messages ... do nothing */
137         if (epbuf.expire_mode == EXPIRE_NEXTLEVEL) return;
138         if (epbuf.expire_mode == EXPIRE_MANUAL) return;
139
140         cdbfr = cdb_fetch(CDB_MSGLISTS, &qrbuf->QRnumber, sizeof(long));
141
142         if (cdbfr != NULL) {
143                 msglist = mallok(cdbfr->len);
144                 memcpy(msglist, cdbfr->ptr, cdbfr->len);
145                 num_msgs = cdbfr->len / sizeof(long);
146                 cdb_free(cdbfr);
147         }
148
149         /* Nothing to do if there aren't any messages */
150         if (num_msgs == 0) {
151                 if (msglist != NULL) phree(msglist);
152                 return;
153         }
154
155         /* If the room is set to expire by count, do that */
156         if (epbuf.expire_mode == EXPIRE_NUMMSGS) {
157                 if (num_msgs > epbuf.expire_value) {
158                         for (a=0; a<(num_msgs - epbuf.expire_value); ++a) {
159                                 fprintf(purgelist, "m=%ld\n", msglist[a]);
160                                 ++messages_purged;
161                         }
162                 }
163         }
164
165         /* If the room is set to expire by age... */
166         if (epbuf.expire_mode == EXPIRE_AGE) {
167                 for (a=0; a<num_msgs; ++a) {
168                         delnum = msglist[a];
169
170                         msg = CtdlFetchMessage(delnum);
171                         if (msg != NULL) {
172                                 xtime = atol(msg->cm_fields['T']);
173                                 CtdlFreeMessage(msg);
174                         } else {
175                                 xtime = 0L;
176                         }
177
178                         if ((xtime > 0L)
179                            && (now - xtime > (time_t)(epbuf.expire_value * 86400L))) {
180                                 fprintf(purgelist, "m=%ld\n", delnum);
181                                 ++messages_purged;
182                         }
183                 }
184         }
185
186         if (msglist != NULL) phree(msglist);
187 }
188
189
190 /*
191  * Second phase of message purge -- read list of msgs from temp file and
192  * delete them.
193  */
194 void DoPurgeMessages(FILE *purgelist) {
195         char roomname[ROOMNAMELEN];
196         long msgnum;
197         char buf[SIZ];
198
199         rewind(purgelist);
200         strcpy(roomname, "nonexistent room ___ ___");
201         while (fgets(buf, sizeof buf, purgelist) != NULL) {
202                 buf[strlen(buf)-1]=0;
203                 if (!strncasecmp(buf, "r=", 2)) {
204                         strcpy(roomname, &buf[2]);
205                 }
206                 if (!strncasecmp(buf, "m=", 2)) {
207                         msgnum = atol(&buf[2]);
208                         if (msgnum > 0L) {
209                                 CtdlDeleteMessages(roomname, msgnum, "");
210                         }
211                 }
212         }
213 }
214
215
216 void PurgeMessages(void) {
217         FILE *purgelist;
218
219         lprintf(CTDL_DEBUG, "PurgeMessages() called\n");
220         messages_purged = 0;
221
222         purgelist = tmpfile();
223         if (purgelist == NULL) {
224                 lprintf(CTDL_CRIT, "Can't create purgelist temp file: %s\n",
225                         strerror(errno));
226                 return;
227         }
228
229         ForEachRoom(GatherPurgeMessages, (void *)purgelist );
230         DoPurgeMessages(purgelist);
231         fclose(purgelist);
232 }
233
234
235 void AddValidUser(struct ctdluser *usbuf, void *data) {
236         struct ValidUser *vuptr;
237
238         vuptr = (struct ValidUser *)mallok(sizeof(struct ValidUser));
239         vuptr->next = ValidUserList;
240         vuptr->vu_usernum = usbuf->usernum;
241         ValidUserList = vuptr;
242 }
243
244 void AddValidRoom(struct ctdlroom *qrbuf, void *data) {
245         struct ValidRoom *vrptr;
246
247         vrptr = (struct ValidRoom *)mallok(sizeof(struct ValidRoom));
248         vrptr->next = ValidRoomList;
249         vrptr->vr_roomnum = qrbuf->QRnumber;
250         vrptr->vr_roomgen = qrbuf->QRgen;
251         ValidRoomList = vrptr;
252 }
253
254 void DoPurgeRooms(struct ctdlroom *qrbuf, void *data) {
255         time_t age, purge_secs;
256         struct PurgeList *pptr;
257         struct ValidUser *vuptr;
258         int do_purge = 0;
259
260         /* For mailbox rooms, there's only one purging rule: if the user who
261          * owns the room still exists, we keep the room; otherwise, we purge
262          * it.  Bypass any other rules.
263          */
264         if (qrbuf->QRflags & QR_MAILBOX) {
265                 /* if user not found, do_purge will be 1 */
266                 do_purge = 1;
267                 for (vuptr=ValidUserList; vuptr!=NULL; vuptr=vuptr->next) {
268                         if (vuptr->vu_usernum == atol(qrbuf->QRname)) {
269                                 do_purge = 0;
270                         }
271                 }
272         }
273         else {
274                 /* Any of these attributes render a room non-purgable */
275                 if (qrbuf->QRflags & QR_PERMANENT) return;
276                 if (qrbuf->QRflags & QR_DIRECTORY) return;
277                 if (qrbuf->QRflags & QR_NETWORK) return;
278                 if (!strcasecmp(qrbuf->QRname, SYSCONFIGROOM)) return;
279                 if (is_noneditable(qrbuf)) return;
280
281                 /* If we don't know the modification date, be safe and don't purge */
282                 if (qrbuf->QRmtime <= (time_t)0) return;
283
284                 /* If no room purge time is set, be safe and don't purge */
285                 if (config.c_roompurge < 0) return;
286
287                 /* Otherwise, check the date of last modification */
288                 age = time(NULL) - (qrbuf->QRmtime);
289                 purge_secs = (time_t)config.c_roompurge * (time_t)86400;
290                 if (purge_secs <= (time_t)0) return;
291                 lprintf(CTDL_DEBUG, "<%s> is <%ld> seconds old\n", qrbuf->QRname, (long)age);
292                 if (age > purge_secs) do_purge = 1;
293         } /* !QR_MAILBOX */
294
295         if (do_purge) {
296                 pptr = (struct PurgeList *) mallok(sizeof(struct PurgeList));
297                 pptr->next = RoomPurgeList;
298                 strcpy(pptr->name, qrbuf->QRname);
299                 RoomPurgeList = pptr;
300         }
301
302 }
303
304
305
306 int PurgeRooms(void) {
307         struct PurgeList *pptr;
308         int num_rooms_purged = 0;
309         struct ctdlroom qrbuf;
310         struct ValidUser *vuptr;
311         char *transcript = NULL;
312
313         lprintf(CTDL_DEBUG, "PurgeRooms() called\n");
314
315
316         /* Load up a table full of valid user numbers so we can delete
317          * user-owned rooms for users who no longer exist */
318         ForEachUser(AddValidUser, NULL);
319
320         /* Then cycle through the room file */
321         ForEachRoom(DoPurgeRooms, NULL);
322
323         /* Free the valid user list */
324         while (ValidUserList != NULL) {
325                 vuptr = ValidUserList->next;
326                 phree(ValidUserList);
327                 ValidUserList = vuptr;
328         }
329
330
331         transcript = mallok(SIZ);
332         strcpy(transcript, "The following rooms have been auto-purged:\n");
333
334         while (RoomPurgeList != NULL) {
335                 if (getroom(&qrbuf, RoomPurgeList->name) == 0) {
336                         transcript=reallok(transcript, strlen(transcript)+SIZ);
337                         snprintf(&transcript[strlen(transcript)], SIZ, " %s\n",
338                                 qrbuf.QRname);
339                         delete_room(&qrbuf);
340                 }
341                 pptr = RoomPurgeList->next;
342                 phree(RoomPurgeList);
343                 RoomPurgeList = pptr;
344                 ++num_rooms_purged;
345         }
346
347         if (num_rooms_purged > 0) aide_message(transcript);
348         phree(transcript);
349
350         lprintf(CTDL_DEBUG, "Purged %d rooms.\n", num_rooms_purged);
351         return(num_rooms_purged);
352 }
353
354
355 void do_user_purge(struct ctdluser *us, void *data) {
356         int purge;
357         time_t now;
358         time_t purge_time;
359         struct PurgeList *pptr;
360
361         /* stupid recovery routine to re-create missing mailboxen.
362          * don't enable this.
363         struct ctdlroom qrbuf;
364         char mailboxname[ROOMNAMELEN];
365         MailboxName(mailboxname, us, MAILROOM);
366         create_room(mailboxname, 4, "", 0, 1, 1);
367         if (getroom(&qrbuf, mailboxname) != 0) return;
368         lprintf(CTDL_DEBUG, "Got %s\n", qrbuf.QRname);
369          */
370
371
372         /* Set purge time; if the user overrides the system default, use it */
373         if (us->USuserpurge > 0) {
374                 purge_time = ((time_t)us->USuserpurge) * 86400L;
375         }
376         else {
377                 purge_time = ((time_t)config.c_userpurge) * 86400L;
378         }
379
380         /* The default rule is to not purge. */
381         purge = 0;
382
383         /* If the user hasn't called in two months, his/her account
384          * has expired, so purge the record.
385          */
386         now = time(NULL);
387         if ((now - us->lastcall) > purge_time) purge = 1;
388
389         /* If the user set his/her password to 'deleteme', he/she
390          * wishes to be deleted, so purge the record.
391          */
392         if (!strcasecmp(us->password, "deleteme")) purge = 1;
393
394         /* If the record is marked as permanent, don't purge it.
395          */
396         if (us->flags & US_PERM) purge = 0;
397
398         /* If the access level is 0, the record should already have been
399          * deleted, but maybe the user was logged in at the time or something.
400          * Delete the record now.
401          */
402         if (us->axlevel == 0) purge = 1;
403
404         /* 0 calls is impossible.  If there are 0 calls, it must
405          * be a corrupted record, so purge it.
406          */
407         if (us->timescalled == 0) purge = 1;
408
409         if (purge == 1) {
410                 pptr = (struct PurgeList *) mallok(sizeof(struct PurgeList));
411                 pptr->next = UserPurgeList;
412                 strcpy(pptr->name, us->fullname);
413                 UserPurgeList = pptr;
414         }
415
416 }
417
418
419
420 int PurgeUsers(void) {
421         struct PurgeList *pptr;
422         int num_users_purged = 0;
423         char *transcript = NULL;
424
425         lprintf(CTDL_DEBUG, "PurgeUsers() called\n");
426         if (config.c_userpurge > 0) {
427                 ForEachUser(do_user_purge, NULL);
428         }
429
430         transcript = mallok(SIZ);
431         strcpy(transcript, "The following users have been auto-purged:\n");
432
433         while (UserPurgeList != NULL) {
434                 transcript=reallok(transcript, strlen(transcript)+SIZ);
435                 snprintf(&transcript[strlen(transcript)], SIZ, " %s\n",
436                         UserPurgeList->name);
437                 purge_user(UserPurgeList->name);
438                 pptr = UserPurgeList->next;
439                 phree(UserPurgeList);
440                 UserPurgeList = pptr;
441                 ++num_users_purged;
442         }
443
444         if (num_users_purged > 0) aide_message(transcript);
445         phree(transcript);
446
447         lprintf(CTDL_DEBUG, "Purged %d users.\n", num_users_purged);
448         return(num_users_purged);
449 }
450
451
452 /*
453  * Purge visits
454  *
455  * This is a really cumbersome "garbage collection" function.  We have to
456  * delete visits which refer to rooms and/or users which no longer exist.  In
457  * order to prevent endless traversals of the room and user files, we first
458  * build linked lists of rooms and users which _do_ exist on the system, then
459  * traverse the visit file, checking each record against those two lists and
460  * purging the ones that do not have a match on _both_ lists.  (Remember, if
461  * either the room or user being referred to is no longer on the system, the
462  * record is completely useless.)
463  */
464 int PurgeVisits(void) {
465         struct cdbdata *cdbvisit;
466         struct visit vbuf;
467         struct VPurgeList *VisitPurgeList = NULL;
468         struct VPurgeList *vptr;
469         int purged = 0;
470         char IndexBuf[32];
471         int IndexLen;
472         struct ValidRoom *vrptr;
473         struct ValidUser *vuptr;
474         int RoomIsValid, UserIsValid;
475
476         /* First, load up a table full of valid room/gen combinations */
477         ForEachRoom(AddValidRoom, NULL);
478
479         /* Then load up a table full of valid user numbers */
480         ForEachUser(AddValidUser, NULL);
481
482         /* Now traverse through the visits, purging irrelevant records... */
483         cdb_rewind(CDB_VISIT);
484         while(cdbvisit = cdb_next_item(CDB_VISIT), cdbvisit != NULL) {
485                 memset(&vbuf, 0, sizeof(struct visit));
486                 memcpy(&vbuf, cdbvisit->ptr,
487                         ( (cdbvisit->len > sizeof(struct visit)) ?
488                         sizeof(struct visit) : cdbvisit->len) );
489                 cdb_free(cdbvisit);
490
491                 RoomIsValid = 0;
492                 UserIsValid = 0;
493
494                 /* Check to see if the room exists */
495                 for (vrptr=ValidRoomList; vrptr!=NULL; vrptr=vrptr->next) {
496                         if ( (vrptr->vr_roomnum==vbuf.v_roomnum)
497                              && (vrptr->vr_roomgen==vbuf.v_roomgen))
498                                 RoomIsValid = 1;
499                 }
500
501                 /* Check to see if the user exists */
502                 for (vuptr=ValidUserList; vuptr!=NULL; vuptr=vuptr->next) {
503                         if (vuptr->vu_usernum == vbuf.v_usernum)
504                                 UserIsValid = 1;
505                 }
506
507                 /* Put the record on the purge list if it's dead */
508                 if ((RoomIsValid==0) || (UserIsValid==0)) {
509                         vptr = (struct VPurgeList *)
510                                 mallok(sizeof(struct VPurgeList));
511                         vptr->next = VisitPurgeList;
512                         vptr->vp_roomnum = vbuf.v_roomnum;
513                         vptr->vp_roomgen = vbuf.v_roomgen;
514                         vptr->vp_usernum = vbuf.v_usernum;
515                         VisitPurgeList = vptr;
516                 }
517
518         }
519
520         /* Free the valid room/gen combination list */
521         while (ValidRoomList != NULL) {
522                 vrptr = ValidRoomList->next;
523                 phree(ValidRoomList);
524                 ValidRoomList = vrptr;
525         }
526
527         /* Free the valid user list */
528         while (ValidUserList != NULL) {
529                 vuptr = ValidUserList->next;
530                 phree(ValidUserList);
531                 ValidUserList = vuptr;
532         }
533
534         /* Now delete every visit on the purged list */
535         while (VisitPurgeList != NULL) {
536                 IndexLen = GenerateRelationshipIndex(IndexBuf,
537                                 VisitPurgeList->vp_roomnum,
538                                 VisitPurgeList->vp_roomgen,
539                                 VisitPurgeList->vp_usernum);
540                 cdb_delete(CDB_VISIT, IndexBuf, IndexLen);
541                 vptr = VisitPurgeList->next;
542                 phree(VisitPurgeList);
543                 VisitPurgeList = vptr;
544                 ++purged;
545         }
546
547         return(purged);
548 }
549
550 /*
551  * Purge the use table of old entries.
552  *
553  */
554 int PurgeUseTable(void) {
555         int purged = 0;
556         struct cdbdata *cdbut;
557         struct UseTable ut;
558         struct UPurgeList *ul = NULL;
559         struct UPurgeList *uptr; 
560
561         /* Phase 1: traverse through the table, discovering old records... */
562         lprintf(CTDL_DEBUG, "Purge use table: phase 1\n");
563         cdb_rewind(CDB_USETABLE);
564         while(cdbut = cdb_next_item(CDB_USETABLE), cdbut != NULL) {
565
566                 memcpy(&ut, cdbut->ptr,
567                        ((cdbut->len > sizeof(struct UseTable)) ?
568                         sizeof(struct UseTable) : cdbut->len));
569                 cdb_free(cdbut);
570
571                 if ( (time(NULL) - ut.ut_timestamp) > USETABLE_RETAIN ) {
572                         uptr = (struct UPurgeList *) mallok(sizeof(struct UPurgeList));
573                         if (uptr != NULL) {
574                                 uptr->next = ul;
575                                 safestrncpy(uptr->up_key, ut.ut_msgid, SIZ);
576                                 ul = uptr;
577                         }
578                         ++purged;
579                 }
580
581         }
582
583         /* Phase 2: delete the records */
584         lprintf(CTDL_DEBUG, "Purge use table: phase 2\n");
585         while (ul != NULL) {
586                 cdb_delete(CDB_USETABLE, ul->up_key, strlen(ul->up_key));
587                 uptr = ul->next;
588                 phree(ul);
589                 ul = uptr;
590         }
591
592         lprintf(CTDL_DEBUG, "Purge use table: finished (purged %d records)\n", purged);
593         return(purged);
594 }
595
596
597 void purge_databases(void) {
598         int retval;
599         static time_t last_purge = 0;
600         time_t now;
601         struct tm tm;
602
603         /* Do the auto-purge if the current hour equals the purge hour,
604          * but not if the operation has already been performed in the
605          * last twelve hours.  This is usually enough granularity.
606          */
607         now = time(NULL);
608         memcpy(&tm, localtime(&now), sizeof(struct tm));
609         if (tm.tm_hour != config.c_purge_hour) return;
610         if ((now - last_purge) < 43200) return;
611
612         lprintf(CTDL_INFO, "Auto-purger: starting.\n");
613
614         retval = PurgeUsers();
615         lprintf(CTDL_NOTICE, "Purged %d users.\n", retval);
616
617         PurgeMessages();
618         lprintf(CTDL_NOTICE, "Expired %d messages.\n", messages_purged);
619
620         retval = PurgeRooms();
621         lprintf(CTDL_NOTICE, "Expired %d rooms.\n", retval);
622
623         retval = PurgeVisits();
624         lprintf(CTDL_NOTICE, "Purged %d visits.\n", retval);
625
626         retval = PurgeUseTable();
627         lprintf(CTDL_NOTICE, "Purged %d entries from the use table.\n", retval);
628
629         lprintf(CTDL_INFO, "Auto-purger: finished.\n");
630
631         last_purge = now;       /* So we don't do it again soon */
632 }
633
634 /*****************************************************************************/
635
636
637 void do_fsck_msg(long msgnum, void *userdata) {
638         struct ctdlroomref *ptr;
639
640         ptr = (struct ctdlroomref *)mallok(sizeof(struct ctdlroomref));
641         ptr->next = rr;
642         ptr->msgnum = msgnum;
643         rr = ptr;
644 }
645
646 void do_fsck_room(struct ctdlroom *qrbuf, void *data)
647 {
648         getroom(&CC->room, qrbuf->QRname);
649         CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, do_fsck_msg, NULL);
650 }
651
652 /*
653  * Check message reference counts
654  */
655 void cmd_fsck(char *argbuf) {
656         long msgnum;
657         struct cdbdata *cdbmsg;
658         struct MetaData smi;
659         struct ctdlroomref *ptr;
660         int realcount;
661
662         if (CtdlAccessCheck(ac_aide)) return;
663
664         /* Lame way of checking whether anyone else is doing this now */
665         if (rr != NULL) {
666                 cprintf("%d Another FSCK is already running.\n", ERROR + RESOURCE_BUSY);
667                 return;
668         }
669
670         cprintf("%d Checking message reference counts\n", LISTING_FOLLOWS);
671
672         cprintf("\nThis could take a while.  Please be patient!\n\n");
673         cprintf("Gathering pointers...\n");
674         ForEachRoom(do_fsck_room, NULL);
675
676         get_control();
677         cprintf("Checking message base...\n");
678         for (msgnum = 0L; msgnum <= CitControl.MMhighest; ++msgnum) {
679
680                 cdbmsg = cdb_fetch(CDB_MSGMAIN, &msgnum, sizeof(long));
681                 if (cdbmsg != NULL) {
682                         cdb_free(cdbmsg);
683                         cprintf("Message %7ld    ", msgnum);
684
685                         GetMetaData(&smi, msgnum);
686                         cprintf("refcount=%-2d   ", smi.meta_refcount);
687
688                         realcount = 0;
689                         for (ptr = rr; ptr != NULL; ptr = ptr->next) {
690                                 if (ptr->msgnum == msgnum) ++realcount;
691                         }
692                         cprintf("realcount=%-2d\n", realcount);
693
694                         if ( (smi.meta_refcount != realcount)
695                            || (realcount == 0) ) {
696                                 smi.meta_refcount = realcount;
697                                 PutMetaData(&smi);
698                                 AdjRefCount(msgnum, 0); /* deletes if needed */
699                         }
700
701                 }
702
703         }
704
705         cprintf("Freeing memory...\n");
706         while (rr != NULL) {
707                 ptr = rr->next;
708                 phree(rr);
709                 rr = ptr;
710         }
711
712         cprintf("Done!\n");
713         cprintf("000\n");
714
715 }
716
717
718
719
720 /*****************************************************************************/
721
722 char *serv_expire_init(void)
723 {
724         CtdlRegisterSessionHook(purge_databases, EVT_TIMER);
725         CtdlRegisterProtoHook(cmd_fsck, "FSCK", "Check message ref counts");
726         return "$Id$";
727 }