]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
Notice if client is NUL-terminating strings, and if it is, NUL-terminate them back.
authorTed Lemon <source@isc.org>
Wed, 11 Sep 1996 05:52:18 +0000 (05:52 +0000)
committerTed Lemon <source@isc.org>
Wed, 11 Sep 1996 05:52:18 +0000 (05:52 +0000)
common/options.c
dhcp.c
options.c
server/dhcp.c

index a9bf837452852aadacac08ef53471150f9807ffe..53dd0224b18da308dc7a82e6d98a5ac52d6e527e 100644 (file)
@@ -42,7 +42,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: options.c,v 1.18 1996/09/05 23:57:33 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: options.c,v 1.19 1996/09/11 05:52:18 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #define DHCP_OPTION_DATA
@@ -155,11 +155,12 @@ void parse_option_buffer (packet, buffer, length)
    three seperate buffers if needed.  This allows us to cons up a set
    of vendor options using the same routine. */
 
-void cons_options (inpacket, outpacket, options, overload)
+void cons_options (inpacket, outpacket, options, overload, terminate)
        struct packet *inpacket;
        struct packet *outpacket;
        struct tree_cache **options;
        int overload;   /* Overload flags that may be set. */
+       int terminate;
 {
        unsigned char priority_list [300];
        int priority_len;
@@ -220,7 +221,8 @@ void cons_options (inpacket, outpacket, options, overload)
                                     options, priority_list, priority_len,
                                     main_buffer_size,
                                     (main_buffer_size +
-                                     ((overload & 1) ? DHCP_FILE_LEN : 0)));
+                                     ((overload & 1) ? DHCP_FILE_LEN : 0)),
+                                    terminate);
 
        /* Put the cookie up front... */
        memcpy (outpacket -> raw -> options, DHCP_OPTIONS_COOKIE, 4);
@@ -287,18 +289,20 @@ void cons_options (inpacket, outpacket, options, overload)
 /* Store all the requested options into the requested buffer. */
 
 int store_options (buffer, buflen, options, priority_list, priority_len,
-                  first_cutoff, second_cutoff)
+                  first_cutoff, second_cutoff, terminate)
        unsigned char *buffer;
        int buflen;
        struct tree_cache **options;
        unsigned char *priority_list;
        int priority_len;
        int first_cutoff, second_cutoff;
+       int terminate;
 {
        int bufix = 0;
        int option_stored [256];
        int i;
        int ix;
+       int tto;
 
        /* Zero out the stored-lengths array. */
        memset (option_stored, 0, sizeof option_stored);
@@ -333,6 +337,14 @@ int store_options (buffer, buflen, options, priority_list, priority_len,
                /* We should now have a constant length for the option. */
                length = options [code] -> len;
 
+               /* Do we add a NUL? */
+               if (terminate && dhcp_options [code].format [0] == 't') {
+                       length++;
+                       tto = 1;
+               } else {
+                       tto = 0;
+               }
+
                /* Try to store the option. */
 
                /* If the option's length is more than 255, we must store it
@@ -366,8 +378,15 @@ int store_options (buffer, buflen, options, priority_list, priority_len,
                        /* Everything looks good - copy it in! */
                        buffer [bufix] = code;
                        buffer [bufix + 1] = incr;
-                       memcpy (buffer + bufix + 2,
-                               options [code] -> value + ix, incr);
+                       if (tto && incr == length) {
+                               memcpy (buffer + bufix + 2,
+                                       options [code] -> value + ix,
+                                       incr - 1);
+                               buffer [bufix + 2 + incr - 1] = 0;
+                       } else {
+                               memcpy (buffer + bufix + 2,
+                                       options [code] -> value + ix, incr);
+                       }
                        length -= incr;
                        ix += incr;
                        bufix += 2 + incr;
diff --git a/dhcp.c b/dhcp.c
index d71d0a0af1d8faf819fbbabf693e82253f1834c9..fc5e2e1aed5e65231bf617cd7e9e5db5c62ee11d 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -42,7 +42,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: dhcp.c,v 1.33 1996/09/05 23:52:10 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: dhcp.c,v 1.34 1996/09/11 05:52:18 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -362,7 +362,7 @@ void nak_lease (packet, cip)
                (unsigned char *)0;
 
        /* Set up the option buffer... */
-       cons_options (packet, &outgoing, options, 0);
+       cons_options (packet, &outgoing, options, 0, 0);
 
 /*     memset (&raw.ciaddr, 0, sizeof raw.ciaddr);*/
        memcpy (&raw.siaddr, server_identifier.iabuf, 4);
@@ -807,7 +807,14 @@ void ack_lease (packet, lease, offer, when)
                netmask_tree.tree = (struct tree *)0;
        }
 
-       cons_options (packet, &outgoing, options, bufs);
+       /* See if this is a Microsoft client that NUL-terminates its
+          strings and expects us to do likewise... */
+       if (packet -> options [DHO_HOST_NAME].data &&
+           packet -> options [DHO_HOST_NAME].data
+           [packet -> options [DHO_HOST_NAME].len - 1] == '\0')
+               cons_options (packet, &outgoing, options, bufs, 1);
+       else
+               cons_options (packet, &outgoing, options, bufs, 0);
        if (!offer && outgoing.packet_length < BOOTP_MIN_LEN)
                outgoing.packet_length = BOOTP_MIN_LEN;
 
index a9bf837452852aadacac08ef53471150f9807ffe..53dd0224b18da308dc7a82e6d98a5ac52d6e527e 100644 (file)
--- a/options.c
+++ b/options.c
@@ -42,7 +42,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: options.c,v 1.18 1996/09/05 23:57:33 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: options.c,v 1.19 1996/09/11 05:52:18 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #define DHCP_OPTION_DATA
@@ -155,11 +155,12 @@ void parse_option_buffer (packet, buffer, length)
    three seperate buffers if needed.  This allows us to cons up a set
    of vendor options using the same routine. */
 
-void cons_options (inpacket, outpacket, options, overload)
+void cons_options (inpacket, outpacket, options, overload, terminate)
        struct packet *inpacket;
        struct packet *outpacket;
        struct tree_cache **options;
        int overload;   /* Overload flags that may be set. */
+       int terminate;
 {
        unsigned char priority_list [300];
        int priority_len;
@@ -220,7 +221,8 @@ void cons_options (inpacket, outpacket, options, overload)
                                     options, priority_list, priority_len,
                                     main_buffer_size,
                                     (main_buffer_size +
-                                     ((overload & 1) ? DHCP_FILE_LEN : 0)));
+                                     ((overload & 1) ? DHCP_FILE_LEN : 0)),
+                                    terminate);
 
        /* Put the cookie up front... */
        memcpy (outpacket -> raw -> options, DHCP_OPTIONS_COOKIE, 4);
