| 1 |
adx |
30 |
/* |
| 2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
|
|
* m_spoof.c: Supports dynamic auth{} creation/deletion. |
| 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 |
|
|
/* MODULE CONFIGURATION FOLLOWS -- please read!! */ |
| 26 |
|
|
|
| 27 |
|
|
/* |
| 28 |
|
|
* change to #define if you want to propagate received SPOOF/DELSPOOF messages |
| 29 |
|
|
* to other servers. This allows you create subnets inside which spoofs are |
| 30 |
|
|
* propagated. By manipulating PROPAGATE_SPOOF and RECEIVE_SPOOF, you can |
| 31 |
|
|
* prepare boundary hubs of such subnets. |
| 32 |
|
|
* |
| 33 |
|
|
* I realize a shared{} could be better, but I don't want to touch core code. |
| 34 |
|
|
* |
| 35 |
|
|
* If you decide to enable this, remember to load m_spoof on all servers |
| 36 |
|
|
* I am connected to, or you'll get plenty of "Unknown command" errors... |
| 37 |
|
|
*/ |
| 38 |
|
|
#undef PROPAGATE_SPOOF |
| 39 |
|
|
|
| 40 |
|
|
/* |
| 41 |
|
|
* this server is allowed to receive spoofs/delspoofs from other servers. |
| 42 |
|
|
* Use in conjunction with PROPAGATE_SPOOF (on target servers). |
| 43 |
|
|
*/ |
| 44 |
|
|
#undef RECEIVE_SPOOF |
| 45 |
|
|
|
| 46 |
|
|
/* where to put dynamic auth's -- this must be included from ircd.conf! |
| 47 |
|
|
* Ideally put .include "spoof.conf" before all other auths. |
| 48 |
|
|
* #undef if you want only a propagating hub server, not storing any data */ |
| 49 |
|
|
#define SPOOF_FILE "etc/spoof.conf" |
| 50 |
|
|
|
| 51 |
|
|
/* disable if you don't want opers notices/logs */ |
| 52 |
|
|
#define LOG_SPOOF |
| 53 |
|
|
|
| 54 |
|
|
|
| 55 |
|
|
/* END OF MODULE CONFIGURATION */ |
| 56 |
|
|
|
| 57 |
|
|
/* Usage: SPOOF <umask@hmask> <free.form.spoof|-> [flags|- [password]] |
| 58 |
|
|
* -- Appends an auth{} block. Flags consist of characters: |
| 59 |
|
|
* t (no_tilde), i (need_ident), k (kline_exempt), |
| 60 |
|
|
* g (gline_exempt), l (exceed_limit), o (class = "opers"), |
| 61 |
|
|
* f (can_flood), p (need_password), everything other is ignored. |
| 62 |
|
|
* DELSPOOF <umask@hmask> |
| 63 |
|
|
* -- Removes an auth{} block of exact umask@hmask, if found |
| 64 |
|
|
* |
| 65 |
|
|
* These commands are restricted to admins, so make sure your oper{} block |
| 66 |
|
|
* has admin = yes or so. |
| 67 |
|
|
*/ |
| 68 |
|
|
|
| 69 |
|
|
#if !defined(PROPAGATE_SPOOF) && !defined(SPOOF_FILE) |
| 70 |
|
|
#error You disabled both SPOOF_FILE and PROPAGATE_SPOOF, what do you expect me to do? |
| 71 |
|
|
#endif |
| 72 |
|
|
|
| 73 |
|
|
/* List of ircd includes from ../include/ */ |
| 74 |
|
|
#include "stdinc.h" |
| 75 |
|
|
#include "handlers.h" |
| 76 |
|
|
#include "client.h" |
| 77 |
|
|
#include "common.h" /* FALSE bleah */ |
| 78 |
|
|
#include "hash.h" |
| 79 |
|
|
#include "hostmask.h" |
| 80 |
|
|
#include "ircd.h" |
| 81 |
|
|
#include "numeric.h" |
| 82 |
|
|
#include "s_conf.h" |
| 83 |
|
|
#include "s_serv.h" |
| 84 |
|
|
#include "send.h" |
| 85 |
|
|
#include "msg.h" |
| 86 |
|
|
#include "parse.h" |
| 87 |
|
|
#include "modules.h" |
| 88 |
|
|
|
| 89 |
|
|
static void mo_spoof(struct Client *, struct Client *, int, char *[]); |
| 90 |
|
|
static void mo_delspoof(struct Client *, struct Client *, int, char *[]); |
| 91 |
|
|
|
| 92 |
|
|
struct Message spoof_msgtab = { |
| 93 |
|
|
"SPOOF", 0, 0, 3, 0, MFLG_SLOW, 0, |
| 94 |
|
|
#ifdef RECEIVE_SPOOF |
| 95 |
|
|
{m_unregistered, m_not_oper, mo_spoof, m_ignore, mo_spoof, m_ignore} |
| 96 |
|
|
#else |
| 97 |
|
|
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_spoof, m_ignore} |
| 98 |
|
|
#endif |
| 99 |
|
|
}; |
| 100 |
|
|
|
| 101 |
|
|
struct Message delspoof_msgtab = { |
| 102 |
|
|
"DELSPOOF", 0, 0, 1, 0, MFLG_SLOW, 0, |
| 103 |
|
|
#ifdef RECEIVE_SPOOF |
| 104 |
|
|
{m_unregistered, m_not_oper, mo_delspoof, m_ignore, mo_delspoof, m_ignore} |
| 105 |
|
|
#else |
| 106 |
|
|
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_delspoof, m_ignore} |
| 107 |
|
|
#endif |
| 108 |
|
|
}; |
| 109 |
|
|
|
| 110 |
|
|
#ifndef STATIC_MODULES |
| 111 |
|
|
void |
| 112 |
|
|
_modinit(void) |
| 113 |
|
|
{ |
| 114 |
|
|
mod_add_cmd(&spoof_msgtab); |
| 115 |
|
|
mod_add_cmd(&delspoof_msgtab); |
| 116 |
|
|
} |
| 117 |
|
|
|
| 118 |
|
|
void |
| 119 |
|
|
_moddeinit(void) |
| 120 |
|
|
{ |
| 121 |
|
|
mod_del_cmd(&delspoof_msgtab); |
| 122 |
|
|
mod_del_cmd(&spoof_msgtab); |
| 123 |
|
|
} |
| 124 |
|
|
|
| 125 |
knight |
31 |
const char *_version = "$Revision$"; |
| 126 |
adx |
30 |
#endif |
| 127 |
|
|
|
| 128 |
|
|
#ifdef SPOOF_FILE |
| 129 |
|
|
static void |
| 130 |
|
|
try_flag(FBFILE *f, int *flags, int flag, const char *string) |
| 131 |
|
|
{ |
| 132 |
|
|
if ((*flags & flag)) |
| 133 |
|
|
{ |
| 134 |
|
|
fbputs(string, f, strlen(string)); |
| 135 |
|
|
|
| 136 |
|
|
*flags &= ~flag; |
| 137 |
|
|
fbputs(*flags ? ", " : ";\n", f, 2); |
| 138 |
|
|
} |
| 139 |
|
|
} |
| 140 |
|
|
#endif |
| 141 |
|
|
|
| 142 |
|
|
static void |
| 143 |
|
|
mo_spoof(struct Client *client_p, struct Client *source_p, |
| 144 |
|
|
int parc, char *parv[]) |
| 145 |
|
|
{ |
| 146 |
|
|
char *host, *spoof, *password; |
| 147 |
|
|
const char *tmp = NULL; |
| 148 |
|
|
const char *user = NULL; |
| 149 |
|
|
const char *flags = NULL; |
| 150 |
|
|
int i = 0; |
| 151 |
|
|
#ifdef SPOOF_FILE |
| 152 |
|
|
int class_opers; |
| 153 |
|
|
FBFILE *f; |
| 154 |
|
|
char buffer[1024]; |
| 155 |
|
|
struct AddressRec *arec; |
| 156 |
|
|
#endif |
| 157 |
|
|
|
| 158 |
|
|
if (MyConnect(source_p) && !IsOperAdmin(source_p)) |
| 159 |
|
|
{ |
| 160 |
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS), |
| 161 |
|
|
me.name, source_p->name, "SPOOF"); |
| 162 |
|
|
return; |
| 163 |
|
|
} |
| 164 |
|
|
|
| 165 |
|
|
/* check the user@host mask */ |
| 166 |
|
|
if (strchr(parv[1], '!') != NULL) |
| 167 |
|
|
{ |
| 168 |
|
|
syntax: |
| 169 |
|
|
if (MyConnect(source_p)) |
| 170 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Syntax: SPOOF <umask@hmask> " |
| 171 |
|
|
"<spoof/-> [flags/- [password]]", me.name, source_p->name); |
| 172 |
|
|
return; |
| 173 |
|
|
} |
| 174 |
|
|
|
| 175 |
|
|
(void) collapse(parv[1]); |
| 176 |
|
|
|
| 177 |
|
|
for (tmp = parv[1]; *tmp; tmp++) |
| 178 |
|
|
if (!IsKWildChar(*tmp)) |
| 179 |
|
|
if (++i >= ConfigFileEntry.min_nonwildcard) |
| 180 |
|
|
break; |
| 181 |
|
|
if (i < ConfigFileEntry.min_nonwildcard) |
| 182 |
|
|
{ |
| 183 |
|
|
if (MyConnect(source_p)) |
| 184 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Not enough non-wildcard characters " |
| 185 |
|
|
"in user@host mask", |
| 186 |
|
|
me.name, source_p->name); |
| 187 |
|
|
return; |
| 188 |
|
|
} |
| 189 |
|
|
|
| 190 |
|
|
host = strchr(parv[1], '@'); |
| 191 |
|
|
if (host) |
| 192 |
|
|
{ |
| 193 |
|
|
user = parv[1]; |
| 194 |
|
|
*host = '\0'; |
| 195 |
|
|
host++; |
| 196 |
|
|
} |
| 197 |
|
|
else |
| 198 |
|
|
{ |
| 199 |
|
|
user = "*"; |
| 200 |
|
|
host = parv[1]; |
| 201 |
|
|
} |
| 202 |
|
|
|
| 203 |
|
|
/* check the spoof field */ |
| 204 |
|
|
spoof = parv[2]; |
| 205 |
|
|
if (spoof == NULL || !*spoof) |
| 206 |
|
|
goto syntax; |
| 207 |
|
|
|
| 208 |
|
|
if (spoof[0] != '-' || spoof[1] != '\0') |
| 209 |
|
|
{ |
| 210 |
|
|
for (tmp = spoof; *tmp; tmp++) |
| 211 |
|
|
if (!IsHostChar(*tmp)) { |
| 212 |
|
|
if (MyConnect(source_p)) |
| 213 |
|
|
sendto_one(source_p, ":%s NOTICE %s :The spoof [%s] is invalid", |
| 214 |
|
|
me.name, source_p->name, spoof); |
| 215 |
|
|
return; |
| 216 |
|
|
} |
| 217 |
|
|
if (strlen(spoof) >= HOSTLEN) { |
| 218 |
|
|
if (MyConnect(source_p)) |
| 219 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Spoofs must be less than %d.." |
| 220 |
|
|
"ignoring it", me.name, source_p->name, HOSTLEN); |
| 221 |
|
|
return; |
| 222 |
|
|
} |
| 223 |
|
|
} |
| 224 |
|
|
|
| 225 |
|
|
flags = (parc > 3) ? parv[3] : "-"; |
| 226 |
|
|
password = (parc > 4 && parv[4][0]) ? parv[4] : NULL; |
| 227 |
|
|
|
| 228 |
|
|
#ifdef PROPAGATE_SPOOF |
| 229 |
|
|
sendto_server(client_p, source_p, NULL, NOCAPS, NOCAPS, LL_ICLIENT, |
| 230 |
|
|
":%s SPOOF %s@%s %s %s :%s", |
| 231 |
|
|
source_p->name, user, host, spoof, flags, password ? password : ""); |
| 232 |
|
|
#endif |
| 233 |
|
|
|
| 234 |
|
|
#ifdef SPOOF_FILE |
| 235 |
|
|
/* Walk through auth {} items and check if we have another auth block |
| 236 |
|
|
* for this hostname */ |
| 237 |
|
|
for (i = 0; i < ATABLE_SIZE; i++) |
| 238 |
|
|
for (arec = atable[i]; arec; arec = arec->next) |
| 239 |
|
|
if (arec->type == CONF_CLIENT && !irccmp(arec->aconf->host, host) && |
| 240 |
|
|
!irccmp(arec->aconf->user, user)) |
| 241 |
|
|
{ |
| 242 |
|
|
/* auth entry already exists */ |
| 243 |
|
|
if (MyConnect(source_p)) |
| 244 |
|
|
sendto_one(source_p, |
| 245 |
|
|
":%s NOTICE %s :auth for %s@%s already exists, you need " |
| 246 |
|
|
"to use /DELSPOOF first", me.name, source_p->name, user, host); |
| 247 |
|
|
#ifdef LOG_SPOOF |
| 248 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 249 |
|
|
"%s attemped to re-add auth for %s@%s " |
| 250 |
|
|
"[spoof: %s, flags: %s]", source_p->name, user, host, |
| 251 |
|
|
spoof, flags); |
| 252 |
|
|
#endif |
| 253 |
|
|
return; |
| 254 |
|
|
} |
| 255 |
|
|
|
| 256 |
|
|
/* Add the spoof to the the spoof file */ |
| 257 |
|
|
if ((f = fbopen(SPOOF_FILE, "a")) == NULL) |
| 258 |
|
|
{ |
| 259 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 260 |
|
|
"Could not open %s file, auth for %s@%s " |
| 261 |
|
|
"[spoof: %s, flags: %s, requested by %s] not added", |
| 262 |
|
|
SPOOF_FILE, user, host, spoof, flags, source_p->name); |
| 263 |
|
|
return; |
| 264 |
|
|
} |
| 265 |
|
|
|
| 266 |
|
|
/* write the auth {} block */ |
| 267 |
|
|
fbputs("auth {\n", f, 7); |
| 268 |
|
|
i = ircsprintf(buffer, "\tuser = \"%s@%s\";\n", user, host); |
| 269 |
|
|
fbputs(buffer, f, i); |
| 270 |
|
|
if (spoof[0] != '-' || spoof[1] != '\0') |
| 271 |
|
|
{ |
| 272 |
|
|
i = ircsprintf(buffer, "\tspoof = \"%s\";\n", spoof); |
| 273 |
|
|
fbputs(buffer, f, i); |
| 274 |
|
|
} |
| 275 |
|
|
if (password) |
| 276 |
|
|
{ |
| 277 |
|
|
i = ircsprintf(buffer, "\tpassword = \"%s\";\n", password); |
| 278 |
|
|
fbputs(buffer, f, i); |
| 279 |
|
|
} |
| 280 |
|
|
|
| 281 |
|
|
/* process given flags */ |
| 282 |
|
|
i = class_opers = 0; |
| 283 |
|
|
for (tmp = flags; *tmp; ++tmp) |
| 284 |
|
|
switch (*tmp) |
| 285 |
|
|
{ |
| 286 |
|
|
case 't': i |= CONF_FLAGS_NO_TILDE; /* no_tilde = yes; */ |
| 287 |
|
|
break; |
| 288 |
|
|
case 'i': i |= CONF_FLAGS_NEED_IDENTD; /* need_ident = yes; */ |
| 289 |
|
|
break; |
| 290 |
|
|
case 'k': i |= CONF_FLAGS_EXEMPTKLINE; /* kline_exempt = yes; */ |
| 291 |
|
|
break; |
| 292 |
|
|
case 'g': i |= CONF_FLAGS_EXEMPTGLINE; /* gline_exempt = yes; */ |
| 293 |
|
|
break; |
| 294 |
|
|
case 'l': i |= CONF_FLAGS_NOLIMIT; /* exceed_limit = yes; */ |
| 295 |
|
|
break; |
| 296 |
|
|
case 'o': class_opers = 1; /* class = "opers"; */ |
| 297 |
|
|
break; |
| 298 |
|
|
case 'f': i |= CONF_FLAGS_CAN_FLOOD; /* can_flood = yes; */ |
| 299 |
|
|
break; |
| 300 |
|
|
case 'p': i|= CONF_FLAGS_NEED_PASSWORD; /* need_password = yes; */ |
| 301 |
|
|
} |
| 302 |
|
|
|
| 303 |
|
|
if (i) |
| 304 |
|
|
{ |
| 305 |
|
|
fbputs("\tflags = ", f, 9); |
| 306 |
|
|
try_flag(f, &i, CONF_FLAGS_NO_TILDE, "no_tilde"); |
| 307 |
|
|
try_flag(f, &i, CONF_FLAGS_NEED_IDENTD, "need_ident"); |
| 308 |
|
|
try_flag(f, &i, CONF_FLAGS_EXEMPTKLINE, "kline_exempt"); |
| 309 |
|
|
try_flag(f, &i, CONF_FLAGS_EXEMPTGLINE, "gline_exempt"); |
| 310 |
|
|
try_flag(f, &i, CONF_FLAGS_NOLIMIT, "exceed_limit"); |
| 311 |
|
|
try_flag(f, &i, CONF_FLAGS_CAN_FLOOD, "can_flood"); |
| 312 |
|
|
try_flag(f, &i, CONF_FLAGS_NEED_PASSWORD, "need_password"); |
| 313 |
|
|
} |
| 314 |
|
|
|
| 315 |
|
|
if (class_opers) |
| 316 |
|
|
fbputs("\tclass = \"opers\";\n", f, 18); |
| 317 |
|
|
else |
| 318 |
|
|
fbputs("\tclass = \"users\";\n", f, 18); |
| 319 |
|
|
|
| 320 |
|
|
fbputs("};\n\n", f, 4); |
| 321 |
|
|
fbclose(f); |
| 322 |
|
|
|
| 323 |
|
|
rehash(0); |
| 324 |
|
|
#endif |
| 325 |
|
|
|
| 326 |
|
|
#ifdef LOG_SPOOF |
| 327 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 328 |
|
|
"%s added auth for %s@%s [spoof: %s, flags: %s]", |
| 329 |
|
|
source_p->name, user, host, spoof, flags); |
| 330 |
|
|
ilog(L_TRACE, "%s added auth for %s@%s [spoof: %s, flags: %s]", |
| 331 |
|
|
source_p->name, user, host, spoof, flags); |
| 332 |
|
|
#endif |
| 333 |
|
|
} |
| 334 |
|
|
|
| 335 |
|
|
/* Now, our job is a bit harder. I will scan through the SPOOF_FILE |
| 336 |
|
|
* and read all auths{} (assuming they are written in our line formatting..), |
| 337 |
|
|
* then rewrite them skipping the one to delete. --adx */ |
| 338 |
|
|
static void |
| 339 |
|
|
mo_delspoof(struct Client *client_p, struct Client *source_p, |
| 340 |
|
|
int parc, char *parv[]) |
| 341 |
|
|
{ |
| 342 |
|
|
#ifdef SPOOF_FILE |
| 343 |
|
|
FBFILE *f, *fout; |
| 344 |
|
|
int ignore_it = 1, spoof_found = 0; |
| 345 |
|
|
char buffer[1024], *tmp; |
| 346 |
|
|
#endif |
| 347 |
|
|
const char *user = NULL; |
| 348 |
|
|
char *host = NULL; |
| 349 |
|
|
|
| 350 |
|
|
if (MyConnect(source_p) && !IsOperAdmin(source_p)) |
| 351 |
|
|
{ |
| 352 |
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, parv[0], "DELSPOOF"); |
| 353 |
|
|
return; |
| 354 |
|
|
} |
| 355 |
|
|
|
| 356 |
|
|
if (parv[1] == NULL || !*parv[1]) |
| 357 |
|
|
{ |
| 358 |
|
|
if (MyConnect(source_p)) |
| 359 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Syntax: /DELSPOOF <user@host>", |
| 360 |
|
|
me.name, source_p->name); |
| 361 |
|
|
return; |
| 362 |
|
|
} |
| 363 |
|
|
|
| 364 |
|
|
/* check user@host mask */ |
| 365 |
|
|
(void) collapse(parv[1]); |
| 366 |
|
|
|
| 367 |
|
|
host = strchr(parv[1], '@'); |
| 368 |
|
|
if (host != NULL) |
| 369 |
|
|
{ |
| 370 |
|
|
user = parv[1]; |
| 371 |
|
|
*host = '\0'; |
| 372 |
|
|
host++; |
| 373 |
|
|
} |
| 374 |
|
|
else |
| 375 |
|
|
{ |
| 376 |
|
|
user = "*"; |
| 377 |
|
|
host = parv[1]; |
| 378 |
|
|
} |
| 379 |
|
|
|
| 380 |
|
|
#ifdef PROPAGATE_SPOOF |
| 381 |
|
|
sendto_server(client_p, source_p, NULL, NOCAPS, NOCAPS, LL_ICLIENT, |
| 382 |
|
|
":%s DELSPOOF %s@%s", source_p->name, user, host); |
| 383 |
|
|
#endif |
| 384 |
|
|
|
| 385 |
|
|
#ifdef SPOOF_FILE |
| 386 |
|
|
if ((f = fbopen(SPOOF_FILE, "r")) == NULL) |
| 387 |
|
|
{ |
| 388 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 389 |
|
|
"Could not open %s file, auth for %s@%s not deleted " |
| 390 |
|
|
"(requested by %s)", |
| 391 |
|
|
SPOOF_FILE, user, host, source_p->name); |
| 392 |
|
|
return; |
| 393 |
|
|
} |
| 394 |
|
|
|
| 395 |
|
|
if ((fout = fbopen(SPOOF_FILE ".new", "w")) == NULL) |
| 396 |
|
|
{ |
| 397 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 398 |
|
|
"Could not create %s.new file, auth for %s@%s not " |
| 399 |
|
|
"deleted (requested by %s)", |
| 400 |
|
|
SPOOF_FILE, user, host, source_p->name); |
| 401 |
|
|
return; |
| 402 |
|
|
} |
| 403 |
|
|
|
| 404 |
|
|
while (fbgets(buffer, 1024, f)) |
| 405 |
|
|
{ |
| 406 |
|
|
if (!ircncmp(buffer, "auth {", 6)) |
| 407 |
|
|
{ |
| 408 |
|
|
/* don't process it yet.. we have to check whether the user="..."; field |
| 409 |
|
|
* matches the user@host mask which is being deleted |
| 410 |
|
|
*/ |
| 411 |
|
|
ignore_it = 1; |
| 412 |
|
|
continue; |
| 413 |
|
|
} |
| 414 |
|
|
|
| 415 |
|
|
/* a simple parser substitute... */ |
| 416 |
|
|
for (tmp = buffer; *tmp == '\t' || *tmp == ' '; tmp++) |
| 417 |
|
|
; |
| 418 |
|
|
if (!ircncmp(tmp, "user", 4)) |
| 419 |
|
|
{ |
| 420 |
|
|
for (tmp += 4; *tmp == '\t' || *tmp == ' '; tmp++) |
| 421 |
|
|
; |
| 422 |
|
|
if (*tmp == '=') { |
| 423 |
|
|
for (++tmp; *tmp == '\t' || *tmp == ' '; tmp++) |
| 424 |
|
|
; |
| 425 |
|
|
if (*tmp == '\"') |
| 426 |
|
|
{ |
| 427 |
|
|
/* yuppi, we've just reached the user="..."; field */ |
| 428 |
|
|
int matches; |
| 429 |
|
|
char *tmp2 = strchr(++tmp, '\"'); |
| 430 |
|
|
|
| 431 |
|
|
if (tmp2 != NULL) |
| 432 |
|
|
*tmp2 = '\0'; |
| 433 |
|
|
tmp2 = strchr(tmp, '@'); |
| 434 |
|
|
|
| 435 |
|
|
/* is it matching our mask? */ |
| 436 |
|
|
if (tmp2 == NULL) |
| 437 |
|
|
matches = !irccmp(user, "*") && !irccmp(host, tmp); |
| 438 |
|
|
else |
| 439 |
|
|
{ |
| 440 |
|
|
*tmp2++ = '\0'; |
| 441 |
|
|
matches = !irccmp(user, tmp) && !irccmp(host, tmp2); |
| 442 |
|
|
} |
| 443 |
|
|
|
| 444 |
|
|
if (!matches) |
| 445 |
|
|
{ |
| 446 |
|
|
/* no.. so leave it unchanged */ |
| 447 |
|
|
if (ignore_it) |
| 448 |
|
|
{ |
| 449 |
|
|
ignore_it = 0; |
| 450 |
|
|
fbputs("auth {\n", fout, 7); |
| 451 |
|
|
/* user="..." should be the first field in the auth {}; block, |
| 452 |
|
|
* otherwise we could have problems... |
| 453 |
|
|
*/ |
| 454 |
|
|
} |
| 455 |
|
|
|
| 456 |
|
|
fbputs("\tuser = \"", fout, 9); |
| 457 |
|
|
if (tmp2 == NULL) |
| 458 |
|
|
fbputs("*", fout, 1); |
| 459 |
|
|
else |
| 460 |
|
|
fbputs(tmp, fout, strlen(tmp)); |
| 461 |
|
|
fbputs("@", fout, 1); |
| 462 |
|
|
fbputs(tmp2, fout, strlen(tmp2)); |
| 463 |
|
|
fbputs("\";\n", fout, 3); |
| 464 |
|
|
} |
| 465 |
|
|
else |
| 466 |
|
|
{ |
| 467 |
|
|
/* we've got it! - omit and continue working */ |
| 468 |
|
|
spoof_found = 1; |
| 469 |
|
|
} |
| 470 |
|
|
|
| 471 |
|
|
continue; |
| 472 |
|
|
} |
| 473 |
|
|
} |
| 474 |
|
|
} |
| 475 |
|
|
|
| 476 |
|
|
if (!ignore_it) |
| 477 |
|
|
fbputs(buffer, fout, strlen(buffer)); |
| 478 |
|
|
} |
| 479 |
|
|
|
| 480 |
|
|
fbclose(f); |
| 481 |
|
|
fbclose(fout); |
| 482 |
|
|
|
| 483 |
|
|
if (!spoof_found) |
| 484 |
|
|
{ |
| 485 |
|
|
if (MyConnect(source_p)) |
| 486 |
|
|
sendto_one(source_p, ":%s NOTICE %s :No auth for %s@%s found", |
| 487 |
|
|
me.name, source_p->name, user, host); |
| 488 |
|
|
unlink(SPOOF_FILE ".new"); |
| 489 |
|
|
return; |
| 490 |
|
|
} |
| 491 |
|
|
|
| 492 |
|
|
unlink(SPOOF_FILE); |
| 493 |
|
|
rename(SPOOF_FILE ".new", SPOOF_FILE); |
| 494 |
|
|
rehash(0); |
| 495 |
|
|
#endif |
| 496 |
|
|
|
| 497 |
|
|
#ifdef LOG_SPOOF |
| 498 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, "%s deleted auth for %s@%s", |
| 499 |
|
|
source_p->name, user, host); |
| 500 |
|
|
#endif |
| 501 |
|
|
} |