]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_testmask.c
Filter bogus CTCP ACTION messages.
[irc/rqf/shadowircd.git] / modules / m_testmask.c
CommitLineData
212380e3 1/*
2 * m_testmask.c: Shows the number of matching local and global clients
d5a432fa 3 * for a user@host mask
212380e3 4 *
5 * Copyright (C) 2003 by W. Campbell
6 * Coypright (C) 2004 ircd-ratbox development team
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * 1.Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 * 2.Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3.The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
24 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 *
212380e3 32 *
33 */
34
35/* List of ircd includes from ../include/ */
36#include "stdinc.h"
37#include "client.h"
38#include "common.h" /* FALSE bleah */
39#include "ircd.h"
13ae2f4b 40#include "match.h"
212380e3 41#include "numeric.h"
42#include "s_conf.h"
d3455e2c 43#include "logger.h"
212380e3 44#include "s_serv.h"
45#include "send.h"
46#include "msg.h"
47#include "parse.h"
48#include "modules.h"
49
50static int mo_testmask(struct Client *client_p, struct Client *source_p,
51 int parc, const char *parv[]);
52
53struct Message testmask_msgtab = {
54 "TESTMASK", 0, 0, 0, MFLG_SLOW,
55 {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_testmask, 2}}
56};
57
58mapi_clist_av1 testmask_clist[] = { &testmask_msgtab, NULL };
5366977b 59DECLARE_MODULE_AV1(testmask, NULL, NULL, testmask_clist, NULL, NULL, "$Revision: 3161 $");
212380e3 60
61static const char *empty_sockhost = "255.255.255.255";
62static const char *spoofed_sockhost = "0";
63
64static int
65mo_testmask(struct Client *client_p, struct Client *source_p,
66 int parc, const char *parv[])
67{
68 struct Client *target_p;
69 int lcount = 0;
70 int gcount = 0;
71 char *name, *username, *hostname;
72 const char *sockhost;
eb5e3f15 73 char *gecos = NULL;
08d11e34 74 rb_dlink_node *ptr;
212380e3 75
76 name = LOCAL_COPY(parv[1]);
77 collapse(name);
78
79 /* username is required */
80 if((hostname = strchr(name, '@')) == NULL)
81 {
5366977b 82 sendto_one_notice(source_p, ":Invalid parameters");
212380e3 83 return 0;
84 }
85
86 *hostname++ = '\0';
87
88 /* nickname is optional */
89 if((username = strchr(name, '!')) == NULL)
90 {
91 username = name;
92 name = NULL;
93 }
94 else
95 *username++ = '\0';
96
97 if(EmptyString(username) || EmptyString(hostname))
98 {
5366977b 99 sendto_one_notice(source_p, ":Invalid parameters");
212380e3 100 return 0;
101 }
102
103 if(parc > 2 && !EmptyString(parv[2]))
104 {
105 gecos = LOCAL_COPY(parv[2]);
106 collapse_esc(gecos);
212380e3 107 }
108
08d11e34 109 RB_DLINK_FOREACH(ptr, global_client_list.head)
212380e3 110 {
111 target_p = ptr->data;
112
113 if(!IsPerson(target_p))
114 continue;
115
116 if(EmptyString(target_p->sockhost))
117 sockhost = empty_sockhost;
118 else if(!show_ip(source_p, target_p))
119 sockhost = spoofed_sockhost;
120 else
121 sockhost = target_p->sockhost;
122
123 if(match(username, target_p->username) &&
124 (match(hostname, target_p->host) ||
125 match(hostname, target_p->orighost) ||
126 match(hostname, sockhost) || match_ips(hostname, sockhost)))
127 {
128 if(name && !match(name, target_p->name))
129 continue;
130
eb5e3f15 131 if(gecos && !match_esc(gecos, target_p->info))
212380e3 132 continue;
133
134 if(MyClient(target_p))
135 lcount++;
136 else
137 gcount++;
138 }
139 }
140
141 sendto_one(source_p, form_str(RPL_TESTMASKGECOS),
142 me.name, source_p->name,
143 lcount, gcount, name ? name : "*",
144 username, hostname, gecos ? gecos : "*");
145 return 0;
146}