--- oftc-hybrid-1.6.7bc3r1/modules/m_rehash.c	2009-11-07 23:28:31.000000000 -0500
+++ bc4dev/modules/m_rehash.c	2009-11-11 02:55:28.000000000 -0500
@@ -19,7 +19,6 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
  *
- *  $Id: m_rehash.c 605 2006-06-08 21:26:01Z stu $
  */
 
 #include "stdinc.h"
@@ -29,6 +28,7 @@
 #include "irc_string.h"
 #include "ircd.h"
 #include "list.h"
+#include "s_serv.h"
 #include "numeric.h"
 #include "irc_res.h"
 #include "s_conf.h"
@@ -38,11 +38,18 @@
 #include "parse.h"
 #include "modules.h"
 
-static void mo_rehash(struct Client *, struct Client *, int, char **);
+ /* hybrid7 remote rehash... and kill win32 code, fuck 'em
+    adapted to hybrid 7.2.2(+oftc1.6.7+bc4) from jilles ratbox 2.1 patch
+    adds SHARED_REHASH (s_conf.h, ircd_parser.y)
+                                -- avenj 10 nov 09 
+ */
+
+static int mo_rehash(struct Client *, struct Client *, int, char **);
+static int ms_rehash(struct Client *, struct Client *, int, char **);
 
 struct Message rehash_msgtab = {
   "REHASH", 0, 0, 0, 0, MFLG_SLOW, 0,
-  {m_unregistered, m_not_oper, m_ignore, m_ignore, mo_rehash, m_ignore}
+  {m_unregistered, m_not_oper, mo_rehash, ms_rehash, mo_rehash, m_ignore}
 };
 
 #ifndef STATIC_MODULES
@@ -58,50 +65,37 @@
   mod_del_cmd(&rehash_msgtab);
 }
 
-const char *_version = "$Revision: 605 $";
+const char *_version = "bc4-rev0";
 #endif
 
-/*
- * mo_rehash - REHASH message handler
- *
- */
 static void
-mo_rehash(struct Client *client_p, struct Client *source_p,
-          int parc, char *parv[])
+do_rehash(struct Client *source_p, const char *type)      /* actual rehash */
 {
   int found = 0;
 
-  if (!IsOperRehash(source_p))
+  if (type != NULL)
   {
-    sendto_one(source_p, form_str(ERR_NOPRIVS),
-               me.name, source_p->name, "rehash");
-    return;
-  }
 
-  if (parc > 1)
-  {
-#ifndef _WIN32
-    if (irccmp(parv[1], "DNS") == 0)
+    if (irccmp(type, "DNS") == 0)
     {
-      sendto_one(source_p, form_str(RPL_REHASHING), me.name, parv[0], "DNS");
+      sendto_one(source_p, form_str(RPL_REHASHING), me.name, me.name, "DNS");
       sendto_gnotice_flags(UMODE_ALL, L_ALL, me.name, &me, NULL, "%s is rehashing DNS",
                            get_oper_name(source_p));
       restart_resolver();   /* re-read /etc/resolv.conf AGAIN?
                                and close/re-open res socket */
       found = 1;
     }
-    else if (irccmp(parv[1], "FDLIMIT") == 0)
+    else if (irccmp(type, "FDLIMIT") == 0)
     {
       sendto_one(source_p, form_str(RPL_REHASHING), me.name,
-                 parv[0], "FDLIMIT");
+                 me.name, "FDLIMIT");
       sendto_gnotice_flags(UMODE_ALL, L_ALL, me.name, &me, NULL, "%s is updating FDLIMIT",
                            get_oper_name(source_p));
       recalc_fdlimit(NULL);
       found = 1;
     }
     else
-#endif
-    if (irccmp(parv[1], "MOTD") == 0)
+    if (irccmp(type, "MOTD") == 0)
     {
       sendto_gnotice_flags(UMODE_ALL, L_ALL, me.name, &me, NULL,
                            "%s is forcing re-reading of MOTD file",
@@ -109,7 +103,7 @@
       read_message_file(&ConfigFileEntry.motd);
       found = 1;
     }
-    else if (irccmp(parv[1], "OMOTD") == 0)
+    else if (irccmp(type, "OMOTD") == 0)
     {
       sendto_gnotice_flags(UMODE_ALL, L_ALL, me.name, &me, NULL,
                            "%s is forcing re-reading of OPER MOTD file",
@@ -121,18 +115,13 @@
     if (found)
     {
       ilog(L_NOTICE, "REHASH %s From %s",
-           parv[1], get_client_name(source_p, HIDE_IP));
+           type, get_client_name(source_p, HIDE_IP));
       return;
     }
     else
     {
-#ifdef _WIN32
-      sendto_one(source_p, ":%s NOTICE %s :rehash one of :MOTD OMOTD",
-                 me.name, source_p->name);
-#else
       sendto_one(source_p, ":%s NOTICE %s :rehash one of :DNS FDLIMIT "
                  "MOTD OMOTD", me.name, source_p->name);
-#endif
       return;
     }
   }
@@ -141,11 +130,66 @@
     sendto_one(source_p, form_str(RPL_REHASHING),
                me.name, source_p->name, ConfigFileEntry.configfile);
     sendto_gnotice_flags(UMODE_ALL, L_ALL, me.name, &me, NULL,
-                         "%s is rehashing server config file",
-                         get_oper_name(source_p));
-    ilog(L_NOTICE, "REHASH From %s[%s]",
-         get_oper_name(source_p), source_p->sockhost);
+                         "%s [%s] is rehashing server config file",
+                         get_oper_name(source_p), source_p->servptr->name);
+    ilog(L_NOTICE, "REHASH from %s[%s] on %s",
+         get_oper_name(source_p), source_p->sockhost, source_p->servptr->name);
     rehash(0);
   }
 }
 
