]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * m_svinfo.c: Sends TS information for clock & compatibility checks. | |
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 | #include "stdinc.h" | |
25 | #include "client.h" | |
1235d684 | 26 | #include "common.h" |
4562c604 | 27 | #include "match.h" |
212380e3 AC |
28 | #include "ircd.h" |
29 | #include "numeric.h" | |
30 | #include "send.h" | |
31 | #include "s_conf.h" | |
53307da8 | 32 | #include "s_newconf.h" |
4016731b | 33 | #include "logger.h" |
212380e3 AC |
34 | #include "msg.h" |
35 | #include "parse.h" | |
36 | #include "modules.h" | |
37 | ||
428ca87b | 38 | static int ms_svinfo(struct MsgBuf *, struct Client *, struct Client *, int, const char **); |
3abc337f AW |
39 | static const char svinfo_desc[] = |
40 | "Provides TS6 SVINFO command to ensure version and clock synchronisation"; | |
212380e3 AC |
41 | |
42 | struct Message svinfo_msgtab = { | |
7baa37a9 | 43 | "SVINFO", 0, 0, 0, 0, |
212380e3 AC |
44 | {mg_unreg, mg_ignore, mg_ignore, {ms_svinfo, 5}, mg_ignore, mg_ignore} |
45 | }; | |
46 | ||
47 | mapi_clist_av1 svinfo_clist[] = { &svinfo_msgtab, NULL }; | |
3abc337f | 48 | DECLARE_MODULE_AV2(svinfo, NULL, NULL, svinfo_clist, NULL, NULL, NULL, NULL, svinfo_desc); |
212380e3 AC |
49 | |
50 | /* | |
51 | * ms_svinfo - SVINFO message handler | |
212380e3 AC |
52 | * parv[1] = TS_CURRENT for the server |
53 | * parv[2] = TS_MIN for the server | |
54 | * parv[3] = unused, send 0 | |
55 | * parv[4] = server's idea of UTC time | |
56 | */ | |
57 | static int | |
428ca87b | 58 | ms_svinfo(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 | 59 | { |
29c92cf9 | 60 | signed long deltat; |
212380e3 | 61 | time_t theirtime; |
62433315 | 62 | char squitreason[120]; |
212380e3 AC |
63 | |
64 | /* SVINFO isnt remote. */ | |
65 | if(source_p != client_p) | |
66 | return 0; | |
67 | ||
68 | if(TS_CURRENT < atoi(parv[2]) || atoi(parv[1]) < TS_MIN) | |
69 | { | |
70 | /* TS version is too low on one of the sides, drop the link */ | |
71 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
72 | "Link %s dropped, wrong TS protocol version (%s,%s)", | |
b3ebc7ab | 73 | source_p->name, parv[1], parv[2]); |
5203cba5 | 74 | snprintf(squitreason, sizeof squitreason, "Incompatible TS version (%s,%s)", |
62433315 JT |
75 | parv[1], parv[2]); |
76 | exit_client(source_p, source_p, source_p, squitreason); | |
212380e3 AC |
77 | return 0; |
78 | } | |
79 | ||
80 | /* | |
e3354945 | 81 | * since we're here, might as well set rb_current_time() while we're at it |
212380e3 | 82 | */ |
519bd854 | 83 | rb_set_time(); |
212380e3 | 84 | theirtime = atol(parv[4]); |
29c92cf9 | 85 | deltat = labs(theirtime - rb_current_time()); |
212380e3 AC |
86 | |
87 | if(deltat > ConfigFileEntry.ts_max_delta) | |
88 | { | |
89 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
90 | "Link %s dropped, excessive TS delta" | |
29c92cf9 | 91 | " (my TS=%ld, their TS=%ld, delta=%ld)", |
b3ebc7ab | 92 | source_p->name, |
e3354945 | 93 | (long) rb_current_time(), (long) theirtime, deltat); |
212380e3 AC |
94 | ilog(L_SERVER, |
95 | "Link %s dropped, excessive TS delta" | |
29c92cf9 | 96 | " (my TS=%ld, their TS=%ld, delta=%ld)", |
e3354945 | 97 | log_client_name(source_p, SHOW_IP), (long) rb_current_time(), (long) theirtime, deltat); |
5203cba5 | 98 | snprintf(squitreason, sizeof squitreason, "Excessive TS delta (my TS=%ld, their TS=%ld, delta=%ld)", |
e3354945 | 99 | (long) rb_current_time(), (long) theirtime, deltat); |
53307da8 | 100 | disable_server_conf_autoconn(source_p->name); |
62433315 | 101 | exit_client(source_p, source_p, source_p, squitreason); |
212380e3 AC |
102 | return 0; |
103 | } | |
104 | ||
105 | if(deltat > ConfigFileEntry.ts_warn_delta) | |
106 | { | |
34c10ff5 | 107 | sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, |
212380e3 | 108 | "Link %s notable TS delta" |
29c92cf9 | 109 | " (my TS=%ld, their TS=%ld, delta=%ld)", |
e3354945 | 110 | source_p->name, (long) rb_current_time(), (long) theirtime, deltat); |
212380e3 AC |
111 | } |
112 | ||
113 | return 0; | |
114 | } |