| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
* |
| 4 |
* Copyright (c) 1997-2015 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_undline.c |
| 23 |
* \brief Includes required functions for processing the UNDLINE 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 "conf.h" |
| 32 |
#include "ircd.h" |
| 33 |
#include "hostmask.h" |
| 34 |
#include "numeric.h" |
| 35 |
#include "log.h" |
| 36 |
#include "misc.h" |
| 37 |
#include "send.h" |
| 38 |
#include "server.h" |
| 39 |
#include "parse.h" |
| 40 |
#include "modules.h" |
| 41 |
#include "memory.h" |
| 42 |
|
| 43 |
|
| 44 |
/* static int remove_tdline_match(const char *host, const char *user) |
| 45 |
* Input: An ip to undline. |
| 46 |
* Output: returns YES on success, NO if no tdline removed. |
| 47 |
* Side effects: Any matching tdlines are removed. |
| 48 |
*/ |
| 49 |
static int |
| 50 |
dline_remove(const char *host) |
| 51 |
{ |
| 52 |
struct irc_ssaddr iphost, *piphost; |
| 53 |
struct MaskItem *conf; |
| 54 |
int t = 0; |
| 55 |
int aftype = 0; |
| 56 |
|
| 57 |
if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST) |
| 58 |
{ |
| 59 |
if (t == HM_IPV6) |
| 60 |
aftype = AF_INET6; |
| 61 |
else |
| 62 |
aftype = AF_INET; |
| 63 |
|
| 64 |
piphost = &iphost; |
| 65 |
} |
| 66 |
else |
| 67 |
piphost = NULL; |
| 68 |
|
| 69 |
if ((conf = find_conf_by_address(host, piphost, CONF_DLINE, aftype, NULL, NULL, 0))) |
| 70 |
{ |
| 71 |
if (IsConfDatabase(conf)) |
| 72 |
{ |
| 73 |
delete_one_address_conf(host, conf); |
| 74 |
return 1; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
return 0; |
| 79 |
} |
| 80 |
|
| 81 |
static void |
| 82 |
dline_remove_and_notify(struct Client *source_p, const char *host) |
| 83 |
{ |
| 84 |
if (dline_remove(host)) |
| 85 |
{ |
| 86 |
if (IsClient(source_p)) |
| 87 |
sendto_one_notice(source_p, &me, ":D-Line for [%s] is removed", host); |
| 88 |
|
| 89 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 90 |
"%s has removed the D-Line for: [%s]", |
| 91 |
get_oper_name(source_p), host); |
| 92 |
ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]", |
| 93 |
get_oper_name(source_p), host); |
| 94 |
} |
| 95 |
else if (IsClient(source_p)) |
| 96 |
sendto_one_notice(source_p, &me, ":No D-Line for [%s] found", host); |
| 97 |
} |
| 98 |
|
| 99 |
/*! \brief UNDLINE command handler |
| 100 |
* |
| 101 |
* \param source_p Pointer to allocated Client struct from which the message |
| 102 |
* originally comes from. This can be a local or remote client. |
| 103 |
* \param parc Integer holding the number of supplied arguments. |
| 104 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 105 |
* pointers. |
| 106 |
* \note Valid arguments for this command are: |
| 107 |
* - parv[0] = command |
| 108 |
* - parv[1] = IP address |
| 109 |
* - parv[2] = "ON" |
| 110 |
* - parv[3] = target server |
| 111 |
*/ |
| 112 |
static int |
| 113 |
mo_undline(struct Client *source_p, int parc, char *parv[]) |
| 114 |
{ |
| 115 |
char *addr = NULL; |
| 116 |
char *target_server = NULL; |
| 117 |
|
| 118 |
if (!HasOFlag(source_p, OPER_FLAG_UNDLINE)) |
| 119 |
{ |
| 120 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "undline"); |
| 121 |
return 0; |
| 122 |
} |
| 123 |
|
| 124 |
if (parc < 2 || EmptyString(parv[1])) |
| 125 |
{ |
| 126 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "UNDLINE"); |
| 127 |
return 0; |
| 128 |
} |
| 129 |
|
| 130 |
if (!parse_aline("UNDLINE", source_p, parc, parv, 0, &addr, |
| 131 |
NULL, NULL, &target_server, NULL)) |
| 132 |
return 0; |
| 133 |
|
| 134 |
if (target_server) |
| 135 |
{ |
| 136 |
sendto_match_servs(source_p, target_server, CAP_UNDLN, |
| 137 |
"UNDLINE %s %s", target_server, addr); |
| 138 |
|
| 139 |
/* Allow ON to apply local undline as well if it matches */ |
| 140 |
if (match(target_server, me.name)) |
| 141 |
return 0; |
| 142 |
} |
| 143 |
else |
| 144 |
cluster_a_line(source_p, "UNDLINE", CAP_UNDLN, SHARED_UNDLINE, "%s", addr); |
| 145 |
|
| 146 |
dline_remove_and_notify(source_p, addr); |
| 147 |
return 0; |
| 148 |
} |
| 149 |
|
| 150 |
/*! \brief UNDLINE command handler |
| 151 |
* |
| 152 |
* \param source_p Pointer to allocated Client struct from which the message |
| 153 |
* originally comes from. This can be a local or remote client. |
| 154 |
* \param parc Integer holding the number of supplied arguments. |
| 155 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 156 |
* pointers. |
| 157 |
* \note Valid arguments for this command are: |
| 158 |
* - parv[0] = command |
| 159 |
* - parv[1] = target server |
| 160 |
* - parv[2] = IP address |
| 161 |
*/ |
| 162 |
static int |
| 163 |
ms_undline(struct Client *source_p, int parc, char *parv[]) |
| 164 |
{ |
| 165 |
const char *addr = parv[2]; |
| 166 |
|
| 167 |
if (parc != 3 || EmptyString(parv[2])) |
| 168 |
return 0; |
| 169 |
|
| 170 |
sendto_match_servs(source_p, parv[1], CAP_UNDLN, "UNDLINE %s %s", |
| 171 |
parv[1], parv[2]); |
| 172 |
|
| 173 |
if (match(parv[1], me.name)) |
| 174 |
return 0; |
| 175 |
|
| 176 |
if (HasFlag(source_p, FLAGS_SERVICE) || |
| 177 |
find_matching_name_conf(CONF_ULINE, source_p->servptr->name, |
| 178 |
source_p->username, source_p->host, |
| 179 |
SHARED_UNDLINE)) |
| 180 |
dline_remove_and_notify(source_p, addr); |
| 181 |
|
| 182 |
return 0; |
| 183 |
} |
| 184 |
|
| 185 |
static struct Message undline_msgtab = |
| 186 |
{ |
| 187 |
.cmd = "UNDLINE", |
| 188 |
.args_min = 2, |
| 189 |
.args_max = MAXPARA, |
| 190 |
.handlers[UNREGISTERED_HANDLER] = m_unregistered, |
| 191 |
.handlers[CLIENT_HANDLER] = m_not_oper, |
| 192 |
.handlers[SERVER_HANDLER] = ms_undline, |
| 193 |
.handlers[ENCAP_HANDLER] = m_ignore, |
| 194 |
.handlers[OPER_HANDLER] = mo_undline |
| 195 |
}; |
| 196 |
|
| 197 |
static void |
| 198 |
module_init(void) |
| 199 |
{ |
| 200 |
mod_add_cmd(&undline_msgtab); |
| 201 |
add_capability("UNDLN", CAP_UNDLN); |
| 202 |
} |
| 203 |
|
| 204 |
static void |
| 205 |
module_exit(void) |
| 206 |
{ |
| 207 |
mod_del_cmd(&undline_msgtab); |
| 208 |
delete_capability("UNDLN"); |
| 209 |
} |
| 210 |
|
| 211 |
struct module module_entry = |
| 212 |
{ |
| 213 |
.version = "$Revision$", |
| 214 |
.modinit = module_init, |
| 215 |
.modexit = module_exit, |
| 216 |
}; |