]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * m_connect.c: Connects to a remote IRC server. | |
4 | * | |
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 | |
8 | * | |
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. | |
13 | * | |
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. | |
18 | * | |
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 | |
23 | * | |
24 | * $Id: m_connect.c 3161 2007-01-25 07:23:01Z nenolod $ | |
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 "s_conf.h" | |
33 | #include "s_newconf.h" | |
34 | #include "logger.h" | |
35 | #include "s_serv.h" | |
36 | #include "send.h" | |
37 | #include "msg.h" | |
38 | #include "parse.h" | |
39 | #include "hash.h" | |
40 | #include "modules.h" | |
41 | #include "sslproc.h" | |
42 | ||
43 | static int mo_connect(struct Client *, struct Client *, int, const char **); | |
44 | static int ms_connect(struct Client *, struct Client *, int, const char **); | |
45 | ||
46 | struct Message connect_msgtab = { | |
47 | "CONNECT", 0, 0, 0, MFLG_SLOW, | |
48 | {mg_unreg, mg_not_oper, {ms_connect, 4}, {ms_connect, 4}, mg_ignore, {mo_connect, 2}} | |
49 | }; | |
50 | ||
51 | mapi_clist_av1 connect_clist[] = { &connect_msgtab, NULL }; | |
52 | DECLARE_MODULE_AV1(connect, NULL, NULL, connect_clist, NULL, NULL, "$Revision: 3161 $"); | |
53 | ||
54 | /* | |
55 | * mo_connect - CONNECT command handler | |
56 | * | |
57 | * Added by Jto 11 Feb 1989 | |
58 | * | |
59 | * m_connect | |
60 | * parv[0] = sender prefix | |
61 | * parv[1] = servername | |
62 | * parv[2] = port number | |
63 | * parv[3] = remote server | |
64 | */ | |
65 | static int | |
66 | mo_connect(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
67 | { | |
68 | int port; | |
69 | int tmpport; | |
70 | struct server_conf *server_p; | |
71 | struct Client *target_p; | |
72 | ||
73 | /* always privileged with handlers */ | |
74 | ||
75 | if(MyConnect(source_p) && !IsOperRemote(source_p) && parc > 3) | |
76 | { | |
77 | sendto_one(source_p, form_str(ERR_NOPRIVS), | |
78 | me.name, source_p->name, "remote"); | |
79 | return 0; | |
80 | } | |
81 | ||
82 | if(hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME) | |
83 | return 0; | |
84 | ||
85 | if((target_p = find_server(source_p, parv[1]))) | |
86 | { | |
87 | sendto_one_notice(source_p, ":Connect: Server %s already exists from %s.", parv[1], | |
88 | target_p->from->name); | |
89 | return 0; | |
90 | } | |
91 | ||
92 | /* | |
93 | * try to find the name, then host, if both fail notify ops and bail | |
94 | */ | |
95 | if((server_p = find_server_conf(parv[1])) == NULL) | |
96 | { | |
97 | sendto_one_notice(source_p, ":Connect: Host %s not listed in ircd.conf", parv[1]); | |
98 | return 0; | |
99 | } | |
100 | ||
101 | if(ServerConfSSL(server_p) && (!ssl_ok || !get_ssld_count())) | |
102 | { | |
103 | sendto_one_notice(source_p, | |
104 | ":Connect: Server %s is set to use SSL/TLS but SSL/TLS is not configured.", | |
105 | parv[1]); | |
106 | return 0; | |
107 | } | |
108 | ||
109 | /* | |
110 | * Get port number from user, if given. If not specified, | |
111 | * use the default form configuration structure. If missing | |
112 | * from there, then use the precompiled default. | |
113 | */ | |
114 | tmpport = port = server_p->port; | |
115 | if(parc > 2 && !EmptyString(parv[2])) | |
116 | { | |
117 | if((port = atoi(parv[2])) <= 0) | |
118 | { | |
119 | sendto_one_notice(source_p, ":Connect: Illegal port number"); | |
120 | return 0; | |
121 | } | |
122 | } | |
123 | else if(port <= 0 && (port = PORTNUM) <= 0) | |
124 | { | |
125 | sendto_one_notice(source_p, ":Connect: missing port number"); | |
126 | return 0; | |
127 | } | |
128 | /* | |
129 | * Notify all operators about remote connect requests | |
130 | */ | |
131 | ||
132 | ilog(L_SERVER, "CONNECT From %s : %s %s", parv[0], parv[1], parc > 2 ? parv[2] : ""); | |
133 | ||
134 | server_p->port = port; | |
135 | /* | |
136 | * at this point we should be calling connect_server with a valid | |
137 | * C:line and a valid port in the C:line | |
138 | */ | |
139 | if(serv_connect(server_p, source_p)) | |
140 | { | |
141 | #ifndef HIDE_SERVERS_IPS | |
142 | sendto_one_notice(source_p, ":*** Connecting to %s[%s].%d", | |
143 | server_p->host, server_p->name, server_p->port); | |
144 | #else | |
145 | sendto_one_notice(source_p, ":*** Connecting to %s.%d", | |
146 | server_p->name, server_p->port); | |
147 | #endif | |
148 | ||
149 | } | |
150 | else | |
151 | { | |
152 | sendto_one_notice(source_p, ":*** Couldn't connect to %s.%d", | |
153 | server_p->name, server_p->port); | |
154 | } | |
155 | ||
156 | /* | |
157 | * client is either connecting with all the data it needs or has been | |
158 | * destroyed | |
159 | */ | |
160 | server_p->port = tmpport; | |
161 | return 0; | |
162 | } | |
163 | ||
164 | /* | |
165 | * ms_connect - CONNECT command handler | |
166 | * | |
167 | * Added by Jto 11 Feb 1989 | |
168 | * | |
169 | * m_connect | |
170 | * parv[0] = sender prefix | |
171 | * parv[1] = servername | |
172 | * parv[2] = port number | |
173 | * parv[3] = remote server | |
174 | */ | |
175 | static int | |
176 | ms_connect(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
177 | { | |
178 | int port; | |
179 | int tmpport; | |
180 | struct server_conf *server_p; | |
181 | struct Client *target_p; | |
182 | ||
183 | if(hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME) | |
184 | return 0; | |
185 | ||
186 | if((target_p = find_server(NULL, parv[1]))) | |
187 | { | |
188 | sendto_one_notice(source_p, ":Connect: Server %s already exists from %s.", | |
189 | parv[1], target_p->from->name); | |
190 | return 0; | |
191 | } | |
192 | ||
193 | /* | |
194 | * try to find the name, then host, if both fail notify ops and bail | |
195 | */ | |
196 | if((server_p = find_server_conf(parv[1])) == NULL) | |
197 | { | |
198 | sendto_one_notice(source_p, ":Connect: Host %s not listed in ircd.conf", | |
199 | parv[1]); | |
200 | return 0; | |
201 | } | |
202 | ||
203 | if(ServerConfSSL(server_p) && (!ssl_ok || !get_ssld_count())) | |
204 | { | |
205 | sendto_one_notice(source_p, | |
206 | ":Connect: Server %s is set to use SSL/TLS but SSL/TLS is not configured.", | |
207 | parv[1]); | |
208 | return 0; | |
209 | } | |
210 | ||
211 | /* | |
212 | * Get port number from user, if given. If not specified, | |
213 | * use the default form configuration structure. If missing | |
214 | * from there, then use the precompiled default. | |
215 | */ | |
216 | tmpport = server_p->port; | |
217 | ||
218 | port = atoi(parv[2]); | |
219 | ||
220 | /* if someone sends port 0, and we have a config port.. use it */ | |
221 | if(port == 0 && server_p->port) | |
222 | port = server_p->port; | |
223 | else if(port <= 0) | |
224 | { | |
225 | sendto_one_notice(source_p, ":Connect: Illegal port number"); | |
226 | return 0; | |
227 | } | |
228 | ||
229 | /* | |
230 | * Notify all operators about remote connect requests | |
231 | */ | |
232 | sendto_wallops_flags(UMODE_WALLOP, &me, | |
233 | "Remote CONNECT %s %d from %s", | |
234 | parv[1], port, source_p->name); | |
235 | sendto_server(NULL, NULL, CAP_TS6, NOCAPS, | |
236 | ":%s WALLOPS :Remote CONNECT %s %d from %s", | |
237 | me.id, parv[1], port, source_p->name); | |
238 | sendto_server(NULL, NULL, NOCAPS, CAP_TS6, | |
239 | ":%s WALLOPS :Remote CONNECT %s %d from %s", | |
240 | me.name, parv[1], port, source_p->name); | |
241 | ||
242 | ilog(L_SERVER, "CONNECT From %s : %s %d", source_p->name, parv[1], port); | |
243 | ||
244 | server_p->port = port; | |
245 | /* | |
246 | * at this point we should be calling connect_server with a valid | |
247 | * C:line and a valid port in the C:line | |
248 | */ | |
249 | if(serv_connect(server_p, source_p)) | |
250 | sendto_one_notice(source_p, ":*** Connecting to %s.%d", | |
251 | server_p->name, server_p->port); | |
252 | else | |
253 | sendto_one_notice(source_p, ":*** Couldn't connect to %s.%d", | |
254 | server_p->name, server_p->port); | |
255 | /* | |
256 | * client is either connecting with all the data it needs or has been | |
257 | * destroyed | |
258 | */ | |
259 | server_p->port = tmpport; | |
260 | return 0; | |
261 | } |