ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/core/m_squit.c
Revision: 3171
Committed: Sun Mar 16 11:51:48 2014 UTC (10 years, 1 month ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/modules/core/m_squit.c
File size: 5872 byte(s)
Log Message:
- Incorporate Adam's exit_client/quit storm cleanups
  Note: QS is mandatory now

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2014 ircd-hybrid development team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
20 */
21
22 /*! \file m_squit.c
23 * \brief Includes required functions for processing the SQUIT command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "client.h"
30 #include "hash.h"
31 #include "irc_string.h"
32 #include "ircd.h"
33 #include "numeric.h"
34 #include "conf.h"
35 #include "log.h"
36 #include "s_serv.h"
37 #include "send.h"
38 #include "parse.h"
39 #include "modules.h"
40
41
42 /* mo_squit - SQUIT message handler
43 * parv[0] = command
44 * parv[1] = server name
45 * parv[2] = comment
46 */
47 static int
48 mo_squit(struct Client *source_p, int parc, char *parv[])
49 {
50 struct Client *target_p = NULL;
51 struct Client *p;
52 dlink_node *ptr;
53 char *comment;
54 const char *server;
55 char def_reason[] = CONF_NOREASON;
56
57 if (parc < 2 || EmptyString(parv[1]))
58 {
59 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "SQUIT");
60 return 0;
61 }
62
63 server = parv[1];
64
65 /* The following allows wild cards in SQUIT. Only
66 * useful when the command is issued by an oper.
67 */
68 DLINK_FOREACH(ptr, global_serv_list.head)
69 {
70 p = ptr->data;
71
72 if (IsServer(p) || IsMe(p))
73 {
74 if (!match(server, p->name))
75 {
76 target_p = p;
77 break;
78 }
79 }
80 }
81
82 if ((target_p == NULL) || IsMe(target_p))
83 {
84 sendto_one_numeric(source_p, &me, ERR_NOSUCHSERVER, server);
85 return 0;
86 }
87
88 if (!MyConnect(target_p) && !HasOFlag(source_p, OPER_FLAG_SQUIT_REMOTE))
89 {
90 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "squit:remote");
91 return 0;
92 }
93
94 if (MyConnect(target_p) && !HasOFlag(source_p, OPER_FLAG_SQUIT))
95 {
96 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "squit");
97 return 0;
98 }
99
100 comment = (parc > 2 && parv[2]) ? parv[2] : def_reason;
101
102 if (strlen(comment) > (size_t)REASONLEN)
103 comment[REASONLEN] = '\0';
104
105 if (MyConnect(target_p))
106 {
107 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
108 "Received SQUIT %s from %s (%s)",
109 target_p->name, get_client_name(source_p, HIDE_IP), comment);
110 ilog(LOG_TYPE_IRCD, "Received SQUIT %s from %s (%s)",
111 target_p->name, get_client_name(source_p, HIDE_IP), comment);
112
113 /* To them, we are exiting */
114 sendto_one(target_p, ":%s SQUIT %s :%s", ID(source_p), ID(&me), comment);
115 /* Send to everything but target */
116 sendto_server(target_p, NOCAPS, NOCAPS, ":%s SQUIT %s :%s",
117 ID(source_p), ID(target_p), comment);
118 }
119 else
120 /* Send to everything */
121 sendto_server(NULL, NOCAPS, NOCAPS, ":%s SQUIT %s :%s",
122 ID(source_p), ID(target_p), comment);
123
124 AddFlag(target_p, FLAGS_SQUIT);
125
126 exit_client(target_p, comment);
127 return 0;
128 }
129
130 /** NOTE: I removed wildcard lookups here, because a wildcarded
131 ** SQUIT should/can never happen in ms_squit. -Michael
132 **/
133
134 /* ms_squit - SQUIT message handler
135 * parv[0] = command
136 * parv[1] = server name
137 * parv[2] = comment
138 */
139 static int
140 ms_squit(struct Client *source_p, int parc, char *parv[])
141 {
142 struct Client *target_p = NULL;
143 const char *comment = NULL;
144 dlink_node *ptr;
145
146 if (parc < 2 || EmptyString(parv[parc - 1]))
147 return 0;
148
149 if ((target_p = hash_find_server(parv[1])) == NULL)
150 return 0;
151
152 if (!IsServer(target_p) && !IsMe(target_p))
153 return 0;
154
155 if (IsMe(target_p))
156 target_p = source_p->from;
157
158 comment = (parc > 2 && parv[parc - 1]) ? parv[parc - 1] : source_p->name;
159
160 if (MyConnect(target_p))
161 {
162 sendto_wallops_flags(UMODE_WALLOP, &me, "Remote SQUIT %s from %s (%s)",
163 target_p->name, source_p->name, comment);
164 sendto_server(source_p, NOCAPS, NOCAPS,
165 ":%s WALLOPS :Remote SQUIT %s from %s (%s)",
166 me.id, target_p->name, source_p->name, comment);
167 ilog(LOG_TYPE_IRCD, "SQUIT From %s : %s (%s)", source_p->name,
168 target_p->name, comment);
169
170 /* To them, we are exiting */
171 sendto_one(target_p, ":%s SQUIT %s :%s", ID(source_p), ID(&me), comment);
172
173 /* Send to everything but target and source */
174 DLINK_FOREACH(ptr, serv_list.head)
175 {
176 struct Client *client_p = ptr->data;
177
178 if (client_p == target_p || client_p == source_p->from)
179 continue;
180
181 sendto_one(client_p, ":%s SQUIT %s :%s",
182 ID(source_p), ID(target_p), comment);
183 }
184 }
185 else
186 /* Send to everything but source */
187 sendto_server(source_p, NOCAPS, NOCAPS, ":%s SQUIT %s :%s",
188 ID(source_p), ID(target_p), comment);
189
190 AddFlag(target_p, FLAGS_SQUIT);
191
192 exit_client(target_p, comment);
193 return 0;
194 }
195
196 static struct Message squit_msgtab =
197 {
198 "SQUIT", 0, 0, 1, MAXPARA, MFLG_SLOW, 0,
199 { m_unregistered, m_not_oper, ms_squit, m_ignore, mo_squit, m_ignore }
200 };
201
202 static void
203 module_init(void)
204 {
205 mod_add_cmd(&squit_msgtab);
206 }
207
208 static void
209 module_exit(void)
210 {
211 mod_del_cmd(&squit_msgtab);
212 }
213
214 struct module module_entry =
215 {
216 .node = { NULL, NULL, NULL },
217 .name = NULL,
218 .version = "$Revision$",
219 .handle = NULL,
220 .modinit = module_init,
221 .modexit = module_exit,
222 .flags = MODULE_FLAG_CORE
223 };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision