/[svn]/ircd-hybrid/branches/8.2.x/modules/m_connect.c
ViewVC logotype

Contents of /ircd-hybrid/branches/8.2.x/modules/m_connect.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6364 - (show annotations)
Wed Aug 19 09:59:43 2015 UTC (4 years, 10 months ago) by michael
File MIME type: text/x-chdr
File size: 8853 byte(s)
- Remove unused header includes

1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2015 ircd-hybrid development team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file m_connect.c
23 * \brief Includes required functions for processing the CONNECT command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "client.h"
29 #include "ircd.h"
30 #include "irc_string.h"
31 #include "numeric.h"
32 #include "conf.h"
33 #include "log.h"
34 #include "server.h"
35 #include "send.h"
36 #include "parse.h"
37 #include "hash.h"
38 #include "modules.h"
39
40
41 /*! \brief CONNECT command handler
42 *
43 * \param source_p Pointer to allocated Client struct from which the message
44 * originally comes from. This can be a local or remote client.
45 * \param parc Integer holding the number of supplied arguments.
46 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
47 * pointers.
48 * \note Valid arguments for this command are:
49 * - parv[0] = command
50 * - parv[1] = target server
51 * - parv[2] = port number
52 * - parv[3] = nickname/servername
53 */
54 static int
55 mo_connect(struct Client *source_p, int parc, char *parv[])
56 {
57 int port = 0, tmpport = 0;
58 struct MaskItem *conf = NULL;
59 const struct Client *target_p = NULL;
60
61 if (EmptyString(parv[1]))
62 {
63 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "CONNECT");
64 return 0;
65 }
66
67 if (parc > 3)
68 {
69 if (!HasOFlag(source_p, OPER_FLAG_CONNECT_REMOTE))
70 {
71 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "connect:remote");
72 return 0;
73 }
74
75 if (hunt_server(source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
76 return 0;
77 }
78 else if (!HasOFlag(source_p, OPER_FLAG_CONNECT))
79 {
80 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "connect");
81 return 0;
82 }
83
84 /*
85 * Try to find the name, then host, if both fail notify ops and bail
86 */
87 if (!(conf = find_matching_name_conf(CONF_SERVER, parv[1], NULL, NULL, 0)) &&
88 !(conf = find_matching_name_conf(CONF_SERVER, NULL, NULL, parv[1], 0)))
89 {
90 sendto_one_notice(source_p, &me, ":Connect: Host %s not listed in configuration file", parv[1]);
91 return 0;
92 }
93
94 if ((target_p = hash_find_server(conf->name)))
95 {
96 sendto_one_notice(source_p, &me, ":Connect: Server %s already exists from %s.",
97 target_p->name, target_p->from->name);
98 return 0;
99 }
100
101 /*
102 * Get port number from user, if given. If not specified,
103 * use the default from configuration structure. If missing
104 * from there, then use the precompiled default.
105 */
106 tmpport = port = conf->port;
107
108 if (parc > 2 && !EmptyString(parv[2]))
109 {
110 if ((port = atoi(parv[2])) <= 0)
111 {
112 sendto_one_notice(source_p, &me, ":Connect: Illegal port number");
113 return 0;
114 }
115 }
116 else if (port <= 0 && (port = PORTNUM) <= 0)
117 {
118 sendto_one_notice(source_p, &me, ":Connect: missing port number");
119 return 0;
120 }
121
122 if (find_servconn_in_progress(conf->name))
123 {
124 sendto_one_notice(source_p, &me, ":Connect: a connection to %s "
125 "is already in progress.", conf->name);
126 return 0;
127 }
128
129 /*
130 * Notify all operators about remote connect requests
131 */
132 ilog(LOG_TYPE_IRCD, "CONNECT From %s : %s %s",
133 source_p->name, parv[1], parv[2] ? parv[2] : "");
134
135 conf->port = port;
136
137 /*
138 * At this point we should be calling connect_server with a valid
139 * connect{} block and a valid port in the connect{} block
140 */
141 if (serv_connect(conf, source_p))
142 {
143 if (!ConfigServerHide.hide_server_ips && HasUMode(source_p, UMODE_ADMIN))
144 sendto_one_notice(source_p, &me, ":*** Connecting to %s[%s].%d",
145 conf->host, conf->name, conf->port);
146 else
147 sendto_one_notice(source_p, &me, ":*** Connecting to %s.%d",
148 conf->name, conf->port);
149 }
150 else
151 sendto_one_notice(source_p, &me, ":*** Couldn't connect to %s.%d",
152 conf->name, conf->port);
153
154 /*
155 * Client is either connecting with all the data it needs or has been
156 * destroyed
157 */
158 conf->port = tmpport;
159 return 0;
160 }
161
162 /*! \brief CONNECT command handler
163 *
164 * \param source_p Pointer to allocated Client struct from which the message
165 * originally comes from. This can be a local or remote client.
166 * \param parc Integer holding the number of supplied arguments.
167 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
168 * pointers.
169 * \note Valid arguments for this command are:
170 * - parv[0] = command
171 * - parv[1] = target server
172 * - parv[2] = port number
173 * - parv[3] = nickname/servername
174 */
175 static int
176 ms_connect(struct Client *source_p, int parc, char *parv[])
177 {
178 int port = 0, tmpport = 0;
179 struct MaskItem *conf = NULL;
180 const struct Client *target_p = NULL;
181
182 if (parc < 4 || EmptyString(parv[3]))
183 {
184 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "CONNECT");
185 return 0;
186 }
187
188 if (hunt_server(source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
189 return 0;
190
191 /*
192 * Try to find the name, then host, if both fail notify ops and bail
193 */
194 if (!(conf = find_matching_name_conf(CONF_SERVER, parv[1], NULL, NULL, 0)) &&
195 !(conf = find_matching_name_conf(CONF_SERVER, NULL, NULL, parv[1], 0)))
196 {
197 sendto_one_notice(source_p, &me, ":Connect: Host %s not listed in configuration file", parv[1]);
198 return 0;
199 }
200
201 if ((target_p = hash_find_server(conf->name)))
202 {
203 sendto_one_notice(source_p, &me, ":Connect: Server %s already exists from %s.",
204 target_p->name, target_p->from->name);
205 return 0;
206 }
207
208 /*
209 * Get port number from user, if given. If not specified,
210 * use the default from configuration structure. If missing
211 * from there, then use the precompiled default.
212 */
213 tmpport = port = conf->port;
214
215 if (parc > 2 && !EmptyString(parv[2]))
216 {
217 port = atoi(parv[2]);
218
219 /*
220 * If someone sends port 0, and we have a config port.. use it
221 */
222 if (port == 0 && conf->port)
223 port = conf->port;
224 else if (port <= 0)
225 {
226 sendto_one_notice(source_p, &me, ":Connect: Illegal port number");
227 return 0;
228 }
229 }
230 else if (port <= 0 && (port = PORTNUM) <= 0)
231 {
232 sendto_one_notice(source_p, &me, ":Connect: missing port number");
233 return 0;
234 }
235
236 if (find_servconn_in_progress(conf->name))
237 {
238 sendto_one_notice(source_p, &me, ":Connect: a connection to %s "
239 "is already in progress.", conf->name);
240 return 0;
241 }
242
243 /*
244 * Notify all operators about remote connect requests
245 */
246 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_GLOBAL, "from %s: Remote CONNECT %s %d from %s",
247 me.name, parv[1], port, source_p->name);
248 sendto_server(NULL, 0, 0,
249 ":%s GLOBOPS :Remote CONNECT %s %d from %s",
250 me.id, parv[1], port, source_p->name);
251
252 ilog(LOG_TYPE_IRCD, "CONNECT From %s : %s %d",
253 source_p->name, parv[1], port);
254
255 conf->port = port;
256
257 /*
258 * At this point we should be calling connect_server with a valid
259 * connect{} block and a valid port in the connect{} block
260 */
261 if (serv_connect(conf, source_p))
262 sendto_one_notice(source_p, &me, ":*** Connecting to %s.%d",
263 conf->name, conf->port);
264 else
265 sendto_one_notice(source_p, &me, ":*** Couldn't connect to %s.%d",
266 conf->name, conf->port);
267 /*
268 * Client is either connecting with all the data it needs or has been
269 * destroyed
270 */
271 conf->port = tmpport;
272 return 0;
273 }
274
275 static struct Message connect_msgtab =
276 {
277 .cmd = "CONNECT",
278 .args_min = 2,
279 .args_max = MAXPARA,
280 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
281 .handlers[CLIENT_HANDLER] = m_not_oper,
282 .handlers[SERVER_HANDLER] = ms_connect,
283 .handlers[ENCAP_HANDLER] = m_ignore,
284 .handlers[OPER_HANDLER] = mo_connect
285 };
286
287 static void
288 module_init(void)
289 {
290 mod_add_cmd(&connect_msgtab);
291 }
292
293 static void
294 module_exit(void)
295 {
296 mod_del_cmd(&connect_msgtab);
297 }
298
299 struct module module_entry =
300 {
301 .version = "$Revision$",
302 .modinit = module_init,
303 .modexit = module_exit,
304 };

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28