ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_connect.c
Revision: 2012
Committed: Sun May 12 14:47:26 2013 UTC (12 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 8874 byte(s)
Log Message:
- Removed 'remote', and 'global_kill' oper flags, and added 'connect',
  'squit', and 'kill' flags for better fine-tuning instead. Whether or 
  not a specific action is allowed on a remote server can be controlled
  by appeding the ':remote' flag. For example: 'kill' allows only local
  clients to be killed, whereas 'kill:remote' allows to issue a KILL for
  remote clients

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_connect.c: Connects to a remote IRC 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 "client.h"
27 #include "ircd.h"
28 #include "irc_string.h"
29 #include "numeric.h"
30 #include "fdlist.h"
31 #include "s_bsd.h"
32 #include "conf.h"
33 #include "log.h"
34 #include "s_serv.h"
35 #include "send.h"
36 #include "parse.h"
37 #include "hash.h"
38 #include "modules.h"
39
40
41 /*
42 * mo_connect - CONNECT command handler
43 *
44 * Added by Jto 11 Feb 1989
45 *
46 * m_connect
47 * parv[0] = sender prefix
48 * parv[1] = servername
49 * parv[2] = port number
50 * parv[3] = remote server
51 */
52 static void
53 mo_connect(struct Client *client_p, struct Client *source_p,
54 int parc, char *parv[])
55 {
56 int port;
57 int tmpport;
58 struct MaskItem *conf = NULL;
59 const struct Client *target_p = NULL;
60
61 if (EmptyString(parv[1]))
62 {
63 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
64 me.name, source_p->name, "CONNECT");
65 return;
66 }
67
68 if (parc > 3)
69 {
70 if (!HasOFlag(source_p, OPER_FLAG_CONNECT_REMOTE))
71 {
72 sendto_one(source_p, form_str(ERR_NOPRIVS),
73 me.name, source_p->name, "connect");
74 return;
75 }
76
77 if (hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3,
78 parc, parv) != HUNTED_ISME)
79 return;
80 }
81 else if (!HasOFlag(source_p, OPER_FLAG_CONNECT))
82 {
83 sendto_one(source_p, form_str(ERR_NOPRIVS),
84 me.name, source_p->name, "connect");
85 return;
86 }
87
88 if ((target_p = hash_find_server(parv[1])))
89 {
90 sendto_one(source_p,
91 ":%s NOTICE %s :Connect: Server %s already exists from %s.",
92 me.name, source_p->name, parv[1], target_p->from->name);
93 return;
94 }
95
96 /*
97 * try to find the name, then host, if both fail notify ops and bail
98 */
99 if (!(conf = find_matching_name_conf(CONF_SERVER, parv[1], NULL, NULL, 0)))
100 {
101 if (!(conf = find_matching_name_conf(CONF_SERVER, NULL, NULL, parv[1], 0)))
102 {
103 sendto_one(source_p,
104 ":%s NOTICE %s :Connect: Host %s not listed in ircd.conf",
105 me.name, source_p->name, parv[1]);
106 return;
107 }
108 }
109
110 /* Get port number from user, if given. If not specified,
111 * use the default form configuration structure. If missing
112 * from there, then use the precompiled default.
113 */
114 tmpport = port = conf->port;
115
116 if (parc > 2 && !EmptyString(parv[2]))
117 {
118 if ((port = atoi(parv[2])) <= 0)
119 {
120 sendto_one(source_p, ":%s NOTICE %s :Connect: Illegal port number",
121 me.name, source_p->name);
122 return;
123 }
124 }
125 else if (port <= 0 && (port = PORTNUM) <= 0)
126 {
127 sendto_one(source_p, ":%s NOTICE %s :Connect: missing port number",
128 me.name, source_p->name);
129 return;
130 }
131
132 if (find_servconn_in_progress(conf->name))
133 {
134 sendto_one(source_p, ":%s NOTICE %s :Connect: a connection to %s "
135 "is already in progress.", me.name, source_p->name, conf->name);
136 return;
137 }
138
139 /*
140 * Notify all operators about remote connect requests
141 */
142 ilog(LOG_TYPE_IRCD, "CONNECT From %s : %s %s",
143 source_p->name, parv[1], parv[2] ? parv[2] : "");
144
145 conf->port = port;
146
147 /* at this point we should be calling connect_server with a valid
148 * C:line and a valid port in the C:line
149 */
150 if (serv_connect(conf, source_p))
151 {
152 if (!ConfigServerHide.hide_server_ips && HasUMode(source_p, UMODE_ADMIN))
153 sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s[%s].%d",
154 me.name, source_p->name, conf->host,
155 conf->name, conf->port);
156 else
157 sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d",
158 me.name, source_p->name, conf->name, conf->port);
159 }
160 else
161 {
162 sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d",
163 me.name, source_p->name, conf->name, conf->port);
164 }
165
166 /* client is either connecting with all the data it needs or has been
167 * destroyed
168 */
169 conf->port = tmpport;
170 }
171
172 /*
173 * ms_connect - CONNECT command handler
174 *
175 * Added by Jto 11 Feb 1989
176 *
177 * m_connect
178 * parv[0] = sender prefix
179 * parv[1] = servername
180 * parv[2] = port number
181 * parv[3] = remote server
182 */
183 static void
184 ms_connect(struct Client *client_p, struct Client *source_p,
185 int parc, char *parv[])
186 {
187 int port;
188 int tmpport;
189 struct MaskItem *conf = NULL;
190 const struct Client *target_p = NULL;
191
192 if (hunt_server(client_p, source_p,
193 ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
194 return;
195
196 if (EmptyString(parv[1]))
197 {
198 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
199 me.name, source_p->name, "CONNECT");
200 return;
201 }
202
203 if ((target_p = hash_find_server(parv[1])))
204 {
205 sendto_one(source_p,
206 ":%s NOTICE %s :Connect: Server %s already exists from %s.",
207 me.name, source_p->name, parv[1], target_p->from->name);
208 return;
209 }
210
211 /*
212 * try to find the name, then host, if both fail notify ops and bail
213 */
214 if (!(conf = find_matching_name_conf(CONF_SERVER, parv[1], NULL, NULL, 0)))
215 {
216 if (!(conf = find_matching_name_conf(CONF_SERVER, NULL, NULL, parv[1], 0)))
217 {
218 sendto_one(source_p,
219 ":%s NOTICE %s :Connect: Host %s not listed in ircd.conf",
220 me.name, source_p->name, parv[1]);
221 return;
222 }
223 }
224
225 /* Get port number from user, if given. If not specified,
226 * use the default form configuration structure. If missing
227 * from there, then use the precompiled default.
228 */
229 tmpport = port = conf->port;
230
231 if (parc > 2 && !EmptyString(parv[2]))
232 {
233 port = atoi(parv[2]);
234
235 /* if someone sends port 0, and we have a config port.. use it */
236 if (port == 0 && conf->port)
237 port = conf->port;
238 else if (port <= 0)
239 {
240 sendto_one(source_p, ":%s NOTICE %s :Connect: Illegal port number",
241 me.name, source_p->name);
242 return;
243 }
244 }
245 else if (port <= 0 && (port = PORTNUM) <= 0)
246 {
247 sendto_one(source_p, ":%s NOTICE %s :Connect: missing port number",
248 me.name, source_p->name);
249 return;
250 }
251
252 if (find_servconn_in_progress(conf->name))
253 {
254 sendto_one(source_p, ":%s NOTICE %s :Connect: a connection to %s "
255 "is already in progress.", me.name, source_p->name, conf->name);
256 return;
257 }
258
259 /*
260 * Notify all operators about remote connect requests
261 */
262 sendto_wallops_flags(UMODE_WALLOP, &me, "Remote CONNECT %s %d from %s",
263 parv[1], port, source_p->name);
264 sendto_server(NULL, NOCAPS, CAP_TS6,
265 ":%s WALLOPS :Remote CONNECT %s %d from %s",
266 me.name, parv[1], port, source_p->name);
267 sendto_server(NULL, CAP_TS6, NOCAPS,
268 ":%s WALLOPS :Remote CONNECT %s %d from %s",
269 me.id, parv[1], port, source_p->name);
270
271 ilog(LOG_TYPE_IRCD, "CONNECT From %s : %s %d",
272 source_p->name, parv[1], port);
273
274 conf->port = port;
275
276 /*
277 * At this point we should be calling connect_server with a valid
278 * C:line and a valid port in the C:line
279 */
280 if (serv_connect(conf, source_p))
281 sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d",
282 me.name, source_p->name, conf->name, conf->port);
283 else
284 sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d",
285 me.name, source_p->name, conf->name, conf->port);
286 /*
287 * Client is either connecting with all the data it needs or has been
288 * destroyed
289 */
290 conf->port = tmpport;
291 }
292
293 static struct Message connect_msgtab = {
294 "CONNECT", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
295 { m_unregistered, m_not_oper, ms_connect, m_ignore, mo_connect, m_ignore }
296 };
297
298 static void
299 module_init(void)
300 {
301 mod_add_cmd(&connect_msgtab);
302 }
303
304 static void
305 module_exit(void)
306 {
307 mod_del_cmd(&connect_msgtab);
308 }
309
310 struct module module_entry = {
311 .node = { NULL, NULL, NULL },
312 .name = NULL,
313 .version = "$Revision$",
314 .handle = NULL,
315 .modinit = module_init,
316 .modexit = module_exit,
317 .flags = 0
318 };

Properties

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