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