Committer  : entrope
CVSROOT    : /cvsroot/undernet-ircu
Module     : ircu2.10
Commit time: 2005-04-09 03:37:25 UTC

Modified files:
     ChangeLog include/s_conf.h ircd/ircd.c ircd/ircd_string.c
     ircd/m_whowas.c ircd/s_conf.c

Log message:

Add option to debug Client block selections.  Fix related buglet in
ircd_aton().  Clarify oper-specific output of /whowas.

---------------------- diff included ----------------------
Index: ircu2.10/ChangeLog
diff -u ircu2.10/ChangeLog:1.592 ircu2.10/ChangeLog:1.593
--- ircu2.10/ChangeLog:1.592    Wed Apr  6 19:45:03 2005
+++ ircu2.10/ChangeLog  Fri Apr  8 20:37:15 2005
@@ -1,3 +1,19 @@
+2005-04-08  Michael Poole <[EMAIL PROTECTED]>
+
+       * include/s_conf.h (conf_debug_iline): Declare new function.
+
+       * ircd/ircd.c (dbg_client): New file-scoped variable.
+       (parse_command_line): Set it from the new -c option.
+       (main): If dbg_client is set during chkconf, use it.
+
+       * ircd/ircd_string.c (ircd_aton): Generate IPv4-mapped addresses,
+       not IPv4-compatible addresses, to match ipmask_parse().
+
+       * ircd/m_whowas.c (m_whowas): Split display of real host to a
+       separate line, in hopes of not confusing opers in the future.
+
+       * ircd/s_conf.c (conf_debug_iline): Implement new function.
+
 2005-04-06  Michael Poole <[EMAIL PROTECTED]>
 
        * ircd/m_burst.c (ms_burst): Clear channel manager bit when wiping
Index: ircu2.10/include/s_conf.h
diff -u ircu2.10/include/s_conf.h:1.30 ircu2.10/include/s_conf.h:1.31
--- ircu2.10/include/s_conf.h:1.30      Fri Apr  1 19:32:37 2005
+++ ircu2.10/include/s_conf.h   Fri Apr  8 20:37:15 2005
@@ -1,6 +1,6 @@
 /** @file s_conf.h
  * @brief ircd configuration file API.
- * @version $Id: s_conf.h,v 1.30 2005/04/02 03:32:37 entrope Exp $
+ * @version $Id: s_conf.h,v 1.31 2005/04/09 03:37:15 entrope Exp $
  */
 #ifndef INCLUDED_s_conf_h
 #define INCLUDED_s_conf_h
@@ -183,6 +183,7 @@
 extern const char *find_quarantine(const char* chname);
 extern void lookup_confhost(struct ConfItem *aconf);
 extern void conf_parse_userhost(struct ConfItem *aconf, char *host);
+extern struct ConfItem *conf_debug_iline(const char *client);
 
 extern void yyerror(const char *msg);
 
Index: ircu2.10/ircd/ircd.c
diff -u ircu2.10/ircd/ircd.c:1.82 ircu2.10/ircd/ircd.c:1.83
--- ircu2.10/ircd/ircd.c:1.82   Sun Mar 20 08:06:17 2005
+++ ircu2.10/ircd/ircd.c        Fri Apr  8 20:37:15 2005
@@ -19,7 +19,7 @@
  */
 /** @file
  * @brief Entry point and other initialization functions for the daemon.
- * @version $Id: ircd.c,v 1.82 2005/03/20 16:06:17 entrope Exp $
+ * @version $Id: ircd.c,v 1.83 2005/04/09 03:37:15 entrope Exp $
  */
 #include "config.h"
 
@@ -108,6 +108,7 @@
 int            debuglevel        = -1;    /**< Server debug level  */
 char          *debugmode         = "";    /**< Server debug level */
 static char   *dpath             = DPATH; /**< Working directory for daemon */
+static char   *dbg_client;                /**< Client specifier for chkconf */
 
 static struct Timer connect_timer; /**< timer structure for try_connections() 
*/
 static struct Timer ping_timer; /**< timer structure for check_pings() */
