From 21ced3d1658353412b92c551df8b095022449c82 Mon Sep 17 00:00:00 2001 From: pk910 Date: Sun, 17 Jul 2011 03:58:21 +0200 Subject: [PATCH] added possibility for FAKEIDENTS (srvx initialized) --- include/handlers.h | 1 + include/msg.h | 4 ++++ include/numeric.h | 1 + ircd/m_fakehost.c | 42 ++++++++++++++++++++++++++++++++++++++++++ ircd/parse.c | 7 +++++++ ircd/s_err.c | 2 +- ircd/s_user.c | 22 ++++++++++++++++++---- 7 files changed, 74 insertions(+), 5 deletions(-) diff --git a/include/handlers.h b/include/handlers.h index 8d52215..1fed409 100644 --- a/include/handlers.h +++ b/include/handlers.h @@ -194,6 +194,7 @@ extern int ms_end_of_burst(struct Client*, struct Client*, int, char*[]); extern int ms_end_of_burst_ack(struct Client*, struct Client*, int, char*[]); extern int ms_error(struct Client*, struct Client*, int, char*[]); extern int ms_fakehost(struct Client*, struct Client*, int, char*[]); +extern int ms_fakehost2(struct Client*, struct Client*, int, char*[]); extern int ms_fakehost_old(struct Client*, struct Client*, int, char*[]); extern int ms_gline(struct Client*, struct Client*, int, char*[]); extern int ms_hidehost(struct Client*, struct Client*, int, char*[]); diff --git a/include/msg.h b/include/msg.h index a7448d6..eae4766 100644 --- a/include/msg.h +++ b/include/msg.h @@ -364,6 +364,10 @@ struct Client; #define TOK_FAKEHOST "FH" #define CMD_FAKEHOST MSG_FAKEHOST, TOK_FAKEHOST +#define MSG_FAKEHOST2 "FAKEHOST2" +#define TOK_FAKEHOST2 "FH2" +#define CMD_FAKEHOST2 MSG_FAKEHOST2, TOK_FAKEHOST2 + #define MSG_FAKEHOST_OLD "FAKE" #define TOK_FAKEHOST_OLD "FA" #define CMD_FAKEHOST_OLD MSG_FAKEHOST_OLD, TOK_FAKEHOST_OLD diff --git a/include/numeric.h b/include/numeric.h index ba7affe..ebabc1c 100644 --- a/include/numeric.h +++ b/include/numeric.h @@ -319,6 +319,7 @@ extern const struct Numeric* get_error_numeric(int err); /* RPL_END_USERS 394 Dalnet/EFnet/IRCnet */ /* RPL_NOUSERS 395 Dalnet/EFnet/IRCnet */ #define RPL_HOSTHIDDEN 396 /* UMODE +x completed succesfuly */ +#define RPL_HOSTIDENTHIDDEN 397 /* UMODE +x completed succesfuly (with USERNAME change) */ /* * Errors are in the range from 400-599 currently and are grouped by what diff --git a/ircd/m_fakehost.c b/ircd/m_fakehost.c index 7dd31fd..fa8ff3b 100644 --- a/ircd/m_fakehost.c +++ b/ircd/m_fakehost.c @@ -267,6 +267,48 @@ int ms_fakehost(struct Client *cptr, struct Client *sptr, int parc, char *parv[] return 0; } +/* ms_fakehost2 - new fakehost server message handler (SRVX initialized) + * + * parv[0] = sender prefix + * parv[1] = target user numeric + * parv[2] = target user's new ident + * parv[3] = target user's new fake host + * parv[4] = FORCE (optional) + */ +/** Remote fakehost + * Allows servers to force a fakehost on remote users. + * + * The FAKEHOST request can be generated by EVERY server. It is forwarded to the server + * of the user which then sets the fakehost and broadcasts the new fakehost. + */ +int ms_fakehost2(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) { + struct Client *target, *acptr; + int i; + + if(parc < 4) { + return need_more_params(sptr, "FAKEHOST"); + } + + if(!(target = findNUser(parv[1]))) { + /* Silently ignore FAKEHOSTs for disconnected users. */ + return 0; + } + + /* 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) { + return 0; + } + + /* Set fakehost and propagate the changed host. */ + ircd_strncpy(cli_user(target)->username, parv[2], USERLEN); + ircd_strncpy(cli_user(target)->fakehost, parv[3], HOSTLEN); + hide_hostmask(target, FLAG_FAKEHOST); + + sendcmdto_serv_butone(sptr, CMD_FAKEHOST2, cptr, "%C %s %s", target, parv[2], parv[3]); + + return 0; +} + /* * ms_fakehost_old - old fakehost server message handler * diff --git a/ircd/parse.c b/ircd/parse.c index 8a58d5b..49e6564 100644 --- a/ircd/parse.c +++ b/ircd/parse.c @@ -633,6 +633,13 @@ struct Message msgtab[] = { /* UNREG, CLIENT, SERVER, OPER, SERVICE */ { m_ignore, m_not_oper, ms_fakehost, m_fakehost, m_ignore } }, + { + MSG_FAKEHOST2, + TOK_FAKEHOST2, + 0, MAXPARA, MFLG_SLOW, 0, NULL, + /* UNREG, CLIENT, SERVER, OPER, SERVICE */ + { m_ignore, m_ignore, ms_fakehost2, m_ignore, m_ignore } + }, { MSG_FAKEHOST_OLD, TOK_FAKEHOST_OLD, diff --git a/ircd/s_err.c b/ircd/s_err.c index 99501c6..e088771 100644 --- a/ircd/s_err.c +++ b/ircd/s_err.c @@ -826,7 +826,7 @@ static Numeric replyTable[] = { /* 396 */ { RPL_HOSTHIDDEN, "%s :is now your hidden host", "396" }, /* 397 */ - { 0 }, + { RPL_HOSTIDENTHIDDEN, "%s@%s :is now your hidden username@host", "397" }, /* 398 */ { 0 }, /* 399 */ diff --git a/ircd/s_user.c b/ircd/s_user.c index f8d5b94..3855fbc 100644 --- a/ircd/s_user.c +++ b/ircd/s_user.c @@ -972,8 +972,14 @@ void send_user_info(struct Client* sptr, char* names, int rpl, InfoFormatter fmt * @param[in] flag Some flag that affects host-hiding (FLAG_HIDDENHOST, FLAG_ACCOUNT, FLAG_FAKEHOST). * @return Zero. */ + int -hide_hostmask(struct Client *cptr, unsigned int flag) +hide_hostmask(struct Client *cptr, unsigned int flag) { + return hide_hostmask(chptr, flag, NULL); +} + +int +hide_hostmask(struct Client *cptr, unsigned int flag, char *username) { struct Membership *chan; char buf[HOSTLEN]; @@ -1018,9 +1024,17 @@ hide_hostmask(struct Client *cptr, unsigned int flag) sendcmdto_common_channels_butone(cptr, CMD_QUIT, cptr, ":Registered"); ircd_strncpy(cli_user(cptr)->host, buf, HOSTLEN); - /* ok, the client is now fully hidden, so let them know -- hikari */ - if (MyConnect(cptr)) - send_reply(cptr, RPL_HOSTHIDDEN, cli_user(cptr)->host); + /* spoof also the username if username is passed */ + if(username) { + ircd_strncpy(cli_user(cptr)->username, username, 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); + } else { + /* ok, the client is now fully hidden, so let them know -- hikari */ + if (MyConnect(cptr)) + send_reply(cptr, RPL_HOSTHIDDEN, cli_user(cptr)->host); + } /* * Go through all channels the client was on, rejoin him -- 2.20.1