]> jfr.im git - solanum.git/blame_incremental - modules/m_testline.c
um_callerid: Use newer common channel iteration
[solanum.git] / modules / m_testline.c
... / ...
CommitLineData
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
42static const char testline_desc[] = "Provides the ability to test I/K/D/X lines and RESVs";
43
44static void mo_testline(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
45static void mo_testgecos(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
46
47struct 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};
51struct 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
56mapi_clist_av1 testline_clist[] = { &testline_msgtab, &testgecos_msgtab, NULL };
57
58DECLARE_MODULE_AV2(testline, NULL, NULL, testline_clist, NULL, NULL, NULL, NULL, testline_desc);
59
60static void
61mo_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 if (!HasPrivilege(source_p, "oper:testline"))
79 {
80 sendto_one(source_p, form_str(ERR_NOPRIVS),
81 me.name, source_p->name, "testline");
82 return;
83 }
84
85 mask = LOCAL_COPY(parv[1]);
86
87 if (IsChannelName(mask))
88 {
89 resv_p = hash_find_resv(mask);
90 if (resv_p != NULL)
91 {
92 sendto_one(source_p, form_str(RPL_TESTLINE),
93 me.name, source_p->name,
94 resv_p->hold ? 'q' : 'Q',
95 resv_p->hold ? (long) ((resv_p->hold - rb_current_time()) / 60) : 0L,
96 resv_p->host, resv_p->passwd);
97 /* this is a false positive, so make sure it isn't counted in stats q
98 * --nenolod
99 */
100 resv_p->port--;
101 }
102 else
103 sendto_one(source_p, form_str(RPL_NOTESTLINE),
104 me.name, source_p->name, parv[1]);
105 return;
106 }
107
108 if((p = strchr(mask, '!')))
109 {
110 *p++ = '\0';
111 name = mask;
112 mask = p;
113
114 if(EmptyString(mask))
115 return;
116 }
117
118 if((p = strchr(mask, '@')))
119 {
120 *p++ = '\0';
121 username = mask;
122 host = p;
123
124 if(EmptyString(host))
125 return;
126 }
127 else
128 host = mask;
129
130 /* parses as an IP, check for a dline */
131 if((type = parse_netmask(host, &ip, &host_mask)) != HM_HOST)
132 {
133 if(type == HM_IPV6)
134 aconf = find_dline((struct sockaddr *)&ip, AF_INET6);
135 else
136 aconf = find_dline((struct sockaddr *)&ip, AF_INET);
137
138 if(aconf && aconf->status & CONF_DLINE)
139 {
140 get_printable_kline(source_p, aconf, &phost, &reason, &puser, &operreason);
141 snprintf(reasonbuf, sizeof(reasonbuf), "%s%s%s", reason,
142 operreason ? "|" : "", operreason ? operreason : "");
143 sendto_one(source_p, form_str(RPL_TESTLINE),
144 me.name, source_p->name,
145 (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'd' : 'D',
146 (aconf->flags & CONF_FLAGS_TEMPORARY) ?
147 (long) ((aconf->hold - rb_current_time()) / 60) : 0L,
148 phost, reasonbuf);
149
150 return;
151 }
152 /* Otherwise, aconf is an exempt{} */
153 if(aconf == NULL &&
154 (duration = is_reject_ip((struct sockaddr *)&ip)))
155 sendto_one(source_p, form_str(RPL_TESTLINE),
156 me.name, source_p->name,
157 '!',
158 duration / 60L,
159 host, "Reject cache");
160 if(aconf == NULL &&
161 (duration = is_throttle_ip((struct sockaddr *)&ip)))
162 sendto_one(source_p, form_str(RPL_TESTLINE),
163 me.name, source_p->name,
164 '!',
165 duration / 60L,
166 host, "Throttled");
167 }
168
169 if (username != NULL)
170 {
171 rb_strlcpy(user_trunc, username, sizeof user_trunc);
172 rb_strlcpy(notildeuser_trunc, *username == '~' ? username + 1 : username, sizeof notildeuser_trunc);
173 }
174 else
175 {
176 rb_strlcpy(user_trunc, "dummy", sizeof user_trunc);
177 rb_strlcpy(notildeuser_trunc, "dummy", sizeof notildeuser_trunc);
178 }
179 /* now look for a matching I/K/G */
180 if((aconf = find_address_conf(host, NULL, user_trunc, notildeuser_trunc,
181 (type != HM_HOST) ? (struct sockaddr *)&ip : NULL,
182 (type != HM_HOST) ? (
183 (type == HM_IPV6) ? AF_INET6 :
184 AF_INET) : 0, NULL)))
185 {
186 static char buf[HOSTLEN+USERLEN+2];
187
188 if(aconf->status & CONF_KILL)
189 {
190 get_printable_kline(source_p, aconf, &phost, &reason, &puser, &operreason);
191 snprintf(buf, sizeof(buf), "%s@%s",
192 puser, phost);
193 snprintf(reasonbuf, sizeof(reasonbuf), "%s%s%s", reason,
194 operreason ? "|" : "", operreason ? operreason : "");
195 sendto_one(source_p, form_str(RPL_TESTLINE),
196 me.name, source_p->name,
197 (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'k' : 'K',
198 (aconf->flags & CONF_FLAGS_TEMPORARY) ?
199 (long) ((aconf->hold - rb_current_time()) / 60) : 0L,
200 buf, reasonbuf);
201 return;
202 }
203 }
204
205 /* they asked us to check a nick, so hunt for resvs.. */
206 if(name && (resv_p = find_nick_resv(name)))
207 {
208 sendto_one(source_p, form_str(RPL_TESTLINE),
209 me.name, source_p->name,
210 resv_p->hold ? 'q' : 'Q',
211 resv_p->hold ? (long) ((resv_p->hold - rb_current_time()) / 60) : 0L,
212 resv_p->host, resv_p->passwd);
213
214 /* this is a false positive, so make sure it isn't counted in stats q
215 * --nenolod
216 */
217 resv_p->port--;
218 return;
219 }
220
221 /* no matching resv, we can print the I: if it exists */
222 if(aconf && aconf->status & CONF_CLIENT)
223 {
224 sendto_one_numeric(source_p, RPL_STATSILINE, form_str(RPL_STATSILINE),
225 aconf->info.name, EmptyString(aconf->spasswd) ? "<NULL>" : aconf->spasswd,
226 show_iline_prefix(source_p, aconf, aconf->user),
227 aconf->host, aconf->port, aconf->className);
228 return;
229 }
230
231 /* nothing matches.. */
232 sendto_one(source_p, form_str(RPL_NOTESTLINE),
233 me.name, source_p->name, parv[1]);
234}
235
236static void
237mo_testgecos(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
238{
239 struct ConfItem *aconf;
240
241 if (!HasPrivilege(source_p, "oper:testline"))
242 {
243 sendto_one(source_p, form_str(ERR_NOPRIVS),
244 me.name, source_p->name, "testline");
245 return;
246 }
247
248 if(!(aconf = find_xline(parv[1], 0)))
249 {
250 sendto_one(source_p, form_str(RPL_NOTESTLINE),
251 me.name, source_p->name, parv[1]);
252 return;
253 }
254
255 sendto_one(source_p, form_str(RPL_TESTLINE),
256 me.name, source_p->name,
257 aconf->hold ? 'x' : 'X',
258 aconf->hold ? (long) ((aconf->hold - rb_current_time()) / 60) : 0L,
259 aconf->host, aconf->passwd);
260}