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