summaryrefslogtreecommitdiffstats
path: root/util/reaper.c
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-03-07 23:13:44 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-03-07 23:13:44 +0800
commitae31e19f92e717919ac8e3db9039eb38d2b89aae (patch)
treec70164d6a1852344f44b04a653ae2815043512af /util/reaper.c
downloadpttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.gz
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.bz2
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.lz
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.xz
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.zst
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.zip
Initial revision
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@1 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'util/reaper.c')
-rw-r--r--util/reaper.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/util/reaper.c b/util/reaper.c
new file mode 100644
index 00000000..925ea11b
--- /dev/null
+++ b/util/reaper.c
@@ -0,0 +1,69 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <time.h>
+#include <syslog.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include "config.h"
+#include "pttstruct.h"
+#include "perm.h"
+#include "util.h"
+
+time_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) {
+ time_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);
+ strcpy(buf, ctime(&u->lastlogin));
+ strtok(buf, "\n");
+ 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() {
+ now = time(NULL);
+ openlog("reaper", LOG_PID | LOG_PERROR, SYSLOG_FACILITY);
+ chdir(BBSHOME);
+
+ if(passwd_mmap())
+ exit(1);
+ passwd_apply2(check);
+
+ return 0;
+}