~ubuntu-branches/ubuntu/trusty/charybdis/trusty-proposed

« back to all changes in this revision

Viewing changes to modules/m_rehash.c

  • Committer: Package Import Robot
  • Author(s): Antoine Beaupré
  • Date: 2011-11-10 23:07:37 UTC
  • Revision ID: package-import@ubuntu.com-20111110230737-kqo6qsglp5oh02hr
Tags: upstream-3.3.0
Import upstream version 3.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  ircd-ratbox: A slightly useful ircd.
 
3
 *  m_rehash.c: Re-reads the configuration file.
 
4
 *
 
5
 *  Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
 
6
 *  Copyright (C) 1996-2002 Hybrid Development Team
 
7
 *  Copyright (C) 2002-2005 ircd-ratbox development team
 
8
 *
 
9
 *  This program is free software; you can redistribute it and/or modify
 
10
 *  it under the terms of the GNU General Public License as published by
 
11
 *  the Free Software Foundation; either version 2 of the License, or
 
12
 *  (at your option) any later version.
 
13
 *
 
14
 *  This program is distributed in the hope that it will be useful,
 
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 *  GNU General Public License for more details.
 
18
 *
 
19
 *  You should have received a copy of the GNU General Public License
 
20
 *  along with this program; if not, write to the Free Software
 
21
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 
22
 *  USA
 
23
 *
 
24
 *  $Id: m_rehash.c 3161 2007-01-25 07:23:01Z nenolod $
 
25
 */
 
26
 
 
27
#include "stdinc.h"
 
28
#include "client.h"
 
29
#include "channel.h"
 
30
#include "common.h"
 
31
#include "match.h"
 
32
#include "ircd.h"
 
33
#include "s_serv.h"
 
34
#include "numeric.h"
 
35
#include "res.h"
 
36
#include "s_conf.h"
 
37
#include "s_newconf.h"
 
38
#include "logger.h"
 
39
#include "send.h"
 
40
#include "msg.h"
 
41
#include "parse.h"
 
42
#include "modules.h"
 
43
#include "hostmask.h"
 
44
#include "reject.h"
 
45
#include "hash.h"
 
46
#include "cache.h"
 
47
 
 
48
static int mo_rehash(struct Client *, struct Client *, int, const char **);
 
49
static int me_rehash(struct Client *, struct Client *, int, const char **);
 
50
 
 
51
struct Message rehash_msgtab = {
 
52
        "REHASH", 0, 0, 0, MFLG_SLOW,
 
53
        {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_rehash, 0}, {mo_rehash, 0}}
 
54
};
 
55
 
 
56
mapi_clist_av1 rehash_clist[] = { &rehash_msgtab, NULL };
 
57
DECLARE_MODULE_AV1(rehash, NULL, NULL, rehash_clist, NULL, NULL, "$Revision: 3161 $");
 
58
 
 
59
struct hash_commands
 
60
{
 
61
        const char *cmd;
 
62
        void (*handler) (struct Client * source_p);
 
63
};
 
64
 
 
65
static void
 
66
rehash_bans_loc(struct Client *source_p)
 
67
{
 
68
        sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is rehashing bans",
 
69
                                get_oper_name(source_p));
 
70
        if (!MyConnect(source_p))
 
71
                remote_rehash_oper_p = source_p;
 
72
 
 
73
        rehash_bans(0);
 
74
}
 
75
 
 
76
static void
 
77
rehash_dns(struct Client *source_p)
 
78
{
 
79
        sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is rehashing DNS", 
 
80
                             get_oper_name(source_p));
 
81
        if (!MyConnect(source_p))
 
82
                remote_rehash_oper_p = source_p;
 
83
 
 
84
        /* reread /etc/resolv.conf and reopen res socket */
 
85
        restart_resolver();
 
86
}
 
87
 
 
88
static void
 
89
rehash_motd(struct Client *source_p)
 
90
{
 
91
        sendto_realops_snomask(SNO_GENERAL, L_ALL,
 
92
                             "%s is forcing re-reading of MOTD file",
 
93
                             get_oper_name(source_p));
 
94
        if (!MyConnect(source_p))
 
95
                remote_rehash_oper_p = source_p;
 
96
 
 
97
        cache_user_motd();
 
98
}
 
