ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_testline.c
Revision: 1230
Committed: Thu Sep 22 19:41:19 2011 UTC (13 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 7423 byte(s)
Log Message:
- cleanup module loader. Make module api more flexible

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

Properties

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