]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_testline.c
[svn] Merge old trunk r2817:
[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 *
30 * $Id: m_testline.c 2757 2006-11-10 22:58:15Z jilles $
31 */
32#include "stdinc.h"
33#include "tools.h"
34#include "send.h"
35#include "client.h"
36#include "modules.h"
37#include "msg.h"
38#include "hostmask.h"
39#include "numeric.h"
40#include "s_conf.h"
41#include "s_newconf.h"
42#include "sprintf_irc.h"
43
44static int mo_testline(struct Client *, struct Client *, int, const char **);
45static int mo_testgecos(struct Client *, struct Client *, int, const char **);
46
47struct Message testline_msgtab = {
48 "TESTLINE", 0, 0, 0, MFLG_SLOW,
49 {mg_unreg, mg_ignore, mg_ignore, mg_ignore, mg_ignore, {mo_testline, 2}}
50};
51struct Message testgecos_msgtab = {
52 "TESTGECOS", 0, 0, 0, MFLG_SLOW,
53 {mg_unreg, mg_ignore, mg_ignore, mg_ignore, mg_ignore, {mo_testgecos, 2}}
54};
55
56mapi_clist_av1 testline_clist[] = { &testline_msgtab, &testgecos_msgtab, NULL };
57DECLARE_MODULE_AV1(testline, NULL, NULL, testline_clist, NULL, NULL, "$Revision: 2757 $");
58
59static int
60mo_testline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
61{
62 struct ConfItem *aconf;
63 struct ConfItem *resv_p;
64 struct irc_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;
69 char *mask;
70 char *p;
71 int host_mask;
72 int type;
73
74 mask = LOCAL_COPY(parv[1]);
75
76 if((p = strchr(mask, '!')))
77 {
78 *p++ = '\0';
79 name = mask;
80 mask = p;
81
82 if(EmptyString(mask))
83 return 0;
84 }
85
86 if((p = strchr(mask, '@')))
87 {
88 *p++ = '\0';
89 username = mask;
90 host = p;
91
92 if(EmptyString(host))
93 return 0;
94 }
95 else
96 host = mask;
97
98 /* parses as an IP, check for a dline */
99 if((type = parse_netmask(host, (struct sockaddr *)&ip, &host_mask)) != HM_HOST)
100 {
101#ifdef IPV6
102 if(type == HM_IPV6)
103 aconf = find_dline((struct sockaddr *)&ip, AF_INET6);
104 else
105#endif
106 aconf = find_dline((struct sockaddr *)&ip, AF_INET);
107
108 if(aconf && aconf->status & CONF_DLINE)
109 {
110 sendto_one(source_p, form_str(RPL_TESTLINE),
111 me.name, source_p->name,
112 (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'd' : 'D',
113 (aconf->flags & CONF_FLAGS_TEMPORARY) ?
114 (long) ((aconf->hold - CurrentTime) / 60) : 0L,
115 aconf->host, aconf->passwd);
116
117 return 0;
118 }
119 }
120
121 if (username != NULL)
122 {
123 strlcpy(user_trunc, username, sizeof user_trunc);
124 strlcpy(notildeuser_trunc, *username == '~' ? username + 1 : username, sizeof notildeuser_trunc);
125 }
126 else
127 {
128 strlcpy(user_trunc, "dummy", sizeof user_trunc);
129 strlcpy(notildeuser_trunc, "dummy", sizeof notildeuser_trunc);
130 }
131 /* now look for a matching I/K/G */
132 if((aconf = find_address_conf(host, NULL, user_trunc, notildeuser_trunc,
133 (type != HM_HOST) ? (struct sockaddr *)&ip : NULL,
134 (type != HM_HOST) ? (
135#ifdef IPV6
136 (type == HM_IPV6) ? AF_INET6 :
137#endif
138 AF_INET) : 0)))
139 {
140 static char buf[HOSTLEN+USERLEN+2];
141
142 if(aconf->status & CONF_KILL)
143 {
144 ircsnprintf(buf, sizeof(buf), "%s@%s",
145 aconf->user, aconf->host);
146 sendto_one(source_p, form_str(RPL_TESTLINE),
147 me.name, source_p->name,
148 (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'k' : 'K',
149 (aconf->flags & CONF_FLAGS_TEMPORARY) ?
150 (long) ((aconf->hold - CurrentTime) / 60) : 0L,
151 buf, aconf->passwd);
152 return 0;
153 }
154 else if(aconf->status & CONF_GLINE)
155 {
156 ircsnprintf(buf, sizeof(buf), "%s@%s",
157 aconf->user, aconf->host);
158 sendto_one(source_p, form_str(RPL_TESTLINE),
159 me.name, source_p->name,
160 'G', (long) ((aconf->hold - CurrentTime) / 60),
161 buf, aconf->passwd);
162 return 0;
163 }
164 }
165
166 /* they asked us to check a nick, so hunt for resvs.. */
167 if(name && (resv_p = find_nick_resv(name)))
168 {
169 sendto_one(source_p, form_str(RPL_TESTLINE),
170 me.name, source_p->name,
171 resv_p->hold ? 'q' : 'Q',
172 resv_p->hold ? (long) ((resv_p->hold - CurrentTime) / 60) : 0L,
173 resv_p->name, resv_p->passwd);
174
175 /* this is a false positive, so make sure it isn't counted in stats q
176 * --nenolod
177 */
178 resv_p->port--;
179 return 0;
180 }
181
182 /* no matching resv, we can print the I: if it exists */
183 if(aconf && aconf->status & CONF_CLIENT)
184 {
185 sendto_one_numeric(source_p, RPL_STATSILINE, form_str(RPL_STATSILINE),
186 aconf->name, show_iline_prefix(source_p, aconf, aconf->user),
187 aconf->host, aconf->port, aconf->className);
188 return 0;
189 }
190
191 /* nothing matches.. */
192 sendto_one(source_p, form_str(RPL_NOTESTLINE),
193 me.name, source_p->name, parv[1]);
194 return 0;
195}
196
197static int
198mo_testgecos(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
199{
200 struct ConfItem *aconf;
201
202 if(!(aconf = find_xline(parv[1], 0)))
203 {
204 sendto_one(source_p, form_str(RPL_NOTESTLINE),
205 me.name, source_p->name, parv[1]);
206 return 0;
207 }
208
209 sendto_one(source_p, form_str(RPL_TESTLINE),
210 me.name, source_p->name,
211 aconf->hold ? 'x' : 'X',
212 aconf->hold ? (long) ((aconf->hold - CurrentTime) / 60) : 0L,
213 aconf->name, aconf->passwd);
214 return 0;
215}