]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_testline.c
Removal of ancient SVN ID's part one
[irc/rqf/shadowircd.git] / modules / m_testline.c
CommitLineData
212380e3 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 *
212380e3 30 */
31#include "stdinc.h"
212380e3 32#include "send.h"
33#include "client.h"
34#include "modules.h"
35#include "msg.h"
add9f99d 36#include "hash.h"
212380e3 37#include "hostmask.h"
38#include "numeric.h"
39#include "s_conf.h"
40#include "s_newconf.h"
760ef9e1 41#include "reject.h"
212380e3 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,
0e0c4508 48 {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_testline, 2}}
212380e3 49};
50struct Message testgecos_msgtab = {
51 "TESTGECOS", 0, 0, 0, MFLG_SLOW,
0e0c4508 52 {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_testgecos, 2}}
212380e3 53};
54
55mapi_clist_av1 testline_clist[] = { &testline_msgtab, &testgecos_msgtab, NULL };
add9f99d 56DECLARE_MODULE_AV1(testline, NULL, NULL, testline_clist, NULL, NULL, "$Revision: 3303 $");
212380e3 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;
3ea5fee7 63 struct rb_sockaddr_storage ip;
212380e3 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;
760ef9e1 72 int duration;
c70fcd85
JT
73 char *puser, *phost, *reason, *operreason;
74 char reasonbuf[BUFSIZE];
212380e3 75
76 mask = LOCAL_COPY(parv[1]);
77
add9f99d 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',
9f6bbe3c 86 resv_p->hold ? (long) ((resv_p->hold - rb_current_time()) / 60) : 0L,
70c6c150 87 resv_p->host, resv_p->passwd);
add9f99d 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
212380e3 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 {
2c2e0aa9 124#ifdef RB_IPV6
21c9d815
VY
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);
212380e3 130
131 if(aconf && aconf->status & CONF_DLINE)
132 {
c70fcd85
JT
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 : "");
212380e3 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) ?
9f6bbe3c 140 (long) ((aconf->hold - rb_current_time()) / 60) : 0L,
c70fcd85 141 phost, reasonbuf);
212380e3 142
143 return 0;
144 }
760ef9e1
JT
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");
212380e3 160 }
161
162 if (username != NULL)
163 {
907468c4
VY
164 rb_strlcpy(user_trunc, username, sizeof user_trunc);
165 rb_strlcpy(notildeuser_trunc, *username == '~' ? username + 1 : username, sizeof notildeuser_trunc);
212380e3 166 }
167 else
168 {
907468c4
VY
169 rb_strlcpy(user_trunc, "dummy", sizeof user_trunc);
170 rb_strlcpy(notildeuser_trunc, "dummy", sizeof notildeuser_trunc);
212380e3 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) ? (
2c2e0aa9 176#ifdef RB_IPV6
212380e3 177 (type == HM_IPV6) ? AF_INET6 :
178#endif
969a1ae6 179 AF_INET) : 0, NULL)))
212380e3 180 {
181 static char buf[HOSTLEN+USERLEN+2];
182
183 if(aconf->status & CONF_KILL)
184 {
1b09d115 185 get_printable_kline(source_p, aconf, &phost, &reason, &puser, &operreason);
581fa5c4 186 rb_snprintf(buf, sizeof(buf), "%s@%s",
1b09d115 187 puser, phost);
e19c515c
JT
188 rb_snprintf(reasonbuf, sizeof(reasonbuf), "%s%s%s", reason,
189 operreason ? "|" : "", operreason ? operreason : "");
212380e3 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) ?
9f6bbe3c 194 (long) ((aconf->hold - rb_current_time()) / 60) : 0L,
e19c515c 195 buf, reasonbuf);
212380e3 196 return 0;
197 }
212380e3 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',
9f6bbe3c 206 resv_p->hold ? (long) ((resv_p->hold - rb_current_time()) / 60) : 0L,
70c6c150 207 resv_p->host, resv_p->passwd);
212380e3 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),
a0f4c418 220 aconf->info.name, EmptyString(aconf->spasswd) ? "<NULL>" : aconf->spasswd,
40455022 221 show_iline_prefix(source_p, aconf, aconf->user),
212380e3 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',
9f6bbe3c 247 aconf->hold ? (long) ((aconf->hold - rb_current_time()) / 60) : 0L,
70c6c150 248 aconf->host, aconf->passwd);
212380e3 249 return 0;
250}