Remove cruft left behind by removed stats_p_hook.
[seven-1.x.git] / modules / m_scan.c
blobaca745252b32588cc638cc8508c5205b3a360f9d
1 /*
2 * charybdis: an advanced Internet Relay Chat Daemon(ircd).
3 * m_scan.c: Provides information about various targets on various topics
5 * Copyright (c) 2006 William Pitcock <nenolod -at- nenolod.net>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
11 * 1.Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * 2.Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3.The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include "stdinc.h"
33 #include "class.h"
34 #include "hook.h"
35 #include "client.h"
36 #include "hash.h"
37 #include "common.h"
38 #include "hash.h"
39 #include "irc_string.h"
40 #include "ircd.h"
41 #include "numeric.h"
42 #include "commio.h"
43 #include "s_serv.h"
44 #include "s_conf.h"
45 #include "s_newconf.h"
46 #include "s_user.h"
47 #include "send.h"
48 #include "msg.h"
49 #include "parse.h"
50 #include "modules.h"
52 static int mo_scan(struct Client *, struct Client *, int, const char **);
53 static int scan_umodes(struct Client *, struct Client *, int, const char **);
54 /*static int scan_cmodes(struct Client *, struct Client *, int, const char **);*/
56 struct Message scan_msgtab = {
57 "SCAN", 0, 0, 0, MFLG_SLOW,
58 {mg_ignore, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_scan, 2}}
61 mapi_clist_av1 scan_clist[] = { &scan_msgtab, NULL };
62 DECLARE_MODULE_AV1(scan, NULL, NULL, scan_clist, NULL, NULL, "$Revision: 109 $");
64 typedef int (*scan_handler)(struct Client *, struct Client *, int,
65 const char **);
67 struct scan_cmd {
68 const char *name;
69 int operlevel;
70 scan_handler handler;
71 } scan_cmds[] = {
72 {"UMODES", L_OPER, scan_umodes},
73 {NULL, 0, NULL}
76 static const char *empty_sockhost = "255.255.255.255";
77 static const char *spoofed_sockhost = "0";
80 * m_scan
81 * parv[0] = sender prefix
82 * parv[1] = options [or target]
83 * parv[2] = [target]
85 static int
86 mo_scan(struct Client *client_p, struct Client *source_p, int parc,
87 const char *parv[])
89 struct scan_cmd *sptr;
91 if(!IsOperExperimental(source_p))
93 sendto_one(source_p, form_str(ERR_NOPRIVS),
94 me.name, source_p->name, "scan");
95 return 0;
98 for (sptr = scan_cmds; sptr->name != NULL; sptr++)
100 if (!irccmp(sptr->name, parv[1]))
102 if (sptr->operlevel == L_ADMIN &&
103 !IsOperAdmin(source_p))
104 return -1;
105 else
106 return sptr->handler(client_p, source_p, parc, parv);
110 sendto_one_notice(source_p, ":*** %s is not an implemented SCAN target",
111 parv[1]);
113 return 0;
116 static int
117 scan_umodes(struct Client *client_p, struct Client *source_p, int parc,
118 const char *parv[])
120 unsigned int allowed_umodes = 0, disallowed_umodes = 0;
121 int what = MODE_ADD;
122 int mode;
123 int list_users = YES;
124 int list_max = 0;
125 int list_count = 0, count = 0;
126 const char *mask = NULL;
127 const char *c;
128 struct Client *target_p;
129 dlink_list *target_list = &lclient_list; /* local clients only by default */
130 dlink_node *tn;
131 int i;
132 const char *sockhost;
134 if (parc < 3)
136 if (MyClient(source_p))
137 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
138 me.name, source_p->name, "SCAN UMODES");
140 return -1;
143 for (c = parv[2]; *c; c++)
145 switch(*c)
147 case '+':
148 what = MODE_ADD;
149 break;
150 case '-':
151 what = MODE_DEL;
152 break;
153 default:
154 if ((mode = user_modes[(unsigned char) *c]) != 0)
156 if (what == MODE_ADD)
157 allowed_umodes |= mode;
158 else
159 disallowed_umodes |= mode;
164 for (i = 3; i < parc; i++)
166 if (!irccmp(parv[i], "no-list"))
167 list_users = NO;
168 else if (!irccmp(parv[i], "list"))
169 list_users = YES;
170 else if (!irccmp(parv[i], "global"))
171 target_list = &global_client_list;
172 else if (i < (parc - 1))
174 if (!irccmp(parv[i], "list-max"))
175 list_max = atoi(parv[++i]);
176 else if (!irccmp(parv[i], "mask"))
177 mask = parv[++i];
180 if (target_list == &global_client_list && (list_users || mask))
182 if (!IsAuspex(source_p))
184 sendto_one(source_p, form_str(ERR_NOPRIVS),
185 me.name, source_p->name, "auspex");
186 return -1;
190 DLINK_FOREACH(tn, target_list->head)
192 unsigned int working_umodes = 0;
193 char maskbuf[BUFSIZE];
195 target_p = tn->data;
197 if (!IsClient(target_p))
198 continue;
200 if(EmptyString(target_p->sockhost))
201 sockhost = empty_sockhost;
202 else if(!show_ip(source_p, target_p))
203 sockhost = spoofed_sockhost;
204 else
205 sockhost = target_p->sockhost;
207 working_umodes = target_p->umodes;
209 /* require that we have the allowed umodes... */
210 if ((working_umodes & allowed_umodes) != allowed_umodes)
211 continue;
213 /* require that we have NONE of the disallowed ones */
214 if ((working_umodes & disallowed_umodes) != 0)
215 continue;
217 if (mask != NULL)
219 ircsnprintf(maskbuf, BUFSIZE, "%s!%s@%s",
220 target_p->name, target_p->username, target_p->host);
222 if (!match(mask, maskbuf))
223 continue;
226 if (list_users && (!list_max || (list_count < list_max)))
228 char modebuf[BUFSIZE];
229 char *m = modebuf;
231 *m++ = '+';
233 for (i = 0; i < 128; i++)
235 if (target_p->umodes & user_modes[i])
236 *m++ = (char) i;
239 *m++ = '\0';
241 list_count++;
243 sendto_one_numeric(source_p, RPL_SCANUMODES,
244 form_str(RPL_SCANUMODES),
245 target_p->name, target_p->username,
246 target_p->host, sockhost,
247 target_p->servptr->name, modebuf,
248 target_p->info);
250 count++;
253 sendto_one_numeric(source_p, RPL_SCANMATCHED,
254 form_str(RPL_SCANMATCHED), count);
256 return 0;