@@ -287,18 +289,20 @@ void cons_options (inpacket, outpacket, options, overload)
 /* Store all the requested options into the requested buffer. */
 
 int store_options (buffer, buflen, options, priority_list, priority_len,
-                  first_cutoff, second_cutoff)
+                  first_cutoff, second_cutoff, terminate)
        unsigned char *buffer;
        int buflen;
        struct tree_cache **options;
        unsigned char *priority_list;
        int priority_len;
        int first_cutoff, second_cutoff;
+       int terminate;
 {
        int bufix = 0;
        int option_stored [256];
        int i;
        int ix;
+       int tto;
 
        /* Zero out the stored-lengths array. */
        memset (option_stored, 0, sizeof option_stored);
@@ -333,6 +337,14 @@ int store_options (buffer, buflen, options, priority_list, priority_len,
                /* We should now have a constant length for the option. */
                length = options [code] -> len;
 
+               /* Do we add a NUL? */
+               if (terminate && dhcp_options [code].format [0] == 't') {
+                       length++;
+                       tto = 1;
+               } else {
+                       tto = 0;
+               }
+
                /* Try to store the option. */
 
                /* If the option's length is more than 255, we must store it
@@ -366,8 +378,15 @@ int store_options (buffer, buflen, options, priority_list, priority_len,
                        /* Everything looks good - copy it in! */
                        buffer [bufix] = code;
                        buffer [bufix + 1] = incr;
-                       memcpy (buffer + bufix + 2,
-                               options [code] -> value + ix, incr);
+                       if (tto && incr == length) {
+                               memcpy (buffer + bufix + 2,
+                                       options [code] -> value + ix,
+                                       incr - 1);
+                               buffer [bufix + 2 + incr - 1] = 0;
+                       } else {
+                               memcpy (buffer + bufix + 2,
+                                       options [code] -> value + ix, incr);
+                       }
                        length -= incr;
                        ix += incr;
                        bufix += 2 + incr;
index d71d0a0af1d8faf819fbbabf693e82253f1834c9..fc5e2e1aed5e65231bf617cd7e9e5db5c62ee11d 100644 (file)
@@ -42,7 +42,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: dhcp.c,v 1.33 1996/09/05 23:52:10 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: dhcp.c,v 1.34 1996/09/11 05:52:18 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -362,7 +362,7 @@ void nak_lease (packet, cip)
                (unsigned char *)0;
 
        /* Set up the option buffer... */
-       cons_options (packet, &outgoing, options, 0);
+       cons_options (packet, &outgoing, options, 0, 0);
 
 /*     memset (&raw.ciaddr, 0, sizeof raw.ciaddr);*/
        memcpy (&raw.siaddr, server_identifier.iabuf, 4);
@@ -807,7 +807,14 @@ void ack_lease (packet, lease, offer, when)
                netmask_tree.tree = (struct tree *)0;
        }
 
-       cons_options (packet, &outgoing, options, bufs);
+       /* See if this is a Microsoft client that NUL-terminates its
+          strings and expects us to do likewise... */
+       if (packet -> options [DHO_HOST_NAME].data &&
+           packet -> options [DHO_HOST_NAME].data
+           [packet -> options [DHO_HOST_NAME].len - 1] == '\0')
+               cons_options (packet, &outgoing, options, bufs, 1);
+       else
+               cons_options (packet, &outgoing, options, bufs, 0);
        if (!offer && outgoing.packet_length < BOOTP_MIN_LEN)
                outgoing.packet_length = BOOTP_MIN_LEN;