| 1 |
/* |
| 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 |
* $Id$ |
| 23 |
*/ |
| 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 |
#include "conf.h" |
| 32 |
#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 |
/* 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 |
char parv1_copy[IRCD_BUFSIZE]; |
| 62 |
struct MaskItem *conf = NULL; |
| 63 |
struct irc_ssaddr ip; |
| 64 |
int host_mask; |
| 65 |
int t; |
| 66 |
int matches = 0; |
| 67 |
char userhost[HOSTLEN + USERLEN + 2]; |
| 68 |
struct split_nuh_item nuh; |
| 69 |
|
| 70 |
if (EmptyString(parv[1])) |
| 71 |
{ |
| 72 |
sendto_one(source_p, ":%s NOTICE %s :usage: user@host|ip [password]", |
| 73 |
me.name, source_p->name); |
| 74 |
return; |
| 75 |
} |
| 76 |
|
| 77 |
if (IsChanPrefix(*parv[1])) /* Might be channel resv */ |
| 78 |
{ |
| 79 |
const struct MaskItem *chptr = NULL; |
| 80 |
|
| 81 |
if ((chptr = match_find_resv(parv[1]))) |
| 82 |
{ |
| 83 |
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 |
return; |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
strlcpy(parv1_copy, parv[1], sizeof(parv1_copy)); |
| 91 |
|
| 92 |
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 |
t = parse_netmask(given_host, &ip, &host_mask); |
| 104 |
|
| 105 |
if (t != HM_HOST) |
| 106 |
{ |
| 107 |
conf = find_dline_conf(&ip, |
| 108 |
#ifdef IPV6 |
| 109 |
(t == HM_IPV6) ? AF_INET6 : AF_INET |
| 110 |
#else |
| 111 |
AF_INET |
| 112 |
#endif |
| 113 |
); |
| 114 |
if (conf != NULL) |
| 115 |
{ |
| 116 |
++matches; |
| 117 |
if (conf->status & CONF_EXEMPT) |
| 118 |
sendto_one(source_p, |
| 119 |
":%s NOTICE %s :Exempt D-line host [%s] reason [%s]", |
| 120 |
me.name, source_p->name, conf->host, conf->reason); |
| 121 |
else |
| 122 |
sendto_one(source_p, form_str(RPL_TESTLINE), |
| 123 |
me.name, source_p->name, |
| 124 |
conf->hold ? 'd' : 'D', |
| 125 |
conf->hold ? ((conf->hold - CurrentTime) / 60) |
| 126 |
: 0L, |
| 127 |
conf->host, conf->reason); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
if (t != HM_HOST) |
| 132 |
conf = find_address_conf(given_host, given_name, &ip, |
| 133 |
#ifdef IPV6 |
| 134 |
(t == HM_IPV6) ? AF_INET6 : AF_INET, |
| 135 |
#else |
| 136 |
AF_INET, |
| 137 |
#endif |
| 138 |
parv[2]); |
| 139 |
else |
| 140 |
conf = find_address_conf(given_host, given_name, NULL, 0, parv[2]); |
| 141 |
|
| 142 |
if (conf != NULL) |
| 143 |
{ |
| 144 |
snprintf(userhost, sizeof(userhost), "%s@%s", conf->user, conf->host); |
| 145 |
|
| 146 |
if (conf->status & CONF_CLIENT) |
| 147 |
{ |
| 148 |
sendto_one(source_p, form_str(RPL_TESTLINE), |
| 149 |
me.name, source_p->name, 'I', 0L, userhost, |
| 150 |
conf->class ? conf->class->name : "<default>", ""); |
| 151 |
++matches; |
| 152 |
} |
| 153 |
else if (conf->status & CONF_KLINE) |
| 154 |
{ |
| 155 |
sendto_one(source_p, form_str(RPL_TESTLINE), |
| 156 |
me.name, source_p->name, |
| 157 |
conf->hold ? 'k' : 'K', |
| 158 |
conf->hold ? ((conf->hold - CurrentTime) / 60) |
| 159 |
: 0L, |
| 160 |
userhost, conf->reason? conf->reason : "No reason"); |
| 161 |
++matches; |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
conf = find_matching_name_conf(CONF_NRESV, given_name, NULL, NULL, 0); |
| 166 |
|
| 167 |
if (conf != NULL) |
| 168 |
{ |
| 169 |
sendto_one(source_p, form_str(RPL_TESTLINE), |
| 170 |
me.name, source_p->name, 'Q', 0L, |
| 171 |
conf->name, |
| 172 |
conf->reason ? conf->reason : "No reason");; |
| 173 |
++matches; |
| 174 |
} |
| 175 |
|
| 176 |
if (matches == 0) |
| 177 |
sendto_one(source_p, form_str(RPL_NOTESTLINE), |
| 178 |
me.name, source_p->name, parv1_copy); |
| 179 |
} |
| 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 |
int parc, char *parv[]) |
| 197 |
{ |
| 198 |
struct MaskItem *conf = NULL; |
| 199 |
|
| 200 |
if (EmptyString(parv[1])) |
| 201 |
{ |
| 202 |
sendto_one(source_p, ":%s NOTICE %s :usage: gecos", |
| 203 |
me.name, source_p->name); |
| 204 |
return; |
| 205 |
} |
| 206 |
|
| 207 |
if ((conf = find_matching_name_conf(CONF_XLINE, parv[1], NULL, NULL, 0))) |
| 208 |
sendto_one(source_p, form_str(RPL_TESTLINE), |
| 209 |
me.name, source_p->name, 'X', 0L, |
| 210 |
conf->name, conf->reason ? conf->reason : "X-lined"); |
| 211 |
else |
| 212 |
sendto_one(source_p, form_str(RPL_NOTESTLINE), |
| 213 |
me.name, source_p->name, parv[1]); |
| 214 |
} |
| 215 |
|
| 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 |
}; |