ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/contrib/m_killhost.c
Revision: 76
Committed: Tue Oct 4 19:38:49 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-csrc
File size: 6488 byte(s)
Log Message:
- fixed contrib #includes

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

Properties

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