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