Remove cruft left behind by removed stats_p_hook.
[seven-1.x.git] / modules / m_testmask.c
blob051431f72a12bddf7bdc898aac79d66cddeeaacb
1 /*
2 * m_testmask.c: Shows the number of matching local and global clients
3 * for a user@host mask, helpful when setting GLINE's
5 * Copyright (C) 2003 by W. Campbell
6 * Coypright (C) 2004 ircd-ratbox development team
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
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.
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.
34 /* List of ircd includes from ../include/ */
35 #include "stdinc.h"
36 #include "client.h"
37 #include "common.h" /* FALSE bleah */
38 #include "ircd.h"
39 #include "irc_string.h"
40 #include "numeric.h"
41 #include "s_conf.h"
42 #include "s_log.h"
43 #include "s_serv.h"
44 #include "send.h"
45 #include "msg.h"
46 #include "parse.h"
47 #include "modules.h"
49 static int mo_testmask(struct Client *client_p, struct Client *source_p,
50 int parc, const char *parv[]);
52 struct Message testmask_msgtab = {
53 "TESTMASK", 0, 0, 0, MFLG_SLOW,
54 {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_testmask, 2}}
57 mapi_clist_av1 testmask_clist[] = { &testmask_msgtab, NULL };
58 DECLARE_MODULE_AV1(testmask, NULL, NULL, testmask_clist, NULL, NULL, "$Revision: 147 $");
60 static const char *empty_sockhost = "255.255.255.255";
61 static const char *spoofed_sockhost = "0";
63 static int
64 mo_testmask(struct Client *client_p, struct Client *source_p,
65 int parc, const char *parv[])
67 struct Client *target_p;
68 int lcount = 0;
69 int gcount = 0;
70 char *name, *username, *hostname;
71 const char *sockhost;
72 char *gecos = NULL, *mangle_gecos = NULL;
73 dlink_node *ptr;
75 if(!IsOperStaffer(source_p))
77 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "staffer");
78 return 0;
81 name = LOCAL_COPY(parv[1]);
82 collapse(name);
84 /* username is required */
85 if((hostname = strchr(name, '@')) == NULL)
87 sendto_one(source_p, ":%s NOTICE %s :Invalid parameters",
88 me.name, source_p->name);
89 return 0;
92 *hostname++ = '\0';
94 /* nickname is optional */
95 if((username = strchr(name, '!')) == NULL)
97 username = name;
98 name = NULL;
100 else
101 *username++ = '\0';
103 if(EmptyString(username) || EmptyString(hostname))
105 sendto_one(source_p, ":%s NOTICE %s :Invalid parameters",
106 me.name, source_p->name);
107 return 0;
110 if(parc > 2 && !EmptyString(parv[2]))
112 gecos = LOCAL_COPY(parv[2]);
113 collapse_esc(gecos);
114 if(strstr(gecos, "\\s"))
116 char *tmp = LOCAL_COPY(gecos);
117 char *orig = tmp;
118 char *new = tmp;
119 while(*orig)
121 if(*orig == '\\')
123 if(*(orig + 1) == 's')
125 *new++ = ' ';
126 orig += 2;
128 /* otherwise skip that and the escaped
129 * character after it, so we dont mistake
130 * \\s as \s --fl
132 else
134 *new++ = *orig++;
135 *new++ = *orig++;
138 else
139 *new++ = *orig++;
142 *new = '\0';
143 mangle_gecos = LOCAL_COPY(tmp);
144 } else
145 mangle_gecos = gecos;
148 DLINK_FOREACH(ptr, global_client_list.head)
150 target_p = ptr->data;
152 if(!IsPerson(target_p))
153 continue;
155 if(EmptyString(target_p->sockhost))
156 sockhost = empty_sockhost;
157 else if(!show_ip(source_p, target_p))
158 sockhost = spoofed_sockhost;
159 else
160 sockhost = target_p->sockhost;
162 if(match(username, target_p->username) &&
163 (match(hostname, target_p->host) ||
164 match(hostname, target_p->orighost) ||
165 match(hostname, sockhost) || match_ips(hostname, sockhost)))
167 if(name && !match(name, target_p->name))
168 continue;
170 if(mangle_gecos && !match_esc(mangle_gecos, target_p->info))
171 continue;
173 if(MyClient(target_p))
174 lcount++;
175 else
176 gcount++;
180 sendto_one(source_p, form_str(RPL_TESTMASKGECOS),
181 me.name, source_p->name,
182 lcount, gcount, name ? name : "*",
183 username, hostname, gecos ? gecos : "*");
184 return 0;