Fix SourceForge bug #1674539, and add a test for it.
[ircu2.10.12-pk.git] / ircd / m_version.c
index 082deefcfaa1160920fe78fec36148dc70996b05..340991b81ccf114aa6911c940f3c5023d3f85bd9 100644 (file)
@@ -85,7 +85,7 @@
 #include "hash.h"
 #include "ircd.h"
 #include "ircd_features.h"
-#include "ircd_policy.h"
+#include "ircd_log.h"
 #include "ircd_reply.h"
 #include "ircd_snprintf.h"
 #include "ircd_string.h"
 #include "supported.h"
 #include "version.h"
 
-#include <assert.h>
+/* #include <assert.h> -- Now using assert in ircd_log.h */
 
 /*
  * m_version - generic message handler
  *
  *   parv[0] = sender prefix
- *   parv[1] = remote server
+ *   parv[1] = servername
  */
 int m_version(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
+{
+  struct Client *acptr;
+  if (parc > 1 && (!(acptr = find_match_server(parv[1])) || !IsMe(acptr)))
+    send_reply(sptr, ERR_NOPRIVILEGES);
+  else
+  {
+    send_reply(sptr, RPL_VERSION, version, debugmode, cli_name(&me),
+               debug_serveropts());
+    send_supported(sptr);
+  }
+  return 0;
+}
+
+/*
+ * mo_version - oper message handler
+ *
+ *   parv[0] = sender prefix
+ *   parv[1] = servername
+ */
+int mo_version(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 {
   struct Client *acptr;
 
@@ -120,16 +140,14 @@ int m_version(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     parv[1] = cli_name(acptr);
   }
 
-  if (hunt_server_cmd(sptr, CMD_VERSION, cptr, HEAD_IN_SAND_REMOTE, ":%C", 1,
-                     parc, parv) == HUNTED_ISME)
+  if (hunt_server_cmd(sptr, CMD_VERSION, cptr, feature_int(FEAT_HIS_REMOTE),
+                                                           ":%C", 1,
+                                                           parc, parv)
+                      == HUNTED_ISME)
   {
-    char featurebuf[512];
-    
-    ircd_snprintf(0, featurebuf, sizeof(featurebuf), FEATURES, FEATURESVALUES);
-    
     send_reply(sptr, RPL_VERSION, version, debugmode, cli_name(&me),
               debug_serveropts());
-    send_reply(sptr, RPL_ISUPPORT, featurebuf);
+    send_supported(sptr);
   }
 
   return 0;
@@ -139,7 +157,7 @@ int m_version(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
  * ms_version - server message handler
  *
  *   parv[0] = sender prefix
- *   parv[1] = remote server
+ *   parv[1] = servername
  */
 int ms_version(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 {