+static int
+mo_rehash(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
+{
+    const char *type = NULL, *target_server = NULL;
+
+  if (!IsOperRehash(source_p))
+  {
+    sendto_one(source_p, form_str(ERR_NOPRIVS),
+               me.name, source_p->name, "rehash");
+    return 0;
+  }
+
+  if (parc > 2)
+      type = parv[1], target_server = parv[2];
+  else if (parc > 1 && (strchr(parv[1], '.') || strchr(parv[1], '?') || strchr(parv[1], '*')))
+      type = NULL, target_server = parv[1];
+  else if (parc > 1)
+      type = parv[1], target_server = NULL;
+  else
+      type = NULL, target_server = NULL;
+
+   if (target_server != NULL)
+   {
+      if(!IsOperRemoteBan(source_p))
+      {
+        sendto_one(source_p, form_str(ERR_NOPRIVS),
+                  me.name, source_p->name, "remoteban");
+                  return 0;
+      }
+      sendto_match_servs(source_p, target_server,
+                        CAP_ENCAP, "ENCAP %s REHASH %s",
+                         target_server, type != NULL ? type : "");
+      if (match(target_server, me.name) == 0)
+			return 0;
+    }
+
+    do_rehash(source_p, type);
+
+    return 0;
+}
+
+static int
+ms_rehash(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
+{
+   if (!IsClient(source_p))
+       return 0;
+
+   if (!find_matching_name_conf(ULINE_TYPE, source_p->servptr->name,
+       source_p->username, source_p->host, SHARED_REHASH))
+       return 0;
+
+   do_rehash(source_p, parc > 1 ? parv[1] : NULL);
+
+   return 0;
+}

--- oftc-hybrid-1.6.7bc3r1/include/s_conf.h	2009-11-07 23:28:31.000000000 -0500
+++ bc4dev/include/s_conf.h	2009-11-10 21:22:04.000000000 -0500
@@ -317,10 +317,12 @@
 #define SHARED_TRESV		0x0080
 #define SHARED_UNRESV		0x0100
 #define SHARED_LOCOPS           0x0200
+/* remote rehash */
+#define SHARED_REHASH           0x0400
 #define SHARED_ALL		(SHARED_KLINE | SHARED_TKLINE | SHARED_UNKLINE | \
 				 SHARED_XLINE | SHARED_TXLINE | SHARED_UNXLINE | \
 				 SHARED_RESV | SHARED_TRESV | SHARED_UNRESV |\
-                                 SHARED_LOCOPS)
+                                 SHARED_LOCOPS | SHARED_REHASH)
 
 /* gline acl entry actions */
 #define GDENY_BLOCK		0x1

--- oftc-hybrid-1.6.7bc3r1/src/ircd_parser.y	2009-11-07 23:28:31.000000000 -0500
+++ bc4dev/src/ircd_parser.y	2009-11-11 02:46:15.000000000 -0500
@@ -2390,6 +2390,10 @@
 {
   if (ypass == 2)
     yy_match_item->action |= SHARED_LOCOPS;
+} | REHASH
+{
+  if (ypass == 2)
+    yy_match_item->action |=SHARED_REHASH;
 } | T_ALL
 {
   if (ypass == 2)

