From 3ff8f436014bfe342053877d3d063d181a753e3b Mon Sep 17 00:00:00 2001 From: pk910 Date: Sat, 23 Jul 2011 07:56:01 +0200 Subject: [PATCH] extended & fixed FAKEIDENT support --- include/client.h | 4 ++++ include/msg.h | 4 ++-- include/struct.h | 1 + ircd/m_fakehost.c | 10 ++++++---- ircd/s_user.c | 14 +++++--------- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/include/client.h b/include/client.h index 175dd94..20db743 100644 --- a/include/client.h +++ b/include/client.h @@ -180,6 +180,7 @@ enum Flag FLAG_ACCOUNT, /**< account name has been set */ FLAG_HIDDENHOST, /**< user's host is hidden */ FLAG_FAKEHOST, /**< user has a fakehost */ + FLAG_FAKEIDENT, /**< user has a fakeident */ FLAG_NOCHAN, /**< hide user's channels for non-opers */ FLAG_NOIDLE, /**< hide user's idle time for non-opers */ FLAG_XTRAOP, /**< allow overriding +k */ @@ -648,6 +649,7 @@ struct Client { #define IsSecurityServ(x) HasFlag(x, FLAG_SECURITY_SERV) /** Return non-zero if the client has a fakehost. */ #define IsFakeHost(x) HasFlag(x, FLAG_FAKEHOST) +#define IsFakeIdent(x) HasFlag(x, FLAG_FAKEIDENT) /** Return non-zero if the client has operator or server privileges. */ #define IsPrivileged(x) (IsAnOper(x) || IsServer(x)) @@ -696,6 +698,7 @@ struct Client { #define SetHiddenHost(x) SetFlag(x, FLAG_HIDDENHOST) /** Mark a client as having a fakehost. */ #define SetFakeHost(x) SetFlag(x, FLAG_FAKEHOST) +#define SetFakeIdent(x) SetFlag(x, FLAG_FAKEIDENT) /** Mark a client as having a pending PING. */ #define SetPingSent(x) SetFlag(x, FLAG_PINGSENT) /** Mark a client as having mode +n. */ @@ -751,6 +754,7 @@ struct Client { #define ClearHiddenHost(x) ClrFlag(x, FLAG_HIDDENHOST) /** Remove fakehost flag from the flient. */ #define ClearFakeHost(x) ClrFlag(x, FLAG_FAKEHOST) +#define ClearFakeIdent(x) ClrFlag(x, FLAG_FAKEIDENT) /** Clear the client's pending PING flag. */ #define ClearPingSent(x) ClrFlag(x, FLAG_PINGSENT) /** Clear the client's HUB flag. */ diff --git a/include/msg.h b/include/msg.h index eae4766..e4798f3 100644 --- a/include/msg.h +++ b/include/msg.h @@ -364,8 +364,8 @@ struct Client; #define TOK_FAKEHOST "FH" #define CMD_FAKEHOST MSG_FAKEHOST, TOK_FAKEHOST -#define MSG_FAKEHOST2 "FAKEHOST2" -#define TOK_FAKEHOST2 "FH2" +#define MSG_FAKEHOST2 "NEWFAKEHOST" +#define TOK_FAKEHOST2 "NFH" #define CMD_FAKEHOST2 MSG_FAKEHOST2, TOK_FAKEHOST2 #define MSG_FAKEHOST_OLD "FAKE" diff --git a/include/struct.h b/include/struct.h index beec331..45fb6ec 100644 --- a/include/struct.h +++ b/include/struct.h @@ -80,6 +80,7 @@ struct User { * overwritten with the ident response. */ char username[USERLEN + 1]; + char fakeuser[USERLEN + 1]; char host[HOSTLEN + 1]; /**< displayed hostname */ char realhost[HOSTLEN + 1]; /**< actual hostname */ char fakehost[HOSTLEN + 1]; /**< fakehost */ diff --git a/ircd/m_fakehost.c b/ircd/m_fakehost.c index a73dd53..5aa559e 100644 --- a/ircd/m_fakehost.c +++ b/ircd/m_fakehost.c @@ -91,8 +91,8 @@ #include "s_bsd.h" #include "s_conf.h" #include "s_user.h" +#include "s_debug.h" #include "send.h" - /* * m_fakehost - fakehost user message handler * @@ -295,15 +295,16 @@ int ms_fakehost2(struct Client *cptr, struct Client *sptr, int parc, char *parv[ } /* Ignore the assignment if it changes nothing. */ - if(IsFakeHost(target) && strcmp(cli_user(target)->fakehost, parv[3]) == 0 && strcmp(cli_user(target)->username, parv[2]) == 0) { + if(IsFakeHost(target) && strcmp(cli_user(target)->fakehost, parv[3]) == 0 && strcmp(cli_user(target)->fakeuser, parv[2]) == 0) { return 0; } /* Set fakehost and propagate the changed host. */ ircd_strncpy(cli_user(target)->fakehost, parv[3], HOSTLEN); - hide_ident_hostmask(target, FLAG_FAKEHOST, parv[2]); + ircd_strncpy(cli_user(target)->fakeuser, parv[2], USERLEN); + hide_hostmask(target, FLAG_FAKEHOST | FLAG_FAKEIDENT); - sendcmdto_serv_butone(sptr, CMD_FAKEHOST2, cptr, "%C %s %s", target, parv[2], parv[3]); + sendcmdto_serv_butone(sptr, CMD_FAKEHOST2, cptr, "%C %s %s", target, cli_user(target)->fakeuser, cli_user(target)->fakehost); return 0; } @@ -314,6 +315,7 @@ int ms_fakehost2(struct Client *cptr, struct Client *sptr, int parc, char *parv[ * parv[0] = sender prefix * parv[1] = target user numeric * parv[2] = target user's new fake host + * parv[3] = target user's new fake ident */ int ms_fakehost_old(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) { struct Client *target; diff --git a/ircd/s_user.c b/ircd/s_user.c index ccaed50..9827490 100644 --- a/ircd/s_user.c +++ b/ircd/s_user.c @@ -974,12 +974,7 @@ void send_user_info(struct Client* sptr, char* names, int rpl, InfoFormatter fmt */ int -hide_hostmask(struct Client *cptr, unsigned int flag) { - return hide_ident_hostmask(cptr, flag, NULL); -} - -int -hide_ident_hostmask(struct Client *cptr, unsigned int flag, char *username) +hide_hostmask(struct Client *cptr, unsigned int flag) { struct Membership *chan; char buf[HOSTLEN]; @@ -992,6 +987,7 @@ hide_ident_hostmask(struct Client *cptr, unsigned int flag, char *username) break; case FLAG_ACCOUNT: case FLAG_FAKEHOST: + case FLAG_FAKEIDENT: /* Invalidate all bans against the user so we check them again */ for (chan = (cli_user(cptr))->channel; chan; chan = chan->next_channel) @@ -1011,7 +1007,7 @@ hide_ident_hostmask(struct Client *cptr, unsigned int flag, char *username) if(IsFakeHost(cptr)) ircd_strncpy(buf, cli_user(cptr)->fakehost, HOSTLEN); else if (IsAccount(cptr)) ircd_snprintf(0, buf, HOSTLEN, "%s.%s", cli_user(cptr)->account, feature_str(FEAT_HIDDEN_HOST)); else return 0; - if(strncmp(buf, cli_user(cptr)->host, HOSTLEN) == 0) return 0; + if(strncmp(buf, cli_user(cptr)->host, HOSTLEN) == 0 && (!IsFakeIdent(cptr) || strncmp(cli_user(cptr)->fakeuser, cli_user(cptr)->username, USERLEN) == 0)) return 0; /* Remove all "valid" marks on the bans. This forces them to be * rechecked if the ban is accessed again. @@ -1025,8 +1021,8 @@ hide_ident_hostmask(struct Client *cptr, unsigned int flag, char *username) ircd_strncpy(cli_user(cptr)->host, buf, HOSTLEN); /* spoof also the username if username is passed */ - if(username) { - ircd_strncpy(cli_user(cptr)->username, username, USERLEN); + if(IsFakeIdent(cptr)) { + ircd_strncpy(cli_user(cptr)->username, cli_user(cptr)->fakeuser, USERLEN); /* ok, the client is now fully hidden, so let them know -- hikari */ if (MyConnect(cptr)) send_reply(cptr, RPL_HOSTUSERHIDDEN, cli_user(cptr)->username, cli_user(cptr)->host); -- 2.20.1