]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* modules/m_testline.c |
2 | * | |
3 | * Copyright (C) 2004 Lee Hardy <lee@leeh.co.uk> | |
4 | * Copyright (C) 2004-2005 ircd-ratbox development team | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are | |
8 | * met: | |
9 | * | |
10 | * 1.Redistributions of source code must retain the above copyright notice, | |
11 | * this list of conditions and the following disclaimer. | |
12 | * 2.Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * 3.The name of the author may not be used to endorse or promote products | |
16 | * derived from this software without specific prior written permission. | |
17 | * | |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | |
22 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
26 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
27 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
28 | * POSSIBILITY OF SUCH DAMAGE. | |
29 | * | |
add9f99d | 30 | * $Id: m_testline.c 3303 2007-03-28 15:22:49Z jilles $ |
212380e3 AC |
31 | */ |
32 | #include "stdinc.h" | |
212380e3 AC |
33 | #include "send.h" |
34 | #include "client.h" | |
35 | #include "modules.h" | |
36 | #include "msg.h" | |
add9f99d | 37 | #include "hash.h" |
212380e3 AC |
38 | #include "hostmask.h" |
39 | #include "numeric.h" | |
40 | #include "s_conf.h" | |
41 | #include "s_newconf.h" | |
83235e9e | 42 | #include "reject.h" |
212380e3 AC |
43 | |
44 | static int mo_testline(struct Client *, struct Client *, int, const char **); | |
45 | static int mo_testgecos(struct Client *, struct Client *, int, const char **); | |
46 | ||
47 | struct Message testline_msgtab = { | |
48 | "TESTLINE", 0, 0, 0, MFLG_SLOW, | |
96bfafc1 | 49 | {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_testline, 2}} |
212380e3 AC |
50 | }; |
51 | struct Message testgecos_msgtab = { | |
52 | "TESTGECOS", 0, 0, 0, MFLG_SLOW, | |
96bfafc1 | 53 | {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_testgecos, 2}} |
212380e3 AC |
54 | }; |
55 | ||
56 | mapi_clist_av1 testline_clist[] = { &testline_msgtab, &testgecos_msgtab, NULL }; | |
add9f99d | 57 | DECLARE_MODULE_AV1(testline, NULL, NULL, testline_clist, NULL, NULL, "$Revision: 3303 $"); |
212380e3 AC |
58 | |
59 | static int | |
60 | mo_testline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
61 | { | |
62 | struct ConfItem *aconf; | |
63 | struct ConfItem *resv_p; | |
e7046ee5 | 64 | struct rb_sockaddr_storage ip; |
212380e3 AC |
65 | char user_trunc[USERLEN + 1], notildeuser_trunc[USERLEN + 1]; |
66 | const char *name = NULL; | |
67 | const char *username = NULL; | |
68 | const char *host = NULL; | |
69 | char *mask; | |
70 | char *p; | |
71 | int host_mask; | |
72 | int type; | |
83235e9e | 73 | int duration; |
e5b12a61 JT |
74 | char *puser, *phost, *reason, *operreason; |
75 | char reasonbuf[BUFSIZE]; | |
212380e3 AC |
76 | |
77 | mask = LOCAL_COPY(parv[1]); | |
78 | ||
add9f99d JT |
79 | if (IsChannelName(mask)) |
80 | { | |
81 | resv_p = hash_find_resv(mask); | |
82 | if (resv_p != NULL) | |
83 | { | |
84 | sendto_one(source_p, form_str(RPL_TESTLINE), | |
85 | me.name, source_p->name, | |
86 | resv_p->hold ? 'q' : 'Q', | |
e3354945 | 87 | resv_p->hold ? (long) ((resv_p->hold - rb_current_time()) / 60) : 0L, |
70ea02eb | 88 | resv_p->host, resv_p->passwd); |
add9f99d JT |
89 | /* this is a false positive, so make sure it isn't counted in stats q |
90 | * --nenolod | |
91 | */ | |
92 | resv_p->port--; | |
93 | } | |
94 | else | |
95 | sendto_one(source_p, form_str(RPL_NOTESTLINE), | |
96 | me.name, source_p->name, parv[1]); | |
97 | return 0; | |
98 | } | |
99 | ||
212380e3 AC |
100 | if((p = strchr(mask, '!'))) |
101 | { | |
102 | *p++ = '\0'; | |
103 | name = mask; | |
104 | mask = p; | |
105 | ||
106 | if(EmptyString(mask)) | |
107 | return 0; | |
108 | } | |
109 | ||
110 | if((p = strchr(mask, '@'))) | |
111 | { | |
112 | *p++ = '\0'; | |
113 | username = mask; | |
114 | host = p; | |
115 | ||
116 | if(EmptyString(host)) | |
117 | return 0; | |
118 | } | |
119 | else | |
120 | host = mask; | |
121 | ||
122 | /* parses as an IP, check for a dline */ | |
123 | if((type = parse_netmask(host, (struct sockaddr *)&ip, &host_mask)) != HM_HOST) | |
124 | { | |
ccda6e3f | 125 | #ifdef RB_IPV6 |
54ac8b60 VY |
126 | if(type == HM_IPV6) |
127 | aconf = find_dline((struct sockaddr *)&ip, AF_INET6); | |
128 | else | |
129 | #endif | |
130 | aconf = find_dline((struct sockaddr *)&ip, AF_INET); | |
212380e3 AC |
131 | |
132 | if(aconf && aconf->status & CONF_DLINE) | |
133 | { | |
e5b12a61 JT |
134 | get_printable_kline(source_p, aconf, &phost, &reason, &puser, &operreason); |
135 | rb_snprintf(reasonbuf, sizeof(reasonbuf), "%s%s%s", reason, | |
136 | operreason ? "|" : "", operreason ? operreason : ""); | |
212380e3 AC |
137 | sendto_one(source_p, form_str(RPL_TESTLINE), |
138 | me.name, source_p->name, | |
139 | (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'd' : 'D', | |
140 | (aconf->flags & CONF_FLAGS_TEMPORARY) ? | |
e3354945 | 141 | (long) ((aconf->hold - rb_current_time()) / 60) : 0L, |
e5b12a61 | 142 | phost, reasonbuf); |
212380e3 AC |
143 | |
144 | return 0; | |
145 | } | |
83235e9e JT |
146 | /* Otherwise, aconf is an exempt{} */ |
147 | if(aconf == NULL && | |
148 | (duration = is_reject_ip((struct sockaddr *)&ip))) | |
149 | sendto_one(source_p, form_str(RPL_TESTLINE), | |
150 | me.name, source_p->name, | |
151 | '!', | |
0cce01d3 | 152 | duration / 60L, |
83235e9e JT |
153 | host, "Reject cache"); |
154 | if(aconf == NULL && | |
155 | (duration = is_throttle_ip((struct sockaddr *)&ip))) | |
156 | sendto_one(source_p, form_str(RPL_TESTLINE), | |
157 | me.name, source_p->name, | |
158 | '!', | |
0cce01d3 | 159 | duration / 60L, |
83235e9e | 160 | host, "Throttled"); |
212380e3 AC |
161 | } |
162 | ||
163 | if (username != NULL) | |
164 | { | |
f427c8b0 VY |
165 | rb_strlcpy(user_trunc, username, sizeof user_trunc); |
166 | rb_strlcpy(notildeuser_trunc, *username == '~' ? username + 1 : username, sizeof notildeuser_trunc); | |
212380e3 AC |
167 | } |
168 | else | |
169 | { | |
f427c8b0 VY |
170 | rb_strlcpy(user_trunc, "dummy", sizeof user_trunc); |
171 | rb_strlcpy(notildeuser_trunc, "dummy", sizeof notildeuser_trunc); | |
212380e3 AC |
172 | } |
173 | /* now look for a matching I/K/G */ | |
174 | if((aconf = find_address_conf(host, NULL, user_trunc, notildeuser_trunc, | |
175 | (type != HM_HOST) ? (struct sockaddr *)&ip : NULL, | |
176 | (type != HM_HOST) ? ( | |
ccda6e3f | 177 | #ifdef RB_IPV6 |
212380e3 AC |
178 | (type == HM_IPV6) ? AF_INET6 : |
179 | #endif | |
40c1fd47 | 180 | AF_INET) : 0, NULL))) |
212380e3 AC |
181 | { |
182 | static char buf[HOSTLEN+USERLEN+2]; | |
183 | ||
184 | if(aconf->status & CONF_KILL) | |
185 | { | |
1e57e391 | 186 | get_printable_kline(source_p, aconf, &phost, &reason, &puser, &operreason); |
7cdb0a09 | 187 | rb_snprintf(buf, sizeof(buf), "%s@%s", |
1e57e391 | 188 | puser, phost); |
cb2540a6 JT |
189 | rb_snprintf(reasonbuf, sizeof(reasonbuf), "%s%s%s", reason, |
190 | operreason ? "|" : "", operreason ? operreason : ""); | |
212380e3 AC |
191 | sendto_one(source_p, form_str(RPL_TESTLINE), |
192 | me.name, source_p->name, | |
193 | (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'k' : 'K', | |
194 | (aconf->flags & CONF_FLAGS_TEMPORARY) ? | |
e3354945 | 195 | (long) ((aconf->hold - rb_current_time()) / 60) : 0L, |
cb2540a6 | 196 | buf, reasonbuf); |
212380e3 AC |
197 | return 0; |
198 | } | |
212380e3 AC |
199 | } |
200 | ||
201 | /* they asked us to check a nick, so hunt for resvs.. */ | |
202 | if(name && (resv_p = find_nick_resv(name))) | |
203 | { | |
204 | sendto_one(source_p, form_str(RPL_TESTLINE), | |
205 | me.name, source_p->name, | |
206 | resv_p->hold ? 'q' : 'Q', | |
e3354945 | 207 | resv_p->hold ? (long) ((resv_p->hold - rb_current_time()) / 60) : 0L, |
70ea02eb | 208 | resv_p->host, resv_p->passwd); |
212380e3 AC |
209 | |
210 | /* this is a false positive, so make sure it isn't counted in stats q | |
211 | * --nenolod | |
212 | */ | |
213 | resv_p->port--; | |
214 | return 0; | |
215 | } | |
216 | ||
217 | /* no matching resv, we can print the I: if it exists */ | |
218 | if(aconf && aconf->status & CONF_CLIENT) | |
219 | { | |
220 | sendto_one_numeric(source_p, RPL_STATSILINE, form_str(RPL_STATSILINE), | |
27f616dd | 221 | aconf->info.name, EmptyString(aconf->spasswd) ? "<NULL>" : aconf->spasswd, |
59c3d09a | 222 | show_iline_prefix(source_p, aconf, aconf->user), |
212380e3 AC |
223 | aconf->host, aconf->port, aconf->className); |
224 | return 0; | |
225 | } | |
226 | ||
227 | /* nothing matches.. */ | |
228 | sendto_one(source_p, form_str(RPL_NOTESTLINE), | |
229 | me.name, source_p->name, parv[1]); | |
230 | return 0; | |
231 | } | |
232 | ||
233 | static int | |
234 | mo_testgecos(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
235 | { | |
236 | struct ConfItem *aconf; | |
237 | ||
238 | if(!(aconf = find_xline(parv[1], 0))) | |
239 | { | |
240 | sendto_one(source_p, form_str(RPL_NOTESTLINE), | |
241 | me.name, source_p->name, parv[1]); | |
242 | return 0; | |
243 | } | |
244 | ||
245 | sendto_one(source_p, form_str(RPL_TESTLINE), | |
246 | me.name, source_p->name, | |
247 | aconf->hold ? 'x' : 'X', | |
e3354945 | 248 | aconf->hold ? (long) ((aconf->hold - rb_current_time()) / 60) : 0L, |
70ea02eb | 249 | aconf->host, aconf->passwd); |
212380e3 AC |
250 | return 0; |
251 | } |