static gboolean get_secrets_from_user (const char *request_id, const char *title, const char *msg, GPtrArray *secrets) { int i; for (i = 0; i < secrets->len; i++) { NMSecretAgentSimpleSecret *secret = secrets->pdata[i]; char *pwd = NULL; /* Ask user for the password */ 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); } pwd = nmc_readline ("%s (%s): ", secret->name, secret->prop_name); /* No password provided, cancel the secrets. */ if (!pwd) return FALSE; g_free (secret->value); secret->value = pwd; } return TRUE; }
static gboolean get_secrets_from_user (const char *request_id, const char *title, const char *msg, gboolean ask, GHashTable *pwds_hash, GPtrArray *secrets) { int i; for (i = 0; i < secrets->len; i++) { NMSecretAgentSimpleSecret *secret = secrets->pdata[i]; char *pwd = NULL; /* First try to find the password in provided passwords file, * then ask user. */ if (pwds_hash && (pwd = g_hash_table_lookup (pwds_hash, secret->prop_name))) { pwd = g_strdup (pwd); } else { g_print ("%s\n", msg); if (ask) { if (secret->value) { /* Prefill the password if we have it. */ rl_startup_hook = nmc_rl_set_deftext; nmc_rl_pre_input_deftext = g_strdup (secret->value); } pwd = nmc_readline ("%s (%s): ", secret->name, secret->prop_name); if (!pwd) pwd = g_strdup (""); } else { g_printerr (_("Warning: password for '%s' not given in 'passwd-file' " "and nmcli cannot ask without '--ask' option.\n"), secret->prop_name); } } /* No password provided, cancel the secrets. */ if (!pwd) return FALSE; g_free (secret->value); secret->value = pwd; } return TRUE; }