Remove cruft left behind by removed stats_p_hook.
[seven-1.x.git] / modules / m_connect.c
blob13fd04c727624b8176f6518edecc4bc14d849f59
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_connect.c: Connects to a remote IRC server.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
25 #include "stdinc.h"
26 #include "client.h"
27 #include "ircd.h"
28 #include "irc_string.h"
29 #include "numeric.h"
30 #include "commio.h"
31 #include "s_conf.h"
32 #include "s_newconf.h"
33 #include "s_log.h"
34 #include "s_serv.h"
35 #include "send.h"
36 #include "msg.h"
37 #include "parse.h"
38 #include "hash.h"
39 #include "modules.h"
41 static int mo_connect(struct Client *, struct Client *, int, const char **);
42 static int ms_connect(struct Client *, struct Client *, int, const char **);
44 struct Message connect_msgtab = {
45 "CONNECT", 0, 0, 0, MFLG_SLOW,
46 {mg_unreg, mg_not_oper, {ms_connect, 4}, {ms_connect, 4}, mg_ignore, {mo_connect, 2}}
49 mapi_clist_av1 connect_clist[] = { &connect_msgtab, NULL };
50 DECLARE_MODULE_AV1(connect, NULL, NULL, connect_clist, NULL, NULL, "$Revision: 82 $");
53 * mo_connect - CONNECT command handler
55 * Added by Jto 11 Feb 1989
57 * m_connect
58 * parv[0] = sender prefix
59 * parv[1] = servername
60 * parv[2] = port number
61 * parv[3] = remote server
63 static int
64 mo_connect(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
66 int port;
67 int tmpport;
68 struct server_conf *server_p;
69 struct Client *target_p;
71 /* always privileged with handlers */
73 if(MyConnect(source_p) && !IsOperRouting(source_p))
75 sendto_one(source_p, form_str(ERR_NOPRIVS),
76 me.name, source_p->name, "routing");
77 return 0;
80 if(hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
81 return 0;
83 if((target_p = find_server(source_p, parv[1])))
85 sendto_one(source_p, ":%s NOTICE %s :Connect: Server %s already exists from %s.",
86 me.name, parv[0], parv[1], target_p->from->name);
87 return 0;
91 * try to find the name, then host, if both fail notify ops and bail
93 if((server_p = find_server_conf(parv[1])) == NULL)
95 sendto_one(source_p,
96 "NOTICE %s :Connect: Host %s not listed in ircd.conf",
97 parv[0], parv[1]);
98 return 0;
102 * Get port number from user, if given. If not specified,
103 * use the default form configuration structure. If missing
104 * from there, then use the precompiled default.
106 tmpport = port = server_p->port;
107 if(parc > 2 && !EmptyString(parv[2]))
109 if((port = atoi(parv[2])) <= 0)
111 sendto_one(source_p, "NOTICE %s :Connect: Illegal port number", parv[0]);
112 return 0;
115 else if(port <= 0 && (port = PORTNUM) <= 0)
117 sendto_one(source_p, ":%s NOTICE %s :Connect: missing port number",
118 me.name, parv[0]);
119 return 0;
122 * Notify all operators about remote connect requests
125 ilog(L_SERVER, "CONNECT From %s : %s %s", parv[0], parv[1], parc > 2 ? parv[2] : "");
127 server_p->port = port;
129 * at this point we should be calling connect_server with a valid
130 * C:line and a valid port in the C:line
132 if(serv_connect(server_p, source_p))
134 #ifndef HIDE_SERVERS_IPS
135 sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s[%s].%d",
136 me.name, parv[0], server_p->host, server_p->name, server_p->port);
137 #else
138 sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d",
139 me.name, parv[0], server_p->name, server_p->port);
140 #endif
143 else
145 sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d",
146 me.name, parv[0], server_p->name, server_p->port);
151 * client is either connecting with all the data it needs or has been
152 * destroyed
154 server_p->port = tmpport;
155 return 0;
159 * ms_connect - CONNECT command handler
161 * Added by Jto 11 Feb 1989
163 * m_connect
164 * parv[0] = sender prefix
165 * parv[1] = servername
166 * parv[2] = port number
167 * parv[3] = remote server
169 static int
170 ms_connect(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
172 int port;
173 int tmpport;
174 struct server_conf *server_p;
175 struct Client *target_p;
177 if(hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
178 return 0;
180 if((target_p = find_server(NULL, parv[1])))
182 sendto_one_notice(source_p, ":Connect: Server %s already exists from %s.",
183 parv[1], target_p->from->name);
184 return 0;
188 * try to find the name, then host, if both fail notify ops and bail
190 if((server_p = find_server_conf(parv[1])) == NULL)
192 sendto_one_notice(source_p, ":Connect: Host %s not listed in ircd.conf",
193 parv[1]);
194 return 0;
198 * Get port number from user, if given. If not specified,
199 * use the default form configuration structure. If missing
200 * from there, then use the precompiled default.
202 tmpport = server_p->port;
204 port = atoi(parv[2]);
206 /* if someone sends port 0, and we have a config port.. use it */
207 if(port == 0 && server_p->port)
208 port = server_p->port;
209 else if(port <= 0)
211 sendto_one_notice(source_p, ":Connect: Illegal port number");
212 return 0;
216 * Notify all operators about remote connect requests
218 sendto_wallops_flags(UMODE_WALLOP, &me,
219 "Remote CONNECT %s %d from %s",
220 parv[1], port, source_p->name);
221 sendto_server(NULL, NULL, CAP_TS6, NOCAPS,
222 ":%s WALLOPS :Remote CONNECT %s %d from %s",
223 me.id, parv[1], port, source_p->name);
224 sendto_server(NULL, NULL, NOCAPS, CAP_TS6,
225 ":%s WALLOPS :Remote CONNECT %s %d from %s",
226 me.name, parv[1], port, source_p->name);
228 ilog(L_SERVER, "CONNECT From %s : %s %d", source_p->name, parv[1], port);
230 server_p->port = port;
232 * at this point we should be calling connect_server with a valid
233 * C:line and a valid port in the C:line
235 if(serv_connect(server_p, source_p))
236 sendto_one_notice(source_p, ":*** Connecting to %s.%d",
237 server_p->name, server_p->port);
238 else
239 sendto_one_notice(source_p, ":*** Couldn't connect to %s.%d",
240 server_p->name, server_p->port);
242 * client is either connecting with all the data it needs or has been
243 * destroyed
245 server_p->port = tmpport;
246 return 0;