# --- T2-COPYRIGHT-BEGIN --- # t2/package/*/dnsmasq/no-file-override.patch # Copyright (C) 2020 - 2026 The T2 SDE Project # SPDX-License-Identifier: GPL-2.0 or patched project license # --- T2-COPYRIGHT-END --- --- dnsmasq-2.85/src/rfc2131.c.orig 2021-04-07 22:39:39.000000000 +0200 +++ dnsmasq-2.85/src/rfc2131.c 2021-08-30 17:49:48.447435549 +0200 @@ -57,7 +57,8 @@ unsigned int lease_time, unsigned short fuzz, const char *pxevendor, - int leasequery); + int leasequery, + const char *filename); static void match_vendor_opts(unsigned char *opt, struct dhcp_opt *dopt); @@ -100,6 +101,8 @@ struct dhcp_opt *o; unsigned char pxe_uuid[17]; unsigned char *oui = NULL, *serial = NULL; + char filename[sizeof(((struct dhcp_packet*)0)->file)]; filename[sizeof(filename) - 1] = 0; + #ifdef HAVE_SCRIPT unsigned char *class = NULL; #endif @@ -559,6 +562,9 @@ /* Match incoming filename field as a netid. */ if (mess->file[0]) { + strncpy(filename, (char*)mess->file, sizeof(filename)); filename[sizeof(filename) - 1] = 0; + fprintf(stderr, "filename: %s\n", filename); + memcpy(daemon->dhcp_buff2, mess->file, sizeof(mess->file)); daemon->dhcp_buff2[sizeof(mess->file) + 1] = 0; /* ensure zero term. */ id.net = (char *)daemon->dhcp_buff2; @@ -692,7 +693,7 @@ clear_packet(mess, end); do_options(context, mess, end, NULL, hostname, get_domain(mess->yiaddr), - netid, subnet_addr, 0, 0, -1, NULL, vendor_class_len, now, 0xffffffff, 0, NULL, 0); + netid, subnet_addr, 0, 0, -1, NULL, vendor_class_len, now, 0xffffffff, 0, NULL, 0, filename); } } @@ -898,6 +904,7 @@ else snprintf((char *)mess->file, sizeof(mess->file), "%s.%d", service->basename, layer); + if (filename[0]) snprintf((char *)mess->file, sizeof(mess->file), "%s", filename); option_put(mess, end, OPTION_MESSAGE_TYPE, 1, DHCPACK); option_put(mess, end, OPTION_SERVER_IDENTIFIER, INADDRSZ, htonl(context->local.s_addr)); @@ -976,6 +983,7 @@ if (boot->file) safe_strncpy((char *)mess->file, boot->file, sizeof(mess->file)); + if (filename[0]) safe_strncpy((char *)mess->file, filename, sizeof(mess->file)); } option_put(mess, end, OPTION_MESSAGE_TYPE, 1, @@ -1231,7 +1232,7 @@ subnet_addr.s_addr = 0; do_options(context, mess, end, req_options, lease->hostname, get_domain(lease->addr), netid, subnet_addr, - 0, 0, -1, NULL, vendor_class_len, now, 0xffffffff, 0, NULL, 1); + 0, 0, -1, NULL, vendor_class_len, now, 0xffffffff, 0, NULL, 1, filename); /* Does this have to be last for leasequery replies also? RFC 4388 is silent on the subject. */ if (lease->agent_id && in_list(req_options, OPTION_AGENT_ID) && @@ -1391,7 +1392,7 @@ option_put(mess, end, OPTION_LEASE_TIME, 4, time); /* T1 and T2 are required in DHCPOFFER by HP's wacky Jetdirect client. */ do_options(context, mess, end, req_options, offer_hostname, get_domain(mess->yiaddr), - netid, subnet_addr, fqdn_flags, borken_opt, pxearch, uuid, vendor_class_len, now, time, fuzz, pxevendor, 0); + netid, subnet_addr, fqdn_flags, borken_opt, pxearch, uuid, vendor_class_len, now, time, fuzz, pxevendor, 0, filename); return dhcp_packet_size(mess, agent_id, real_end); @@ -1752,7 +1753,7 @@ if (rapid_commit) option_put(mess, end, OPTION_RAPID_COMMIT, 0, 0); do_options(context, mess, end, req_options, hostname, get_domain(mess->yiaddr), - netid, subnet_addr, fqdn_flags, borken_opt, pxearch, uuid, vendor_class_len, now, time, fuzz, pxevendor, 0); + netid, subnet_addr, fqdn_flags, borken_opt, pxearch, uuid, vendor_class_len, now, time, fuzz, pxevendor, 0, filename); } return dhcp_packet_size(mess, agent_id, real_end); @@ -1819,7 +1820,7 @@ } do_options(context, mess, end, req_options, hostname, get_domain(mess->ciaddr), - netid, subnet_addr, fqdn_flags, borken_opt, pxearch, uuid, vendor_class_len, now, 0xffffffff, 0, pxevendor, 0); + netid, subnet_addr, fqdn_flags, borken_opt, pxearch, uuid, vendor_class_len, now, 0xffffffff, 0, pxevendor, 0, filename); *is_inform = 1; /* handle reply differently */ return dhcp_packet_size(mess, agent_id, real_end); @@ -2625,7 +2626,8 @@ unsigned int lease_time, unsigned short fuzz, const char *pxevendor, - int leasequery) + int leasequery, + const char *filename) { struct dhcp_opt *opt, *config_opts = daemon->dhcp_opts; struct dhcp_boot *boot; @@ -2697,9 +2699,9 @@ if (!option_bool(OPT_NO_OVERRIDE) && req_options && in_list(req_options, OPTION_FILENAME)) - option_put_string(mess, end, OPTION_FILENAME, boot->file, 1); + option_put_string(mess, end, OPTION_FILENAME, filename[0] ? filename : boot->file, 1); else - safe_strncpy((char *)mess->file, boot->file, sizeof(mess->file)); + safe_strncpy((char *)mess->file, filename[0] ? filename : boot->file, sizeof(mess->file)); } if (boot->next_server.s_addr)