summaryrefslogtreecommitdiffstats
path: root/util/reaper.c
blob: 348224e97a6f4dc805bbe59ec1d103779a8da036 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* $Id$ */
#define _UTIL_C_
#include "bbs.h"

time4_t now;

int invalid(char *userid) {
    int i;
    
    if(!isalpha(userid[0]))
    return 1;
    
    for(i = 1; i < IDLEN && userid[i]; i++)
    if(!isalpha(userid[i]) && !isdigit(userid[i]))
        return 1;
    return 0;
}

int check(int n, userec_t *u) {
    time4_t d;
    char buf[256];
    
    if(u->userid[0] != '\0') {
    if(invalid(u->userid)) {
        syslog(LOG_ERR, "bad userid(%d): %s", n, u->userid);
        u->userid[0] = '\0';
    } else {
        d = now - u->lastlogin;
        if((d > MAX_GUEST_LIFE && (u->userlevel & PERM_LOGINOK) == 0) ||
           (d > MAX_LIFE && (u->userlevel & PERM_XEMPT) == 0)) {
        /* expired */
        int unum;
        
        unum = searchuser(u->userid, u->userid);
        strcpy(buf, ctime4(&u->lastlogin));
        syslog(LOG_NOTICE, "kill user(%d): %s %s", unum, u->userid, buf);
        sprintf(buf, "mv home/%c/%s tmp/", u->userid[0], u->userid);
        if(system(buf))
            syslog(LOG_ERR, "can't move user home: %s", u->userid);
        u->userid[0] = '\0';
        setuserid(unum, u->userid);
        }
    }
    }
    return 0;
}

int main(int argc, char **argv)
{
    now = time(NULL);
#ifdef Solaris
    openlog("reaper", LOG_PID, SYSLOG_FACILITY);
#else
    openlog("reaper", LOG_PID | LOG_PERROR, SYSLOG_FACILITY);
#endif
    chdir(BBSHOME);

    attach_SHM();
    if(passwd_init())
    exit(1);
    passwd_apply(check);
    
    return 0;
}