X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Fclass.c;h=0f617b8213d1ff3fe56a5cbf9babf58265080df9;hp=ee034f2873869f47f3f1be493372d1d19f2dde58;hb=808c291c76b7ecb4ae13b6ee12e8afe658b627c1;hpb=06a20b87c464c67b288daf8bff841ce21e9105f3 diff --git a/src/ngircd/class.c b/src/ngircd/class.c index ee034f28..0f617b82 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-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,12 +26,15 @@ #include "client.h" #include "lists.h" #include "match.h" +#include "stdio.h" #include "exp.h" #include "class.h" struct list_head My_Classes[CLASS_COUNT]; +char Reject_Reason[COMMAND_LEN]; + GLOBAL void Class_Init(void) { @@ -46,22 +49,71 @@ Class_Exit(void) for (i = 0; i < CLASS_COUNT; Lists_Free(&My_Classes[i++])); } -GLOBAL bool -Class_IsMember(const int Class, CLIENT *Client) +GLOBAL char * +Class_GetMemberReason(const int Class, CLIENT *Client) { + char *reason; + assert(Class < CLASS_COUNT); assert(Client != NULL); - return Lists_Check(&My_Classes[Class], Client); + reason = Lists_CheckReason(&My_Classes[Class], Client); + if (!reason) + return NULL; + + if (!*reason) + reason = "listed"; + + switch(Class) { + case CLASS_GLINE: + snprintf(Reject_Reason, sizeof(Reject_Reason), + "\"%s\" (G-Line)", reason); + return Reject_Reason; + case CLASS_KLINE: + snprintf(Reject_Reason, sizeof(Reject_Reason), + "\"%s\" (K-Line)", reason); + return Reject_Reason; + } + return reason; } +/** + * 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 *rejectptr; + + assert(Client != NULL); + + rejectptr = Class_GetMemberReason(CLASS_GLINE, Client); + if (!rejectptr) + rejectptr = Class_GetMemberReason(CLASS_KLINE, Client); + if (rejectptr) { + Client_Reject(Client, rejectptr, true); + return DISCONNECTED; + } + + return CONNECTED; +} + + +GLOBAL bool +Class_AddMask(const int Class, const char *Mask, time_t ValidUntil, + const char *Reason) { assert(Class < CLASS_COUNT); assert(Mask != NULL); + assert(Reason != NULL); - return Lists_Add(&My_Classes[Class], Mask, ValidUntil); + return Lists_Add(&My_Classes[Class], Lists_MakeMask(Mask), + ValidUntil, Reason); } GLOBAL void @@ -70,7 +122,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 * +Class_GetList(const int Class) +{ + assert(Class < CLASS_COUNT); + + 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- */