1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* m_svinfo.c: Sends TS information for clock & compatibility checks. |
4 |
* |
5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
* |
22 |
* $Id$ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "client.h" |
27 |
#include "irc_string.h" |
28 |
#include "ircd.h" |
29 |
#include "numeric.h" |
30 |
#include "send.h" |
31 |
#include "s_conf.h" |
32 |
#include "s_log.h" |
33 |
#include "parse.h" |
34 |
#include "modules.h" |
35 |
|
36 |
|
37 |
/* |
38 |
* ms_svinfo - SVINFO message handler |
39 |
* parv[0] = sender prefix |
40 |
* parv[1] = TS_CURRENT for the server |
41 |
* parv[2] = TS_MIN for the server |
42 |
* parv[3] = server is standalone or connected to non-TS only |
43 |
* parv[4] = server's idea of UTC time |
44 |
*/ |
45 |
static void |
46 |
ms_svinfo(struct Client *client_p, struct Client *source_p, |
47 |
int parc, char *parv[]) |
48 |
{ |
49 |
time_t deltat; |
50 |
time_t theirtime; |
51 |
|
52 |
if (MyConnect(source_p) && IsUnknown(source_p)) |
53 |
{ |
54 |
exit_client(source_p, source_p, "Need SERVER before SVINFO"); |
55 |
return; |
56 |
} |
57 |
|
58 |
if (!IsServer(source_p) || !MyConnect(source_p) || parc < 5) |
59 |
return; |
60 |
|
61 |
if (TS_CURRENT < atoi(parv[2]) || atoi(parv[1]) < TS_MIN) |
62 |
{ |
63 |
/* |
64 |
* a server with the wrong TS version connected; since we're |
65 |
* TS_ONLY we can't fall back to the non-TS protocol so |
66 |
* we drop the link -orabidoo |
67 |
*/ |
68 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
69 |
"Link %s dropped, wrong TS protocol version (%s,%s)", |
70 |
get_client_name(source_p, SHOW_IP), parv[1], parv[2]); |
71 |
sendto_realops_flags(UMODE_ALL, L_OPER, |
72 |
"Link %s dropped, wrong TS protocol version (%s,%s)", |
73 |
get_client_name(source_p, MASK_IP), parv[1], parv[2]); |
74 |
exit_client(source_p, source_p, "Incompatible TS version"); |
75 |
return; |
76 |
} |
77 |
|
78 |
/* |
79 |
* since we're here, might as well set CurrentTime while we're at it |
80 |
*/ |
81 |
set_time(); |
82 |
theirtime = atol(parv[4]); |
83 |
deltat = abs(theirtime - CurrentTime); |
84 |
|
85 |
if (deltat > ConfigFileEntry.ts_max_delta) |
86 |
{ |
87 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
88 |
"Link %s dropped, excessive TS delta (my TS=%lu, their TS=%lu, delta=%d)", |
89 |
get_client_name(source_p, SHOW_IP), |
90 |
(unsigned long) CurrentTime, |
91 |
(unsigned long) theirtime, |
92 |
(int) deltat); |
93 |
sendto_realops_flags(UMODE_ALL, L_OPER, |
94 |
"Link %s dropped, excessive TS delta (my TS=%lu, their TS=%lu, delta=%d)", |
95 |
get_client_name(source_p, MASK_IP), |
96 |
(unsigned long) CurrentTime, |
97 |
(unsigned long) theirtime, |
98 |
(int) deltat); |
99 |
ilog(LOG_TYPE_IRCD, |
100 |
"Link %s dropped, excessive TS delta (my TS=%lu, their TS=%lu, delta=%d)", |
101 |
get_client_name(source_p, SHOW_IP), |
102 |
(unsigned long) CurrentTime, |
103 |
(unsigned long) theirtime, |
104 |
(int) deltat); |
105 |
exit_client(source_p, source_p, "Excessive TS delta"); |
106 |
return; |
107 |
} |
108 |
|
109 |
if (deltat > ConfigFileEntry.ts_warn_delta) |
110 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
111 |
"Link %s notable TS delta (my TS=%lu, their TS=%lu, delta=%d)", |
112 |
source_p->name, |
113 |
(unsigned long) CurrentTime, |
114 |
(unsigned long) theirtime, |
115 |
(int) deltat); |
116 |
} |
117 |
|
118 |
static struct Message svinfo_msgtab = { |
119 |
"SVINFO", 0, 0, 4, MAXPARA, MFLG_SLOW, 0, |
120 |
{m_unregistered, m_ignore, ms_svinfo, m_ignore, m_ignore, m_ignore} |
121 |
}; |
122 |
|
123 |
static void |
124 |
module_init(void) |
125 |
{ |
126 |
mod_add_cmd(&svinfo_msgtab); |
127 |
} |
128 |
|
129 |
static void |
130 |
module_exit(void) |
131 |
{ |
132 |
mod_del_cmd(&svinfo_msgtab); |
133 |
} |
134 |
|
135 |
struct module module_entry = { |
136 |
.node = { NULL, NULL, NULL }, |
137 |
.name = NULL, |
138 |
.version = "$Revision$", |
139 |
.handle = NULL, |
140 |
.modinit = module_init, |
141 |
.modexit = module_exit, |
142 |
.flags = 0 |
143 |
}; |