1 |
|
/* |
2 |
< |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
< |
* conf.c: Configuration file functions. |
2 |
> |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
|
* |
4 |
< |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
4 |
> |
* Copyright (c) 1997-2018 ircd-hybrid development team |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
15 |
|
* |
16 |
|
* You should have received a copy of the GNU General Public License |
17 |
|
* along with this program; if not, write to the Free Software |
18 |
< |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
18 |
> |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
|
* USA |
20 |
< |
* |
21 |
< |
* $Id$ |
20 |
> |
*/ |
21 |
> |
|
22 |
> |
/*! \file conf.c |
23 |
> |
* \brief Configuration file functions. |
24 |
> |
* \version $Id$ |
25 |
|
*/ |
26 |
|
|
27 |
|
#include "stdinc.h" |
28 |
|
#include "list.h" |
29 |
|
#include "ircd_defs.h" |
30 |
|
#include "conf.h" |
31 |
< |
#include "s_serv.h" |
32 |
< |
#include "resv.h" |
31 |
> |
#include "conf_cluster.h" |
32 |
> |
#include "conf_gecos.h" |
33 |
> |
#include "conf_pseudo.h" |
34 |
> |
#include "conf_resv.h" |
35 |
> |
#include "conf_service.h" |
36 |
> |
#include "conf_shared.h" |
37 |
> |
#include "server.h" |
38 |
|
#include "channel.h" |
39 |
|
#include "client.h" |
40 |
|
#include "event.h" |
34 |
– |
#include "hook.h" |
41 |
|
#include "irc_string.h" |
42 |
|
#include "s_bsd.h" |
43 |
|
#include "ircd.h" |
48 |
|
#include "fdlist.h" |
49 |
|
#include "log.h" |
50 |
|
#include "send.h" |
45 |
– |
#include "s_gline.h" |
51 |
|
#include "memory.h" |
52 |
< |
#include "mempool.h" |
48 |
< |
#include "irc_res.h" |
52 |
> |
#include "res.h" |
53 |
|
#include "userhost.h" |
54 |
< |
#include "s_user.h" |
54 |
> |
#include "user.h" |
55 |
|
#include "channel_mode.h" |
56 |
|
#include "parse.h" |
57 |
< |
#include "s_misc.h" |
57 |
> |
#include "misc.h" |
58 |
|
#include "conf_db.h" |
59 |
|
#include "conf_class.h" |
60 |
+ |
#include "motd.h" |
61 |
+ |
#include "ipcache.h" |
62 |
+ |
#include "isupport.h" |
63 |
+ |
#include "whowas.h" |
64 |
|
|
65 |
< |
struct config_server_hide ConfigServerHide; |
65 |
> |
|
66 |
> |
struct config_channel_entry ConfigChannel; |
67 |
> |
struct config_serverhide_entry ConfigServerHide; |
68 |
> |
struct config_general_entry ConfigGeneral; |
69 |
> |
struct config_log_entry ConfigLog = { .use_logging = 1 }; |
70 |
> |
struct config_serverinfo_entry ConfigServerInfo; |
71 |
> |
struct config_admin_entry ConfigAdminInfo; |
72 |
> |
struct conf_parser_context conf_parser_ctx; |
73 |
|
|
74 |
|
/* general conf items link list root, other than k lines etc. */ |
75 |
< |
dlink_list service_items = { NULL, NULL, 0 }; |
76 |
< |
dlink_list server_items = { NULL, NULL, 0 }; |
62 |
< |
dlink_list cluster_items = { NULL, NULL, 0 }; |
63 |
< |
dlink_list oconf_items = { NULL, NULL, 0 }; |
64 |
< |
dlink_list uconf_items = { NULL, NULL, 0 }; |
65 |
< |
dlink_list xconf_items = { NULL, NULL, 0 }; |
66 |
< |
dlink_list nresv_items = { NULL, NULL, 0 }; |
67 |
< |
dlink_list temporary_resv = { NULL, NULL, 0 }; |
75 |
> |
dlink_list connect_items; |
76 |
> |
dlink_list operator_items; |
77 |
|
|
78 |
|
extern unsigned int lineno; |
79 |
|
extern char linebuf[]; |
80 |
|
extern char conffilebuf[IRCD_BUFSIZE]; |
81 |
|
extern int yyparse(); /* defined in y.tab.c */ |
82 |
|
|
74 |
– |
struct conf_parser_context conf_parser_ctx = { 0, 0, NULL }; |
75 |
– |
|
76 |
– |
/* internally defined functions */ |
77 |
– |
static void read_conf(FILE *); |
78 |
– |
static void clear_out_old_conf(void); |
79 |
– |
static void expire_tklines(dlink_list *); |
80 |
– |
static void garbage_collect_ip_entries(void); |
81 |
– |
static int hash_ip(struct irc_ssaddr *); |
82 |
– |
static int verify_access(struct Client *); |
83 |
– |
static int attach_iline(struct Client *, struct MaskItem *); |
84 |
– |
static struct ip_entry *find_or_add_ip(struct irc_ssaddr *); |
85 |
– |
static dlink_list *map_to_list(enum maskitem_type); |
86 |
– |
static int find_user_host(struct Client *, char *, char *, char *, unsigned int); |
87 |
– |
|
88 |
– |
|
89 |
– |
/* usually, with hash tables, you use a prime number... |
90 |
– |
* but in this case I am dealing with ip addresses, |
91 |
– |
* not ascii strings. |
92 |
– |
*/ |
93 |
– |
#define IP_HASH_SIZE 0x1000 |
94 |
– |
|
95 |
– |
struct ip_entry |
96 |
– |
{ |
97 |
– |
struct irc_ssaddr ip; |
98 |
– |
unsigned int count; |
99 |
– |
time_t last_attempt; |
100 |
– |
struct ip_entry *next; |
101 |
– |
}; |
102 |
– |
|
103 |
– |
static struct ip_entry *ip_hash_table[IP_HASH_SIZE]; |
104 |
– |
static mp_pool_t *ip_entry_pool = NULL; |
105 |
– |
static int ip_entries_count = 0; |
106 |
– |
|
83 |
|
|
84 |
|
/* conf_dns_callback() |
85 |
|
* |
92 |
|
* if successful save hp in the conf item it was called with |
93 |
|
*/ |
94 |
|
static void |
95 |
< |
conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name) |
95 |
> |
conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name, size_t namelength) |
96 |
|
{ |
97 |
< |
struct MaskItem *conf = vptr; |
97 |
> |
struct MaskItem *const conf = vptr; |
98 |
|
|
99 |
|
conf->dns_pending = 0; |
100 |
|
|
101 |
< |
if (addr != NULL) |
101 |
> |
if (addr) |
102 |
|
memcpy(&conf->addr, addr, sizeof(conf->addr)); |
103 |
|
else |
104 |
|
conf->dns_failed = 1; |
113 |
|
static void |
114 |
|
conf_dns_lookup(struct MaskItem *conf) |
115 |
|
{ |
116 |
< |
if (!conf->dns_pending) |
116 |
> |
if (conf->dns_pending) |
117 |
> |
return; |
118 |
> |
|
119 |
> |
conf->dns_pending = 1; |
120 |
> |
|
121 |
> |
if (conf->aftype == AF_INET) |
122 |
> |
gethost_byname_type(conf_dns_callback, conf, conf->host, T_A); |
123 |
> |
else |
124 |
> |
gethost_byname_type(conf_dns_callback, conf, conf->host, T_AAAA); |
125 |
> |
} |
126 |
> |
|
127 |
> |
/* map_to_list() |
128 |
> |
* |
129 |
> |
* inputs - ConfType conf |
130 |
> |
* output - pointer to dlink_list to use |
131 |
> |
* side effects - none |
132 |
> |
*/ |
133 |
> |
static dlink_list * |
134 |
> |
map_to_list(enum maskitem_type type) |
135 |
> |
{ |
136 |
> |
switch (type) |
137 |
|
{ |
138 |
< |
conf->dns_pending = 1; |
139 |
< |
gethost_byname(conf_dns_callback, conf, conf->host); |
138 |
> |
case CONF_OPER: |
139 |
> |
return &operator_items; |
140 |
> |
break; |
141 |
> |
case CONF_SERVER: |
142 |
> |
return &connect_items; |
143 |
> |
break; |
144 |
> |
default: |
145 |
> |
return NULL; |
146 |
|
} |
147 |
|
} |
148 |
|
|
149 |
|
struct MaskItem * |
150 |
|
conf_make(enum maskitem_type type) |
151 |
|
{ |
152 |
< |
struct MaskItem *conf = MyMalloc(sizeof(*conf)); |
152 |
> |
struct MaskItem *const conf = xcalloc(sizeof(*conf)); |
153 |
|
dlink_list *list = NULL; |
154 |
|
|
155 |
|
conf->type = type; |
164 |
|
void |
165 |
|
conf_free(struct MaskItem *conf) |
166 |
|
{ |
167 |
< |
dlink_node *ptr = NULL, *ptr_next = NULL; |
167 |
> |
dlink_node *node = NULL, *node_next = NULL; |
168 |
|
dlink_list *list = NULL; |
169 |
|
|
170 |
< |
if (conf->node.next) |
171 |
< |
if ((list = map_to_list(conf->type))) |
170 |
< |
dlinkDelete(&conf->node, list); |
170 |
> |
if ((list = map_to_list(conf->type))) |
171 |
> |
dlinkFindDelete(list, conf); |
172 |
|
|
173 |
< |
MyFree(conf->name); |
173 |
> |
xfree(conf->name); |
174 |
|
|
175 |
|
if (conf->dns_pending) |
176 |
|
delete_resolver_queries(conf); |
177 |
< |
if (conf->passwd != NULL) |
177 |
> |
if (conf->passwd) |
178 |
|
memset(conf->passwd, 0, strlen(conf->passwd)); |
179 |
< |
if (conf->spasswd != NULL) |
179 |
> |
if (conf->spasswd) |
180 |
|
memset(conf->spasswd, 0, strlen(conf->spasswd)); |
181 |
|
|
182 |
|
conf->class = NULL; |
183 |
|
|
184 |
< |
MyFree(conf->passwd); |
185 |
< |
MyFree(conf->spasswd); |
186 |
< |
MyFree(conf->reason); |
187 |
< |
MyFree(conf->user); |
188 |
< |
MyFree(conf->host); |
189 |
< |
#ifdef HAVE_LIBCRYPTO |
190 |
< |
MyFree(conf->cipher_list); |
184 |
> |
xfree(conf->passwd); |
185 |
> |
xfree(conf->spasswd); |
186 |
> |
xfree(conf->reason); |
187 |
> |
xfree(conf->certfp); |
188 |
> |
xfree(conf->whois); |
189 |
> |
xfree(conf->user); |
190 |
> |
xfree(conf->host); |
191 |
> |
xfree(conf->cipher_list); |
192 |
|
|
193 |
< |
if (conf->rsa_public_key) |
192 |
< |
RSA_free(conf->rsa_public_key); |
193 |
< |
#endif |
194 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, conf->hub_list.head) |
193 |
> |
DLINK_FOREACH_SAFE(node, node_next, conf->hub_list.head) |
194 |
|
{ |
195 |
< |
MyFree(ptr->data); |
196 |
< |
free_dlink_node(ptr); |
195 |
> |
xfree(node->data); |
196 |
> |
dlinkDelete(node, &conf->hub_list); |
197 |
> |
free_dlink_node(node); |
198 |
|
} |
199 |
|
|
200 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, conf->leaf_list.head) |
200 |
> |
DLINK_FOREACH_SAFE(node, node_next, conf->leaf_list.head) |
201 |
|
{ |
202 |
< |
MyFree(ptr->data); |
203 |
< |
free_dlink_node(ptr); |
202 |
> |
xfree(node->data); |
203 |
> |
dlinkDelete(node, &conf->leaf_list); |
204 |
> |
free_dlink_node(node); |
205 |
|
} |
206 |
|
|
207 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, conf->exempt_list.head) |
207 |
< |
{ |
208 |
< |
struct exempt *exptr = ptr->data; |
209 |
< |
|
210 |
< |
MyFree(exptr->name); |
211 |
< |
MyFree(exptr->user); |
212 |
< |
MyFree(exptr->host); |
213 |
< |
MyFree(exptr); |
214 |
< |
} |
215 |
< |
|
216 |
< |
MyFree(conf); |
217 |
< |
} |
218 |
< |
|
219 |
< |
/* check_client() |
220 |
< |
* |
221 |
< |
* inputs - pointer to client |
222 |
< |
* output - 0 = Success |
223 |
< |
* NOT_AUTHORIZED (-1) = Access denied (no I line match) |
224 |
< |
* IRCD_SOCKET_ERROR (-2) = Bad socket. |
225 |
< |
* I_LINE_FULL (-3) = I-line is full |
226 |
< |
* TOO_MANY (-4) = Too many connections from hostname |
227 |
< |
* BANNED_CLIENT (-5) = K-lined |
228 |
< |
* side effects - Ordinary client access check. |
229 |
< |
* Look for conf lines which have the same |
230 |
< |
* status as the flags passed. |
231 |
< |
*/ |
232 |
< |
int |
233 |
< |
check_client(struct Client *source_p) |
234 |
< |
{ |
235 |
< |
int i; |
236 |
< |
|
237 |
< |
if ((i = verify_access(source_p))) |
238 |
< |
ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]", |
239 |
< |
source_p->name, source_p->sockhost); |
240 |
< |
|
241 |
< |
switch (i) |
242 |
< |
{ |
243 |
< |
case TOO_MANY: |
244 |
< |
sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE, |
245 |
< |
"Too many on IP for %s (%s).", |
246 |
< |
get_client_name(source_p, SHOW_IP), |
247 |
< |
source_p->sockhost); |
248 |
< |
ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.", |
249 |
< |
get_client_name(source_p, SHOW_IP)); |
250 |
< |
++ServerStats.is_ref; |
251 |
< |
exit_client(source_p, &me, "No more connections allowed on that IP"); |
252 |
< |
break; |
253 |
< |
|
254 |
< |
case I_LINE_FULL: |
255 |
< |
sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE, |
256 |
< |
"auth{} block is full for %s (%s).", |
257 |
< |
get_client_name(source_p, SHOW_IP), |
258 |
< |
source_p->sockhost); |
259 |
< |
ilog(LOG_TYPE_IRCD, "Too many connections from %s.", |
260 |
< |
get_client_name(source_p, SHOW_IP)); |
261 |
< |
++ServerStats.is_ref; |
262 |
< |
exit_client(source_p, &me, |
263 |
< |
"No more connections allowed in your connection class"); |
264 |
< |
break; |
265 |
< |
|
266 |
< |
case NOT_AUTHORIZED: |
267 |
< |
++ServerStats.is_ref; |
268 |
< |
/* jdc - lists server name & port connections are on */ |
269 |
< |
/* a purely cosmetical change */ |
270 |
< |
sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE, |
271 |
< |
"Unauthorized client connection from %s [%s] on [%s/%u].", |
272 |
< |
get_client_name(source_p, SHOW_IP), |
273 |
< |
source_p->sockhost, |
274 |
< |
source_p->localClient->listener->name, |
275 |
< |
source_p->localClient->listener->port); |
276 |
< |
ilog(LOG_TYPE_IRCD, |
277 |
< |
"Unauthorized client connection from %s on [%s/%u].", |
278 |
< |
get_client_name(source_p, SHOW_IP), |
279 |
< |
source_p->localClient->listener->name, |
280 |
< |
source_p->localClient->listener->port); |
281 |
< |
|
282 |
< |
exit_client(source_p, &me, "You are not authorized to use this server"); |
283 |
< |
break; |
284 |
< |
|
285 |
< |
case BANNED_CLIENT: |
286 |
< |
exit_client(source_p, &me, "Banned"); |
287 |
< |
++ServerStats.is_ref; |
288 |
< |
break; |
289 |
< |
|
290 |
< |
case 0: |
291 |
< |
default: |
292 |
< |
break; |
293 |
< |
} |
294 |
< |
|
295 |
< |
return (i < 0 ? 0 : 1); |
296 |
< |
} |
297 |
< |
|
298 |
< |
/* verify_access() |
299 |
< |
* |
300 |
< |
* inputs - pointer to client to verify |
301 |
< |
* output - 0 if success -'ve if not |
302 |
< |
* side effect - find the first (best) I line to attach. |
303 |
< |
*/ |
304 |
< |
static int |
305 |
< |
verify_access(struct Client *client_p) |
306 |
< |
{ |
307 |
< |
struct MaskItem *conf = NULL; |
308 |
< |
char non_ident[USERLEN + 1] = { '~', '\0' }; |
309 |
< |
|
310 |
< |
if (IsGotId(client_p)) |
311 |
< |
{ |
312 |
< |
conf = find_address_conf(client_p->host, client_p->username, |
313 |
< |
&client_p->localClient->ip, |
314 |
< |
client_p->localClient->aftype, |
315 |
< |
client_p->localClient->passwd); |
316 |
< |
} |
317 |
< |
else |
318 |
< |
{ |
319 |
< |
strlcpy(non_ident+1, client_p->username, sizeof(non_ident)-1); |
320 |
< |
conf = find_address_conf(client_p->host,non_ident, |
321 |
< |
&client_p->localClient->ip, |
322 |
< |
client_p->localClient->aftype, |
323 |
< |
client_p->localClient->passwd); |
324 |
< |
} |
325 |
< |
|
326 |
< |
if (conf != NULL) |
327 |
< |
{ |
328 |
< |
if (IsConfClient(conf)) |
329 |
< |
{ |
330 |
< |
if (IsConfRedir(conf)) |
331 |
< |
{ |
332 |
< |
sendto_one(client_p, form_str(RPL_REDIR), |
333 |
< |
me.name, client_p->name, |
334 |
< |
conf->name ? conf->name : "", |
335 |
< |
conf->port); |
336 |
< |
return(NOT_AUTHORIZED); |
337 |
< |
} |
338 |
< |
|
339 |
< |
if (IsConfDoIdentd(conf)) |
340 |
< |
SetNeedId(client_p); |
341 |
< |
|
342 |
< |
/* Thanks for spoof idea amm */ |
343 |
< |
if (IsConfDoSpoofIp(conf)) |
344 |
< |
{ |
345 |
< |
if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(conf)) |
346 |
< |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
347 |
< |
"%s spoofing: %s as %s", |
348 |
< |
client_p->name, client_p->host, conf->name); |
349 |
< |
strlcpy(client_p->host, conf->name, sizeof(client_p->host)); |
350 |
< |
SetIPSpoof(client_p); |
351 |
< |
} |
352 |
< |
|
353 |
< |
return(attach_iline(client_p, conf)); |
354 |
< |
} |
355 |
< |
else if (IsConfKill(conf) || (ConfigFileEntry.glines && IsConfGline(conf))) |
356 |
< |
{ |
357 |
< |
if (IsConfGline(conf)) |
358 |
< |
sendto_one(client_p, ":%s NOTICE %s :*** G-lined", me.name, |
359 |
< |
client_p->name); |
360 |
< |
sendto_one(client_p, ":%s NOTICE %s :*** Banned: %s", |
361 |
< |
me.name, client_p->name, conf->reason); |
362 |
< |
return(BANNED_CLIENT); |
363 |
< |
} |
364 |
< |
} |
365 |
< |
|
366 |
< |
return(NOT_AUTHORIZED); |
207 |
> |
xfree(conf); |
208 |
|
} |
209 |
|
|
210 |
|
/* attach_iline() |
211 |
|
* |
212 |
< |
* inputs - client pointer |
213 |
< |
* - conf pointer |
214 |
< |
* output - |
215 |
< |
* side effects - do actual attach |
212 |
> |
* inputs - client pointer |
213 |
> |
* - conf pointer |
214 |
> |
* output - |
215 |
> |
* side effects - do actual attach |
216 |
|
*/ |
217 |
|
static int |
218 |
|
attach_iline(struct Client *client_p, struct MaskItem *conf) |
219 |
|
{ |
220 |
< |
struct ClassItem *class = NULL; |
220 |
> |
const struct ClassItem *const class = conf->class; |
221 |
|
struct ip_entry *ip_found; |
222 |
|
int a_limit_reached = 0; |
223 |
< |
unsigned int local = 0, global = 0, ident = 0; |
223 |
> |
unsigned int local = 0, global = 0; |
224 |
|
|
225 |
< |
ip_found = find_or_add_ip(&client_p->localClient->ip); |
225 |
> |
ip_found = ipcache_find_or_add_address(&client_p->connection->ip); |
226 |
|
ip_found->count++; |
227 |
< |
SetIpHash(client_p); |
387 |
< |
|
388 |
< |
if (conf->class == NULL) |
389 |
< |
return NOT_AUTHORIZED; /* If class is missing, this is best */ |
390 |
< |
|
391 |
< |
class = conf->class; |
227 |
> |
AddFlag(client_p, FLAGS_IPHASH); |
228 |
|
|
229 |
< |
count_user_host(client_p->username, client_p->host, |
394 |
< |
&global, &local, &ident); |
229 |
> |
userhost_count(client_p->sockhost, &global, &local); |
230 |
|
|
231 |
|
/* XXX blah. go down checking the various silly limits |
232 |
|
* setting a_limit_reached if any limit is reached. |
233 |
|
* - Dianora |
234 |
|
*/ |
235 |
< |
if (class->max_total != 0 && class->ref_count >= class->max_total) |
235 |
> |
if (class->max_total && class->ref_count >= class->max_total) |
236 |
|
a_limit_reached = 1; |
237 |
< |
else if (class->max_perip != 0 && ip_found->count > class->max_perip) |
237 |
> |
else if (class->max_perip && ip_found->count > class->max_perip) |
238 |
|
a_limit_reached = 1; |
239 |
< |
else if (class->max_local != 0 && local >= class->max_local) |
239 |
> |
else if (class->max_local && local >= class->max_local) /* XXX: redundant */ |
240 |
|
a_limit_reached = 1; |
241 |
< |
else if (class->max_global != 0 && global >= class->max_global) |
407 |
< |
a_limit_reached = 1; |
408 |
< |
else if (class->max_ident != 0 && ident >= class->max_ident && |
409 |
< |
client_p->username[0] != '~') |
241 |
> |
else if (class->max_global && global >= class->max_global) |
242 |
|
a_limit_reached = 1; |
243 |
|
|
244 |
|
if (a_limit_reached) |
246 |
|
if (!IsConfExemptLimits(conf)) |
247 |
|
return TOO_MANY; /* Already at maximum allowed */ |
248 |
|
|
249 |
< |
sendto_one(client_p, |
250 |
< |
":%s NOTICE %s :*** Your connection class is full, " |
419 |
< |
"but you have exceed_limit = yes;", me.name, client_p->name); |
249 |
> |
sendto_one_notice(client_p, &me, ":*** Your connection class is full, " |
250 |
> |
"but you have exceed_limit = yes;"); |
251 |
|
} |
252 |
|
|
253 |
|
return attach_conf(client_p, conf); |
254 |
|
} |
255 |
|
|
256 |
< |
/* init_ip_hash_table() |
426 |
< |
* |
427 |
< |
* inputs - NONE |
428 |
< |
* output - NONE |
429 |
< |
* side effects - allocate memory for ip_entry(s) |
430 |
< |
* - clear the ip hash table |
431 |
< |
*/ |
432 |
< |
void |
433 |
< |
init_ip_hash_table(void) |
434 |
< |
{ |
435 |
< |
ip_entry_pool = mp_pool_new(sizeof(struct ip_entry), MP_CHUNK_SIZE_IP_ENTRY); |
436 |
< |
memset(ip_hash_table, 0, sizeof(ip_hash_table)); |
437 |
< |
} |
438 |
< |
|
439 |
< |
/* find_or_add_ip() |
440 |
< |
* |
441 |
< |
* inputs - pointer to struct irc_ssaddr |
442 |
< |
* output - pointer to a struct ip_entry |
443 |
< |
* side effects - |
256 |
> |
/* verify_access() |
257 |
|
* |
258 |
< |
* If the ip # was not found, a new struct ip_entry is created, and the ip |
259 |
< |
* count set to 0. |
258 |
> |
* inputs - pointer to client to verify |
259 |
> |
* output - 0 if success -'ve if not |
260 |
> |
* side effect - find the first (best) I line to attach. |
261 |
|
*/ |
262 |
< |
static struct ip_entry * |
263 |
< |
find_or_add_ip(struct irc_ssaddr *ip_in) |
262 |
> |
static int |
263 |
> |
verify_access(struct Client *client_p) |
264 |
|
{ |
265 |
< |
struct ip_entry *ptr, *newptr; |
452 |
< |
int hash_index = hash_ip(ip_in), res; |
453 |
< |
struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4; |
454 |
< |
#ifdef IPV6 |
455 |
< |
struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6; |
456 |
< |
#endif |
265 |
> |
struct MaskItem *conf = NULL; |
266 |
|
|
267 |
< |
for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next) |
267 |
> |
if (HasFlag(client_p, FLAGS_GOTID)) |
268 |
|
{ |
269 |
< |
#ifdef IPV6 |
270 |
< |
if (ptr->ip.ss.ss_family != ip_in->ss.ss_family) |
271 |
< |
continue; |
272 |
< |
if (ip_in->ss.ss_family == AF_INET6) |
464 |
< |
{ |
465 |
< |
ptr_v6 = (struct sockaddr_in6 *)&ptr->ip; |
466 |
< |
res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr)); |
467 |
< |
} |
468 |
< |
else |
469 |
< |
#endif |
470 |
< |
{ |
471 |
< |
ptr_v4 = (struct sockaddr_in *)&ptr->ip; |
472 |
< |
res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr)); |
473 |
< |
} |
474 |
< |
if (res == 0) |
475 |
< |
{ |
476 |
< |
/* Found entry already in hash, return it. */ |
477 |
< |
return ptr; |
478 |
< |
} |
269 |
> |
conf = find_address_conf(client_p->host, client_p->username, |
270 |
> |
&client_p->connection->ip, |
271 |
> |
client_p->connection->aftype, |
272 |
> |
client_p->connection->password); |
273 |
|
} |
274 |
+ |
else |
275 |
+ |
{ |
276 |
+ |
char non_ident[USERLEN + 1] = "~"; |
277 |
|
|
278 |
< |
if (ip_entries_count >= 2 * hard_fdlimit) |
279 |
< |
garbage_collect_ip_entries(); |
280 |
< |
|
281 |
< |
newptr = mp_pool_get(ip_entry_pool); |
282 |
< |
memset(newptr, 0, sizeof(*newptr)); |
283 |
< |
ip_entries_count++; |
487 |
< |
memcpy(&newptr->ip, ip_in, sizeof(struct irc_ssaddr)); |
488 |
< |
|
489 |
< |
newptr->next = ip_hash_table[hash_index]; |
490 |
< |
ip_hash_table[hash_index] = newptr; |
278 |
> |
strlcpy(non_ident + 1, client_p->username, sizeof(non_ident) - 1); |
279 |
> |
conf = find_address_conf(client_p->host, non_ident, |
280 |
> |
&client_p->connection->ip, |
281 |
> |
client_p->connection->aftype, |
282 |
> |
client_p->connection->password); |
283 |
> |
} |
284 |
|
|
285 |
< |
return newptr; |
286 |
< |
} |
285 |
> |
if (!conf) |
286 |
> |
return NOT_AUTHORIZED; |
287 |
|
|
288 |
< |
/* remove_one_ip() |
496 |
< |
* |
497 |
< |
* inputs - unsigned long IP address value |
498 |
< |
* output - NONE |
499 |
< |
* side effects - The ip address given, is looked up in ip hash table |
500 |
< |
* and number of ip#'s for that ip decremented. |
501 |
< |
* If ip # count reaches 0 and has expired, |
502 |
< |
* the struct ip_entry is returned to the ip_entry_heap |
503 |
< |
*/ |
504 |
< |
void |
505 |
< |
remove_one_ip(struct irc_ssaddr *ip_in) |
506 |
< |
{ |
507 |
< |
struct ip_entry *ptr; |
508 |
< |
struct ip_entry *last_ptr = NULL; |
509 |
< |
int hash_index = hash_ip(ip_in), res; |
510 |
< |
struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4; |
511 |
< |
#ifdef IPV6 |
512 |
< |
struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6; |
513 |
< |
#endif |
288 |
> |
assert(IsConfClient(conf) || IsConfKill(conf)); |
289 |
|
|
290 |
< |
for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next) |
290 |
> |
if (IsConfClient(conf)) |
291 |
|
{ |
292 |
< |
#ifdef IPV6 |
518 |
< |
if (ptr->ip.ss.ss_family != ip_in->ss.ss_family) |
519 |
< |
continue; |
520 |
< |
if (ip_in->ss.ss_family == AF_INET6) |
292 |
> |
if (IsConfRedir(conf)) |
293 |
|
{ |
294 |
< |
ptr_v6 = (struct sockaddr_in6 *)&ptr->ip; |
295 |
< |
res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr)); |
294 |
> |
sendto_one_numeric(client_p, &me, RPL_REDIR, |
295 |
> |
conf->name ? conf->name : "", |
296 |
> |
conf->port); |
297 |
> |
return NOT_AUTHORIZED; |
298 |
|
} |
299 |
< |
else |
300 |
< |
#endif |
527 |
< |
{ |
528 |
< |
ptr_v4 = (struct sockaddr_in *)&ptr->ip; |
529 |
< |
res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr)); |
530 |
< |
} |
531 |
< |
if (res) |
532 |
< |
continue; |
533 |
< |
if (ptr->count > 0) |
534 |
< |
ptr->count--; |
535 |
< |
if (ptr->count == 0 && |
536 |
< |
(CurrentTime-ptr->last_attempt) >= ConfigFileEntry.throttle_time) |
299 |
> |
|
300 |
> |
if (IsConfDoSpoofIp(conf)) |
301 |
|
{ |
302 |
< |
if (last_ptr != NULL) |
303 |
< |
last_ptr->next = ptr->next; |
304 |
< |
else |
541 |
< |
ip_hash_table[hash_index] = ptr->next; |
302 |
> |
if (IsConfSpoofNotice(conf)) |
303 |
> |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, "%s spoofing: %s as %s", |
304 |
> |
client_p->name, client_p->host, conf->name); |
305 |
|
|
306 |
< |
mp_pool_release(ptr); |
544 |
< |
ip_entries_count--; |
545 |
< |
return; |
306 |
> |
strlcpy(client_p->host, conf->name, sizeof(client_p->host)); |
307 |
|
} |
547 |
– |
last_ptr = ptr; |
548 |
– |
} |
549 |
– |
} |
550 |
– |
|
551 |
– |
/* hash_ip() |
552 |
– |
* |
553 |
– |
* input - pointer to an irc_inaddr |
554 |
– |
* output - integer value used as index into hash table |
555 |
– |
* side effects - hopefully, none |
556 |
– |
*/ |
557 |
– |
static int |
558 |
– |
hash_ip(struct irc_ssaddr *addr) |
559 |
– |
{ |
560 |
– |
if (addr->ss.ss_family == AF_INET) |
561 |
– |
{ |
562 |
– |
struct sockaddr_in *v4 = (struct sockaddr_in *)addr; |
563 |
– |
int hash; |
564 |
– |
uint32_t ip; |
308 |
|
|
309 |
< |
ip = ntohl(v4->sin_addr.s_addr); |
567 |
< |
hash = ((ip >> 12) + ip) & (IP_HASH_SIZE-1); |
568 |
< |
return hash; |
309 |
> |
return attach_iline(client_p, conf); |
310 |
|
} |
311 |
< |
#ifdef IPV6 |
312 |
< |
else |
313 |
< |
{ |
573 |
< |
int hash; |
574 |
< |
struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr; |
575 |
< |
uint32_t *ip = (uint32_t *)&v6->sin6_addr.s6_addr; |
576 |
< |
|
577 |
< |
hash = ip[0] ^ ip[3]; |
578 |
< |
hash ^= hash >> 16; |
579 |
< |
hash ^= hash >> 8; |
580 |
< |
hash = hash & (IP_HASH_SIZE - 1); |
581 |
< |
return hash; |
582 |
< |
} |
583 |
< |
#else |
584 |
< |
return 0; |
585 |
< |
#endif |
311 |
> |
|
312 |
> |
sendto_one_notice(client_p, &me, ":*** Banned: %s", conf->reason); |
313 |
> |
return BANNED_CLIENT; |
314 |
|
} |
315 |
|
|
316 |
< |
/* count_ip_hash() |
589 |
< |
* |
590 |
< |
* inputs - pointer to counter of number of ips hashed |
591 |
< |
* - pointer to memory used for ip hash |
592 |
< |
* output - returned via pointers input |
593 |
< |
* side effects - NONE |
316 |
> |
/* check_client() |
317 |
|
* |
318 |
< |
* number of hashed ip #'s is counted up, plus the amount of memory |
319 |
< |
* used in the hash. |
318 |
> |
* inputs - pointer to client |
319 |
> |
* output - 0 = Success |
320 |
> |
* NOT_AUTHORIZED (-1) = Access denied (no I line match) |
321 |
> |
* IRCD_SOCKET_ERROR (-2) = Bad socket. |
322 |
> |
* I_LINE_FULL (-3) = I-line is full |
323 |
> |
* TOO_MANY (-4) = Too many connections from hostname |
324 |
> |
* BANNED_CLIENT (-5) = K-lined |
325 |
> |
* side effects - Ordinary client access check. |
326 |
> |
* Look for conf lines which have the same |
327 |
> |
* status as the flags passed. |
328 |
|
*/ |
329 |
< |
void |
330 |
< |
count_ip_hash(unsigned int *number_ips_stored, uint64_t *mem_ips_stored) |
329 |
> |
int |
330 |
> |
check_client(struct Client *source_p) |
331 |
|
{ |
601 |
– |
struct ip_entry *ptr; |
332 |
|
int i; |
333 |
|
|
334 |
< |
*number_ips_stored = 0; |
335 |
< |
*mem_ips_stored = 0; |
334 |
> |
if ((i = verify_access(source_p))) |
335 |
> |
ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]", |
336 |
> |
source_p->name, source_p->sockhost); |
337 |
|
|
338 |
< |
for (i = 0; i < IP_HASH_SIZE; i++) |
338 |
> |
switch (i) |
339 |
|
{ |
340 |
< |
for (ptr = ip_hash_table[i]; ptr; ptr = ptr->next) |
341 |
< |
{ |
342 |
< |
*number_ips_stored += 1; |
343 |
< |
*mem_ips_stored += sizeof(struct ip_entry); |
344 |
< |
} |
345 |
< |
} |
346 |
< |
} |
340 |
> |
case TOO_MANY: |
341 |
> |
sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE, |
342 |
> |
"Too many on IP for %s (%s).", |
343 |
> |
client_get_name(source_p, SHOW_IP), |
344 |
> |
source_p->sockhost); |
345 |
> |
ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.", |
346 |
> |
client_get_name(source_p, SHOW_IP)); |
347 |
> |
++ServerStats.is_ref; |
348 |
> |
exit_client(source_p, "No more connections allowed on that IP"); |
349 |
> |
break; |
350 |
|
|
351 |
< |
/* garbage_collect_ip_entries() |
352 |
< |
* |
353 |
< |
* input - NONE |
354 |
< |
* output - NONE |
355 |
< |
* side effects - free up all ip entries with no connections |
356 |
< |
*/ |
357 |
< |
static void |
358 |
< |
garbage_collect_ip_entries(void) |
359 |
< |
{ |
360 |
< |
struct ip_entry *ptr; |
627 |
< |
struct ip_entry *last_ptr; |
628 |
< |
struct ip_entry *next_ptr; |
629 |
< |
int i; |
351 |
> |
case I_LINE_FULL: |
352 |
> |
sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE, |
353 |
> |
"auth {} block is full for %s (%s).", |
354 |
> |
client_get_name(source_p, SHOW_IP), |
355 |
> |
source_p->sockhost); |
356 |
> |
ilog(LOG_TYPE_IRCD, "Too many connections from %s.", |
357 |
> |
client_get_name(source_p, SHOW_IP)); |
358 |
> |
++ServerStats.is_ref; |
359 |
> |
exit_client(source_p, "No more connections allowed in your connection class"); |
360 |
> |
break; |
361 |
|
|
362 |
< |
for (i = 0; i < IP_HASH_SIZE; i++) |
363 |
< |
{ |
364 |
< |
last_ptr = NULL; |
362 |
> |
case NOT_AUTHORIZED: |
363 |
> |
/* jdc - lists server name & port connections are on */ |
364 |
> |
/* a purely cosmetical change */ |
365 |
> |
sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE, |
366 |
> |
"Unauthorized client connection from %s on [%s/%u].", |
367 |
> |
client_get_name(source_p, SHOW_IP), |
368 |
> |
source_p->connection->listener->name, |
369 |
> |
source_p->connection->listener->port); |
370 |
> |
ilog(LOG_TYPE_IRCD, "Unauthorized client connection from %s on [%s/%u].", |
371 |
> |
client_get_name(source_p, SHOW_IP), |
372 |
> |
source_p->connection->listener->name, |
373 |
> |
source_p->connection->listener->port); |
374 |
|
|
375 |
< |
for (ptr = ip_hash_table[i]; ptr; ptr = next_ptr) |
376 |
< |
{ |
377 |
< |
next_ptr = ptr->next; |
375 |
> |
++ServerStats.is_ref; |
376 |
> |
exit_client(source_p, "You are not authorized to use this server"); |
377 |
> |
break; |
378 |
|
|
379 |
< |
if (ptr->count == 0 && |
380 |
< |
(CurrentTime - ptr->last_attempt) >= ConfigFileEntry.throttle_time) |
381 |
< |
{ |
382 |
< |
if (last_ptr != NULL) |
383 |
< |
last_ptr->next = ptr->next; |
384 |
< |
else |
385 |
< |
ip_hash_table[i] = ptr->next; |
386 |
< |
mp_pool_release(ptr); |
647 |
< |
ip_entries_count--; |
648 |
< |
} |
649 |
< |
else |
650 |
< |
last_ptr = ptr; |
651 |
< |
} |
379 |
> |
case BANNED_CLIENT: |
380 |
> |
++ServerStats.is_ref; |
381 |
> |
exit_client(source_p, "Banned"); |
382 |
> |
break; |
383 |
> |
|
384 |
> |
case 0: |
385 |
> |
default: |
386 |
> |
break; |
387 |
|
} |
388 |
+ |
|
389 |
+ |
return !(i < 0); |
390 |
|
} |
391 |
|
|
392 |
|
/* detach_conf() |
400 |
|
void |
401 |
|
detach_conf(struct Client *client_p, enum maskitem_type type) |
402 |
|
{ |
403 |
< |
dlink_node *ptr = NULL, *next_ptr = NULL; |
403 |
> |
dlink_node *node = NULL, *node_next = NULL; |
404 |
|
|
405 |
< |
DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->confs.head) |
405 |
> |
DLINK_FOREACH_SAFE(node, node_next, client_p->connection->confs.head) |
406 |
|
{ |
407 |
< |
struct MaskItem *conf = ptr->data; |
407 |
> |
struct MaskItem *conf = node->data; |
408 |
|
|
409 |
|
assert(conf->type & (CONF_CLIENT | CONF_OPER | CONF_SERVER)); |
410 |
|
assert(conf->ref_count > 0); |
413 |
|
if (!(conf->type & type)) |
414 |
|
continue; |
415 |
|
|
416 |
< |
dlinkDelete(ptr, &client_p->localClient->confs); |
417 |
< |
free_dlink_node(ptr); |
416 |
> |
dlinkDelete(node, &client_p->connection->confs); |
417 |
> |
free_dlink_node(node); |
418 |
|
|
419 |
|
if (conf->type == CONF_CLIENT) |
420 |
< |
remove_from_cidr_check(&client_p->localClient->ip, conf->class); |
420 |
> |
remove_from_cidr_check(&client_p->connection->ip, conf->class); |
421 |
|
|
422 |
|
if (--conf->class->ref_count == 0 && conf->class->active == 0) |
423 |
|
{ |
443 |
|
int |
444 |
|
attach_conf(struct Client *client_p, struct MaskItem *conf) |
445 |
|
{ |
446 |
< |
if (dlinkFind(&client_p->localClient->confs, conf) != NULL) |
446 |
> |
if (dlinkFind(&client_p->connection->confs, conf)) |
447 |
|
return 1; |
448 |
|
|
449 |
|
if (conf->type == CONF_CLIENT) |
450 |
|
if (cidr_limit_reached(IsConfExemptLimits(conf), |
451 |
< |
&client_p->localClient->ip, conf->class)) |
451 |
> |
&client_p->connection->ip, conf->class)) |
452 |
|
return TOO_MANY; /* Already at maximum allowed */ |
453 |
|
|
454 |
|
conf->class->ref_count++; |
455 |
|
conf->ref_count++; |
456 |
|
|
457 |
< |
dlinkAdd(conf, make_dlink_node(), &client_p->localClient->confs); |
457 |
> |
dlinkAdd(conf, make_dlink_node(), &client_p->connection->confs); |
458 |
|
|
459 |
|
return 0; |
460 |
|
} |
471 |
|
attach_connect_block(struct Client *client_p, const char *name, |
472 |
|
const char *host) |
473 |
|
{ |
474 |
< |
dlink_node *ptr; |
738 |
< |
struct MaskItem *conf = NULL; |
474 |
> |
dlink_node *node = NULL; |
475 |
|
|
476 |
< |
assert(client_p != NULL); |
741 |
< |
assert(host != NULL); |
476 |
> |
assert(host); |
477 |
|
|
478 |
< |
if (client_p == NULL || host == NULL) |
744 |
< |
return 0; |
745 |
< |
|
746 |
< |
DLINK_FOREACH(ptr, server_items.head) |
478 |
> |
DLINK_FOREACH(node, connect_items.head) |
479 |
|
{ |
480 |
< |
conf = ptr->data; |
480 |
> |
struct MaskItem *conf = node->data; |
481 |
|
|
482 |
< |
if (match(conf->name, name) || match(conf->host, host)) |
482 |
> |
if (irccmp(conf->name, name) || |
483 |
> |
irccmp(conf->host, host)) |
484 |
|
continue; |
485 |
|
|
486 |
|
attach_conf(client_p, conf); |
487 |
< |
return -1; |
487 |
> |
return 1; |
488 |
|
} |
489 |
|
|
490 |
|
return 0; |
502 |
|
struct MaskItem * |
503 |
|
find_conf_name(dlink_list *list, const char *name, enum maskitem_type type) |
504 |
|
{ |
505 |
< |
dlink_node *ptr; |
773 |
< |
struct MaskItem* conf; |
505 |
> |
dlink_node *node = NULL; |
506 |
|
|
507 |
< |
DLINK_FOREACH(ptr, list->head) |
507 |
> |
DLINK_FOREACH(node, list->head) |
508 |
|
{ |
509 |
< |
conf = ptr->data; |
510 |
< |
|
509 |
> |
struct MaskItem *conf = node->data; |
510 |
> |
|
511 |
|
if (conf->type == type) |
512 |
|
{ |
513 |
< |
if (conf->name && (irccmp(conf->name, name) == 0 || |
514 |
< |
!match(conf->name, name))) |
783 |
< |
return conf; |
513 |
> |
if (conf->name && !irccmp(conf->name, name)) |
514 |
> |
return conf; |
515 |
|
} |
516 |
|
} |
517 |
|
|
518 |
|
return NULL; |
519 |
|
} |
520 |
|
|
790 |
– |
/* map_to_list() |
791 |
– |
* |
792 |
– |
* inputs - ConfType conf |
793 |
– |
* output - pointer to dlink_list to use |
794 |
– |
* side effects - none |
795 |
– |
*/ |
796 |
– |
static dlink_list * |
797 |
– |
map_to_list(enum maskitem_type type) |
798 |
– |
{ |
799 |
– |
switch(type) |
800 |
– |
{ |
801 |
– |
case CONF_XLINE: |
802 |
– |
return(&xconf_items); |
803 |
– |
break; |
804 |
– |
case CONF_ULINE: |
805 |
– |
return(&uconf_items); |
806 |
– |
break; |
807 |
– |
case CONF_NRESV: |
808 |
– |
return(&nresv_items); |
809 |
– |
break; |
810 |
– |
case CONF_CRESV: |
811 |
– |
return(&resv_channel_list); |
812 |
– |
case CONF_OPER: |
813 |
– |
return(&oconf_items); |
814 |
– |
break; |
815 |
– |
case CONF_SERVER: |
816 |
– |
return(&server_items); |
817 |
– |
break; |
818 |
– |
case CONF_SERVICE: |
819 |
– |
return(&service_items); |
820 |
– |
break; |
821 |
– |
case CONF_CLUSTER: |
822 |
– |
return(&cluster_items); |
823 |
– |
break; |
824 |
– |
default: |
825 |
– |
return NULL; |
826 |
– |
} |
827 |
– |
} |
828 |
– |
|
521 |
|
/* find_matching_name_conf() |
522 |
|
* |
523 |
|
* inputs - type of link list to look in |
529 |
|
* side effects - looks for a match on name field |
530 |
|
*/ |
531 |
|
struct MaskItem * |
532 |
< |
find_matching_name_conf(enum maskitem_type type, const char *name, const char *user, |
841 |
< |
const char *host, unsigned int flags) |
532 |
> |
connect_find(const char *name, const char *host, int (*compare)(const char *, const char *)) |
533 |
|
{ |
534 |
< |
dlink_node *ptr=NULL; |
844 |
< |
struct MaskItem *conf=NULL; |
845 |
< |
dlink_list *list_p = map_to_list(type); |
534 |
> |
dlink_node *node = NULL; |
535 |
|
|
536 |
< |
switch (type) |
536 |
> |
DLINK_FOREACH(node, connect_items.head) |
537 |
|
{ |
538 |
< |
case CONF_SERVICE: |
850 |
< |
DLINK_FOREACH(ptr, list_p->head) |
851 |
< |
{ |
852 |
< |
conf = ptr->data; |
853 |
< |
|
854 |
< |
if (EmptyString(conf->name)) |
855 |
< |
continue; |
856 |
< |
if ((name != NULL) && !irccmp(name, conf->name)) |
857 |
< |
return conf; |
858 |
< |
} |
859 |
< |
break; |
860 |
< |
|
861 |
< |
case CONF_XLINE: |
862 |
< |
case CONF_ULINE: |
863 |
< |
case CONF_NRESV: |
864 |
< |
case CONF_CRESV: |
865 |
< |
DLINK_FOREACH(ptr, list_p->head) |
866 |
< |
{ |
867 |
< |
conf = ptr->data; |
868 |
< |
|
869 |
< |
if (EmptyString(conf->name)) |
870 |
< |
continue; |
871 |
< |
if ((name != NULL) && !match(conf->name, name)) |
872 |
< |
{ |
873 |
< |
if ((user == NULL && (host == NULL))) |
874 |
< |
return conf; |
875 |
< |
if ((conf->flags & flags) != flags) |
876 |
< |
continue; |
877 |
< |
if (EmptyString(conf->user) || EmptyString(conf->host)) |
878 |
< |
return conf; |
879 |
< |
if (!match(conf->user, user) && !match(conf->host, host)) |
880 |
< |
return conf; |
881 |
< |
} |
882 |
< |
} |
883 |
< |
break; |
884 |
< |
|
885 |
< |
case CONF_SERVER: |
886 |
< |
DLINK_FOREACH(ptr, list_p->head) |
887 |
< |
{ |
888 |
< |
conf = ptr->data; |
538 |
> |
struct MaskItem *conf = node->data; |
539 |
|
|
540 |
< |
if ((name != NULL) && !match(name, conf->name)) |
541 |
< |
return conf; |
542 |
< |
else if ((host != NULL) && !match(host, conf->host)) |
543 |
< |
return conf; |
894 |
< |
} |
895 |
< |
break; |
896 |
< |
|
897 |
< |
default: |
898 |
< |
break; |
540 |
> |
if (name && !compare(name, conf->name)) |
541 |
> |
return conf; |
542 |
> |
if (host && !compare(host, conf->host)) |
543 |
> |
return conf; |
544 |
|
} |
545 |
+ |
|
546 |
|
return NULL; |
547 |
|
} |
548 |
|
|
556 |
|
* side effects - looks for an exact match on name field |
557 |
|
*/ |
558 |
|
struct MaskItem * |
559 |
< |
find_exact_name_conf(enum maskitem_type type, const struct Client *who, const char *name, |
914 |
< |
const char *user, const char *host) |
559 |
> |
operator_find(const struct Client *who, const char *name) |
560 |
|
{ |
561 |
< |
dlink_node *ptr = NULL; |
917 |
< |
struct MaskItem *conf; |
918 |
< |
dlink_list *list_p = map_to_list(type); |
561 |
> |
dlink_node *node = NULL; |
562 |
|
|
563 |
< |
switch(type) |
563 |
> |
DLINK_FOREACH(node, operator_items.head) |
564 |
|
{ |
565 |
< |
case CONF_XLINE: |
923 |
< |
case CONF_ULINE: |
924 |
< |
case CONF_NRESV: |
925 |
< |
case CONF_CRESV: |
565 |
> |
struct MaskItem *conf = node->data; |
566 |
|
|
567 |
< |
DLINK_FOREACH(ptr, list_p->head) |
567 |
> |
if (!irccmp(conf->name, name)) |
568 |
|
{ |
569 |
< |
conf = ptr->data; |
570 |
< |
|
931 |
< |
if (EmptyString(conf->name)) |
932 |
< |
continue; |
933 |
< |
|
934 |
< |
if (irccmp(conf->name, name) == 0) |
935 |
< |
{ |
936 |
< |
if ((user == NULL && (host == NULL))) |
937 |
< |
return (conf); |
938 |
< |
if (EmptyString(conf->user) || EmptyString(conf->host)) |
939 |
< |
return (conf); |
940 |
< |
if (!match(conf->user, user) && !match(conf->host, host)) |
941 |
< |
return (conf); |
942 |
< |
} |
943 |
< |
} |
944 |
< |
break; |
945 |
< |
|
946 |
< |
case CONF_OPER: |
947 |
< |
DLINK_FOREACH(ptr, list_p->head) |
948 |
< |
{ |
949 |
< |
conf = ptr->data; |
950 |
< |
|
951 |
< |
if (EmptyString(conf->name)) |
952 |
< |
continue; |
569 |
> |
if (!who) |
570 |
> |
return conf; |
571 |
|
|
572 |
< |
if (!irccmp(conf->name, name)) |
572 |
> |
if (!match(conf->user, who->username)) |
573 |
|
{ |
574 |
< |
if (!who) |
957 |
< |
return conf; |
958 |
< |
if (EmptyString(conf->user) || EmptyString(conf->host)) |
959 |
< |
return NULL; |
960 |
< |
if (!match(conf->user, who->username)) |
574 |
> |
switch (conf->htype) |
575 |
|
{ |
576 |
< |
switch (conf->htype) |
577 |
< |
{ |
578 |
< |
case HM_HOST: |
579 |
< |
if (!match(conf->host, who->host) || !match(conf->host, who->sockhost)) |
576 |
> |
case HM_HOST: |
577 |
> |
if (!match(conf->host, who->host) || !match(conf->host, who->sockhost)) |
578 |
> |
if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total) |
579 |
> |
return conf; |
580 |
> |
break; |
581 |
> |
case HM_IPV4: |
582 |
> |
if (who->connection->aftype == AF_INET) |
583 |
> |
if (match_ipv4(&who->connection->ip, &conf->addr, conf->bits)) |
584 |
|
if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total) |
585 |
|
return conf; |
586 |
< |
break; |
587 |
< |
case HM_IPV4: |
588 |
< |
if (who->localClient->aftype == AF_INET) |
589 |
< |
if (match_ipv4(&who->localClient->ip, &conf->addr, conf->bits)) |
590 |
< |
if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total) |
591 |
< |
return conf; |
592 |
< |
break; |
593 |
< |
#ifdef IPV6 |
594 |
< |
case HM_IPV6: |
977 |
< |
if (who->localClient->aftype == AF_INET6) |
978 |
< |
if (match_ipv6(&who->localClient->ip, &conf->addr, conf->bits)) |
979 |
< |
if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total) |
980 |
< |
return conf; |
981 |
< |
break; |
982 |
< |
#endif |
983 |
< |
default: |
984 |
< |
assert(0); |
985 |
< |
} |
586 |
> |
break; |
587 |
> |
case HM_IPV6: |
588 |
> |
if (who->connection->aftype == AF_INET6) |
589 |
> |
if (match_ipv6(&who->connection->ip, &conf->addr, conf->bits)) |
590 |
> |
if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total) |
591 |
> |
return conf; |
592 |
> |
break; |
593 |
> |
default: |
594 |
> |
assert(0); |
595 |
|
} |
596 |
|
} |
597 |
|
} |
989 |
– |
|
990 |
– |
break; |
991 |
– |
|
992 |
– |
case CONF_SERVER: |
993 |
– |
DLINK_FOREACH(ptr, list_p->head) |
994 |
– |
{ |
995 |
– |
conf = ptr->data; |
996 |
– |
|
997 |
– |
if (EmptyString(conf->name)) |
998 |
– |
continue; |
999 |
– |
|
1000 |
– |
if (name == NULL) |
1001 |
– |
{ |
1002 |
– |
if (EmptyString(conf->host)) |
1003 |
– |
continue; |
1004 |
– |
if (irccmp(conf->host, host) == 0) |
1005 |
– |
return(conf); |
1006 |
– |
} |
1007 |
– |
else if (irccmp(conf->name, name) == 0) |
1008 |
– |
{ |
1009 |
– |
return (conf); |
1010 |
– |
} |
1011 |
– |
} |
1012 |
– |
break; |
1013 |
– |
|
1014 |
– |
default: |
1015 |
– |
break; |
598 |
|
} |
1017 |
– |
return(NULL); |
1018 |
– |
} |
1019 |
– |
|
1020 |
– |
/* rehash() |
1021 |
– |
* |
1022 |
– |
* Actual REHASH service routine. Called with sig == 0 if it has been called |
1023 |
– |
* as a result of an operator issuing this command, else assume it has been |
1024 |
– |
* called as a result of the server receiving a HUP signal. |
1025 |
– |
*/ |
1026 |
– |
int |
1027 |
– |
rehash(int sig) |
1028 |
– |
{ |
1029 |
– |
if (sig != 0) |
1030 |
– |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1031 |
– |
"Got signal SIGHUP, reloading ircd.conf file"); |
1032 |
– |
|
1033 |
– |
restart_resolver(); |
599 |
|
|
600 |
< |
/* don't close listeners until we know we can go ahead with the rehash */ |
1036 |
< |
|
1037 |
< |
/* Check to see if we magically got(or lost) IPv6 support */ |
1038 |
< |
check_can_use_v6(); |
1039 |
< |
|
1040 |
< |
read_conf_files(0); |
1041 |
< |
|
1042 |
< |
if (ServerInfo.description != NULL) |
1043 |
< |
strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
1044 |
< |
|
1045 |
< |
load_conf_modules(); |
1046 |
< |
|
1047 |
< |
rehashed_klines = 1; |
1048 |
< |
|
1049 |
< |
return 0; |
600 |
> |
return NULL; |
601 |
|
} |
602 |
|
|
603 |
|
/* set_default_conf() |
617 |
|
*/ |
618 |
|
assert(class_default == class_get_list()->tail->data); |
619 |
|
|
620 |
< |
#ifdef HAVE_LIBCRYPTO |
621 |
< |
ServerInfo.rsa_private_key = NULL; |
622 |
< |
ServerInfo.rsa_private_key_file = NULL; |
623 |
< |
#endif |
624 |
< |
|
625 |
< |
/* ServerInfo.name is not rehashable */ |
626 |
< |
/* ServerInfo.name = ServerInfo.name; */ |
627 |
< |
ServerInfo.description = NULL; |
628 |
< |
ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT); |
629 |
< |
ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT); |
630 |
< |
|
631 |
< |
memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip)); |
1081 |
< |
ServerInfo.specific_ipv4_vhost = 0; |
1082 |
< |
memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6)); |
1083 |
< |
ServerInfo.specific_ipv6_vhost = 0; |
1084 |
< |
|
1085 |
< |
ServerInfo.max_clients = MAXCLIENTS_MAX; |
1086 |
< |
ServerInfo.max_nick_length = 9; |
1087 |
< |
ServerInfo.max_topic_length = 80; |
1088 |
< |
|
1089 |
< |
ServerInfo.hub = 0; |
1090 |
< |
ServerInfo.dns_host.sin_addr.s_addr = 0; |
1091 |
< |
ServerInfo.dns_host.sin_port = 0; |
1092 |
< |
AdminInfo.name = NULL; |
1093 |
< |
AdminInfo.email = NULL; |
1094 |
< |
AdminInfo.description = NULL; |
620 |
> |
ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT); |
621 |
> |
ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT); |
622 |
> |
|
623 |
> |
memset(&ConfigServerInfo.ip, 0, sizeof(ConfigServerInfo.ip)); |
624 |
> |
ConfigServerInfo.specific_ipv4_vhost = 0; |
625 |
> |
memset(&ConfigServerInfo.ip6, 0, sizeof(ConfigServerInfo.ip6)); |
626 |
> |
ConfigServerInfo.specific_ipv6_vhost = 0; |
627 |
> |
|
628 |
> |
ConfigServerInfo.default_max_clients = MAXCLIENTS_MAX; |
629 |
> |
ConfigServerInfo.max_nick_length = 9; |
630 |
> |
ConfigServerInfo.max_topic_length = 80; |
631 |
> |
ConfigServerInfo.hub = 0; |
632 |
|
|
633 |
|
log_del_all(); |
634 |
|
|
635 |
< |
ConfigLoggingEntry.use_logging = 1; |
635 |
> |
ConfigLog.use_logging = 1; |
636 |
|
|
637 |
|
ConfigChannel.disable_fake_channels = 0; |
638 |
< |
ConfigChannel.knock_delay = 300; |
638 |
> |
ConfigChannel.invite_client_count = 10; |
639 |
> |
ConfigChannel.invite_client_time = 300; |
640 |
> |
ConfigChannel.invite_delay_channel = 5; |
641 |
> |
ConfigChannel.invite_expire_time = 1800; |
642 |
> |
ConfigChannel.knock_client_count = 1; |
643 |
> |
ConfigChannel.knock_client_time = 300; |
644 |
|
ConfigChannel.knock_delay_channel = 60; |
645 |
< |
ConfigChannel.max_chans_per_user = 25; |
646 |
< |
ConfigChannel.max_chans_per_oper = 50; |
647 |
< |
ConfigChannel.max_bans = 25; |
648 |
< |
ConfigChannel.default_split_user_count = 0; |
649 |
< |
ConfigChannel.default_split_server_count = 0; |
650 |
< |
ConfigChannel.no_join_on_split = 0; |
1109 |
< |
ConfigChannel.no_create_on_split = 0; |
645 |
> |
ConfigChannel.max_channels = 25; |
646 |
> |
ConfigChannel.max_invites = 20; |
647 |
> |
ConfigChannel.max_bans = 100; |
648 |
> |
ConfigChannel.max_bans_large = 500; |
649 |
> |
ConfigChannel.default_join_flood_count = 18; |
650 |
> |
ConfigChannel.default_join_flood_time = 6; |
651 |
|
|
652 |
|
ConfigServerHide.flatten_links = 0; |
653 |
< |
ConfigServerHide.links_delay = 300; |
653 |
> |
ConfigServerHide.flatten_links_delay = 300; |
654 |
|
ConfigServerHide.hidden = 0; |
655 |
|
ConfigServerHide.hide_servers = 0; |
656 |
|
ConfigServerHide.hide_services = 0; |
657 |
|
ConfigServerHide.hidden_name = xstrdup(NETWORK_NAME_DEFAULT); |
658 |
|
ConfigServerHide.hide_server_ips = 0; |
659 |
+ |
ConfigServerHide.disable_remote_commands = 0; |
660 |
|
|
661 |
< |
|
662 |
< |
ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT); |
663 |
< |
ConfigFileEntry.max_watch = WATCHSIZE_DEFAULT; |
664 |
< |
ConfigFileEntry.glines = 0; |
665 |
< |
ConfigFileEntry.gline_time = 12 * 3600; |
666 |
< |
ConfigFileEntry.gline_request_time = GLINE_REQUEST_EXPIRE_DEFAULT; |
667 |
< |
ConfigFileEntry.gline_min_cidr = 16; |
668 |
< |
ConfigFileEntry.gline_min_cidr6 = 48; |
669 |
< |
ConfigFileEntry.invisible_on_connect = 1; |
670 |
< |
ConfigFileEntry.tkline_expire_notices = 1; |
671 |
< |
ConfigFileEntry.hide_spoof_ips = 1; |
672 |
< |
ConfigFileEntry.ignore_bogus_ts = 0; |
673 |
< |
ConfigFileEntry.disable_auth = 0; |
674 |
< |
ConfigFileEntry.disable_remote = 0; |
675 |
< |
ConfigFileEntry.kill_chase_time_limit = 90; |
676 |
< |
ConfigFileEntry.default_floodcount = 8; |
677 |
< |
ConfigFileEntry.failed_oper_notice = 1; |
678 |
< |
ConfigFileEntry.dots_in_ident = 0; |
679 |
< |
ConfigFileEntry.min_nonwildcard = 4; |
680 |
< |
ConfigFileEntry.min_nonwildcard_simple = 3; |
681 |
< |
ConfigFileEntry.max_accept = 20; |
682 |
< |
ConfigFileEntry.anti_nick_flood = 0; |
683 |
< |
ConfigFileEntry.max_nick_time = 20; |
684 |
< |
ConfigFileEntry.max_nick_changes = 5; |
685 |
< |
ConfigFileEntry.anti_spam_exit_message_time = 0; |
686 |
< |
ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT; |
687 |
< |
ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT; |
688 |
< |
ConfigFileEntry.warn_no_nline = 1; |
689 |
< |
ConfigFileEntry.stats_o_oper_only = 0; |
690 |
< |
ConfigFileEntry.stats_k_oper_only = 1; /* masked */ |
691 |
< |
ConfigFileEntry.stats_i_oper_only = 1; /* masked */ |
692 |
< |
ConfigFileEntry.stats_P_oper_only = 0; |
693 |
< |
ConfigFileEntry.caller_id_wait = 60; |
694 |
< |
ConfigFileEntry.opers_bypass_callerid = 0; |
695 |
< |
ConfigFileEntry.pace_wait = 10; |
696 |
< |
ConfigFileEntry.pace_wait_simple = 1; |
697 |
< |
ConfigFileEntry.short_motd = 0; |
698 |
< |
ConfigFileEntry.ping_cookie = 0; |
699 |
< |
ConfigFileEntry.no_oper_flood = 0; |
700 |
< |
ConfigFileEntry.true_no_oper_flood = 0; |
701 |
< |
ConfigFileEntry.oper_pass_resv = 1; |
702 |
< |
ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT; |
703 |
< |
ConfigFileEntry.oper_only_umodes = UMODE_DEBUG; |
704 |
< |
ConfigFileEntry.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE | |
705 |
< |
UMODE_OPERWALL | UMODE_WALLOP; |
706 |
< |
ConfigFileEntry.use_egd = 0; |
707 |
< |
ConfigFileEntry.egdpool_path = NULL; |
708 |
< |
ConfigFileEntry.throttle_time = 10; |
661 |
> |
ConfigGeneral.away_count = 2; |
662 |
> |
ConfigGeneral.away_time = 10; |
663 |
> |
ConfigGeneral.max_watch = 50; |
664 |
> |
ConfigGeneral.whowas_history_length = 15000; |
665 |
> |
ConfigGeneral.cycle_on_host_change = 1; |
666 |
> |
ConfigGeneral.dline_min_cidr = 16; |
667 |
> |
ConfigGeneral.dline_min_cidr6 = 48; |
668 |
> |
ConfigGeneral.kline_min_cidr = 16; |
669 |
> |
ConfigGeneral.kline_min_cidr6 = 48; |
670 |
> |
ConfigGeneral.invisible_on_connect = 1; |
671 |
> |
ConfigGeneral.tkline_expire_notices = 1; |
672 |
> |
ConfigGeneral.ignore_bogus_ts = 0; |
673 |
> |
ConfigGeneral.disable_auth = 0; |
674 |
> |
ConfigGeneral.kill_chase_time_limit = 90; |
675 |
> |
ConfigGeneral.default_floodcount = 8; |
676 |
> |
ConfigGeneral.default_floodtime = 1; |
677 |
> |
ConfigGeneral.failed_oper_notice = 1; |
678 |
> |
ConfigGeneral.dots_in_ident = 0; |
679 |
> |
ConfigGeneral.min_nonwildcard = 4; |
680 |
> |
ConfigGeneral.min_nonwildcard_simple = 3; |
681 |
> |
ConfigGeneral.max_accept = 50; |
682 |
> |
ConfigGeneral.anti_nick_flood = 0; |
683 |
> |
ConfigGeneral.max_nick_time = 20; |
684 |
> |
ConfigGeneral.max_nick_changes = 5; |
685 |
> |
ConfigGeneral.anti_spam_exit_message_time = 0; |
686 |
> |
ConfigGeneral.ts_warn_delta = 30; |
687 |
> |
ConfigGeneral.ts_max_delta = 600; |
688 |
> |
ConfigGeneral.warn_no_connect_block = 1; |
689 |
> |
ConfigGeneral.stats_e_disabled = 0; |
690 |
> |
ConfigGeneral.stats_i_oper_only = 1; /* 1 = masked */ |
691 |
> |
ConfigGeneral.stats_k_oper_only = 1; /* 1 = masked */ |
692 |
> |
ConfigGeneral.stats_o_oper_only = 1; |
693 |
> |
ConfigGeneral.stats_m_oper_only = 1; |
694 |
> |
ConfigGeneral.stats_P_oper_only = 0; |
695 |
> |
ConfigGeneral.stats_u_oper_only = 0; |
696 |
> |
ConfigGeneral.caller_id_wait = 60; |
697 |
> |
ConfigGeneral.opers_bypass_callerid = 1; |
698 |
> |
ConfigGeneral.pace_wait = 10; |
699 |
> |
ConfigGeneral.pace_wait_simple = 1; |
700 |
> |
ConfigGeneral.short_motd = 0; |
701 |
> |
ConfigGeneral.ping_cookie = 0; |
702 |
> |
ConfigGeneral.no_oper_flood = 0; |
703 |
> |
ConfigGeneral.max_targets = MAX_TARGETS_DEFAULT; |
704 |
> |
ConfigGeneral.oper_only_umodes = UMODE_DEBUG | UMODE_LOCOPS | UMODE_HIDDEN | UMODE_FARCONNECT | |
705 |
> |
UMODE_UNAUTH | UMODE_EXTERNAL | UMODE_BOTS | UMODE_NCHANGE | |
706 |
> |
UMODE_SPY | UMODE_FULL | UMODE_SKILL | UMODE_REJ | UMODE_CCONN; |
707 |
> |
ConfigGeneral.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE | UMODE_WALLOP; |
708 |
> |
ConfigGeneral.throttle_count = 1; |
709 |
> |
ConfigGeneral.throttle_time = 1; |
710 |
|
} |
711 |
|
|
712 |
|
static void |
713 |
|
validate_conf(void) |
714 |
|
{ |
715 |
< |
if (ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN) |
716 |
< |
ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT; |
1174 |
< |
|
1175 |
< |
if (ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN) |
1176 |
< |
ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT; |
1177 |
< |
|
1178 |
< |
if (ServerInfo.network_name == NULL) |
1179 |
< |
ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT); |
1180 |
< |
|
1181 |
< |
if (ServerInfo.network_desc == NULL) |
1182 |
< |
ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT); |
1183 |
< |
|
1184 |
< |
if (ConfigFileEntry.service_name == NULL) |
1185 |
< |
ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT); |
715 |
> |
if (EmptyString(ConfigServerInfo.network_name)) |
716 |
> |
ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT); |
717 |
|
|
718 |
< |
ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN); |
718 |
> |
if (EmptyString(ConfigServerInfo.network_desc)) |
719 |
> |
ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT); |
720 |
|
} |
721 |
|
|
722 |
< |
/* read_conf() |
722 |
> |
/* read_conf() |
723 |
|
* |
724 |
|
* inputs - file descriptor pointing to config file to use |
725 |
|
* output - None |
728 |
|
static void |
729 |
|
read_conf(FILE *file) |
730 |
|
{ |
731 |
< |
lineno = 0; |
731 |
> |
lineno = 1; |
732 |
|
|
733 |
< |
set_default_conf(); /* Set default values prior to conf parsing */ |
733 |
> |
set_default_conf(); /* Set default values prior to conf parsing */ |
734 |
|
conf_parser_ctx.pass = 1; |
735 |
< |
yyparse(); /* pick up the classes first */ |
735 |
> |
yyparse(); /* Pick up the classes first */ |
736 |
|
|
737 |
|
rewind(file); |
738 |
|
|
739 |
|
conf_parser_ctx.pass = 2; |
740 |
< |
yyparse(); /* Load the values from the conf */ |
741 |
< |
validate_conf(); /* Check to make sure some values are still okay. */ |
742 |
< |
/* Some global values are also loaded here. */ |
743 |
< |
class_delete_marked(); /* Make sure classes are valid */ |
740 |
> |
yyparse(); /* Load the values from the conf */ |
741 |
> |
validate_conf(); /* Check to make sure some values are still okay. */ |
742 |
> |
/* Some global values are also loaded here. */ |
743 |
> |
whowas_trim(); /* Attempt to trim whowas list if necessary */ |
744 |
> |
class_delete_marked(); /* Delete unused classes that are marked for deletion */ |
745 |
> |
} |
746 |
> |
|
747 |
> |
/* conf_rehash() |
748 |
> |
* |
749 |
> |
* Actual REHASH service routine. Called with sig == 0 if it has been called |
750 |
> |
* as a result of an operator issuing this command, else assume it has been |
751 |
> |
* called as a result of the server receiving a HUP signal. |
752 |
> |
*/ |
753 |
> |
void |
754 |
> |
conf_rehash(int sig) |
755 |
> |
{ |
756 |
> |
if (sig) |
757 |
> |
{ |
758 |
> |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
759 |
> |
"Got signal SIGHUP, reloading configuration file(s)"); |
760 |
> |
ilog(LOG_TYPE_IRCD, "Got signal SIGHUP, reloading configuration file(s)"); |
761 |
> |
} |
762 |
> |
|
763 |
> |
restart_resolver(); |
764 |
> |
|
765 |
> |
/* don't close listeners until we know we can go ahead with the rehash */ |
766 |
> |
|
767 |
> |
read_conf_files(0); |
768 |
> |
|
769 |
> |
load_conf_modules(); |
770 |
> |
check_conf_klines(); |
771 |
|
} |
772 |
|
|
773 |
|
/* lookup_confhost() |
780 |
|
{ |
781 |
|
struct addrinfo hints, *res; |
782 |
|
|
783 |
< |
/* Do name lookup now on hostnames given and store the |
783 |
> |
/* |
784 |
> |
* Do name lookup now on hostnames given and store the |
785 |
|
* ip numbers in conf structure. |
786 |
|
*/ |
787 |
|
memset(&hints, 0, sizeof(hints)); |
798 |
|
return; |
799 |
|
} |
800 |
|
|
801 |
< |
assert(res != NULL); |
801 |
> |
assert(res); |
802 |
|
|
803 |
|
memcpy(&conf->addr, res->ai_addr, res->ai_addrlen); |
804 |
|
conf->addr.ss_len = res->ai_addrlen; |
817 |
|
int |
818 |
|
conf_connect_allowed(struct irc_ssaddr *addr, int aftype) |
819 |
|
{ |
820 |
< |
struct ip_entry *ip_found; |
821 |
< |
struct MaskItem *conf = find_dline_conf(addr, aftype); |
1262 |
< |
|
1263 |
< |
/* DLINE exempt also gets you out of static limits/pacing... */ |
1264 |
< |
if (conf && (conf->type == CONF_EXEMPT)) |
1265 |
< |
return 0; |
820 |
> |
struct ip_entry *ip_found = NULL; |
821 |
> |
const struct MaskItem *conf = find_dline_conf(addr, aftype); |
822 |
|
|
823 |
< |
if (conf != NULL) |
823 |
> |
if (conf) |
824 |
> |
{ |
825 |
> |
/* DLINE exempt also gets you out of static limits/pacing... */ |
826 |
> |
if (conf->type == CONF_EXEMPT) |
827 |
> |
return 0; |
828 |
|
return BANNED_CLIENT; |
829 |
+ |
} |
830 |
|
|
831 |
< |
ip_found = find_or_add_ip(addr); |
831 |
> |
ip_found = ipcache_find_or_add_address(addr); |
832 |
|
|
833 |
< |
if ((CurrentTime - ip_found->last_attempt) < |
1273 |
< |
ConfigFileEntry.throttle_time) |
833 |
> |
if ((CurrentTime - ip_found->last_attempt) < ConfigGeneral.throttle_time) |
834 |
|
{ |
835 |
< |
ip_found->last_attempt = CurrentTime; |
836 |
< |
return TOO_FAST; |
835 |
> |
if (ip_found->connection_count >= ConfigGeneral.throttle_count) |
836 |
> |
return TOO_FAST; |
837 |
> |
|
838 |
> |
++ip_found->connection_count; |
839 |
|
} |
840 |
+ |
else |
841 |
+ |
ip_found->connection_count = 1; |
842 |
|
|
843 |
|
ip_found->last_attempt = CurrentTime; |
844 |
|
return 0; |
845 |
|
} |
846 |
|
|
1283 |
– |
/* find_kill() |
1284 |
– |
* |
1285 |
– |
* inputs - pointer to client structure |
1286 |
– |
* output - pointer to struct MaskItem if found |
1287 |
– |
* side effects - See if this user is klined already, |
1288 |
– |
* and if so, return struct MaskItem pointer |
1289 |
– |
*/ |
1290 |
– |
struct MaskItem * |
1291 |
– |
find_kill(struct Client *client_p) |
1292 |
– |
{ |
1293 |
– |
struct MaskItem *conf = NULL; |
1294 |
– |
|
1295 |
– |
assert(client_p != NULL); |
1296 |
– |
|
1297 |
– |
conf = find_conf_by_address(client_p->host, &client_p->localClient->ip, |
1298 |
– |
CONF_KLINE, client_p->localClient->aftype, |
1299 |
– |
client_p->username, NULL, 1); |
1300 |
– |
return conf; |
1301 |
– |
} |
1302 |
– |
|
1303 |
– |
struct MaskItem * |
1304 |
– |
find_gline(struct Client *client_p) |
1305 |
– |
{ |
1306 |
– |
struct MaskItem *conf; |
1307 |
– |
|
1308 |
– |
assert(client_p != NULL); |
1309 |
– |
|
1310 |
– |
conf = find_conf_by_address(client_p->host, &client_p->localClient->ip, |
1311 |
– |
CONF_GLINE, client_p->localClient->aftype, |
1312 |
– |
client_p->username, NULL, 1); |
1313 |
– |
return conf; |
1314 |
– |
} |
1315 |
– |
|
847 |
|
/* cleanup_tklines() |
848 |
|
* |
849 |
|
* inputs - NONE |
852 |
|
* This is an event started off in ircd.c |
853 |
|
*/ |
854 |
|
void |
855 |
< |
cleanup_tklines(void *notused) |
855 |
> |
cleanup_tklines(void *unused) |
856 |
|
{ |
857 |
|
hostmask_expire_temporary(); |
858 |
< |
expire_tklines(&xconf_items); |
859 |
< |
expire_tklines(&nresv_items); |
1329 |
< |
expire_tklines(&resv_channel_list); |
1330 |
< |
} |
1331 |
< |
|
1332 |
< |
/* expire_tklines() |
1333 |
< |
* |
1334 |
< |
* inputs - tkline list pointer |
1335 |
< |
* output - NONE |
1336 |
< |
* side effects - expire tklines |
1337 |
< |
*/ |
1338 |
< |
static void |
1339 |
< |
expire_tklines(dlink_list *tklist) |
1340 |
< |
{ |
1341 |
< |
dlink_node *ptr; |
1342 |
< |
dlink_node *next_ptr; |
1343 |
< |
struct MaskItem *conf; |
1344 |
< |
|
1345 |
< |
DLINK_FOREACH_SAFE(ptr, next_ptr, tklist->head) |
1346 |
< |
{ |
1347 |
< |
conf = ptr->data; |
1348 |
< |
|
1349 |
< |
if (!conf->until || conf->until > CurrentTime) |
1350 |
< |
continue; |
1351 |
< |
|
1352 |
< |
if (conf->type == CONF_XLINE) |
1353 |
< |
{ |
1354 |
< |
if (ConfigFileEntry.tkline_expire_notices) |
1355 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1356 |
< |
"Temporary X-line for [%s] expired", conf->name); |
1357 |
< |
conf_free(conf); |
1358 |
< |
} |
1359 |
< |
else if (conf->type == CONF_NRESV || conf->type == CONF_CRESV) |
1360 |
< |
{ |
1361 |
< |
if (ConfigFileEntry.tkline_expire_notices) |
1362 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1363 |
< |
"Temporary RESV for [%s] expired", conf->name); |
1364 |
< |
conf_free(conf); |
1365 |
< |
} |
1366 |
< |
} |
858 |
> |
gecos_expire(); |
859 |
> |
resv_expire(); |
860 |
|
} |
861 |
|
|
862 |
|
/* oper_privs_as_string() |
865 |
|
* output - pointer to static string showing oper privs |
866 |
|
* side effects - return as string, the oper privs as derived from port |
867 |
|
*/ |
868 |
< |
static const struct oper_privs |
868 |
> |
static const struct oper_flags |
869 |
|
{ |
870 |
|
const unsigned int flag; |
871 |
|
const unsigned char c; |
872 |
< |
} flag_list[] = { |
872 |
> |
} flag_table[] = { |
873 |
|
{ OPER_FLAG_ADMIN, 'A' }, |
874 |
< |
{ OPER_FLAG_REMOTEBAN, 'B' }, |
875 |
< |
{ OPER_FLAG_DIE, 'D' }, |
876 |
< |
{ OPER_FLAG_GLINE, 'G' }, |
877 |
< |
{ OPER_FLAG_REHASH, 'H' }, |
878 |
< |
{ OPER_FLAG_K, 'K' }, |
879 |
< |
{ OPER_FLAG_OPERWALL, 'L' }, |
880 |
< |
{ OPER_FLAG_KILL, 'N' }, |
881 |
< |
{ OPER_FLAG_KILL_REMOTE, 'O' }, |
882 |
< |
{ OPER_FLAG_CONNECT, 'P' }, |
883 |
< |
{ OPER_FLAG_CONNECT_REMOTE, 'Q' }, |
884 |
< |
{ OPER_FLAG_SQUIT, 'R' }, |
885 |
< |
{ OPER_FLAG_SQUIT_REMOTE, 'S' }, |
886 |
< |
{ OPER_FLAG_UNKLINE, 'U' }, |
887 |
< |
{ OPER_FLAG_X, 'X' }, |
874 |
> |
{ OPER_FLAG_CLOSE, 'B' }, |
875 |
> |
{ OPER_FLAG_CONNECT, 'C' }, |
876 |
> |
{ OPER_FLAG_CONNECT_REMOTE, 'D' }, |
877 |
> |
{ OPER_FLAG_DIE, 'E' }, |
878 |
> |
{ OPER_FLAG_DLINE, 'F' }, |
879 |
> |
{ OPER_FLAG_GLOBOPS, 'G' }, |
880 |
> |
{ OPER_FLAG_JOIN_RESV, 'H' }, |
881 |
> |
{ OPER_FLAG_KILL, 'I' }, |
882 |
> |
{ OPER_FLAG_KILL_REMOTE, 'J' }, |
883 |
> |
{ OPER_FLAG_KLINE, 'K' }, |
884 |
> |
{ OPER_FLAG_LOCOPS, 'L' }, |
885 |
> |
{ OPER_FLAG_MODULE, 'M' }, |
886 |
> |
{ OPER_FLAG_NICK_RESV, 'N' }, |
887 |
> |
{ OPER_FLAG_OPME, 'O' }, |
888 |
> |
{ OPER_FLAG_REHASH, 'P' }, |
889 |
> |
{ OPER_FLAG_REMOTEBAN, 'Q' }, |
890 |
> |
{ OPER_FLAG_RESTART, 'R' }, |
891 |
> |
{ OPER_FLAG_RESV, 'S' }, |
892 |
> |
{ OPER_FLAG_SET, 'T' }, |
893 |
> |
{ OPER_FLAG_SQUIT, 'U' }, |
894 |
> |
{ OPER_FLAG_SQUIT_REMOTE, 'V' }, |
895 |
> |
{ OPER_FLAG_UNDLINE, 'W' }, |
896 |
> |
{ OPER_FLAG_UNKLINE, 'X' }, |
897 |
> |
{ OPER_FLAG_UNRESV, 'Y' }, |
898 |
> |
{ OPER_FLAG_UNXLINE, 'Z' }, |
899 |
> |
{ OPER_FLAG_WALLOPS, 'a' }, |
900 |
> |
{ OPER_FLAG_XLINE, 'b' }, |
901 |
|
{ 0, '\0' } |
902 |
|
}; |
903 |
|
|
904 |
< |
char * |
905 |
< |
oper_privs_as_string(const unsigned int port) |
904 |
> |
const char * |
905 |
> |
oper_privs_as_string(const unsigned int flags) |
906 |
|
{ |
907 |
< |
static char privs_out[16]; |
908 |
< |
char *privs_ptr = privs_out; |
1403 |
< |
const struct oper_privs *opriv = flag_list; |
907 |
> |
static char buf[sizeof(flag_table) / sizeof(flag_table[0])]; |
908 |
> |
char *p = buf; |
909 |
|
|
910 |
< |
for (; opriv->flag; ++opriv) |
911 |
< |
{ |
912 |
< |
if (port & opriv->flag) |
913 |
< |
*privs_ptr++ = opriv->c; |
914 |
< |
else |
915 |
< |
*privs_ptr++ = ToLower(opriv->c); |
1411 |
< |
} |
910 |
> |
for (const struct oper_flags *tab = flag_table; tab->flag; ++tab) |
911 |
> |
if (flags & tab->flag) |
912 |
> |
*p++ = tab->c; |
913 |
> |
|
914 |
> |
if (p == buf) |
915 |
> |
*p++ = '0'; |
916 |
|
|
917 |
< |
*privs_ptr = '\0'; |
917 |
> |
*p = '\0'; |
918 |
|
|
919 |
< |
return privs_out; |
919 |
> |
return buf; |
920 |
|
} |
921 |
|
|
922 |
|
/* |
923 |
< |
* Input: A client to find the active oper{} name for. |
923 |
> |
* Input: A client to find the active operator {} name for. |
924 |
|
* Output: The nick!user@host{oper} of the oper. |
925 |
|
* "oper" is server name for remote opers |
926 |
|
* Side effects: None. |
928 |
|
const char * |
929 |
|
get_oper_name(const struct Client *client_p) |
930 |
|
{ |
931 |
< |
dlink_node *cnode = NULL; |
932 |
< |
/* +5 for !,@,{,} and null */ |
933 |
< |
static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5]; |
931 |
> |
static char buffer[IRCD_BUFSIZE]; |
932 |
> |
|
933 |
> |
if (IsServer(client_p)) |
934 |
> |
return client_p->name; |
935 |
|
|
936 |
|
if (MyConnect(client_p)) |
937 |
|
{ |
938 |
< |
if ((cnode = client_p->localClient->confs.head)) |
938 |
> |
const dlink_node *const node = client_p->connection->confs.head; |
939 |
> |
|
940 |
> |
if (node) |
941 |
|
{ |
942 |
< |
struct MaskItem *conf = cnode->data; |
942 |
> |
const struct MaskItem *const conf = node->data; |
943 |
|
|
944 |
< |
if (IsConfOperator(conf)) |
944 |
> |
if (conf->type == CONF_OPER) |
945 |
|
{ |
946 |
< |
snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name, |
946 |
> |
snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name, |
947 |
|
client_p->username, client_p->host, conf->name); |
948 |
< |
return buffer; |
948 |
> |
return buffer; |
949 |
|
} |
950 |
|
} |
951 |
|
|
952 |
< |
/* Probably should assert here for now. If there is an oper out there |
953 |
< |
* with no oper{} conf attached, it would be good for us to know... |
952 |
> |
/* |
953 |
> |
* Probably should assert here for now. If there is an oper out there |
954 |
> |
* with no operator {} conf attached, it would be good for us to know... |
955 |
|
*/ |
956 |
< |
assert(0); /* Oper without oper conf! */ |
956 |
> |
assert(0); /* Oper without oper conf! */ |
957 |
|
} |
958 |
|
|
959 |
|
snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name, |
960 |
< |
client_p->username, client_p->host, client_p->servptr->name); |
960 |
> |
client_p->username, client_p->host, client_p->servptr->name); |
961 |
|
return buffer; |
962 |
|
} |
963 |
|
|
964 |
+ |
/* clear_out_old_conf() |
965 |
+ |
* |
966 |
+ |
* inputs - none |
967 |
+ |
* output - none |
968 |
+ |
* side effects - Clear out the old configuration |
969 |
+ |
*/ |
970 |
+ |
static void |
971 |
+ |
clear_out_old_conf(void) |
972 |
+ |
{ |
973 |
+ |
dlink_node *node = NULL, *node_next = NULL; |
974 |
+ |
dlink_list *free_items [] = { |
975 |
+ |
&connect_items, &operator_items, NULL |
976 |
+ |
}; |
977 |
+ |
|
978 |
+ |
dlink_list ** iterator = free_items; /* C is dumb */ |
979 |
+ |
|
980 |
+ |
/* We only need to free anything allocated by yyparse() here. |
981 |
+ |
* Resetting structs, etc, is taken care of by set_default_conf(). |
982 |
+ |
*/ |
983 |
+ |
|
984 |
+ |
for (; *iterator; iterator++) |
985 |
+ |
{ |
986 |
+ |
DLINK_FOREACH_SAFE(node, node_next, (*iterator)->head) |
987 |
+ |
{ |
988 |
+ |
struct MaskItem *conf = node->data; |
989 |
+ |
|
990 |
+ |
conf->active = 0; |
991 |
+ |
dlinkDelete(&conf->node, *iterator); |
992 |
+ |
|
993 |
+ |
if (!conf->ref_count) |
994 |
+ |
conf_free(conf); |
995 |
+ |
} |
996 |
+ |
} |
997 |
+ |
|
998 |
+ |
/* |
999 |
+ |
* Don't delete the class table, rather mark all entries for deletion. |
1000 |
+ |
* The table is cleaned up by class_delete_marked. - avalon |
1001 |
+ |
*/ |
1002 |
+ |
class_mark_for_deletion(); |
1003 |
+ |
|
1004 |
+ |
clear_out_address_conf(); |
1005 |
+ |
|
1006 |
+ |
modules_conf_clear(); /* Clear modules {} items */ |
1007 |
+ |
|
1008 |
+ |
motd_clear(); /* Clear motd {} items and re-cache default motd */ |
1009 |
+ |
|
1010 |
+ |
cluster_clear(); /* Clear cluster {} items */ |
1011 |
+ |
|
1012 |
+ |
gecos_clear(); /* Clear gecos {} items */ |
1013 |
+ |
|
1014 |
+ |
resv_clear(); /* Clear resv {} items */ |
1015 |
+ |
|
1016 |
+ |
service_clear(); /* Clear service {} items */ |
1017 |
+ |
|
1018 |
+ |
shared_clear(); /* Clear shared {} items */ |
1019 |
+ |
|
1020 |
+ |
pseudo_clear(); /* Clear pseudo {} items */ |
1021 |
+ |
|
1022 |
+ |
/* Clean out ConfigServerInfo */ |
1023 |
+ |
xfree(ConfigServerInfo.description); |
1024 |
+ |
ConfigServerInfo.description = NULL; |
1025 |
+ |
xfree(ConfigServerInfo.network_name); |
1026 |
+ |
ConfigServerInfo.network_name = NULL; |
1027 |
+ |
xfree(ConfigServerInfo.network_desc); |
1028 |
+ |
ConfigServerInfo.network_desc = NULL; |
1029 |
+ |
xfree(ConfigServerInfo.rsa_private_key_file); |
1030 |
+ |
ConfigServerInfo.rsa_private_key_file = NULL; |
1031 |
+ |
xfree(ConfigServerInfo.ssl_certificate_file); |
1032 |
+ |
ConfigServerInfo.ssl_certificate_file = NULL; |
1033 |
+ |
xfree(ConfigServerInfo.ssl_dh_param_file); |
1034 |
+ |
ConfigServerInfo.ssl_dh_param_file = NULL; |
1035 |
+ |
xfree(ConfigServerInfo.ssl_dh_elliptic_curve); |
1036 |
+ |
ConfigServerInfo.ssl_dh_elliptic_curve = NULL; |
1037 |
+ |
xfree(ConfigServerInfo.ssl_cipher_list); |
1038 |
+ |
ConfigServerInfo.ssl_cipher_list = NULL; |
1039 |
+ |
xfree(ConfigServerInfo.ssl_message_digest_algorithm); |
1040 |
+ |
ConfigServerInfo.ssl_message_digest_algorithm = NULL; |
1041 |
+ |
|
1042 |
+ |
/* Clean out ConfigAdminInfo */ |
1043 |
+ |
xfree(ConfigAdminInfo.name); |
1044 |
+ |
ConfigAdminInfo.name = NULL; |
1045 |
+ |
xfree(ConfigAdminInfo.email); |
1046 |
+ |
ConfigAdminInfo.email = NULL; |
1047 |
+ |
xfree(ConfigAdminInfo.description); |
1048 |
+ |
ConfigAdminInfo.description = NULL; |
1049 |
+ |
|
1050 |
+ |
xfree(ConfigServerHide.flatten_links_file); |
1051 |
+ |
ConfigServerHide.flatten_links_file = NULL; |
1052 |
+ |
|
1053 |
+ |
/* Clean out listeners */ |
1054 |
+ |
listener_close_marked(); |
1055 |
+ |
} |
1056 |
+ |
|
1057 |
+ |
static void |
1058 |
+ |
conf_handle_tls(int cold) |
1059 |
+ |
{ |
1060 |
+ |
if (!tls_new_cred()) |
1061 |
+ |
{ |
1062 |
+ |
if (cold) |
1063 |
+ |
{ |
1064 |
+ |
ilog(LOG_TYPE_IRCD, "Error while initializing TLS"); |
1065 |
+ |
exit(EXIT_FAILURE); |
1066 |
+ |
} |
1067 |
+ |
else |
1068 |
+ |
{ |
1069 |
+ |
/* Failed to load new settings/certs, old ones remain active */ |
1070 |
+ |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
1071 |
+ |
"Error reloading TLS settings, check the ircd log"); // report_crypto_errors logs this |
1072 |
+ |
} |
1073 |
+ |
} |
1074 |
+ |
} |
1075 |
+ |
|
1076 |
|
/* read_conf_files() |
1077 |
|
* |
1078 |
|
* inputs - cold start YES or NO |
1082 |
|
void |
1083 |
|
read_conf_files(int cold) |
1084 |
|
{ |
1085 |
< |
const char *filename; |
1086 |
< |
char chanmodes[32]; |
1087 |
< |
char chanlimit[32]; |
1085 |
> |
const char *filename = NULL; |
1086 |
> |
char chanmodes[IRCD_BUFSIZE] = ""; |
1087 |
> |
char chanlimit[IRCD_BUFSIZE] = ""; |
1088 |
|
|
1089 |
|
conf_parser_ctx.boot = cold; |
1090 |
< |
filename = ConfigFileEntry.configfile; |
1090 |
> |
filename = ConfigGeneral.configfile; |
1091 |
|
|
1092 |
|
/* We need to know the initial filename for the yyerror() to report |
1093 |
|
FIXME: The full path is in conffilenamebuf first time since we |
1094 |
< |
dont know anything else |
1094 |
> |
don't know anything else |
1095 |
|
|
1096 |
< |
- Gozem 2002-07-21 |
1096 |
> |
- Gozem 2002-07-21 |
1097 |
|
*/ |
1098 |
|
strlcpy(conffilebuf, filename, sizeof(conffilebuf)); |
1099 |
|
|
1103 |
|
{ |
1104 |
|
ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s", |
1105 |
|
filename, strerror(errno)); |
1106 |
< |
exit(-1); |
1106 |
> |
exit(EXIT_FAILURE); |
1107 |
|
} |
1108 |
|
else |
1109 |
|
{ |
1110 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1111 |
< |
"Unable to read configuration file '%s': %s", |
1112 |
< |
filename, strerror(errno)); |
1110 |
> |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
1111 |
> |
"Unable to read configuration file '%s': %s", |
1112 |
> |
filename, strerror(errno)); |
1113 |
|
return; |
1114 |
|
} |
1115 |
|
} |
1121 |
|
fclose(conf_parser_ctx.conf_file); |
1122 |
|
|
1123 |
|
log_reopen_all(); |
1124 |
+ |
conf_handle_tls(cold); |
1125 |
|
|
1126 |
< |
add_isupport("NICKLEN", NULL, ServerInfo.max_nick_length); |
1127 |
< |
add_isupport("NETWORK", ServerInfo.network_name, -1); |
1507 |
< |
|
1508 |
< |
snprintf(chanmodes, sizeof(chanmodes), "beI:%d", ConfigChannel.max_bans); |
1509 |
< |
add_isupport("MAXLIST", chanmodes, -1); |
1510 |
< |
add_isupport("MAXTARGETS", NULL, ConfigFileEntry.max_targets); |
1511 |
< |
add_isupport("CHANTYPES", "#", -1); |
1512 |
< |
|
1513 |
< |
snprintf(chanlimit, sizeof(chanlimit), "#:%d", |
1514 |
< |
ConfigChannel.max_chans_per_user); |
1515 |
< |
add_isupport("CHANLIMIT", chanlimit, -1); |
1516 |
< |
snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,imnprstORS"); |
1517 |
< |
add_isupport("CHANNELLEN", NULL, LOCAL_CHANNELLEN); |
1518 |
< |
add_isupport("TOPICLEN", NULL, ServerInfo.max_topic_length); |
1519 |
< |
add_isupport("EXCEPTS", "e", -1); |
1520 |
< |
add_isupport("INVEX", "I", -1); |
1521 |
< |
add_isupport("CHANMODES", chanmodes, -1); |
1522 |
< |
|
1523 |
< |
/* |
1524 |
< |
* message_locale may have changed. rebuild isupport since it relies |
1525 |
< |
* on strlen(form_str(RPL_ISUPPORT)) |
1526 |
< |
*/ |
1527 |
< |
rebuild_isupport_message_line(); |
1528 |
< |
} |
1529 |
< |
|
1530 |
< |
/* clear_out_old_conf() |
1531 |
< |
* |
1532 |
< |
* inputs - none |
1533 |
< |
* output - none |
1534 |
< |
* side effects - Clear out the old configuration |
1535 |
< |
*/ |
1536 |
< |
static void |
1537 |
< |
clear_out_old_conf(void) |
1538 |
< |
{ |
1539 |
< |
dlink_node *ptr = NULL, *next_ptr = NULL; |
1540 |
< |
struct MaskItem *conf; |
1541 |
< |
dlink_list *free_items [] = { |
1542 |
< |
&server_items, &oconf_items, |
1543 |
< |
&uconf_items, &xconf_items, |
1544 |
< |
&nresv_items, &cluster_items, &service_items, &resv_channel_list, NULL |
1545 |
< |
}; |
1546 |
< |
|
1547 |
< |
dlink_list ** iterator = free_items; /* C is dumb */ |
1548 |
< |
|
1549 |
< |
/* We only need to free anything allocated by yyparse() here. |
1550 |
< |
* Resetting structs, etc, is taken care of by set_default_conf(). |
1551 |
< |
*/ |
1552 |
< |
|
1553 |
< |
for (; *iterator != NULL; iterator++) |
1554 |
< |
{ |
1555 |
< |
DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head) |
1556 |
< |
{ |
1557 |
< |
conf = ptr->data; |
1558 |
< |
|
1559 |
< |
dlinkDelete(&conf->node, map_to_list(conf->type)); |
1126 |
> |
isupport_add("NICKLEN", NULL, ConfigServerInfo.max_nick_length); |
1127 |
> |
isupport_add("NETWORK", ConfigServerInfo.network_name, -1); |
1128 |
|
|
1129 |
< |
/* XXX This is less than pretty */ |
1130 |
< |
if (conf->type == CONF_SERVER || conf->type == CONF_OPER) |
1131 |
< |
{ |
1132 |
< |
if (!conf->ref_count) |
1133 |
< |
conf_free(conf); |
1134 |
< |
} |
1135 |
< |
else if (conf->type == CONF_XLINE) |
1136 |
< |
{ |
1137 |
< |
if (!conf->until) |
1138 |
< |
conf_free(conf); |
1139 |
< |
} |
1140 |
< |
else |
1573 |
< |
conf_free(conf); |
1574 |
< |
} |
1575 |
< |
} |
1576 |
< |
|
1577 |
< |
/* |
1578 |
< |
* don't delete the class table, rather mark all entries |
1579 |
< |
* for deletion. The table is cleaned up by class_delete_marked. - avalon |
1580 |
< |
*/ |
1581 |
< |
class_mark_for_deletion(); |
1582 |
< |
|
1583 |
< |
clear_out_address_conf(); |
1584 |
< |
|
1585 |
< |
/* clean out module paths */ |
1586 |
< |
mod_clear_paths(); |
1587 |
< |
|
1588 |
< |
/* clean out ServerInfo */ |
1589 |
< |
MyFree(ServerInfo.description); |
1590 |
< |
ServerInfo.description = NULL; |
1591 |
< |
MyFree(ServerInfo.network_name); |
1592 |
< |
ServerInfo.network_name = NULL; |
1593 |
< |
MyFree(ServerInfo.network_desc); |
1594 |
< |
ServerInfo.network_desc = NULL; |
1595 |
< |
MyFree(ConfigFileEntry.egdpool_path); |
1596 |
< |
ConfigFileEntry.egdpool_path = NULL; |
1597 |
< |
#ifdef HAVE_LIBCRYPTO |
1598 |
< |
if (ServerInfo.rsa_private_key != NULL) |
1599 |
< |
{ |
1600 |
< |
RSA_free(ServerInfo.rsa_private_key); |
1601 |
< |
ServerInfo.rsa_private_key = NULL; |
1602 |
< |
} |
1603 |
< |
|
1604 |
< |
MyFree(ServerInfo.rsa_private_key_file); |
1605 |
< |
ServerInfo.rsa_private_key_file = NULL; |
1606 |
< |
|
1607 |
< |
if (ServerInfo.server_ctx) |
1608 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2| |
1609 |
< |
SSL_OP_NO_SSLv3| |
1610 |
< |
SSL_OP_NO_TLSv1); |
1611 |
< |
if (ServerInfo.client_ctx) |
1612 |
< |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2| |
1613 |
< |
SSL_OP_NO_SSLv3| |
1614 |
< |
SSL_OP_NO_TLSv1); |
1615 |
< |
#endif |
1616 |
< |
|
1617 |
< |
/* clean out AdminInfo */ |
1618 |
< |
MyFree(AdminInfo.name); |
1619 |
< |
AdminInfo.name = NULL; |
1620 |
< |
MyFree(AdminInfo.email); |
1621 |
< |
AdminInfo.email = NULL; |
1622 |
< |
MyFree(AdminInfo.description); |
1623 |
< |
AdminInfo.description = NULL; |
1624 |
< |
|
1625 |
< |
/* clean out listeners */ |
1626 |
< |
close_listeners(); |
1627 |
< |
|
1628 |
< |
/* clean out general */ |
1629 |
< |
MyFree(ConfigFileEntry.service_name); |
1630 |
< |
ConfigFileEntry.service_name = NULL; |
1631 |
< |
|
1632 |
< |
delete_isupport("INVEX"); |
1633 |
< |
delete_isupport("EXCEPTS"); |
1129 |
> |
snprintf(chanmodes, sizeof(chanmodes), "beI:%u", ConfigChannel.max_bans); |
1130 |
> |
isupport_add("MAXLIST", chanmodes, -1); |
1131 |
> |
isupport_add("MAXTARGETS", NULL, ConfigGeneral.max_targets); |
1132 |
> |
isupport_add("CHANTYPES", "#", -1); |
1133 |
> |
|
1134 |
> |
snprintf(chanlimit, sizeof(chanlimit), "#:%u", |
1135 |
> |
ConfigChannel.max_channels); |
1136 |
> |
isupport_add("CHANLIMIT", chanlimit, -1); |
1137 |
> |
snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,cimnprstuCLMORST"); |
1138 |
> |
isupport_add("CHANNELLEN", NULL, CHANNELLEN); |
1139 |
> |
isupport_add("TOPICLEN", NULL, ConfigServerInfo.max_topic_length); |
1140 |
> |
isupport_add("CHANMODES", chanmodes, -1); |
1141 |
|
} |
1142 |
|
|
1143 |
|
/* conf_add_class_to_conf() |
1144 |
|
* |
1145 |
|
* inputs - pointer to config item |
1146 |
|
* output - NONE |
1147 |
< |
* side effects - Add a class pointer to a conf |
1147 |
> |
* side effects - Add a class pointer to a conf |
1148 |
|
*/ |
1149 |
|
void |
1150 |
< |
conf_add_class_to_conf(struct MaskItem *conf, const char *class_name) |
1150 |
> |
conf_add_class_to_conf(struct MaskItem *conf, const char *name) |
1151 |
|
{ |
1152 |
< |
if (class_name == NULL) |
1152 |
> |
if (EmptyString(name) || (conf->class = class_find(name, 1)) == NULL) |
1153 |
|
{ |
1154 |
|
conf->class = class_default; |
1155 |
|
|
1156 |
< |
if (conf->type == CONF_CLIENT) |
1157 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1158 |
< |
"Warning *** Defaulting to default class for %s@%s", |
1159 |
< |
conf->user, conf->host); |
1156 |
> |
if (conf->type == CONF_CLIENT || conf->type == CONF_OPER) |
1157 |
> |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
1158 |
> |
"Warning *** Defaulting to default class for %s@%s", |
1159 |
> |
conf->user, conf->host); |
1160 |
|
else |
1161 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1162 |
< |
"Warning *** Defaulting to default class for %s", |
1163 |
< |
conf->name); |
1657 |
< |
} |
1658 |
< |
else |
1659 |
< |
conf->class = class_find(class_name, 1); |
1660 |
< |
|
1661 |
< |
if (conf->class == NULL) |
1662 |
< |
{ |
1663 |
< |
if (conf->type == CONF_CLIENT) |
1664 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1665 |
< |
"Warning *** Defaulting to default class for %s@%s", |
1666 |
< |
conf->user, conf->host); |
1667 |
< |
else |
1668 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1669 |
< |
"Warning *** Defaulting to default class for %s", |
1670 |
< |
conf->name); |
1671 |
< |
conf->class = class_default; |
1161 |
> |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
1162 |
> |
"Warning *** Defaulting to default class for %s", |
1163 |
> |
conf->name); |
1164 |
|
} |
1165 |
|
} |
1166 |
|
|
1173 |
|
void |
1174 |
|
yyerror(const char *msg) |
1175 |
|
{ |
1684 |
– |
char newlinebuf[IRCD_BUFSIZE]; |
1685 |
– |
|
1176 |
|
if (conf_parser_ctx.pass != 1) |
1177 |
|
return; |
1178 |
|
|
1179 |
< |
strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf)); |
1180 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1179 |
> |
const char *p = stripws(linebuf); |
1180 |
> |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
1181 |
|
"\"%s\", line %u: %s: %s", |
1182 |
< |
conffilebuf, lineno + 1, msg, newlinebuf); |
1182 |
> |
conffilebuf, lineno, msg, p); |
1183 |
|
ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s", |
1184 |
< |
conffilebuf, lineno + 1, msg, newlinebuf); |
1184 |
> |
conffilebuf, lineno, msg, p); |
1185 |
|
} |
1186 |
|
|
1187 |
|
void |
1188 |
|
conf_error_report(const char *msg) |
1189 |
|
{ |
1190 |
< |
char newlinebuf[IRCD_BUFSIZE]; |
1191 |
< |
|
1702 |
< |
strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf)); |
1703 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1190 |
> |
const char *p = stripws(linebuf); |
1191 |
> |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
1192 |
|
"\"%s\", line %u: %s: %s", |
1193 |
< |
conffilebuf, lineno + 1, msg, newlinebuf); |
1193 |
> |
conffilebuf, lineno, msg, p); |
1194 |
|
ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s", |
1195 |
< |
conffilebuf, lineno + 1, msg, newlinebuf); |
1195 |
> |
conffilebuf, lineno, msg, p); |
1196 |
|
} |
1197 |
|
|
1198 |
|
/* |
1199 |
|
* valid_tkline() |
1200 |
< |
* |
1200 |
> |
* |
1201 |
|
* inputs - pointer to ascii string to check |
1202 |
|
* - whether the specified time is in seconds or minutes |
1203 |
|
* output - -1 not enough parameters |
1205 |
|
* side effects - none |
1206 |
|
* Originally written by Dianora (Diane, db@db.net) |
1207 |
|
*/ |
1208 |
< |
time_t |
1209 |
< |
valid_tkline(const char *p, int minutes) |
1208 |
> |
uintmax_t |
1209 |
> |
valid_tkline(const char *data, const int minutes) |
1210 |
|
{ |
1211 |
< |
time_t result = 0; |
1211 |
> |
const unsigned char *p = (const unsigned char *)data; |
1212 |
> |
unsigned char tmpch = '\0'; |
1213 |
> |
uintmax_t result = 0; |
1214 |
|
|
1215 |
< |
for (; *p; ++p) |
1215 |
> |
while ((tmpch = *p++)) |
1216 |
|
{ |
1217 |
< |
if (!IsDigit(*p)) |
1217 |
> |
if (!IsDigit(tmpch)) |
1218 |
|
return 0; |
1219 |
|
|
1220 |
|
result *= 10; |
1221 |
< |
result += ((*p) & 0xF); |
1221 |
> |
result += (tmpch & 0xF); |
1222 |
|
} |
1223 |
|
|
1224 |
|
/* |
1225 |
< |
* In the degenerate case where oper does a /quote kline 0 user@host :reason |
1226 |
< |
* i.e. they specifically use 0, I am going to return 1 instead |
1227 |
< |
* as a return value of non-zero is used to flag it as a temporary kline |
1225 |
> |
* In the degenerate case where oper does a /quote kline 0 user@host :reason |
1226 |
> |
* i.e. they specifically use 0, I am going to return 1 instead as a return |
1227 |
> |
* value of non-zero is used to flag it as a temporary kline |
1228 |
|
*/ |
1229 |
|
if (result == 0) |
1230 |
|
result = 1; |
1231 |
|
|
1232 |
< |
/* |
1232 |
> |
/* |
1233 |
|
* If the incoming time is in seconds convert it to minutes for the purpose |
1234 |
|
* of this calculation |
1235 |
|
*/ |
1236 |
|
if (!minutes) |
1237 |
< |
result = result / (time_t)60; |
1237 |
> |
result = result / 60; |
1238 |
|
|
1239 |
|
if (result > MAX_TDKLINE_TIME) |
1240 |
|
result = MAX_TDKLINE_TIME; |
1241 |
|
|
1242 |
< |
result = result * (time_t)60; /* turn it into seconds */ |
1242 |
> |
result = result * 60; /* Turn it into seconds */ |
1243 |
|
|
1244 |
|
return result; |
1245 |
|
} |
1255 |
|
{ |
1256 |
|
const unsigned char *p = (const unsigned char *)data; |
1257 |
|
unsigned char tmpch = '\0'; |
1258 |
< |
int nonwild = 0; |
1258 |
> |
unsigned int nonwild = 0, wild = 0; |
1259 |
|
|
1260 |
|
while ((tmpch = *p++)) |
1261 |
|
{ |
1262 |
< |
if (tmpch == '\\') |
1262 |
> |
if (tmpch == '\\' && *p) |
1263 |
|
{ |
1264 |
|
++p; |
1265 |
< |
if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple) |
1265 |
> |
if (++nonwild >= ConfigGeneral.min_nonwildcard_simple) |
1266 |
|
return 1; |
1267 |
|
} |
1268 |
|
else if (!IsMWildChar(tmpch)) |
1269 |
|
{ |
1270 |
< |
if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple) |
1270 |
> |
if (++nonwild >= ConfigGeneral.min_nonwildcard_simple) |
1271 |
|
return 1; |
1272 |
|
} |
1273 |
+ |
else |
1274 |
+ |
++wild; |
1275 |
|
} |
1276 |
|
|
1277 |
< |
return 0; |
1277 |
> |
return !wild; |
1278 |
|
} |
1279 |
|
|
1280 |
|
/* valid_wild_card() |
1286 |
|
* side effects - NOTICE is given to source_p if warn is 1 |
1287 |
|
*/ |
1288 |
|
int |
1289 |
< |
valid_wild_card(struct Client *source_p, int warn, int count, ...) |
1289 |
> |
valid_wild_card(int count, ...) |
1290 |
|
{ |
1291 |
< |
char *p; |
1292 |
< |
char tmpch; |
1801 |
< |
int nonwild = 0; |
1291 |
> |
unsigned char tmpch = '\0'; |
1292 |
> |
unsigned int nonwild = 0; |
1293 |
|
va_list args; |
1294 |
|
|
1295 |
|
/* |
1308 |
|
|
1309 |
|
while (count--) |
1310 |
|
{ |
1311 |
< |
p = va_arg(args, char *); |
1311 |
> |
const unsigned char *p = va_arg(args, const unsigned char *); |
1312 |
|
if (p == NULL) |
1313 |
|
continue; |
1314 |
|
|
1320 |
|
* If we find enough non-wild characters, we can |
1321 |
|
* break - no point in searching further. |
1322 |
|
*/ |
1323 |
< |
if (++nonwild >= ConfigFileEntry.min_nonwildcard) |
1323 |
> |
if (++nonwild >= ConfigGeneral.min_nonwildcard) |
1324 |
> |
{ |
1325 |
> |
va_end(args); |
1326 |
|
return 1; |
1327 |
+ |
} |
1328 |
|
} |
1329 |
|
} |
1330 |
|
} |
1331 |
|
|
1332 |
< |
if (warn) |
1333 |
< |
sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the mask", |
1334 |
< |
me.name, source_p->name, ConfigFileEntry.min_nonwildcard); |
1332 |
> |
va_end(args); |
1333 |
> |
return 0; |
1334 |
> |
} |
1335 |
> |
|
1336 |
> |
/* find_user_host() |
1337 |
> |
* |
1338 |
> |
* inputs - pointer to client placing kline |
1339 |
> |
* - pointer to user_host_or_nick |
1340 |
> |
* - pointer to user buffer |
1341 |
> |
* - pointer to host buffer |
1342 |
> |
* output - 0 if not ok to kline, 1 to kline i.e. if valid user host |
1343 |
> |
* side effects - |
1344 |
> |
*/ |
1345 |
> |
static int |
1346 |
> |
find_user_host(struct Client *source_p, char *user_host_or_nick, |
1347 |
> |
char *luser, char *lhost) |
1348 |
> |
{ |
1349 |
> |
struct Client *target_p = NULL; |
1350 |
> |
char *hostp = NULL; |
1351 |
> |
|
1352 |
> |
if (lhost == NULL) |
1353 |
> |
{ |
1354 |
> |
strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); |
1355 |
> |
return 1; |
1356 |
> |
} |
1357 |
> |
|
1358 |
> |
if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*') |
1359 |
> |
{ |
1360 |
> |
/* Explicit user@host mask given */ |
1361 |
> |
if (hostp) /* I'm a little user@host */ |
1362 |
> |
{ |
1363 |
> |
*(hostp++) = '\0'; /* short and squat */ |
1364 |
> |
|
1365 |
> |
if (*user_host_or_nick) |
1366 |
> |
strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */ |
1367 |
> |
else |
1368 |
> |
strcpy(luser, "*"); |
1369 |
> |
|
1370 |
> |
if (*hostp) |
1371 |
> |
strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */ |
1372 |
> |
else |
1373 |
> |
strcpy(lhost, "*"); |
1374 |
> |
} |
1375 |
> |
else |
1376 |
> |
{ |
1377 |
> |
luser[0] = '*'; /* no @ found, assume its *@somehost */ |
1378 |
> |
luser[1] = '\0'; |
1379 |
> |
strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1); |
1380 |
> |
} |
1381 |
> |
|
1382 |
> |
return 1; |
1383 |
> |
} |
1384 |
> |
else |
1385 |
> |
{ |
1386 |
> |
/* Try to find user@host mask from nick */ |
1387 |
> |
/* Okay to use source_p as the first param, because source_p == client_p */ |
1388 |
> |
if ((target_p = |
1389 |
> |
find_chasing(source_p, user_host_or_nick)) == NULL) |
1390 |
> |
return 0; /* find_chasing sends ERR_NOSUCHNICK */ |
1391 |
> |
|
1392 |
> |
if (HasFlag(target_p, FLAGS_EXEMPTKLINE)) |
1393 |
> |
{ |
1394 |
> |
if (IsClient(source_p)) |
1395 |
> |
sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name); |
1396 |
> |
return 0; |
1397 |
> |
} |
1398 |
> |
|
1399 |
> |
/* |
1400 |
> |
* Turn the "user" bit into "*user", blow away '~' |
1401 |
> |
* if found in original user name (non-idented) |
1402 |
> |
*/ |
1403 |
> |
strlcpy(luser, target_p->username, USERLEN*4 + 1); |
1404 |
> |
|
1405 |
> |
if (target_p->username[0] == '~') |
1406 |
> |
luser[0] = '*'; |
1407 |
> |
|
1408 |
> |
strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1); |
1409 |
> |
return 1; |
1410 |
> |
} |
1411 |
> |
|
1412 |
|
return 0; |
1413 |
|
} |
1414 |
|
|
1422 |
|
* - parse_flags bit map of things to test |
1423 |
|
* - pointer to user or string to parse into |
1424 |
|
* - pointer to host or NULL to parse into if non NULL |
1425 |
< |
* - pointer to optional tkline time or NULL |
1425 |
> |
* - pointer to optional tkline time or NULL |
1426 |
|
* - pointer to target_server to parse into if non NULL |
1427 |
|
* - pointer to reason to parse into |
1428 |
|
* |
1429 |
< |
* output - 1 if valid, -1 if not valid |
1429 |
> |
* output - 1 if valid, 0 if not valid |
1430 |
|
* side effects - A generalised k/d/x etc. line parser, |
1431 |
|
* "ALINE [time] user@host|string [ON] target :reason" |
1432 |
|
* will parse returning a parsed user, host if |
1444 |
|
*/ |
1445 |
|
int |
1446 |
|
parse_aline(const char *cmd, struct Client *source_p, |
1447 |
< |
int parc, char **parv, |
1448 |
< |
int parse_flags, char **up_p, char **h_p, time_t *tkline_time, |
1449 |
< |
char **target_server, char **reason) |
1447 |
> |
int parc, char **parv, |
1448 |
> |
char **up_p, char **h_p, uintmax_t *tkline_time, |
1449 |
> |
char **target_server, char **reason) |
1450 |
|
{ |
1451 |
< |
int found_tkline_time=0; |
1452 |
< |
static char def_reason[] = "No Reason"; |
1451 |
> |
uintmax_t found_tkline_time=0; |
1452 |
> |
static char default_reason[] = CONF_NOREASON; |
1453 |
|
static char user[USERLEN*4+1]; |
1454 |
|
static char host[HOSTLEN*4+1]; |
1455 |
|
|
1458 |
|
|
1459 |
|
found_tkline_time = valid_tkline(*parv, TK_MINUTES); |
1460 |
|
|
1461 |
< |
if (found_tkline_time != 0) |
1461 |
> |
if (found_tkline_time) |
1462 |
|
{ |
1463 |
|
parv++; |
1464 |
|
parc--; |
1465 |
|
|
1466 |
< |
if (tkline_time != NULL) |
1466 |
> |
if (tkline_time) |
1467 |
|
*tkline_time = found_tkline_time; |
1468 |
|
else |
1469 |
|
{ |
1470 |
< |
sendto_one(source_p, ":%s NOTICE %s :temp_line not supported by %s", |
1471 |
< |
me.name, source_p->name, cmd); |
1901 |
< |
return -1; |
1470 |
> |
sendto_one_notice(source_p, &me, ":temp_line not supported by %s", cmd); |
1471 |
> |
return 0; |
1472 |
|
} |
1473 |
|
} |
1474 |
|
|
1475 |
|
if (parc == 0) |
1476 |
|
{ |
1477 |
< |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
1478 |
< |
me.name, source_p->name, cmd); |
1909 |
< |
return -1; |
1477 |
> |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd); |
1478 |
> |
return 0; |
1479 |
|
} |
1480 |
|
|
1481 |
|
if (h_p == NULL) |
1482 |
|
*up_p = *parv; |
1483 |
|
else |
1484 |
|
{ |
1485 |
< |
if (find_user_host(source_p, *parv, user, host, parse_flags) == 0) |
1486 |
< |
return -1; |
1485 |
> |
if (find_user_host(source_p, *parv, user, host) == 0) |
1486 |
> |
return 0; |
1487 |
|
|
1488 |
|
*up_p = user; |
1489 |
|
*h_p = host; |
1490 |
|
} |
1491 |
< |
|
1491 |
> |
|
1492 |
|
parc--; |
1493 |
|
parv++; |
1494 |
|
|
1495 |
< |
if (parc != 0) |
1495 |
> |
if (parc) |
1496 |
|
{ |
1497 |
|
if (irccmp(*parv, "ON") == 0) |
1498 |
|
{ |
1499 |
|
parc--; |
1500 |
|
parv++; |
1501 |
|
|
1933 |
– |
if (target_server == NULL) |
1934 |
– |
{ |
1935 |
– |
sendto_one(source_p, ":%s NOTICE %s :ON server not supported by %s", |
1936 |
– |
me.name, source_p->name, cmd); |
1937 |
– |
return -1; |
1938 |
– |
} |
1939 |
– |
|
1502 |
|
if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN)) |
1503 |
|
{ |
1504 |
< |
sendto_one(source_p, form_str(ERR_NOPRIVS), |
1505 |
< |
me.name, source_p->name, "remoteban"); |
1944 |
< |
return -1; |
1504 |
> |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "remoteban"); |
1505 |
> |
return 0; |
1506 |
|
} |
1507 |
|
|
1508 |
|
if (parc == 0 || EmptyString(*parv)) |
1509 |
|
{ |
1510 |
< |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
1511 |
< |
me.name, source_p->name, cmd); |
1951 |
< |
return -1; |
1510 |
> |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd); |
1511 |
> |
return 0; |
1512 |
|
} |
1513 |
|
|
1514 |
|
*target_server = *parv; |
1520 |
|
/* Make sure target_server *is* NULL if no ON server found |
1521 |
|
* caller probably NULL'd it first, but no harm to do it again -db |
1522 |
|
*/ |
1523 |
< |
if (target_server != NULL) |
1524 |
< |
*target_server = NULL; |
1965 |
< |
} |
1966 |
< |
} |
1967 |
< |
|
1968 |
< |
if (h_p != NULL) |
1969 |
< |
{ |
1970 |
< |
if (strchr(user, '!') != NULL) |
1971 |
< |
{ |
1972 |
< |
sendto_one(source_p, ":%s NOTICE %s :Invalid character '!' in kline", |
1973 |
< |
me.name, source_p->name); |
1974 |
< |
return -1; |
1523 |
> |
if (target_server) |
1524 |
> |
*target_server = NULL; |
1525 |
|
} |
1976 |
– |
|
1977 |
– |
if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 2, *up_p, *h_p)) |
1978 |
– |
return -1; |
1526 |
|
} |
1980 |
– |
else |
1981 |
– |
if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 1, *up_p)) |
1982 |
– |
return -1; |
1527 |
|
|
1528 |
< |
if (reason != NULL) |
1528 |
> |
if (reason) |
1529 |
|
{ |
1530 |
< |
if (parc != 0 && !EmptyString(*parv)) |
1987 |
< |
{ |
1530 |
> |
if (parc && !EmptyString(*parv)) |
1531 |
|
*reason = *parv; |
1989 |
– |
if (!valid_comment(source_p, *reason, 1)) |
1990 |
– |
return -1; |
1991 |
– |
} |
1992 |
– |
else |
1993 |
– |
*reason = def_reason; |
1994 |
– |
} |
1995 |
– |
|
1996 |
– |
return 1; |
1997 |
– |
} |
1998 |
– |
|
1999 |
– |
/* find_user_host() |
2000 |
– |
* |
2001 |
– |
* inputs - pointer to client placing kline |
2002 |
– |
* - pointer to user_host_or_nick |
2003 |
– |
* - pointer to user buffer |
2004 |
– |
* - pointer to host buffer |
2005 |
– |
* output - 0 if not ok to kline, 1 to kline i.e. if valid user host |
2006 |
– |
* side effects - |
2007 |
– |
*/ |
2008 |
– |
static int |
2009 |
– |
find_user_host(struct Client *source_p, char *user_host_or_nick, |
2010 |
– |
char *luser, char *lhost, unsigned int flags) |
2011 |
– |
{ |
2012 |
– |
struct Client *target_p = NULL; |
2013 |
– |
char *hostp = NULL; |
2014 |
– |
|
2015 |
– |
if (lhost == NULL) |
2016 |
– |
{ |
2017 |
– |
strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); |
2018 |
– |
return 1; |
2019 |
– |
} |
2020 |
– |
|
2021 |
– |
if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*') |
2022 |
– |
{ |
2023 |
– |
/* Explicit user@host mask given */ |
2024 |
– |
|
2025 |
– |
if (hostp != NULL) /* I'm a little user@host */ |
2026 |
– |
{ |
2027 |
– |
*(hostp++) = '\0'; /* short and squat */ |
2028 |
– |
if (*user_host_or_nick) |
2029 |
– |
strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */ |
2030 |
– |
else |
2031 |
– |
strcpy(luser, "*"); |
2032 |
– |
if (*hostp) |
2033 |
– |
strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */ |
2034 |
– |
else |
2035 |
– |
strcpy(lhost, "*"); |
2036 |
– |
} |
2037 |
– |
else |
2038 |
– |
{ |
2039 |
– |
luser[0] = '*'; /* no @ found, assume its *@somehost */ |
2040 |
– |
luser[1] = '\0'; |
2041 |
– |
strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1); |
2042 |
– |
} |
2043 |
– |
|
2044 |
– |
return 1; |
2045 |
– |
} |
2046 |
– |
else |
2047 |
– |
{ |
2048 |
– |
/* Try to find user@host mask from nick */ |
2049 |
– |
/* Okay to use source_p as the first param, because source_p == client_p */ |
2050 |
– |
if ((target_p = |
2051 |
– |
find_chasing(source_p, source_p, user_host_or_nick, NULL)) == NULL) |
2052 |
– |
return 0; |
2053 |
– |
|
2054 |
– |
if (IsExemptKline(target_p)) |
2055 |
– |
{ |
2056 |
– |
if (!IsServer(source_p)) |
2057 |
– |
sendto_one(source_p, |
2058 |
– |
":%s NOTICE %s :%s is E-lined", |
2059 |
– |
me.name, source_p->name, target_p->name); |
2060 |
– |
return 0; |
2061 |
– |
} |
2062 |
– |
|
2063 |
– |
/* |
2064 |
– |
* turn the "user" bit into "*user", blow away '~' |
2065 |
– |
* if found in original user name (non-idented) |
2066 |
– |
*/ |
2067 |
– |
strlcpy(luser, target_p->username, USERLEN*4 + 1); |
2068 |
– |
|
2069 |
– |
if (target_p->username[0] == '~') |
2070 |
– |
luser[0] = '*'; |
2071 |
– |
|
2072 |
– |
if (target_p->sockhost[0] == '\0' || |
2073 |
– |
(target_p->sockhost[0] == '0' && target_p->sockhost[1] == '\0')) |
2074 |
– |
strlcpy(lhost, target_p->host, HOSTLEN*4 + 1); |
1532 |
|
else |
1533 |
< |
strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1); |
2077 |
< |
return 1; |
1533 |
> |
*reason = default_reason; |
1534 |
|
} |
1535 |
|
|
2080 |
– |
return 0; |
2081 |
– |
} |
2082 |
– |
|
2083 |
– |
/* valid_comment() |
2084 |
– |
* |
2085 |
– |
* inputs - pointer to client |
2086 |
– |
* - pointer to comment |
2087 |
– |
* output - 0 if no valid comment, |
2088 |
– |
* - 1 if valid |
2089 |
– |
* side effects - truncates reason where necessary |
2090 |
– |
*/ |
2091 |
– |
int |
2092 |
– |
valid_comment(struct Client *source_p, char *comment, int warn) |
2093 |
– |
{ |
2094 |
– |
if (strlen(comment) > REASONLEN) |
2095 |
– |
comment[REASONLEN-1] = '\0'; |
2096 |
– |
|
1536 |
|
return 1; |
1537 |
|
} |
1538 |
|
|
1556 |
|
else |
1557 |
|
encr = password; |
1558 |
|
|
1559 |
< |
return !strcmp(encr, conf->passwd); |
2121 |
< |
} |
2122 |
< |
|
2123 |
< |
/* |
2124 |
< |
* cluster_a_line |
2125 |
< |
* |
2126 |
< |
* inputs - client sending the cluster |
2127 |
< |
* - command name "KLINE" "XLINE" etc. |
2128 |
< |
* - capab -- CAP_KLN etc. from s_serv.h |
2129 |
< |
* - cluster type -- CLUSTER_KLINE etc. from conf.h |
2130 |
< |
* - pattern and args to send along |
2131 |
< |
* output - none |
2132 |
< |
* side effects - Take source_p send the pattern with args given |
2133 |
< |
* along to all servers that match capab and cluster type |
2134 |
< |
*/ |
2135 |
< |
void |
2136 |
< |
cluster_a_line(struct Client *source_p, const char *command, |
2137 |
< |
int capab, int cluster_type, const char *pattern, ...) |
2138 |
< |
{ |
2139 |
< |
va_list args; |
2140 |
< |
char buffer[IRCD_BUFSIZE]; |
2141 |
< |
const dlink_node *ptr = NULL; |
2142 |
< |
|
2143 |
< |
va_start(args, pattern); |
2144 |
< |
vsnprintf(buffer, sizeof(buffer), pattern, args); |
2145 |
< |
va_end(args); |
2146 |
< |
|
2147 |
< |
DLINK_FOREACH(ptr, cluster_items.head) |
2148 |
< |
{ |
2149 |
< |
const struct MaskItem *conf = ptr->data; |
2150 |
< |
|
2151 |
< |
if (conf->flags & cluster_type) |
2152 |
< |
sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab, |
2153 |
< |
"%s %s %s", command, conf->name, buffer); |
2154 |
< |
} |
1559 |
> |
return encr && !strcmp(encr, conf->passwd); |
1560 |
|
} |
1561 |
|
|
1562 |
|
/* |
1594 |
|
|
1595 |
|
if (iptr->nickptr) |
1596 |
|
strlcpy(iptr->nickptr, "*", iptr->nicksize); |
1597 |
+ |
|
1598 |
|
if (iptr->userptr) |
1599 |
|
strlcpy(iptr->userptr, "*", iptr->usersize); |
1600 |
+ |
|
1601 |
|
if (iptr->hostptr) |
1602 |
|
strlcpy(iptr->hostptr, "*", iptr->hostsize); |
1603 |
|
|
1605 |
|
{ |
1606 |
|
*p = '\0'; |
1607 |
|
|
1608 |
< |
if (iptr->nickptr && *iptr->nuhmask != '\0') |
1608 |
> |
if (iptr->nickptr && *iptr->nuhmask) |
1609 |
|
strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize); |
1610 |
|
|
1611 |
< |
if ((q = strchr(++p, '@'))) { |
1611 |
> |
if ((q = strchr(++p, '@'))) |
1612 |
> |
{ |
1613 |
|
*q++ = '\0'; |
1614 |
|
|
1615 |
< |
if (*p != '\0') |
1615 |
> |
if (*p) |
1616 |
|
strlcpy(iptr->userptr, p, iptr->usersize); |
1617 |
|
|
1618 |
< |
if (*q != '\0') |
1618 |
> |
if (*q) |
1619 |
|
strlcpy(iptr->hostptr, q, iptr->hostsize); |
1620 |
|
} |
1621 |
|
else |
1622 |
|
{ |
1623 |
< |
if (*p != '\0') |
1623 |
> |
if (*p) |
1624 |
|
strlcpy(iptr->userptr, p, iptr->usersize); |
1625 |
|
} |
1626 |
|
} |
1632 |
|
/* if found a @ */ |
1633 |
|
*p++ = '\0'; |
1634 |
|
|
1635 |
< |
if (*iptr->nuhmask != '\0') |
1635 |
> |
if (*iptr->nuhmask) |
1636 |
|
strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize); |
1637 |
|
|
1638 |
< |
if (*p != '\0') |
1638 |
> |
if (*p) |
1639 |
|
strlcpy(iptr->hostptr, p, iptr->hostsize); |
1640 |
|
} |
1641 |
|
else |
1642 |
|
{ |
1643 |
< |
/* no @ found */ |
1643 |
> |
/* No @ found */ |
1644 |
|
if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:")) |
1645 |
|
strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize); |
1646 |
|
else |