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