(Log entry for previous version is bogus.) Minor changes to host
[become] / src / class.c
index d2f5e4b..faae653 100644 (file)
@@ -1,13 +1,13 @@
 /* -*-c-*-
  *
- * $Id: class.c,v 1.1 1997/07/21 13:47:52 mdw Exp $
+ * $Id: class.c,v 1.4 1997/08/07 09:56:37 mdw Exp $
  *
  * Handling classes of things nicely
  *
  * (c) 1997 EBI
  */
 
-/*----- Licencing notice --------------------------------------------------*
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of `become'
  *
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with `become'; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * along with `become'; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
 /*----- Revision history --------------------------------------------------*
  *
  * $Log: class.c,v $
- * Revision 1.1  1997/07/21 13:47:52  mdw
+ * Revision 1.4  1997/08/07 09:56:37  mdw
+ * (Log entry for previous version is bogus.)  Minor changes to host
+ * checking code.
+ *
+ * Revision 1.2  1997/08/04 10:24:21  mdw
+ * Sources placed under CVS control.
+ *
+ * Revision 1.1  1997/07/21  13:47:52  mdw
  * Initial revision
  *
  */
@@ -55,6 +62,7 @@
 
 /* --- Local headers --- */
 
+#include "become.h"
 #include "class.h"
 #include "set.h"
 #include "sym.h"
@@ -166,10 +174,16 @@ int class_userMatch(classdef *c, int u)
 {
   if (~c->type & clType_user)
     return (0);
-  else if (c == class_all)
+  else if (c == class_all) {
+    T( trace(TRACE_CHECK, "check: user %i matched by all", u); )
     return (1);
-  else
-    return (sym_find(c->t, (char *)&u, sizeof(u), 0, 0) != 0);
+  } else {
+    sym_base *s = sym_find(c->t, (char *)&u, sizeof(u), 0, 0);
+    T( trace(TRACE_CHECK,
+            s ? "check: user %i matched" : "check: user %i not matched",
+            u); )
+    return (s != 0);
+  }
 }
 
 /* --- @class_commandMatch@ --- *
@@ -192,13 +206,18 @@ int class_commandMatch(classdef *c, const char *p)
 
   if (~c->type & clType_command)
     return (0);
-  else if (c == class_all)
+  else if (c == class_all) {
+    T( trace(TRACE_CHECK, "check: command `%s' matched by all", p); )
     return (1);
-  else {
+  else {
     for (sym_createIter(&i, c->t); (s = sym_next(&i)) != 0; ) {
-      if (class__wildMatch(s->name, p))
+      if (class__wildMatch(s->name, p)) {
+       T( trace(TRACE_CHECK, "check: command `%s' matched by `%s'",
+                p, s->name); )
        return (1);
+      }
     }
+    T( trace(TRACE_CHECK, "check: command `%s' not matched", p); )
     return (0);
   }
 }
@@ -224,16 +243,21 @@ int class_hostMatch(classdef *c, struct in_addr addr)
 
   if (~c->type & clType_host)
     return (0);
-  else if (c == class_all)
+  else if (c == class_all) {
+    T( trace(TRACE_CHECK, "check: host %s matched by all",
+            inet_ntoa(addr)); )
     return (1);
-  else {
+  else {
 
     /* --- Get the dotted-quad and other names for the address --- */
 
-    if ((a = inet_ntoa(addr)) == 0)
+    if ((a = inet_ntoa(addr)) == 0) {
+      T( trace(TRACE_CHECK, "check: couldn't translate address (erk!)"); )
       return (0);
+    }
+
     if ((he = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET)) == 0)
-      return (0);
+      T( trace(TRACE_CHECK, "check: couldn't resolve hostname for %s", a); )
 
     /* --- Now search the list for a match --- *
      *
@@ -244,21 +268,36 @@ int class_hostMatch(classdef *c, struct in_addr addr)
 
       /* --- Check the dotted-quad name first --- */
 
-      if (class__wildMatch(s->name, a))
+      if (class__wildMatch(s->name, a)) {
+       T( trace(TRACE_CHECK, "check: host address `%s' matched by `%s'",
+                a, s->name); )
        return (1);
+      }
 
-      /* --- Now try the host's main name --- */
-
-      if (class__wildMatch(s->name, he->h_name))
-       return (1);
+      if (he) {
 
-      /* --- Now go through all the names --- */
+       /* --- Now try the host's main name --- */
 
-      for (p = he->h_aliases; *p; p++) {
-       if (class__wildMatch(s->name, *p))
+       if (class__wildMatch(s->name, he->h_name)) {
+         T( trace(TRACE_CHECK, "check: host name `%s' matched by `%s'",
+                  he->h_name, s->name); )
          return (1);
+       }
+
+       /* --- Now go through all the names --- */
+
+       for (p = he->h_aliases; *p; p++) {
+         if (class__wildMatch(s->name, *p)) {
+           T( trace(TRACE_CHECK, "check: host alias `%s' matched by `%s'",
+                    *p, s->name); )
+           return (1);
+         }
+       }
       }
     }
+
+    T( trace(TRACE_CHECK, "check: couldn't match hostname `%s'",
+            he->h_name); )
     return (0);
   }
 }
@@ -266,60 +305,34 @@ int class_hostMatch(classdef *c, struct in_addr addr)
 /* --- @class_dump@ --- *
  *
  * Arguments:  @classdef *c@ = pointer to a class block
- *             @FILE *fp@ = pointer to a stream object
  *
  * Returns:    ---
  *
  * Use:                Dumps the contents of a class to a stream.
  */
 
-void class_dump(classdef *c, FILE *fp)
+void class_dump(classdef *c)
 {
   sym_iter i;
   sym_base *s;
 
-  /* --- Write a little header block --- */
-
-  {
-    const char *typetbl[] = {
-      "bad class",
-      "user",
-      "command",
-      "user/command",
-      "host",
-      "host/user",
-      "host/command",
-      "all",
-    };
-
-    fprintf(fp,
-           "*** Type: %s\n"
-           "*** Refs: %u\n"
-           "*** \n"
-           "*** Items:\n",
-           c->type < clType__limit ? typetbl[c->type] : "bad class",
-           c->ref);
-  }
-
   /* --- Dump the table --- */
 
   if (c->type != clType_all) {
     for (sym_createIter(&i, c->t); (s = sym_next(&i)) != 0; ) {
       switch (c->type) {
        case clType_user:
-         fprintf(fp, "***   %i\n", *(int *)s->name);
+         trace(TRACE_RULE, "    %i", *(int *)s->name);
          break;
        case clType_command:
        case clType_host:
-         fputs("***   ", fp);
-         fwrite(s->name, s->len, 1, fp);
-         putc('\n', fp);
+         trace(TRACE_RULE, "    `%s'", s->name);
          break;
       }
     }
   }
-
-  putc('\n', fp);
+  else
+    trace(TRACE_RULE, "    ALL");
 }
 
 /*----- That's all, folks -------------------------------------------------*/