added recover command to recover zombies from user side
authorpk910 <philipp@zoelle1.de>
Fri, 11 May 2012 02:38:58 +0000 (04:38 +0200)
committerpk910 <philipp@zoelle1.de>
Fri, 11 May 2012 02:38:58 +0000 (04:38 +0200)
include/handlers.h
include/msg.h
include/numeric.h
ircd/Makefile.in
ircd/ircd.c
ircd/m_quit.c
ircd/m_recover.c [new file with mode: 0644]
ircd/parse.c
ircd/s_err.c

index ee594303c25dedb0bb4268a63b2744bd7d228c47..19b64ceb1d8adab8b81701c8d3b5ef471279cdd3 100644 (file)
@@ -125,6 +125,7 @@ extern int m_privs(struct Client*, struct Client*, int, char*[]);
 extern int m_proto(struct Client*, struct Client*, int, char*[]);
 extern int m_pseudo(struct Client*, struct Client*, int, char*[]);
 extern int m_quit(struct Client*, struct Client*, int, char*[]);
+extern int m_recover(struct Client*, struct Client*, int, char*[]);
 extern int m_registered(struct Client*, struct Client*, int, char*[]);
 extern int m_silence(struct Client*, struct Client*, int, char*[]);
 extern int m_stats(struct Client*, struct Client*, int, char*[]);
index 9eb6572d06eb2642746ddd907d4123691360c9a6..4afde55c7ee02a2babee5679359acc57b447f622 100644 (file)
@@ -336,6 +336,10 @@ struct Client;
 #define TOK_ACCOUNT            "AC"
 #define CMD_ACCOUNT            MSG_ACCOUNT, TOK_ACCOUNT
 
+#define MSG_RECOVER            "RECOVER"       /* RECOVER */
+#define TOK_RECOVER            "RC"
+#define CMD_RECOVER            MSG_RECOVER, TOK_RECOVER
+
 #define MSG_ZOMBIE             "ZOMBIE"        /* ZOMB */
 #define TOK_ZOMBIE             "ZO"
 #define CMD_ZOMBIE             MSG_ZOMBIE, TOK_ZOMBIE
index 30e54d936cdbad663bac4d1887e561bb273cf9cb..6de836346df470b0c6f6c2a3a1dd463ea5886f6d 100644 (file)
@@ -357,6 +357,7 @@ extern const struct Numeric* get_error_numeric(int err);
 #define ERR_NONICKNAMEGIVEN  431
 #define ERR_ERRONEUSNICKNAME 432
 #define ERR_NICKNAMEINUSE    433
+#define ERR_RECOVERDENIED    434
 /*      ERR_SERVICENAMEINUSE 434 ? */
 /*     ERR_NORULES          434   unreal */
 /*      ERR_SERVICECONFUSED  435 ? */
index 476b540baf9479f1f3b624493ebe89a344780911..c3361889b420c1336be6d78935c9f45baba34910 100644 (file)
@@ -160,7 +160,8 @@ IRCD_SRC = \
        m_proto.c \
        m_pseudo.c \
        m_quit.c \
-       m_rehash.c \
+       m_recover.c \
+    m_rehash.c \
        m_relay.c \
        m_reset.c \
        m_restart.c \
