]> git.ipfire.org Git - thirdparty/dhcp.git/blobdiff - common/print.c
MASSIVE merge from V3-RELEASE-BRANCH into HEAD. HEAD and V3-RELEASE are
[thirdparty/dhcp.git] / common / print.c
index ef90adedb5a584728b64e588753048c25176ae3c..f46d8c559ff227b3b8534a7c80f622b751de1a54 100644 (file)
@@ -3,39 +3,30 @@
    Turn data structures into printable text. */
 
 /*
- * Copyright (c) 1995-2001 Internet Software Consortium.
- * All rights reserved.
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 1995-2003 by Internet Software Consortium
  *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
  *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of The Internet Software Consortium nor the names
- *    of its contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  *
- * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
- * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED.  IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+ *   Internet Systems Consortium, Inc.
+ *   950 Charter Street
+ *   Redwood City, CA 94063
+ *   <info@isc.org>
+ *   http://www.isc.org/
  *
- * This software has been written for the Internet Software Consortium
+ * This software has been written for Internet Systems Consortium
  * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
- * To learn more about the Internet Software Consortium, see
+ * To learn more about Internet Systems Consortium, see
  * ``http://www.isc.org/''.  To learn more about Vixie Enterprises,
  * see ``http://www.vix.com''.   To learn more about Nominum, Inc., see
  * ``http://www.nominum.com''.
@@ -43,7 +34,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: print.c,v 1.56 2002/04/30 06:18:39 murray Exp $ Copyright (c) 1995-2001 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: print.c,v 1.57 2005/03/17 20:14:59 dhankins Exp $ Copyright (c) 2004 Internet Systems Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -223,7 +214,7 @@ void print_lease (lease)
               lease -> host ? lease -> host -> name : "<none>");
 }      
 
-#if defined (DEBUG)
+#if defined (DEBUG_PACKET)
 void dump_packet_option (struct option_cache *oc,
                         struct packet *packet,
                         struct lease *lease,
@@ -304,19 +295,46 @@ void dump_raw (buf, len)
        char lbuf [80];
        int lbix = 0;
 
-       lbuf [0] = 0;
+/*
+          1         2         3         4         5         6         7
+01234567890123456789012345678901234567890123456789012345678901234567890123
+280: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   .................  
+*/
+
+       memset(lbuf, ' ', 79);
+       lbuf [79] = 0;
 
        for (i = 0; i < len; i++) {
                if ((i & 15) == 0) {
-                       if (lbix)
-                               log_info (lbuf);
-                       sprintf (lbuf, "%03x:", i);
-                       lbix = 4;
+                 if (lbix) {
+                       lbuf[53]=' ';
+                       lbuf[54]=' ';
+                       lbuf[55]=' ';
+                       lbuf[73]='\0';
+                       log_info (lbuf);
+                 }
+                 memset(lbuf, ' ', 79);
+                 lbuf [79] = 0;
+                 sprintf (lbuf, "%03x:", i);
+                 lbix = 4;
                } else if ((i & 7) == 0)
                        lbuf [lbix++] = ' ';
+
+               if(isprint(buf[i])) {
+                 lbuf[56+(i%16)]=buf[i];
+               } else {
+                 lbuf[56+(i%16)]='.';
+               }
+
                sprintf (&lbuf [lbix], " %02x", buf [i]);
                lbix += 3;
+               lbuf[lbix]=' ';
+
        }
+       lbuf[53]=' ';
+       lbuf[54]=' ';
+       lbuf[55]=' ';
+       lbuf[73]='\0';
        log_info (lbuf);
 }
 
@@ -337,7 +355,7 @@ void hash_dump (table)
                        if (bp -> len)
                                dump_raw (bp -> name, bp -> len);
                        else
-                               log_info ((const char *)bp -> name);
+                               log_info ("%s", (const char *)bp -> name);
                }
        }
 }
@@ -396,8 +414,13 @@ char *print_dotted_quads (len, data)
        
        i = 0;
 
+       /* %Audit% Loop bounds checks to 21 bytes. %2004.06.17,Safe%
+        * The sprintf can't exceed 18 bytes, and since the loop enforces
+        * 21 bytes of space per iteration at no time can we exit the
+        * loop without at least 3 bytes spare.
+        */
        do {
-               sprintf (s, "%d.%d.%d.%d, ",
+               sprintf (s, "%u.%u.%u.%u, ",
                         data [i], data [i + 1], data [i + 2], data [i + 3]);
                s += strlen (s);
                i += 4;
@@ -1248,6 +1271,9 @@ void print_dns_status (int status, ns_updque *uq)
                      case T_TXT:
                        en = "TXT";
                        break;
+                     case T_KEY:
+                       en = "KEY";
+                       break;
                      case T_CNAME:
                        en = "CNAME";
                        break;
@@ -1268,13 +1294,19 @@ void print_dns_status (int status, ns_updque *uq)
                                if (s + 1 < end)
                                        *s++ = '"';
                        }
-                       if (s + u -> r_size < end) {
-                               memcpy (s, u -> r_data, u -> r_size);
-                               s += u -> r_size;
-                               if (u -> r_type == T_TXT) {
-                                       if (s + 1 < end)
-                                               *s++ = '"';
-                               }
+                       if(u->r_type == T_KEY) {
+                         strcat(s, "<keydata>");
+                         s+=strlen("<keydata>");
+                       }
+                       else {  
+                         if (s + u -> r_size < end) {
+                           memcpy (s, u -> r_data, u -> r_size);
+                           s += u -> r_size;
+                           if (u -> r_type == T_TXT) {
+                             if (s + 1 < end)
+                               *s++ = '"';
+                           }
+                         }
                        }
                }
                if (position) {