]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/proto-p10.c
Added basic support to X3 for host hiding style 3
[irc/evilnet/x3.git] / src / proto-p10.c
index 880ac402f131355dd5980764299615ae2fe44520..f3cd0f9bf568dd8fb552ea1d0d4e0100715fd7c1 100644 (file)
@@ -85,6 +85,7 @@
 #define CMD_RESTART             "RESTART"
 #define CMD_RPING               "RPING"
 #define CMD_RPONG               "RPONG"
+#define CMD_SASL                "SASL"
 #define CMD_SERVER              "SERVER"
 #define CMD_SERVLIST            "SERVLIST"
 #define CMD_SERVSET             "SERVSET"
 #define TOK_PONG                "Z"
 #define TOK_POST                "POST"
 #define TOK_PRIVMSG             "P"
-#define TOK_PRIVS              "PR"
+#define TOK_PRIVS              "PRIVS"
 #define TOK_PROTO               "PROTO"
 #define TOK_QUIT                "Q"
 #define TOK_REHASH              "REHASH"
 #define TOK_RESTART             "RESTART"
 #define TOK_RPING               "RI"
 #define TOK_RPONG               "RO"
+#define TOK_SASL                "SASL"
 #define TOK_SERVER              "S"
 #define TOK_SERVLIST            "SERVSET"
 #define TOK_SERVSET             "SERVSET"
 #define P10_RESTART             TYPE(RESTART)
 #define P10_RPING               TYPE(RPING)
 #define P10_RPONG               TYPE(RPONG)
+#define P10_SASL                TYPE(SASL)
 #define P10_SERVER              CMD_SERVER
 #define P10_SERVLIST            TYPE(SERVLIST)
 #define P10_SERVSET             TYPE(SERVSET)
@@ -1094,23 +1097,27 @@ void
 irc_topic(struct userNode *service, struct userNode *who, struct chanNode *what, const char *topic)
 {
 
-   int type = 4, host_in_topic = 0, hasident = 0;
-   const char *hstr, *tstr;
+   int type = 4, host_in_topic = 0, hasident = 0, hhtype = 0;
+   const char *hstr, *tstr, *hhstr, *htstr;
    char *host, *hostmask;
    char shost[MAXLEN];
    char sident[MAXLEN];
 
    tstr = conf_get_data("server/type", RECDB_QSTRING);
    hstr = conf_get_data("server/host_in_topic", RECDB_QSTRING);
+   hhstr = conf_get_data("server/hidden_host", RECDB_QSTRING);
+   htstr = conf_get_data("server/hidden_host_type", RECDB_QSTRING);
    if(tstr)
      type = atoi(tstr);
    else
      type = 4;/* default to 040 style topics */
+   if (htstr)
+     hhtype = atoi(htstr);
 
    if (hstr) {
-      if (IsFakeHost(who))
+      if (IsHiddenHost(who) && IsFakeHost(who))
           safestrncpy(shost, who->fakehost, sizeof(shost));
-      else if (IsSetHost(who)) {
+      else if (IsHiddenHost(who) && IsSetHost(who)) {
           hostmask = strdup(who->sethost);
           if ((host = (strrchr(hostmask, '@')))) {
               hasident = 1;
@@ -1124,6 +1131,10 @@ irc_topic(struct userNode *service, struct userNode *who, struct chanNode *what,
               safestrncpy(sident, who->ident, sizeof(shost));
 
           safestrncpy(shost, host, sizeof(shost));
+      } else if (IsHiddenHost(who) && ((hhtype == 1) || (hhtype == 3)) && who->handle_info && hhstr) {
+          snprintf(shost, sizeof(shost), "%s.%s", who->handle_info->handle, hhstr);
+      } else if (IsHiddenHost(who) && ((hhtype == 2) || (hhtype == 3)) && who->crypthost[0]) {
+          safestrncpy(shost, who->crypthost, sizeof(shost));
       } else
           safestrncpy(shost, who->hostname, sizeof(shost));
 
@@ -1208,6 +1219,12 @@ void irc_sno(unsigned int mask, char const* format, ...) {
     putsock("%s " CMD_SNO " %d :%s", self->numeric, mask, buffer);
 }
 
+void
+irc_sasl(struct server* dest, const char *identifier, const char *subcmd, const char *data)
+{
+    putsock("%s " P10_SASL " %s %s %s %s", self->numeric, dest->numeric, identifier, subcmd, data);
+}
+
 static void send_burst(void);
 
 static void
@@ -1426,6 +1443,22 @@ static CMD_FUNC(cmd_rping)
     return 1;
 }
 
+static CMD_FUNC(cmd_sasl)
+{
+    struct server *serv;
+
+    if (argc < 5)
+        return 0;
+
+    serv = GetServerH(origin);
+    if (!serv)
+      return 0;
+
+    call_sasl_input_func(serv, argv[2], argv[3], argv[4], (argc>5 ? argv[5] : NULL));
+
+    return 1;
+}
+
 static CMD_FUNC(cmd_ping)
 {
     struct server *srv;
@@ -1835,24 +1868,14 @@ static CMD_FUNC(cmd_burst)
             break;
         }
         case '%': {
+            ctype = 1;
             for(parm = mysep(&argv[next], " "); /* parm = first param */
                   parm;   /* While param is not null */
                   parm = mysep(&argv[next], " ")  /* parm = next param */
                )
             {
-              switch (parm[0]) {
-                case '%': {
-                  ctype = 1;
-                  break;
-                }
-                case '~': {
-                  ctype = 2;
-                  break;
-                }
-                default: {
-                  break;
-                }
-              }
+              if (0 == strcmp("~", parm))
+                ctype = 2;
               if (ctype == 1) {
                 if (bcheck == 0) {
                   /* strip % char off start of very first ban */
@@ -2241,9 +2264,11 @@ static CMD_FUNC(cmd_kill)
          * Ghost response to a KILL we sent out earlier.  So we only
          * whine if the target is local.
          */
-        if (!strncmp(argv[1], self->numeric, strlen(self->numeric)))
+        if (!strncmp(argv[1], self->numeric, strlen(self->numeric))) {
             log_module(MAIN_LOG, LOG_ERROR, "Unable to find kill victim %s", argv[1]);
-        return 0;
+            return 0;
+        }
+        return 1;
     }
 
     if (IsLocal(user) && IsService(user)) {
@@ -2673,6 +2698,9 @@ init_parse(void)
     dict_insert(irc_func_dict, CMD_RPONG, cmd_dummy);
     dict_insert(irc_func_dict, TOK_RPONG, cmd_dummy);
 
+    dict_insert(irc_func_dict, CMD_SASL, cmd_sasl);
+    dict_insert(irc_func_dict, TOK_SASL, cmd_sasl);
+
     /* In P10, DESTRUCT doesn't do anything except be broadcast to servers.
      * Apparently to obliterate channels from any servers that think they
      * exist?
@@ -3807,7 +3835,7 @@ mod_chanmode_format(struct mod_chanmode *change, char *outbuff)
 
 #define DO_MODE_PARM(BIT, PARM) if (change->modes_set & MODE_##BIT) used += sprintf(outbuff+used, " %s", PARM);
        DO_MODE_PARM(KEY, change->new_key);
-       DO_MODE_PARM(LIMIT, change->new_limit);
+       if (change->modes_set & MODE_LIMIT) used += sprintf(outbuff+used, " %d", change->new_limit);
        DO_MODE_PARM(APASS, change->new_apass);
        DO_MODE_PARM(UPASS, change->new_upass);
 #undef DO_MODE_PARM