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