Commit graph

15 commits

Author SHA1 Message Date
Thomas Haller
ab7d0c62f9
keyfile: rework error reporting from read/write handler
Setting the error on the callback does not work well from bindings.
Instead, let bindings call a (future) nm_keyfile_handler_data_fail_with_error()
function on the handler_data to indicate failure.
2020-06-05 09:17:18 +02:00
Thomas Haller
e3d7ba89e5
keyfile: rename handler variable in KeyfileReaderInfo and KeyfileWriterInfo 2020-06-05 09:17:18 +02:00
Thomas Haller
0bfdb26973
keyfile: add NMKeyfileHandlerData typedef for arguments of keyfile callbacks
As the keyfile handler callback will become public API, it needs to be
usable via bindings. A plain void pointer is not usable. Instead, add
a new type that can be used via introspection.
2020-06-05 09:17:18 +02:00
Thomas Haller
18c1fe6ed8
keyfile: merge NMKeyfile{Read,Write}Type as NMKeyfileHandlerType
This will become public API. The enum for read and write callback
serves very similar purposes. Merge them so that we have fewer
types in the public API.
2020-06-05 09:17:14 +02:00
Thomas Haller
82a468c9ad
keyfile: suppress bogus warning about [ethernet-s390-options] setting
S390 options are stored in a separate [ethernet-s390-options] section.
This group must not be interpreted as a NMSetting name, otherwise we
log a bogus warning:

  <warn>  [1590523563.7757] keyfile: ethernet-s390-options: invalid setting name 'ethernet-s390-options'

Fixes: cf9b8d3bad ('libnm/keyfile: implement ethernet.s390-options in keyfile')
2020-05-26 22:45:10 +02:00
Thomas Haller
618ae93b94
libnm: rename nm_setting_gendata_*() API to nm_setting_option_*()
We are going to expose some of this API in libnm.

The name "gendata" (for "generic data") is not very suited. Instead,
call the public API nm_setting_option_*(). This also brings no naming
conflict, because currently no API exists with such naming.

Rename the internal API, so that it matches the API that we are going
to expose next.
2020-05-22 15:58:08 +02:00
Antonio Cardace
858fb211ad
keyfile: add support for uint32 variant types when using gendata
https://bugzilla.redhat.com/show_bug.cgi?id=1614700
2020-05-13 10:15:23 +02:00
Thomas Haller
e08bb66b34
keyfile,config: use nm_keyfile_error_is_not_found() helper 2020-05-07 14:08:32 +02:00
Thomas Haller
dade5055fb
keyfile: add nm_keyfile_plugin_kf_get_integer_list_uint() to parse a list of integers
We had three callers of nm_keyfile_plugin_kf_get_integer_list(). Two
only wanted to read values in range of guint8. One, wanted to read
unsigned integers (for which nm_keyfile_plugin_kf_get_integer_list()
was not suitable).

Instead, implement a integer list reader ourself.

One change is that g_key_file_get_integer_list() would accept list elements
with a number followed by a white space and garbage ([1]). We don't do that,
so there is a change in behavior here. That seems preferable, we don't
want to accept garbage.

The error reason text from the reader now also changes, and obviously we
no longer fail for integer values larger than G_MAXINT.

[1] c9bf247eb9/glib/gkeyfile.c (L4445)
2020-05-04 13:12:43 +02:00
Thomas Haller
93285a465f
keyfile: refactor writing of G_TYPE_ARRAY list of unsigned integers
Keyfile handles GObject properties of type G_TYPE_ARRAY as a GArray
of unsigned ints. That is correct, because all our properties of this
GType happen to be of this kind.

However, then the function was using nm_keyfile_plugin_kf_set_integer_list(),
which only can handle signed integers. There was thus an assertion that all
integers were non-negative. Which, probably was also correct, because NMSettingDcb
would validate that all values of such kind are in fact positive. Anyway, that
is an unexpected limitation (if not a bug).

Fix that by handling the array as unsigned list of integers.

Also, since glib doesn't provide an API for storing lists of unsigend
integers, we have to implement our own. but that is no loss. We probably
do it better anyway.
2020-05-04 12:47:11 +02:00
Thomas Haller
2cf31bfef0 keyfile: minor cleanup handling error in read_array_of_uint()
Why "if (length > G_MAXUINT)"? This is never going to hit. Also,
we probably should actual missing keys handle differently from
empty lists. If @error is set, return without setting the property.
2020-04-15 22:37:51 +02:00
Thomas Haller
12c2aacea7 keyfile: cleanup mac_address_parser() 2020-04-15 11:25:23 +02:00
Thomas Haller
073994ca42 all: use nm_clear_g_free() instead of g_clear_pointer()
I think it's preferable to use nm_clear_g_free() instead of
g_clear_pointer(, g_free). The reasons are not very strong,
but I think it is overall preferable to have a shorthand for this
frequently used functionality.

   sed 's/\<g_clear_pointer *(\([^;]*\), *\(g_free\) *)/nm_clear_g_free (\1)/g' $(git grep -l g_clear_pointer) -i
2020-03-23 11:05:34 +01:00
Thomas Haller
8f3b43f009 all: use nm_utils_ipaddr_is_valid() instead of nm_utils_ipaddr_valid()
We should use the same "is-valid" function everywhere.

Since nm_utils_ipaddr_valid() is part of libnm, it does not qualify.

Use nm_utils_ipaddr_is_valid() instead.
2020-01-28 11:17:41 +01:00
Thomas Haller
d964decbbd 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 59eb5312a5 ('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
2020-01-07 13:17:47 +01:00
Renamed from libnm-core/nm-keyfile.c (Browse further)