2011-12-24 13:40:27 +01:00
|
|
|
/*
|
|
|
|
* ngIRCd -- The Next Generation IRC Daemon
|
2014-03-16 20:07:08 +01:00
|
|
|
* Copyright (c)2001-2014 Alexander Barton (alex@barton.de) and Contributors.
|
2011-12-24 13:40:27 +01:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
* Please read the file COPYING, README and AUTHORS for more information.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portab.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* User class management.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2014-03-17 02:28:39 +01:00
|
|
|
#include <stdio.h>
|
2011-12-24 13:40:27 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "conn.h"
|
|
|
|
#include "lists.h"
|
|
|
|
|
|
|
|
#include "class.h"
|
|
|
|
|
|
|
|
struct list_head My_Classes[CLASS_COUNT];
|
|
|
|
|
|
|
|
GLOBAL void
|
|
|
|
Class_Init(void)
|
|
|
|
{
|
|
|
|
memset(My_Classes, 0, sizeof(My_Classes));
|
|
|
|
}
|
|
|
|
|
|
|
|
GLOBAL void
|
|
|
|
Class_Exit(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < CLASS_COUNT; Lists_Free(&My_Classes[i++]));
|
|
|
|
}
|
|
|
|
|
2013-04-20 00:51:42 +02:00
|
|
|
GLOBAL bool
|
|
|
|
Class_GetMemberReason(const int Class, CLIENT *Client, char *reason, size_t len)
|
2011-12-24 13:40:27 +01:00
|
|
|
{
|
2014-03-16 20:07:08 +01:00
|
|
|
char str[COMMAND_LEN];
|
2012-01-22 18:33:45 +01:00
|
|
|
|
2011-12-24 13:40:27 +01:00
|
|
|
assert(Class < CLASS_COUNT);
|
|
|
|
assert(Client != NULL);
|
|
|
|
|
2014-03-16 20:07:08 +01:00
|
|
|
strlcpy(str, "listed", sizeof(str));
|
|
|
|
|
2013-04-20 00:51:42 +02:00
|
|
|
if (!Lists_CheckReason(&My_Classes[Class], Client, str, sizeof(str)))
|
|
|
|
return false;
|
2012-01-22 18:33:45 +01:00
|
|
|
|
|
|
|
switch(Class) {
|
|
|
|
case CLASS_GLINE:
|
2013-04-20 00:51:42 +02:00
|
|
|
snprintf(reason, len, "\"%s\" (G-Line)", str);
|
|
|
|
break;
|
2012-01-22 18:33:45 +01:00
|
|
|
case CLASS_KLINE:
|
2013-04-20 00:51:42 +02:00
|
|
|
snprintf(reason, len, "\"%s\" (K-Line)", str);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
snprintf(reason, len, "%s", str);
|
|
|
|
break;
|
2012-01-22 18:33:45 +01:00
|
|
|
}
|
2013-04-20 00:51:42 +02:00
|
|
|
return true;
|
2012-01-22 18:33:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2013-04-20 00:51:42 +02:00
|
|
|
char reject[COMMAND_LEN];
|
2012-01-22 18:33:45 +01:00
|
|
|
|
|
|
|
assert(Client != NULL);
|
|
|
|
|
2013-04-20 00:51:42 +02:00
|
|
|
if (Class_GetMemberReason(CLASS_GLINE, Client, reject, sizeof(reject)) ||
|
|
|
|
Class_GetMemberReason(CLASS_KLINE, Client, reject, sizeof(reject))) {
|
|
|
|
Client_Reject(Client, reject, true);
|
2012-01-22 18:33:45 +01:00
|
|
|
return DISCONNECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CONNECTED;
|
2011-12-24 13:40:27 +01:00
|
|
|
}
|
|
|
|
|
2012-01-22 18:33:45 +01:00
|
|
|
|
2011-12-24 13:40:27 +01:00
|
|
|
GLOBAL bool
|
2013-04-20 01:19:03 +02:00
|
|
|
Class_AddMask(const int Class, const char *Pattern, time_t ValidUntil,
|
2011-12-25 14:19:45 +01:00
|
|
|
const char *Reason)
|
2011-12-24 13:40:27 +01:00
|
|
|
{
|
2013-04-20 01:19:03 +02:00
|
|
|
char mask[MASK_LEN];
|
|
|
|
|
2011-12-24 13:40:27 +01:00
|
|
|
assert(Class < CLASS_COUNT);
|
2013-04-21 15:57:51 +02:00
|
|
|
assert(Pattern != NULL);
|
2011-12-25 14:19:45 +01:00
|
|
|
assert(Reason != NULL);
|
2011-12-24 13:40:27 +01:00
|
|
|
|
2013-04-20 01:19:03 +02:00
|
|
|
Lists_MakeMask(Pattern, mask, sizeof(mask));
|
|
|
|
return Lists_Add(&My_Classes[Class], mask,
|
2015-05-13 22:08:26 +02:00
|
|
|
ValidUntil, Reason, false);
|
2011-12-24 13:40:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GLOBAL void
|
2013-04-20 01:19:03 +02:00
|
|
|
Class_DeleteMask(const int Class, const char *Pattern)
|
2011-12-24 13:40:27 +01:00
|
|
|
{
|
2013-04-20 01:19:03 +02:00
|
|
|
char mask[MASK_LEN];
|
|
|
|
|
2011-12-24 13:40:27 +01:00
|
|
|
assert(Class < CLASS_COUNT);
|
2013-04-21 15:57:51 +02:00
|
|
|
assert(Pattern != NULL);
|
2011-12-24 13:40:27 +01:00
|
|
|
|
2013-04-20 01:19:03 +02:00
|
|
|
Lists_MakeMask(Pattern, mask, sizeof(mask));
|
|
|
|
Lists_Del(&My_Classes[Class], mask);
|
2011-12-24 13:40:27 +01:00
|
|
|
}
|
|
|
|
|
2011-12-25 19:11:07 +01:00
|
|
|
GLOBAL struct list_head *
|
2011-12-25 14:49:52 +01:00
|
|
|
Class_GetList(const int Class)
|
|
|
|
{
|
|
|
|
assert(Class < CLASS_COUNT);
|
|
|
|
|
2011-12-25 19:11:07 +01:00
|
|
|
return &My_Classes[Class];
|
2011-12-25 14:49:52 +01:00
|
|
|
}
|
|
|
|
|
2011-12-25 17:44:20 +01:00
|
|
|
GLOBAL void
|
|
|
|
Class_Expire(void)
|
|
|
|
{
|
|
|
|
Lists_Expire(&My_Classes[CLASS_GLINE], "G-Line");
|
|
|
|
Lists_Expire(&My_Classes[CLASS_KLINE], "K-Line");
|
|
|
|
}
|
|
|
|
|
2011-12-24 13:40:27 +01:00
|
|
|
/* -eof- */
|