[IRC-Dev CVS] SF.net SVN: irc-dev:[199] ircd/trunk
Brought to you by:
zolty
|
From: <zo...@us...> - 2008-08-15 20:04:08
|
Revision: 199
http://irc-dev.svn.sourceforge.net/irc-dev/?rev=199&view=rev
Author: zolty
Date: 2008-08-15 20:04:12 +0000 (Fri, 15 Aug 2008)
Log Message:
-----------
Soporte de REHASH, RESTART y DIE remotos
Modified Paths:
--------------
ircd/trunk/include/handlers.h
ircd/trunk/include/ircd_features.h
ircd/trunk/include/msg.h
ircd/trunk/ircd/ircd_features.c
ircd/trunk/ircd/m_die.c
ircd/trunk/ircd/m_rehash.c
ircd/trunk/ircd/m_restart.c
ircd/trunk/ircd/parse.c
Modified: ircd/trunk/include/handlers.h
===================================================================
--- ircd/trunk/include/handlers.h 2008-08-15 18:54:05 UTC (rev 198)
+++ ircd/trunk/include/handlers.h 2008-08-15 20:04:12 UTC (rev 199)
@@ -205,6 +205,7 @@
extern int ms_dbq(struct Client*, struct Client*, int, char*[]);
extern int ms_destruct(struct Client*, struct Client*, int, char*[]);
extern int ms_desynch(struct Client*, struct Client*, int, char*[]);
+extern int ms_die(struct Client*, struct Client*, int, char*[]);
extern int ms_end_of_burst(struct Client*, struct Client*, int, char*[]);
extern int ms_end_of_burst_ack(struct Client*, struct Client*, int, char*[]);
extern int ms_error(struct Client*, struct Client*, int, char*[]);
@@ -230,6 +231,8 @@
extern int ms_privmsg(struct Client*, struct Client*, int, char*[]);
extern int ms_privs(struct Client*, struct Client*, int, char*[]);
extern int ms_quit(struct Client*, struct Client*, int, char*[]);
+extern int ms_rehash(struct Client*, struct Client*, int, char*[]);
+extern int ms_restart(struct Client*, struct Client*, int, char*[]);
extern int ms_rping(struct Client*, struct Client*, int, char*[]);
extern int ms_rpong(struct Client*, struct Client*, int, char*[]);
extern int ms_server(struct Client*, struct Client*, int, char*[]);
Modified: ircd/trunk/include/ircd_features.h
===================================================================
--- ircd/trunk/include/ircd_features.h 2008-08-15 18:54:05 UTC (rev 198)
+++ ircd/trunk/include/ircd_features.h 2008-08-15 20:04:12 UTC (rev 199)
@@ -203,6 +203,11 @@
FEAT_SPAM_JOINED_TIME,
FEAT_SPAM_FJP_COUNT,
+ /* Really special features (tm) */
+ FEAT_NETWORK_REHASH,
+ FEAT_NETWORK_RESTART,
+ FEAT_NETWORK_DIE,
+
#if 1 /* TRANSICION IRC-HISPANO */
FEAT_TRANSICION_HISPANO,
#endif
Modified: ircd/trunk/include/msg.h
===================================================================
--- ircd/trunk/include/msg.h 2008-08-15 18:54:05 UTC (rev 198)
+++ ircd/trunk/include/msg.h 2008-08-15 20:04:12 UTC (rev 199)
@@ -268,11 +268,11 @@
#define CMD_SERVSET MSG_SERVSET, TOK_SERVSET
#define MSG_REHASH "REHASH" /* REHA */
-#define TOK_REHASH "REHASH"
+#define TOK_REHASH "RH"
#define CMD_REHASH MSG_REHASH, TOK_REHASH
#define MSG_RESTART "RESTART" /* REST */
-#define TOK_RESTART "RESTART"
+#define TOK_RESTART "RS"
#define CMD_RESTART MSG_RESTART, TOK_RESTART
#define MSG_CLOSE "CLOSE" /* CLOS */
@@ -280,7 +280,7 @@
#define CMD_CLOSE MSG_CLOSE, TOK_CLOSE
#define MSG_DIE "DIE" /* DIE */
-#define TOK_DIE "DIE"
+#define TOK_DIE "DI"
#define CMD_DIE MSG_DIE, TOK_DIE
#define MSG_HASH "HASH" /* HASH */
Modified: ircd/trunk/ircd/ircd_features.c
===================================================================
--- ircd/trunk/ircd/ircd_features.c 2008-08-15 18:54:05 UTC (rev 198)
+++ ircd/trunk/ircd/ircd_features.c 2008-08-15 20:04:12 UTC (rev 199)
@@ -535,6 +535,11 @@
F_I(SPAM_JOINED_TIME, 0, 60, 0),
F_I(SPAM_FJP_COUNT, 0, 5, 0),
+ /* Really special features (tm) */
+ F_B(NETWORK_REHASH, 0, 0, 0),
+ F_B(NETWORK_RESTART, 0, 0, 0),
+ F_B(NETWORK_DIE, 0, 0, 0),
+
#if 1 /* TRANSICION IRC-HISPANO */
F_B(TRANSICION_HISPANO, 0, 1, 0),
#endif
Modified: ircd/trunk/ircd/m_die.c
===================================================================
--- ircd/trunk/ircd/m_die.c 2008-08-15 18:54:05 UTC (rev 198)
+++ ircd/trunk/ircd/m_die.c 2008-08-15 20:04:12 UTC (rev 199)
@@ -27,6 +27,7 @@
#include "client.h"
#include "ircd.h"
+#include "ircd_features.h"
#include "ircd_log.h"
#include "ircd_reply.h"
#include "ircd_string.h"
@@ -34,15 +35,69 @@
#include "numeric.h"
#include "numnicks.h"
#include "s_bsd.h"
+#include "s_user.h"
#include "send.h"
/* #include <assert.h> -- Now using assert in ircd_log.h */
+/** Handle a DIE message from a server connection.
+ *
+ * \a parv has the following elements:
+ * \li \a parv[1] is the target server, or "*" for all.
+ * \li \a parv[2] is either "cancel" or a time interval in seconds
+ * \li \a parv[\a parc - 1] is the reason
+ *
+ * All fields must be present. Additionally, the time interval should
+ * not be 0 for messages sent to "*", as that may not function
+ * reliably due to buffering in the server.
+ *
+ * See @ref m_functions for discussion of the arguments.
+ * @param[in] cptr Client that sent us the message.
+ * @param[in] sptr Original source of message.
+ * @param[in] parc Number of arguments.
+ * @param[in] parv Argument vector.
+*/
+int ms_die(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
+{
+ const char *target, *when, *reason;
+
+ if (parc < 4)
+ return need_more_params(sptr, "DIE");
+
+ target = parv[1];
+ when = parv[2];
+ reason = parv[parc - 1];
+
+ /* is it a message we should pay attention to? */
+ if (target[0] != '*' || target[1] != '\0') {
+ if (hunt_server_cmd(sptr, CMD_DIE, cptr, 0, "%C %s :%s", 1, parc, parv)
+ != HUNTED_ISME)
+ return 0;
+ } else /* must forward the message */
+ sendcmdto_serv(sptr, CMD_DIE, cptr, "* %s :%s", when, reason);
+
+ /* OK, the message has been forwarded, but before we can act... */
+ if (!feature_bool(FEAT_NETWORK_DIE))
+ return 0;
+
+ /* is it a cancellation? */
+ if (!ircd_strcmp(when, "cancel"))
+ exit_cancel(sptr); /* cancel a pending exit */
+ else /* schedule an exit */
+ exit_schedule(0, atoi(when), sptr, reason);
+
+ return 0;
+}
+
/** Handle a DIE message from an operator.
*
- * \a parv is ignored.
+ * \a parv has the following elements:
+ * \li \a parv[1] is either "cancel" or a time interval in seconds
+ * \li \a parv[\a parc - 1] is the reason
*
+ * Either the time interval or the reason (or both) may be omitted.
+ *
* See @ref m_functions for discussion of the arguments.
* @param[in] cptr Client that sent us the message.
* @param[in] sptr Original source of message.
@@ -51,23 +106,22 @@
*/
int mo_die(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
{
- struct Client *acptr;
- int i;
+ time_t when = 0;
+ const char *reason = 0;
if (!HasPriv(sptr, PRIV_DIE))
return send_reply(sptr, ERR_NOPRIVILEGES);
- for (i = 0; i <= HighestFd; i++)
- {
- if (!(acptr = LocalClientArray[i]))
- continue;
- if (IsUser(acptr))
- sendcmdto_one(&me, CMD_NOTICE, acptr, "%C :Server Terminating. %s",
- acptr, get_client_name(sptr, HIDE_IP));
- else if (IsServer(acptr))
- sendcmdto_one(&me, CMD_ERROR, acptr, ":Terminated by %s",
- get_client_name(sptr, HIDE_IP));
- }
+ if (parc > 1 && !ircd_strcmp(parv[1], "cancel")) {
+ exit_cancel(sptr); /* cancel a pending exit */
+ return 0;
+ } else if (parc > 2) { /* have both time and reason */
+ when = atoi(parv[1]);
+ reason = parv[parc - 1];
+ } else if (parc > 1 && !(when = atoi(parv[1])))
+ reason = parv[parc - 1];
+
+ /* now, let's schedule the exit */
exit_schedule(0, 0, 0, "Received DIE");
return 0;
Modified: ircd/trunk/ircd/m_rehash.c
===================================================================
--- ircd/trunk/ircd/m_rehash.c 2008-08-15 18:54:05 UTC (rev 198)
+++ ircd/trunk/ircd/m_rehash.c 2008-08-15 20:04:12 UTC (rev 199)
@@ -27,17 +27,92 @@
#include "client.h"
#include "ircd.h"
+#include "ircd_features.h"
#include "ircd_log.h"
#include "ircd_reply.h"
#include "ircd_string.h"
#include "motd.h"
+#include "msg.h"
#include "numeric.h"
#include "s_conf.h"
+#include "s_user.h"
#include "send.h"
#include "ssl.h"
/* #include <assert.h> -- Now using assert in ircd_log.h */
+/** Handle a REHASH message from a server connection.
+ *
+ * \a parv has the following elements:
+ * \li \a parv[1] is the target server, or "*" for all.
+ * \li \a parv[2] (optional) is a flag indicating what to rehash
+ *
+ * The following flags are recognized:
+ * \li 'm' flushes the MOTD cache
+ * \li 'l' reopens the log files
+ * \li 's' reopens SSL pem file
+ * \li 'q' reloads the configuration file but does not rehash the DNS
+ * resolver
+ * \li the default is to reload the configuration file and restart the
+ * DNS resolver
+ *
+ * See @ref m_functions for discussion of the arguments.
+ * @param[in] cptr Client that sent us the message.
+ * @param[in] sptr Original source of message.
+ * @param[in] parc Number of arguments.
+ * @param[in] parv Argument vector.
+ */
+int ms_rehash(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
+{
+ int flag = 0;
+ const char *target;
+
+ if (parc < 2)
+ return need_more_params(sptr, "REHASH");
+
+ target = parv[1];
+
+ /* is it a message we should pay attention to? */
+ if (target[0] != '*' || target[1] != '\0') {
+ if (hunt_server_cmd(sptr, CMD_REHASH, cptr, 0, parc > 2 ? "%C %s" : "%C",
+ 1, parc, parv)
+ != HUNTED_ISME)
+ return 0;
+ } else if (parc > 2) /* must forward the message with flags */
+ sendcmdto_serv(sptr, CMD_REHASH, cptr, "* %s", parv[2]);
+ else /* just have to forward the message */
+ sendcmdto_serv(sptr, CMD_REHASH, cptr, "*");
+
+ /* OK, the message has been forwarded, but before we can act... */
+ if (!feature_bool(FEAT_NETWORK_REHASH))
+ return 0;
+
+ if (parc > 2) { /* special processing */
+ if (*parv[2] == 'm') {
+ send_reply(sptr, SND_EXPLICIT | RPL_REHASHING, ":Flushing MOTD cache");
+ motd_recache(); /* flush MOTD cache */
+ return 0;
+ } else if (*parv[2] == 'l') {
+ send_reply(sptr, SND_EXPLICIT | RPL_REHASHING, ":Reopening log files");
+ log_reopen(); /* reopen log files */
+ return 0;
+#ifdef USE_SSL
+ } else if (*parv[1] == 's') {
+ send_reply(sptr, SND_EXPLICIT | RPL_REHASHING, ":Reopening SSL pem file");
+ ssl_init();
+ return 0;
+#endif
+ } else if (*parv[2] == 'q')
+ flag = 2;
+ }
+
+ send_reply(sptr, RPL_REHASHING, configfile);
+ sendto_opmask(0, SNO_OLDSNO, "%C is rehashing Server config file", sptr);
+ log_write(LS_SYSTEM, L_INFO, 0, "REHASH From %#C", sptr);
+
+ return rehash(cptr, flag);
+}
+
/** Handle a REHASH message from an operator connection.
*
* \a parv has the following elements:
Modified: ircd/trunk/ircd/m_restart.c
===================================================================
--- ircd/trunk/ircd/m_restart.c 2008-08-15 18:54:05 UTC (rev 198)
+++ ircd/trunk/ircd/m_restart.c 2008-08-15 20:04:12 UTC (rev 199)
@@ -27,19 +27,76 @@
#include "client.h"
#include "ircd.h"
+#include "ircd_features.h"
#include "ircd_log.h"
#include "ircd_reply.h"
#include "ircd_string.h"
+#include "msg.h"
#include "numeric.h"
#include "numnicks.h"
+#include "s_user.h"
#include "send.h"
/* #include <assert.h> -- Now using assert in ircd_log.h */
+
+/** Handle a RESTART message from a server connection.
+ *
+ * \a parv has the following elements:
+ * \li \a parv[1] is the target server, or "*" for all.
+ * \li \a parv[2] is either "cancel" or a time interval in seconds
+ * \li \a parv[\a parc - 1] is the reason
+ *
+ * All fields must be present. Additionally, the time interval should
+ * not be 0 for messages sent to "*", as that may not function
+ * reliably due to buffering in the server.
+ *
+ * See @ref m_functions for discussion of the arguments.
+ * @param[in] cptr Client that sent us the message.
+ * @param[in] sptr Original source of message.
+ * @param[in] parc Number of arguments.
+ * @param[in] parv Argument vector.
+ */
+int ms_restart(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
+{
+ const char *target, *when, *reason;
+
+ if (parc < 4)
+ return need_more_params(sptr, "RESTART");
+
+ target = parv[1];
+ when = parv[2];
+ reason = parv[parc - 1];
+
+ /* is it a message we should pay attention to? */
+ if (target[0] != '*' || target[1] != '\0') {
+ if (hunt_server_cmd(sptr, CMD_RESTART, cptr, 0, "%C %s :%s", 1, parc, parv)
+ != HUNTED_ISME)
+ return 0;
+ } else /* must forward the message */
+ sendcmdto_serv(sptr, CMD_RESTART, cptr, "* %s :%s", when, reason);
+
+ /* OK, the message has been forwarded, but before we can act... */
+ if (!feature_bool(FEAT_NETWORK_RESTART))
+ return 0;
+
+ /* is it a cancellation? */
+ if (!ircd_strcmp(when, "cancel"))
+ exit_cancel(sptr); /* cancel a pending exit */
+ else /* schedule an exit */
+ exit_schedule(1, atoi(when), sptr, reason);
+
+ return 0;
+}
+
/** Handle a RESTART message from an operator connection.
*
- * \a parv is ignored.
+ * \a parv has the following elements:
+ * \li \a parv[1] is either "cancel" or a time interval in seconds
+ * \li \a parv[\a parc - 1] is the reason
*
+ * Either the time interval or the reason (or both) may be omitted.
+ *
* See @ref m_functions for discussion of the arguments.
* @param[in] cptr Client that sent us the message.
* @param[in] sptr Original source of message.
@@ -48,11 +105,23 @@
*/
int mo_restart(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
{
+ time_t when = 0;
+ const char *reason = 0;
+
if (!HasPriv(sptr, PRIV_RESTART))
return send_reply(sptr, ERR_NOPRIVILEGES);
- log_write(LS_SYSTEM, L_NOTICE, 0, "Server RESTART by %#C", sptr);
- exit_schedule(1, 0, 0, "Received RESTART");
+ if (parc > 1 && !ircd_strcmp(parv[1], "cancel")) {
+ exit_cancel(sptr); /* cancel a pending exit */
+ return 0;
+ } else if (parc > 2) { /* have both time and reason */
+ when = atoi(parv[1]);
+ reason = parv[parc - 1];
+ } else if (parc > 1 && !(when = atoi(parv[1])))
+ reason = parv[parc - 1];
+ /* now, let's schedule the exit */
+ exit_schedule(1, when, sptr, reason);
+
return 0;
}
Modified: ircd/trunk/ircd/parse.c
===================================================================
--- ircd/trunk/ircd/parse.c 2008-08-15 18:54:05 UTC (rev 198)
+++ ircd/trunk/ircd/parse.c 2008-08-15 20:04:12 UTC (rev 199)
@@ -559,21 +559,21 @@
TOK_REHASH,
0, MAXPARA, MFLG_SLOW, 0, NULL,
/* UNREG, CLIENT, SERVER, OPER, SERVICE */
- { m_unregistered, m_not_oper, m_ignore, mo_rehash, m_ignore }
+ { m_unregistered, m_not_oper, ms_rehash, mo_rehash, m_ignore }
},
{
MSG_RESTART,
TOK_RESTART,
0, MAXPARA, MFLG_SLOW, 0, NULL,
/* UNREG, CLIENT, SERVER, OPER, SERVICE */
- { m_unregistered, m_not_oper, m_ignore, mo_restart, m_ignore }
+ { m_unregistered, m_not_oper, ms_restart, mo_restart, m_ignore }
},
{
MSG_DIE,
TOK_DIE,
0, MAXPARA, MFLG_SLOW, 0, NULL,
/* UNREG, CLIENT, SERVER, OPER, SERVICE */
- { m_unregistered, m_not_oper, m_ignore, mo_die, m_ignore }
+ { m_unregistered, m_not_oper, ms_die, mo_die, m_ignore }
},
{
MSG_PROTO,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|