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