fixed some collisions with older commits
[ircu2.10.12-pk.git] / ircd / m_recover.c
1 /*
2  * IRC - Internet Relay Chat, ircd/m_recover.c
3  * Copyright (C) 2012 Philipp Kreil <srvx@pk910.de>
4  *
5  * See file AUTHORS in IRC package for additional names of
6  * the programmers.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 1, or (at your option)
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  * $Id$
23  */
24 /*
25  * m_functions execute protocol messages on this server:
26  *
27  *    cptr    is always NON-NULL, pointing to a *LOCAL* client
28  *            structure (with an open socket connected!). This
29  *            identifies the physical socket where the message
30  *            originated (or which caused the m_function to be
31  *            executed--some m_functions may call others...).
32  *
33  *    sptr    is the source of the message, defined by the
34  *            prefix part of the message if present. If not
35  *            or prefix not found, then sptr==cptr.
36  *
37  *            (!IsServer(cptr)) => (cptr == sptr), because
38  *            prefixes are taken *only* from servers...
39  *
40  *            (IsServer(cptr))
41  *                    (sptr == cptr) => the message didn't
42  *                    have the prefix.
43  *
44  *                    (sptr != cptr && IsServer(sptr) means
45  *                    the prefix specified servername. (?)
46  *
47  *                    (sptr != cptr && !IsServer(sptr) means
48  *                    that message originated from a remote
49  *                    user (not local).
50  *
51  *            combining
52  *
53  *            (!IsServer(sptr)) means that, sptr can safely
54  *            taken as defining the target structure of the
55  *            message in this server.
56  *
57  *    *Always* true (if 'parse' and others are working correct):
58  *
59  *    1)      sptr->from == cptr  (note: cptr->from == cptr)
60  *
61  *    2)      MyConnect(sptr) <=> sptr == cptr (e.g. sptr
62  *            *cannot* be a local connection, unless it's
63  *            actually cptr!). [MyConnect(x) should probably
64  *            be defined as (x == x->from) --msa ]
65  *
66  *    parc    number of variable parameter strings (if zero,
67  *            parv is allowed to be NULL)
68  *
69  *    parv    a NULL terminated list of parameter pointers,
70  *
71  *                    parv[0], sender (prefix string), if not present
72  *                            this points to an empty string.
73  *                    parv[1]...parv[parc-1]
74  *                            pointers to additional parameters
75  *                    parv[parc] == NULL, *always*
76  *
77  *            note:   it is guaranteed that parv[0]..parv[parc-1] are all
78  *                    non-NULL pointers.
79  */
80 #include "config.h"
81
82 #include "client.h"
83 #include "hash.h"
84 #include "ircd.h"
85 #include "ircd_log.h"
86 #include "ircd_reply.h"
87 #include "ircd_string.h"
88 #include "msg.h"
89 #include "numeric.h"
90 #include "numnicks.h"
91 #include "s_debug.h"
92 #include "s_misc.h"
93 #include "s_user.h"
94 #include "send.h"
95
96 #include <stdlib.h>
97 #include <string.h>
98
99 /** m_recover - Try to recover a disconnected Client (Zombie)
100  *
101  * parv[0] = sender prefix
102  * parv[1] = nick of the zombie to be recovered
103  */
104 int m_recover(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
105 {
106   struct Client *victim;
107
108   if (parc < 2)
109     return need_more_params(sptr, "RECOVER");
110
111   //check Auth
112   if(!IsAccount(sptr)) {
113     send_reply(sptr, ERR_NOTREGISTERED);
114     return 0;
115   }
116
117   if (!(victim = FindUser(parv[1]))) {
118     send_reply(sptr, ERR_NOSUCHNICK, parv[1]);
119     return 0;
120   }
121
122   if (!IsNotConn(victim)) {
123     send_reply(sptr, ERR_RECOVERDENIED, cli_name(victim), "not zombie");
124     return 0;
125   }
126   assert(IsAccount(victim));
127
128   const struct User* sptr_user = cli_user(sptr);
129   const struct User* victim_user = cli_user(victim);
130   if(ircd_strcmp(sptr_user->account, victim_user->account)) {
131     send_reply(sptr, ERR_RECOVERDENIED, cli_name(victim), "auth missmatch");
132     return 0;
133   }
134
135   unzombie_client(&me, &me, sptr, victim);
136   return 0;
137 }