99
 
 
100
static void
 
101
rehash_omotd(struct Client *source_p)
 
102
{
 
103
        sendto_realops_snomask(SNO_GENERAL, L_ALL,
 
104
                             "%s is forcing re-reading of OPER MOTD file",
 
105
                             get_oper_name(source_p));
 
106
        if (!MyConnect(source_p))
 
107
                remote_rehash_oper_p = source_p;
 
108
 
 
109
        free_cachefile(oper_motd);
 
110
        oper_motd = cache_file(OPATH, "opers.motd", 0);
 
111
}
 
112
 
 
113
static void
 
114
rehash_tklines(struct Client *source_p)
 
115
{
 
116
        struct ConfItem *aconf;
 
117
        rb_dlink_node *ptr, *next_ptr;
 
118
        int i;
 
119
 
 
120
        sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp klines",
 
121
                                get_oper_name(source_p));
 
122
        if (!MyConnect(source_p))
 
123
                remote_rehash_oper_p = source_p;
 
124
 
 
125
        for(i = 0; i < LAST_TEMP_TYPE; i++)
 
126
        {
 
127
                RB_DLINK_FOREACH_SAFE(ptr, next_ptr, temp_klines[i].head)
 
128
                {
 
129
                        aconf = ptr->data;
 
130
 
 
131
                        delete_one_address_conf(aconf->host, aconf);
 
132
                        rb_dlinkDestroy(ptr, &temp_klines[i]);
 
133
                }
 
134
        }
 
135
}
 
136
 
 
137
static void
 
138
rehash_tdlines(struct Client *source_p)
 
139
{
 
140
        struct ConfItem *aconf;
 
141
        rb_dlink_node *ptr, *next_ptr;
 
142
        int i;
 
143
 
 
144
        sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp dlines",
 
145
                                get_oper_name(source_p));
 
146
        if (!MyConnect(source_p))
 
147
                remote_rehash_oper_p = source_p;
 
148
 
 
149
        for(i = 0; i < LAST_TEMP_TYPE; i++)
 
150
        {
 
151
                RB_DLINK_FOREACH_SAFE(ptr, next_ptr, temp_dlines[i].head)
 
152
                {
 
153
                        aconf = ptr->data;
 
154
 
 
155
                        delete_one_address_conf(aconf->host, aconf);
 
156
                        rb_dlinkDestroy(ptr, &temp_dlines[i]);
 
157
                }
 
158
        }
 
159
}
 
160
 
 
161
static void
 
162
rehash_txlines(struct Client *source_p)
 
163
{
 
164
        struct ConfItem *aconf;
 
165
        rb_dlink_node *ptr;
 
166
        rb_dlink_node *next_ptr;
 
167
 
 
168
        sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp xlines",
 
169
                                get_oper_name(source_p));
 
170
        if (!MyConnect(source_p))
 
171
                remote_rehash_oper_p = source_p;
 
172
 
 
173
        RB_DLINK_FOREACH_SAFE(ptr, next_ptr, xline_conf_list.head)
 
174
        {
 
175
                aconf = ptr->data;
 
176
 
 
177
                if(!aconf->hold || aconf->lifetime)
 
178
                        continue;
 
179
 
 
180
                free_conf(aconf);
 
181
                rb_dlinkDestroy(ptr, &xline_conf_list);
 
182
        }
 
183
}
 
184
 
 
185
static void
 
186
rehash_tresvs(struct Client *source_p)
 
187
{
 
188
        struct ConfItem *aconf;
 
189
        rb_dlink_node *ptr;
 
190
        rb_dlink_node *next_ptr;
 
191
        int i;
 
192
 
 
193
        sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp resvs",
 
194
                                get_oper_name(source_p));
 
195
        if (!MyConnect(source_p))
 
196
                remote_rehash_oper_p = source_p;
 
197
 
 
198
        HASH_WALK_SAFE(i, R_MAX, ptr, next_ptr, resvTable)
 
