summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2018-07-16 12:59:08 +0200
committerThomas Haller <thaller@redhat.com>2018-09-11 18:00:50 +0200
commitafd618b789cd161021107180e625bb92bcfcb17a (patch)
tree4c7810c2ad38503aa7ce3039144597a4919c2148
parent85f35193e966c3327e0ef0ab4702068eb4a2c061 (diff)
downloadNetworkManager-afd618b789cd161021107180e625bb92bcfcb17a.tar.gz
service-plugin: allow continuations in the auth-dialog protocol
Equals sign was picked as a continuation character arbitratily. It would simplify parsing, if we cared. DATA_KEY=some-key DATA_VAL=string =continued after a line break SECRET_KEY=key names =can have =continuations too SECRET_VAL=value
-rw-r--r--libnm/nm-vpn-service-plugin.c60
-rw-r--r--libnm/tests/test-general.c11
2 files changed, 45 insertions, 26 deletions
diff --git a/libnm/nm-vpn-service-plugin.c b/libnm/nm-vpn-service-plugin.c
index 31a3f5b109..375948aa1d 100644
--- a/libnm/nm-vpn-service-plugin.c
+++ b/libnm/nm-vpn-service-plugin.c
@@ -787,10 +787,13 @@ nm_vpn_service_plugin_read_vpn_details (int fd,
gs_unref_hashtable GHashTable *data = NULL;
gs_unref_hashtable GHashTable *secrets = NULL;
gboolean success = FALSE;
- char *key = NULL, *val = NULL;
+ GHashTable *hash = NULL;
+ GString *key = NULL, *val = NULL;
nm_auto_free_gstring GString *line = NULL;
char c;
+ GString *str = NULL;
+
if (out_data)
g_return_val_if_fail (*out_data == NULL, FALSE);
if (out_secrets)
@@ -804,7 +807,6 @@ nm_vpn_service_plugin_read_vpn_details (int fd,
/* Read stdin for data and secret items until we get a DONE */
while (1) {
ssize_t nr;
- GHashTable *hash = NULL;
errno = 0;
nr = read (fd, &c, 1);
@@ -823,32 +825,50 @@ nm_vpn_service_plugin_read_vpn_details (int fd,
continue;
}
- /* Check for the finish marker */
- if (strcmp (line->str, "DONE") == 0)
- break;
+ if (str && *line->str == '=') {
+ /* continuation */
+ g_string_append_c (str, '\n');
+ g_string_append (str, line->str + 1);
+ } else if (key && val) {
+ /* done a line */
+ g_return_val_if_fail (hash, FALSE);
+ g_hash_table_insert (hash,
+ g_string_free (key, FALSE),
+ g_string_free (val, FALSE));
+ key = NULL;
+ val = NULL;
+ hash = NULL;
+ success = TRUE; /* Got at least one value */
+ }
- /* Otherwise it's a data/secret item */
- if (strncmp (line->str, DATA_KEY_TAG, strlen (DATA_KEY_TAG)) == 0) {
+ if (strcmp (line->str, "DONE") == 0) {
+ /* finish marker */
+ break;
+ } else if (strncmp (line->str, DATA_KEY_TAG, strlen (DATA_KEY_TAG)) == 0) {
+ if (key != NULL)
+ g_string_free (key, TRUE);
+ key = g_string_new (line->str + strlen (DATA_KEY_TAG));
+ str = key;
hash = data;
- key = g_strdup (line->str + strlen (DATA_KEY_TAG));
} else if (strncmp (line->str, DATA_VAL_TAG, strlen (DATA_VAL_TAG)) == 0) {
- hash = data;
- val = g_strdup (line->str + strlen (DATA_VAL_TAG));
+ if (val != NULL)
+ g_string_free (val, TRUE);
+ val = g_string_new (line->str + strlen (DATA_VAL_TAG));
+ str = val;
} else if (strncmp (line->str, SECRET_KEY_TAG, strlen (SECRET_KEY_TAG)) == 0) {
+ if (key != NULL)
+ g_string_free (key, TRUE);
+ key = g_string_new (line->str + strlen (SECRET_KEY_TAG));
+ str = key;
hash = secrets;
- key = g_strdup (line->str + strlen (SECRET_KEY_TAG));
} else if (strncmp (line->str, SECRET_VAL_TAG, strlen (SECRET_VAL_TAG)) == 0) {
- hash = secrets;
- val = g_strdup (line->str + strlen (SECRET_VAL_TAG));
+ if (val != NULL)
+ g_string_free (val, TRUE);
+ val = g_string_new (line->str + strlen (SECRET_VAL_TAG));
+ str = val;
}
- g_string_truncate (line, 0);
- if (key && val && hash) {
- g_hash_table_insert (hash, key, val);
- key = NULL;
- val = NULL;
- success = TRUE; /* Got at least one value */
- }
+ g_string_truncate (line, 0);
}
if (success) {
diff --git a/libnm/tests/test-general.c b/libnm/tests/test-general.c
index d03b50c322..9f0d582cf3 100644
--- a/libnm/tests/test-general.c
+++ b/libnm/tests/test-general.c
@@ -2359,13 +2359,13 @@ test_nm_vpn_service_plugin_read_vpn_details (void)
"DONE\n"
"",
READ_VPN_DETAIL_DATA (
- { "some-key", "string" },
+ { "some-key", "string\ncontinued after a line break" },
{ "", "x" },
{ "y", "y" },
- { "s1", "z" },
),
READ_VPN_DETAIL_DATA (
- { "key names", "value" },
+ { "key names\ncan have\ncontinuations too", "value" },
+ { "s1", "z" },
),
);
@@ -2379,10 +2379,9 @@ test_nm_vpn_service_plugin_read_vpn_details (void)
"SECRET_VAL=value\n"
"",
READ_VPN_DETAIL_DATA (
- { "some-key", "string" },
+ { "some-key", "string\ncontinued after a line break" },
),
READ_VPN_DETAIL_DATA (
- { "key names", "value" },
),
);
@@ -2417,7 +2416,7 @@ test_nm_vpn_service_plugin_read_vpn_details (void)
"\n"
"",
READ_VPN_DETAIL_DATA (
- { "some", "val2" },
+ { "some\nkey-2", "val2" },
{ "some-key", "string" },
{ "key3", "val3" },
),