ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_testline.c
Revision: 1156
Committed: Tue Aug 9 20:29:20 2011 UTC (14 years ago) by michael
Content type: text/x-csrc
File size: 7373 byte(s)
Log Message:
- create ircd-hybrid-8 "branch"

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 michael 593 static void mo_testline(struct Client *, struct Client *, int, char *[]);
44     static void mo_testgecos(struct Client *, struct Client *, int, char *[]);
45 adx 30
46     struct Message testline_msgtab = {
47     "TESTLINE", 0, 0, 0, 0, MFLG_SLOW, 0,
48 michael 593 { m_unregistered, m_not_oper, m_ignore, m_ignore, mo_testline, m_ignore }
49 adx 30 };
50    
51     struct Message testgecos_msgtab = {
52     "TESTGECOS", 0, 0, 0, 0, MFLG_SLOW, 0,
53 michael 593 { m_unregistered, m_not_oper, m_ignore, m_ignore, mo_testgecos, m_ignore }
54 adx 30 };
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 knight 31 const char *_version = "$Revision$";
71 adx 30
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 michael 593 /* 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 michael 808 char parv1_copy[IRCD_BUFSIZE];
93 adx 30 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 michael 593 struct split_nuh_item nuh;
101 adx 30
102 michael 593 if (EmptyString(parv[1]))
103 adx 30 {
104     sendto_one(source_p, ":%s NOTICE %s :usage: user@host|ip [password]",
105     me.name, source_p->name);
106     return;
107     }
108    
109 michael 593 if (IsChanPrefix(*parv[1])) /* Might be channel resv */
110     {
111     const struct ResvChannel *chptr = NULL;
112 adx 30
113 michael 593 if ((chptr = match_find_resv(parv[1])))
114 adx 30 {
115 michael 593 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 adx 30 return;
119     }
120     }
121    
122 michael 808 strlcpy(parv1_copy, parv[1], sizeof(parv1_copy));
123 adx 30
124 michael 593 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 db 136 t = parse_netmask(given_host, &ip, &host_mask);
136 adx 30
137     if (t != HM_HOST)
138     {
139     aconf = find_dline_conf(&ip,
140     #ifdef IPV6
141 michael 593 (t == HM_IPV6) ? AF_INET6 : AF_INET
142 adx 30 #else
143 michael 593 AF_INET
144 adx 30 #endif
145 michael 593 );
146 adx 30 if (aconf != NULL)
147     {
148 michael 808 ++matches;
149 adx 30 if (aconf->status & CONF_EXEMPTDLINE)
150 michael 593 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 adx 30 else
154 michael 593 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 adx 30 }
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 michael 808 me.name, source_p->name, 'I', 0L, userhost,
182 michael 593 aconf->class_ptr ? aconf->class_ptr->name : "<default>", "");
183 adx 30 ++matches;
184     }
185 db 150 else if (aconf->status & CONF_KILL)
186     {
187     sendto_one(source_p, form_str(RPL_TESTLINE),
188 michael 593 me.name, source_p->name,
189     IsConfTemporary(aconf) ? 'k' : 'K',
190     IsConfTemporary(aconf) ? ((aconf->hold - CurrentTime) / 60)
191     : 0L,
192 michael 808 userhost, aconf->reason? aconf->reason : "No reason",
193 michael 593 aconf->oper_reason ? aconf->oper_reason : "");
194 db 150 ++matches;
195     }
196 adx 30 }
197    
198     conf = find_matching_name_conf(NRESV_TYPE, given_name, NULL, NULL, 0);
199    
200     if (conf != NULL)
201     {
202 michael 808 const struct MatchItem *mconf = map_to_conf(conf);
203 adx 30
204     sendto_one(source_p, form_str(RPL_TESTLINE),
205 michael 808 me.name, source_p->name, 'Q', 0L,
206 michael 593 conf->name,
207     mconf->reason ? mconf->reason : "No reason",
208     mconf->oper_reason ? mconf->oper_reason : "");
209 adx 30 ++matches;
210     }
211    
212     if (matches == 0)
213     sendto_one(source_p, form_str(RPL_NOTESTLINE),
214 michael 808 me.name, source_p->name, parv1_copy);
215 adx 30 }
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 michael 808 int parc, char *parv[])
233 adx 30 {
234     struct ConfItem *conf = NULL;
235    
236 michael 593 if (EmptyString(parv[1]))
237 adx 30 {
238     sendto_one(source_p, ":%s NOTICE %s :usage: gecos",
239     me.name, source_p->name);
240     return;
241     }
242    
243 michael 593 if ((conf = find_matching_name_conf(XLINE_TYPE, parv[1], NULL, NULL, 0)))
244 adx 30 {
245 michael 808 const struct MatchItem *xconf = map_to_conf(conf);
246 adx 30 sendto_one(source_p, form_str(RPL_TESTLINE),
247 michael 593 me.name, source_p->name, 'X', 0L,
248     conf->name, xconf->reason ? xconf->reason : "X-lined",
249     xconf->oper_reason ? xconf->oper_reason : "");
250 adx 30 }
251     else
252     sendto_one(source_p, form_str(RPL_NOTESTLINE),
253 michael 593 me.name, source_p->name, parv[1]);
254 adx 30 }

Properties

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