1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 2003-2014 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_unxline.c |
23 |
* \brief Includes required functions for processing the UNXLINE command. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "list.h" |
29 |
#include "client.h" |
30 |
#include "irc_string.h" |
31 |
#include "ircd.h" |
32 |
#include "conf.h" |
33 |
#include "numeric.h" |
34 |
#include "log.h" |
35 |
#include "send.h" |
36 |
#include "server.h" |
37 |
#include "parse.h" |
38 |
#include "modules.h" |
39 |
#include "conf_db.h" |
40 |
#include "memory.h" |
41 |
|
42 |
|
43 |
/* static int remove_tkline_match(const char *host, const char *user) |
44 |
* |
45 |
* Inputs: gecos |
46 |
* Output: returns YES on success, NO if no tkline removed. |
47 |
* Side effects: Any matching tklines are removed. |
48 |
*/ |
49 |
static int |
50 |
remove_xline_exact(const char *gecos) |
51 |
{ |
52 |
dlink_node *ptr = NULL; |
53 |
|
54 |
DLINK_FOREACH(ptr, xconf_items.head) |
55 |
{ |
56 |
struct MaskItem *conf = ptr->data; |
57 |
|
58 |
if (!IsConfDatabase(conf)) |
59 |
continue; |
60 |
|
61 |
if (!irccmp(gecos, conf->name)) |
62 |
{ |
63 |
conf_free(conf); |
64 |
return 1; |
65 |
} |
66 |
} |
67 |
|
68 |
return 0; |
69 |
} |
70 |
|
71 |
static void |
72 |
remove_xline(struct Client *source_p, const char *gecos) |
73 |
{ |
74 |
if (remove_xline_exact(gecos)) |
75 |
{ |
76 |
if (IsClient(source_p)) |
77 |
sendto_one_notice(source_p, &me, ":X-Line for [%s] is removed", gecos); |
78 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
79 |
"%s has removed the X-Line for: [%s]", |
80 |
get_oper_name(source_p), gecos); |
81 |
ilog(LOG_TYPE_XLINE, "%s removed X-Line for [%s]", |
82 |
get_oper_name(source_p), gecos); |
83 |
} |
84 |
else if (IsClient(source_p)) |
85 |
sendto_one_notice(source_p, &me, ":No X-Line for %s", gecos); |
86 |
} |
87 |
|
88 |
/*! \brief UNXLINE command handler |
89 |
* |
90 |
* \param source_p Pointer to allocated Client struct from which the message |
91 |
* originally comes from. This can be a local or remote client. |
92 |
* \param parc Integer holding the number of supplied arguments. |
93 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
94 |
* pointers. |
95 |
* \note Valid arguments for this command are: |
96 |
* - parv[0] = command |
97 |
* - parv[1] = gecos |
98 |
* - parv[2] = "ON" |
99 |
* - parv[3] = target server |
100 |
*/ |
101 |
static int |
102 |
mo_unxline(struct Client *source_p, int parc, char *parv[]) |
103 |
{ |
104 |
char *gecos = NULL; |
105 |
char *target_server = NULL; |
106 |
|
107 |
if (!HasOFlag(source_p, OPER_FLAG_UNXLINE)) |
108 |
{ |
109 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "unxline"); |
110 |
return 0; |
111 |
} |
112 |
|
113 |
/* UNXLINE bill ON irc.server.com */ |
114 |
if (parse_aline("UNXLINE", source_p, parc, parv, 0, &gecos, |
115 |
NULL, NULL, &target_server, NULL) < 0) |
116 |
return 0; |
117 |
|
118 |
if (target_server) |
119 |
{ |
120 |
sendto_match_servs(source_p, target_server, CAP_CLUSTER, |
121 |
"UNXLINE %s %s", target_server, gecos); |
122 |
|
123 |
/* Allow ON to apply local unxline as well if it matches */ |
124 |
if (match(target_server, me.name)) |
125 |
return 0; |
126 |
} |
127 |
else |
128 |
cluster_a_line(source_p, "UNXLINE", CAP_CLUSTER, SHARED_UNXLINE, "%s", gecos); |
129 |
|
130 |
remove_xline(source_p, gecos); |
131 |
return 0; |
132 |
} |
133 |
|
134 |
/*! \brief UNXLINE command handler |
135 |
* |
136 |
* \param source_p Pointer to allocated Client struct from which the message |
137 |
* originally comes from. This can be a local or remote client. |
138 |
* \param parc Integer holding the number of supplied arguments. |
139 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
140 |
* pointers. |
141 |
* \note Valid arguments for this command are: |
142 |
* - parv[0] = command |
143 |
* - parv[1] = target server |
144 |
* - parv[2] = gecos |
145 |
*/ |
146 |
static int |
147 |
ms_unxline(struct Client *source_p, int parc, char *parv[]) |
148 |
{ |
149 |
if (parc != 3 || EmptyString(parv[2])) |
150 |
return 0; |
151 |
|
152 |
sendto_match_servs(source_p, parv[1], CAP_CLUSTER, "UNXLINE %s %s", |
153 |
parv[1], parv[2]); |
154 |
|
155 |
if (match(parv[1], me.name)) |
156 |
return 0; |
157 |
|
158 |
if (HasFlag(source_p, FLAGS_SERVICE) || |
159 |
find_matching_name_conf(CONF_ULINE, source_p->servptr->name, |
160 |
source_p->username, source_p->host, |
161 |
SHARED_UNXLINE)) |
162 |
remove_xline(source_p, parv[2]); |
163 |
return 0; |
164 |
} |
165 |
|
166 |
static struct Message unxline_msgtab = |
167 |
{ |
168 |
"UNXLINE", NULL, 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
169 |
{ m_unregistered, m_not_oper, ms_unxline, m_ignore, mo_unxline, m_ignore } |
170 |
}; |
171 |
|
172 |
static void |
173 |
module_init(void) |
174 |
{ |
175 |
mod_add_cmd(&unxline_msgtab); |
176 |
} |
177 |
|
178 |
static void |
179 |
module_exit(void) |
180 |
{ |
181 |
mod_del_cmd(&unxline_msgtab); |
182 |
} |
183 |
|
184 |
struct module module_entry = |
185 |
{ |
186 |
.node = { NULL, NULL, NULL }, |
187 |
.name = NULL, |
188 |
.version = "$Revision$", |
189 |
.handle = NULL, |
190 |
.modinit = module_init, |
191 |
.modexit = module_exit, |
192 |
.flags = 0 |
193 |
}; |