More RCS keyword removal...
[seven-1.x.git] / modules / core / m_squit.c
blob9cb6a94d4a06ff6078ca3ec11b2853f404061a85
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_squit.c: Makes a server quit.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
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 2 of the License, or
12 * (at your option) any later version.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
25 #include "stdinc.h"
26 #include "client.h"
27 #include "common.h" /* FALSE bleah */
28 #include "irc_string.h"
29 #include "ircd.h"
30 #include "numeric.h"
31 #include "s_conf.h"
32 #include "s_log.h"
33 #include "s_serv.h"
34 #include "send.h"
35 #include "msg.h"
36 #include "parse.h"
37 #include "modules.h"
38 #include "hash.h"
39 #include "s_newconf.h"
41 static int ms_squit(struct Client *, struct Client *, int, const char **);
42 static int mo_squit(struct Client *, struct Client *, int, const char **);
44 static struct Message squit_msgtab = {
45 "SQUIT", 0, 0, 0, MFLG_SLOW,
46 {mg_unreg, mg_not_oper, {ms_squit, 0}, {ms_squit, 0}, mg_ignore, {mo_squit, 2}}
49 mapi_clist_av1 squit_clist[] = { &squit_msgtab, NULL };
51 DECLARE_MODULE_AV1(squit, NULL, NULL, squit_clist, NULL, NULL, "$Revision: 108 $");
53 struct squit_parms
55 const char *server_name;
56 struct Client *target_p;
59 static struct squit_parms *find_squit(struct Client *client_p,
60 struct Client *source_p, const char *server);
64 * mo_squit - SQUIT message handler
65 * parv[0] = sender prefix
66 * parv[1] = server name
67 * parv[2] = comment
69 static int
70 mo_squit(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
72 struct squit_parms *found_squit;
73 const char *comment = (parc > 2 && parv[2]) ? parv[2] : client_p->name;
75 if(!IsOperRouting(source_p))
77 sendto_one(source_p, form_str(ERR_NOPRIVS),
78 me.name, source_p->name, "routing");
79 return 0;
82 if((found_squit = find_squit(client_p, source_p, parv[1])))
84 if(MyConnect(found_squit->target_p))
86 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
87 "Received SQUIT %s from %s (%s)",
88 found_squit->target_p->name,
89 get_client_name(source_p, HIDE_IP), comment);
90 ilog(L_SERVER, "Received SQUIT %s from %s (%s)",
91 found_squit->target_p->name, log_client_name(source_p, HIDE_IP),
92 comment);
95 exit_client(client_p, found_squit->target_p, source_p, comment);
96 return 0;
98 else
100 sendto_one_numeric(source_p, ERR_NOSUCHSERVER, form_str(ERR_NOSUCHSERVER), parv[1]);
103 return 0;
107 * ms_squit - SQUIT message handler
108 * parv[0] = sender prefix
109 * parv[1] = server name
110 * parv[2] = comment
112 static int
113 ms_squit(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
115 struct Client *target_p;
116 const char *comment = (parc > 2 && parv[2]) ? parv[2] : client_p->name;
118 if(parc < 2)
119 target_p = client_p;
120 else
122 if((target_p = find_server(NULL, parv[1])) == NULL)
123 return 0;
125 if(IsMe(target_p))
126 target_p = client_p;
127 if(!IsServer(target_p))
128 return 0;
131 /* Server is closing its link */
132 if (target_p == client_p)
134 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "Server %s closing link (%s)",
135 target_p->name, comment);
138 ** Notify all opers, if my local link is remotely squitted
140 else if(MyConnect(target_p))
142 sendto_wallops_flags(UMODE_WALLOP, &me,
143 "Remote SQUIT %s from %s (%s)",
144 target_p->name, source_p->name, comment);
146 sendto_server(NULL, NULL, CAP_TS6, NOCAPS,
147 ":%s WALLOPS :Remote SQUIT %s from %s (%s)",
148 me.id, target_p->name, source_p->name, comment);
150 sendto_server(NULL, NULL, NOCAPS, CAP_TS6,
151 ":%s WALLOPS :Remote SQUIT %s from %s (%s)",
152 me.name, target_p->name, source_p->name, comment);
154 ilog(L_SERVER, "SQUIT From %s : %s (%s)", parv[0], target_p->name, comment);
157 exit_client(client_p, target_p, source_p, comment);
158 return 0;
163 * find_squit
164 * inputs - local server connection
167 * output - pointer to struct containing found squit or none if not found
168 * side effects -
170 static struct squit_parms *
171 find_squit(struct Client *client_p, struct Client *source_p, const char *server)
173 static struct squit_parms found_squit;
174 struct Client *target_p = NULL;
175 struct Client *p;
176 dlink_node *ptr;
178 /* must ALWAYS be reset */
179 found_squit.target_p = NULL;
180 found_squit.server_name = NULL;
184 ** The following allows wild cards in SQUIT. Only useful
185 ** when the command is issued by an oper.
188 DLINK_FOREACH(ptr, global_serv_list.head)
190 p = ptr->data;
191 if(IsServer(p) || IsMe(p))
193 if(match(server, p->name))
195 target_p = p;
196 break;
201 if(target_p == NULL)
202 return NULL;
204 found_squit.target_p = target_p;
205 found_squit.server_name = server;
207 if(IsMe(target_p))
209 if(IsClient(client_p))
211 if(MyClient(client_p))
212 sendto_one(source_p, ":%s NOTICE %s :You are trying to squit me.",
213 me.name, client_p->name);
214 return NULL;
216 else
218 found_squit.target_p = client_p;
219 found_squit.server_name = client_p->name;
223 if(found_squit.target_p != NULL)
224 return &found_squit;
225 else
226 return (NULL);