* note: it is guaranteed that parv[0]..parv[parc-1] are all
* non-NULL pointers.
*/
-#if 0
-/*
- * No need to include handlers.h here the signatures must match
- * and we don't need to force a rebuild of all the handlers everytime
- * we add a new one to the list. --Bleep
- */
-#include "handlers.h"
-#endif /* 0 */
+#include "config.h"
+
#include "client.h"
#include "hash.h"
#include "ircd.h"
#include "ircd_features.h"
+#include "ircd_log.h"
#include "ircd_reply.h"
+#include "ircd_snprintf.h"
#include "ircd_string.h"
#include "list.h"
#include "msg.h"
#include "send.h"
#include "struct.h"
-#include <assert.h>
+/* #include <assert.h> -- Now using assert in ircd_log.h */
#include <stdlib.h>
/*
*
* parv[0] = sender prefix
* parv[1] = new time
- * parv[2] = servername (Only used when sptr is an Oper).
+ * parv[2] = server name (Only used when sptr is an Oper).
*/
int ms_settime(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
{
time_t t;
- long int dt;
+ long dt;
static char tbuf[11];
struct DLink *lp;
- if (!IsPrivileged(sptr))
- return 0;
-
- if (parc < 2)
+ if (parc < 2) /* verify argument count */
return need_more_params(sptr, "SETTIME");
- if (parc == 2 && MyUser(sptr))
- parv[parc++] = cli_name(&me);
-
- t = atoi(parv[1]);
+ t = atoi(parv[1]); /* convert time and compute delta */
dt = TStime() - t;
+ /* verify value */
if (t < OLDEST_TS || dt < -9000000)
{
- sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :SETTIME: Bad value", sptr);
+ if (IsServer(sptr)) /* protocol violation if it's from a server */
+ protocol_violation(sptr, "SETTIME: Bad value (%Tu, delta %ld)", t, dt);
+ else
+ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :SETTIME: Bad value (%Tu, "
+ "delta %ld)", sptr, t, dt);
+ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :SETTIME: Bad value", sptr);
return 0;
}
- if (IsServer(sptr)) /* send to unlagged servers */
+ /* reset time... */
+ if (feature_bool(FEAT_RELIABLE_CLOCK))
{
- if (feature_bool(FEAT_RELIABLE_CLOCK)) {
- sprintf_irc(tbuf, TIME_T_FMT, TStime());
- parv[1] = tbuf;
- }
+ ircd_snprintf(0, tbuf, sizeof(tbuf), "%Tu", TStime());
+ parv[1] = tbuf;
+ }
+ if (BadPtr(parv[2])) /* spam the network */
+ {
for (lp = cli_serv(&me)->down; lp; lp = lp->next)
- if (cptr != lp->value.cptr && MsgQLength(&(cli_sendQ(lp->value.cptr))) < 8000)
- sendcmdto_one(sptr, CMD_NOTICE, lp->value.cptr, "%s", parv[1]);
+ if (cptr != lp->value.cptr)
+ sendcmdto_prio_one(sptr, CMD_SETTIME, lp->value.cptr, "%s", parv[1]);
}
else
{
- sprintf_irc(tbuf, TIME_T_FMT, TStime());
- parv[1] = tbuf;
- if (hunt_server_cmd(sptr, CMD_SETTIME, cptr, 1, "%s %C", 2, parc, parv) !=
- HUNTED_ISME)
+ if (hunt_server_prio_cmd(sptr, CMD_SETTIME, cptr, 1, "%s %C", 2, parc,
+ parv) != HUNTED_ISME)
+ {
+ /* If the destination was *not* me, but I'm RELIABLE_CLOCK and the
+ * delta is more than 30 seconds off, bounce back a corrected
+ * SETTIME
+ */
+ if (feature_bool(FEAT_RELIABLE_CLOCK) && (dt > 30 || dt < -30))
+ sendcmdto_prio_one(&me, CMD_SETTIME, cptr, "%s %C", parv[1], cptr);
return 0;
+ }
}
- if (feature_bool(FEAT_RELIABLE_CLOCK)) {
+ if (feature_bool(FEAT_RELIABLE_CLOCK))
+ {
+ /* don't apply settime--reliable */
if ((dt > 600) || (dt < -600))
- sendcmdto_serv_butone(&me, CMD_WALLOPS, 0, ":Bad SETTIME from %s: %Tu",
- cli_name(sptr), t);
- if (IsUser(sptr)) {
+ sendcmdto_serv_butone(&me, CMD_DESYNCH, 0, ":Bad SETTIME from %s: %Tu "
+ "(delta %ld)", cli_name(sptr), t, dt);
+ /* Let user know we're ignoring him */
+ if (IsUser(sptr))
+ {
sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is not set %ld "
"seconds %s : RELIABLE_CLOCK is defined", sptr,
(dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
}
- } else {
+ }
+ else /* tell opers about time change */
+ {
sendto_opmask_butone(0, SNO_OLDSNO, "SETTIME from %s, clock is set %ld "
"seconds %s", cli_name(sptr), (dt < 0) ? -dt : dt,
(dt < 0) ? "forwards" : "backwards");
+ /* Apply time change... */
TSoffset -= dt;
- if (IsUser(sptr)) {
+ /* Let the issuing user know what we did... */
+ if (IsUser(sptr))
+ {
sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is set %ld seconds %s",
- sptr, (dt < 0) ? -dt : dt,
- (dt < 0) ? "forwards" : "backwards");
+ sptr, (dt < 0) ? -dt : dt,
+ (dt < 0) ? "forwards" : "backwards");
}
}
int mo_settime(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
{
time_t t;
- long int dt;
+ long dt;
static char tbuf[11];
- struct DLink *lp;
- if (!IsPrivileged(sptr))
- return 0;
+ /* Must be a global oper */
+ if (!IsOper(sptr))
+ return send_reply(sptr, ERR_NOPRIVILEGES);
- if (parc < 2)
+ if (parc < 2) /* verify argument count */
return need_more_params(sptr, "SETTIME");
- if (parc == 2 && MyUser(sptr))
+ if (parc == 2 && MyUser(sptr)) /* default to me */
parv[parc++] = cli_name(&me);
- t = atoi(parv[1]);
- dt = TStime() - t;
+ t = atoi(parv[1]); /* convert the time */
- if (t < OLDEST_TS || dt < -9000000)
+ /* If we're reliable_clock or if the oper specified a 0 time, use current */
+ if (!t || feature_bool(FEAT_RELIABLE_CLOCK))
{
- sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :SETTIME: Bad value", sptr);
- return 0;
+ t = TStime();
+ ircd_snprintf(0, tbuf, sizeof(tbuf), "%Tu", TStime());
+ parv[1] = tbuf;
}
- if (IsServer(sptr)) /* send to unlagged servers */
- {
- if (feature_bool(FEAT_RELIABLE_CLOCK)) {
- sprintf_irc(tbuf, TIME_T_FMT, TStime());
- parv[1] = tbuf;
- }
+ dt = TStime() - t; /* calculate the delta */
- for (lp = cli_serv(&me)->down; lp; lp = lp->next)
- if (cptr != lp->value.cptr && MsgQLength(&(cli_sendQ(lp->value.cptr))) < 8000)
- sendcmdto_one(sptr, CMD_SETTIME, lp->value.cptr, "%s", parv[1]);
- }
- else
+ if (t < OLDEST_TS || dt < -9000000) /* verify value */
{
- sprintf_irc(tbuf, TIME_T_FMT, TStime());
- parv[1] = tbuf;
- if (hunt_server_cmd(sptr, CMD_SETTIME, cptr, 1, "%s %C", 2, parc, parv) !=
- HUNTED_ISME)
- return 0;
+ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :SETTIME: Bad value", sptr);
+ return 0;
}
- if (feature_bool(FEAT_RELIABLE_CLOCK)) {
+ /* OK, send the message off to its destination */
+ if (hunt_server_prio_cmd(sptr, CMD_SETTIME, cptr, 1, "%s %C", 2, parc,
+ parv) != HUNTED_ISME)
+ return 0;
+
+ if (feature_bool(FEAT_RELIABLE_CLOCK)) /* don't apply settime--reliable */
+ {
if ((dt > 600) || (dt < -600))
- sendcmdto_serv_butone(&me, CMD_WALLOPS, 0, ":Bad SETTIME from %s: %Tu",
- cli_name(sptr), t);
- if (IsUser(sptr)) {
- sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is not set %ld "
- "seconds %s : RELIABLE_CLOCK is defined", sptr,
- (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
- }
- } else {
+ sendcmdto_serv_butone(&me, CMD_DESYNCH, 0, ":Bad SETTIME from %s: %Tu "
+ "(delta %ld)", cli_name(sptr), t, dt);
+ if (IsUser(sptr)) /* Let user know we're ignoring him */
+ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is not set %ld seconds "
+ "%s: RELIABLE_CLOCK is defined", sptr, (dt < 0) ? -dt : dt,
+ (dt < 0) ? "forwards" : "backwards");
+ }
+ else /* tell opers about time change */
+ {
sendto_opmask_butone(0, SNO_OLDSNO, "SETTIME from %s, clock is set %ld "
"seconds %s", cli_name(sptr), (dt < 0) ? -dt : dt,
(dt < 0) ? "forwards" : "backwards");
- TSoffset -= dt;
- if (IsUser(sptr)) {
+ TSoffset -= dt; /* apply time change */
+ if (IsUser(sptr)) /* let user know what we did */
sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is set %ld seconds %s",
sptr, (dt < 0) ? -dt : dt,
(dt < 0) ? "forwards" : "backwards");
- }
- }
-
- return 0;
-}
-
-
-#if 0
-/*
- * m_settime
- *
- * parv[0] = sender prefix
- * parv[1] = new time
- * parv[2] = servername (Only used when sptr is an Oper).
- */
-int m_settime(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
-{
- time_t t;
- long int dt;
- static char tbuf[11];
- struct DLink *lp;
-
- if (!IsPrivileged(sptr))
- return 0;
-
- if (parc < 2)
- return need_more_params(sptr, "SETTIME");
-
- if (parc == 2 && MyUser(sptr))
- parv[parc++] = me.name;
-
- t = atoi(parv[1]);
- dt = TStime() - t;
-
- if (t < OLDEST_TS || dt < -9000000)
- {
- sendto_one(sptr, ":%s NOTICE %s :SETTIME: Bad value", me.name, parv[0]); /* XXX DEAD */
- return 0;
- }
-
- if (IsServer(sptr)) /* send to unlagged servers */
- {
-#ifdef RELIABLE_CLOCK
- sprintf_irc(tbuf, TIME_T_FMT, TStime());
- parv[1] = tbuf;
-#endif
- for (lp = me.serv->down; lp; lp = lp->next)
- if (cptr != lp->value.cptr && DBufLength(&lp->value.cptr->sendQ) < 8000) /* XXX DEAD */
- sendto_one(lp->value.cptr, ":%s SETTIME %s", parv[0], parv[1]); /* XXX DEAD */
- }
- else
- {
- sprintf_irc(tbuf, TIME_T_FMT, TStime());
- parv[1] = tbuf;
- if (hunt_server(1, cptr, sptr, "%s%s " TOK_SETTIME " %s %s", 2, parc, parv) != /* XXX DEAD */
- HUNTED_ISME)
- return 0;
}
-#ifdef RELIABLE_CLOCK
- if ((dt > 600) || (dt < -600))
- sendto_serv_butone(0, ":%s " TOK_WALLOPS " :Bad SETTIME from %s: " TIME_T_FMT, /* XXX DEAD */
- me.name, sptr->name, t);
- if (IsUser(sptr))
- {
- if (MyUser(sptr) || Protocol(cptr) < 10)
- sendto_one(sptr, ":%s NOTICE %s :clock is not set %ld seconds %s : " /* XXX DEAD */
- "RELIABLE_CLOCK is defined", me.name, parv[0],
- (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
- else
- sendto_one(sptr, "%s NOTICE %s%s :clock is not set %ld seconds %s : " /* XXX DEAD */
- "RELIABLE_CLOCK is defined", NumServ(&me), NumNick(sptr),
- (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
- }
-#else
- sendto_ops("SETTIME from %s, clock is set %ld seconds %s", /* XXX DEAD */
- sptr->name, (dt < 0) ? -dt : dt,
- (dt < 0) ? "forwards" : "backwards");
- TSoffset -= dt;
- if (IsUser(sptr))
- {
- if (MyUser(sptr) || Protocol(cptr) < 10)
- sendto_one(sptr, ":%s NOTICE %s :clock is set %ld seconds %s", me.name, /* XXX DEAD */
- parv[0], (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
- else
- sendto_one(sptr, "%s NOTICE %s%s :clock is set %ld seconds %s", /* XXX DEAD */
- NumServ(&me), NumNick(sptr),
- (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
- }
-#endif
return 0;
}
-#endif /* 0 */