From: Matthew Mondor Date: Thu, 13 Jan 2005 06:19:56 +0000 (+0000) Subject: Applied fake-host diff X-Git-Tag: rubiks-ircd-1-0-6~49 X-Git-Url: http://git.pulsar-zone.net/?a=commitdiff_plain;h=d1f1ade3b0fe72ec2a9b62f7049889022443c689;p=rubiks-ircd.git Applied fake-host diff --- diff --git a/include/confparse.h b/include/confparse.h index 0f6b3b8..c45c874 100644 --- a/include/confparse.h +++ b/include/confparse.h @@ -4,7 +4,7 @@ * Apply the GPL here. */ -/* $Id: confparse.h,v 1.1 2005/01/12 07:44:57 mmondor Exp $ */ +/* $Id: confparse.h,v 1.2 2005/01/13 06:19:56 mmondor Exp $ */ /* our structures */ @@ -240,6 +240,7 @@ sConf confallowtab[] = {SCONFT_PASSWD, SCONFF_PASSWD, VARTYPE_NAME}, {SCONFT_CLASS, SCONFF_CLASS, VARTYPE_NAME}, {SCONFT_FLAGS, SCONFF_FLAGS, VARTYPE_NAME}, + {SCONFT_MASK, SCONFF_MASK, VARTYPE_NAME}, {(char *) 0, 0, 0} }; @@ -250,6 +251,7 @@ sConf confopertab[] = {SCONFT_PASSWD, SCONFF_PASSWD, VARTYPE_NAME}, {SCONFT_ACCESS, SCONFF_ACCESS, VARTYPE_NAME}, {SCONFT_CLASS, SCONFF_CLASS, VARTYPE_NAME}, + {SCONFT_MASK, SCONFF_MASK, VARTYPE_NAME}, {(char *) 0, 0, 0} }; diff --git a/include/struct.h b/include/struct.h index 6740202..523b93e 100644 --- a/include/struct.h +++ b/include/struct.h @@ -20,7 +20,7 @@ * */ -/* $Id: struct.h,v 1.1 2005/01/12 07:44:58 mmondor Exp $ */ +/* $Id: struct.h,v 1.2 2005/01/13 06:19:56 mmondor Exp $ */ #ifndef __struct_include__ #define __struct_include__ @@ -634,6 +634,8 @@ typedef struct Whowas #define CONF_FLAGS_FORCEFLOOD 0x0080 /* skip clone checks? */ #define CONF_FLAGS_SKIPCLONES 0x0100 +/* fake this client's host? */ +#define CONF_FLAGS_I_FAKE_HOST 0x0200 /* global configuration flags */ @@ -678,6 +680,7 @@ struct Conf_Allow char *ipmask; char *passwd; char *hostmask; + char *fakehost; int port; int flags; int clients; @@ -705,6 +708,7 @@ struct Conf_Oper char *hosts[MAXHOSTS+1]; char *passwd; char *nick; + char *fakehost; int flags; int legal; int opers; /* number of opers currently using this */ diff --git a/src/s_conf.c b/src/s_conf.c index 5554494..e47d527 100644 --- a/src/s_conf.c +++ b/src/s_conf.c @@ -18,7 +18,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: s_conf.c,v 1.1 2005/01/12 07:44:57 mmondor Exp $ */ +/* $Id: s_conf.c,v 1.2 2005/01/13 06:19:56 mmondor Exp $ */ #include "struct.h" #include "common.h" @@ -166,6 +166,7 @@ free_allow(aAllow *ptr) MyFree(ptr->ipmask); MyFree(ptr->passwd); MyFree(ptr->hostmask); + MyFree(ptr->fakehost); MyFree(ptr->class_name); MyFree(ptr); return; @@ -182,6 +183,7 @@ free_oper(aOper *ptr) } MyFree(ptr->passwd); MyFree(ptr->nick); + MyFree(ptr->fakehost); MyFree(ptr->class_name); MyFree(ptr); return; @@ -685,6 +687,17 @@ confadd_oper(cVar *vars[], int lnum) tmp->type = NULL; DupString(x->class_name, tmp->value); } + else if(tmp->type && (tmp->type->flag & SCONFF_MASK)) + { + if (x->fakehost) + { + confparse_error("Multiple mask definitions", lnum); + free_oper(x); + return -1; + } + tmp->type = NULL; + DupString(x->fakehost, tmp->value); + } } if(!x->nick) { @@ -1144,6 +1157,44 @@ confadd_allow(cVar *vars[], int lnum) tmp->type = NULL; } + else if(tmp->type && (tmp->type->flag & SCONFF_MASK)) + { + char *p = tmp->value; + int bad_dns = 0; + int dots = 0; + if(x->fakehost) + { + confparse_error("Multiple hostmask definitions", lnum); + free_allow(x); + return -1; + } + while (*p) + { + if (!IsAlnum(*p)) + { +#ifdef RFC1035_ANAL + if ((*p != '-') && (*p != '.')) +#else + if ((*p != '-') && (*p != '.') && + (*p != '_') && (*p != '/')) +#endif + bad_dns = YES; + } + if (*p == '.') + dots++; + p++; + } + if (bad_dns || !dots) + { + confparse_error("Invalid hostmask encountered",lnum); + free_allow(x); + return -1; + } + tmp->type = NULL; + DupString(x->fakehost, tmp->value); + x->flags |= CONF_FLAGS_I_FAKE_HOST; + + } } if(!x->ipmask && !x->hostmask) { @@ -1953,6 +2004,11 @@ merge_opers() old_oper->hosts[i] = aoper->hosts[i]; old_oper->hosts[i] = NULL; old_oper->passwd = aoper->passwd; + MyFree(old_oper->fakehost); + if (aoper->fakehost) + DupString(old_oper->fakehost, aoper->fakehost); + else + old_oper->fakehost = NULL; old_oper->class_name = aoper->class_name; old_oper->class = find_class(aoper->class_name); old_oper->class->refs++; diff --git a/src/s_user.c b/src/s_user.c index c47c7bc..797048d 100644 --- a/src/s_user.c +++ b/src/s_user.c @@ -21,7 +21,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: s_user.c,v 1.1 2005/01/12 07:44:57 mmondor Exp $ */ +/* $Id: s_user.c,v 1.2 2005/01/13 06:19:56 mmondor Exp $ */ #include "struct.h" #include "common.h" @@ -365,8 +365,27 @@ canonize(char *buffer) return cbuf; } +static void +client_set_fakehost(aClient *sptr, aAllow *pwaconf) +{ + if (pwaconf->flags & CONF_FLAGS_I_FAKE_HOST) + { + sptr->user->real_oper_host = + MyMalloc(strlen(sptr->user->host) + 1); + sptr->user->real_oper_username = + MyMalloc(strlen(sptr->user->username) + 1); + sptr->user->real_oper_ip = + MyMalloc(strlen(sptr->hostip) + 1); + strcpy(sptr->user->real_oper_host, sptr->user->host); + strcpy(sptr->user->real_oper_username, sptr->user->username); + strcpy(sptr->user->real_oper_ip, sptr->hostip); + strncpyzt(sptr->user->host, pwaconf->fakehost, HOSTLEN + 1); + strncpy(sptr->sockhost, pwaconf->fakehost, HOSTLEN + 1); + } +} + #if (RIDICULOUS_PARANOIA_LEVEL>=1) -static int +static char * check_oper_can_mask(aClient *sptr, char *name, char *password, char **onick) { aOper *aoper; @@ -379,7 +398,7 @@ check_oper_can_mask(aClient *sptr, char *name, char *password, char **onick) sendto_realops("Failed OPERMASK attempt by %s (%s@%s) [No Entry for " "%s]", sptr->name, sptr->user->username, sptr->user->host, name); - return 0; + return NULL; } /* use first two chars of the password they send in as salt */ @@ -403,13 +422,13 @@ check_oper_can_mask(aClient *sptr, char *name, char *password, char **onick) *onick = aoper->nick; sendto_realops("%s [%s] (%s@) has masked their hostname.", sptr->name, aoper->nick, sptr->user->username); - return 1; + return (aoper->fakehost ? aoper->fakehost : Staff_Address); } sendto_realops("Failed OPERMASK attempt by %s (%s@%s) [Bad Password]", sptr->name, sptr->user->username, sptr->user->host); - return 0; + return NULL; } #endif @@ -921,15 +940,21 @@ register_user(aClient *cptr, aClient *sptr, char *nick, char *username) char *opptr; char *onick; char *tmpptr; + char *ohost; char tmppwd[PASSWDLEN + 1]; if(!(opptr = strchr(onptr, ':'))) + { +#endif + client_set_fakehost(sptr,pwaconf); +#if (RIDICULOUS_PARANOIA_LEVEL>=1) break; + } *opptr++ = '\0'; if((tmpptr = strchr(opptr, ':'))) *tmpptr++ = '\0'; - if(check_oper_can_mask(sptr, onptr, opptr, &onick) != 0) + if((ohost = check_oper_can_mask(sptr,onptr,opptr, &onick)) != NULL) { sendto_one(sptr, ":%s NOTICE %s :*** Your hostname has " "been masked.", @@ -949,13 +974,13 @@ register_user(aClient *cptr, aClient *sptr, char *nick, char *username) strcpy(sptr->user->real_oper_host, sptr->user->host); strcpy(sptr->user->real_oper_username, sptr->user->username); strcpy(sptr->user->real_oper_ip, sptr->hostip); - strncpyzt(sptr->user->host, Staff_Address, HOSTLEN + 1); + strncpyzt(sptr->user->host, ohost, HOSTLEN + 1); strncpyzt(sptr->user->username, onick, USERLEN + 1); strncpyzt(sptr->username, onick, USERLEN + 1); sptr->flags |= FLAGS_GOTID; /* fake ident */ sptr->ip.s_addr = 0; strcpy(sptr->hostip, "0.0.0.0"); - strncpy(sptr->sockhost, Staff_Address, HOSTLEN + 1); + strncpy(sptr->sockhost, ohost, HOSTLEN + 1); } if(tmpptr) @@ -966,6 +991,8 @@ register_user(aClient *cptr, aClient *sptr, char *nick, char *username) else sptr->passwd[0] = '\0'; } while(0); + else + client_set_fakehost(sptr,pwaconf); #endif sendto_realops_lev(CCONN_LEV, "Client connecting: %s (%s@%s) [%s] {%s}",