ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_testline.c
Revision: 69
Committed: Tue Oct 4 16:09:51 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-csrc
File size: 7203 byte(s)
Log Message:
- splitted ircd/libio, all headers connected with libio sources have been
  moved for internal use only. To use libio interface, include "libio.h"
  (which is already done in "stdinc.h")


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 "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 knight 31 const char *_version = "$Revision$";
71 adx 30 #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 *given_name, *p;
91     const char *given_host = NULL;
92     struct ConfItem *conf;
93     struct AccessItem *aconf;
94     struct irc_ssaddr ip;
95     int host_mask;
96     int t;
97     int matches = 0;
98     char userhost[HOSTLEN + USERLEN + 2];
99    
100     if (parc < 2 || EmptyString(parv[1]))
101     {
102     sendto_one(source_p, ":%s NOTICE %s :usage: user@host|ip [password]",
103     me.name, source_p->name);
104     return;
105     }
106    
107     given_name = parv[1];
108    
109     if (IsChanPrefix(*given_name)) /* Might be channel resv */
110     {
111     struct ResvChannel *chptr;
112    
113     chptr = match_find_resv(given_name);
114     if (chptr != NULL)
115     {
116     sendto_one(source_p,
117     form_str(RPL_TESTLINE),
118     me.name, source_p->name,
119     'Q', 0, chptr->name,
120     chptr->reason ? chptr->reason : "No reason", "" );
121     return;
122     }
123     }
124    
125     if ((p = strchr(given_name, '@')) != NULL)
126     {
127     *p++ = '\0';
128     given_host = p;
129     }
130     else
131     given_host = "*";
132    
133     t = parse_netmask(given_name, &ip, &host_mask);
134    
135     if (t != HM_HOST)
136     {
137     aconf = find_dline_conf(&ip,
138     #ifdef IPV6
139     (t == HM_IPV6) ? AF_INET6 : AF_INET
140     #else
141     AF_INET
142     #endif
143     );
144     if (aconf != NULL)
145     {
146     conf = unmap_conf_item(aconf);
147    
148     if (aconf->status & CONF_EXEMPTDLINE)
149     {
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     ++matches;
154     }
155     else
156     {
157     sendto_one(source_p,
158     form_str(RPL_TESTLINE),
159     me.name, source_p->name,
160     IsConfTemporary(aconf) ? 'd' : 'D',
161     IsConfTemporary(aconf) ? ((aconf->hold - CurrentTime) / 60)
162     : 0L,
163     aconf->host, aconf->reason, aconf->oper_reason);
164     ++matches;
165     }
166     }
167     }
168    
169     aconf = find_kline_conf(given_host, given_name, &ip, t);
170     if ((aconf != NULL) && (aconf->status & CONF_KILL))
171     {
172     snprintf(userhost, sizeof(userhost), "%s@%s", aconf->user, aconf->host);
173     sendto_one(source_p, form_str(RPL_TESTLINE),
174     me.name, source_p->name,
175     IsConfTemporary(aconf) ? 'k' : 'K',
176     IsConfTemporary(aconf) ? ((aconf->hold - CurrentTime) / 60)
177     : 0L,
178     userhost,
179     aconf->passwd ? aconf->passwd : "No reason",
180     aconf->oper_reason ? aconf->oper_reason : "");
181     ++matches;
182     }
183    
184    
185     if (t != HM_HOST)
186     aconf = find_address_conf(given_host, given_name, &ip,
187     #ifdef IPV6
188     (t == HM_IPV6) ? AF_INET6 : AF_INET,
189     #else
190     AF_INET,
191     #endif
192     parv[2]);
193     else
194     aconf = find_address_conf(given_host, given_name, NULL, 0, parv[2]);
195    
196     if (aconf != NULL)
197     {
198     conf = unmap_conf_item(aconf);
199    
200     snprintf(userhost, sizeof(userhost), "%s@%s", aconf->user, aconf->host);
201    
202     if (aconf->status & CONF_CLIENT)
203     {
204     sendto_one(source_p, form_str(RPL_TESTLINE),
205     me.name, source_p->name,
206     'I', 0L, userhost,
207     aconf->class_ptr ? aconf->class_ptr->name : "<default>", "");
208     ++matches;
209     }
210     }
211    
212     conf = find_matching_name_conf(NRESV_TYPE, given_name, NULL, NULL, 0);
213    
214     if (conf != NULL)
215     {
216     struct MatchItem *mconf;
217     mconf = (struct MatchItem *)map_to_conf(conf);
218    
219     sendto_one(source_p, form_str(RPL_TESTLINE),
220     me.name, source_p->name,
221     'Q', 0L,
222     conf->name,
223     mconf->reason ? mconf->reason : "No reason",
224     mconf->oper_reason ? mconf->oper_reason : "");
225     ++matches;
226     }
227    
228     if (matches == 0)
229     sendto_one(source_p, form_str(RPL_NOTESTLINE),
230     me.name, source_p->name, parv[1]);
231     }
232    
233     /* mo_testgecos()
234     *
235     * inputs - pointer to physical connection request is coming from
236     * - pointer to source connection request is coming from
237     * - parc arg count
238     * - parv actual arguments
239     *
240     * output - always 0
241     * side effects - command to test X lines on server
242     *
243     * i.e. /quote testgecos gecos
244     *
245     */
246     static void
247     mo_testgecos(struct Client *client_p, struct Client *source_p,
248     int parc, char *parv[])
249     {
250     struct ConfItem *conf = NULL;
251     struct MatchItem *xconf = NULL;
252     const char *gecos_name = NULL;
253    
254     if (parc < 2 || EmptyString(parv[1]))
255     {
256     sendto_one(source_p, ":%s NOTICE %s :usage: gecos",
257     me.name, source_p->name);
258     return;
259     }
260    
261     gecos_name = parv[1];
262    
263     if ((conf = find_matching_name_conf(XLINE_TYPE, gecos_name, NULL, NULL, 0))
264     != NULL)
265     {
266     xconf = (struct MatchItem *)map_to_conf(conf);
267     sendto_one(source_p, form_str(RPL_TESTLINE),
268     me.name, source_p->name, 'X', 0L,
269     conf->name, xconf->reason ? xconf->reason : "X-lined",
270     xconf->oper_reason ? xconf->oper_reason : "");
271     }
272     else
273     sendto_one(source_p, form_str(RPL_NOTESTLINE),
274     me.name, source_p->name, parv[1]);
275     }

Properties

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