• Bug#1069897: Netcfg to get search domain (2/2)

    From =?UTF-8?B?RnLDqWTDqXJpYyBHdXlvdA==?@1:229/2 to All on Thu Jul 3 14:20:01 2025
    [continued from previous message]

    <div dir="ltr"><div><div>Right so I was wrong, netcfg reads the domain from here: /tmp/domain_name which is filled by udhcpc default.script<br></div>The patch above won&#39;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)<br><br></div>Here is an updated version of the hack:<br>d-i preseed/early_command string \<br>        sed -i &#39;s|printf &quot;\$domain&quot; &gt; /tmp/domain_name|
    printf &quot;$search&quot; &gt; /tmp/domain_name|&#39; /etc/udhcpc/default.script; \<br>        mv /sbin/udhcpc /sbin/udhcpc.real; \<br>        echo &#39;#!/bin/sh&#39; &gt; /sbin/udhcpc; \<br>        echo &#39;exec /bin/busybox udhcpc -O
    search &quot;$@&quot;&#39; &gt;&gt; /sbin/udhcpc; \<br>        chmod +x /sbin/udhcpc</div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Thu, Jul 3, 2025 at 12:30 PM Frédéric Guyot &lt;<a href="mailto:
    [email protected]">[email protected]</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Here is an updated patch for this issue:
    <pre>--- dhcp.c<br>+++ dhcp.c<br>@@ -41,6 +41,7 @@<br>                                                   &quot;domain&quot;,<br>                                                   &quot;hostname&quot;,<
                                                       &quot;dns&quot;,<br>+                                                  &quot;search&quot;,<br>                                     
                 &quot;ntpsrv&quot;, /* extra */<br>                                                   NULL };<br> <br>@@ -510,7 +511,7 @@<br>              * nameservers now so we can do rDNS lookups later to
    possibly<br>              * find out the domain.<br>              */<br>-            netcfg_write_resolv(NULL, interface);<br>+            netcfg_write_resolv(NULL, NULL, interface);<br>             state = HOSTNAME;<br> 
               break;<br> <br>@@ -613,7 +614,7 @@<br>                 netcfg_write_common(&quot;&quot;, hostname, domain);<br>                 netcfg_write_loopback();<br>                 netcfg_write_interface(interface);<
    -                netcfg_write_resolv(domain, interface);<br>+                netcfg_write_resolv(domain, search, interface);<br> #if !defined(__FreeBSD_kernel__)<br>                 kill_dhcp_client();<br> #endif<br>
    --- static.c<br>+++ static.c<br>@@ -258,14 +258,16 @@<br>     return 1;<br> }<br> <br>-int netcfg_write_resolv (const char *domain, const struct netcfg_interface *interface)<br>+int netcfg_write_resolv (const char *domain , const char *search, const
    struct netcfg_interface *interface)<br> {<br>     FILE* fp = NULL;<br> <br>     if ((fp = file_open(RESOLV_FILE, &quot;w&quot;))) {<br>         unsigned int i = 0;<br>+        if (search &amp;&amp; !empty_str(search))<br>+          
     fprintf(fp, &quot;search %s\n&quot;, search);<br>         if (domain &amp;&amp; !empty_str(domain))<br>-            fprintf(fp, &quot;search %s\n&quot;, domain);<br>+            fprintf(fp, &quot;domain %s\n&quot;, domain);<br> <br> 
           for (i = 0; i &lt; NETCFG_NAMESERVERS_MAX; i++)<br>             if (!empty_str(interface-&gt;nameservers[i]))<br></pre><pre>This should do the trick.<br><br></pre><pre>If someone comes across this issue and this patch hasn&#39;t been