Only log "IDENT ... no result" when IDENT was looked up
[ngircd-alex.git] / src / ngircd / class.c
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  * Copyright (c)2001-2012 Alexander Barton (alex@barton.de) and Contributors.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * Please read the file COPYING, README and AUTHORS for more information.
10  */
11
12 #include "portab.h"
13
14 /**
15  * @file
16  * User class management.
17  */
18
19 #include "imp.h"
20 #include <assert.h>
21 #include <string.h>
22
23 #include "defines.h"
24 #include "array.h"
25 #include "conn.h"
26 #include "client.h"
27 #include "lists.h"
28 #include "match.h"
29 #include "stdio.h"
30
31 #include "exp.h"
32 #include "class.h"
33
34 struct list_head My_Classes[CLASS_COUNT];
35
36 GLOBAL void
37 Class_Init(void)
38 {
39         memset(My_Classes, 0, sizeof(My_Classes));
40 }
41
42 GLOBAL void
43 Class_Exit(void)
44 {
45         int i;
46
47         for (i = 0; i < CLASS_COUNT; Lists_Free(&My_Classes[i++]));
48 }
49
50 GLOBAL bool
51 Class_GetMemberReason(const int Class, CLIENT *Client, char *reason, size_t len)
52 {
53         char str[COMMAND_LEN] = "listed";
54
55         assert(Class < CLASS_COUNT);
56         assert(Client != NULL);
57
58         if (!Lists_CheckReason(&My_Classes[Class], Client, str, sizeof(str)))
59                 return false;
60
61         switch(Class) {
62                 case CLASS_GLINE:
63                         snprintf(reason, len, "\"%s\" (G-Line)", str);
64                         break;
65                 case CLASS_KLINE:
66                         snprintf(reason, len, "\"%s\" (K-Line)", str);
67                         break;
68                 default:
69                         snprintf(reason, len, "%s", str);
70                         break;
71         }
72         return true;
73 }
74
75 /**
76  * Check if a client is banned from this server: GLINE, KLINE.
77  *
78  * If a client isn't allowed to connect, it will be disconnected again.
79  *
80  * @param Client The client to check.
81  * @return CONNECTED if client is allowed to join, DISCONNECTED if not.
82  */
83 GLOBAL bool
84 Class_HandleServerBans(CLIENT *Client)
85 {
86         char reject[COMMAND_LEN];
87
88         assert(Client != NULL);
89
90         if (Class_GetMemberReason(CLASS_GLINE, Client, reject, sizeof(reject)) ||
91             Class_GetMemberReason(CLASS_KLINE, Client, reject, sizeof(reject))) {
92                 Client_Reject(Client, reject, true);
93                 return DISCONNECTED;
94         }
95
96         return CONNECTED;
97 }
98
99
100 GLOBAL bool
101 Class_AddMask(const int Class, const char *Pattern, time_t ValidUntil,
102               const char *Reason)
103 {
104         char mask[MASK_LEN];
105
106         assert(Class < CLASS_COUNT);
107         assert(Pattern != NULL);
108         assert(Reason != NULL);
109
110         Lists_MakeMask(Pattern, mask, sizeof(mask));
111         return Lists_Add(&My_Classes[Class], mask,
112                          ValidUntil, Reason);
113 }
114
115 GLOBAL void
116 Class_DeleteMask(const int Class, const char *Pattern)
117 {
118         char mask[MASK_LEN];
119
120         assert(Class < CLASS_COUNT);
121         assert(Pattern != NULL);
122
123         Lists_MakeMask(Pattern, mask, sizeof(mask));
124         Lists_Del(&My_Classes[Class], mask);
125 }
126
127 GLOBAL struct list_head *
128 Class_GetList(const int Class)
129 {
130         assert(Class < CLASS_COUNT);
131
132         return &My_Classes[Class];
133 }
134
135 GLOBAL void
136 Class_Expire(void)
137 {
138         Lists_Expire(&My_Classes[CLASS_GLINE], "G-Line");
139         Lists_Expire(&My_Classes[CLASS_KLINE], "K-Line");
140 }
141
142 /* -eof- */