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
24 * $Id: m_squit.c 3161 2007-01-25 07:23:01Z nenolod $
29 #include "common.h" /* FALSE bleah */
41 #include "s_newconf.h"
43 static int ms_squit(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
44 static int mo_squit(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
46 struct Message squit_msgtab
= {
47 "SQUIT", 0, 0, 0, MFLG_SLOW
,
48 {mg_unreg
, mg_not_oper
, {ms_squit
, 0}, {ms_squit
, 0}, mg_ignore
, {mo_squit
, 2}}
51 mapi_clist_av1 squit_clist
[] = { &squit_msgtab
, NULL
};
53 DECLARE_MODULE_AV1(squit
, NULL
, NULL
, squit_clist
, NULL
, NULL
, "$Revision: 3161 $");
57 const char *server_name
;
58 struct Client
*target_p
;
61 static struct squit_parms
*find_squit(struct Client
*client_p
,
62 struct Client
*source_p
, const char *server
);
66 * mo_squit - SQUIT message handler
67 * parv[1] = server name
71 mo_squit(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
73 struct squit_parms
*found_squit
;
74 const char *comment
= (parc
> 2 && parv
[2]) ? parv
[2] : client_p
->name
;
76 if((found_squit
= find_squit(client_p
, source_p
, parv
[1])))
78 if(MyConnect(found_squit
->target_p
))
80 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
81 "Received SQUIT %s from %s (%s)",
82 found_squit
->target_p
->name
,
83 get_client_name(source_p
, HIDE_IP
), comment
);
84 ilog(L_SERVER
, "Received SQUIT %s from %s (%s)",
85 found_squit
->target_p
->name
, log_client_name(source_p
, HIDE_IP
),
88 else if(!IsOperRemote(source_p
))
90 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
91 me
.name
, source_p
->name
, "remote");
95 exit_client(client_p
, found_squit
->target_p
, source_p
, comment
);
100 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
, form_str(ERR_NOSUCHSERVER
), parv
[1]);
107 * ms_squit - SQUIT message handler
108 * parv[1] = server name
112 ms_squit(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
114 struct Client
*target_p
;
115 const char *comment
= (parc
> 2 && parv
[2]) ? parv
[2] : client_p
->name
;
121 if((target_p
= find_server(NULL
, parv
[1])) == NULL
)
126 if(!IsServer(target_p
))
130 /* Server is closing its link */
131 if (target_p
== client_p
)
133 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Server %s closing link (%s)",
134 target_p
->name
, comment
);
137 ** Notify all opers, if my local link is remotely squitted
139 else if(MyConnect(target_p
))
141 sendto_wallops_flags(UMODE_WALLOP
, &me
,
142 "Remote SQUIT %s from %s (%s)",
143 target_p
->name
, source_p
->name
, comment
);
145 sendto_server(NULL
, NULL
, CAP_TS6
, NOCAPS
,
146 ":%s WALLOPS :Remote SQUIT %s from %s (%s)",
147 me
.id
, target_p
->name
, source_p
->name
, comment
);
149 ilog(L_SERVER
, "SQUIT From %s : %s (%s)", source_p
->name
, target_p
->name
, comment
);
151 exit_client(client_p
, target_p
, source_p
, comment
);
158 * inputs - local server connection
161 * output - pointer to struct containing found squit or none if not found
164 static struct squit_parms
*
165 find_squit(struct Client
*client_p
, struct Client
*source_p
, const char *server
)
167 static struct squit_parms found_squit
;
168 struct Client
*target_p
= NULL
;
172 /* must ALWAYS be reset */
173 found_squit
.target_p
= NULL
;
174 found_squit
.server_name
= NULL
;
178 ** The following allows wild cards in SQUIT. Only useful
179 ** when the command is issued by an oper.
182 RB_DLINK_FOREACH(ptr
, global_serv_list
.head
)
185 if(IsServer(p
) || IsMe(p
))
187 if(match(server
, p
->name
))
198 found_squit
.target_p
= target_p
;
199 found_squit
.server_name
= server
;
203 if(IsClient(client_p
))
205 if(MyClient(client_p
))
206 sendto_one_notice(source_p
, ":You are trying to squit me.");
212 found_squit
.target_p
= client_p
;
213 found_squit
.server_name
= client_p
->name
;
217 if(found_squit
.target_p
!= NULL
)