]> jfr.im git - irc/quakenet/newserv.git/commitdiff
CHANSERV: more checks on lastchannelID / lastuserID
authorChris Porter <redacted>
Sun, 24 Jan 2016 16:02:39 +0000 (16:02 +0000)
committerChris Porter <redacted>
Sun, 24 Jan 2016 16:02:39 +0000 (16:02 +0000)
chanserv/chancmds/delchan.c
chanserv/chanserv_cleanupdb.c
chanserv/chanservuser.c
chanserv/usercmds/deluser.c

index aa661f71a5124807d90963cb2175d6a63bfeef1d..87c58881e5d798dc0184ec1b4808335bb69e47ef 100644 (file)
@@ -41,6 +41,11 @@ int csc_dodelchan(void *source, int cargc, char **cargv) {
     return CMD_ERROR;
   }
 
+  if (rcp->ID == lastchannelID) {
+    chanservsendmessage(sender, "Sorry, can't delete last channel -- wait a while and try again.");
+    return CMD_ERROR;
+  }
+
   cs_log(sender,"DELCHAN %s (%s)",cip->name->content,cargc>1?cargv[1]:"");
   cs_removechannel(rcp, "Channel deleted.");
   chanservstdmessage(sender, QM_DONE);
index 3dd3131cba88494e5aa5f20d6a9e9f4899624f1a..fb141f27a57bee3a2ff4c1f76d29d895ad8608fa 100644 (file)
@@ -53,7 +53,7 @@ static void cleanupdb_real(DBConn *dbconn, void *arg) {
   authname *anp;
   int i,j;
   time_t t, to_age, unused_age, maxchan_age, authhistory_age;
-  int expired = 0, unauthed = 0, chansvaped = 0;
+  int expired = 0, unauthed = 0, chansvaped = 0, chansempty = 0;
   chanindex *cip, *ncip;
   regchan *rcp;
   DBResult *pgres;
@@ -172,8 +172,14 @@ static void cleanupdb_real(DBConn *dbconn, void *arg) {
             cs_log(NULL, "Removing user %s from channel %s (no flags)",rcup->user->username,rcp->index->name->content);
             csdb_deletechanuser(rcup);
             delreguserfromchannel(rcp, rcup->user);
+            freeregchanuser(rcup);
           }
         }
+
+        if (cs_removechannelifempty(NULL, rcp)) {
+          /* logged+parted by cs_removechannelifempty */
+          chansempty++;
+        }
       }
     }
   }
@@ -182,7 +188,7 @@ static void cleanupdb_real(DBConn *dbconn, void *arg) {
     
   csdb_cleanuphistories(authhistory_age);
   
-  cleanuplog("Stats: %d accounts inactive for %d days, %d accounts weren't used within %d days, %d channels were inactive for %d days.", expired, CLEANUP_ACCOUNT_INACTIVE, unauthed, CLEANUP_ACCOUNT_UNUSED, chansvaped, CLEANUP_CHANNEL_INACTIVE);
+  cleanuplog("Stats: %d accounts inactive for %d days, %d accounts weren't used within %d days, %d channels were inactive for %d days, %d channels empty.", expired, CLEANUP_ACCOUNT_INACTIVE, unauthed, CLEANUP_ACCOUNT_UNUSED, chansvaped, CLEANUP_CHANNEL_INACTIVE, chansempty);
 
 out:
   cleanupdb_active=0;
index 47f432a04ab4d59f63cfb080ec28e94bb23dc35d..0428050082ac734a2cb7debc510c15c8ed498114 100644 (file)
@@ -1131,7 +1131,16 @@ int cs_removechannelifempty(nick *sender, regchan *rcp) {
         return 0;
     }
   }
-  
+
+  /*
+   * don't cleanup the last channel to prevent channel id reuse.
+   * the channel will be orphaned but will be cleaned up by cleanup eventually
+   */
+  if(rcp->ID == lastchannelID) {
+    cs_log(sender,"DELCHAN FAILED %s (last id)",rcp->index->name->content);
+    return 0;
+  }
+
   cs_log(sender,"DELCHAN %s (Empty)",rcp->index->name->content);
   cs_removechannel(rcp, "Last user removed - channel deleted.");
   
index 735f701fd1d571455bd600752239872e562bc2b8..d6f6595e9c89d8bfd42e04819b64f2eb748f8c79 100644 (file)
@@ -36,7 +36,12 @@ int csu_dodeluser(void *source, int cargc, char **cargv) {
 
   if (!(target=findreguser(sender, cargv[0])))
     return CMD_ERROR;
-  
+
+  if(target->ID == lastuserID) {
+    chanservsendmessage(sender, "Sorry, can't delete last user -- wait a while and try again.");
+    return CMD_ERROR;
+  }
+
   if(UHasStaffPriv(target)) {
     cs_log(sender,"DELUSER FAILED username %s (reason: %s)",target->username,reason);
     chanservwallmessage("%s (%s) just FAILED using DELUSER on %s (reason: %s)", sender->nick, rup->username, target->username, reason);