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.
39 #include "s_newconf.h"
40 #include "sprintf_irc.h"
42 static int mo_testline(struct Client
*, struct Client
*, int, const char **);
43 static int mo_testgecos(struct Client
*, struct Client
*, int, const char **);
45 struct Message testline_msgtab
= {
46 "TESTLINE", 0, 0, 0, MFLG_SLOW
,
47 {mg_unreg
, mg_ignore
, mg_ignore
, mg_ignore
, mg_ignore
, {mo_testline
, 2}}
49 struct Message testgecos_msgtab
= {
50 "TESTGECOS", 0, 0, 0, MFLG_SLOW
,
51 {mg_unreg
, mg_ignore
, mg_ignore
, mg_ignore
, mg_ignore
, {mo_testgecos
, 2}}
54 mapi_clist_av1 testline_clist
[] = { &testline_msgtab
, &testgecos_msgtab
, NULL
};
55 DECLARE_MODULE_AV1(testline
, NULL
, NULL
, testline_clist
, NULL
, NULL
, "$Revision: 147 $");
58 mo_testline(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
60 struct ConfItem
*aconf
;
61 struct ConfItem
*resv_p
;
62 struct irc_sockaddr_storage ip
;
63 const char *name
= NULL
;
64 const char *username
= NULL
;
65 const char *host
= NULL
;
71 if(!IsOperStaffer(source_p
))
73 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "staffer");
77 mask
= LOCAL_COPY(parv
[1]);
79 if((p
= strchr(mask
, '!')))
89 if((p
= strchr(mask
, '@')))
101 /* parses as an IP, check for a dline */
102 if((type
= parse_netmask(host
, (struct sockaddr
*)&ip
, &host_mask
)) != HM_HOST
)
106 aconf
= find_dline((struct sockaddr
*)&ip
, AF_INET6
);
109 aconf
= find_dline((struct sockaddr
*)&ip
, AF_INET
);
111 if(aconf
&& aconf
->status
& CONF_DLINE
)
113 sendto_one(source_p
, form_str(RPL_TESTLINE
),
114 me
.name
, source_p
->name
,
115 (aconf
->flags
& CONF_FLAGS_TEMPORARY
) ? 'd' : 'D',
116 (aconf
->flags
& CONF_FLAGS_TEMPORARY
) ?
117 (long) ((aconf
->hold
- CurrentTime
) / 60) : 0L,
118 aconf
->host
, aconf
->passwd
);
124 /* now look for a matching I/K/G */
125 if((aconf
= find_address_conf(host
, NULL
, username
? username
: "dummy",
126 (type
!= HM_HOST
) ? (struct sockaddr
*)&ip
: NULL
,
127 (type
!= HM_HOST
) ? (
129 (type
== HM_IPV6
) ? AF_INET6
:
133 static char buf
[HOSTLEN
+USERLEN
+2];
135 if(aconf
->status
& CONF_KILL
)
137 ircsnprintf(buf
, sizeof(buf
), "%s@%s",
138 aconf
->user
, aconf
->host
);
139 sendto_one(source_p
, form_str(RPL_TESTLINE
),
140 me
.name
, source_p
->name
,
141 (aconf
->flags
& CONF_FLAGS_TEMPORARY
) ? 'k' : 'K',
142 (aconf
->flags
& CONF_FLAGS_TEMPORARY
) ?
143 (long) ((aconf
->hold
- CurrentTime
) / 60) : 0L,
149 /* they asked us to check a nick, so hunt for resvs.. */
150 if(name
&& (resv_p
= find_nick_resv(name
)))
152 sendto_one(source_p
, form_str(RPL_TESTLINE
),
153 me
.name
, source_p
->name
,
154 resv_p
->hold
? 'q' : 'Q',
155 resv_p
->hold
? (long) ((resv_p
->hold
- CurrentTime
) / 60) : 0L,
156 resv_p
->name
, resv_p
->passwd
);
158 /* this is a false positive, so make sure it isn't counted in stats q
165 /* no matching resv, we can print the I: if it exists */
166 if(aconf
&& aconf
->status
& CONF_CLIENT
)
168 sendto_one_numeric(source_p
, RPL_STATSILINE
, form_str(RPL_STATSILINE
),
169 aconf
->name
, show_iline_prefix(source_p
, aconf
, aconf
->user
),
170 aconf
->host
, aconf
->port
, aconf
->className
);
174 /* nothing matches.. */
175 sendto_one(source_p
, form_str(RPL_NOTESTLINE
),
176 me
.name
, source_p
->name
, parv
[1]);
181 mo_testgecos(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
183 struct ConfItem
*aconf
;
185 if(!IsOperStaffer(source_p
))
187 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "staffer");
191 if(!(aconf
= find_xline(parv
[1], 0)))
193 sendto_one(source_p
, form_str(RPL_NOTESTLINE
),
194 me
.name
, source_p
->name
, parv
[1]);
198 sendto_one(source_p
, form_str(RPL_TESTLINE
),
199 me
.name
, source_p
->name
,
200 aconf
->hold
? 'x' : 'X',
201 aconf
->hold
? (long) ((aconf
->hold
- CurrentTime
) / 60) : 0L,
202 aconf
->name
, aconf
->passwd
);