199
        {
 
200
                aconf = ptr->data;
 
201
 
 
202
                if(!aconf->hold || aconf->lifetime)
 
203
                        continue;
 
204
 
 
205
                free_conf(aconf);
 
206
                rb_dlinkDestroy(ptr, &resvTable[i]);
 
207
        }
 
208
        HASH_WALK_END
 
209
 
 
210
        RB_DLINK_FOREACH_SAFE(ptr, next_ptr, resv_conf_list.head)
 
211
        {
 
212
                aconf = ptr->data;
 
213
 
 
214
                if(!aconf->hold || aconf->lifetime)
 
215
                        continue;
 
216
 
 
217
                free_conf(aconf);
 
218
                rb_dlinkDestroy(ptr, &resv_conf_list);
 
219
        }
 
220
}
 
221
 
 
222
static void
 
223
rehash_rejectcache(struct Client *source_p)
 
224
{
 
225
        sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing reject cache",
 
226
                                get_oper_name(source_p));
 
227
        if (!MyConnect(source_p))
 
228
                remote_rehash_oper_p = source_p;
 
229
        flush_reject();
 
230
 
 
231
}
 
232
 
 
233
static void
 
234
rehash_throttles(struct Client *source_p)
 
235
{
 
236
        sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing throttles",
 
237
                                get_oper_name(source_p));
 
238
        if (!MyConnect(source_p))
 
239
                remote_rehash_oper_p = source_p;
 
240
        flush_throttle();
 
241
 
 
242
}
 
243
 
 
244
static void
 
245
rehash_help(struct Client *source_p)
 
246
{
 
247
        sendto_realops_snomask(SNO_GENERAL, L_ALL,
 
248
                             "%s is forcing re-reading of HELP files", 
 
249
                             get_oper_name(source_p));
 
250
        if (!MyConnect(source_p))
 
251
                remote_rehash_oper_p = source_p;
 
252
        load_help();
 
253
}
 
254
 
 
255
static void
 
256
rehash_nickdelay(struct Client *source_p)
 
257
{
 
258
        struct nd_entry *nd;
 
259
        rb_dlink_node *ptr;
 
260
        rb_dlink_node *safe_ptr;
 
261
 
 
262
        sendto_realops_snomask(SNO_GENERAL, L_ALL,
 
263
                             "%s is clearing the nick delay table",
 
264
                             get_oper_name(source_p));
 
265
        if (!MyConnect(source_p))
 
266
                remote_rehash_oper_p = source_p;
 
267
 
 
268
        RB_DLINK_FOREACH_SAFE(ptr, safe_ptr, nd_list.head)
 
269
        {
 
270
                nd = ptr->data;
 
271
        
 
272
                free_nd_entry(nd);
 
273
        }
 
274
}
 
275
 
 
276
/* *INDENT-OFF* */
 
277
static struct hash_commands rehash_commands[] =
 
278
{
 
279
        {"BANS",        rehash_bans_loc         },
 
280
        {"DNS",         rehash_dns              },
 
281
        {"MOTD",        rehash_motd             },
 
282
        {"OMOTD",       rehash_omotd            },
 
283
        {"TKLINES",     rehash_tklines          },
 
284
        {"TDLINES",     rehash_tdlines          },
 
285
        {"TXLINES",     rehash_txlines          },
 
286
        {"TRESVS",      rehash_tresvs           },
 
287
        {"REJECTCACHE", rehash_rejectcache      },
 
288
        {"THROTTLES",   rehash_throttles        },
 
289
        {"HELP",        rehash_help             },
 
290
        {"NICKDELAY",   rehash_nickdelay        },
 
291
        {NULL,          NULL                    }
 
292
};
 
293
/* *INDENT-ON* */
 
294
 
 
295
static void
 
296
do_rehash(struct Client *source_p, const char *type)
 
