ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_testline.c
Revision: 357
Committed: Thu Jan 5 16:06:45 2006 UTC (20 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 7801 byte(s)
Log Message:
- Mainly re-wrote split_nuh() to fix a regexp kline bug where we would cut off
  the user portion after 9 chars, but also to be a bit more flexible when we
  have to deal with different user/host name lengths.
- Re-wrote m_capture() to use split_nuh()

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_testline.c: Tests a hostmask to see what will happen to it.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "handlers.h"
27 #include "client.h"
28 #include "common.h"
29 #include "ircd_defs.h"
30 #include "ircd.h"
31 #include "restart.h"
32 #include "s_conf.h"
33 #include "send.h"
34 #include "msg.h"
35 #include "hostmask.h"
36 #include "numeric.h"
37 #include "parse.h"
38 #include "resv.h"
39 #include "hash.h"
40 #include "modules.h"
41
42 static void mo_testline(struct Client *, struct Client *, int, char *[]);
43 static void mo_testgecos(struct Client *, struct Client *, int, char *[]);
44
45 struct Message testline_msgtab = {
46 "TESTLINE", 0, 0, 0, 0, MFLG_SLOW, 0,
47 {m_unregistered, m_not_oper, m_ignore, m_ignore, mo_testline, m_ignore}
48 };
49
50 struct Message testgecos_msgtab = {
51 "TESTGECOS", 0, 0, 0, 0, MFLG_SLOW, 0,
52 {m_unregistered, m_not_oper, m_ignore, m_ignore, mo_testgecos, m_ignore}
53 };
54
55 #ifndef STATIC_MODULES
56 void
57 _modinit(void)
58 {
59 mod_add_cmd(&testline_msgtab);
60 mod_add_cmd(&testgecos_msgtab);
61 }
62
63 void
64 _moddeinit(void)
65 {
66 mod_del_cmd(&testline_msgtab);
67 mod_del_cmd(&testgecos_msgtab);
68 }
69
70 const char *_version = "$Revision$";
71 #endif
72
73 /* mo_testline()
74 *
75 * inputs - pointer to physical connection request is coming from
76 * - pointer to source connection request is coming from
77 * - parc arg count
78 * - parv actual arguments
79 *
80 * output - NONE
81 * side effects - command to test I/K lines on server
82 *
83 * i.e. /quote testline user@host,ip [password]
84 *
85 */
86 static void
87 mo_testline(struct Client *client_p, struct Client *source_p,
88 int parc, char *parv[])
89 {
90 char *orig_parv1 = NULL;
91 /* IRCD_BUFSIZE to allow things like *u*s*e*r*n*a*m*e* etc. */
92 char given_name[IRCD_BUFSIZE];
93 char given_host[IRCD_BUFSIZE];
94 struct ConfItem *conf;
95 struct AccessItem *aconf;
96 struct irc_ssaddr ip;
97 int host_mask;
98 int t;
99 int matches = 0;
100 char userhost[HOSTLEN + USERLEN + 2];
101 struct split_nuh_item nuh;
102
103 if (EmptyString(parv[1]))
104 {
105 sendto_one(source_p, ":%s NOTICE %s :usage: user@host|ip [password]",
106 me.name, source_p->name);
107 return;
108 }
109
110 if (IsChanPrefix(*parv[1])) /* Might be channel resv */
111 {
112 struct ResvChannel *chptr;
113
114 chptr = match_find_resv(parv[1]);
115 if (chptr != NULL)
116 {
117 sendto_one(source_p,
118 form_str(RPL_TESTLINE),
119 me.name, source_p->name,
120 'Q', 0, chptr->name,
121 chptr->reason ? chptr->reason : "No reason", "" );
122 return;
123 }
124 }
125
126 DupString(orig_parv1, parv[1]);
127
128 nuh.nuhmask = parv[1];
129 nuh.nickptr = NULL;
130 nuh.userptr = given_name;
131 nuh.hostptr = given_host;
132
133 nuh.nicksize = 0;
134 nuh.usersize = sizeof(given_name);
135 nuh.hostsize = sizeof(given_host);
136
137 split_nuh(&nuh);
138
139 t = parse_netmask(given_host, &ip, &host_mask);
140
141 if (t != HM_HOST)
142 {
143 aconf = find_dline_conf(&ip,
144 #ifdef IPV6
145 (t == HM_IPV6) ? AF_INET6 : AF_INET
146 #else
147 AF_INET
148 #endif
149 );
150 if (aconf != NULL)
151 {
152 conf = aconf->conf_ptr;
153
154 if (aconf->status & CONF_EXEMPTDLINE)
155 {
156 sendto_one(source_p,
157 ":%s NOTICE %s :Exempt D-line host [%s] reason [%s]",
158 me.name, source_p->name, aconf->host, aconf->reason);
159 ++matches;
160 }
161 else
162 {
163 sendto_one(source_p,
164 form_str(RPL_TESTLINE),
165 me.name, source_p->name,
166 IsConfTemporary(aconf) ? 'd' : 'D',
167 IsConfTemporary(aconf) ? ((aconf->hold - CurrentTime) / 60)
168 : 0L,
169 aconf->host, aconf->reason, aconf->oper_reason);
170 ++matches;
171 }
172 }
173 }
174
175 aconf = find_kline_conf(given_host, given_name, &ip, t);
176 if ((aconf != NULL) && (aconf->status & CONF_KILL))
177 {
178 snprintf(userhost, sizeof(userhost), "%s@%s", aconf->user, aconf->host);
179 sendto_one(source_p, form_str(RPL_TESTLINE),
180 me.name, source_p->name,
181 IsConfTemporary(aconf) ? 'k' : 'K',
182 IsConfTemporary(aconf) ? ((aconf->hold - CurrentTime) / 60)
183 : 0L,
184 userhost,
185 aconf->passwd ? aconf->passwd : "No reason",
186 aconf->oper_reason ? aconf->oper_reason : "");
187 ++matches;
188 }
189
190
191 if (t != HM_HOST)
192 aconf = find_address_conf(given_host, given_name, &ip,
193 #ifdef IPV6
194 (t == HM_IPV6) ? AF_INET6 : AF_INET,
195 #else
196 AF_INET,
197 #endif
198 parv[2]);
199 else
200 aconf = find_address_conf(given_host, given_name, NULL, 0, parv[2]);
201
202 if (aconf != NULL)
203 {
204 conf = aconf->conf_ptr;
205
206 snprintf(userhost, sizeof(userhost), "%s@%s", aconf->user, aconf->host);
207
208 if (aconf->status & CONF_CLIENT)
209 {
210 sendto_one(source_p, form_str(RPL_TESTLINE),
211 me.name, source_p->name,
212 'I', 0L, userhost,
213 aconf->class_ptr ? aconf->class_ptr->name : "<default>", "");
214 ++matches;
215 }
216 else if (aconf->status & CONF_KILL)
217 {
218 sendto_one(source_p, form_str(RPL_TESTLINE),
219 me.name, source_p->name,
220 IsConfTemporary(aconf) ? 'k' : 'K',
221 IsConfTemporary(aconf) ? ((aconf->hold - CurrentTime) / 60)
222 : 0L,
223 userhost, aconf->passwd ? aconf->passwd : "No reason",
224 aconf->oper_reason ? aconf->oper_reason : "");
225 ++matches;
226 }
227 }
228
229 conf = find_matching_name_conf(NRESV_TYPE, given_name, NULL, NULL, 0);
230
231 if (conf != NULL)
232 {
233 struct MatchItem *mconf = &conf->conf.MatchItem;
234
235 sendto_one(source_p, form_str(RPL_TESTLINE),
236 me.name, source_p->name,
237 'Q', 0L,
238 conf->name,
239 mconf->reason ? mconf->reason : "No reason",
240 mconf->oper_reason ? mconf->oper_reason : "");
241 ++matches;
242 }
243
244 if (matches == 0)
245 sendto_one(source_p, form_str(RPL_NOTESTLINE),
246 me.name, source_p->name, orig_parv1);
247
248 MyFree(orig_parv1);
249 }
250
251 /* mo_testgecos()
252 *
253 * inputs - pointer to physical connection request is coming from
254 * - pointer to source connection request is coming from
255 * - parc arg count
256 * - parv actual arguments
257 *
258 * output - always 0
259 * side effects - command to test X lines on server
260 *
261 * i.e. /quote testgecos gecos
262 *
263 */
264 static void
265 mo_testgecos(struct Client *client_p, struct Client *source_p,
266 int parc, char *parv[])
267 {
268 struct ConfItem *conf = NULL;
269 struct MatchItem *xconf = NULL;
270
271 if (EmptyString(parv[1]))
272 {
273 sendto_one(source_p, ":%s NOTICE %s :usage: gecos",
274 me.name, source_p->name);
275 return;
276 }
277
278 if ((conf = find_matching_name_conf(XLINE_TYPE, parv[1],
279 NULL, NULL, 0)) != NULL)
280 {
281 xconf = &conf->conf.MatchItem;
282 sendto_one(source_p, form_str(RPL_TESTLINE),
283 me.name, source_p->name, 'X', 0L,
284 conf->name, xconf->reason ? xconf->reason : "X-lined",
285 xconf->oper_reason ? xconf->oper_reason : "");
286 }
287 else
288 sendto_one(source_p, form_str(RPL_NOTESTLINE),
289 me.name, source_p->name, parv[1]);
290 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision