ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_connect.c
Revision: 470
Committed: Fri Feb 17 05:07:43 2006 UTC (18 years, 2 months ago) by db
Content type: text/x-csrc
File size: 9298 byte(s)
Log Message:
- fix compile errors with moved modules.h
- fix a few missing includes, msg.h and parse.h


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 "handlers.h"
27 #include "client.h"
28 #include "ircd.h"
29 #include "numeric.h"
30 #include "s_conf.h"
31 #include "s_serv.h"
32 #include "send.h"
33 #include "msg.h"
34 #include "parse.h"
35 #include "hash.h"
36 #include "conf/modules.h"
37
38 static void mo_connect(struct Client *, struct Client *, int, char *[]);
39 static void ms_connect(struct Client *, struct Client *, int, char *[]);
40
41 struct Message connect_msgtab = {
42 "CONNECT", 0, 0, 2, 0, MFLG_SLOW, 0,
43 { m_unregistered, m_not_oper, ms_connect, m_ignore, mo_connect, m_ignore }
44 };
45
46 INIT_MODULE(m_connect, "$Revision$")
47 {
48 mod_add_cmd(&connect_msgtab);
49 }
50
51 CLEANUP_MODULE
52 {
53 mod_del_cmd(&connect_msgtab);
54 }
55
56 /*! \brief CONNECT command handler (called for operators only)
57 *
58 * \param client_p Pointer to allocated Client struct with physical connection
59 * to this server, i.e. with an open socket connected.
60 * \param source_p Pointer to allocated Client struct from which the message
61 * originally comes from. This can be a local or remote client.
62 * \param parc Integer holding the number of supplied arguments.
63 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
64 * pointers.
65 * \note Valid arguments for this command are:
66 * - parv[0] = sender prefix
67 * - parv[1] = servername
68 * - parv[2] = port number
69 * - parv[3] = remote server
70 */
71 static void
72 mo_connect(struct Client *client_p, struct Client *source_p,
73 int parc, char *parv[])
74 {
75 int port = 0;
76 struct ConfItem *conf = NULL;
77 struct AccessItem *aconf = NULL;
78 struct Client *target_p = NULL;
79
80 /* always privileged with handlers */
81 if (MyConnect(source_p) && !IsOperRemote(source_p) && parc > 3)
82 {
83 sendto_one(source_p, form_str(ERR_NOPRIVS),
84 me.name, source_p->name, "connect");
85 return;
86 }
87
88 if (hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3,
89 parc, parv) != HUNTED_ISME)
90 return;
91
92 if (*parv[1] == '\0')
93 {
94 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
95 me.name, source_p->name, "CONNECT");
96 return;
97 }
98
99 if ((target_p = find_server(parv[1])))
100 {
101 sendto_one(source_p,
102 ":%s NOTICE %s :Connect: Server %s already exists from %s.",
103 me.name, source_p->name, parv[1], target_p->from->name);
104 return;
105 }
106
107 /*
108 * Try to find the name, then host, if both fail notify ops and bail
109 */
110 if ((conf = find_matching_name_conf(SERVER_TYPE,
111 parv[1], NULL, NULL, 0)) != NULL)
112 aconf = &conf->conf.AccessItem;
113 else if ((conf = find_matching_name_conf(SERVER_TYPE,
114 NULL, NULL, parv[1], 0)) != NULL)
115 aconf = &conf->conf.AccessItem;
116
117 if (conf == NULL)
118 {
119 sendto_one(source_p,
120 ":%s NOTICE %s :Connect: Host %s not listed in ircd.conf",
121 me.name, source_p->name, parv[1]);
122 return;
123 }
124
125 /*
126 * Get port number from user, if given. If not specified,
127 * use the default from configuration structure.
128 */
129 port = aconf->port;
130
131 if (parc > 2 && !EmptyString(parv[2]))
132 port = atoi(parv[2]);
133
134 if (port <= 0 || port > 0xFFFF)
135 {
136 sendto_one(source_p, ":%s NOTICE %s :Connect: Illegal or missing port number",
137 me.name, source_p->name);
138 return;
139 }
140
141 if (find_servconn_in_progress(conf->name))
142 {
143 sendto_one(source_p, ":%s NOTICE %s :Connect: a connection to %s "
144 "is already in progress.", me.name, source_p->name, conf->name);
145 return;
146 }
147
148 /*
149 * Notify all operators about remote connect requests
150 */
151 ilog(L_TRACE, "CONNECT From %s : %s %s",
152 source_p->name, parv[1], parv[2] ? parv[2] : "");
153
154 /*
155 * At this point we should be calling connect_server with a valid
156 * connect{} and a valid port in the connect{}
157 */
158 if (serv_connect(aconf, source_p, port))
159 {
160 if (!ConfigServerHide.hide_server_ips && IsAdmin(source_p))
161 sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s[%s].%d",
162 me.name, source_p->name, aconf->host,
163 conf->name, port);
164 else
165 sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d",
166 me.name, source_p->name, conf->name, port);
167 }
168 else
169 {
170 sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d",
171 me.name, source_p->name, conf->name, port);
172 }
173
174 /*
175 * Client is either connecting with all the data it needs or has been
176 * destroyed
177 */
178 }
179
180 /*! \brief CONNECT command handler (called for remote clients only)
181 *
182 * \param client_p Pointer to allocated Client struct with physical connection
183 * to this server, i.e. with an open socket connected.
184 * \param source_p Pointer to allocated Client struct from which the message
185 * originally comes from. This can be a local or remote client.
186 * \param parc Integer holding the number of supplied arguments.
187 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
188 * pointers.
189 * \note Valid arguments for this command are:
190 * - parv[0] = sender prefix
191 * - parv[1] = servername
192 * - parv[2] = port number
193 * - parv[3] = remote server
194 */
195 static void
196 ms_connect(struct Client *client_p, struct Client *source_p,
197 int parc, char *parv[])
198 {
199 int port = 0;
200 struct ConfItem *conf = NULL;
201 struct AccessItem *aconf = NULL;
202 struct Client *target_p = NULL;
203
204 if (hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3,
205 parc, parv) != HUNTED_ISME)
206 return;
207
208 if (*parv[1] == '\0')
209 {
210 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
211 me.name, source_p->name, "CONNECT");
212 return;
213 }
214
215 if ((target_p = find_server(parv[1])))
216 {
217 sendto_one(source_p,
218 ":%s NOTICE %s :Connect: Server %s already exists from %s.",
219 me.name, source_p->name, parv[1], target_p->from->name);
220 return;
221 }
222
223 /*
224 * Try to find the name, then host, if both fail notify ops and bail
225 */
226 if ((conf = find_matching_name_conf(SERVER_TYPE,
227 parv[1], NULL, NULL, 0)) != NULL)
228 aconf = &conf->conf.AccessItem;
229 else if ((conf = find_matching_name_conf(SERVER_TYPE,
230 NULL, NULL, parv[1], 0)) != NULL)
231 aconf = &conf->conf.AccessItem;
232
233 if (aconf == NULL)
234 {
235 sendto_one(source_p,
236 ":%s NOTICE %s :Connect: Host %s not listed in ircd.conf",
237 me.name, source_p->name, parv[1]);
238 return;
239 }
240
241 assert(aconf != NULL);
242
243 /*
244 * Get port number from user, if given. If not specified,
245 * use the default from configuration structure.
246 */
247 port = aconf->port;
248
249 if (parc > 2 && !EmptyString(parv[2]))
250 {
251 port = atoi(parv[2]);
252
253 /* if someone sends port 0, use the config port instead */
254 if (port == 0)
255 port = aconf->port;
256 }
257
258 if (port <= 0 || port > 0xFFFF)
259 {
260 sendto_one(source_p, ":%s NOTICE %s :Connect: Illegal or missing port number",
261 me.name, source_p->name);
262 return;
263 }
264
265 if (find_servconn_in_progress(conf->name))
266 {
267 sendto_one(source_p, ":%s NOTICE %s :Connect: a connection to %s "
268 "is already in progress.", me.name, source_p->name, conf->name);
269 return;
270 }
271
272 /*
273 * Notify all operators about remote connect requests
274 */
275 sendto_wallops_flags(UMODE_WALLOP, &me, "Remote CONNECT %s %d from %s",
276 parv[1], port, source_p->name);
277 sendto_server(NULL, NULL, NULL, NOCAPS, NOCAPS,
278 ":%s WALLOPS :Remote CONNECT %s %d from %s",
279 me.name, parv[1], port, source_p->name);
280
281 ilog(L_TRACE, "CONNECT From %s : %s %d",
282 source_p->name, parv[1], port);
283
284 /*
285 * At this point we should be calling connect_server with a valid
286 * connect{} and a valid port in the connect{}
287 */
288 if (serv_connect(aconf, source_p, port))
289 sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d",
290 me.name, source_p->name, conf->name, port);
291 else
292 sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d",
293 me.name, source_p->name, conf->name, port);
294
295 /*
296 * Client is either connecting with all the data it needs or has been
297 * destroyed
298 */
299 }

Properties

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