ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/contrib/m_killhost.c
Revision: 112
Committed: Wed Oct 12 14:35:04 2005 UTC (20 years, 9 months ago) by knight
Content type: text/x-csrc
File size: 6513 byte(s)
Log Message:
- Missing header; parse_aline.h for function valid_wild_card()

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * m_killhost.c: Kills a users with agree host.
4     *
5     * Copyright (C) 2002 by Ilya Shtift.
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 knight 31 * $Id$
23 adx 30 *
24     */
25    
26     #include "stdinc.h"
27     #include "handlers.h"
28     #include "client.h"
29     #include "common.h"
30     #include "hash.h"
31     #include "ircd.h"
32     #include "numeric.h"
33     #include "s_serv.h"
34     #include "s_conf.h"
35     #include "send.h"
36     #include "whowas.h"
37     #include "msg.h"
38     #include "parse.h"
39     #include "channel_mode.h" /* needed only for split_nuh() */
40     #include "modules.h"
41 knight 112 #include "parse_aline.h"
42 adx 30
43     static void mo_killhost(struct Client *, struct Client *, int, char *[]);
44     static void kh_relay_kill(struct Client *, struct Client *, struct Client *,
45     const char *, const char *);
46    
47     struct Message killhost_msgtab = {
48     "KILLHOST", 0, 0, 2, 0, MFLG_SLOW, 0,
49     { m_unregistered, m_ignore, m_ignore, m_ignore, mo_killhost, m_ignore }
50     };
51    
52     #ifndef STATIC_MODULES
53     void
54     _modinit(void)
55     {
56     mod_add_cmd(&killhost_msgtab);
57     }
58    
59     void
60     _moddeinit(void)
61     {
62     mod_del_cmd(&killhost_msgtab);
63     }
64    
65 knight 31 const char *_version = "$Revision$";
66 adx 30 #endif
67    
68     /* mo_killhost()
69     * Created May 5, 2003
70     * common (Ilya Shtift) ishtift@tagil.svrw.ru
71     *
72     * parv[0] = sender prefix
73     * parv[1] = host
74     * parv[2] = reason
75     */
76     static void
77     mo_killhost(struct Client *client_p, struct Client *source_p,
78     int parc, char *parv[])
79     {
80     dlink_node *ptr = NULL, *ptr_next = NULL;
81     struct Client *target_p = NULL;
82     const char *inpath = client_p->name;
83     char *nick = NULL;
84     char *user = NULL;
85     char *host = NULL;
86     char *reason = NULL;
87     char bufhost[IRCD_BUFSIZE];
88     char buf_nuh[NICKLEN + USERLEN + HOSTLEN + 3];
89     char def_reason[] = "No reason specified";
90     unsigned int count = 0;
91    
92     if (!(IsOperK(source_p) || IsOperGlobalKill(source_p)))
93     {
94     sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
95     me.name, source_p->name);
96     return;
97     }
98    
99     strlcpy(buf_nuh, parv[1], sizeof(buf_nuh));
100     split_nuh(buf_nuh, &nick, &user, &host);
101    
102     if (!valid_wild_card(source_p, YES, 3, nick, user, host))
103     goto cleanup;
104    
105     if (!EmptyString(parv[2]))
106     {
107     reason = parv[2];
108     if (strlen(reason) > (size_t)KILLLEN)
109     reason[KILLLEN] = '\0';
110     }
111     else
112     reason = def_reason;
113    
114     DLINK_FOREACH_SAFE(ptr, ptr_next, global_client_list.head)
115     {
116     target_p = ptr->data;
117    
118     if (!IsClient(target_p) || (source_p == target_p))
119     continue;
120    
121     if (!MyConnect(target_p) && !IsOperGlobalKill(source_p))
122     continue;
123    
124     if (match(nick, target_p->name) &&
125     match(user, target_p->username) &&
126     match(host, target_p->host))
127     {
128     if (MyConnect(target_p))
129     sendto_one(target_p, ":%s!%s@%s KILL %s :%s",
130     source_p->name, source_p->username, source_p->host,
131     target_p->name, reason);
132    
133     sendto_realops_flags(UMODE_ALL, L_ALL,
134     "Received KILL message for %s. From %s Path: %s (%s)",
135     target_p->name, source_p->name, me.name, reason);
136    
137     ilog(L_INFO,"KILL From %s For %s Path %s (%s)",
138     source_p->name, target_p->name, me.name, reason);
139    
140     if (!MyConnect(target_p))
141     {
142     kh_relay_kill(client_p, source_p, target_p, inpath, reason);
143     SetKilled(target_p);
144     }
145    
146     if (!count++)
147     ircsprintf(bufhost, "Killed (%s (%s))", source_p->name, reason);
148    
149     exit_client(target_p, source_p, bufhost);
150     }
151     }
152    
153     if (count > 0)
154     sendto_wallops_flags(UMODE_OPERWALL, source_p, "OPERWALL - KILLHOST %s %s",
155     host, reason);
156    
157     sendto_one(source_p,":%s NOTICE %s :%u clients killed",
158     me.name, source_p->name, count);
159     cleanup:
160     MyFree(nick);
161     MyFree(user);
162     MyFree(host);
163     }
164    
165     static void
166     kh_relay_kill(struct Client *one, struct Client *source_p, struct Client *target_p,
167     const char *inpath, const char *reason)
168     {
169     dlink_node *ptr;
170     struct Client *client_p;
171     int introduce_killed_client;
172     char *user;
173    
174     /* LazyLinks:
175     * Check if each lazylink knows about target_p.
176     * If it does, send the kill, introducing source_p if required.
177     * If it doesn't either:
178     * a) don't send the kill (risk ghosts)
179     * b) introduce the client (and source_p, if required)
180     * [rather redundant]
181     *
182     * Use a) if IsServer(source_p), but if an oper kills someone,
183     * ensure we blow away any ghosts.
184     *
185     * -davidt
186     */
187    
188     if(IsServer(source_p))
189     introduce_killed_client = 0;
190     else
191     introduce_killed_client = 1;
192    
193     DLINK_FOREACH(ptr, serv_list.head)
194     {
195     client_p = ptr->data;
196    
197     if (client_p == one)
198     continue;
199    
200     if (!introduce_killed_client)
201     {
202     if (ServerInfo.hub && IsCapable(client_p, CAP_LL) )
203     {
204     if (((client_p->localClient->serverMask &
205     target_p->lazyLinkClientExists) == 0))
206     {
207     /* target isn't known to lazy leaf, skip it */
208     continue;
209     }
210     }
211     }
212     /* force introduction of killed client but check that
213     * its not on the server we're bursting too.. */
214     else if (strcmp(target_p->servptr->name,client_p->name))
215     client_burst_if_needed(client_p, target_p);
216    
217     /* introduce source of kill */
218     client_burst_if_needed(client_p, source_p);
219    
220     /* check the server supports TS6 */
221     if (IsCapable(client_p, CAP_TS6))
222     user = ID(target_p);
223     else
224     user = target_p->name;
225    
226     if (MyClient(source_p))
227     {
228     sendto_one(client_p, ":%s KILL %s :%s!%s!%s!%s (%s)",
229     source_p->name, user,
230     me.name, source_p->host, source_p->username,
231     source_p->name, reason);
232     }
233     else
234     {
235     sendto_one(client_p, ":%s KILL %s :%s %s",
236     source_p->name, user,
237     inpath, reason);
238     }
239     }
240     }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision