Re: [Unreal-users] Services patch: Warning LARGE
Status: Beta
Brought to you by:
wildchild
From: Jonathan M. <ch...@cy...> - 2000-06-27 10:19:05
|
>hmm, rather: i don't have +x support but ive added some features such as >halfop support and some command ignores - would like to see the patch thou I've expanded the patch as text into this mail. It consists of two additional source files which effectively contain the small part of Unreal that does the mangling, and a patch to the Makefile and one of the Services sourcefiles that calls it. ---- BEGIN mangle.h ---- /* Just a header to contain the following: */ #ifdef MANGLE_HOST char *hidehost (char *s, int useless); #endif ---- END mangle.h ---- ---- BEGIN mangle.c ---- /************************************************************************ * IRC - Internet Relay Chat, src/cloak.c * (C) VirtualWorld code made originally by RogerY (ro...@au...) * Some coding by Potvin (po...@sh...) * Modified by Stskeeps with some TerraX codebits * TerraX (de...@te...) - great job guys! * Stskeeps (sts...@ts...) * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 1, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* This source file was snaffled from UnrealIRCd to make IRC Services */ /* compatible with it. Much of the code was subsequently cut out for */ /* leanness and clarity. [Chromatix] */ /* #include the bare minimum necessary... [Chromatix] */ #include <string.h> #include <ctype.h> #include <stdio.h> #include "mangle.h" /* {FIXME!!!} a kludge to make it appear to work with the default */ /* (at least for ChatCircuit) settings... [Chromatix] */ #warning FIXME! This is a hard-coded default: the hiddenhost 'prefix' which is "cc" by default. #define hidden_host "cc" /* Hidden host code below */ #define MAXVIRTSIZE (3 + 5 + 1) #define HASHVAL_TOTAL 30011 #define HASHVAL_PARTIAL 211 #define B_BASE 1000 int Maskchecksum (char *data, int len) { int i; int j; j=0; for (i=0 ; i<len ; i++) { j += *data++ * (i < 16 ? (i+1)*(i+1) : i*(i-15)); } return (j+B_BASE)%0xffff; } /* hidehost * command takes the realhost of a user * and changes the content of it. * new hidehost by vmlinuz * added some extra fixes by stskeeps * originally based on TerraIRCd */ char *hidehost (char *s, int useless) { // static char mask[128]; char *mask; static char ipmask[64]; int csum; char *dot,*tmp; char *cp; int i, isdns; int dots = 0; mask = (char *) malloc(129); memset (mask, 0, 128); csum = Maskchecksum (s, strlen(s)); if (strlen (s) > 127) /* this isn't likely to happen: s is limited to HOSTLEN+1 (64) */ { s[128] = 0; } isdns = 0; cp = s; for (i=0; i < strlen(s); i++) { if (*cp == '.') { dots++; } cp++; } for (i=0 ; i<strlen(s) ; i++) { if (s[i] == '.') { continue; } if (isalpha(s[i])) { isdns = 1; break; } } if (isdns) { /* it is a resolved yes.. */ if (dots == 1) { /* mystro.org f.x */ sprintf(mask, "%s%c%d.%s", hidden_host, (csum < 0 ? '=' : '-'), (csum < 0 ? -csum : csum), s); } if (dots == 0) { /* localhost */ sprintf(mask, "%s%c%d", s, (csum < 0 ? '=' : '-'), (csum < 0 ? -csum : csum)); } if (dots > 1) { dot = (char *) strchr((char *) s, '.'); /* mask like *<first dot> */ sprintf(mask, "%s%c%d.%s", hidden_host, (csum < 0 ? '=' : '-'), (csum < 0 ? -csum : csum), dot+1); } } else { strncpy(ipmask, s, sizeof(ipmask)); ipmask[sizeof(ipmask)-1]='\0'; /* safety check */ dot = (char *) strrchr((char *) ipmask, '.'); *dot = '\0'; if (dot == NULL) /* dot should never be NULL: IP needs dots */ sprintf (mask, "%s%c%i", hidden_host, (csum < 0 ? '=' : '-'), (csum < 0 ? -csum : csum)); else sprintf (mask, "%s.%s%c%i", ipmask, hidden_host, (csum < 0 ? '=' : '-'), (csum < 0 ? -csum : csum)); } ok1: return mask; } ---- END mangle.c ---- ---- BEGIN mangle.diff ---- diff -c ircservices-4.3.3/Makefile ircservices/Makefile *** ircservices-4.3.3/Makefile Wed Jun 2 08:40:04 1999 --- ircservices/Makefile Sun Apr 30 00:03:38 2000 *************** *** 26,32 **** # debugging symbols on GCC. If you have a non-GCC compiler, you may want # to comment it out or change it. ! MORE_CFLAGS = -Wall -g ######################## End configuration section ######################## --- 26,32 ---- # debugging symbols on GCC. If you have a non-GCC compiler, you may want # to comment it out or change it. ! MORE_CFLAGS = -Wall -g -DMANGLE_HOST ######################## End configuration section ######################## *************** *** 40,52 **** config.o datafiles.o encrypt.o helpserv.o init.o language.o \ list.o log.o main.o memory.o memoserv.o messages.o misc.o news.o \ nickserv.o operserv.o process.o send.o sessions.o sockutil.o \ ! timeout.o users.o \ $(VSNPRINTF_O) SRCS = actions.c akill.c channels.c chanserv.c commands.c compat.c \ config.c datafiles.c encrypt.c helpserv.c init.c language.c \ list.c log.c main.c memory.c memoserv.c messages.c misc.c news.c \ nickserv.c operserv.c process.c send.c sessions.c sockutil.c \ ! timeout.c users.c \ $(VSNPRINTF_C) .c.o: --- 40,52 ---- config.o datafiles.o encrypt.o helpserv.o init.o language.o \ list.o log.o main.o memory.o memoserv.o messages.o misc.o news.o \ nickserv.o operserv.o process.o send.o sessions.o sockutil.o \ ! timeout.o users.o mangle.o \ $(VSNPRINTF_O) SRCS = actions.c akill.c channels.c chanserv.c commands.c compat.c \ config.c datafiles.c encrypt.c helpserv.c init.c language.c \ list.c log.c main.c memory.c memoserv.c messages.c misc.c news.c \ nickserv.c operserv.c process.c send.c sessions.c sockutil.c \ ! timeout.c users.c mangle.c \ $(VSNPRINTF_C) .c.o: *************** *** 114,119 **** --- 114,120 ---- list.o: list.c services.h log.o: log.c services.h pseudo.h main.o: main.c services.h timeout.h version.h + mangle.o: mangle.c mangle.h memory.o: memory.c services.h memoserv.o: memoserv.c services.h pseudo.h messages.o: messages.c services.h messages.h language.h *************** *** 126,132 **** sessions.o: sessions.c services.h pseudo.h sockutil.o: sockutil.c services.h timeout.o: timeout.c services.h timeout.h ! users.o: users.c services.h vsnprintf.o: vsnprintf.c --- 127,133 ---- sessions.o: sessions.c services.h pseudo.h sockutil.o: sockutil.c services.h timeout.o: timeout.c services.h timeout.h ! users.o: users.c services.h mangle.h vsnprintf.o: vsnprintf.c diff -c ircservices-4.3.3/users.c ircservices/users.c *** ircservices-4.3.3/users.c Fri Sep 24 04:04:27 1999 --- ircservices/users.c Sun Apr 30 10:54:31 2000 *************** *** 7,12 **** --- 7,13 ---- */ #include "services.h" + #include "mangle.h" #define HASH(nick) (((nick)[0]&31)<<5 | ((nick)[1]&31)) static User *userlist[1024]; *************** *** 740,749 **** * just user@host)? */ int match_usermask(const char *mask, User *user) { char *mask2 = sstrdup(mask); ! char *nick, *username, *host, *nick2, *host2; int result; if (strchr(mask2, '!')) { --- 741,753 ---- * just user@host)? */ + /* IRCd's supporting hostmask mangling (+x) require extra support here */ + /* See mangle.c for the mangling code. [Chromatix] */ + int match_usermask(const char *mask, User *user) { char *mask2 = sstrdup(mask); ! char *nick, *username, *host, *nick2, *host2, *manglehost, *logstr; int result; if (strchr(mask2, '!')) { *************** *** 770,775 **** --- 774,815 ---- result = match_wild(username, user->username) && match_wild(host, host2); } + + if(debug) { + logstr = (char *) malloc(256); + sprintf(logstr, "debug: matching %s!%s@%s to user %s %s match", + nick?nick:"", username, host, user->nick, result?"did":"did not"); + log(logstr); + free(logstr); + } + + #ifdef MANGLE_HOST + if(!result) { + manglehost = hidehost(host2, 0); + + if (nick) { + nick2 = strlower(sstrdup(user->nick)); + result = match_wild(nick, nick2) && + match_wild(username, user->username) && + match_wild(host, manglehost); + free(nick2); + } else { + result = match_wild(username, user->username) && + match_wild(host, manglehost); + } + + if(debug) { + logstr = (char *) malloc(256); + sprintf(logstr, "debug: matching %s!%s@%s to user %s [hostmangle: %s] %s match", + nick?nick:"", username, host, user->nick, manglehost, result?"did":"did not"); + log(logstr); + free(logstr); + } + + free(manglehost); + } + #endif + free(mask2); free(host2); return result; ---- END mangle.diff ---- -------------------------------------------------------------- from: Jonathan "Chromatix" Morton mail: ch...@cy... (not for attachments) uni-mail: j.d...@la... The key to knowledge is not to rely on people to teach you it. Get VNC Server for Macintosh from http://chromatix.autistics.org/vnc/ -----BEGIN GEEK CODE BLOCK----- Version 3.12 GCS$/E/S dpu s:- a19 C+++ UL++ P L+++ E W+ N- o? K? w--- O-- M++$ V? PS PE- Y+ PGP++ t- 5- X- R !tv b++ DI+++ D G e+ h+ r- y+ -----END GEEK CODE BLOCK----- |