2 * ircd-ratbox: A slightly useful ircd.
3 * m_dline.c: Bans/unbans a user.
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
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.
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.
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
37 #include "s_newconf.h"
47 static int mo_dline(struct Client
*, struct Client
*, int, const char **);
48 static int me_dline(struct Client
*, struct Client
*, int, const char **);
49 static int mo_undline(struct Client
*, struct Client
*, int, const char **);
50 static int me_undline(struct Client
*, struct Client
*, int, const char **);
52 struct Message dline_msgtab
= {
53 "DLINE", 0, 0, 0, MFLG_SLOW
,
54 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_dline
, 3}, {mo_dline
, 2}}
57 struct Message undline_msgtab
= {
58 "UNDLINE", 0, 0, 0, MFLG_SLOW
,
59 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_undline
, 1}, {mo_undline
, 2}}
62 mapi_clist_av1 dline_clist
[] = { &dline_msgtab
, &undline_msgtab
, NULL
};
64 DECLARE_MODULE_AV1(dline
, NULL
, NULL
, dline_clist
, NULL
, NULL
, "$Revision$");
66 static int valid_comment(char *comment
);
67 static int remove_temp_dline(struct ConfItem
*);
68 static int apply_dline(struct Client
*, const char *, int, char *);
69 static int apply_undline(struct Client
*, const char *);
73 * parv[1] - dline to add
77 mo_dline(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
79 char def
[] = "No Reason";
82 char cidr_form_host
[HOSTLEN
+ 1];
84 const char *target_server
= NULL
;
87 if(!IsOperK(source_p
))
89 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "kline");
93 if((tdline_time
= valid_temp_time(parv
[loc
])) >= 0)
97 rb_strlcpy(cidr_form_host
, dlhost
, sizeof(cidr_form_host
));
101 if(parc
>= loc
+ 2 && !irccmp(parv
[loc
], "ON"))
103 if(!IsOperRemoteBan(source_p
))
105 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
106 me
.name
, source_p
->name
, "remoteban");
110 target_server
= parv
[loc
+ 1];
114 if(parc
>= loc
+ 1 && !EmptyString(parv
[loc
]))
115 reason
= LOCAL_COPY(parv
[loc
]);
117 if(target_server
!= NULL
)
119 sendto_match_servs(source_p
, target_server
,
121 "ENCAP %s DLINE %d %s :%s",
122 target_server
, tdline_time
, dlhost
, reason
);
124 if(!match(target_server
, me
.name
))
128 apply_dline(source_p
, dlhost
, tdline_time
, reason
);
136 * parv[1] = dline to remove
139 mo_undline(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
142 const char *target_server
= NULL
;
144 if(!IsOperK(source_p
))
146 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "unkline");
152 if(parc
>= 4 && !irccmp(parv
[2], "ON"))
154 if(!IsOperRemoteBan(source_p
))
156 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
157 me
.name
, source_p
->name
, "remoteban");
161 target_server
= parv
[3];
162 sendto_match_servs(source_p
, target_server
,
163 CAP_ENCAP
, NOCAPS
, "ENCAP %s UNDLINE %s", target_server
, cidr
);
165 if(!match(target_server
, me
.name
))
169 apply_undline(source_p
, cidr
);
175 me_dline(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
177 int tdline_time
= atoi(parv
[1]);
178 /* Since this is coming over a server link, assume that the originating
179 * server did the relevant permission/sanity checks...
182 if(!IsPerson(source_p
))
185 if(!find_shared_conf(source_p
->username
, source_p
->host
,
186 source_p
->servptr
->name
,
187 tdline_time
> 0 ? SHARED_TDLINE
: SHARED_PDLINE
))
190 apply_dline(source_p
, parv
[2], tdline_time
, LOCAL_COPY(parv
[3]));
197 me_undline(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
199 if(!IsPerson(source_p
))
202 if(!find_shared_conf(source_p
->username
, source_p
->host
,
203 source_p
->servptr
->name
, SHARED_UNDLINE
))
206 apply_undline(source_p
, parv
[1]);
212 apply_dline(struct Client
*source_p
, const char *dlhost
, int tdline_time
, char *reason
)
214 struct ConfItem
*aconf
;
216 struct rb_sockaddr_storage daddr
;
217 int t
= AF_INET
, ty
, b
;
220 ty
= parse_netmask(dlhost
, (struct sockaddr
*) &daddr
, &b
);
223 sendto_one(source_p
, ":%s NOTICE %s :Invalid D-Line", me
.name
, source_p
->name
);
233 /* This means dlines wider than /16 cannot be set remotely */
234 if(IsOperAdmin(source_p
))
238 sendto_one_notice(source_p
,
239 ":For safety, bitmasks less than 8 require conf access.");
247 sendto_one_notice(source_p
,
248 ":Dline bitmasks less than 16 are for admins only.");
253 if(!valid_comment(reason
))
256 ":%s NOTICE %s :Invalid character '\"' in comment",
257 me
.name
, source_p
->name
);
261 if(ConfigFileEntry
.non_redundant_klines
)
263 if((aconf
= find_dline((struct sockaddr
*) &daddr
, t
)) != NULL
)
266 parse_netmask(aconf
->host
, NULL
, &bx
);
269 creason
= aconf
->passwd
? aconf
->passwd
: "<No Reason>";
270 if(IsConfExemptKline(aconf
))
272 ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
273 me
.name
, source_p
->name
, dlhost
, aconf
->host
,
277 ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
278 me
.name
, source_p
->name
, dlhost
, aconf
->host
,
288 aconf
->status
= CONF_DLINE
;
289 aconf
->created
= rb_current_time();
290 aconf
->host
= rb_strdup(dlhost
);
291 aconf
->passwd
= rb_strdup(reason
);
293 /* Look for an oper reason */
294 if((oper_reason
= strchr(reason
, '|')) != NULL
)
299 if(!EmptyString(oper_reason
))
300 aconf
->spasswd
= rb_strdup(oper_reason
);
305 aconf
->hold
= rb_current_time() + tdline_time
;
306 add_temp_dline(aconf
);
308 if(EmptyString(oper_reason
))
310 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
311 "%s added temporary %d min. D-Line for [%s] [%s]",
312 get_oper_name(source_p
), tdline_time
/ 60,
313 aconf
->host
, reason
);
314 ilog(L_KLINE
, "D %s %d %s %s",
315 get_oper_name(source_p
), tdline_time
/ 60, aconf
->host
, reason
);
319 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
320 "%s added temporary %d min. D-Line for [%s] [%s|%s]",
321 get_oper_name(source_p
), tdline_time
/ 60,
322 aconf
->host
, reason
, oper_reason
);
323 ilog(L_KLINE
, "D %s %d %s %s|%s",
324 get_oper_name(source_p
), tdline_time
/ 60,
325 aconf
->host
, reason
, oper_reason
);
328 sendto_one(source_p
, ":%s NOTICE %s :Added temporary %d min. D-Line for [%s]",
329 me
.name
, source_p
->name
, tdline_time
/ 60, aconf
->host
);
333 add_conf_by_address(aconf
->host
, CONF_DLINE
, NULL
, NULL
, aconf
);
335 bandb_add(BANDB_DLINE
, source_p
, aconf
->host
, NULL
,
336 reason
, EmptyString(aconf
->spasswd
) ? NULL
: aconf
->spasswd
, 0);
338 if(EmptyString(oper_reason
))
340 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
341 "%s added D-Line for [%s] [%s]",
342 get_oper_name(source_p
), aconf
->host
, reason
);
343 ilog(L_KLINE
, "D %s 0 %s %s",
344 get_oper_name(source_p
), aconf
->host
, reason
);
348 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
349 "%s added D-Line for [%s] [%s|%s]",
350 get_oper_name(source_p
), aconf
->host
, reason
, oper_reason
);
351 ilog(L_KLINE
, "D %s 0 %s %s|%s",
352 get_oper_name(source_p
),
353 aconf
->host
, reason
, oper_reason
);
361 apply_undline(struct Client
*source_p
, const char *cidr
)
364 struct ConfItem
*aconf
;
366 if(parse_netmask(cidr
, NULL
, NULL
) == HM_HOST
)
368 sendto_one_notice(source_p
, ":Invalid D-Line");
372 aconf
= find_exact_conf_by_address(cidr
, CONF_DLINE
, NULL
);
375 sendto_one_notice(source_p
, ":No D-Line for %s", cidr
);
379 rb_strlcpy(buf
, aconf
->host
, sizeof buf
);
380 if(remove_temp_dline(aconf
))
383 ":%s NOTICE %s :Un-dlined [%s] from temporary D-lines",
384 me
.name
, source_p
->name
, buf
);
385 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
386 "%s has removed the temporary D-Line for: [%s]",
387 get_oper_name(source_p
), buf
);
388 ilog(L_KLINE
, "UD %s %s", get_oper_name(source_p
), buf
);
392 bandb_del(BANDB_DLINE
, aconf
->host
, NULL
);
394 sendto_one(source_p
, ":%s NOTICE %s :D-Line for [%s] is removed", me
.name
, source_p
->name
,
396 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s has removed the D-Line for: [%s]",
397 get_oper_name(source_p
), aconf
->host
);
398 ilog(L_KLINE
, "UD %s %s", get_oper_name(source_p
), aconf
->host
);
399 delete_one_address_conf(aconf
->host
, aconf
);
406 * inputs - pointer to client
407 * - pointer to comment
408 * output - 0 if no valid comment, 1 if valid
409 * side effects - NONE
412 valid_comment(char *comment
)
414 if(strchr(comment
, '"'))
417 if(strlen(comment
) > BANREASONLEN
)
418 comment
[BANREASONLEN
] = '\0';
423 /* remove_temp_dline()
425 * inputs - confitem to undline
427 * side effects - tries to undline anything that matches
430 remove_temp_dline(struct ConfItem
*aconf
)
435 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
437 RB_DLINK_FOREACH(ptr
, temp_dlines
[i
].head
)
439 if(aconf
== ptr
->data
)
441 rb_dlinkDestroy(ptr
, &temp_dlines
[i
]);
442 delete_one_address_conf(aconf
->host
, aconf
);