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"
48 static int mo_dline(struct Client
*, struct Client
*, int, const char **);
49 static int me_dline(struct Client
*, struct Client
*, int, const char **);
50 static int mo_undline(struct Client
*, struct Client
*, int, const char **);
51 static int me_undline(struct Client
*, struct Client
*, int, const char **);
53 struct Message dline_msgtab
= {
54 "DLINE", 0, 0, 0, MFLG_SLOW
,
55 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_dline
, 3}, {mo_dline
, 2}}
58 struct Message undline_msgtab
= {
59 "UNDLINE", 0, 0, 0, MFLG_SLOW
,
60 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_undline
, 1}, {mo_undline
, 2}}
63 mapi_clist_av1 dline_clist
[] = { &dline_msgtab
, &undline_msgtab
, NULL
};
65 DECLARE_MODULE_AV1(dline
, NULL
, NULL
, dline_clist
, NULL
, NULL
, "$Revision$");
67 static int valid_comment(char *comment
);
68 static int remove_temp_dline(struct ConfItem
*);
69 static int apply_dline(struct Client
*, const char *, int, char *);
70 static int apply_undline(struct Client
*, const char *);
74 * parv[1] - dline to add
78 mo_dline(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
80 char def
[] = "No Reason";
83 char cidr_form_host
[HOSTLEN
+ 1];
85 const char *target_server
= NULL
;
88 if(!IsOperK(source_p
))
90 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "kline");
94 if((tdline_time
= valid_temp_time(parv
[loc
])) >= 0)
98 rb_strlcpy(cidr_form_host
, dlhost
, sizeof(cidr_form_host
));
101 /* would break the protocol */
104 sendto_one_notice(source_p
, ":Invalid D-Line");
108 if(parc
>= loc
+ 2 && !irccmp(parv
[loc
], "ON"))
110 if(!IsOperRemoteBan(source_p
))
112 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
113 me
.name
, source_p
->name
, "remoteban");
117 target_server
= parv
[loc
+ 1];
121 if(parc
>= loc
+ 1 && !EmptyString(parv
[loc
]))
122 reason
= LOCAL_COPY(parv
[loc
]);
124 if(target_server
!= NULL
)
126 sendto_match_servs(source_p
, target_server
,
128 "ENCAP %s DLINE %d %s :%s",
129 target_server
, tdline_time
, dlhost
, reason
);
131 if(!match(target_server
, me
.name
))
135 apply_dline(source_p
, dlhost
, tdline_time
, reason
);
143 * parv[1] = dline to remove
146 mo_undline(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
149 const char *target_server
= NULL
;
151 if(!IsOperK(source_p
))
153 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "unkline");
159 if(parc
>= 4 && !irccmp(parv
[2], "ON"))
161 if(!IsOperRemoteBan(source_p
))
163 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
164 me
.name
, source_p
->name
, "remoteban");
168 target_server
= parv
[3];
169 sendto_match_servs(source_p
, target_server
,
170 CAP_ENCAP
, NOCAPS
, "ENCAP %s UNDLINE %s", target_server
, cidr
);
172 if(!match(target_server
, me
.name
))
176 apply_undline(source_p
, cidr
);
182 me_dline(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
184 int tdline_time
= atoi(parv
[1]);
185 /* Since this is coming over a server link, assume that the originating
186 * server did the relevant permission/sanity checks...
189 if(!IsPerson(source_p
))
192 if(!find_shared_conf(source_p
->username
, source_p
->host
,
193 source_p
->servptr
->name
,
194 tdline_time
> 0 ? SHARED_TDLINE
: SHARED_PDLINE
))
197 apply_dline(source_p
, parv
[2], tdline_time
, LOCAL_COPY(parv
[3]));
204 me_undline(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
206 if(!IsPerson(source_p
))
209 if(!find_shared_conf(source_p
->username
, source_p
->host
,
210 source_p
->servptr
->name
, SHARED_UNDLINE
))
213 apply_undline(source_p
, parv
[1]);
219 apply_dline(struct Client
*source_p
, const char *dlhost
, int tdline_time
, char *reason
)
221 struct ConfItem
*aconf
;
223 struct rb_sockaddr_storage daddr
;
224 int t
= AF_INET
, ty
, b
;
227 ty
= parse_netmask(dlhost
, (struct sockaddr
*) &daddr
, &b
);
230 sendto_one(source_p
, ":%s NOTICE %s :Invalid D-Line", me
.name
, source_p
->name
);
240 /* This means dlines wider than /16 cannot be set remotely */
241 if(IsOperAdmin(source_p
))
245 sendto_one_notice(source_p
,
246 ":For safety, bitmasks less than 8 require conf access.");
254 sendto_one_notice(source_p
,
255 ":Dline bitmasks less than 16 are for admins only.");
260 if(!valid_comment(reason
))
263 ":%s NOTICE %s :Invalid character '\"' in comment",
264 me
.name
, source_p
->name
);
268 if(ConfigFileEntry
.non_redundant_klines
)
270 if((aconf
= find_dline((struct sockaddr
*) &daddr
, t
)) != NULL
)
273 parse_netmask(aconf
->host
, NULL
, &bx
);
276 creason
= aconf
->passwd
? aconf
->passwd
: "<No Reason>";
277 if(IsConfExemptKline(aconf
))
279 ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
280 me
.name
, source_p
->name
, dlhost
, aconf
->host
,
284 ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
285 me
.name
, source_p
->name
, dlhost
, aconf
->host
,
295 aconf
->status
= CONF_DLINE
;
296 aconf
->created
= rb_current_time();
297 aconf
->host
= rb_strdup(dlhost
);
298 aconf
->passwd
= rb_strdup(reason
);
299 aconf
->info
.oper
= operhash_add(get_oper_name(source_p
));
301 /* Look for an oper reason */
302 if((oper_reason
= strchr(reason
, '|')) != NULL
)
307 if(!EmptyString(oper_reason
))
308 aconf
->spasswd
= rb_strdup(oper_reason
);
313 aconf
->hold
= rb_current_time() + tdline_time
;
314 add_temp_dline(aconf
);
316 if(EmptyString(oper_reason
))
318 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
319 "%s added temporary %d min. D-Line for [%s] [%s]",
320 get_oper_name(source_p
), tdline_time
/ 60,
321 aconf
->host
, reason
);
322 ilog(L_KLINE
, "D %s %d %s %s",
323 get_oper_name(source_p
), tdline_time
/ 60, aconf
->host
, reason
);
327 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
328 "%s added temporary %d min. D-Line for [%s] [%s|%s]",
329 get_oper_name(source_p
), tdline_time
/ 60,
330 aconf
->host
, reason
, oper_reason
);
331 ilog(L_KLINE
, "D %s %d %s %s|%s",
332 get_oper_name(source_p
), tdline_time
/ 60,
333 aconf
->host
, reason
, oper_reason
);
336 sendto_one(source_p
, ":%s NOTICE %s :Added temporary %d min. D-Line for [%s]",
337 me
.name
, source_p
->name
, tdline_time
/ 60, aconf
->host
);
341 add_conf_by_address(aconf
->host
, CONF_DLINE
, NULL
, NULL
, aconf
);
343 bandb_add(BANDB_DLINE
, source_p
, aconf
->host
, NULL
,
344 reason
, EmptyString(aconf
->spasswd
) ? NULL
: aconf
->spasswd
, 0);
346 if(EmptyString(oper_reason
))
348 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
349 "%s added D-Line for [%s] [%s]",
350 get_oper_name(source_p
), aconf
->host
, reason
);
351 ilog(L_KLINE
, "D %s 0 %s %s",
352 get_oper_name(source_p
), aconf
->host
, reason
);
356 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
357 "%s added D-Line for [%s] [%s|%s]",
358 get_oper_name(source_p
), aconf
->host
, reason
, oper_reason
);
359 ilog(L_KLINE
, "D %s 0 %s %s|%s",
360 get_oper_name(source_p
),
361 aconf
->host
, reason
, oper_reason
);
369 apply_undline(struct Client
*source_p
, const char *cidr
)
372 struct ConfItem
*aconf
;
374 if(parse_netmask(cidr
, NULL
, NULL
) == HM_HOST
)
376 sendto_one_notice(source_p
, ":Invalid D-Line");
380 aconf
= find_exact_conf_by_address(cidr
, CONF_DLINE
, NULL
);
383 sendto_one_notice(source_p
, ":No D-Line for %s", cidr
);
387 rb_strlcpy(buf
, aconf
->host
, sizeof buf
);
388 if(remove_temp_dline(aconf
))
391 ":%s NOTICE %s :Un-dlined [%s] from temporary D-lines",
392 me
.name
, source_p
->name
, buf
);
393 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
394 "%s has removed the temporary D-Line for: [%s]",
395 get_oper_name(source_p
), buf
);
396 ilog(L_KLINE
, "UD %s %s", get_oper_name(source_p
), buf
);
400 bandb_del(BANDB_DLINE
, aconf
->host
, NULL
);
402 sendto_one(source_p
, ":%s NOTICE %s :D-Line for [%s] is removed", me
.name
, source_p
->name
,
404 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s has removed the D-Line for: [%s]",
405 get_oper_name(source_p
), aconf
->host
);
406 ilog(L_KLINE
, "UD %s %s", get_oper_name(source_p
), aconf
->host
);
407 delete_one_address_conf(aconf
->host
, aconf
);
414 * inputs - pointer to client
415 * - pointer to comment
416 * output - 0 if no valid comment, 1 if valid
417 * side effects - NONE
420 valid_comment(char *comment
)
422 if(strchr(comment
, '"'))
425 if(strlen(comment
) > BANREASONLEN
)
426 comment
[BANREASONLEN
] = '\0';
431 /* remove_temp_dline()
433 * inputs - confitem to undline
435 * side effects - tries to undline anything that matches
438 remove_temp_dline(struct ConfItem
*aconf
)
443 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
445 RB_DLINK_FOREACH(ptr
, temp_dlines
[i
].head
)
447 if(aconf
== ptr
->data
)
449 rb_dlinkDestroy(ptr
, &temp_dlines
[i
]);
450 delete_one_address_conf(aconf
->host
, aconf
);