summaryrefslogtreecommitdiff
path: root/src/settings/plugins
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-02-16 15:38:20 +0100
committerLubomir Rintel <lkundrak@v3.sk>2017-02-17 14:24:34 +0100
commit324cf7ce8265ce551a977ceeb4d4693ffe45590b (patch)
treebf69725cd2ec4d7260cb67ebff64460071d70c64 /src/settings/plugins
parent7a21ae3e7785e8c763316b6d2c5a1f96bb7abc50 (diff)
downloadNetworkManager-324cf7ce8265ce551a977ceeb4d4693ffe45590b.tar.gz
ifcfg-rh: reuse file-suffix from NMSetting8021xSchemeVtablelr/pkcs11-pin
Keyfile writer computes the file extension and only uses the file suffix from the vtable. Do that for ifcfg-rh too. No change in behavior.
Diffstat (limited to 'src/settings/plugins')
-rw-r--r--src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c15
-rw-r--r--src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h2
-rw-r--r--src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c26
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c6
-rw-r--r--src/settings/plugins/keyfile/nms-keyfile-writer.c2
5 files changed, 22 insertions, 29 deletions
diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c
index d1c0097649..0a6b16947a 100644
--- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c
+++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c
@@ -100,19 +100,20 @@ utils_should_ignore_file (const char *filename, gboolean only_ifcfg)
}
char *
-utils_cert_path (const char *parent, const char *suffix)
+utils_cert_path (const char *parent, const char *suffix, const char *extension)
{
+ gs_free char *dir = NULL;
const char *name;
- char *dir, *path;
- g_return_val_if_fail (parent != NULL, NULL);
- g_return_val_if_fail (suffix != NULL, NULL);
+ g_return_val_if_fail (parent, NULL);
+ g_return_val_if_fail (suffix, NULL);
+ g_return_val_if_fail (extension, NULL);
name = utils_get_ifcfg_name (parent, FALSE);
+ g_return_val_if_fail (name, NULL);
+
dir = g_path_get_dirname (parent);
- path = g_strdup_printf ("%s/%s-%s", dir, name, suffix);
- g_free (dir);
- return path;
+ return g_strdup_printf ("%s/%s-%s.%s", dir, name, suffix, extension);
}
const char *
diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h
index af0469e66f..d209a0673c 100644
--- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h
+++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h
@@ -31,7 +31,7 @@
#define NM_IFCFG_CONNECTION_LOG_FMTD "%s (%s,\"%s\",%p)"
#define NM_IFCFG_CONNECTION_LOG_ARGD(con) NM_IFCFG_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con)), (con)
-char *utils_cert_path (const char *parent, const char *suffix);
+char *utils_cert_path (const char *parent, const char *suffix, const char *extension);
const char *utils_get_ifcfg_name (const char *file, gboolean only_ifcfg);
diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c
index 96f8d062f3..bdfb641fb2 100644
--- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c
+++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c
@@ -149,42 +149,32 @@ error:
typedef struct {
const NMSetting8021xSchemeVtable *vtable;
const char *ifcfg_rh_key;
- const char *ifcfg_rh_suffix;
- const char *ifcfg_rh_suffix_p12;
} Setting8021xSchemeVtable;
static const Setting8021xSchemeVtable setting_8021x_scheme_vtable[] = {
[NM_SETTING_802_1X_SCHEME_TYPE_CA_CERT] = {
.vtable = &nm_setting_8021x_scheme_vtable[NM_SETTING_802_1X_SCHEME_TYPE_CA_CERT],
.ifcfg_rh_key = "IEEE_8021X_CA_CERT",
- .ifcfg_rh_suffix = "ca-cert.der",
},
[NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_CA_CERT] = {
.vtable = &nm_setting_8021x_scheme_vtable[NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_CA_CERT],
.ifcfg_rh_key = "IEEE_8021X_INNER_CA_CERT",
- .ifcfg_rh_suffix = "inner-ca-cert.der",
},
[NM_SETTING_802_1X_SCHEME_TYPE_CLIENT_CERT] = {
.vtable = &nm_setting_8021x_scheme_vtable[NM_SETTING_802_1X_SCHEME_TYPE_CLIENT_CERT],
.ifcfg_rh_key = "IEEE_8021X_CLIENT_CERT",
- .ifcfg_rh_suffix = "client-cert.der",
},
[NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_CLIENT_CERT] = {
.vtable = &nm_setting_8021x_scheme_vtable[NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_CLIENT_CERT],
.ifcfg_rh_key = "IEEE_8021X_INNER_CLIENT_CERT",
- .ifcfg_rh_suffix = "inner-client-cert.der",
},
[NM_SETTING_802_1X_SCHEME_TYPE_PRIVATE_KEY] = {
.vtable = &nm_setting_8021x_scheme_vtable[NM_SETTING_802_1X_SCHEME_TYPE_PRIVATE_KEY],
.ifcfg_rh_key = "IEEE_8021X_PRIVATE_KEY",
- .ifcfg_rh_suffix = "private-key.pem",
- .ifcfg_rh_suffix_p12 = "private-key.p12",
},
[NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_PRIVATE_KEY] = {
.vtable = &nm_setting_8021x_scheme_vtable[NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_PRIVATE_KEY],
.ifcfg_rh_key = "IEEE_8021X_INNER_PRIVATE_KEY",
- .ifcfg_rh_suffix = "inner-private-key.pem",
- .ifcfg_rh_suffix_p12 = "inner-private-key.p12",
},
};
@@ -200,7 +190,7 @@ write_object (NMSetting8021x *s_8021x,
const char *password = NULL;
NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE;
char *secret_name, *secret_flags;
- const char *suffix;
+ const char *extension;
g_return_val_if_fail (ifcfg != NULL, FALSE);
g_return_val_if_fail (objtype != NULL, FALSE);
@@ -233,10 +223,12 @@ write_object (NMSetting8021x *s_8021x,
g_free (secret_name);
g_free (secret_flags);
- suffix = objtype->ifcfg_rh_suffix;
- if ( objtype->vtable->format_func
- && objtype->vtable->format_func (s_8021x) == NM_SETTING_802_1X_CK_FORMAT_PKCS12)
- suffix = objtype->ifcfg_rh_suffix_p12;
+ if (!objtype->vtable->format_func)
+ extension = "der";
+ else if (objtype->vtable->format_func (s_8021x) == NM_SETTING_802_1X_CK_FORMAT_PKCS12)
+ extension = "p12";
+ else
+ extension = "pem";
/* If certificate/private key wasn't sent, the connection may no longer be
* 802.1x and thus we clear out the paths and certs.
@@ -251,7 +243,7 @@ write_object (NMSetting8021x *s_8021x,
* /etc/sysconfig/network-scripts/ca-cert-Test_Write_Wifi_WPA_EAP-TLS.der
* will be deleted, but /etc/pki/tls/cert.pem will not.
*/
- standard_file = utils_cert_path (svFileGetName (ifcfg), suffix);
+ standard_file = utils_cert_path (svFileGetName (ifcfg), objtype->vtable->file_suffix, extension);
if (g_file_test (standard_file, G_FILE_TEST_EXISTS))
ignored = unlink (standard_file);
g_free (standard_file);
@@ -274,7 +266,7 @@ write_object (NMSetting8021x *s_8021x,
char *new_file;
GError *write_error = NULL;
- new_file = utils_cert_path (svFileGetName (ifcfg), suffix);
+ new_file = utils_cert_path (svFileGetName (ifcfg), objtype->vtable->file_suffix, extension);
if (!new_file) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED,
"Could not create file path for %s / %s",
diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
index f467d864cc..11c412edca 100644
--- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
+++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
@@ -4486,15 +4486,15 @@ test_write_wired_8021x_tls (gconstpointer test_data)
}
/* Clean up created certs and keys */
- tmp = utils_cert_path (testfile, "ca-cert.der");
+ tmp = utils_cert_path (testfile, "ca-cert", "der");
nmtst_file_unlink_if_exists (tmp);
g_free (tmp);
- tmp = utils_cert_path (testfile, "client-cert.der");
+ tmp = utils_cert_path (testfile, "client-cert", "der");
nmtst_file_unlink_if_exists (tmp);
g_free (tmp);
- tmp = utils_cert_path (testfile, "private-key.pem");
+ tmp = utils_cert_path (testfile, "private-key", "pem");
nmtst_file_unlink_if_exists (tmp);
g_free (tmp);
}
diff --git a/src/settings/plugins/keyfile/nms-keyfile-writer.c b/src/settings/plugins/keyfile/nms-keyfile-writer.c
index 50b4113649..a673742050 100644
--- a/src/settings/plugins/keyfile/nms-keyfile-writer.c
+++ b/src/settings/plugins/keyfile/nms-keyfile-writer.c
@@ -124,7 +124,7 @@ cert_writer (NMConnection *connection,
* from now on instead of pushing around the certificate data.
*/
new_path = g_strdup_printf ("%s/%s-%s.%s", info->keyfile_dir, nm_connection_get_uuid (connection),
- cert_data->vtable->keyfile_suffix, ext);
+ cert_data->vtable->file_suffix, ext);
success = nm_utils_file_set_contents (new_path, (const gchar *) blob_data,
blob_len, 0600, &local);