about summary refs log tree commit diff
path: root/src/nmcli/agent.c
diff options
context:
space:
mode:
authorJeremy Bicha <jeremy.bicha@canonical.com>2022-02-03 09:24:19 -0500
committerJeremy Bicha <jeremy.bicha@canonical.com>2022-02-03 12:01:26 -0500
commit240934659cd8326a14324c73d4f0f88eecfddcab (patch)
treee07cde48aa0a143bebf10ca7103cc0e69febad25 /src/nmcli/agent.c
parentfbe61ddadf4a89800a8e3651ae91099259ddf2ad (diff)
parent1628eda029ba4dede8d4d45572c6b60367882436 (diff)
Merge tag 'debian/1.34.0-2' into ubuntu/master
network-manager Debian release 1.34.0-2
Diffstat (limited to 'src/nmcli/agent.c')
-rw-r--r--src/nmcli/agent.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/nmcli/agent.c b/src/nmcli/agent.c
index a0b23dd1..bdbd6e45 100644
--- a/src/nmcli/agent.c
+++ b/src/nmcli/agent.c
@@ -7,9 +7,12 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#if HAVE_EDITLINE_READLINE
+#include <editline/readline.h>
+#else
 #include <readline/readline.h>
 #include <readline/history.h>
-
+#endif
 #include "common.h"
 #include "utils.h"
 #include "libnmc-base/nm-secret-agent-simple.h"
@@ -51,16 +54,14 @@ usage_agent_all(void)
                  "Runs nmcli as both NetworkManager secret and a polkit agent.\n\n"));
 }
 
-/* for pre-filling a string to readline prompt */
 static char *pre_input_deftext;
-static int
-set_deftext(void)
+
+static int set_deftext(_NMC_RL_STARTUPHOOK_ARGS)
 {
     if (pre_input_deftext && rl_startup_hook) {
         rl_insert_text(pre_input_deftext);
-        g_free(pre_input_deftext);
-        pre_input_deftext = NULL;
-        rl_startup_hook   = NULL;
+        nm_clear_g_free(&pre_input_deftext);
+        rl_startup_hook = NULL;
     }
     return 0;
 }
@@ -83,8 +84,8 @@ get_secrets_from_user(const NmcConfig *nmc_config,
             g_print("%s\n", msg);
         if (secret->value) {
             /* Prefill the password if we have it. */
-            rl_startup_hook   = set_deftext;
-            pre_input_deftext = g_strdup(secret->value);
+            rl_startup_hook = set_deftext;
+            nm_strdup_reset(&pre_input_deftext, secret->value);
         }
         if (secret->no_prompt_entry_id)
             pwd = nmc_readline(nmc_config, "%s: ", secret->pretty_name);