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
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.
32 * $Id: m_testmask.c 147 2006-11-13 12:35:45Z spb $
36 /* List of ircd includes from ../include/ */
39 #include "common.h" /* FALSE bleah */
41 #include "irc_string.h"
51 static int mo_testmask(struct Client
*client_p
, struct Client
*source_p
,
52 int parc
, const char *parv
[]);
54 struct Message testmask_msgtab
= {
55 "TESTMASK", 0, 0, 0, MFLG_SLOW
,
56 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, mg_ignore
, {mo_testmask
, 2}}
59 mapi_clist_av1 testmask_clist
[] = { &testmask_msgtab
, NULL
};
60 DECLARE_MODULE_AV1(testmask
, NULL
, NULL
, testmask_clist
, NULL
, NULL
, "$Revision: 147 $");
62 static const char *empty_sockhost
= "255.255.255.255";
63 static const char *spoofed_sockhost
= "0";
66 mo_testmask(struct Client
*client_p
, struct Client
*source_p
,
67 int parc
, const char *parv
[])
69 struct Client
*target_p
;
72 char *name
, *username
, *hostname
;
74 char *gecos
= NULL
, *mangle_gecos
= NULL
;
77 if(!IsOperStaffer(source_p
))
79 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "staffer");
83 name
= LOCAL_COPY(parv
[1]);
86 /* username is required */
87 if((hostname
= strchr(name
, '@')) == NULL
)
89 sendto_one(source_p
, ":%s NOTICE %s :Invalid parameters",
90 me
.name
, source_p
->name
);
96 /* nickname is optional */
97 if((username
= strchr(name
, '!')) == NULL
)
105 if(EmptyString(username
) || EmptyString(hostname
))
107 sendto_one(source_p
, ":%s NOTICE %s :Invalid parameters",
108 me
.name
, source_p
->name
);
112 if(parc
> 2 && !EmptyString(parv
[2]))
114 gecos
= LOCAL_COPY(parv
[2]);
116 if(strstr(gecos
, "\\s"))
118 char *tmp
= LOCAL_COPY(gecos
);
125 if(*(orig
+ 1) == 's')
130 /* otherwise skip that and the escaped
131 * character after it, so we dont mistake
145 mangle_gecos
= LOCAL_COPY(tmp
);
147 mangle_gecos
= gecos
;
150 DLINK_FOREACH(ptr
, global_client_list
.head
)
152 target_p
= ptr
->data
;
154 if(!IsPerson(target_p
))
157 if(EmptyString(target_p
->sockhost
))
158 sockhost
= empty_sockhost
;
159 else if(!show_ip(source_p
, target_p
))
160 sockhost
= spoofed_sockhost
;
162 sockhost
= target_p
->sockhost
;
164 if(match(username
, target_p
->username
) &&
165 (match(hostname
, target_p
->host
) ||
166 match(hostname
, target_p
->orighost
) ||
167 match(hostname
, sockhost
) || match_ips(hostname
, sockhost
)))
169 if(name
&& !match(name
, target_p
->name
))
172 if(mangle_gecos
&& !match_esc(mangle_gecos
, target_p
->info
))
175 if(MyClient(target_p
))
182 sendto_one(source_p
, form_str(RPL_TESTMASKGECOS
),
183 me
.name
, source_p
->name
,
184 lcount
, gcount
, name
? name
: "*",
185 username
, hostname
, gecos
? gecos
: "*");