summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-05-04 16:33:59 +0200
committerThomas Haller <thaller@redhat.com>2020-05-13 10:28:04 +0200
commit38a79ca5cd0366c3c6bac82c963b2d7aace2e4b0 (patch)
treeecef1dff7a88434f428490d5b338987ac4262eda
parent360f0fae111a76cc47fb559d035096221a3a5993 (diff)
downloadNetworkManager-38a79ca5cd0366c3c6bac82c963b2d7aace2e4b0.tar.gz
cli: split parsing from nmc_utils_read_passwd_file()
Makes it easier testable.
-rw-r--r--clients/common/nm-client-utils.c25
-rw-r--r--clients/common/nm-client-utils.h4
2 files changed, 22 insertions, 7 deletions
diff --git a/clients/common/nm-client-utils.c b/clients/common/nm-client-utils.c
index a296a3b9dc..97885291d6 100644
--- a/clients/common/nm-client-utils.c
+++ b/clients/common/nm-client-utils.c
@@ -611,16 +611,11 @@ nmc_utils_read_passwd_file (const char *passwd_file,
GError **error)
{
nm_auto_clear_secret_ptr NMSecretPtr contents = { 0 };
- gs_unref_hashtable GHashTable *pwds_hash = NULL;
- const char *contents_str;
- gsize contents_line;
-
- pwds_hash = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, (GDestroyNotify) nm_free_secret);
NM_SET_OUT (out_error_line, -1);
if (!passwd_file)
- return g_steal_pointer (&pwds_hash);
+ return g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, (GDestroyNotify) nm_free_secret);
if (!nm_utils_file_get_contents (-1,
passwd_file,
@@ -632,7 +627,23 @@ nmc_utils_read_passwd_file (const char *passwd_file,
error))
return NULL;
- contents_str = contents.str;
+ return nmc_utils_parse_passwd_file (contents.str, out_error_line, error);
+}
+
+GHashTable *
+nmc_utils_parse_passwd_file (char *contents /* will be modified */,
+ gssize *out_error_line,
+ GError **error)
+{
+ gs_unref_hashtable GHashTable *pwds_hash = NULL;
+ const char *contents_str;
+ gsize contents_line;
+
+ pwds_hash = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, (GDestroyNotify) nm_free_secret);
+
+ NM_SET_OUT (out_error_line, -1);
+
+ contents_str = contents;
contents_line = 0;
while (contents_str[0]) {
nm_auto_free_secret char *l_hash_key = NULL;
diff --git a/clients/common/nm-client-utils.h b/clients/common/nm-client-utils.h
index f4f67544e7..8983e6c89b 100644
--- a/clients/common/nm-client-utils.h
+++ b/clients/common/nm-client-utils.h
@@ -43,6 +43,10 @@ const char *nmc_password_subst_char (void);
void nmc_print_qrcode (const char *str);
+GHashTable *nmc_utils_parse_passwd_file (char *contents,
+ gssize *out_error_line,
+ GError **error);
+
GHashTable *nmc_utils_read_passwd_file (const char *passwd_file,
gssize *out_error_line,
GError **error);