]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/expire/serv_expire.c
* Discovered that my system hasn't processed its refcount_adjustments queue in about...
[citadel.git] / citadel / modules / expire / serv_expire.c
index cd30915dc610fc3c0f91123b467bf4224aa043a3..4d384a56cefc2356b46b4adecafeb1d95d4851a9 100644 (file)
@@ -121,10 +121,9 @@ int messages_purged;
 int users_not_purged;
 char *users_corrupt_msg = NULL;
 char *users_zero_msg = NULL;
-
 struct ctdlroomref *rr = NULL;
-
 extern struct CitContext *ContextList;
+int force_purge_now = 0;                       /* set to nonzero to force a run right now */
 
 
 /*
@@ -152,6 +151,10 @@ void GatherPurgeMessages(struct ctdlroom *qrbuf, void *data) {
        if (epbuf.expire_mode == EXPIRE_NEXTLEVEL) return;
        if (epbuf.expire_mode == EXPIRE_MANUAL) return;
 
+       /* Don't purge messages containing system configuration, dumbass. */
+       if (!strcasecmp(qrbuf->QRname, SYSCONFIGROOM)) return;
+
+       /* Ok, we got this far ... now let's see what's in the room */
         cdbfr = cdb_fetch(CDB_MSGLISTS, &qrbuf->QRnumber, sizeof(long));
 
         if (cdbfr != NULL) {
@@ -167,6 +170,7 @@ void GatherPurgeMessages(struct ctdlroom *qrbuf, void *data) {
                return;
        }
 
+
        /* If the room is set to expire by count, do that */
        if (epbuf.expire_mode == EXPIRE_NUMMSGS) {
                if (num_msgs > epbuf.expire_value) {
@@ -290,6 +294,7 @@ void DoPurgeRooms(struct ctdlroom *qrbuf, void *data) {
                if (qrbuf->QRflags & QR_PERMANENT) return;
                if (qrbuf->QRflags & QR_DIRECTORY) return;
                if (qrbuf->QRflags & QR_NETWORK) return;
+               if (qrbuf->QRflags2 & QR2_SYSTEM) return;
                if (!strcasecmp(qrbuf->QRname, SYSCONFIGROOM)) return;
                if (is_noneditable(qrbuf)) return;
 
@@ -446,21 +451,31 @@ void do_user_purge(struct ctdluser *us, void *data) {
         */
        if (us->timescalled < 0) purge = 1;
 
-       /* User number 0, as well as any negative user number, is
+       /* any negative user number, is
         * also impossible.
         */
        if (us->usernum < 0L) purge = 1;
        
        /** Don't purge user 0. That user is there for the system */
-       if (us->usernum == 0) purge = 0;
+       if (us->usernum == 0L)
+       {
+               /* FIXME: Temporary log message. Until we do unauth access with user 0 we should
+                * try to get rid of all user 0 occurences. Many will be remnants from old code so
+                * we will need to try and purge them from users data bases.Some will not have names but
+                * those with names should be purged.
+                */
+               CtdlLogPrintf(CTDL_DEBUG, "Auto purger found a user 0 with name \"%s\"\n", us->fullname);
+               // purge = 0;
+       }
        
        /* If the user has no full name entry then we can't purge them
         * since the actual purge can't find them.
         * This shouldn't happen but does somehow.
-        * So we make an Aide message to alert to it but don't add it to the purge list
         */
        if (IsEmptyStr(us->fullname))
        {
+               purge = 0;
+               
                if (us->usernum > 0L)
                {
                        purge=0;
@@ -468,40 +483,15 @@ void do_user_purge(struct ctdluser *us, void *data) {
                        {
                                users_corrupt_msg = malloc(SIZ);
                                strcpy(users_corrupt_msg, "The auto-purger found the following user numbers with no name.\n"
-                               "If the user number is 0 you should report this to the Citadel development\n"
-                               "team either by a bugzilla report at http://bugzilla.citadel.org or\n"
-                               "posting a message in the Citadel Support room on Uncensored at\n"
-                               "https://uncensored.citadel.org You should make it clear that you have seen a\n"
-                               "user 0 messages in the Aide room which means a module has not named its\n"
-                               "private context.\n"
-                               "Unfortunately the auto-purger is not yet able to fix this problem.\n"
-                               "This problem is not considered serious since a user with no name can\n"
-                               "not log in.\n");
+                               "The system has no way to purge user with no name and should not be able to\n"
+                               "create them either.\n"
+                               "This indicates corruption of the user DB or possibly a bug.\n"
+                               "It may be a good idea to restore your DB from a backup.\n");
                        }
                
-                       users_corrupt_msg=realloc(users_corrupt_msg, strlen(users_corrupt_msg)+SIZ);
-                       snprintf(&users_corrupt_msg[strlen(users_corrupt_msg)], SIZ, " %ld\n", us->usernum);
+                       users_corrupt_msg=realloc(users_corrupt_msg, strlen(users_corrupt_msg)+30);
+                       snprintf(&users_corrupt_msg[strlen(users_corrupt_msg)], 29, " %ld\n", us->usernum);
                }
-               else if (us->usernum == 0L)
-               {
-                       purge=0;
-                       if (users_zero_msg == NULL)
-                       {
-                               users_zero_msg = malloc(SIZ);
-                               strcpy(users_zero_msg, "The auto-purger found a user with a user number of 0 but no name.\n"
-                               "This is the result of a bug where a private contaxt has been created but\n"
-                               "not named.\n\n"
-                               "Please report this to the Citadel development team either by a bugzilla\n"
-                               "report at http://bugzilla.citadel.org or by posting a message in the\n"
-                               "Citadel Support room on Uncensored at https://uncensored.citadel.org\n"
-                               "You should make it clear that you have seen a user 0 messages in the\n"
-                               "Aide room which means a module has not named its private context.\n\n"
-                               "This problem is not considered serious since it does not constitute a\n"
-                               "security risk and should not impare system operation.\n"
-                               );
-                       }
-               }
-
        }
 
 
@@ -856,7 +846,7 @@ void *purge_databases(void *args)
 
        CtdlLogPrintf(CTDL_DEBUG, "Auto-purger_thread() initializing\n");
 
-       CtdlFillPrivateContext(&purgerCC, "purger");
+       CtdlFillSystemContext(&purgerCC, "purger");
        citthread_setspecific(MyConKey, (void *)&purgerCC );
 
         while (!CtdlThreadCheckStop()) {
@@ -866,7 +856,10 @@ void *purge_databases(void *args)
                  */
                 now = time(NULL);
                 localtime_r(&now, &tm);
-                if ((tm.tm_hour != config.c_purge_hour) || ((now - last_purge) < 43200)) {
+                if (
+                       ((tm.tm_hour != config.c_purge_hour) || ((now - last_purge) < 43200))
+                       && (force_purge_now == 0)
+               ) {
                         CtdlThreadSleep(60);
                         continue;
                 }
@@ -926,6 +919,7 @@ void *purge_databases(void *args)
                {
                        CtdlLogPrintf(CTDL_INFO, "Auto-purger: finished.\n");
                        last_purge = now;       /* So we don't do it again soon */
+                       force_purge_now = 0;
                }
                else
                        CtdlLogPrintf(CTDL_INFO, "Auto-purger: STOPPED.\n");
@@ -1015,6 +1009,14 @@ void cmd_fsck(char *argbuf) {
 }
 
 
+/*
+ * Manually initiate a run of The Dreaded Auto-Purger (tm)
+ */
+void cmd_tdap(char *argbuf) {
+       if (CtdlAccessCheck(ac_aide)) return;
+       force_purge_now = 1;
+       cprintf("%d Manually initiating a purger run now.\n", CIT_OK);
+}
 
 
 /*****************************************************************************/
@@ -1024,6 +1026,7 @@ CTDL_MODULE_INIT(expire)
        if (!threading)
        {
                CtdlRegisterProtoHook(cmd_fsck, "FSCK", "Check message ref counts");
+               CtdlRegisterProtoHook(cmd_tdap, "TDAP", "Manually initiate auto-purger");
        }
        else
                CtdlThreadCreate("Auto Purger", CTDLTHREAD_BIGSTACK, purge_databases, NULL);