ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_testline.c
Revision: 1649
Committed: Sat Nov 10 19:27:13 2012 UTC (13 years, 8 months ago) by michael
Content type: text/x-csrc
File size: 6949 byte(s)
Log Message:
- minor MaskItem structure cleanup

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

Properties

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