Named uci sections may be overwritten by misstake in luci

All named uci sections of a given config file share the same name space, as noted in Cannot create multiple named sections with same name , but with different section types

It means that if the user is allowed to add named sections of one type (via luci or ubus in general), then there shouldn't be named sections in the config file of any other type. Otherwise the user might overwrite other named sections by mistake.

One example is the dnsmasq type that shares the name space (/etc/config/dhcp) with the dhcp type.

Another example is strongswan ipsec where the remote configuration (remote), tunnel configuration (tunnel) and encryption proposal (crypto_proposal) share the same name space (/etc/config/ipsec).

Maybe the ubus call uci add (which is used by luci) shouldn't succeed if the named section already exists. (Or at least it shouldn't succeed if contains another section type than the existing section.)

In case you are interested. This is a patch which aborts uci add if the named section already exists:

diff -uN rpcd-2024.02.22~8ef4c258/uci.c.orig rpcd-2024.02.22~8ef4c258/uci.c
--- rpcd-2024.02.22~8ef4c258/uci.c.orig 2024-06-05 15:18:16.439098788 +0200
+++ rpcd-2024.02.22~8ef4c258/uci.c      2024-06-05 15:23:57.128080697 +0200
@@ -717,8 +717,18 @@
                ptr.value   = blobmsg_data(tb[RPC_A_TYPE]);
                ptr.option  = NULL;
-               if (rpc_uci_lookup(&ptr) || uci_set(cursor, &ptr))
+               if (rpc_uci_lookup(&ptr))
                        goto out;
+               if (ptr.s)
+               {
+                       err = UBUS_STATUS_NOT_SUPPORTED;
+                       goto out;
+               }
+               else if (uci_set(cursor, &ptr))
+               {
+                       goto out;
+               }
        /* add anon section */

How do you uci in uci-defaults after this change? It is intended to exactly change section types and rename them.

The change I posted modifies rpc_uci_add in rpcd which is the method that's called when running for example ubus call uci add, it shouldn't effect the uci command. Is that ubus method usually called when you want to change the type of a named section? Do you have an example?

So it should not be implemented to not affect migration scripts.

grep uci.add /rom/etc/uci-defaults/*

Is rpcd even running when the uci-defaults scripts are executed?