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