]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * m_testmask.c: Shows the number of matching local and global clients | |
170703fe | 3 | * for a user@host mask |
212380e3 AC |
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 | * | |
5366977b | 32 | * $Id: m_testmask.c 3161 2007-01-25 07:23:01Z nenolod $ |
212380e3 AC |
33 | * |
34 | */ | |
35 | ||
36 | /* List of ircd includes from ../include/ */ | |
37 | #include "stdinc.h" | |
38 | #include "client.h" | |
39 | #include "common.h" /* FALSE bleah */ | |
40 | #include "ircd.h" | |
4562c604 | 41 | #include "match.h" |
212380e3 AC |
42 | #include "numeric.h" |
43 | #include "s_conf.h" | |
4016731b | 44 | #include "logger.h" |
212380e3 AC |
45 | #include "s_serv.h" |
46 | #include "send.h" | |
47 | #include "msg.h" | |
48 | #include "parse.h" | |
49 | #include "modules.h" | |
50 | ||
51 | static int mo_testmask(struct Client *client_p, struct Client *source_p, | |
52 | int parc, const char *parv[]); | |
53 | ||
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}} | |
57 | }; | |
58 | ||
59 | mapi_clist_av1 testmask_clist[] = { &testmask_msgtab, NULL }; | |
5366977b | 60 | DECLARE_MODULE_AV1(testmask, NULL, NULL, testmask_clist, NULL, NULL, "$Revision: 3161 $"); |
212380e3 AC |
61 | |
62 | static const char *empty_sockhost = "255.255.255.255"; | |
63 | static const char *spoofed_sockhost = "0"; | |
64 | ||
65 | static int | |
66 | mo_testmask(struct Client *client_p, struct Client *source_p, | |
67 | int parc, const char *parv[]) | |
68 | { | |
69 | struct Client *target_p; | |
70 | int lcount = 0; | |
71 | int gcount = 0; | |
72 | char *name, *username, *hostname; | |
73 | const char *sockhost; | |
74 | char *gecos = NULL, *mangle_gecos = NULL; | |
5b96d9a6 | 75 | rb_dlink_node *ptr; |
212380e3 AC |
76 | |
77 | name = LOCAL_COPY(parv[1]); | |
78 | collapse(name); | |
79 | ||
80 | /* username is required */ | |
81 | if((hostname = strchr(name, '@')) == NULL) | |
82 | { | |
5366977b | 83 | sendto_one_notice(source_p, ":Invalid parameters"); |
212380e3 AC |
84 | return 0; |
85 | } | |
86 | ||
87 | *hostname++ = '\0'; | |
88 | ||
89 | /* nickname is optional */ | |
90 | if((username = strchr(name, '!')) == NULL) | |
91 | { | |
92 | username = name; | |
93 | name = NULL; | |
94 | } | |
95 | else | |
96 | *username++ = '\0'; | |
97 | ||
98 | if(EmptyString(username) || EmptyString(hostname)) | |
99 | { | |
5366977b | 100 | sendto_one_notice(source_p, ":Invalid parameters"); |
212380e3 AC |
101 | return 0; |
102 | } | |
103 | ||
104 | if(parc > 2 && !EmptyString(parv[2])) | |
105 | { | |
106 | gecos = LOCAL_COPY(parv[2]); | |
107 | collapse_esc(gecos); | |
108 | if(strstr(gecos, "\\s")) | |
109 | { | |
110 | char *tmp = LOCAL_COPY(gecos); | |
111 | char *orig = tmp; | |
112 | char *new = tmp; | |
113 | while(*orig) | |
114 | { | |
115 | if(*orig == '\\' && *(orig + 1) != '\0') | |
116 | { | |
117 | if(*(orig + 1) == 's') | |
118 | { | |
119 | *new++ = ' '; | |
120 | orig += 2; | |
121 | } | |
122 | /* otherwise skip that and the escaped | |
123 | * character after it, so we dont mistake | |
124 | * \\s as \s --fl | |
125 | */ | |
126 | else | |
127 | { | |
128 | *new++ = *orig++; | |
129 | *new++ = *orig++; | |
130 | } | |
131 | } | |
132 | else | |
133 | *new++ = *orig++; | |
134 | } | |
135 | ||
136 | *new = '\0'; | |
137 | mangle_gecos = LOCAL_COPY(tmp); | |
138 | } else | |
139 | mangle_gecos = gecos; | |
140 | } | |
141 | ||
5b96d9a6 | 142 | RB_DLINK_FOREACH(ptr, global_client_list.head) |
212380e3 AC |
143 | { |
144 | target_p = ptr->data; | |
145 | ||
146 | if(!IsPerson(target_p)) | |
147 | continue; | |
148 | ||
149 | if(EmptyString(target_p->sockhost)) | |
150 | sockhost = empty_sockhost; | |
151 | else if(!show_ip(source_p, target_p)) | |
152 | sockhost = spoofed_sockhost; | |
153 | else | |
154 | sockhost = target_p->sockhost; | |
155 | ||
156 | if(match(username, target_p->username) && | |
157 | (match(hostname, target_p->host) || | |
158 | match(hostname, target_p->orighost) || | |
159 | match(hostname, sockhost) || match_ips(hostname, sockhost))) | |
160 | { | |
161 | if(name && !match(name, target_p->name)) | |
162 | continue; | |
163 | ||
164 | if(mangle_gecos && !match_esc(mangle_gecos, target_p->info)) | |
165 | continue; | |
166 | ||
167 | if(MyClient(target_p)) | |
168 | lcount++; | |
169 | else | |
170 | gcount++; | |
171 | } | |
172 | } | |
173 | ||
174 | sendto_one(source_p, form_str(RPL_TESTMASKGECOS), | |
175 | me.name, source_p->name, | |
176 | lcount, gcount, name ? name : "*", | |
177 | username, hostname, gecos ? gecos : "*"); | |
178 | return 0; | |
179 | } |