]>
Commit | Line | Data |
---|---|---|
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 | */ | |
30 | #include "stdinc.h" | |
31 | #include "send.h" | |
32 | #include "client.h" | |
33 | #include "modules.h" | |
34 | #include "msg.h" | |
35 | #include "hash.h" | |
36 | #include "hostmask.h" | |
37 | #include "numeric.h" | |
38 | #include "s_conf.h" | |
39 | #include "s_newconf.h" | |
40 | #include "reject.h" | |
41 | ||
42 | static const char testline_desc[] = "Provides the ability to test I/K/D/X lines and RESVs"; | |
43 | ||
44 | static void mo_testline(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
45 | static void mo_testgecos(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
46 | ||
47 | struct Message testline_msgtab = { | |
48 | "TESTLINE", 0, 0, 0, 0, | |
49 | {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_testline, 2}} | |
50 | }; | |
51 | struct Message testgecos_msgtab = { | |
52 | "TESTGECOS", 0, 0, 0, 0, | |
53 | {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_testgecos, 2}} | |
54 | }; | |
55 | ||
56 | mapi_clist_av1 testline_clist[] = { &testline_msgtab, &testgecos_msgtab, NULL }; | |
57 | ||
58 | DECLARE_MODULE_AV2(testline, NULL, NULL, testline_clist, NULL, NULL, NULL, NULL, testline_desc); | |
59 | ||
60 | static void | |
61 | mo_testline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
62 | { | |
63 | struct ConfItem *aconf; | |
64 | struct ConfItem *resv_p; | |
65 | struct rb_sockaddr_storage ip; | |
66 | char user_trunc[USERLEN + 1], notildeuser_trunc[USERLEN + 1]; | |
67 | const char *name = NULL; | |
68 | const char *username = NULL; | |
69 | const char *host = NULL; | |
70 | char *mask; | |
71 | char *p; | |
72 | int host_mask; | |
73 | int type; | |
74 | int duration; | |
75 | char *puser, *phost, *reason, *operreason; | |
76 | char reasonbuf[BUFSIZE]; | |
77 | ||
78 | mask = LOCAL_COPY(parv[1]); | |
79 | ||
80 | if (IsChannelName(mask)) | |
81 | { | |
82 | resv_p = hash_find_resv(mask); | |
83 | if (resv_p != NULL) | |
84 | { | |
85 | sendto_one(source_p, form_str(RPL_TESTLINE), | |
86 | me.name, source_p->name, | |
87 | resv_p->hold ? 'q' : 'Q', | |
88 | resv_p->hold ? (long) ((resv_p->hold - rb_current_time()) / 60) : 0L, | |
89 | resv_p->host, resv_p->passwd); | |
90 | /* this is a false positive, so make sure it isn't counted in stats q | |
91 | * --nenolod | |
92 | */ | |
93 | resv_p->port--; | |
94 | } | |
95 | else | |
96 | sendto_one(source_p, form_str(RPL_NOTESTLINE), | |
97 | me.name, source_p->name, parv[1]); | |
98 | return; | |
99 | } | |
100 | ||
101 | if((p = strchr(mask, '!'))) | |
102 | { | |
103 | *p++ = '\0'; | |
104 | name = mask; | |
105 | mask = p; | |
106 | ||
107 | if(EmptyString(mask)) | |
108 | return; | |
109 | } | |
110 | ||
111 | if((p = strchr(mask, '@'))) | |
112 | { | |
113 | *p++ = '\0'; | |
114 | username = mask; | |
115 | host = p; | |
116 | ||
117 | if(EmptyString(host)) | |
118 | return; | |
119 | } | |
120 | else | |
121 | host = mask; | |
122 | ||
123 | /* parses as an IP, check for a dline */ | |
124 | if((type = parse_netmask(host, &ip, &host_mask)) != HM_HOST) | |
125 | { | |
126 | #ifdef RB_IPV6 | |
127 | if(type == HM_IPV6) | |
128 | aconf = find_dline((struct sockaddr *)&ip, AF_INET6); | |
129 | else | |
130 | #endif | |
131 | aconf = find_dline((struct sockaddr *)&ip, AF_INET); | |
132 | ||
133 | if(aconf && aconf->status & CONF_DLINE) | |
134 | { | |
135 | get_printable_kline(source_p, aconf, &phost, &reason, &puser, &operreason); | |
136 | snprintf(reasonbuf, sizeof(reasonbuf), "%s%s%s", reason, | |
137 | operreason ? "|" : "", operreason ? operreason : ""); | |
138 | sendto_one(source_p, form_str(RPL_TESTLINE), | |
139 | me.name, source_p->name, | |
140 | (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'd' : 'D', | |
141 | (aconf->flags & CONF_FLAGS_TEMPORARY) ? | |
142 | (long) ((aconf->hold - rb_current_time()) / 60) : 0L, | |
143 | phost, reasonbuf); | |
144 | ||
145 | return; | |
146 | } | |
147 | /* Otherwise, aconf is an exempt{} */ | |
148 | if(aconf == NULL && | |
149 | (duration = is_reject_ip((struct sockaddr *)&ip))) | |
150 | sendto_one(source_p, form_str(RPL_TESTLINE), | |
151 | me.name, source_p->name, | |
152 | '!', | |
153 | duration / 60L, | |
154 | host, "Reject cache"); | |
155 | if(aconf == NULL && | |
156 | (duration = is_throttle_ip((struct sockaddr *)&ip))) | |
157 | sendto_one(source_p, form_str(RPL_TESTLINE), | |
158 | me.name, source_p->name, | |
159 | '!', | |
160 | duration / 60L, | |
161 | host, "Throttled"); | |
162 | } | |
163 | ||
164 | if (username != NULL) | |
165 | { | |
166 | rb_strlcpy(user_trunc, username, sizeof user_trunc); | |
167 | rb_strlcpy(notildeuser_trunc, *username == '~' ? username + 1 : username, sizeof notildeuser_trunc); | |
168 | } | |
169 | else | |
170 | { | |
171 | rb_strlcpy(user_trunc, "dummy", sizeof user_trunc); | |
172 | rb_strlcpy(notildeuser_trunc, "dummy", sizeof notildeuser_trunc); | |
173 | } | |
174 | /* now look for a matching I/K/G */ | |
175 | if((aconf = find_address_conf(host, NULL, user_trunc, notildeuser_trunc, | |
176 | (type != HM_HOST) ? (struct sockaddr *)&ip : NULL, | |
177 | (type != HM_HOST) ? ( | |
178 | #ifdef RB_IPV6 | |
179 | (type == HM_IPV6) ? AF_INET6 : | |
180 | #endif | |
181 | AF_INET) : 0, NULL))) | |
182 | { | |
183 | static char buf[HOSTLEN+USERLEN+2]; | |
184 | ||
185 | if(aconf->status & CONF_KILL) | |
186 | { | |
187 | get_printable_kline(source_p, aconf, &phost, &reason, &puser, &operreason); | |
188 | snprintf(buf, sizeof(buf), "%s@%s", | |
189 | puser, phost); | |
190 | snprintf(reasonbuf, sizeof(reasonbuf), "%s%s%s", reason, | |
191 | operreason ? "|" : "", operreason ? operreason : ""); | |
192 | sendto_one(source_p, form_str(RPL_TESTLINE), | |
193 | me.name, source_p->name, | |
194 | (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'k' : 'K', | |
195 | (aconf->flags & CONF_FLAGS_TEMPORARY) ? | |
196 | (long) ((aconf->hold - rb_current_time()) / 60) : 0L, | |
197 | buf, reasonbuf); | |
198 | return; | |
199 | } | |
200 | } | |
201 | ||
202 | /* they asked us to check a nick, so hunt for resvs.. */ | |
203 | if(name && (resv_p = find_nick_resv(name))) | |
204 | { | |
205 | sendto_one(source_p, form_str(RPL_TESTLINE), | |
206 | me.name, source_p->name, | |
207 | resv_p->hold ? 'q' : 'Q', | |
208 | resv_p->hold ? (long) ((resv_p->hold - rb_current_time()) / 60) : 0L, | |
209 | resv_p->host, resv_p->passwd); | |
210 | ||
211 | /* this is a false positive, so make sure it isn't counted in stats q | |
212 | * --nenolod | |
213 | */ | |
214 | resv_p->port--; | |
215 | return; | |
216 | } | |
217 | ||
218 | /* no matching resv, we can print the I: if it exists */ | |
219 | if(aconf && aconf->status & CONF_CLIENT) | |
220 | { | |
221 | sendto_one_numeric(source_p, RPL_STATSILINE, form_str(RPL_STATSILINE), | |
222 | aconf->info.name, EmptyString(aconf->spasswd) ? "<NULL>" : aconf->spasswd, | |
223 | show_iline_prefix(source_p, aconf, aconf->user), | |
224 | aconf->host, aconf->port, aconf->className); | |
225 | return; | |
226 | } | |
227 | ||
228 | /* nothing matches.. */ | |
229 | sendto_one(source_p, form_str(RPL_NOTESTLINE), | |
230 | me.name, source_p->name, parv[1]); | |
231 | } | |
232 | ||
233 | static void | |
234 | mo_testgecos(struct MsgBuf *msgbuf_p, 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; | |
243 | } | |
244 | ||
245 | sendto_one(source_p, form_str(RPL_TESTLINE), | |
246 | me.name, source_p->name, | |
247 | aconf->hold ? 'x' : 'X', | |
248 | aconf->hold ? (long) ((aconf->hold - rb_current_time()) / 60) : 0L, | |
249 | aconf->host, aconf->passwd); | |
250 | } |