From 21592a40b5608357580412667ce0c31b8a1ebc5f Mon Sep 17 00:00:00 2001 From: pk910 Date: Thu, 3 Nov 2011 21:26:57 +0100 Subject: [PATCH 1/1] reimplemented fakeident support --- include/s_user.h | 5 ++++ include/struct.h | 2 +- ircd/m_account.c | 2 +- ircd/m_fakehost.c | 12 ++++----- ircd/m_hidehost.c | 2 +- ircd/s_user.c | 67 +++++++++++++++++++++++++++-------------------- 6 files changed, 52 insertions(+), 38 deletions(-) diff --git a/include/s_user.h b/include/s_user.h index 7b1fc18..970e45b 100644 --- a/include/s_user.h +++ b/include/s_user.h @@ -80,6 +80,11 @@ extern int whisper(struct Client* source, const char* nick, extern void send_user_info(struct Client* to, char* names, int rpl, InfoFormatter fmt); +#define HIDE_HOSTMASK_FLAG_HIDDENHOST 0x01 +#define HIDE_HOSTMASK_FLAG_ACCOUNT 0x02 +#define HIDE_HOSTMASK_FLAG_FAKEHOST 0x04 +#define HIDE_HOSTMASK_FLAG_FAKEIDENT 0x08 + extern int hide_hostmask(struct Client *cptr, unsigned int flags); extern int apply_fakehost(struct Client *cptr); extern int set_user_mode(struct Client *cptr, struct Client *sptr, diff --git a/include/struct.h b/include/struct.h index 45fb6ec..7120269 100644 --- a/include/struct.h +++ b/include/struct.h @@ -85,7 +85,7 @@ struct User { char realhost[HOSTLEN + 1]; /**< actual hostname */ char fakehost[HOSTLEN + 1]; /**< fakehost */ char account[ACCOUNTLEN + 1]; /**< IRC account name */ - time_t acc_create; /**< IRC account timestamp */ + time_t acc_create; /**< IRC account timestamp */ time_t lastmsg_time; /**< time last PRIVMSG was sent */ unsigned int lastmsg_num; /**< number of prev msg that matched */ char *lastmsg; /**< last message */ diff --git a/ircd/m_account.c b/ircd/m_account.c index b7aa229..e617c84 100644 --- a/ircd/m_account.c +++ b/ircd/m_account.c @@ -145,7 +145,7 @@ int ms_account(struct Client* cptr, struct Client* sptr, int parc, has_fakehost = HasHiddenHost(acptr); ircd_strncpy(cli_user(acptr)->account, parv[2], ACCOUNTLEN); if(has_fakehost) SetAccount(acptr); - else hide_hostmask(acptr, FLAG_ACCOUNT); + else hide_hostmask(acptr, HIDE_HOSTMASK_FLAG_ACCOUNT); for(chan = (cli_user(acptr))->channel; chan; chan = chan->next_channel) { ClearBanValid(chan); diff --git a/ircd/m_fakehost.c b/ircd/m_fakehost.c index 5aa559e..793be41 100644 --- a/ircd/m_fakehost.c +++ b/ircd/m_fakehost.c @@ -113,7 +113,7 @@ int i; /* Assign and propagate the fakehost */ ircd_strncpy(cli_user(cptr)->fakehost, parv[1], HOSTLEN); - hide_hostmask(cptr, FLAG_FAKEHOST); + hide_hostmask(cptr, HIDE_HOSTMASK_FLAG_FAKEHOST); /*for(i = HighestFd; i >= 0; i--) { if((another = LocalClientArray[i]) && IsServer(another)) { @@ -137,7 +137,7 @@ int i; /* Assign and propagate the fakehost */ ircd_strncpy(cli_user(acptr)->fakehost, parv[2], HOSTLEN); - hide_hostmask(acptr, FLAG_FAKEHOST); + hide_hostmask(acptr, HIDE_HOSTMASK_FLAG_FAKEHOST); /* for(i = HighestFd; i >= 0; i--) { if((another = LocalClientArray[i]) && IsServer(another)) { @@ -252,7 +252,7 @@ int ms_fakehost(struct Client *cptr, struct Client *sptr, int parc, char *parv[] /* Set fakehost and propagate the changed host. */ ircd_strncpy(cli_user(target)->fakehost, parv[2], HOSTLEN); - hide_hostmask(target, FLAG_FAKEHOST); + hide_hostmask(target, HIDE_HOSTMASK_FLAG_FAKEHOST); /* Borrowed from send_umode_out(). * I found no better way to do this. However, maybe someone has the time to check out @@ -295,14 +295,14 @@ 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)->fakeuser, parv[2]) == 0) { + if(IsFakeHost(target) && IsFakeIdent(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); ircd_strncpy(cli_user(target)->fakeuser, parv[2], USERLEN); - hide_hostmask(target, FLAG_FAKEHOST | FLAG_FAKEIDENT); + hide_hostmask(target, HIDE_HOSTMASK_FLAG_FAKEHOST | HIDE_HOSTMASK_FLAG_FAKEIDENT); sendcmdto_serv_butone(sptr, CMD_FAKEHOST2, cptr, "%C %s %s", target, cli_user(target)->fakeuser, cli_user(target)->fakehost); @@ -334,7 +334,7 @@ int ms_fakehost_old(struct Client* cptr, struct Client* sptr, int parc, char* pa /* Assign and propagate the fakehost */ ircd_strncpy(cli_user(target)->fakehost, parv[2], HOSTLEN); - hide_hostmask(target, FLAG_FAKEHOST); + hide_hostmask(target, HIDE_HOSTMASK_FLAG_FAKEHOST); sendcmdto_serv_butone(sptr, CMD_FAKEHOST_OLD, cptr, "%C %s", target, cli_user(target)->fakehost); diff --git a/ircd/m_hidehost.c b/ircd/m_hidehost.c index 7694a36..8fd9a60 100644 --- a/ircd/m_hidehost.c +++ b/ircd/m_hidehost.c @@ -114,7 +114,7 @@ int ms_hidehost(struct Client *cptr, struct Client *sptr, int parc, char *parv[] /* Set +x and propagate the changed modes. */ propagate = !!HasPriv(acptr, PRIV_PROPAGATE); setflags = cli_flags(acptr); - hide_hostmask(acptr, FLAG_HIDDENHOST); + hide_hostmask(acptr, HIDE_HOSTMASK_FLAG_HIDDENHOST); send_umode_out(acptr, acptr, &setflags, propagate); return 0; diff --git a/ircd/s_user.c b/ircd/s_user.c index 942c44c..53cebf2 100644 --- a/ircd/s_user.c +++ b/ircd/s_user.c @@ -485,7 +485,7 @@ int register_user(struct Client *cptr, struct Client *sptr) * account assignment causes a numeric reply during registration. */ if (HasHiddenHost(sptr)) - hide_hostmask(sptr, FLAG_HIDDENHOST); + hide_hostmask(sptr, HIDE_HOSTMASK_FLAG_HIDDENHOST); if (IsInvisible(sptr)) ++UserStats.inv_clients; if (IsOper(sptr)) @@ -979,35 +979,47 @@ hide_hostmask(struct Client *cptr, unsigned int flag) struct Membership *chan; char buf[HOSTLEN]; - switch (flag) { - case FLAG_HIDDENHOST: + if (flag & HIDE_HOSTMASK_FLAG_HIDDENHOST) { /* Local users cannot set +x unless FEAT_HOST_HIDING is true. */ if (MyConnect(cptr) && !feature_bool(FEAT_HOST_HIDING)) return 0; - break; - case FLAG_ACCOUNT: - case FLAG_FAKEHOST: - case FLAG_FAKEIDENT: + } + if (flag & (HIDE_HOSTMASK_FLAG_ACCOUNT | HIDE_HOSTMASK_FLAG_FAKEHOST | HIDE_HOSTMASK_FLAG_FAKEIDENT)) { /* Invalidate all bans against the user so we check them again */ for (chan = (cli_user(cptr))->channel; chan; chan = chan->next_channel) ClearBanValid(chan); - break; - default: - /* default: no special handling */ - break; } /* Set flags and stop if no fakehost has to be applied. */ - SetFlag(cptr, flag); + if(flag & HIDE_HOSTMASK_FLAG_HIDDENHOST) + SetFlag(cptr, FLAG_HIDDENHOST); + if(flag & HIDE_HOSTMASK_FLAG_ACCOUNT) + SetFlag(cptr, FLAG_ACCOUNT); + if(flag & HIDE_HOSTMASK_FLAG_FAKEHOST) + SetFlag(cptr, FLAG_FAKEHOST); + if(flag & HIDE_HOSTMASK_FLAG_FAKEIDENT) + SetFlag(cptr, FLAG_FAKEIDENT); + if(!HasHiddenHost(cptr)) return 0; /* Generate new fakehost. */ - 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 && (!IsFakeIdent(cptr) || strncmp(cli_user(cptr)->fakeuser, cli_user(cptr)->username, USERLEN) == 0)) return 0; + unsigned int reregister = 0; + if(IsFakeHost(cptr) || IsAccount(cptr)) { + if(IsFakeHost(cptr)) + ircd_strncpy(buf, cli_user(cptr)->fakehost, HOSTLEN); + else + ircd_snprintf(0, buf, HOSTLEN, "%s.%s", cli_user(cptr)->account, feature_str(FEAT_HIDDEN_HOST)); + if(strncmp(buf, cli_user(cptr)->host, HOSTLEN)) + reregister |= HIDE_HOSTMASK_FLAG_FAKEHOST; + } + if(IsFakeIdent(cptr)) { + if(strncmp(cli_user(cptr)->fakeuser, cli_user(cptr)->username, USERLEN)) + reregister |= HIDE_HOSTMASK_FLAG_FAKEIDENT; + } + + if (!reregister) return 0; /* Remove all "valid" marks on the bans. This forces them to be * rechecked if the ban is accessed again. @@ -1018,20 +1030,17 @@ hide_hostmask(struct Client *cptr, unsigned int flag) /* Quit user and set the previously generated fakehost. */ sendcmdto_common_channels_butone(cptr, CMD_QUIT, cptr, ":Registered"); - ircd_strncpy(cli_user(cptr)->host, buf, HOSTLEN); - - /* spoof also the username if username is passed */ - if(IsFakeIdent(cptr)) { - if(strncmp(cli_user(cptr)->username, cli_user(cptr)->fakeuser, USERLEN) != 0) { - ircd_strncpy(cli_username(cptr), cli_user(cptr)->fakeuser, USERLEN); - 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)) + if(reregister & HIDE_HOSTMASK_FLAG_FAKEHOST) + ircd_strncpy(cli_user(cptr)->host, buf, HOSTLEN); + if(reregister & HIDE_HOSTMASK_FLAG_FAKEIDENT) + 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)) { + if (IsFakeIdent(cptr)) send_reply(cptr, RPL_HOSTUSERHIDDEN, cli_user(cptr)->username, cli_user(cptr)->host); - } else { - /* ok, the client is now fully hidden, so let them know -- hikari */ - if (MyConnect(cptr)) + else send_reply(cptr, RPL_HOSTHIDDEN, cli_user(cptr)->host); } -- 2.20.1