2 * IRC - Internet Relay Chat, ircd/s_serv.c (formerly ircd/s_msg.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.
34 #include "ircd_alloc.h"
35 #include "ircd_reply.h"
36 #include "ircd_string.h"
37 #include "ircd_snprintf.h"
38 #include "ircd_xopen.h"
47 #include "querycmds.h"
54 #include "sprintf_irc.h"
63 unsigned int max_connection_count = 0;
64 unsigned int max_client_count = 0;
66 int exit_new_server(struct Client *cptr, struct Client *sptr, const char *host,
67 time_t timestamp, const char *pattern, ...)
72 vd.vd_format = pattern;
73 va_start(vd.vd_args, pattern);
76 retval = vexit_client_msg(cptr, cptr, &me, pattern, vd.vd_args);
78 sendcmdto_one(&me, CMD_SQUIT, cptr, "%s %Tu :%v", host, timestamp, &vd);
85 int a_kills_b_too(struct Client *a, struct Client *b)
87 for (; b != a && b != &me; b = cli_serv(b)->up);
88 return (a == b ? 1 : 0);
94 * May only be called after a SERVER was received from cptr,
95 * and thus make_server was called, and serv->prot set. --Run
97 int server_estab(struct Client *cptr, struct ConfItem *aconf,
100 struct Client* acptr = 0;
105 assert(0 != cli_local(cptr));
107 split = (0 != ircd_strcmp(cli_name(cptr), cli_sockhost(cptr))
108 && 0 != ircd_strncmp(cli_info(cptr), "JUPE", 4));
109 inpath = cli_name(cptr);
111 if (IsUnknown(cptr)) {
112 if (aconf->passwd[0])
113 sendrawto_one(cptr, MSG_PASS " :%s", aconf->passwd);
115 * Pass my info to the new server
117 sendrawto_one(cptr, MSG_SERVER " %s 1 %Tu %Tu J%s %s%s :%s", cli_name(&me),
118 cli_serv(&me)->timestamp, cli_serv(cptr)->timestamp, MAJOR_PROTOCOL,
119 NumServCap(&me), *(cli_info(&me)) ? cli_info(&me) : "IRCers United");
121 * Don't charge this IP# for connecting
122 * XXX - if this comes from a server port, it will not have been added
123 * to the IP check registry, see add_connection in s_bsd.c
125 IPcheck_connect_fail(cli_ip(cptr));
128 det_confs_butmask(cptr, CONF_LEAF | CONF_HUB | CONF_SERVER | CONF_UWORLD);
130 if (!IsHandshake(cptr))
133 cli_handler(cptr) = SERVER_HANDLER;
134 Count_unknownbecomesserver(UserStats);
136 release_dns_reply(cptr);
140 nextping = CurrentTime;
143 * NOTE: check for acptr->user == cptr->serv->user is necessary to insure
144 * that we got the same one... bleah
146 if (cli_serv(cptr)->user && *(cli_serv(cptr))->by &&
147 (acptr = findNUser(cli_serv(cptr)->by))) {
148 if (cli_user(acptr) == cli_serv(cptr)->user) {
149 sendcmdto_one(&me, CMD_NOTICE, acptr, "%C :Link with %s established.",
154 * if not the same client, set by to empty string
157 *(cli_serv(cptr))->by = '\0';
161 sendto_opmask_butone(acptr, SNO_OLDSNO, "Link with %s established.", inpath);
162 cli_serv(cptr)->up = &me;
163 cli_serv(cptr)->updown = add_dlink(&(cli_serv(&me))->down, cptr);
164 sendto_opmask_butone(0, SNO_NETWORK, "Net junction: %s %s", cli_name(&me),
168 * Old sendto_serv_but_one() call removed because we now
169 * need to send different names to different servers
170 * (domain name matching) Send new server to other servers.
172 for (i = 0; i <= HighestFd; i++)
174 if (!(acptr = LocalClientArray[i]) || !IsServer(acptr) ||
175 acptr == cptr || IsMe(acptr))
177 if (!match(cli_name(&me), cli_name(cptr)))
180 sendcmdto_one(&me, CMD_SERVER, acptr,
181 "%s 2 0 %Tu J%02u %s%s 0 %%%Tu :%s", cli_name(cptr),
182 cli_serv(cptr)->timestamp, Protocol(cptr), NumServCap(cptr),
183 JupeLastMod(ajupe), cli_info(cptr));
185 sendcmdto_one(&me, CMD_SERVER, acptr,
186 "%s 2 0 %Tu J%02u %s%s 0 :%s", cli_name(cptr),
187 cli_serv(cptr)->timestamp, Protocol(cptr), NumServCap(cptr),
192 * Pass on my client information to the new server
194 * First, pass only servers (idea is that if the link gets
195 * cancelled beacause the server was already there,
196 * there are no NICK's to be cancelled...). Of course,
197 * if cancellation occurs, all this info is sent anyway,
198 * and I guess the link dies when a read is attempted...? --msa
200 * Note: Link cancellation to occur at this point means
201 * that at least two servers from my fragment are building
202 * up connection this other fragment at the same time, it's
203 * a race condition, not the normal way of operation...
206 for (acptr = &me; acptr; acptr = cli_prev(acptr)) {
207 /* acptr->from == acptr for acptr == cptr */
208 if (cli_from(acptr) == cptr)
210 if (IsServer(acptr)) {
211 const char* protocol_str;
213 if (Protocol(acptr) > 9)
214 protocol_str = IsBurst(acptr) ? "J" : "P";
216 protocol_str = IsBurst(acptr) ? "J0" : "P0";
218 if (0 == match(cli_name(&me), cli_name(acptr)))
220 split = (MyConnect(acptr) &&
221 0 != ircd_strcmp(cli_name(acptr), cli_sockhost(acptr)) &&
222 0 != ircd_strncmp(cli_info(acptr), "JUPE", 4));
223 if ((ajupe = jupe_find(cli_name(acptr))) && !JupeIsLocal(ajupe))
224 sendcmdto_one(cli_serv(acptr)->up, CMD_SERVER, cptr,
225 "%s %d 0 %Tu %s%u %s%s 0 %%%Tu :%s", cli_name(acptr),
226 cli_hopcount(acptr) + 1, cli_serv(acptr)->timestamp,
227 protocol_str, Protocol(acptr), NumServCap(acptr),
228 JupeLastMod(ajupe), cli_info(acptr));
230 sendcmdto_one(cli_serv(acptr)->up, CMD_SERVER, cptr,
231 "%s %d 0 %Tu %s%u %s%s 0 :%s", cli_name(acptr),
232 cli_hopcount(acptr) + 1, cli_serv(acptr)->timestamp,
233 protocol_str, Protocol(acptr), NumServCap(acptr),
238 for (acptr = &me; acptr; acptr = cli_prev(acptr))
240 /* acptr->from == acptr for acptr == cptr */
241 if (cli_from(acptr) == cptr)
246 char *s = umode_str(acptr);
247 struct Gline *agline = 0;
248 if ((agline = gline_lookup(acptr, GLINE_GLOBAL | GLINE_LASTMOD)))
249 sendcmdto_one(cli_user(acptr)->server, CMD_NICK, cptr,
250 "%s %d %Tu %s %s %s%s%s%%%Tu:%s@%s %s %s%s :%s",
251 cli_name(acptr), cli_hopcount(acptr) + 1, cli_lastnick(acptr),
252 cli_user(acptr)->username, cli_user(acptr)->host,
253 *s ? "+" : "", s, *s ? " " : "",
254 GlineLastMod(agline), GlineUser(agline),
256 inttobase64(xxx_buf, ntohl(cli_ip(acptr).s_addr), 6),
257 NumNick(acptr), cli_info(acptr));
259 sendcmdto_one(cli_user(acptr)->server, CMD_NICK, cptr,
260 "%s %d %Tu %s %s %s%s%s%s %s%s :%s",
261 cli_name(acptr), cli_hopcount(acptr) + 1, cli_lastnick(acptr),
262 cli_user(acptr)->username, cli_user(acptr)->host,
263 *s ? "+" : "", s, *s ? " " : "",
264 inttobase64(xxx_buf, ntohl(cli_ip(acptr).s_addr), 6),
265 NumNick(acptr), cli_info(acptr));
269 * Last, send the BURST.
270 * (Or for 2.9 servers: pass all channels plus statuses)
273 struct Channel *chptr;
274 for (chptr = GlobalChannelList; chptr; chptr = chptr->next)
275 send_channel_modes(cptr, chptr);
279 sendcmdto_one(&me, CMD_END_OF_BURST, cptr, "");