core: config-data: don't ignore [.intern.device/connection] sections

Now it is possible to have [.intern.device-*] sections in
NetworkManager-intern.conf. Take them into account when parsing the
configuration keyfiles.
This commit is contained in:
Íñigo Huguet 2026-02-12 12:49:12 +01:00
parent b9564f936d
commit 5b40d20e48

View file

@ -2058,12 +2058,15 @@ _match_section_infos_construct(GKeyFile *keyfile, gboolean is_device)
{ {
char **groups; char **groups;
gsize i, j, ngroups; gsize i, j, ngroups;
char *connection_tag = NULL; char *main_group = NULL;
MatchSectionInfo *match_section_infos = NULL; MatchSectionInfo *match_section_infos = NULL;
const char *prefix; const char *prefix, *prefix_intern;
prefix = prefix =
is_device ? NM_CONFIG_KEYFILE_GROUPPREFIX_DEVICE : NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION; is_device ? NM_CONFIG_KEYFILE_GROUPPREFIX_DEVICE : NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION;
prefix_intern =
is_device ? NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN NM_CONFIG_KEYFILE_GROUPPREFIX_DEVICE
: NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION;
/* get the list of existing [connection.\+]/[device.\+] sections. /* get the list of existing [connection.\+]/[device.\+] sections.
* *
@ -2074,27 +2077,30 @@ _match_section_infos_construct(GKeyFile *keyfile, gboolean is_device)
if (!groups) if (!groups)
return NULL; return NULL;
if (ngroups > 0) { for (i = 0, j = 0; i < ngroups; i++) {
gsize l = strlen(prefix); if (nm_streq0(groups[i], prefix)) {
main_group = groups[i];
for (i = 0, j = 0; i < ngroups; i++) { } else if (nm_streq0(groups[i], prefix_intern)) {
if (g_str_has_prefix(groups[i], prefix)) { /* [.intern.connection] and [.intern.device] should not exist */
if (groups[i][l] == '\0') nm_assert_not_reached();
connection_tag = groups[i]; continue;
else } else if (g_str_has_prefix(groups[i], prefix)) {
groups[j++] = groups[i]; groups[j++] = groups[i];
} else } else if (g_str_has_prefix(groups[i], prefix_intern)) {
g_free(groups[i]); /* [.intern.connection-whatever] and [.intern.device-whatever] can exist*/
groups[j++] = groups[i];
} else {
g_free(groups[i]);
} }
ngroups = j;
} }
ngroups = j;
if (ngroups == 0 && !connection_tag) { if (ngroups == 0 && !main_group) {
g_free(groups); g_free(groups);
return NULL; return NULL;
} }
match_section_infos = g_new0(MatchSectionInfo, ngroups + 1 + (connection_tag ? 1 : 0)); match_section_infos = g_new0(MatchSectionInfo, ngroups + 1 + (main_group ? 1 : 0));
match_section_infos->is_device = is_device; match_section_infos->is_device = is_device;
for (i = 0; i < ngroups; i++) { for (i = 0; i < ngroups; i++) {
/* pass ownership of @group on... */ /* pass ownership of @group on... */
@ -2103,9 +2109,9 @@ _match_section_infos_construct(GKeyFile *keyfile, gboolean is_device)
groups[ngroups - i - 1], groups[ngroups - i - 1],
is_device); is_device);
} }
if (connection_tag) { if (main_group) {
/* pass ownership of @connection_tag on... */ /* pass ownership of @main_group on... */
_match_section_info_init(&match_section_infos[i], keyfile, connection_tag, is_device); _match_section_info_init(&match_section_infos[i], keyfile, main_group, is_device);
} }
g_free(groups); g_free(groups);