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