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

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 2820 * Copyright (c) 1997-2014 ircd-hybrid development team
5 adx 30 *
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 michael 4564 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2820 /*! \file m_connect.c
23     * \brief Includes required functions for processing the CONNECT command.
24     * \version $Id$
25     */
26    
27 adx 30 #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 michael 1309 #include "conf.h"
35     #include "log.h"
36 michael 3347 #include "server.h"
37 adx 30 #include "send.h"
38     #include "parse.h"
39     #include "hash.h"
40     #include "modules.h"
41    
42    
43 michael 3300 /*! \brief CONNECT command handler
44 adx 30 *
45 michael 3300 * \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 adx 30 */
56 michael 2820 static int
57 michael 3156 mo_connect(struct Client *source_p, int parc, char *parv[])
58 adx 30 {
59 michael 3874 int port = 0, tmpport = 0;
60 michael 1632 struct MaskItem *conf = NULL;
61 michael 971 const struct Client *target_p = NULL;
62 adx 30
63 michael 971 if (EmptyString(parv[1]))
64 adx 30 {
65 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "CONNECT");
66 michael 2820 return 0;
67 adx 30 }
68    
69 michael 971 if (parc > 3)
70     {
71 michael 2012 if (!HasOFlag(source_p, OPER_FLAG_CONNECT_REMOTE))
72 michael 971 {
73 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "connect:remote");
74 michael 2820 return 0;
75 michael 971 }
76 adx 30
77 michael 4682 if (hunt_server(source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
78 michael 2820 return 0;
79 adx 30 }
80 michael 2012 else if (!HasOFlag(source_p, OPER_FLAG_CONNECT))
81     {
82 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "connect");
83 michael 2820 return 0;
84 michael 2012 }
85 adx 30
86     /*
87 michael 2820 * Try to find the name, then host, if both fail notify ops and bail
88 adx 30 */
89 michael 4682 if (!(conf = find_matching_name_conf(CONF_SERVER, parv[1], NULL, NULL, 0)) &&
90 michael 4688 !(conf = find_matching_name_conf(CONF_SERVER, NULL, NULL, parv[1], 0)))
91 adx 30 {
92 michael 4686 sendto_one_notice(source_p, &me, ":Connect: Host %s not listed in configuration file", parv[1]);
93 michael 4682 return 0;
94 adx 30 }
95 michael 971
96 michael 4681 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 michael 2345 /*
104     * Get port number from user, if given. If not specified,
105 michael 4682 * use the default from configuration structure. If missing
106 adx 30 * from there, then use the precompiled default.
107     */
108 michael 1632 tmpport = port = conf->port;
109 adx 30
110     if (parc > 2 && !EmptyString(parv[2]))
111     {
112     if ((port = atoi(parv[2])) <= 0)
113     {
114 michael 3110 sendto_one_notice(source_p, &me, ":Connect: Illegal port number");
115 michael 2820 return 0;
116 adx 30 }
117     }
118     else if (port <= 0 && (port = PORTNUM) <= 0)
119     {
120 michael 3110 sendto_one_notice(source_p, &me, ":Connect: missing port number");
121 michael 2820 return 0;
122 adx 30 }
123    
124     if (find_servconn_in_progress(conf->name))
125     {
126 michael 3110 sendto_one_notice(source_p, &me, ":Connect: a connection to %s "
127     "is already in progress.", conf->name);
128 michael 2820 return 0;
129 adx 30 }
130    
131     /*
132     * Notify all operators about remote connect requests
133     */
134 michael 3795 ilog(LOG_TYPE_IRCD, "CONNECT From %s : %s %s",
135 adx 30 source_p->name, parv[1], parv[2] ? parv[2] : "");
136    
137 michael 1632 conf->port = port;
138 adx 30
139 michael 2345 /*
140 michael 2820 * At this point we should be calling connect_server with a valid
141 michael 3300 * connect{} block and a valid port in the connect{} block
142 adx 30 */
143 michael 1632 if (serv_connect(conf, source_p))
144 adx 30 {
145 michael 1219 if (!ConfigServerHide.hide_server_ips && HasUMode(source_p, UMODE_ADMIN))
146 michael 3110 sendto_one_notice(source_p, &me, ":*** Connecting to %s[%s].%d",
147     conf->host, conf->name, conf->port);
148 adx 30 else
149 michael 3110 sendto_one_notice(source_p, &me, ":*** Connecting to %s.%d",
150     conf->name, conf->port);
151 adx 30 }
152     else
153 michael 3110 sendto_one_notice(source_p, &me, ":*** Couldn't connect to %s.%d",
154     conf->name, conf->port);
155 adx 30
156 michael 2345 /*
157     * Client is either connecting with all the data it needs or has been
158 adx 30 * destroyed
159     */
160 michael 1632 conf->port = tmpport;
161 michael 2820 return 0;
162 adx 30 }
163    
164 michael 3300 /*! \brief CONNECT command handler
165 adx 30 *
166 michael 3300 * \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 adx 30 */
177 michael 2820 static int
178 michael 3156 ms_connect(struct Client *source_p, int parc, char *parv[])
179 adx 30 {
180 michael 3874 int port = 0, tmpport = 0;
181 michael 1632 struct MaskItem *conf = NULL;
182 michael 971 const struct Client *target_p = NULL;
183 adx 30
184 michael 4685 if (parc < 4 || EmptyString(parv[3]))
185 adx 30 {
186 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "CONNECT");
187 michael 2820 return 0;
188 adx 30 }
189    
190 michael 4685 if (hunt_server(source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
191     return 0;
192    
193 adx 30 /*
194 michael 2820 * Try to find the name, then host, if both fail notify ops and bail
195 adx 30 */
196 michael 4682 if (!(conf = find_matching_name_conf(CONF_SERVER, parv[1], NULL, NULL, 0)) &&
197 michael 4688 !(conf = find_matching_name_conf(CONF_SERVER, NULL, NULL, parv[1], 0)))
198 michael 3795 {
199 michael 4686 sendto_one_notice(source_p, &me, ":Connect: Host %s not listed in configuration file", parv[1]);
200 michael 4682 return 0;
201 adx 30 }
202    
203 michael 4681 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 michael 2345 /*
211     * Get port number from user, if given. If not specified,
212 michael 4682 * use the default from configuration structure. If missing
213 adx 30 * from there, then use the precompiled default.
214     */
215 michael 1632 tmpport = port = conf->port;
216 adx 30
217     if (parc > 2 && !EmptyString(parv[2]))
218     {
219     port = atoi(parv[2]);
220    
221 michael 2345 /*
222 michael 2820 * If someone sends port 0, and we have a config port.. use it
223 michael 2345 */
224 michael 1632 if (port == 0 && conf->port)
225     port = conf->port;
226 adx 30 else if (port <= 0)
227     {
228 michael 3110 sendto_one_notice(source_p, &me, ":Connect: Illegal port number");
229 michael 2820 return 0;
230 adx 30 }
231     }
232     else if (port <= 0 && (port = PORTNUM) <= 0)
233     {
234 michael 3110 sendto_one_notice(source_p, &me, ":Connect: missing port number");
235 michael 2820 return 0;
236 adx 30 }
237    
238     if (find_servconn_in_progress(conf->name))
239     {
240 michael 3110 sendto_one_notice(source_p, &me, ":Connect: a connection to %s "
241     "is already in progress.", conf->name);
242 michael 2820 return 0;
243 adx 30 }
244    
245     /*
246     * Notify all operators about remote connect requests
247     */
248 michael 3849 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 michael 3135 sendto_server(NULL, NOCAPS, NOCAPS,
251 michael 3807 ":%s GLOBOPS :Remote CONNECT %s %d from %s",
252 michael 1463 me.id, parv[1], port, source_p->name);
253 adx 30
254 michael 3795 ilog(LOG_TYPE_IRCD, "CONNECT From %s : %s %d",
255 adx 30 source_p->name, parv[1], port);
256    
257 michael 1632 conf->port = port;
258 adx 30
259 michael 885 /*
260     * At this point we should be calling connect_server with a valid
261 michael 3300 * connect{} block and a valid port in the connect{} block
262 adx 30 */
263 michael 1632 if (serv_connect(conf, source_p))
264 michael 3110 sendto_one_notice(source_p, &me, ":*** Connecting to %s.%d",
265     conf->name, conf->port);
266 adx 30 else
267 michael 3110 sendto_one_notice(source_p, &me, ":*** Couldn't connect to %s.%d",
268     conf->name, conf->port);
269 michael 885 /*
270     * Client is either connecting with all the data it needs or has been
271 adx 30 * destroyed
272     */
273 michael 1632 conf->port = tmpport;
274 michael 2820 return 0;
275 adx 30 }
276 michael 1230
277 michael 2820 static struct Message connect_msgtab =
278     {
279 michael 4546 "CONNECT", NULL, 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
280 michael 1230 { 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 michael 2820 struct module module_entry =
296     {
297 michael 1230 .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