1 /* modules/m_testline.c
3 * Copyright (C) 2004 Lee Hardy <lee@leeh.co.uk>
4 * Copyright (C) 2004-2005 ircd-ratbox development team
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
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.
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.
30 * $Id: m_testline.c 3303 2007-03-28 15:22:49Z jilles $
41 #include "s_newconf.h"
44 static int mo_testline(struct Client
*, struct Client
*, int, const char **);
45 static int mo_testgecos(struct Client
*, struct Client
*, int, const char **);
47 struct Message testline_msgtab
= {
48 "TESTLINE", 0, 0, 0, MFLG_SLOW
,
49 {mg_unreg
, mg_ignore
, mg_ignore
, mg_ignore
, mg_ignore
, {mo_testline
, 2}}
51 struct Message testgecos_msgtab
= {
52 "TESTGECOS", 0, 0, 0, MFLG_SLOW
,
53 {mg_unreg
, mg_ignore
, mg_ignore
, mg_ignore
, mg_ignore
, {mo_testgecos
, 2}}
56 mapi_clist_av1 testline_clist
[] = { &testline_msgtab
, &testgecos_msgtab
, NULL
};
57 DECLARE_MODULE_AV1(testline
, NULL
, NULL
, testline_clist
, NULL
, NULL
, "$Revision: 3303 $");
60 mo_testline(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
62 struct ConfItem
*aconf
;
63 struct ConfItem
*resv_p
;
64 struct rb_sockaddr_storage ip
;
65 char user_trunc
[USERLEN
+ 1], notildeuser_trunc
[USERLEN
+ 1];
66 const char *name
= NULL
;
67 const char *username
= NULL
;
68 const char *host
= NULL
;
75 mask
= LOCAL_COPY(parv
[1]);
77 if (IsChannelName(mask
))
79 resv_p
= hash_find_resv(mask
);
82 sendto_one(source_p
, form_str(RPL_TESTLINE
),
83 me
.name
, source_p
->name
,
84 resv_p
->hold
? 'q' : 'Q',
85 resv_p
->hold
? (long) ((resv_p
->hold
- rb_current_time()) / 60) : 0L,
86 resv_p
->name
, resv_p
->passwd
);
87 /* this is a false positive, so make sure it isn't counted in stats q
93 sendto_one(source_p
, form_str(RPL_NOTESTLINE
),
94 me
.name
, source_p
->name
, parv
[1]);
98 if((p
= strchr(mask
, '!')))
104 if(EmptyString(mask
))
108 if((p
= strchr(mask
, '@')))
114 if(EmptyString(host
))
120 /* parses as an IP, check for a dline */
121 if((type
= parse_netmask(host
, (struct sockaddr
*)&ip
, &host_mask
)) != HM_HOST
)
125 aconf
= find_dline((struct sockaddr
*)&ip
, AF_INET6
);
128 aconf
= find_dline((struct sockaddr
*)&ip
, AF_INET
);
130 if(aconf
&& aconf
->status
& CONF_DLINE
)
132 sendto_one(source_p
, form_str(RPL_TESTLINE
),
133 me
.name
, source_p
->name
,
134 (aconf
->flags
& CONF_FLAGS_TEMPORARY
) ? 'd' : 'D',
135 (aconf
->flags
& CONF_FLAGS_TEMPORARY
) ?
136 (long) ((aconf
->hold
- rb_current_time()) / 60) : 0L,
137 aconf
->host
, aconf
->passwd
);
141 /* Otherwise, aconf is an exempt{} */
143 (duration
= is_reject_ip((struct sockaddr
*)&ip
)))
144 sendto_one(source_p
, form_str(RPL_TESTLINE
),
145 me
.name
, source_p
->name
,
148 host
, "Reject cache");
150 (duration
= is_throttle_ip((struct sockaddr
*)&ip
)))
151 sendto_one(source_p
, form_str(RPL_TESTLINE
),
152 me
.name
, source_p
->name
,
158 if (username
!= NULL
)
160 rb_strlcpy(user_trunc
, username
, sizeof user_trunc
);
161 rb_strlcpy(notildeuser_trunc
, *username
== '~' ? username
+ 1 : username
, sizeof notildeuser_trunc
);
165 rb_strlcpy(user_trunc
, "dummy", sizeof user_trunc
);
166 rb_strlcpy(notildeuser_trunc
, "dummy", sizeof notildeuser_trunc
);
168 /* now look for a matching I/K/G */
169 if((aconf
= find_address_conf(host
, NULL
, user_trunc
, notildeuser_trunc
,
170 (type
!= HM_HOST
) ? (struct sockaddr
*)&ip
: NULL
,
171 (type
!= HM_HOST
) ? (
173 (type
== HM_IPV6
) ? AF_INET6
:
175 AF_INET
) : 0, NULL
)))
177 static char buf
[HOSTLEN
+USERLEN
+2];
179 if(aconf
->status
& CONF_KILL
)
181 rb_snprintf(buf
, sizeof(buf
), "%s@%s",
182 aconf
->user
, aconf
->host
);
183 sendto_one(source_p
, form_str(RPL_TESTLINE
),
184 me
.name
, source_p
->name
,
185 (aconf
->flags
& CONF_FLAGS_TEMPORARY
) ? 'k' : 'K',
186 (aconf
->flags
& CONF_FLAGS_TEMPORARY
) ?
187 (long) ((aconf
->hold
- rb_current_time()) / 60) : 0L,
193 /* they asked us to check a nick, so hunt for resvs.. */
194 if(name
&& (resv_p
= find_nick_resv(name
)))
196 sendto_one(source_p
, form_str(RPL_TESTLINE
),
197 me
.name
, source_p
->name
,
198 resv_p
->hold
? 'q' : 'Q',
199 resv_p
->hold
? (long) ((resv_p
->hold
- rb_current_time()) / 60) : 0L,
200 resv_p
->name
, resv_p
->passwd
);
202 /* this is a false positive, so make sure it isn't counted in stats q
209 /* no matching resv, we can print the I: if it exists */
210 if(aconf
&& aconf
->status
& CONF_CLIENT
)
212 sendto_one_numeric(source_p
, RPL_STATSILINE
, form_str(RPL_STATSILINE
),
213 aconf
->name
, EmptyString(aconf
->spasswd
) ? "<NULL>" : aconf
->spasswd
,
214 show_iline_prefix(source_p
, aconf
, aconf
->user
),
215 aconf
->host
, aconf
->port
, aconf
->className
);
219 /* nothing matches.. */
220 sendto_one(source_p
, form_str(RPL_NOTESTLINE
),
221 me
.name
, source_p
->name
, parv
[1]);
226 mo_testgecos(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
228 struct ConfItem
*aconf
;
230 if(!(aconf
= find_xline(parv
[1], 0)))
232 sendto_one(source_p
, form_str(RPL_NOTESTLINE
),
233 me
.name
, source_p
->name
, parv
[1]);
237 sendto_one(source_p
, form_str(RPL_TESTLINE
),
238 me
.name
, source_p
->name
,
239 aconf
->hold
? 'x' : 'X',
240 aconf
->hold
? (long) ((aconf
->hold
- rb_current_time()) / 60) : 0L,
241 aconf
->name
, aconf
->passwd
);