]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/class.c
Fix use-after-free on Lists_CheckReason()
[ngircd-alex.git] / src / ngircd / class.c
index dd10ac81021fb0e80fd8336a67b4ecddf329ad89..800e99353647f8758488a30db2d8f41259dc1129 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2011 Alexander Barton (alex@barton.de) and Contributors.
+ * Copyright (c)2001-2012 Alexander Barton (alex@barton.de) and Contributors.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -26,6 +26,7 @@
 #include "client.h"
 #include "lists.h"
 #include "match.h"
+#include "stdio.h"
 
 #include "exp.h"
 #include "class.h"
@@ -47,14 +48,55 @@ Class_Exit(void)
 }
 
 GLOBAL bool
-Class_IsMember(const int Class, CLIENT *Client)
+Class_GetMemberReason(const int Class, CLIENT *Client, char *reason, size_t len)
 {
+       char str[COMMAND_LEN] = "listed";
+
        assert(Class < CLASS_COUNT);
        assert(Client != NULL);
 
-       return Lists_Check(&My_Classes[Class], Client);
+       if (!Lists_CheckReason(&My_Classes[Class], Client, str, sizeof(str)))
+               return false;
+
+       switch(Class) {
+               case CLASS_GLINE:
+                       snprintf(reason, len, "\"%s\" (G-Line)", str);
+                       break;
+               case CLASS_KLINE:
+                       snprintf(reason, len, "\"%s\" (K-Line)", str);
+                       break;
+               default:
+                       snprintf(reason, len, "%s", str);
+                       break;
+       }
+       return true;
+}
+
+/**
+ * Check if a client is banned from this server: GLINE, KLINE.
+ *
+ * If a client isn't allowed to connect, it will be disconnected again.
+ *
+ * @param Client The client to check.
+ * @return CONNECTED if client is allowed to join, DISCONNECTED if not.
+ */
+GLOBAL bool
+Class_HandleServerBans(CLIENT *Client)
+{
+       char reject[COMMAND_LEN];
+
+       assert(Client != NULL);
+
+       if (Class_GetMemberReason(CLASS_GLINE, Client, reject, sizeof(reject)) ||
+           Class_GetMemberReason(CLASS_KLINE, Client, reject, sizeof(reject))) {
+               Client_Reject(Client, reject, true);
+               return DISCONNECTED;
+       }
+
+       return CONNECTED;
 }
 
+
 GLOBAL bool
 Class_AddMask(const int Class, const char *Mask, time_t ValidUntil,
              const char *Reason)
@@ -63,7 +105,8 @@ Class_AddMask(const int Class, const char *Mask, time_t ValidUntil,
        assert(Mask != NULL);
        assert(Reason != NULL);
 
-       return Lists_Add(&My_Classes[Class], Mask, ValidUntil, Reason);
+       return Lists_Add(&My_Classes[Class], Lists_MakeMask(Mask),
+                        ValidUntil, Reason);
 }
 
 GLOBAL void
@@ -72,15 +115,22 @@ Class_DeleteMask(const int Class, const char *Mask)
        assert(Class < CLASS_COUNT);
        assert(Mask != NULL);
 
-       Lists_Del(&My_Classes[Class], Mask);
+       Lists_Del(&My_Classes[Class], Lists_MakeMask(Mask));
 }
 
-GLOBAL struct list_head
+GLOBAL struct list_head *
 Class_GetList(const int Class)
 {
        assert(Class < CLASS_COUNT);
 
-       return My_Classes[Class];
+       return &My_Classes[Class];
+}
+
+GLOBAL void
+Class_Expire(void)
+{
+       Lists_Expire(&My_Classes[CLASS_GLINE], "G-Line");
+       Lists_Expire(&My_Classes[CLASS_KLINE], "K-Line");
 }
 
 /* -eof- */