]> jfr.im git - solanum.git/blame - modules/m_testline.c
Add oper:privs
[solanum.git] / modules / m_testline.c
CommitLineData
212380e3 1/* modules/m_testline.c
55abcbb2 2 *
212380e3
AC
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.
212380e3
AC
29 */
30#include "stdinc.h"
212380e3
AC
31#include "send.h"
32#include "client.h"
33#include "modules.h"
34#include "msg.h"
add9f99d 35#include "hash.h"
212380e3
AC
36#include "hostmask.h"
37#include "numeric.h"
38#include "s_conf.h"
39#include "s_newconf.h"
83235e9e 40#include "reject.h"
212380e3 41
eeabf33a
EM
42static const char testline_desc[] = "Provides the ability to test I/K/D/X lines and RESVs";
43
3c7d6fcc
EM
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 **);
212380e3
AC
46
47struct Message testline_msgtab = {
7baa37a9 48 "TESTLINE", 0, 0, 0, 0,
96bfafc1 49 {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_testline, 2}}
212380e3
AC
50};
51struct Message testgecos_msgtab = {
7baa37a9 52 "TESTGECOS", 0, 0, 0, 0,
96bfafc1 53 {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_testgecos, 2}}
212380e3
AC
54};
55
56mapi_clist_av1 testline_clist[] = { &testline_msgtab, &testgecos_msgtab, NULL };
eeabf33a 57
be9c3979 58DECLARE_MODULE_AV2(testline, NULL, NULL, testline_clist, NULL, NULL, NULL, NULL, testline_desc);
212380e3 59
3c7d6fcc 60static void
428ca87b 61mo_testline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
62{
63 struct ConfItem *aconf;
64 struct ConfItem *resv_p;
e7046ee5 65 struct rb_sockaddr_storage ip;
212380e3
AC
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;
83235e9e 74 int duration;
e5b12a61
JT
75 char *puser, *phost, *reason, *operreason;
76 char reasonbuf[BUFSIZE];
212380e3
AC
77
78 mask = LOCAL_COPY(parv[1]);
79
add9f99d
JT
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',
e3354945 88 resv_p->hold ? (long) ((resv_p->hold - rb_current_time()) / 60) : 0L,
70ea02eb 89 resv_p->host, resv_p->passwd);
add9f99d
JT
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]);
3c7d6fcc 98 return;
add9f99d
JT
99 }
100
212380e3
AC
101 if((p = strchr(mask, '!')))
102 {
103 *p++ = '\0';
104 name = mask;
105 mask = p;
106
107 if(EmptyString(mask))
3c7d6fcc 108 return;
212380e3
AC
109 }
110
111 if((p = strchr(mask, '@')))
112 {
113 *p++ = '\0';
114 username = mask;
115 host = p;
116
117 if(EmptyString(host))
3c7d6fcc 118 return;
212380e3
AC
119 }
120 else
121 host = mask;
122
123 /* parses as an IP, check for a dline */
29c92cf9 124 if((type = parse_netmask(host, &ip, &host_mask)) != HM_HOST)
212380e3 125 {
54ac8b60
VY
126 if(type == HM_IPV6)
127 aconf = find_dline((struct sockaddr *)&ip, AF_INET6);
128 else
54ac8b60 129 aconf = find_dline((struct sockaddr *)&ip, AF_INET);
212380e3
AC
130
131 if(aconf && aconf->status & CONF_DLINE)
132 {
e5b12a61 133 get_printable_kline(source_p, aconf, &phost, &reason, &puser, &operreason);
5203cba5 134 snprintf(reasonbuf, sizeof(reasonbuf), "%s%s%s", reason,
e5b12a61 135 operreason ? "|" : "", operreason ? operreason : "");
212380e3
AC
136 sendto_one(source_p, form_str(RPL_TESTLINE),
137 me.name, source_p->name,
138 (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'd' : 'D',
55abcbb2
KB
139 (aconf->flags & CONF_FLAGS_TEMPORARY) ?
140 (long) ((aconf->hold - rb_current_time()) / 60) : 0L,
e5b12a61 141 phost, reasonbuf);
212380e3 142
3c7d6fcc 143 return;
212380e3 144 }
83235e9e
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 '!',
0cce01d3 151 duration / 60L,
83235e9e
JT
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 '!',
0cce01d3 158 duration / 60L,
83235e9e 159 host, "Throttled");
212380e3
AC
160 }
161
162 if (username != NULL)
163 {
f427c8b0
VY
164 rb_strlcpy(user_trunc, username, sizeof user_trunc);
165 rb_strlcpy(notildeuser_trunc, *username == '~' ? username + 1 : username, sizeof notildeuser_trunc);
212380e3
AC
166 }
167 else
168 {
f427c8b0
VY
169 rb_strlcpy(user_trunc, "dummy", sizeof user_trunc);
170 rb_strlcpy(notildeuser_trunc, "dummy", sizeof notildeuser_trunc);
212380e3
AC
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) ? (
55abcbb2 176 (type == HM_IPV6) ? AF_INET6 :
40c1fd47 177 AF_INET) : 0, NULL)))
212380e3
AC
178 {
179 static char buf[HOSTLEN+USERLEN+2];
180
181 if(aconf->status & CONF_KILL)
182 {
1e57e391 183 get_printable_kline(source_p, aconf, &phost, &reason, &puser, &operreason);
5203cba5 184 snprintf(buf, sizeof(buf), "%s@%s",
1e57e391 185 puser, phost);
5203cba5 186 snprintf(reasonbuf, sizeof(reasonbuf), "%s%s%s", reason,
cb2540a6 187 operreason ? "|" : "", operreason ? operreason : "");
212380e3
AC
188 sendto_one(source_p, form_str(RPL_TESTLINE),
189 me.name, source_p->name,
190 (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'k' : 'K',
55abcbb2 191 (aconf->flags & CONF_FLAGS_TEMPORARY) ?
e3354945 192 (long) ((aconf->hold - rb_current_time()) / 60) : 0L,
cb2540a6 193 buf, reasonbuf);
3c7d6fcc 194 return;
212380e3 195 }
212380e3
AC
196 }
197
198 /* they asked us to check a nick, so hunt for resvs.. */
199 if(name && (resv_p = find_nick_resv(name)))
200 {
201 sendto_one(source_p, form_str(RPL_TESTLINE),
202 me.name, source_p->name,
203 resv_p->hold ? 'q' : 'Q',
e3354945 204 resv_p->hold ? (long) ((resv_p->hold - rb_current_time()) / 60) : 0L,
70ea02eb 205 resv_p->host, resv_p->passwd);
212380e3
AC
206
207 /* this is a false positive, so make sure it isn't counted in stats q
208 * --nenolod
209 */
210 resv_p->port--;
3c7d6fcc 211 return;
212380e3
AC
212 }
213
214 /* no matching resv, we can print the I: if it exists */
215 if(aconf && aconf->status & CONF_CLIENT)
216 {
217 sendto_one_numeric(source_p, RPL_STATSILINE, form_str(RPL_STATSILINE),
27f616dd 218 aconf->info.name, EmptyString(aconf->spasswd) ? "<NULL>" : aconf->spasswd,
59c3d09a 219 show_iline_prefix(source_p, aconf, aconf->user),
212380e3 220 aconf->host, aconf->port, aconf->className);
3c7d6fcc 221 return;
212380e3
AC
222 }
223
224 /* nothing matches.. */
225 sendto_one(source_p, form_str(RPL_NOTESTLINE),
226 me.name, source_p->name, parv[1]);
212380e3
AC
227}
228
3c7d6fcc 229static void
428ca87b 230mo_testgecos(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
231{
232 struct ConfItem *aconf;
233
234 if(!(aconf = find_xline(parv[1], 0)))
235 {
236 sendto_one(source_p, form_str(RPL_NOTESTLINE),
237 me.name, source_p->name, parv[1]);
3c7d6fcc 238 return;
212380e3
AC
239 }
240
241 sendto_one(source_p, form_str(RPL_TESTLINE),
242 me.name, source_p->name,
243 aconf->hold ? 'x' : 'X',
e3354945 244 aconf->hold ? (long) ((aconf->hold - rb_current_time()) / 60) : 0L,
70ea02eb 245 aconf->host, aconf->passwd);
212380e3 246}