297
{
 
298
        if (type != NULL)
 
299
        {
 
300
                int x;
 
301
                char cmdbuf[100];
 
302
 
 
303
                for (x = 0; rehash_commands[x].cmd != NULL && rehash_commands[x].handler != NULL;
 
304
                     x++)
 
305
                {
 
306
                        if(irccmp(type, rehash_commands[x].cmd) == 0)
 
307
                        {
 
308
                                sendto_one(source_p, form_str(RPL_REHASHING), me.name,
 
309
                                           source_p->name, rehash_commands[x].cmd);
 
310
                                ilog(L_MAIN, "REHASH %s From %s[%s]", type,
 
311
                                     get_oper_name(source_p), source_p->sockhost);
 
312
                                rehash_commands[x].handler(source_p);
 
313
                                remote_rehash_oper_p = NULL;
 
314
                                return;
 
315
                        }
 
316
                }
 
317
 
 
318
                /* We are still here..we didn't match */
 
319
                cmdbuf[0] = '\0';
 
320
                for (x = 0; rehash_commands[x].cmd != NULL && rehash_commands[x].handler != NULL;
 
321
                     x++)
 
322
                {
 
323
                        rb_strlcat(cmdbuf, " ", sizeof(cmdbuf));
 
324
                        rb_strlcat(cmdbuf, rehash_commands[x].cmd, sizeof(cmdbuf));
 
325
                }
 
326
                sendto_one_notice(source_p, ":rehash one of:%s", cmdbuf);
 
327
        }
 
328
        else
 
329
        {
 
330
                sendto_one(source_p, form_str(RPL_REHASHING), me.name, source_p->name,
 
331
                           ConfigFileEntry.configfile);
 
332
                sendto_realops_snomask(SNO_GENERAL, L_ALL,
 
333
                                     "%s is rehashing server config file", get_oper_name(source_p));
 
334
                if (!MyConnect(source_p))
 
335
                        remote_rehash_oper_p = source_p;
 
336
                ilog(L_MAIN, "REHASH From %s[%s]", get_oper_name(source_p),
 
337
                     source_p->sockhost);
 
338
                rehash(0);
 
339
                remote_rehash_oper_p = NULL;
 
340
        }
 
341
}
 
342
 
 
343
/*
 
344
 * mo_rehash - REHASH message handler
 
345
 *
 
346
 * parv[1] = rehash type or destination
 
347
 * parv[2] = destination
 
348
 */
 
349
static int
 
350
mo_rehash(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 
351
{
 
352
        const char *type = NULL, *target_server = NULL;
 
353
 
 
354
        if(!IsOperRehash(source_p))
 
355
        {
 
356
                sendto_one(source_p, form_str(ERR_NOPRIVS),
 
357
                           me.name, source_p->name, "rehash");
 
358
                return 0;
 
359
        }
 
360
 
 
361
        if (parc > 2)
 
362
                type = parv[1], target_server = parv[2];
 
363
        else if (parc > 1 && (strchr(parv[1], '.') || strchr(parv[1], '?') || strchr(parv[1], '*')))
 
364
                type = NULL, target_server = parv[1];
 
365
        else if (parc > 1)
 
366
                type = parv[1], target_server = NULL;
 
367
        else
 
368
                type = NULL, target_server = NULL;
 
369
 
 
370
        if (target_server != NULL)
 
371
        {
 
372
                if(!IsOperRemoteBan(source_p))
 
373
                {
 
374
                        sendto_one(source_p, form_str(ERR_NOPRIVS),
 
375
                                me.name, source_p->name, "remoteban");
 
376
                        return 0;
 
377
                }
 
378
                sendto_match_servs(source_p, target_server,
 
379
                                CAP_ENCAP, NOCAPS,
 
380
                                "ENCAP %s REHASH %s",
 
381
                                target_server, type != NULL ? type : "");
 
382
                if (match(target_server, me.name) == 0)
 
383
                        return 0;
 
384
        }
 
385
 
 
386
        do_rehash(source_p, type);
 
387
 
 
388
        return 0;
 
389
}
 
390
 
 
391
static int
 
392
me_rehash(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 
393
{
 
394
 
 
395
        if (!IsPerson(source_p))
 
396
                return 0;
 
397
 
 
398
        if (!find_shared_conf(source_p->username, source_p->host,
 
399
                                source_p->servptr->name, SHARED_REHASH))
 
400
                return 0;
 
401
 
 
402
        do_rehash(source_p, parc > 1 ? parv[1] : NULL);
 
403
 
 
404
        return 0;
 
405
}