fixed ssl.c bug when ssl backend returns IO_BLOCKED but IO engine doesn't get informe...
[ircu2.10.12-pk.git] / ircd / m_squit.c
1 /*
2  * IRC - Internet Relay Chat, ircd/m_squit.c
3  * Copyright (C) 1990 Jarkko Oikarinen and
4  *                    University of Oulu, Computing Center
5  *
6  * See file AUTHORS in IRC package for additional names of
7  * the programmers.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 1, or (at your option)
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  * $Id: m_squit.c 1334 2005-03-20 16:06:30Z entrope $
24  */
25 #include "config.h"
26
27 #include "client.h"
28 #include "hash.h"
29 #include "ircd.h"
30 #include "ircd_chattr.h"
31 #include "ircd_log.h"
32 #include "ircd_reply.h"
33 #include "ircd_string.h"
34 #include "numeric.h"
35 #include "numnicks.h"
36 #include "match.h"
37 #include "s_debug.h"
38 #include "s_misc.h"
39 #include "s_user.h"
40 #include "send.h"
41
42 /* #include <assert.h> -- Now using assert in ircd_log.h */
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <string.h>
46
47 /*
48  *  ms_squit (server)
49  *
50  *    parv[0] = sender prefix
51  *    parv[1] = server name
52  *    parv[2] = timestamp
53  *    parv[parc-1] = comment
54  *
55  * No longer supports wildcards from servers. 
56  * No longer squits a server that gave us an malformed squit message.
57  *    - Isomer 1999-12-18
58  * 
59  */
60 int ms_squit(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
61 {
62   const char* server = parv[1];
63   struct Client *acptr;
64   time_t timestamp = 0;
65   char *comment = 0;
66   
67   if (parc < 2) 
68     return need_more_params(sptr, "SQUIT");
69
70   comment = parv[parc-1];
71   
72   if (BadPtr(parv[parc - 1]))
73         comment = cli_name(sptr);
74         
75   acptr = FindServer(server);
76
77   if (!acptr)
78     acptr = FindNServer(server);
79   
80   if (!acptr) {
81     Debug((DEBUG_NOTICE, "Ignoring SQUIT to an unknown server"));
82     return 0;
83   }
84   
85   if (IsMaster(acptr)) {
86         return 0;
87   }
88   /* If they are squitting me, we reverse it */
89   if (IsMe(acptr))
90     acptr = cptr; /* Bugfix by Prefect */
91
92   if (parc > 2)
93     timestamp = atoi(parv[2]);
94   else
95     protocol_violation(cptr, "SQUIT with no timestamp/reason");
96
97   /* If atoi(parv[2]) == 0 we must indeed squit !
98    * It will be our neighbour.
99    */
100   if ( timestamp != 0 && timestamp != cli_serv(acptr)->timestamp)
101   {
102     Debug((DEBUG_NOTICE, "Ignoring SQUIT with the wrong timestamp"));
103     return 0;
104   }
105   
106   return exit_client(cptr, acptr, sptr, comment);
107 }
108
109 /*
110  *  mo_squit (oper)
111  *
112  *    parv[0] = sender prefix
113  *    parv[1] = server name
114  *    parv[2] = comment (optional)
115  *
116  */
117 int mo_squit(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
118 {
119   const char* server;
120   struct Client *acptr;
121   struct Client *acptr2;
122   char *comment;
123       
124   if (parc < 2) 
125     return need_more_params(sptr, "SQUIT");
126
127   if (parc < 3 || BadPtr(parv[2]))
128     comment = cli_name(sptr);
129   else
130     comment = parv[2];
131
132   server = parv[1];
133   /*
134    * The following allows wild cards in SQUIT. Only useful
135    * when the command is issued by an oper.
136    */
137   for (acptr = GlobalClientList; (acptr = next_client(acptr, server));
138       acptr = cli_next(acptr)) {
139     if (IsServer(acptr) || IsMe(acptr))
140       break;
141   }
142   
143   /* Not found? Bugger. */
144   if (!acptr || IsMe(acptr))
145     return send_reply(sptr, ERR_NOSUCHSERVER, server);
146
147   /*
148    * Look for a matching server that is closer,
149    * that way we won't accidentally squit two close
150    * servers like davis.* and davis-r.* when typing
151    * /SQUIT davis*
152    */
153   for (acptr2 = cli_serv(acptr)->up; acptr2 != &me;
154       acptr2 = cli_serv(acptr2)->up)
155     if (!match(server, cli_name(acptr2)))
156       acptr = acptr2;
157   
158   /* Disallow local opers to squit remote servers */
159   
160   if ((IsLocOp(sptr) && !MyConnect(acptr)) || IsMaster(acptr))
161     return send_reply(sptr, ERR_NOPRIVILEGES);
162
163   return exit_client(cptr, acptr, sptr, comment);
164 }