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: 5346
Committed: Sun Jan 11 12:41:14 2015 UTC (9 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 6443 byte(s)
Log Message:
- Update copyright years

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 5346 * Copyright (c) 1997-2015 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 michael 4598 /*! \brief SQUIT command handler
43     *
44     * \param source_p Pointer to allocated Client struct from which the message
45     * originally comes from. This can be a local or remote client.
46     * \param parc Integer holding the number of supplied arguments.
47     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
48     * pointers.
49     * \note Valid arguments for this command are:
50     * - parv[0] = command
51     * - parv[1] = server name
52     * - parv[2] = comment
53 adx 30 */
54 michael 2820 static int
55 michael 3156 mo_squit(struct Client *source_p, int parc, char *parv[])
56 adx 30 {
57 michael 3904 char comment[REASONLEN + 1] = "";
58 adx 30 struct Client *target_p = NULL;
59 michael 4816 dlink_node *node = NULL;
60 michael 4771 const char *server = parv[1];
61 adx 30
62     if (parc < 2 || EmptyString(parv[1]))
63     {
64 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "SQUIT");
65 michael 2820 return 0;
66 adx 30 }
67    
68 michael 4771 /* The following allows wild cards in SQUIT. */
69 michael 4816 DLINK_FOREACH(node, global_server_list.head)
70 adx 30 {
71 michael 4816 struct Client *p = node->data;
72 adx 30
73     if (IsServer(p) || IsMe(p))
74     {
75 michael 1652 if (!match(server, p->name))
76 adx 30 {
77     target_p = p;
78     break;
79     }
80     }
81     }
82    
83 michael 4771 if (!target_p || IsMe(target_p))
84 adx 30 {
85 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOSUCHSERVER, server);
86 michael 2820 return 0;
87 adx 30 }
88    
89 michael 2801 if (!MyConnect(target_p) && !HasOFlag(source_p, OPER_FLAG_SQUIT_REMOTE))
90 adx 30 {
91 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "squit:remote");
92 michael 2820 return 0;
93 adx 30 }
94    
95 michael 2801 if (MyConnect(target_p) && !HasOFlag(source_p, OPER_FLAG_SQUIT))
96     {
97 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "squit");
98 michael 2820 return 0;
99 michael 2801 }
100    
101 michael 3904 if (!EmptyString(parv[2]))
102     strlcpy(comment, parv[2], sizeof(comment));
103     else
104     strlcpy(comment, CONF_NOREASON, sizeof(comment));
105 adx 30
106     if (MyConnect(target_p))
107     {
108 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
109     "Received SQUIT %s from %s (%s)",
110 adx 30 target_p->name, get_client_name(source_p, HIDE_IP), comment);
111 michael 1247 ilog(LOG_TYPE_IRCD, "Received SQUIT %s from %s (%s)",
112 adx 30 target_p->name, get_client_name(source_p, HIDE_IP), comment);
113 michael 3171
114     /* To them, we are exiting */
115 michael 3186 sendto_one(target_p, ":%s SQUIT %s :%s", source_p->id, me.id, comment);
116 michael 4771
117 michael 3171 /* Send to everything but target */
118 michael 4963 sendto_server(target_p, 0, 0, ":%s SQUIT %s :%s",
119 michael 3186 source_p->id, target_p->id, comment);
120 adx 30 }
121 michael 3171 else
122     /* Send to everything */
123 michael 4963 sendto_server(NULL, 0, 0, ":%s SQUIT %s :%s",
124 michael 3186 source_p->id, target_p->id, comment);
125 adx 30
126 michael 3171 AddFlag(target_p, FLAGS_SQUIT);
127    
128     exit_client(target_p, comment);
129 michael 2820 return 0;
130 adx 30 }
131    
132 michael 4598 /*! \brief SQUIT command handler
133     *
134     * \param source_p Pointer to allocated Client struct from which the message
135     * originally comes from. This can be a local or remote client.
136     * \param parc Integer holding the number of supplied arguments.
137     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
138     * pointers.
139     * \note Valid arguments for this command are:
140     * - parv[0] = command
141     * - parv[1] = server name
142     * - parv[2] = comment
143 adx 30 */
144 michael 2820 static int
145 michael 3156 ms_squit(struct Client *source_p, int parc, char *parv[])
146 adx 30 {
147     struct Client *target_p = NULL;
148 michael 1572 const char *comment = NULL;
149 michael 4816 dlink_node *node = NULL;
150 adx 30
151 michael 4768 if (parc < 2 || EmptyString(parv[1]))
152 michael 2820 return 0;
153 adx 30
154 michael 1572 if ((target_p = hash_find_server(parv[1])) == NULL)
155 michael 2820 return 0;
156 adx 30
157 michael 1572 if (!IsServer(target_p) && !IsMe(target_p))
158 michael 2820 return 0;
159 adx 30
160 michael 1572 if (IsMe(target_p))
161 michael 3156 target_p = source_p->from;
162 adx 30
163 michael 3156 comment = (parc > 2 && parv[parc - 1]) ? parv[parc - 1] : source_p->name;
164 adx 30
165     if (MyConnect(target_p))
166     {
167 michael 3850 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_GLOBAL, "from %s: Remote SQUIT %s from %s (%s)",
168     me.name, target_p->name, source_p->name, comment);
169 michael 4963 sendto_server(source_p, 0, 0, ":%s GLOBOPS :Remote SQUIT %s from %s (%s)",
170 adx 30 me.id, target_p->name, source_p->name, comment);
171 michael 1247 ilog(LOG_TYPE_IRCD, "SQUIT From %s : %s (%s)", source_p->name,
172 adx 30 target_p->name, comment);
173 michael 3171
174     /* To them, we are exiting */
175 michael 3186 sendto_one(target_p, ":%s SQUIT %s :%s", source_p->id, me.id, comment);
176 michael 3171
177     /* Send to everything but target and source */
178 michael 4816 DLINK_FOREACH(node, local_server_list.head)
179 michael 3171 {
180 michael 4816 struct Client *client_p = node->data;
181 michael 3171
182     if (client_p == target_p || client_p == source_p->from)
183     continue;
184    
185     sendto_one(client_p, ":%s SQUIT %s :%s",
186 michael 3186 source_p->id, target_p->id, comment);
187 michael 3171 }
188 michael 2820 }
189 michael 3171 else
190     /* Send to everything but source */
191 michael 4963 sendto_server(source_p, 0, 0, ":%s SQUIT %s :%s",
192 michael 3186 source_p->id, target_p->id, comment);
193 adx 30
194 michael 3171 AddFlag(target_p, FLAGS_SQUIT);
195    
196     exit_client(target_p, comment);
197 michael 2820 return 0;
198 adx 30 }
199 michael 1230
200 michael 2820 static struct Message squit_msgtab =
201     {
202 michael 4546 "SQUIT", NULL, 0, 0, 1, MAXPARA, MFLG_SLOW, 0,
203 michael 2820 { m_unregistered, m_not_oper, ms_squit, m_ignore, mo_squit, m_ignore }
204 michael 1230 };
205    
206     static void
207     module_init(void)
208     {
209     mod_add_cmd(&squit_msgtab);
210     }
211    
212     static void
213     module_exit(void)
214     {
215     mod_del_cmd(&squit_msgtab);
216     }
217    
218 michael 2820 struct module module_entry =
219     {
220 michael 1230 .node = { NULL, NULL, NULL },
221     .name = NULL,
222     .version = "$Revision$",
223     .handle = NULL,
224     .modinit = module_init,
225     .modexit = module_exit,
226     .flags = MODULE_FLAG_CORE
227     };

Properties

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