• Bug#1069897: Netcfg to get search domain

    From =?UTF-8?B?RnLDqWTDqXJpYyBHdXlvdA==?@1:229/2 to All on Thu Jul 3 12:40:01 2025
    XPost: linux.debian.maint.boot
    From: [email protected]

    Here is an updated patch for this issue:

    --- dhcp.c
    +++ dhcp.c
    @@ -41,6 +41,7 @@
    "domain",
    "hostname",
    "dns",
    + "search",
    "ntpsrv", /* extra */
    NULL };

    @@ -510,7 +511,7 @@
    * nameservers now so we can do rDNS lookups later to possibly
    * find out the domain.
    */
    - netcfg_write_resolv(NULL, interface);
    + netcfg_write_resolv(NULL, NULL, interface);
    state = HOSTNAME;
    break;

    @@ -613,7 +614,7 @@
    netcfg_write_common("", hostname, domain);
    netcfg_write_loopback();
    netcfg_write_interface(interface);
    - netcfg_write_resolv(domain, interface);
    + netcfg_write_resolv(domain
  • From =?UTF-8?B?RnLDqWTDqXJpYyBHdXlvdA==?@1:229/2 to All on Thu Jul 3 14:20:01 2025
    XPost: linux.debian.maint.boot
    From: [email protected]

    Right so I was wrong, netcfg reads the domain from here: /tmp/domain_name
    which is filled by udhcpc default.script
    The patch above won't work alone as we would need udhcpc to write the
    search domain to a file and make a read function in netcfg to get the info
    (or something along those lines)

    Here is an updated version of the hack:
    d-i preseed/early_command string \
    sed -i 's|printf "\$domain" > /tmp/domain_name|printf "$search" > /tmp/domain_name|' /etc/udhcpc/default.script; \
    mv /sbin/udhcpc /sbin/udhcpc.real; \
    echo '#!/bin/sh' > /sbin/udhcpc; \
    echo 'exec /bin/busybox udhcpc -O search "$@"' >> /sbin/udhcpc; \
    chmod +x /sbin/udhcpc

    On Thu, Jul 3, 2025 at 12:30 PM Frédéric Guyot <[email protected]> wrote:

    Here is an updated patch for this issue:

    --- dhcp.c
    +++ dhcp.c
    @@ -41,6 +41,7 @@
    "domain",
    "hostname",
    "dns",
    + "search",
    "ntpsrv", /* extra */
    NULL };

    @@ -510,7 +511,7 @@
    * nameservers now so we can do rDNS lookups later to possibly
    * find out the domain.
    */
    - netcfg_write_resolv(NULL, interface);
    + netcfg_write_resolv(NULL, NULL, interface);
    state = HOSTNAME;
    break;

    @@ -613,7 +614,7 @@
    netcfg_write_common("", hostname, domain);
    netcfg_write_loopback();
    netcfg_write_interface(interface);
    - netcfg_write_resolv(domain, interface);
    + netcfg_write_resolv(domain, search, interface);
    #if !defined(__FreeBSD_kernel__)
    kill_dhcp_client();
    #endif

    --- static.c
    +++ static.c
    @@ -258,14 +258,16 @@
    return 1;
    }

    -int netcfg_write_resolv (const char *domain, const struct netcfg_interface *interface)
    +int netcfg_write_resolv (const char *domain , const char *search, const struct netcfg_interface *interface)
    {
    FILE* fp = NULL;

    if ((fp = file_open(RESOLV_FILE, "w"))) {
    unsigned int i = 0;
    + if (search && !empty_str(search))
    + fprintf(fp, "search %s\n", search);
    if (domain && !empty_str(domain))
    - fprintf(fp, "search %s\n", domain);
    + fprintf(fp, "domain %s\n", domain);

    for (i = 0; i < NETCFG_NAMESERVERS_MAX; i++)
    if (!empty_str(interface->nameservers[i]))

    This should do the trick.

    If someone comes across this issue and this patch hasn't been merged we found an ugly workaround using a preseed file:

    d-i preseed/early_command string \
    sed -i '/^case /i domain="$search"' /etc/udhcpc/default.script; \
    mv /sbin/udhcpc /sbin/udhcpc.real; \
    echo '#!/bin/sh' > /sbin/udhcpc; \
    echo 'exec /bin/busybox udhcpc -O search "$@"' >> /sbin/udhcpc; \
    chmod +x /sbin/udhcpc

    It will make a wrapper for udhcpc that will force netcfg to query search domains, patch the default.script callback script from udhcpc to make domain="$seach".

    regards





    [continued in next message]

    --- SoupGate-Win32 v1.05
    * Origin: you cannot sedate... all the things you hate (1:229/2)