ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_testline.c
Revision: 1155
Committed: Tue Aug 9 20:27:45 2011 UTC (14 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 7373 byte(s)
Log Message:
- recreate "trunk"

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 "irc_string.h"
30 #include "ircd_defs.h"
31 #include "ircd.h"
32 #include "restart.h"
33 #include "s_conf.h"
34 #include "send.h"
35 #include "msg.h"
36 #include "hostmask.h"
37 #include "numeric.h"
38 #include "parse.h"
39 #include "resv.h"
40 #include "hash.h"
41 #include "modules.h"
42
43 static void mo_testline(struct Client *, struct Client *, int, char *[]);
44 static void mo_testgecos(struct Client *, struct Client *, int, char *[]);
45
46 struct Message testline_msgtab = {
47 "TESTLINE", 0, 0, 0, 0, MFLG_SLOW, 0,
48 { m_unregistered, m_not_oper, m_ignore, m_ignore, mo_testline, m_ignore }
49 };
50
51 struct Message testgecos_msgtab = {
52 "TESTGECOS", 0, 0, 0, 0, MFLG_SLOW, 0,
53 { m_unregistered, m_not_oper, m_ignore, m_ignore, mo_testgecos, m_ignore }
54 };
55
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
72 /* mo_testline()
73 *
74 * inputs - pointer to physical connection request is coming from
75 * - pointer to source connection request is coming from
76 * - parc arg count
77 * - parv actual arguments
78 *
79 * output - NONE
80 * side effects - command to test I/K lines on server
81 *
82 * i.e. /quote testline user@host,ip [password]
83 *
84 */
85 static void
86 mo_testline(struct Client *client_p, struct Client *source_p,
87 int parc, char *parv[])
88 {
89 /* IRCD_BUFSIZE to allow things like *u*s*e*r*n*a*m*e* etc. */
90 char given_name[IRCD_BUFSIZE];
91 char given_host[IRCD_BUFSIZE];
92 char parv1_copy[IRCD_BUFSIZE];
93 struct ConfItem *conf;
94 struct AccessItem *aconf;
95 struct irc_ssaddr ip;
96 int host_mask;
97 int t;
98 int matches = 0;
99 char userhost[HOSTLEN + USERLEN + 2];
100 struct split_nuh_item nuh;
101
102 if (EmptyString(parv[1]))
103 {
104 sendto_one(source_p, ":%s NOTICE %s :usage: user@host|ip [password]",
105 me.name, source_p->name);
106 return;
107 }
108
109 if (IsChanPrefix(*parv[1])) /* Might be channel resv */
110 {
111 const struct ResvChannel *chptr = NULL;
112
113 if ((chptr = match_find_resv(parv[1])))
114 {
115 sendto_one(source_p, form_str(RPL_TESTLINE),
116 me.name, source_p->name, 'Q', 0, chptr->name,
117 chptr->reason ? chptr->reason : "No reason", "");
118 return;
119 }
120 }
121
122 strlcpy(parv1_copy, parv[1], sizeof(parv1_copy));
123
124 nuh.nuhmask = parv[1];
125 nuh.nickptr = NULL;
126 nuh.userptr = given_name;
127 nuh.hostptr = given_host;
128
129 nuh.nicksize = 0;
130 nuh.usersize = sizeof(given_name);
131 nuh.hostsize = sizeof(given_host);
132
133 split_nuh(&nuh);
134
135 t = parse_netmask(given_host, &ip, &host_mask);
136
137 if (t != HM_HOST)
138 {
139 aconf = find_dline_conf(&ip,
140 #ifdef IPV6
141 (t == HM_IPV6) ? AF_INET6 : AF_INET
142 #else
143 AF_INET
144 #endif
145 );
146 if (aconf != NULL)
147 {
148 ++matches;
149 if (aconf->status & CONF_EXEMPTDLINE)
150 sendto_one(source_p,
151 ":%s NOTICE %s :Exempt D-line host [%s] reason [%s]",
152 me.name, source_p->name, aconf->host, aconf->reason);
153 else
154 sendto_one(source_p, form_str(RPL_TESTLINE),
155 me.name, source_p->name,
156 IsConfTemporary(aconf) ? 'd' : 'D',
157 IsConfTemporary(aconf) ? ((aconf->hold - CurrentTime) / 60)
158 : 0L,
159 aconf->host, aconf->reason, aconf->oper_reason);
160 }
161 }
162
163 if (t != HM_HOST)
164 aconf = find_address_conf(given_host, given_name, &ip,
165 #ifdef IPV6
166 (t == HM_IPV6) ? AF_INET6 : AF_INET,
167 #else
168 AF_INET,
169 #endif
170 parv[2]);
171 else
172 aconf = find_address_conf(given_host, given_name, NULL, 0, parv[2]);
173
174 if (aconf != NULL)
175 {
176 snprintf(userhost, sizeof(userhost), "%s@%s", aconf->user, aconf->host);
177
178 if (aconf->status & CONF_CLIENT)
179 {
180 sendto_one(source_p, form_str(RPL_TESTLINE),
181 me.name, source_p->name, 'I', 0L, userhost,
182 aconf->class_ptr ? aconf->class_ptr->name : "<default>", "");
183 ++matches;
184 }
185 else if (aconf->status & CONF_KILL)
186 {
187 sendto_one(source_p, form_str(RPL_TESTLINE),
188 me.name, source_p->name,
189 IsConfTemporary(aconf) ? 'k' : 'K',
190 IsConfTemporary(aconf) ? ((aconf->hold - CurrentTime) / 60)
191 : 0L,
192 userhost, aconf->reason? aconf->reason : "No reason",
193 aconf->oper_reason ? aconf->oper_reason : "");
194 ++matches;
195 }
196 }
197
198 conf = find_matching_name_conf(NRESV_TYPE, given_name, NULL, NULL, 0);
199
200 if (conf != NULL)
201 {
202 const struct MatchItem *mconf = map_to_conf(conf);
203
204 sendto_one(source_p, form_str(RPL_TESTLINE),
205 me.name, source_p->name, 'Q', 0L,
206 conf->name,
207 mconf->reason ? mconf->reason : "No reason",
208 mconf->oper_reason ? mconf->oper_reason : "");
209 ++matches;
210 }
211
212 if (matches == 0)
213 sendto_one(source_p, form_str(RPL_NOTESTLINE),
214 me.name, source_p->name, parv1_copy);
215 }
216
217 /* mo_testgecos()
218 *
219 * inputs - pointer to physical connection request is coming from
220 * - pointer to source connection request is coming from
221 * - parc arg count
222 * - parv actual arguments
223 *
224 * output - always 0
225 * side effects - command to test X lines on server
226 *
227 * i.e. /quote testgecos gecos
228 *
229 */
230 static void
231 mo_testgecos(struct Client *client_p, struct Client *source_p,
232 int parc, char *parv[])
233 {
234 struct ConfItem *conf = NULL;
235
236 if (EmptyString(parv[1]))
237 {
238 sendto_one(source_p, ":%s NOTICE %s :usage: gecos",
239 me.name, source_p->name);
240 return;
241 }
242
243 if ((conf = find_matching_name_conf(XLINE_TYPE, parv[1], NULL, NULL, 0)))
244 {
245 const struct MatchItem *xconf = map_to_conf(conf);
246 sendto_one(source_p, form_str(RPL_TESTLINE),
247 me.name, source_p->name, 'X', 0L,
248 conf->name, xconf->reason ? xconf->reason : "X-lined",
249 xconf->oper_reason ? xconf->oper_reason : "");
250 }
251 else
252 sendto_one(source_p, form_str(RPL_NOTESTLINE),
253 me.name, source_p->name, parv[1]);
254 }

Properties

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