extended & fixed FAKEIDENT support
[ircu2.10.12-pk.git] / ircd / m_fakehost.c
index 7dd31fd0035b64e4d43811929b8f77035acc39a0..5aa559e59a80c907a240287ab34f7b10b628dd96 100644 (file)
@@ -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
  *
@@ -267,12 +267,55 @@ 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)->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);
+
+    sendcmdto_serv_butone(sptr, CMD_FAKEHOST2, cptr, "%C %s %s", target, cli_user(target)->fakeuser, cli_user(target)->fakehost);
+
+    return 0;
+}
+
 /*
  * ms_fakehost_old - old fakehost server message handler
  *
  * 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;