From 7cbbc6aa8338d394d79cb7048438dd45adf5c648 Mon Sep 17 00:00:00 2001 From: pk910 Date: Fri, 11 May 2012 04:38:58 +0200 Subject: [PATCH] added recover command to recover zombies from user side --- include/handlers.h | 1 + include/msg.h | 4 ++ include/numeric.h | 1 + ircd/Makefile.in | 3 +- ircd/ircd.c | 4 +- ircd/m_quit.c | 5 ++ ircd/m_recover.c | 135 +++++++++++++++++++++++++++++++++++++++++++++ ircd/parse.c | 7 +++ ircd/s_err.c | 2 +- 9 files changed, 158 insertions(+), 4 deletions(-) create mode 100644 ircd/m_recover.c diff --git a/include/handlers.h b/include/handlers.h index ee59430..19b64ce 100644 --- a/include/handlers.h +++ b/include/handlers.h @@ -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*[]); diff --git a/include/msg.h b/include/msg.h index 9eb6572..4afde55 100644 --- a/include/msg.h +++ b/include/msg.h @@ -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 diff --git a/include/numeric.h b/include/numeric.h index 30e54d9..6de8363 100644 --- a/include/numeric.h +++ b/include/numeric.h @@ -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 ? */ diff --git a/ircd/Makefile.in b/ircd/Makefile.in index 476b540..c336188 100644 --- a/ircd/Makefile.in +++ b/ircd/Makefile.in @@ -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 \ diff --git a/ircd/ircd.c b/ircd/ircd.c index 91ab9b4..ad6ae5f 100644 --- a/ircd/ircd.c +++ b/ircd/ircd.c @@ -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); diff --git a/ircd/m_quit.c b/ircd/m_quit.c index 16376e4..20b8224 100644 --- a/ircd/m_quit.c +++ b/ircd/m_quit.c @@ -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 index 0000000..8a507ce --- /dev/null +++ b/ircd/m_recover.c @@ -0,0 +1,135 @@ +/* + * IRC - Internet Relay Chat, ircd/m_recover.c + * Copyright (C) 2012 Philipp Kreil + * + * 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 +#include + +/** 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; +} diff --git a/ircd/parse.c b/ircd/parse.c index 2760821..977e85c 100644 --- a/ircd/parse.c +++ b/ircd/parse.c @@ -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, diff --git a/ircd/s_err.c b/ircd/s_err.c index cc9ccf8..bc7d0ff 100644 --- a/ircd/s_err.c +++ b/ircd/s_err.c @@ -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 */ -- 2.20.1