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: 3807
Committed: Tue Jun 3 18:55:28 2014 UTC (11 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 8815 byte(s)
Log Message:
- m_connect.c:ms_connect(): use GLOBOPS to announce remote connects

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

Properties

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