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
24 * $Id: m_connect.c 3161 2007-01-25 07:23:01Z nenolod $
30 #include "irc_string.h"
33 #include "s_newconf.h"
42 static int mo_connect(struct Client
*, struct Client
*, int, const char **);
43 static int ms_connect(struct Client
*, struct Client
*, int, const char **);
45 struct Message connect_msgtab
= {
46 "CONNECT", 0, 0, 0, MFLG_SLOW
,
47 {mg_unreg
, mg_not_oper
, {ms_connect
, 4}, {ms_connect
, 4}, mg_ignore
, {mo_connect
, 2}}
50 mapi_clist_av1 connect_clist
[] = { &connect_msgtab
, NULL
};
51 DECLARE_MODULE_AV1(connect
, NULL
, NULL
, connect_clist
, NULL
, NULL
, "$Revision: 3161 $");
54 * mo_connect - CONNECT command handler
56 * Added by Jto 11 Feb 1989
59 * parv[0] = sender prefix
60 * parv[1] = servername
61 * parv[2] = port number
62 * parv[3] = remote server
65 mo_connect(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
69 struct server_conf
*server_p
;
70 struct Client
*target_p
;
72 /* always privileged with handlers */
74 if(MyConnect(source_p
) && !IsOperRemote(source_p
) && parc
> 3)
76 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
77 me
.name
, source_p
->name
, "remote");
81 if(hunt_server(client_p
, source_p
, ":%s CONNECT %s %s :%s", 3, parc
, parv
) != HUNTED_ISME
)
84 if((target_p
= find_server(source_p
, parv
[1])))
86 sendto_one_notice(source_p
, ":Connect: Server %s already exists from %s.", parv
[1],
87 target_p
->from
->name
);
92 * try to find the name, then host, if both fail notify ops and bail
94 if((server_p
= find_server_conf(parv
[1])) == NULL
)
96 sendto_one_notice(source_p
, ":Connect: Host %s not listed in ircd.conf", parv
[1]);
101 * Get port number from user, if given. If not specified,
102 * use the default form configuration structure. If missing
103 * from there, then use the precompiled default.
105 tmpport
= port
= server_p
->port
;
106 if(parc
> 2 && !EmptyString(parv
[2]))
108 if((port
= atoi(parv
[2])) <= 0)
110 sendto_one_notice(source_p
, ":Connect: Illegal port number");
114 else if(port
<= 0 && (port
= PORTNUM
) <= 0)
116 sendto_one_notice(source_p
, ":Connect: missing port number");
120 * Notify all operators about remote connect requests
123 ilog(L_SERVER
, "CONNECT From %s : %s %s", parv
[0], parv
[1], parc
> 2 ? parv
[2] : "");
125 server_p
->port
= port
;
127 * at this point we should be calling connect_server with a valid
128 * C:line and a valid port in the C:line
130 if(serv_connect(server_p
, source_p
))
132 #ifndef HIDE_SERVERS_IPS
133 sendto_one_notice(source_p
, ":*** Connecting to %s[%s].%d",
134 server_p
->host
, server_p
->name
, server_p
->port
);
136 sendto_one_notice(source_p
, ":*** Connecting to %s.%d",
137 server_p
->name
, server_p
->port
);
143 sendto_one_notice(source_p
, ":*** Couldn't connect to %s.%d",
144 server_p
->name
, server_p
->port
);
148 * client is either connecting with all the data it needs or has been
151 server_p
->port
= tmpport
;
156 * ms_connect - CONNECT command handler
158 * Added by Jto 11 Feb 1989
161 * parv[0] = sender prefix
162 * parv[1] = servername
163 * parv[2] = port number
164 * parv[3] = remote server
167 ms_connect(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
171 struct server_conf
*server_p
;
172 struct Client
*target_p
;
174 if(hunt_server(client_p
, source_p
, ":%s CONNECT %s %s :%s", 3, parc
, parv
) != HUNTED_ISME
)
177 if((target_p
= find_server(NULL
, parv
[1])))
179 sendto_one_notice(source_p
, ":Connect: Server %s already exists from %s.",
180 parv
[1], target_p
->from
->name
);
185 * try to find the name, then host, if both fail notify ops and bail
187 if((server_p
= find_server_conf(parv
[1])) == NULL
)
189 sendto_one_notice(source_p
, ":Connect: Host %s not listed in ircd.conf",
195 * Get port number from user, if given. If not specified,
196 * use the default form configuration structure. If missing
197 * from there, then use the precompiled default.
199 tmpport
= server_p
->port
;
201 port
= atoi(parv
[2]);
203 /* if someone sends port 0, and we have a config port.. use it */
204 if(port
== 0 && server_p
->port
)
205 port
= server_p
->port
;
208 sendto_one_notice(source_p
, ":Connect: Illegal port number");
213 * Notify all operators about remote connect requests
215 sendto_wallops_flags(UMODE_WALLOP
, &me
,
216 "Remote CONNECT %s %d from %s",
217 parv
[1], port
, source_p
->name
);
218 sendto_server(NULL
, NULL
, CAP_TS6
, NOCAPS
,
219 ":%s WALLOPS :Remote CONNECT %s %d from %s",
220 me
.id
, parv
[1], port
, source_p
->name
);
221 sendto_server(NULL
, NULL
, NOCAPS
, CAP_TS6
,
222 ":%s WALLOPS :Remote CONNECT %s %d from %s",
223 me
.name
, parv
[1], port
, source_p
->name
);
225 ilog(L_SERVER
, "CONNECT From %s : %s %d", source_p
->name
, parv
[1], port
);
227 server_p
->port
= port
;
229 * at this point we should be calling connect_server with a valid
230 * C:line and a valid port in the C:line
232 if(serv_connect(server_p
, source_p
))
233 sendto_one_notice(source_p
, ":*** Connecting to %s.%d",
234 server_p
->name
, server_p
->port
);
236 sendto_one_notice(source_p
, ":*** Couldn't connect to %s.%d",
237 server_p
->name
, server_p
->port
);
239 * client is either connecting with all the data it needs or has been
242 server_p
->port
= tmpport
;