1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 1997-2016 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 |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
* USA |
20 |
*/ |
21 |
|
22 |
/*! \file m_close.c |
23 |
* \brief Includes required functions for processing the CLOSE command. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "list.h" |
29 |
#include "client.h" |
30 |
#include "ircd.h" |
31 |
#include "numeric.h" |
32 |
#include "send.h" |
33 |
#include "parse.h" |
34 |
#include "modules.h" |
35 |
|
36 |
|
37 |
/*! \brief CLOSE command handler |
38 |
* |
39 |
* \param source_p Pointer to allocated Client struct from which the message |
40 |
* originally comes from. This can be a local or remote client. |
41 |
* \param parc Integer holding the number of supplied arguments. |
42 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
43 |
* pointers. |
44 |
* \note Valid arguments for this command are: |
45 |
* - parv[0] = command |
46 |
*/ |
47 |
static int |
48 |
mo_close(struct Client *source_p, int parc, char *parv[]) |
49 |
{ |
50 |
dlink_node *node = NULL, *node_next = NULL; |
51 |
unsigned int closed = dlink_list_length(&unknown_list); |
52 |
|
53 |
if (!HasOFlag(source_p, OPER_FLAG_CLOSE)) |
54 |
{ |
55 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "close"); |
56 |
return 0; |
57 |
} |
58 |
|
59 |
DLINK_FOREACH_SAFE(node, node_next, unknown_list.head) |
60 |
{ |
61 |
struct Client *target_p = node->data; |
62 |
|
63 |
sendto_one_numeric(source_p, &me, RPL_CLOSING, |
64 |
get_client_name(target_p, SHOW_IP), |
65 |
target_p->status); |
66 |
|
67 |
/* |
68 |
* Exit here is safe, because it is guaranteed not to be source_p |
69 |
* because it is unregistered and source_p is an oper. |
70 |
*/ |
71 |
exit_client(target_p, "Oper Closing"); |
72 |
} |
73 |
|
74 |
sendto_one_numeric(source_p, &me, RPL_CLOSEEND, closed); |
75 |
return 0; |
76 |
} |
77 |
|
78 |
static struct Message close_msgtab = |
79 |
{ |
80 |
.cmd = "CLOSE", |
81 |
.args_max = MAXPARA, |
82 |
.handlers[UNREGISTERED_HANDLER] = m_unregistered, |
83 |
.handlers[CLIENT_HANDLER] = m_not_oper, |
84 |
.handlers[SERVER_HANDLER] = m_ignore, |
85 |
.handlers[ENCAP_HANDLER] = m_ignore, |
86 |
.handlers[OPER_HANDLER] = mo_close |
87 |
}; |
88 |
|
89 |
static void |
90 |
module_init(void) |
91 |
{ |
92 |
mod_add_cmd(&close_msgtab); |
93 |
} |
94 |
|
95 |
static void |
96 |
module_exit(void) |
97 |
{ |
98 |
mod_del_cmd(&close_msgtab); |
99 |
} |
100 |
|
101 |
struct module module_entry = |
102 |
{ |
103 |
.version = "$Revision$", |
104 |
.modinit = module_init, |
105 |
.modexit = module_exit, |
106 |
}; |