]> jfr.im git - irc/quakenet/snircd.git/blame - ircd/m_squit.c
Should be unsigned long for A
[irc/quakenet/snircd.git] / ircd / m_squit.c
CommitLineData
189935b1 1/*
2 * IRC - Internet Relay Chat, ircd/m_squit.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
5 *
6 * See file AUTHORS in IRC package for additional names of
7 * the programmers.
8 *
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 1, or (at your option)
12 * any later version.
13 *
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.
18 *
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., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 * $Id: m_squit.c,v 1.12 2005/03/20 16:06:24 entrope Exp $
24 */
25#include "config.h"
26
27#include "client.h"
28#include "hash.h"
29#include "ircd.h"
30#include "ircd_chattr.h"
31#include "ircd_log.h"
32#include "ircd_reply.h"
33#include "ircd_string.h"
34#include "numeric.h"
35#include "numnicks.h"
36#include "match.h"
37#include "s_debug.h"
38#include "s_misc.h"
39#include "s_user.h"
40#include "send.h"
41
42/* #include <assert.h> -- Now using assert in ircd_log.h */
43#include <stdio.h>
44#include <stdlib.h>
45#include <string.h>
46
47/*
48 * ms_squit (server)
49 *
50 * parv[0] = sender prefix
51 * parv[1] = server name
52 * parv[2] = timestamp
53 * parv[parc-1] = comment
54 *
55 * No longer supports wildcards from servers.
56 * No longer squits a server that gave us an malformed squit message.
57 * - Isomer 1999-12-18
58 *
59 */
60int ms_squit(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
61{
62 const char* server = parv[1];
63 struct Client *acptr;
64 time_t timestamp = 0;
65 char *comment = 0;
66
67 if (parc < 2)
68 return need_more_params(sptr, "SQUIT");
69
70 comment = parv[parc-1];
71
72 if (BadPtr(parv[parc - 1]))
73 comment = cli_name(sptr);
74
75 acptr = FindServer(server);
76
77 if (!acptr)
78 acptr = FindNServer(server);
79
80 if (!acptr) {
81 Debug((DEBUG_NOTICE, "Ignoring SQUIT to an unknown server"));
82 return 0;
83 }
84
85 /* If they are squitting me, we reverse it */
86 if (IsMe(acptr))
87 acptr = cptr; /* Bugfix by Prefect */
88
89 if (parc > 2)
90 timestamp = atoi(parv[2]);
91 else
92 protocol_violation(cptr, "SQUIT with no timestamp/reason");
93
94 /* If atoi(parv[2]) == 0 we must indeed squit !
95 * It will be our neighbour.
96 */
97 if ( timestamp != 0 && timestamp != cli_serv(acptr)->timestamp)
98 {
99 Debug((DEBUG_NOTICE, "Ignoring SQUIT with the wrong timestamp"));
100 return 0;
101 }
102
103 return exit_client(cptr, acptr, sptr, comment);
104}
105
106/*
107 * mo_squit (oper)
108 *
109 * parv[0] = sender prefix
110 * parv[1] = server name
111 * parv[2] = comment (optional)
112 *
113 */
114int mo_squit(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
115{
116 const char* server;
117 struct Client *acptr;
118 struct Client *acptr2;
119 char *comment;
120
121 if (parc < 2)
122 return need_more_params(sptr, "SQUIT");
123
124 if (parc < 3 || BadPtr(parv[2]))
125 comment = cli_name(sptr);
126 else
127 comment = parv[2];
128
129 server = parv[1];
130 /*
131 * The following allows wild cards in SQUIT. Only useful
132 * when the command is issued by an oper.
133 */
134 for (acptr = GlobalClientList; (acptr = next_client(acptr, server));
135 acptr = cli_next(acptr)) {
136 if (IsServer(acptr) || IsMe(acptr))
137 break;
138 }
139
140 /* Not found? Bugger. */
141 if (!acptr || IsMe(acptr))
142 return send_reply(sptr, ERR_NOSUCHSERVER, server);
143
144 /*
145 * Look for a matching server that is closer,
146 * that way we won't accidentally squit two close
147 * servers like davis.* and davis-r.* when typing
148 * /SQUIT davis*
149 */
150 for (acptr2 = cli_serv(acptr)->up; acptr2 != &me;
151 acptr2 = cli_serv(acptr2)->up)
152 if (!match(server, cli_name(acptr2)))
153 acptr = acptr2;
154
155 /* Disallow local opers to squit remote servers */
156 if (IsLocOp(sptr) && !MyConnect(acptr))
157 return send_reply(sptr, ERR_NOPRIVILEGES);
158
159 return exit_client(cptr, acptr, sptr, comment);
160}