From d964decbbd925b1cc8fa2eafe03678253db33ac8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 2 Jan 2020 07:37:59 +0100 Subject: [PATCH] libnm/keyfile: build keyfile code as separate GPL licensed internal library Keyfile support was initially added under GPL-2.0+ license as part of core. It was moved to "libnm-core" in commit 59eb5312a5d6 ('keyfile: merge branch 'th/libnm-keyfile-bgo744699''). "libnm-core" is statically linked with by core and "libnm". In the former case under terms of GPL-2.0+ (good) and in the latter case under terms of LGPL-2.1+ (bad). In fact, to this day, "libnm" doesn't actually use the code. The linker will probably remove all the GPL-2.0+ symbols when compiled with gc-sections or LTO. Still, linking them together in the first place makes "libnm" only available under GPL code (despite the code not actually being used). Instead, move the GPL code to a separate static library "shared/nm-keyfile/libnm-keyfile.la" and only link it to the part that actually uses the code (and which is GPL licensed too). This fixes the license violation. Eventually, it would be very useful to be able to expose keyfile handling via "libnm". However that is not straight forward due to the licensing conflict. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/381 --- Makefile.am | 43 +++++++++++++++++-- libnm-core/meson.build | 20 ++++++++- libnm-core/tests/meson.build | 1 + libnm-core/tests/test-general.c | 2 +- libnm-core/tests/test-keyfile.c | 4 +- libnm-core/tests/test-setting.c | 2 +- po/POTFILES.in | 4 +- shared/meson.build | 5 +++ .../nm-keyfile}/nm-keyfile-internal.h | 0 .../nm-keyfile}/nm-keyfile-utils.c | 0 .../nm-keyfile}/nm-keyfile-utils.h | 2 +- .../nm-keyfile}/nm-keyfile.c | 0 src/initrd/nm-initrd-generator.c | 2 +- src/meson.build | 1 + src/nm-config-data.c | 2 +- src/nm-config.c | 2 +- src/nm-test-utils-core.h | 2 +- src/settings/nm-settings.c | 2 +- .../plugins/keyfile/nms-keyfile-plugin.c | 2 +- .../plugins/keyfile/nms-keyfile-reader.c | 2 +- .../plugins/keyfile/nms-keyfile-utils.c | 2 +- .../plugins/keyfile/nms-keyfile-writer.c | 2 +- 22 files changed, 80 insertions(+), 22 deletions(-) rename {libnm-core => shared/nm-keyfile}/nm-keyfile-internal.h (100%) rename {libnm-core => shared/nm-keyfile}/nm-keyfile-utils.c (100%) rename {libnm-core => shared/nm-keyfile}/nm-keyfile-utils.h (99%) rename {libnm-core => shared/nm-keyfile}/nm-keyfile.c (100%) diff --git a/Makefile.am b/Makefile.am index 249a188c81..f8020794b4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -527,6 +527,41 @@ $(shared_nm_libnm_core_aux_libnm_libnm_core_aux_la_OBJECTS): $(libnm_core_lib_h_ ############################################################################### +noinst_LTLIBRARIES += shared/nm-keyfile/libnm-keyfile.la + +shared_nm_keyfile_libnm_keyfile_la_CPPFLAGS = \ + $(dflt_cppflags) \ + -I$(srcdir)/shared \ + -I$(builddir)/shared \ + -I$(srcdir)/libnm-core \ + -I$(builddir)/libnm-core \ + $(CODE_COVERAGE_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(SANITIZER_LIB_CFLAGS) \ + -DG_LOG_DOMAIN=\""libnm"\" \ + -DNETWORKMANAGER_COMPILATION='(NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_INTERNAL|NM_NETWORKMANAGER_COMPILATION_WITH_GLIB|NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_LIB)' \ + $(NULL) + +shared_nm_keyfile_libnm_keyfile_la_SOURCES = \ + shared/nm-keyfile/nm-keyfile-internal.h \ + shared/nm-keyfile/nm-keyfile-utils.c \ + shared/nm-keyfile/nm-keyfile-utils.h \ + shared/nm-keyfile/nm-keyfile.c \ + $(NULL) + +shared_nm_keyfile_libnm_keyfile_la_LDFLAGS = \ + $(CODE_COVERAGE_LDFLAGS) \ + $(SANITIZER_LIB_LDFLAGS) \ + $(NULL) + +shared_nm_keyfile_libnm_keyfile_la_LIBADD = \ + $(GLIB_LIBS) \ + $(NULL) + +$(shared_nm_keyfile_libnm_keyfile_la_OBJECTS): $(libnm_core_lib_h_pub_mkenums) + +############################################################################### + noinst_LTLIBRARIES += shared/nm-libnm-aux/libnm-libnm-aux.la shared_nm_libnm_aux_libnm_libnm_aux_la_CPPFLAGS = \ @@ -909,8 +944,6 @@ libnm_core_lib_h_priv = \ libnm-core/nm-core-types-internal.h \ libnm-core/nm-crypto-impl.h \ libnm-core/nm-crypto.h \ - libnm-core/nm-keyfile-internal.h \ - libnm-core/nm-keyfile-utils.h \ libnm-core/nm-property-compare.h \ libnm-core/nm-setting-private.h \ libnm-core/nm-team-utils.h \ @@ -973,8 +1006,6 @@ libnm_core_lib_c_real = \ libnm-core/nm-crypto.c \ libnm-core/nm-dbus-utils.c \ libnm-core/nm-errors.c \ - libnm-core/nm-keyfile-utils.c \ - libnm-core/nm-keyfile.c \ libnm-core/nm-property-compare.c \ libnm-core/nm-setting.c \ libnm-core/nm-simple-connection.c \ @@ -1182,6 +1213,7 @@ nodist_libnm_core_tests_test_general_SOURCES = \ libnm_core_tests_ldadd = \ shared/nm-libnm-core-aux/libnm-libnm-core-aux.la \ + shared/nm-keyfile/libnm-keyfile.la \ libnm-core/libnm-core.la \ $(libnm_crypto_lib) \ shared/nm-libnm-core-intern/libnm-libnm-core-intern.la \ @@ -2269,6 +2301,7 @@ src_libNetworkManager_la_SOURCES = \ src_libNetworkManager_la_LIBADD = \ src/libNetworkManagerBase.la \ shared/nm-libnm-core-aux/libnm-libnm-core-aux.la \ + shared/nm-keyfile/libnm-keyfile.la \ libnm-core/libnm-core.la \ $(libnm_crypto_lib) \ shared/nm-libnm-core-intern/libnm-libnm-core-intern.la \ @@ -2358,6 +2391,7 @@ src_nm_iface_helper_SOURCES = \ src_nm_iface_helper_LDADD = \ src/libNetworkManagerBase.la \ shared/nm-libnm-core-aux/libnm-libnm-core-aux.la \ + shared/nm-keyfile/libnm-keyfile.la \ libnm-core/libnm-core.la \ $(libnm_crypto_lib) \ shared/nm-libnm-core-intern/libnm-libnm-core-intern.la \ @@ -2406,6 +2440,7 @@ src_initrd_nm_initrd_generator_LDADD = \ src/initrd/libnmi-core.la \ src/libNetworkManagerBase.la \ shared/nm-libnm-core-aux/libnm-libnm-core-aux.la \ + shared/nm-keyfile/libnm-keyfile.la \ libnm-core/libnm-core.la \ $(libnm_crypto_lib) \ shared/nm-libnm-core-intern/libnm-libnm-core-intern.la \ diff --git a/libnm-core/meson.build b/libnm-core/meson.build index 857e0330a1..4e1c93e778 100644 --- a/libnm-core/meson.build +++ b/libnm-core/meson.build @@ -165,8 +165,6 @@ libnm_core_sources = libnm_core_settings_sources + files( 'nm-crypto.c', 'nm-dbus-utils.c', 'nm-errors.c', - 'nm-keyfile-utils.c', - 'nm-keyfile.c', 'nm-property-compare.c', 'nm-setting.c', 'nm-simple-connection.c', @@ -229,6 +227,24 @@ libnm_libnm_core_aux_dep = declare_dependency( link_with: libnm_libnm_core_aux, ) +libnm_keyfile = static_library( + 'nm-keyfile', + sources: nm_keyfile_source + [libnm_core_enum_sources[1]], + dependencies: libnm_utils_base_dep, + c_args: [ + '-DG_LOG_DOMAIN="@0@"'.format(libnm_name), + '-DNETWORKMANAGER_COMPILATION=(NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_INTERNAL|NM_NETWORKMANAGER_COMPILATION_WITH_GLIB|NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_LIB)', + ], + link_with: libnm_libnm_core_intern, +) + +libnm_keyfile_dep = declare_dependency( + sources: [libnm_core_enum_sources[1], nm_version_macro_header], + include_directories: [libnm_core_inc, shared_inc], + dependencies: glib_dep, + link_with: libnm_keyfile, +) + enums_to_docbook = join_paths(source_root, 'tools', 'enums-to-docbook.pl') docbooks = [ diff --git a/libnm-core/tests/meson.build b/libnm-core/tests/meson.build index 292eeaa015..148841155c 100644 --- a/libnm-core/tests/meson.build +++ b/libnm-core/tests/meson.build @@ -16,6 +16,7 @@ enum_sources = gnome.mkenums_simple( ) deps = [ + libnm_keyfile_dep, libnm_core_dep, libnm_core_nm_default_dep, ] diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index c1b7b84a16..e1cafb14b4 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -52,7 +52,7 @@ #include "nm-setting-wireless-security.h" #include "nm-setting-wpan.h" #include "nm-simple-connection.h" -#include "nm-keyfile-internal.h" +#include "nm-keyfile/nm-keyfile-internal.h" #include "nm-glib-aux/nm-dedup-multi.h" #include "nm-libnm-core-intern/nm-ethtool-utils.h" diff --git a/libnm-core/tests/test-keyfile.c b/libnm-core/tests/test-keyfile.c index 574d671fbb..9675de831e 100644 --- a/libnm-core/tests/test-keyfile.c +++ b/libnm-core/tests/test-keyfile.c @@ -5,8 +5,8 @@ #include "nm-default.h" -#include "nm-keyfile-utils.h" -#include "nm-keyfile-internal.h" +#include "nm-keyfile/nm-keyfile-utils.h" +#include "nm-keyfile/nm-keyfile-internal.h" #include "nm-simple-connection.h" #include "nm-setting-connection.h" #include "nm-setting-wired.h" diff --git a/libnm-core/tests/test-setting.c b/libnm-core/tests/test-setting.c index 40852277f7..c2cf5edd03 100644 --- a/libnm-core/tests/test-setting.c +++ b/libnm-core/tests/test-setting.c @@ -24,7 +24,7 @@ #include "nm-simple-connection.h" #include "nm-setting-connection.h" #include "nm-errors.h" -#include "nm-keyfile-internal.h" +#include "nm-keyfile/nm-keyfile-internal.h" #include "nm-utils/nm-test-utils.h" diff --git a/po/POTFILES.in b/po/POTFILES.in index 0279f865fa..d48d92a00e 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -56,8 +56,6 @@ libnm-core/nm-crypto-gnutls.c libnm-core/nm-crypto-nss.c libnm-core/nm-connection.c libnm-core/nm-dbus-utils.c -libnm-core/nm-keyfile-utils.c -libnm-core/nm-keyfile.c libnm-core/nm-setting-6lowpan.c libnm-core/nm-setting-8021x.c libnm-core/nm-setting-adsl.c @@ -138,6 +136,8 @@ libnm/nm-vpn-plugin-old.c libnm/nm-vpn-service-plugin.c data/org.freedesktop.NetworkManager.policy.in.in shared/nm-glib-aux/nm-shared-utils.c +shared/nm-keyfile/nm-keyfile-utils.c +shared/nm-keyfile/nm-keyfile.c shared/nm-libnm-core-aux/nm-libnm-core-aux.c src/NetworkManagerUtils.c src/main.c diff --git a/shared/meson.build b/shared/meson.build index 481df98317..7bb5bca7a9 100644 --- a/shared/meson.build +++ b/shared/meson.build @@ -111,6 +111,11 @@ nm_libnm_core_aux_source = files('nm-libnm-core-aux/nm-libnm-core-aux.c') nm_libnm_core_utils_source = files('nm-libnm-core-intern/nm-libnm-core-utils.c') +nm_keyfile_source = files( + 'nm-keyfile/nm-keyfile-utils.c', + 'nm-keyfile/nm-keyfile.c', +) + nm_libnm_aux_source = files('nm-libnm-aux/nm-libnm-aux.c') nm_meta_setting_source = files('nm-meta-setting.c') diff --git a/libnm-core/nm-keyfile-internal.h b/shared/nm-keyfile/nm-keyfile-internal.h similarity index 100% rename from libnm-core/nm-keyfile-internal.h rename to shared/nm-keyfile/nm-keyfile-internal.h diff --git a/libnm-core/nm-keyfile-utils.c b/shared/nm-keyfile/nm-keyfile-utils.c similarity index 100% rename from libnm-core/nm-keyfile-utils.c rename to shared/nm-keyfile/nm-keyfile-utils.c diff --git a/libnm-core/nm-keyfile-utils.h b/shared/nm-keyfile/nm-keyfile-utils.h similarity index 99% rename from libnm-core/nm-keyfile-utils.h rename to shared/nm-keyfile/nm-keyfile-utils.h index 7fb807176b..a351262e7b 100644 --- a/libnm-core/nm-keyfile-utils.h +++ b/shared/nm-keyfile/nm-keyfile-utils.h @@ -6,7 +6,7 @@ #ifndef __NM_KEYFILE_UTILS_H__ #define __NM_KEYFILE_UTILS_H__ -#if !((NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_PRIVATE) +#if !((NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_INTERNAL) #error Cannot use this header. #endif diff --git a/libnm-core/nm-keyfile.c b/shared/nm-keyfile/nm-keyfile.c similarity index 100% rename from libnm-core/nm-keyfile.c rename to shared/nm-keyfile/nm-keyfile.c diff --git a/src/initrd/nm-initrd-generator.c b/src/initrd/nm-initrd-generator.c index f3f53acfe0..b486b93f31 100644 --- a/src/initrd/nm-initrd-generator.c +++ b/src/initrd/nm-initrd-generator.c @@ -6,7 +6,7 @@ #include "nm-default.h" #include "nm-core-utils.h" #include "nm-core-internal.h" -#include "nm-keyfile-internal.h" +#include "nm-keyfile/nm-keyfile-internal.h" #include "nm-initrd-generator.h" #include "nm-glib-aux/nm-io-utils.h" diff --git a/src/meson.build b/src/meson.build index 9251cfd1ab..47acb4a686 100644 --- a/src/meson.build +++ b/src/meson.build @@ -49,6 +49,7 @@ sources = files( deps = [ daemon_nm_default_dep, libn_dhcp4_dep, + libnm_keyfile_dep, libnm_core_dep, libnm_systemd_shared_dep, libnm_udev_aux_dep, diff --git a/src/nm-config-data.c b/src/nm-config-data.c index c787aa98ac..c019f65867 100644 --- a/src/nm-config-data.c +++ b/src/nm-config-data.c @@ -11,7 +11,7 @@ #include "nm-config.h" #include "devices/nm-device.h" #include "nm-core-internal.h" -#include "nm-keyfile-internal.h" +#include "nm-keyfile/nm-keyfile-internal.h" /*****************************************************************************/ diff --git a/src/nm-config.c b/src/nm-config.c index a7bb350302..ab60082b78 100644 --- a/src/nm-config.c +++ b/src/nm-config.c @@ -14,7 +14,7 @@ #include "devices/nm-device.h" #include "NetworkManagerUtils.h" #include "nm-core-internal.h" -#include "nm-keyfile-internal.h" +#include "nm-keyfile/nm-keyfile-internal.h" #define DEFAULT_CONFIG_MAIN_FILE NMCONFDIR "/NetworkManager.conf" #define DEFAULT_CONFIG_DIR NMCONFDIR "/conf.d" diff --git a/src/nm-test-utils-core.h b/src/nm-test-utils-core.h index e1d250dd2c..d984c6c00c 100644 --- a/src/nm-test-utils-core.h +++ b/src/nm-test-utils-core.h @@ -7,7 +7,7 @@ #define __NM_TEST_UTILS_CORE_H__ #include "NetworkManagerUtils.h" -#include "nm-keyfile-internal.h" +#include "nm-keyfile/nm-keyfile-internal.h" #define _NMTST_INSIDE_CORE 1 diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index d4fff4f2fa..a0b61e18ce 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -22,7 +22,7 @@ #include "nm-libnm-core-intern/nm-common-macros.h" #include "nm-glib-aux/nm-keyfile-aux.h" -#include "nm-keyfile-internal.h" +#include "nm-keyfile/nm-keyfile-internal.h" #include "nm-dbus-interface.h" #include "nm-connection.h" #include "nm-setting-8021x.h" diff --git a/src/settings/plugins/keyfile/nms-keyfile-plugin.c b/src/settings/plugins/keyfile/nms-keyfile-plugin.c index fdb88d2a6d..2906b3995c 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-plugin.c +++ b/src/settings/plugins/keyfile/nms-keyfile-plugin.c @@ -23,7 +23,7 @@ #include "nm-utils.h" #include "nm-config.h" #include "nm-core-internal.h" -#include "nm-keyfile-internal.h" +#include "nm-keyfile/nm-keyfile-internal.h" #include "systemd/nm-sd-utils-shared.h" diff --git a/src/settings/plugins/keyfile/nms-keyfile-reader.c b/src/settings/plugins/keyfile/nms-keyfile-reader.c index af9e67265b..e8c9f9fe2a 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-reader.c +++ b/src/settings/plugins/keyfile/nms-keyfile-reader.c @@ -9,7 +9,7 @@ #include -#include "nm-keyfile-internal.h" +#include "nm-keyfile/nm-keyfile-internal.h" #include "NetworkManagerUtils.h" #include "nms-keyfile-utils.h" diff --git a/src/settings/plugins/keyfile/nms-keyfile-utils.c b/src/settings/plugins/keyfile/nms-keyfile-utils.c index f03c601a56..bc8dfd12c2 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-utils.c +++ b/src/settings/plugins/keyfile/nms-keyfile-utils.c @@ -11,7 +11,7 @@ #include #include "nm-glib-aux/nm-io-utils.h" -#include "nm-keyfile-internal.h" +#include "nm-keyfile/nm-keyfile-internal.h" #include "nm-utils.h" #include "nm-setting-wired.h" #include "nm-setting-wireless.h" diff --git a/src/settings/plugins/keyfile/nms-keyfile-writer.c b/src/settings/plugins/keyfile/nms-keyfile-writer.c index fa95198c00..3a630c16f5 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-writer.c +++ b/src/settings/plugins/keyfile/nms-keyfile-writer.c @@ -12,7 +12,7 @@ #include #include -#include "nm-keyfile-internal.h" +#include "nm-keyfile/nm-keyfile-internal.h" #include "nms-keyfile-utils.h" #include "nms-keyfile-reader.h"