libnm/keyfile: add writer_full() hook for persisting non GObject based properties

This commit is contained in:
Thomas Haller
2019-03-22 15:16:48 +01:00
parent 699257d432
commit c02fadecec

View File

@@ -41,6 +41,8 @@
/*****************************************************************************/ /*****************************************************************************/
typedef struct _ParseInfoProperty ParseInfoProperty;
typedef struct { typedef struct {
NMConnection *connection; NMConnection *connection;
GKeyFile *keyfile; GKeyFile *keyfile;
@@ -2271,24 +2273,32 @@ cert_writer (KeyfileWriterInfo *info,
/*****************************************************************************/ /*****************************************************************************/
typedef struct { struct _ParseInfoProperty {
const char *property_name; const char *property_name;
void (*parser) (KeyfileReaderInfo *info, void (*parser) (KeyfileReaderInfo *info,
NMSetting *setting, NMSetting *setting,
const char *key); const char *key);
void (*writer) (KeyfileWriterInfo *info, union {
NMSetting *setting, void (*writer) (KeyfileWriterInfo *info,
const char *key, NMSetting *setting,
const GValue *value); const char *key,
const GValue *value);
void (*writer_full) (KeyfileWriterInfo *info,
const NMMetaSettingInfo *setting_info,
const NMSettInfoProperty *property_info,
const ParseInfoProperty *pip,
NMSetting *setting);
};
bool parser_skip; bool parser_skip;
bool parser_no_check_key:1; bool parser_no_check_key:1;
bool writer_skip:1; bool writer_skip:1;
bool has_writer_full:1;
/* usually, we skip to write values that have their /* usually, we skip to write values that have their
* default value. By setting this flag to TRUE, also * default value. By setting this flag to TRUE, also
* default values are written. */ * default values are written. */
bool writer_persist_default:1; bool writer_persist_default:1;
} ParseInfoProperty; };
#define PARSE_INFO_PROPERTY(_property_name, ...) \ #define PARSE_INFO_PROPERTY(_property_name, ...) \
(&((const ParseInfoProperty) { \ (&((const ParseInfoProperty) { \
@@ -3343,32 +3353,36 @@ write_setting_value (KeyfileWriterInfo *info,
nm_assert ( !property_info->param_spec nm_assert ( !property_info->param_spec
|| nm_streq (property_info->param_spec->name, property_info->name)); || nm_streq (property_info->param_spec->name, property_info->name));
if (!property_info->param_spec) key = property_info->name;
return;
key = property_info->param_spec->name;
pip = _parse_info_find (setting, key, &setting_info); pip = _parse_info_find (setting, key, &setting_info);
if (!setting_info) { if (!pip) {
/* the setting type is unknown. That is highly unexpected if (!setting_info) {
* (and as this is currently only called from NetworkManager /* the setting type is unknown. That is highly unexpected
* daemon, not possible). * (and as this is currently only called from NetworkManager
* * daemon, not possible).
* Still, handle it gracefully, because later keyfile writer will become *
* public API of libnm, where @setting is (untrusted) user input. * Still, handle it gracefully, because later keyfile writer will become
* * public API of libnm, where @setting is (untrusted) user input.
* Gracefully here just means: ignore the setting. */ *
return; * Gracefully here just means: ignore the setting. */
return;
}
if (!property_info->param_spec)
return;
if (nm_streq (key, NM_SETTING_NAME))
return;
} else {
if (pip->has_writer_full) {
pip->writer_full (info, setting_info, property_info, pip, setting);
return;
}
if (pip->writer_skip)
return;
} }
if ( !pip nm_assert (property_info->param_spec);
&& nm_streq (key, NM_SETTING_NAME))
return;
if ( pip
&& pip->writer_skip)
return;
/* Don't write secrets that are owned by user secret agents or aren't /* Don't write secrets that are owned by user secret agents or aren't
* supposed to be saved. VPN secrets are handled specially though since * supposed to be saved. VPN secrets are handled specially though since