1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* m_jupe.c: Jupes a server. |
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 "irc_string.h" |
28 |
#include "sprintf_irc.h" |
29 |
#include "handlers.h" |
30 |
#include "channel.h" |
31 |
#include "client.h" |
32 |
#include "ircd.h" |
33 |
#include "numeric.h" |
34 |
#include "s_log.h" |
35 |
#include "s_serv.h" |
36 |
#include "send.h" |
37 |
#include "whowas.h" |
38 |
#include "hash.h" |
39 |
#include "msg.h" |
40 |
#include "parse.h" |
41 |
#include "modules.h" |
42 |
#include "common.h" |
43 |
#include "event.h" |
44 |
#include "fdlist.h" |
45 |
#include "s_conf.h" |
46 |
|
47 |
static void mo_jupe(struct Client *, struct Client *, int, char *[]); |
48 |
static int bogus_host(char *); |
49 |
|
50 |
struct Message jupe_msgtab = { |
51 |
"JUPE", 0, 0, 3, 0, MFLG_SLOW, 0, |
52 |
{m_unregistered, m_not_oper, mo_jupe, m_ignore, mo_jupe, m_ignore} |
53 |
}; |
54 |
|
55 |
#ifndef STATIC_MODULES |
56 |
void |
57 |
_modinit(void) |
58 |
{ |
59 |
mod_add_cmd(&jupe_msgtab); |
60 |
} |
61 |
|
62 |
void |
63 |
_moddeinit(void) |
64 |
{ |
65 |
mod_del_cmd(&jupe_msgtab); |
66 |
} |
67 |
|
68 |
const char *_version = "$Revision$"; |
69 |
#endif |
70 |
|
71 |
/* |
72 |
* mo_jupe() |
73 |
* parv[0] = sender prefix |
74 |
* parv[1] = server we're juping |
75 |
* parv[2] = reason for jupe |
76 |
*/ |
77 |
static void |
78 |
mo_jupe(struct Client *client_p, struct Client *source_p, |
79 |
int parc, char *parv[]) |
80 |
{ |
81 |
struct Client *target_p = NULL; |
82 |
struct Client *ajupe = NULL; |
83 |
dlink_node *m = NULL; |
84 |
char reason[REALLEN + 1]; |
85 |
|
86 |
if (!IsAdmin(source_p)) |
87 |
{ |
88 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
89 |
me.name, source_p->name); |
90 |
return; |
91 |
} |
92 |
|
93 |
if (*parv[2] == '\0') |
94 |
{ |
95 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
96 |
me.name, source_p->name, "JUPE"); |
97 |
return; |
98 |
} |
99 |
|
100 |
if (!ServerInfo.hub) |
101 |
{ |
102 |
sendto_one(source_p, ":%s NOTICE %s :Must be used from a hub server", |
103 |
me.name, source_p->name); |
104 |
return; |
105 |
} |
106 |
|
107 |
if (bogus_host(parv[1])) |
108 |
{ |
109 |
sendto_one(source_p, ":%s NOTICE %s :Invalid servername: %s", |
110 |
me.name, source_p->name, parv[1]); |
111 |
return; |
112 |
} |
113 |
|
114 |
if (match(parv[1], me.name)) |
115 |
{ |
116 |
sendto_one(source_p, ":%s NOTICE %s :I can't jupe myself!", |
117 |
me.name, source_p->name); |
118 |
return; |
119 |
} |
120 |
|
121 |
/* we need to give 7 chars to prepend "JUPED: " */ |
122 |
if (strlen(parv[2]) > (REALLEN - 7)) |
123 |
parv[2][REALLEN - 7] = '\0'; |
124 |
|
125 |
sendto_wallops_flags(UMODE_WALLOP, &me, |
126 |
"JUPE for %s requested by %s: %s", |
127 |
parv[1], get_oper_name(source_p), parv[2]); |
128 |
|
129 |
sendto_server(NULL, NULL, NOCAPS, NOCAPS, |
130 |
":%s WALLOPS :JUPE for %s requested by %s!%s@%s: %s", |
131 |
me.name, parv[1], source_p->name, |
132 |
source_p->username, source_p->host, parv[2]); |
133 |
ilog(L_NOTICE, "JUPE for %s requested by %s: %s", |
134 |
parv[1], get_oper_name(source_p), parv[2]); |
135 |
|
136 |
if ((target_p = find_server(parv[1])) != NULL) |
137 |
exit_client(target_p, &me, parv[2]); |
138 |
|
139 |
sendto_server(NULL, NULL, NOCAPS, NOCAPS, |
140 |
":%s SERVER %s 1 :JUPED: %s", |
141 |
me.name, parv[1], parv[2]); |
142 |
|
143 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
144 |
"Link with %s established: (JUPED) link", |
145 |
parv[1]); |
146 |
|
147 |
ajupe = make_client(NULL); |
148 |
|
149 |
/* make_client() adds client to unknown_list */ |
150 |
if ((m = dlinkFindDelete(&unknown_list, ajupe)) != NULL) |
151 |
free_dlink_node(m); |
152 |
|
153 |
make_server(ajupe); |
154 |
|
155 |
strlcpy(ajupe->name, parv[1], sizeof(ajupe->name)); |
156 |
ircsprintf(reason, "JUPED: %s", parv[2]); |
157 |
strlcpy(ajupe->info, reason, sizeof(ajupe->info)); |
158 |
|
159 |
ajupe->servptr = &me; |
160 |
ajupe->hopcount = 1; |
161 |
|
162 |
SetServer(ajupe); |
163 |
SetDead(ajupe); |
164 |
|
165 |
Count.myserver++; |
166 |
|
167 |
hash_add_client(ajupe); |
168 |
dlinkAdd(ajupe, &ajupe->lnode, &ajupe->servptr->serv->server_list); |
169 |
dlinkAdd(ajupe, make_dlink_node(), &global_serv_list); |
170 |
|
171 |
/* XXX is this really necessary? |
172 |
* for now, 'cause of the way squit works |
173 |
*/ |
174 |
dlinkAdd(ajupe, &ajupe->node, &global_client_list); |
175 |
} |
176 |
|
177 |
/* bogus_host() |
178 |
* |
179 |
* inputs - hostname |
180 |
* output - 1 if a bogus hostname input, |
181 |
* - 0 if its valid |
182 |
* side effects - none |
183 |
*/ |
184 |
static int |
185 |
bogus_host(char *host) |
186 |
{ |
187 |
unsigned int length = 0; |
188 |
unsigned int dots = 0; |
189 |
char *s = host; |
190 |
|
191 |
for (; *s; s++) |
192 |
{ |
193 |
if (!IsServChar(*s)) |
194 |
return 1; |
195 |
|
196 |
++length; |
197 |
|
198 |
if ('.' == *s) |
199 |
++dots; |
200 |
} |
201 |
|
202 |
return !dots || length > HOSTLEN; |
203 |
} |