index 91ab9b41f6d5de57e42b85ce7153e62713039b5f..ad6ae5fb5f9699e4f7e521575496efa005eb9e8a 100644 (file)
@@ -343,8 +343,8 @@ static void check_pings(struct Event* ev) {
     /* We don't need to check zombies here */
     if (IsNotConn(cptr)) {
       assert(IsUser(cptr));
-      /* for now: reap after fixed time (15 minutes) */
-      if ((CurrentTime - cli_user(cptr)->last) >= 900) {
+      /* for now: reap after fixed time (5 minutes) */
+      if ((CurrentTime - cli_user(cptr)->last) >= 300) {
         SetFlag(cptr, FLAG_DEADSOCKET);
         /* this will be used as exit message */
         ircd_strncpy(cli_info(cptr), "Ping timeout", REALLEN);
index 16376e42a4406b33988dc96d649ae2577bf54a72..20b8224145f2bff5a9a8224a1ddd60eed8df33a1 100644 (file)
@@ -105,6 +105,11 @@ int m_quit(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   assert(0 != sptr);
   assert(cptr == sptr);
 
+  if (!irc_strcmp(parv[parc - 1], "ZOMBIE")) {
+    zombie_client(&me, &me, sptr);
+    return 0;
+  }
+
   if (cli_user(sptr)) {
     struct Membership* chan;
     for (chan = cli_user(sptr)->channel; chan; chan = chan->next_channel) {
diff --git a/ircd/m_recover.c b/ircd/m_recover.c
new file mode 100644 (file)
index 0000000..8a507ce
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+ * IRC - Internet Relay Chat, ircd/m_recover.c
+ * Copyright (C) 2012 Philipp Kreil <srvx@pk910.de>
+ *
+ * See file AUTHORS in IRC package for additional names of
+ * the programmers.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 1, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ */
+/*
+ * m_functions execute protocol messages on this server:
+ *
+ *    cptr    is always NON-NULL, pointing to a *LOCAL* client
+ *            structure (with an open socket connected!). This
+ *            identifies the physical socket where the message
+ *            originated (or which caused the m_function to be
+ *            executed--some m_functions may call others...).
+ *
+ *    sptr    is the source of the message, defined by the
+ *            prefix part of the message if present. If not
+ *            or prefix not found, then sptr==cptr.
+ *
+ *            (!IsServer(cptr)) => (cptr == sptr), because
+ *            prefixes are taken *only* from servers...
+ *
+ *            (IsServer(cptr))
+ *                    (sptr == cptr) => the message didn't
+ *                    have the prefix.
+ *
+ *                    (sptr != cptr && IsServer(sptr) means
+ *                    the prefix specified servername. (?)
+ *
+ *                    (sptr != cptr && !IsServer(sptr) means
+ *                    that message originated from a remote
+ *                    user (not local).
+ *
+ *            combining
+ *
+ *            (!IsServer(sptr)) means that, sptr can safely
+ *            taken as defining the target structure of the
+ *            message in this server.
+ *
+ *    *Always* true (if 'parse' and others are working correct):
+ *
+ *    1)      sptr->from == cptr  (note: cptr->from == cptr)
+ *
+ *    2)      MyConnect(sptr) <=> sptr == cptr (e.g. sptr
+ *            *cannot* be a local connection, unless it's
+ *            actually cptr!). [MyConnect(x) should probably
+ *            be defined as (x == x->from) --msa ]
+ *
+ *    parc    number of variable parameter strings (if zero,
+ *            parv is allowed to be NULL)
+ *
+ *    parv    a NULL terminated list of parameter pointers,
+ *
+ *                    parv[0], sender (prefix string), if not present
+ *                            this points to an empty string.
+ *                    parv[1]...parv[parc-1]
+ *                            pointers to additional parameters
+ *                    parv[parc] == NULL, *always*
+ *
+ *            note:   it is guaranteed that parv[0]..parv[parc-1] are all
+ *                    non-NULL pointers.
+ */
+#include "config.h"
+
+#include "client.h"
+#include "ircd.h"
+#include "ircd_log.h"
+#include "ircd_reply.h"
+#include "ircd_string.h"
+#include "msg.h"
+#include "numnicks.h"
+#include "s_debug.h"
+#include "s_misc.h"
+#include "s_user.h"
+#include "send.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+/** m_recover - Try to recover a disconnected Client (Zombie)
+ *
+ * parv[0] = sender prefix
+ * parv[1] = nick of the zombie to be recovered
+ */
+int m_recover(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
+{
+  struct Client *victim;
+
+  if (parc < 2)
+    return need_more_params(sptr, "RECOVER");
+
+  //check Auth
+  if(!IsAccount(sptr)) {
+    send_reply(sptr, ERR_NOTREGISTERED);
+    return 0;
+  }
+
+  if (!(victim = findUser(parv[1]))) {
+    send_reply(sptr, ERR_NOSUCHNICK, parv[1]);
+    return 0;
+  }
+
+  if (!IsNotConn(victim)) {
+    send_reply(sptr, ERR_RECOVERDENIED, cli_name(victim), "not zombie");
+    return 0;
+  }
+  assert(IsAccount(victim));
+
+  const struct User* sptr_user = cli_user(sptr);
+  const struct User* victim_user = cli_user(victim);
+  if(ircd_strcmp(sptr_user->account, victim_user->account)) {
+    send_reply(sptr, ERR_RECOVERDENIED, cli_name(victim), "auth missmatch");
+    return 0;
+  }
+
+  unzombie_client(&me, &me, sptr, victim);
+  return 0;
+}
index 27608219400226b592cfc5c304687814c1c6173a..977e85c849d91664e94ff10c77589a957cb2a39e 100644 (file)
@@ -610,6 +610,13 @@ struct Message msgtab[] = {
     /* UNREG, CLIENT, SERVER, OPER, SERVICE */
     { m_ignore, m_ignore, ms_account, m_ignore, m_ignore }
   },
+  {
+    MSG_RECOVER,
+    TOK_RECOVER,
+    0, MAXPARA, MFLG_SLOW, 0, NULL,
+    /* UNREG, CLIENT, SERVER, OPER, SERVICE */
+    { m_unregistered, m_recover, m_ignore, m_ignore, m_ignore }
+  },
   {
     MSG_ZOMBIE,
     TOK_ZOMBIE,
index cc9ccf88f933c8970d6cd932819339d175532a11..bc7d0ffbd4347d677789b550fc1aa3ccc3d53537 100644 (file)
@@ -900,7 +900,7 @@ static Numeric replyTable[] = {
 /* 433 */
   { ERR_NICKNAMEINUSE, "%s :Nickname is already in use.", "433" },
 /* 434 */
-  { 0 },
+  { ERR_RECOVERDENIED, "%s :You may not recover this connection. (%s)", "434" },
 /* 435 */
   { 0 },
 /* 436 */