2 * IRC - Internet Relay Chat, ircd/m_connect.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
6 * See file AUTHORS in IRC package for additional names of
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 1, or (at your option)
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., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * m_functions execute protocol messages on this server:
29 * cptr is always NON-NULL, pointing to a *LOCAL* client
30 * structure (with an open socket connected!). This
31 * identifies the physical socket where the message
32 * originated (or which caused the m_function to be
33 * executed--some m_functions may call others...).
35 * sptr is the source of the message, defined by the
36 * prefix part of the message if present. If not
37 * or prefix not found, then sptr==cptr.
39 * (!IsServer(cptr)) => (cptr == sptr), because
40 * prefixes are taken *only* from servers...
43 * (sptr == cptr) => the message didn't
46 * (sptr != cptr && IsServer(sptr) means
47 * the prefix specified servername. (?)
49 * (sptr != cptr && !IsServer(sptr) means
50 * that message originated from a remote
55 * (!IsServer(sptr)) means that, sptr can safely
56 * taken as defining the target structure of the
57 * message in this server.
59 * *Always* true (if 'parse' and others are working correct):
61 * 1) sptr->from == cptr (note: cptr->from == cptr)
63 * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
64 * *cannot* be a local connection, unless it's
65 * actually cptr!). [MyConnect(x) should probably
66 * be defined as (x == x->from) --msa ]
68 * parc number of variable parameter strings (if zero,
69 * parv is allowed to be NULL)
71 * parv a NULL terminated list of parameter pointers,
73 * parv[0], sender (prefix string), if not present
74 * this points to an empty string.
75 * parv[1]...parv[parc-1]
76 * pointers to additional parameters
77 * parv[parc] == NULL, *always*
79 * note: it is guaranteed that parv[0]..parv[parc-1] are all
84 * No need to include handlers.h here the signatures must match
85 * and we don't need to force a rebuild of all the handlers everytime
86 * we add a new one to the list. --Bleep
94 #include "ircd_features.h"
96 #include "ircd_reply.h"
97 #include "ircd_string.h"
102 #include "numnicks.h"
112 * ms_connect - server message handler
113 * - Added by Jto 11 Feb 1989
115 * parv[0] = sender prefix
116 * parv[1] = servername
117 * parv[2] = port number
118 * parv[3] = remote server
120 int ms_connect(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
123 unsigned short tmpport;
125 struct ConfItem* aconf;
126 struct Client* acptr;
132 if (!IsPrivileged(sptr))
133 return send_reply(sptr, ERR_NOPRIVILEGES);
137 * this is coming from a server which should have already
138 * checked it's args, if we don't have parc == 4, something
141 protocol_violation(sptr, "Too few parameters to connect");
142 return need_more_params(sptr, "CONNECT");
145 if (hunt_server_cmd(sptr, CMD_CONNECT, cptr, 1, "%s %s :%C", 3, parc, parv)
150 * need to find the conf entry first so we can use the server name from
151 * the conf entry instead of parv[1] to find out if the server is already
152 * present below. --Bleep
154 if (0 == (aconf = conf_find_server(parv[1]))) {
155 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Host %s not listed "
156 "in ircd.conf", sptr, parv[1]);
160 * use aconf->name to look up the server
162 if ((acptr = FindServer(aconf->name))) {
163 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Server %s already "
164 "exists from %s", sptr, parv[1], cli_name(cli_from(acptr)));
168 * Evaluate connection rules... If no rules found, allow the
169 * connect. Otherwise stop with the first true rule (ie: rules
170 * are ored together. Oper connects are effected only by D
171 * lines (CRULEALL) not d lines (CRULEAUTO).
173 if ((rule = conf_eval_crule(aconf->name, CRULE_ALL))) {
174 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Disallowed by rule: %s", sptr, rule);
178 * Check to see if the server is juped; if it is, disallow the connect
180 if ((ajupe = jupe_find(aconf->name)) && JupeIsActive(ajupe)) {
181 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Server %s is juped: %s",
182 sptr, JupeServer(ajupe), JupeReason(ajupe));
187 * Allow opers to /connect foo.* 0 bah.* to connect foo and bah
188 * using the conf's configured port
190 port = atoi(parv[2]);
194 tmpport = aconf->port;
202 * Notify all operators about remote connect requests
204 sendcmdto_flag_butone(&me, CMD_WALLOPS, 0, FLAGS_WALLOP,
205 ":Remote CONNECT %s %s from %s", parv[1],
206 parv[2] ? parv[2] : "",
207 get_client_name(sptr, HIDE_IP));
208 log_write(LS_NETWORK, L_INFO, 0, "CONNECT From %C : %s %s", sptr, parv[1],
209 parv[2] ? parv[2] : "");
211 if (connect_server(aconf, sptr, 0)) {
212 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :*** Connecting to %s.", sptr,
216 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :*** Connection to %s failed",
219 aconf->port = tmpport;
224 * mo_connect - oper message handler
225 * - Added by Jto 11 Feb 1989
227 * parv[0] = sender prefix
228 * parv[1] = servername
229 * parv[2] = port number
230 * parv[3] = remote server
232 int mo_connect(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
235 unsigned short tmpport;
237 struct ConfItem* aconf;
238 struct Client* acptr;
242 assert(cptr == sptr);
243 assert(IsAnOper(sptr));
246 return need_more_params(sptr, "CONNECT");
250 * if parc > 3, we are trying to connect two remote
251 * servers to each other
255 * Only allow LocOps to make local CONNECTS --SRB
260 struct Client* acptr2;
261 struct Client* acptr3;
263 if (!(acptr3 = find_match_server(parv[3]))) {
264 send_reply(sptr, ERR_NOSUCHSERVER, parv[3]);
269 * Look for closest matching server
270 * needed for "/connect blah 4400 *"?
272 for (acptr2 = acptr3; acptr2 != &me; acptr2 = cli_serv(acptr2)->up) {
273 if (!match(parv[3], cli_name(acptr2)))
276 parv[3] = cli_name(acptr3);
277 if (hunt_server_cmd(sptr, CMD_CONNECT, cptr, 1, "%s %s :%C", 3, parc,
278 parv) != HUNTED_ISME)
283 * need to find the conf entry first so we can use the server name from
284 * the conf entry instead of parv[1] to find out if the server is already
285 * present below. --Bleep
287 if (0 == (aconf = conf_find_server(parv[1]))) {
288 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Host %s not listed "
289 "in ircd.conf", sptr, parv[1]);
293 * use aconf->name to look up the server, see above
295 if ((acptr = FindServer(aconf->name))) {
296 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Server %s already "
297 "exists from %s", sptr, parv[1], cli_name(cli_from(acptr)));
301 * Evaluate connection rules... If no rules found, allow the
302 * connect. Otherwise stop with the first true rule (ie: rules
303 * are ored together. Oper connects are effected only by D
304 * lines (CRULEALL) not d lines (CRULEAUTO).
306 if ((rule = conf_eval_crule(aconf->name, CRULE_ALL))) {
307 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Disallowed by rule: %s", sptr, rule);
311 * Check to see if the server is juped; if it is, disallow the connect
313 if ((ajupe = jupe_find(aconf->name)) && JupeIsActive(ajupe)) {
314 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Server %s is juped: %s",
315 sptr, JupeServer(ajupe), JupeReason(ajupe));
319 * Get port number from user, if given. If not specified,
320 * use the default from configuration structure. If missing
321 * from there, then use the precompiled default.
325 assert(0 != parv[2]);
326 if (0 == (port = atoi(parv[2]))) {
327 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Invalid port number",
332 if (0 == port && 0 == (port = feature_int(FEAT_SERVER_PORT))) {
333 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: missing port number",
338 tmpport = aconf->port;
341 if (connect_server(aconf, sptr, 0)) {
342 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :*** Connecting to %s.", sptr,
346 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :*** Connection to %s failed",
349 aconf->port = tmpport;