ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_testline.c
Revision: 808
Committed: Sun Sep 3 18:58:00 2006 UTC (18 years, 11 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/modules/m_testline.c
File size: 7403 byte(s)
Log Message:
- Misc. fixes to TESTMASK/TESTLINE as reported by Phar Lap
  - Prevent TESTLINE from reporting k-lines twice
  - Show the actual k-line reason when reporting k-lines
  - Test the host part of a u@h mask against the client's sockhost field in TESTMASK
  - Added support for nick masks to TESTMASK
  - CIDR is to come in 7.3

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

Properties

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