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

File Contents

# User Rev Content
1 adx 30 /*
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 knight 31 * $Id$
23 adx 30 */
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 michael 593 /* 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 michael 808 char parv1_copy[IRCD_BUFSIZE];
65 adx 30 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 michael 593 struct split_nuh_item nuh;
73 adx 30
74 michael 593 if (EmptyString(parv[1]))
75 adx 30 {
76     sendto_one(source_p, ":%s NOTICE %s :usage: user@host|ip [password]",
77     me.name, source_p->name);
78     return;
79     }
80    
81 michael 593 if (IsChanPrefix(*parv[1])) /* Might be channel resv */
82     {
83     const struct ResvChannel *chptr = NULL;
84 adx 30
85 michael 593 if ((chptr = match_find_resv(parv[1])))
86 adx 30 {
87 michael 593 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 adx 30 return;
91     }
92     }
93    
94 michael 808 strlcpy(parv1_copy, parv[1], sizeof(parv1_copy));
95 adx 30
96 michael 593 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 db 136 t = parse_netmask(given_host, &ip, &host_mask);
108 adx 30
109     if (t != HM_HOST)
110     {
111     aconf = find_dline_conf(&ip,
112     #ifdef IPV6
113 michael 593 (t == HM_IPV6) ? AF_INET6 : AF_INET
114 adx 30 #else
115 michael 593 AF_INET
116 adx 30 #endif
117 michael 593 );
118 adx 30 if (aconf != NULL)
119     {
120 michael 808 ++matches;
121 adx 30 if (aconf->status & CONF_EXEMPTDLINE)
122 michael 593 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 adx 30 else
126 michael 593 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 adx 30 }
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 michael 808 me.name, source_p->name, 'I', 0L, userhost,
154 michael 593 aconf->class_ptr ? aconf->class_ptr->name : "<default>", "");
155 adx 30 ++matches;
156     }
157 db 150 else if (aconf->status & CONF_KILL)
158     {
159     sendto_one(source_p, form_str(RPL_TESTLINE),
160 michael 593 me.name, source_p->name,
161     IsConfTemporary(aconf) ? 'k' : 'K',
162     IsConfTemporary(aconf) ? ((aconf->hold - CurrentTime) / 60)
163     : 0L,
164 michael 808 userhost, aconf->reason? aconf->reason : "No reason",
165 michael 593 aconf->oper_reason ? aconf->oper_reason : "");
166 db 150 ++matches;
167     }
168 adx 30 }
169    
170     conf = find_matching_name_conf(NRESV_TYPE, given_name, NULL, NULL, 0);
171    
172     if (conf != NULL)
173     {
174 michael 808 const struct MatchItem *mconf = map_to_conf(conf);
175 adx 30
176     sendto_one(source_p, form_str(RPL_TESTLINE),
177 michael 808 me.name, source_p->name, 'Q', 0L,
178 michael 593 conf->name,
179     mconf->reason ? mconf->reason : "No reason",
180     mconf->oper_reason ? mconf->oper_reason : "");
181 adx 30 ++matches;
182     }
183    
184     if (matches == 0)
185     sendto_one(source_p, form_str(RPL_NOTESTLINE),
186 michael 808 me.name, source_p->name, parv1_copy);
187 adx 30 }
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 michael 808 int parc, char *parv[])
205 adx 30 {
206     struct ConfItem *conf = NULL;
207    
208 michael 593 if (EmptyString(parv[1]))
209 adx 30 {
210     sendto_one(source_p, ":%s NOTICE %s :usage: gecos",
211     me.name, source_p->name);
212     return;
213     }
214    
215 michael 593 if ((conf = find_matching_name_conf(XLINE_TYPE, parv[1], NULL, NULL, 0)))
216 adx 30 {
217 michael 808 const struct MatchItem *xconf = map_to_conf(conf);
218 adx 30 sendto_one(source_p, form_str(RPL_TESTLINE),
219 michael 593 me.name, source_p->name, 'X', 0L,
220     conf->name, xconf->reason ? xconf->reason : "X-lined",
221     xconf->oper_reason ? xconf->oper_reason : "");
222 adx 30 }
223     else
224     sendto_one(source_p, form_str(RPL_NOTESTLINE),
225 michael 593 me.name, source_p->name, parv[1]);
226 adx 30 }
227 michael 1230
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