X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Fclass.c;h=9ffa8b147471b18b8ee2a97d4914c162e21e6f44;hp=aeecaaecc7440313ca89f59b55e6fbf46a57e0c3;hb=6171beb7ab5dc0586581660852576f437470df63;hpb=af70c3dbc927c77167a26c1f4d8ed6bf2b97e3c5 diff --git a/src/ngircd/class.c b/src/ngircd/class.c index aeecaaec..9ffa8b14 100644 --- a/src/ngircd/class.c +++ b/src/ngircd/class.c @@ -1,6 +1,6 @@ /* * ngIRCd -- The Next Generation IRC Daemon - * Copyright (c)2001-2011 Alexander Barton (alex@barton.de) and Contributors. + * Copyright (c)2001-2014 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 @@ -16,18 +16,13 @@ * User class management. */ -#include "imp.h" #include +#include #include -#include "defines.h" -#include "array.h" #include "conn.h" -#include "client.h" #include "lists.h" -#include "match.h" -#include "exp.h" #include "class.h" struct list_head My_Classes[CLASS_COUNT]; @@ -47,32 +42,97 @@ 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]; + assert(Class < CLASS_COUNT); assert(Client != NULL); - return Lists_Check(&My_Classes[Class], Client); + strlcpy(str, "listed", sizeof(str)); + + 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_AddMask(const int Class, const char *Mask, time_t ValidUntil, +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 *Pattern, time_t ValidUntil, const char *Reason) { + char mask[MASK_LEN]; + assert(Class < CLASS_COUNT); - assert(Mask != NULL); + assert(Pattern != NULL); assert(Reason != NULL); - return Lists_Add(&My_Classes[Class], Mask, ValidUntil, Reason); + Lists_MakeMask(Pattern, mask, sizeof(mask)); + return Lists_Add(&My_Classes[Class], mask, + ValidUntil, Reason); } GLOBAL void -Class_DeleteMask(const int Class, const char *Mask) +Class_DeleteMask(const int Class, const char *Pattern) +{ + char mask[MASK_LEN]; + + assert(Class < CLASS_COUNT); + assert(Pattern != NULL); + + Lists_MakeMask(Pattern, mask, sizeof(mask)); + Lists_Del(&My_Classes[Class], mask); +} + +GLOBAL struct list_head * +Class_GetList(const int Class) { assert(Class < CLASS_COUNT); - assert(Mask != NULL); - Lists_Del(&My_Classes[Class], Mask); + 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- */