| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
* m_dline.c: Bans a user. |
| 4 |
* |
| 5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 20 |
* USA |
| 21 |
* |
| 22 |
* $Id$ |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "stdinc.h" |
| 26 |
#include "list.h" |
| 27 |
#include "channel.h" |
| 28 |
#include "client.h" |
| 29 |
#include "common.h" |
| 30 |
#include "irc_string.h" |
| 31 |
#include "sprintf_irc.h" |
| 32 |
#include "ircd.h" |
| 33 |
#include "hostmask.h" |
| 34 |
#include "numeric.h" |
| 35 |
#include "fdlist.h" |
| 36 |
#include "s_bsd.h" |
| 37 |
#include "s_conf.h" |
| 38 |
#include "s_log.h" |
| 39 |
#include "s_misc.h" |
| 40 |
#include "send.h" |
| 41 |
#include "hash.h" |
| 42 |
#include "handlers.h" |
| 43 |
#include "s_serv.h" |
| 44 |
#include "msg.h" |
| 45 |
#include "s_gline.h" |
| 46 |
#include "parse.h" |
| 47 |
#include "modules.h" |
| 48 |
|
| 49 |
|
| 50 |
static int remove_tdline_match(const char *); |
| 51 |
|
| 52 |
/* apply_tdline() |
| 53 |
* |
| 54 |
* inputs - |
| 55 |
* output - NONE |
| 56 |
* side effects - tkline as given is placed |
| 57 |
*/ |
| 58 |
static void |
| 59 |
apply_tdline(struct Client *source_p, struct ConfItem *conf, |
| 60 |
const char *current_date, int tkline_time) |
| 61 |
{ |
| 62 |
struct AccessItem *aconf; |
| 63 |
|
| 64 |
aconf = map_to_conf(conf); |
| 65 |
aconf->hold = CurrentTime + tkline_time; |
| 66 |
|
| 67 |
add_temp_line(conf); |
| 68 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 69 |
"%s added temporary %d min. D-Line for [%s] [%s]", |
| 70 |
get_oper_name(source_p), tkline_time/60, |
| 71 |
aconf->host, aconf->reason); |
| 72 |
|
| 73 |
sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line [%s]", |
| 74 |
MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from), |
| 75 |
source_p->name, tkline_time/60, aconf->host); |
| 76 |
ilog(L_TRACE, "%s added temporary %d min. D-Line for [%s] [%s]", |
| 77 |
source_p->name, tkline_time/60, aconf->host, aconf->reason); |
| 78 |
log_oper_action(LOG_TEMP_DLINE_TYPE, source_p, "[%s@%s] [%s]\n", |
| 79 |
aconf->user, aconf->host, aconf->reason); |
| 80 |
rehashed_klines = 1; |
| 81 |
} |
| 82 |
|
| 83 |
/* mo_dline() |
| 84 |
* |
| 85 |
* inputs - pointer to server |
| 86 |
* - pointer to client |
| 87 |
* - parameter count |
| 88 |
* - parameter list |
| 89 |
* output - |
| 90 |
* side effects - D line is added |
| 91 |
* |
| 92 |
*/ |
| 93 |
static void |
| 94 |
mo_dline(struct Client *client_p, struct Client *source_p, |
| 95 |
int parc, char *parv[]) |
| 96 |
{ |
| 97 |
char def_reason[] = "No reason"; |
| 98 |
char *dlhost, *oper_reason, *reason; |
| 99 |
const char *creason; |
| 100 |
const struct Client *target_p = NULL; |
| 101 |
struct irc_ssaddr daddr; |
| 102 |
struct ConfItem *conf=NULL; |
| 103 |
struct AccessItem *aconf=NULL; |
| 104 |
time_t tkline_time=0; |
| 105 |
int bits, t; |
| 106 |
const char *current_date = NULL; |
| 107 |
time_t cur_time; |
| 108 |
char hostip[HOSTIPLEN]; |
| 109 |
char buffer[IRCD_BUFSIZE]; |
| 110 |
|
| 111 |
if (!HasOFlag(source_p, OPER_FLAG_K)) |
| 112 |
{ |
| 113 |
sendto_one(source_p, form_str(ERR_NOPRIVS), |
| 114 |
me.name, source_p->name, "kline"); |
| 115 |
return; |
| 116 |
} |
| 117 |
|
| 118 |
if (parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost, |
| 119 |
NULL, &tkline_time, NULL, &reason) < 0) |
| 120 |
return; |
| 121 |
|
| 122 |
if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST) |
| 123 |
{ |
| 124 |
if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL) |
| 125 |
return; |
| 126 |
|
| 127 |
if (!MyConnect(target_p)) |
| 128 |
{ |
| 129 |
sendto_one(source_p, |
| 130 |
":%s NOTICE %s :Can't DLINE nick on another server", |
| 131 |
me.name, source_p->name); |
| 132 |
return; |
| 133 |
} |
| 134 |
|
| 135 |
if (IsExemptKline(target_p)) |
| 136 |
{ |
| 137 |
sendto_one(source_p, |
| 138 |
":%s NOTICE %s :%s is E-lined", me.name, |
| 139 |
source_p->name, target_p->name); |
| 140 |
return; |
| 141 |
} |
| 142 |
|
| 143 |
getnameinfo((struct sockaddr *)&target_p->localClient->ip, |
| 144 |
target_p->localClient->ip.ss_len, hostip, |
| 145 |
sizeof(hostip), NULL, 0, NI_NUMERICHOST); |
| 146 |
dlhost = hostip; |
| 147 |
t = parse_netmask(dlhost, NULL, &bits); |
| 148 |
assert(t == HM_IPV4 || t == HM_IPV6); |
| 149 |
} |
| 150 |
|
| 151 |
if (bits < 8) |
| 152 |
{ |
| 153 |
sendto_one(source_p, |
| 154 |
":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.", |
| 155 |
me.name, source_p->name); |
| 156 |
return; |
| 157 |
} |
| 158 |
|
| 159 |
#ifdef IPV6 |
| 160 |
if (t == HM_IPV6) |
| 161 |
t = AF_INET6; |
| 162 |
else |
| 163 |
#endif |
| 164 |
t = AF_INET; |
| 165 |
|
| 166 |
parse_netmask(dlhost, &daddr, NULL); |
| 167 |
|
| 168 |
if ((aconf = find_dline_conf(&daddr, t)) != NULL) |
| 169 |
{ |
| 170 |
creason = aconf->reason ? aconf->reason : def_reason; |
| 171 |
if (IsConfExemptKline(aconf)) |
| 172 |
sendto_one(source_p, |
| 173 |
":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s", |
| 174 |
me.name, source_p->name, dlhost, aconf->host, creason); |
| 175 |
else |
| 176 |
sendto_one(source_p, |
| 177 |
":%s NOTICE %s :[%s] already D-lined by [%s] - %s", |
| 178 |
me.name, source_p->name, dlhost, aconf->host, creason); |
| 179 |
return; |
| 180 |
} |
| 181 |
|
| 182 |
cur_time = CurrentTime; |
| 183 |
current_date = smalldate(cur_time); |
| 184 |
|
| 185 |
/* Look for an oper reason */ |
| 186 |
if ((oper_reason = strchr(reason, '|')) != NULL) |
| 187 |
*oper_reason++ = '\0'; |
| 188 |
|
| 189 |
if (!valid_comment(source_p, reason, YES)) |
| 190 |
return; |
| 191 |
|
| 192 |
conf = make_conf_item(DLINE_TYPE); |
| 193 |
aconf = map_to_conf(conf); |
| 194 |
DupString(aconf->host, dlhost); |
| 195 |
|
| 196 |
if (tkline_time != 0) |
| 197 |
{ |
| 198 |
snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)", |
| 199 |
(int)(tkline_time/60), reason, current_date); |
| 200 |
DupString(aconf->reason, buffer); |
| 201 |
if (oper_reason != NULL) |
| 202 |
DupString(aconf->oper_reason, oper_reason); |
| 203 |
apply_tdline(source_p, conf, current_date, tkline_time); |
| 204 |
} |
| 205 |
else |
| 206 |
{ |
| 207 |
snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date); |
| 208 |
DupString(aconf->reason, buffer); |
| 209 |
if (oper_reason != NULL) |
| 210 |
DupString(aconf->oper_reason, oper_reason); |
| 211 |
add_conf_by_address(CONF_DLINE, aconf); |
| 212 |
write_conf_line(source_p, conf, current_date, cur_time); |
| 213 |
} |
| 214 |
|
| 215 |
rehashed_klines = 1; |
| 216 |
} |
| 217 |
|
| 218 |
/* static int remove_tdline_match(const char *host, const char *user) |
| 219 |
* Input: An ip to undline. |
| 220 |
* Output: returns YES on success, NO if no tdline removed. |
| 221 |
* Side effects: Any matching tdlines are removed. |
| 222 |
*/ |
| 223 |
static int |
| 224 |
remove_tdline_match(const char *cidr) |
| 225 |
{ |
| 226 |
struct AccessItem *td_conf; |
| 227 |
dlink_node *td_node; |
| 228 |
struct irc_ssaddr addr, caddr; |
| 229 |
int nm_t, cnm_t, bits, cbits; |
| 230 |
nm_t = parse_netmask(cidr, &addr, &bits); |
| 231 |
|
| 232 |
DLINK_FOREACH(td_node, temporary_dlines.head) |
| 233 |
{ |
| 234 |
td_conf = map_to_conf(td_node->data); |
| 235 |
cnm_t = parse_netmask(td_conf->host, &caddr, &cbits); |
| 236 |
|
| 237 |
if (cnm_t != nm_t) |
| 238 |
continue; |
| 239 |
|
| 240 |
if((nm_t==HM_HOST && !irccmp(td_conf->host, cidr)) || |
| 241 |
(nm_t==HM_IPV4 && bits==cbits && match_ipv4(&addr, &caddr, bits)) |
| 242 |
#ifdef IPV6 |
| 243 |
|| (nm_t==HM_IPV6 && bits==cbits && match_ipv6(&addr, &caddr, bits)) |
| 244 |
#endif |
| 245 |
) |
| 246 |
{ |
| 247 |
dlinkDelete(td_node, &temporary_dlines); |
| 248 |
delete_one_address_conf(td_conf->host, td_conf); |
| 249 |
return 1; |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
return 0; |
| 254 |
} |
| 255 |
|
| 256 |
/* |
| 257 |
** m_undline |
| 258 |
** added May 28th 2000 by Toby Verrall <toot@melnet.co.uk> |
| 259 |
** based totally on m_unkline |
| 260 |
** added to hybrid-7 7/11/2000 --is |
| 261 |
** |
| 262 |
** parv[0] = sender nick |
| 263 |
** parv[1] = dline to remove |
| 264 |
*/ |
| 265 |
static void |
| 266 |
mo_undline(struct Client *client_p, struct Client *source_p, |
| 267 |
int parc, char *parv[]) |
| 268 |
{ |
| 269 |
const char *cidr = NULL; |
| 270 |
|
| 271 |
if (!HasOFlag(source_p, OPER_FLAG_UNKLINE)) |
| 272 |
{ |
| 273 |
sendto_one(source_p, form_str(ERR_NOPRIVS), |
| 274 |
me.name, source_p->name, "undline"); |
| 275 |
return; |
| 276 |
} |
| 277 |
|
| 278 |
cidr = parv[1]; |
| 279 |
|
| 280 |
if (remove_tdline_match(cidr)) |
| 281 |
{ |
| 282 |
sendto_one(source_p, |
| 283 |
":%s NOTICE %s :Un-Dlined [%s] from temporary D-Lines", |
| 284 |
me.name, source_p->name, cidr); |
| 285 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 286 |
"%s has removed the temporary D-Line for: [%s]", |
| 287 |
get_oper_name(source_p), cidr); |
| 288 |
ilog(L_NOTICE, "%s removed temporary D-Line for [%s]", source_p->name, cidr); |
| 289 |
return; |
| 290 |
} |
| 291 |
|
| 292 |
if (remove_conf_line(DLINE_TYPE, source_p, cidr, NULL) > 0) |
| 293 |
{ |
| 294 |
sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed", |
| 295 |
me.name, source_p->name, cidr); |
| 296 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 297 |
"%s has removed the D-Line for: [%s]", |
| 298 |
get_oper_name(source_p), cidr); |
| 299 |
ilog(L_NOTICE, "%s removed D-Line for [%s]", |
| 300 |
get_oper_name(source_p), cidr); |
| 301 |
} |
| 302 |
else |
| 303 |
sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found", |
| 304 |
me.name, source_p->name, cidr); |
| 305 |
} |
| 306 |
|
| 307 |
static struct Message dline_msgtab = { |
| 308 |
"DLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
| 309 |
{m_unregistered, m_not_oper, rfc1459_command_send_error, m_ignore, mo_dline, m_ignore} |
| 310 |
}; |
| 311 |
|
| 312 |
static struct Message undline_msgtab = { |
| 313 |
"UNDLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
| 314 |
{m_unregistered, m_not_oper, rfc1459_command_send_error, m_ignore, mo_undline, m_ignore} |
| 315 |
}; |
| 316 |
|
| 317 |
static void |
| 318 |
module_init(void) |
| 319 |
{ |
| 320 |
mod_add_cmd(&dline_msgtab); |
| 321 |
mod_add_cmd(&undline_msgtab); |
| 322 |
} |
| 323 |
|
| 324 |
static void |
| 325 |
module_exit(void) |
| 326 |
{ |
| 327 |
mod_del_cmd(&dline_msgtab); |
| 328 |
mod_del_cmd(&undline_msgtab); |
| 329 |
} |
| 330 |
|
| 331 |
struct module module_entry = { |
| 332 |
.node = { NULL, NULL, NULL }, |
| 333 |
.name = NULL, |
| 334 |
.version = "$Revision$", |
| 335 |
.handle = NULL, |
| 336 |
.modinit = module_init, |
| 337 |
.modexit = module_exit, |
| 338 |
.flags = 0 |
| 339 |
}; |