@@ -451,7 +452,7 @@
  * @param[in,out] argv Command-lne arguments.
  */
 static void parse_command_line(int argc, char** argv) {
-  const char *options = "d:f:h:nktvx:";
+  const char *options = "d:f:h:nktvx:c:";
   int opt;
 
   if (thisServer.euid != thisServer.uid)
@@ -463,6 +464,7 @@
   while ((opt = getopt(argc, argv, options)) != EOF)
     switch (opt) {
     case 'k':  thisServer.bootopt |= BOOT_CHKCONF | BOOT_TTY; break;
+    case 'c':  dbg_client = optarg;                    break;
     case 'n':
     case 't':  thisServer.bootopt |= BOOT_TTY;         break;
     case 'd':  dpath      = optarg;                    break;
@@ -487,7 +489,7 @@
 
       exit(0);
       break;
-      
+
     case 'x':
       debuglevel = atoi(optarg);
       if (debuglevel < 0)
@@ -675,6 +677,8 @@
   }
 
   if (thisServer.bootopt & BOOT_CHKCONF) {
+    if (dbg_client)
+      conf_debug_iline(dbg_client);
     fprintf(stderr, "Configuration file %s checked okay.\n", configfile);
     return 0;
   }
Index: ircu2.10/ircd/ircd_string.c
diff -u ircu2.10/ircd/ircd_string.c:1.20 ircu2.10/ircd/ircd_string.c:1.21
--- ircu2.10/ircd/ircd_string.c:1.20    Sun Mar 20 08:06:18 2005
+++ ircu2.10/ircd/ircd_string.c Fri Apr  8 20:37:15 2005
@@ -18,7 +18,7 @@
  */
 /** @file
  * @brief Implementation of string operations.
- * @version $Id: ircd_string.c,v 1.20 2005/03/20 16:06:18 entrope Exp $
+ * @version $Id: ircd_string.c,v 1.21 2005/04/09 03:37:15 entrope Exp $
  */
 #include "config.h"
 
@@ -667,6 +667,7 @@
     unsigned int addr;
     int len = ircd_aton_ip4(input, &addr);
     if (len) {
+      ip->in6_16[5] = htons(65535);
       ip->in6_16[6] = htons(ntohl(addr) >> 16);
       ip->in6_16[7] = htons(ntohl(addr) & 65535);
       return len;
Index: ircu2.10/ircd/m_whowas.c
diff -u ircu2.10/ircd/m_whowas.c:1.9 ircu2.10/ircd/m_whowas.c:1.10
--- ircu2.10/ircd/m_whowas.c:1.9        Sun Mar 20 08:06:29 2005
+++ ircu2.10/ircd/m_whowas.c    Fri Apr  8 20:37:15 2005
@@ -20,7 +20,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: m_whowas.c,v 1.9 2005/03/20 16:06:29 entrope Exp $
+ * $Id: m_whowas.c,v 1.10 2005/04/09 03:37:15 entrope Exp $
  */
 
 /*
@@ -137,8 +137,9 @@
       if (0 == ircd_strcmp(nick, temp->name))
       {
        send_reply(sptr, RPL_WHOWASUSER, temp->name, temp->username,
-                  (IsAnOper(sptr) && temp->realhost) ? temp->realhost :
                   temp->hostname, temp->realname);
+        if (IsAnOper(sptr) && strcmp(temp->hostname, temp->realhost))
+          send_reply(sptr, RPL_WHOISACTUALLY, temp->name, temp->username, 
temp->realhost);
         send_reply(sptr, RPL_WHOISSERVER, temp->name,
                    (feature_bool(FEAT_HIS_WHOIS_SERVERNAME) && !IsOper(sptr)) ?
                      feature_str(FEAT_HIS_SERVERNAME) :
Index: ircu2.10/ircd/s_conf.c
diff -u ircu2.10/ircd/s_conf.c:1.72 ircu2.10/ircd/s_conf.c:1.73
--- ircu2.10/ircd/s_conf.c:1.72 Sun Mar 20 08:06:30 2005
+++ ircu2.10/ircd/s_conf.c      Fri Apr  8 20:37:15 2005
@@ -19,7 +19,7 @@
  */
 /** @file
  * @brief ircd configuration file driver
- * @version $Id: s_conf.c,v 1.72 2005/03/20 16:06:30 entrope Exp $
+ * @version $Id: s_conf.c,v 1.73 2005/04/09 03:37:15 entrope Exp $
  */
 #include "config.h"
 
@@ -383,6 +383,9 @@
   for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
     if (aconf->status != CONF_CLIENT)
       continue;
+    /* If you change any of this logic, please make corresponding
+     * changes in conf_debug_iline() below.
+     */
     if (aconf->address.port && aconf->address.port != 
cli_listener(cptr)->addr.port)
       continue;
     if (aconf->username) {
@@ -400,6 +403,103 @@
   return ACR_NO_AUTHORIZATION;
 }
 
+/** Interpret \a client as a client specifier and show which Client
+ * block(s) match that client.
+ *
+ * The client specifier may contain an IP address, hostname, listener
+ * port, or a combination of those separated by commas.  IP addresses
+ * and hostnamese may be preceded by "username@"; the last given
+ * username will be used for the match.
+ *
+ * @param[in] client Client specifier.
+ * @return Matching Client block structure.
+ */
+struct ConfItem *conf_debug_iline(const char *client)
+{
+  struct irc_in_addr address;
+  struct ConfItem *aconf;
+  char *sep;
+  unsigned short listener;
+  char username[USERLEN+1], hostname[HOSTLEN+1];
+
+  /* Initialize variables. */
+  listener = 0;
+  memset(&address, 0, sizeof(address));
+  memset(&username, 0, sizeof(username));
+  memset(&hostname, 0, sizeof(hostname));
+
+  /* Parse client specifier. */
+  while (*client) {
+    struct irc_in_addr tmpaddr;
+    long tmp;
+
+    /* Try to parse as listener port number first. */
+    tmp = strtol(client, &sep, 10);
+    if (tmp && (*sep == '\0' || *sep == ',')) {
+      listener = tmp;
+      client = sep + (*sep != '\0');
+      continue;
+    }
+
+    /* Maybe username@ before an IP address or hostname? */
+    tmp = strcspn(client, ",@");
+    if (client[tmp] == '@') {
+      if (tmp > USERLEN)
+        tmp = USERLEN;
+      ircd_strncpy(username, client, tmp);
+      /* and fall through */
+      client += tmp + 1;
+    }
+
+    /* Looks like an IP address? */
+    tmp = ircd_aton(&tmpaddr, client);
+    if (tmp && (client[tmp] == '\0' || client[tmp] == ',')) {
+        memcpy(&address, &tmpaddr, sizeof(address));
+        client += tmp + (client[tmp] != '\0');
+        continue;
+    }
+
+    /* Else must be a hostname. */
+    tmp = strcspn(client, ",");
+    if (tmp > HOSTLEN)
+      tmp = HOSTLEN;
+    ircd_strncpy(hostname, client, tmp);
+    client += tmp + (client[tmp] != '\0');
+  }
+
+  /* Walk configuration to find matching Client block. */
+  for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
+    if (aconf->status != CONF_CLIENT)
+      continue;
+    if (aconf->address.port && aconf->address.port != listener) {
+      fprintf(stdout, "Listener port mismatch: %u != %u\n", 
aconf->address.port, listener);
+      continue;
+    }
+    if (aconf->username && match(aconf->username, username)) {
+      fprintf(stdout, "Username mismatch: %s != %s\n", aconf->username, 
username);
+      continue;
+    }
+    if (aconf->host && match(aconf->host, hostname)) {
+      fprintf(stdout, "Hostname mismatch: %s != %s\n", aconf->host, hostname);
+      continue;
+    }
+    if ((aconf->addrbits >= 0)
+        && !ipmask_check(&address, &aconf->address.addr, aconf->addrbits)) {
+      fprintf(stdout, "IP address mismatch: %s != %s\n", aconf->name, 
ircd_ntoa(&address));
+      continue;
+    }
+    fprintf(stdout, "Match! username=%s host=%s ip=%s class=%s maxlinks=%u 
password=%s\n",
+            (aconf->username ? aconf->username : "(null)"),
+            (aconf->host ? aconf->host : "(null)"),
+            (aconf->name ? aconf->name : "(null)"),
+            ConfClass(aconf), aconf->maximum,  aconf->passwd);
+    return aconf;
+  }
+
+  fprintf(stdout, "No matches found.\n");
+  return NULL;
+}
+
 /** Check whether a particular ConfItem is already attached to a
  * Client.
  * @param aconf ConfItem to search for
----------------------- End of diff -----------------------

Reply via email to