ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_connect.c
Revision: 4689
Committed: Fri Oct 3 13:05:54 2014 UTC (10 years, 10 months ago) by michael
Content type: text/x-csrc
File size: 8837 byte(s)
Log Message:
- m_connect.c: whitespace changes

File Contents

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

Properties

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