-void *purge_databases(void *args)
-{
- int retval;
- static time_t last_purge = 0;
- time_t now;
- struct tm tm;
- struct CitContext purgerCC;
-
- lprintf(CTDL_DEBUG, "Auto-purger_thread() initializing\n");
-
- memset(&purgerCC, 0, sizeof(struct CitContext));
- purgerCC.internal_pgm = 1;
- purgerCC.cs_pid = 0;
- pthread_setspecific(MyConKey, (void *)&purgerCC );
-
- while (!CtdlThreadCheckStop()) {
- /* Do the auto-purge if the current hour equals the purge hour,
- * but not if the operation has already been performed in the
- * last twelve hours. This is usually enough granularity.
- */
- now = time(NULL);
- localtime_r(&now, &tm);
- if ((tm.tm_hour != config.c_purge_hour) || ((now - last_purge) < 43200)) {
- CtdlThreadSleep(60);
- continue;
- }
-
-
- lprintf(CTDL_INFO, "Auto-purger: starting.\n");
-
- if (!CtdlThreadCheckStop())
- {
- retval = PurgeUsers();
- lprintf(CTDL_NOTICE, "Purged %d users.\n", retval);
- }
-
- if (!CtdlThreadCheckStop())
- {
- PurgeMessages();
- lprintf(CTDL_NOTICE, "Expired %d messages.\n", messages_purged);
- }
-
- if (!CtdlThreadCheckStop())
- {
- retval = PurgeRooms();
- lprintf(CTDL_NOTICE, "Expired %d rooms.\n", retval);
- }
-
- if (!CtdlThreadCheckStop())
- {
- retval = PurgeVisits();
- lprintf(CTDL_NOTICE, "Purged %d visits.\n", retval);
- }
-
- if (!CtdlThreadCheckStop())
- {
- retval = PurgeUseTable();
- lprintf(CTDL_NOTICE, "Purged %d entries from the use table.\n", retval);
- }
-
- if (!CtdlThreadCheckStop())
- {
- retval = PurgeEuidIndexTable();
- lprintf(CTDL_NOTICE, "Purged %d entries from the EUID index.\n", retval);
- }
-
- if (!CtdlThreadCheckStop())
- {
- retval = TDAP_ProcessAdjRefCountQueue();
- lprintf(CTDL_NOTICE, "Processed %d message reference count adjustments.\n", retval);
+/*
+ * Purge external auth assocations for missing users (theoretically this will never delete anything)
+ */
+int PurgeStaleExtAuthAssociations(void) {
+ struct cdbdata *cdboi;
+ struct ctdluser usbuf;
+ HashList *keys = NULL;
+ HashPos *HashPos;
+ char *deleteme = NULL;
+ long len;
+ void *Value;
+ const char *Key;
+ int num_deleted = 0;
+ long usernum = 0L;
+
+ keys = NewHash(1, NULL);
+ if (!keys) return(0);
+
+
+ cdb_rewind(CDB_EXTAUTH);
+ while (cdboi = cdb_next_item(CDB_EXTAUTH), cdboi != NULL) {
+ if (cdboi->len > sizeof(long)) {
+ memcpy(&usernum, cdboi->ptr, sizeof(long));
+ if (CtdlGetUserByNumber(&usbuf, usernum) != 0) {
+ deleteme = strdup(cdboi->ptr + sizeof(long)),
+ Put(keys, deleteme, strlen(deleteme), deleteme, NULL);
+ }