402b8483e517af1d9dfbeb5fe03787011f0a666b
[citadel.git] / citadel / userpurge.c
1 /*
2  * userpurge.c
3  *
4  * This program is a server extension which purges the user file of any user
5  * who has not logged in for a period of time, or who has elected to delete
6  * their account by setting their password to "deleteme".
7  */
8
9 /* PURGE_TIME is the amount of time (in seconds) for which a user must not
10  * have logged in for his/her account to be purged.
11  */
12 #define PURGE_TIME (5184000L) /* two months */
13
14 #include <stdlib.h>
15 #include <unistd.h>
16 #include <stdio.h>
17 #include <time.h>
18 #include <ctype.h>
19 #include <string.h>
20 #include <errno.h>
21 #include "citadel.h"
22
23 void do_user_purge(struct usersupp *us) {
24         int purge;
25         time_t now;
26
27         /* The default rule is to not purge. */
28         purge = 0;
29
30         /* If the user hasn't called in two months, his/her account
31          * has expired, so purge the record.
32          */
33         now = time(NULL);
34         if ((now - us->lastcall) > PURGE_TIME) purge = 1;
35
36         /* If the user set his/her password to 'deleteme', he/she
37          * wishes to be deleted, so purge the record.
38          */
39         if (!strcasecmp(us->password, "deleteme")) purge = 1;
40
41         /* If the record is marked as permanent, don't purge it.
42          */
43         if (us->flags & US_PERM) purge = 0;
44
45         /* If the access level is 0, the record should already have been
46          * deleted, but maybe the user was logged in at the time or something.
47          * Delete the record now.
48          */
49         if (us->axlevel == 0) purge = 1;
50
51         /* 0 calls is impossible.  If there are 0 calls, it must
52          * be a corrupted record, so purge it.
53          */
54         if (us->timescalled == 0) purge = 1;
55
56         if (purge == 1) {
57                 /* do the delete call */
58                 }
59
60
61         }
62
63
64 void MyReallyCoolModuleEntryPoint() {
65         ForEachUser(do_user_purge);
66         }