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: 4564
Committed: Sun Aug 24 10:24:47 2014 UTC (9 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 5905 byte(s)
Log Message:
- Update GPL 2 license headers

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 2820 * Copyright (c) 1997-2014 ircd-hybrid development team
5 adx 30 *
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 michael 4564 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2820 /*! \file m_squit.c
23     * \brief Includes required functions for processing the SQUIT command.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1011 #include "list.h"
29 adx 30 #include "client.h"
30     #include "hash.h"
31     #include "irc_string.h"
32     #include "ircd.h"
33     #include "numeric.h"
34 michael 1309 #include "conf.h"
35     #include "log.h"
36 michael 3347 #include "server.h"
37 adx 30 #include "send.h"
38     #include "parse.h"
39     #include "modules.h"
40    
41    
42     /* mo_squit - SQUIT message handler
43 michael 3096 * parv[0] = command
44 adx 30 * parv[1] = server name
45     * parv[2] = comment
46     */
47 michael 2820 static int
48 michael 3156 mo_squit(struct Client *source_p, int parc, char *parv[])
49 adx 30 {
50 michael 3904 char comment[REASONLEN + 1] = "";
51 adx 30 struct Client *target_p = NULL;
52     struct Client *p;
53     dlink_node *ptr;
54     const char *server;
55    
56     if (parc < 2 || EmptyString(parv[1]))
57     {
58 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "SQUIT");
59 michael 2820 return 0;
60 adx 30 }
61    
62     server = parv[1];
63    
64     /* The following allows wild cards in SQUIT. Only
65     * useful when the command is issued by an oper.
66     */
67 michael 4208 DLINK_FOREACH(ptr, global_server_list.head)
68 adx 30 {
69     p = ptr->data;
70    
71     if (IsServer(p) || IsMe(p))
72     {
73 michael 1652 if (!match(server, p->name))
74 adx 30 {
75     target_p = p;
76     break;
77     }
78     }
79     }
80    
81     if ((target_p == NULL) || IsMe(target_p))
82     {
83 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOSUCHSERVER, server);
84 michael 2820 return 0;
85 adx 30 }
86    
87 michael 2801 if (!MyConnect(target_p) && !HasOFlag(source_p, OPER_FLAG_SQUIT_REMOTE))
88 adx 30 {
89 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "squit:remote");
90 michael 2820 return 0;
91 adx 30 }
92    
93 michael 2801 if (MyConnect(target_p) && !HasOFlag(source_p, OPER_FLAG_SQUIT))
94     {
95 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "squit");
96 michael 2820 return 0;
97 michael 2801 }
98    
99 michael 3904 if (!EmptyString(parv[2]))
100     strlcpy(comment, parv[2], sizeof(comment));
101     else
102     strlcpy(comment, CONF_NOREASON, sizeof(comment));
103 adx 30
104     if (MyConnect(target_p))
105     {
106 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
107     "Received SQUIT %s from %s (%s)",
108 adx 30 target_p->name, get_client_name(source_p, HIDE_IP), comment);
109 michael 1247 ilog(LOG_TYPE_IRCD, "Received SQUIT %s from %s (%s)",
110 adx 30 target_p->name, get_client_name(source_p, HIDE_IP), comment);
111 michael 3171
112     /* To them, we are exiting */
113 michael 3186 sendto_one(target_p, ":%s SQUIT %s :%s", source_p->id, me.id, comment);
114 michael 3171 /* Send to everything but target */
115     sendto_server(target_p, NOCAPS, NOCAPS, ":%s SQUIT %s :%s",
116 michael 3186 source_p->id, target_p->id, comment);
117 adx 30 }
118 michael 3171 else
119     /* Send to everything */
120     sendto_server(NULL, NOCAPS, NOCAPS, ":%s SQUIT %s :%s",
121 michael 3186 source_p->id, target_p->id, comment);
122 adx 30
123 michael 3171 AddFlag(target_p, FLAGS_SQUIT);
124    
125     exit_client(target_p, comment);
126 michael 2820 return 0;
127 adx 30 }
128    
129     /** NOTE: I removed wildcard lookups here, because a wildcarded
130     ** SQUIT should/can never happen in ms_squit. -Michael
131     **/
132    
133     /* ms_squit - SQUIT message handler
134 michael 3096 * parv[0] = command
135 adx 30 * parv[1] = server name
136     * parv[2] = comment
137     */
138 michael 2820 static int
139 michael 3156 ms_squit(struct Client *source_p, int parc, char *parv[])
140 adx 30 {
141     struct Client *target_p = NULL;
142 michael 1572 const char *comment = NULL;
143 michael 3171 dlink_node *ptr;
144 adx 30
145 michael 1572 if (parc < 2 || EmptyString(parv[parc - 1]))
146 michael 2820 return 0;
147 adx 30
148 michael 1572 if ((target_p = hash_find_server(parv[1])) == NULL)
149 michael 2820 return 0;
150 adx 30
151 michael 1572 if (!IsServer(target_p) && !IsMe(target_p))
152 michael 2820 return 0;
153 adx 30
154 michael 1572 if (IsMe(target_p))
155 michael 3156 target_p = source_p->from;
156 adx 30
157 michael 3156 comment = (parc > 2 && parv[parc - 1]) ? parv[parc - 1] : source_p->name;
158 adx 30
159     if (MyConnect(target_p))
160     {
161 michael 3850 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_GLOBAL, "from %s: Remote SQUIT %s from %s (%s)",
162     me.name, target_p->name, source_p->name, comment);
163 michael 3156 sendto_server(source_p, NOCAPS, NOCAPS,
164 michael 3808 ":%s GLOBOPS :Remote SQUIT %s from %s (%s)",
165 adx 30 me.id, target_p->name, source_p->name, comment);
166 michael 1247 ilog(LOG_TYPE_IRCD, "SQUIT From %s : %s (%s)", source_p->name,
167 adx 30 target_p->name, comment);
168 michael 3171
169     /* To them, we are exiting */
170 michael 3186 sendto_one(target_p, ":%s SQUIT %s :%s", source_p->id, me.id, comment);
171 michael 3171
172     /* Send to everything but target and source */
173 michael 4212 DLINK_FOREACH(ptr, local_server_list.head)
174 michael 3171 {
175     struct Client *client_p = ptr->data;
176    
177     if (client_p == target_p || client_p == source_p->from)
178     continue;
179    
180     sendto_one(client_p, ":%s SQUIT %s :%s",
181 michael 3186 source_p->id, target_p->id, comment);
182 michael 3171 }
183 michael 2820 }
184 michael 3171 else
185     /* Send to everything but source */
186     sendto_server(source_p, NOCAPS, NOCAPS, ":%s SQUIT %s :%s",
187 michael 3186 source_p->id, target_p->id, comment);
188 adx 30
189 michael 3171 AddFlag(target_p, FLAGS_SQUIT);
190    
191     exit_client(target_p, comment);
192 michael 2820 return 0;
193 adx 30 }
194 michael 1230
195 michael 2820 static struct Message squit_msgtab =
196     {
197 michael 4546 "SQUIT", NULL, 0, 0, 1, MAXPARA, MFLG_SLOW, 0,
198 michael 2820 { m_unregistered, m_not_oper, ms_squit, m_ignore, mo_squit, m_ignore }
199 michael 1230 };
200    
201     static void
202     module_init(void)
203     {
204     mod_add_cmd(&squit_msgtab);
205     }
206    
207     static void
208     module_exit(void)
209     {
210     mod_del_cmd(&squit_msgtab);
211     }
212    
213 michael 2820 struct module module_entry =
214     {
215 michael 1230 .node = { NULL, NULL, NULL },
216     .name = NULL,
217     .version = "$Revision$",
218     .handle = NULL,
219     .modinit = module_init,
220     .modexit = module_exit,
221     .flags = MODULE_FLAG_CORE
222     };

Properties

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