mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-27 12:50:09 +01:00
clients: merge branch 'bg/clients-agent-message-rh1351272'
https://bugzilla.redhat.com/show_bug.cgi?id=1351272
(cherry picked from commit 73c649f365)
This commit is contained in:
commit
1064dcafbe
7 changed files with 61 additions and 35 deletions
|
|
@ -96,7 +96,8 @@ get_secrets_from_user (const char *request_id,
|
|||
char *pwd = NULL;
|
||||
|
||||
/* Ask user for the password */
|
||||
g_print ("%s\n", msg);
|
||||
if (msg)
|
||||
g_print ("%s\n", msg);
|
||||
if (secret->value) {
|
||||
/* Prefill the password if we have it. */
|
||||
rl_startup_hook = set_deftext;
|
||||
|
|
@ -148,7 +149,10 @@ do_agent_secret (NmCli *nmc, int argc, char **argv)
|
|||
nmc->should_wait++;
|
||||
|
||||
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (nmc->secret_agent), NULL);
|
||||
g_signal_connect (nmc->secret_agent, "request-secrets", G_CALLBACK (secrets_requested), nmc);
|
||||
g_signal_connect (nmc->secret_agent,
|
||||
NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS,
|
||||
G_CALLBACK (secrets_requested),
|
||||
nmc);
|
||||
g_print (_("nmcli successfully registered as a NetworkManager's secret agent.\n"));
|
||||
} else {
|
||||
g_string_printf (nmc->return_text, _("Error: secret agent initialization failed"));
|
||||
|
|
|
|||
|
|
@ -1058,13 +1058,15 @@ get_secrets_from_user (const char *request_id,
|
|||
nmc_rl_pre_input_deftext = g_strdup (secret->value);
|
||||
}
|
||||
}
|
||||
g_print ("%s\n", msg);
|
||||
if (msg)
|
||||
g_print ("%s\n", msg);
|
||||
pwd = nmc_readline_echo (secret->password ? echo_on : TRUE,
|
||||
"%s (%s): ", secret->name, secret->prop_name);
|
||||
if (!pwd)
|
||||
pwd = g_strdup ("");
|
||||
} else {
|
||||
g_print ("%s\n", msg);
|
||||
if (msg)
|
||||
g_print ("%s\n", msg);
|
||||
g_printerr (_("Warning: password for '%s' not given in 'passwd-file' "
|
||||
"and nmcli cannot ask without '--ask' option.\n"),
|
||||
secret->prop_name);
|
||||
|
|
|
|||
|
|
@ -2530,7 +2530,10 @@ nmc_activate_connection (NmCli *nmc,
|
|||
/* Create secret agent */
|
||||
nmc->secret_agent = nm_secret_agent_simple_new ("nmcli-connect");
|
||||
if (nmc->secret_agent) {
|
||||
g_signal_connect (nmc->secret_agent, "request-secrets", G_CALLBACK (nmc_secrets_requested), nmc);
|
||||
g_signal_connect (nmc->secret_agent,
|
||||
NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS,
|
||||
G_CALLBACK (nmc_secrets_requested),
|
||||
nmc);
|
||||
if (connection) {
|
||||
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (nmc->secret_agent),
|
||||
nm_object_get_path (NM_OBJECT (connection)));
|
||||
|
|
|
|||
|
|
@ -1860,8 +1860,12 @@ do_device_connect (NmCli *nmc, int argc, char **argv)
|
|||
|
||||
/* Create secret agent */
|
||||
nmc->secret_agent = nm_secret_agent_simple_new ("nmcli-connect");
|
||||
if (nmc->secret_agent)
|
||||
g_signal_connect (nmc->secret_agent, "request-secrets", G_CALLBACK (nmc_secrets_requested), nmc);
|
||||
if (nmc->secret_agent) {
|
||||
g_signal_connect (nmc->secret_agent,
|
||||
NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS,
|
||||
G_CALLBACK (nmc_secrets_requested),
|
||||
nmc);
|
||||
}
|
||||
|
||||
info = g_malloc0 (sizeof (AddAndActivateInfo));
|
||||
info->nmc = nmc;
|
||||
|
|
|
|||
|
|
@ -428,11 +428,28 @@ static void
|
|||
request_secrets_from_ui (NMSecretAgentSimpleRequest *request)
|
||||
{
|
||||
GPtrArray *secrets;
|
||||
NMSecretAgentSimplePrivate *priv;
|
||||
NMSecretAgentSimpleSecret *secret;
|
||||
const char *title;
|
||||
char *msg;
|
||||
gboolean ok = TRUE;
|
||||
|
||||
priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (request->self);
|
||||
g_return_if_fail (priv->enabled);
|
||||
|
||||
/* We only handle requests for connection with @path if set. */
|
||||
if (!g_str_has_prefix (request->request_id, priv->path)) {
|
||||
gs_free_error GError *error = NULL;
|
||||
|
||||
error = g_error_new (NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_FAILED,
|
||||
"Request for %s secrets doesn't match path %s",
|
||||
request->request_id, priv->path);
|
||||
request->callback (NM_SECRET_AGENT_OLD (request->self), request->connection,
|
||||
NULL, error, request->callback_data);
|
||||
g_hash_table_remove (priv->requests, request->request_id);
|
||||
return;
|
||||
}
|
||||
|
||||
secrets = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_secret_agent_simple_secret_free);
|
||||
|
||||
if (nm_connection_is_type (request->connection, NM_SETTING_WIRELESS_SETTING_NAME)) {
|
||||
|
|
@ -455,19 +472,14 @@ request_secrets_from_ui (NMSecretAgentSimpleRequest *request)
|
|||
s_con = nm_connection_get_setting_connection (request->connection);
|
||||
|
||||
title = _("Wired 802.1X authentication");
|
||||
msg = NULL;
|
||||
msg = g_strdup_printf (_("Secrets are required to access the wired network '%s'"),
|
||||
nm_connection_get_id (request->connection));
|
||||
|
||||
secret = nm_secret_agent_simple_secret_new (_("Network name"),
|
||||
NM_SETTING (s_con),
|
||||
NM_SETTING_CONNECTION_ID,
|
||||
NULL,
|
||||
NULL,
|
||||
FALSE);
|
||||
g_ptr_array_add (secrets, secret);
|
||||
ok = add_8021x_secrets (request, secrets);
|
||||
} else if (nm_connection_is_type (request->connection, NM_SETTING_PPPOE_SETTING_NAME)) {
|
||||
title = _("DSL authentication");
|
||||
msg = NULL;
|
||||
msg = g_strdup_printf (_("Secrets are required for the DSL connection '%s'"),
|
||||
nm_connection_get_id (request->connection));
|
||||
|
||||
ok = add_pppoe_secrets (request, secrets);
|
||||
} else if (nm_connection_is_type (request->connection, NM_SETTING_GSM_SETTING_NAME)) {
|
||||
|
|
@ -739,11 +751,18 @@ nm_secret_agent_simple_enable (NMSecretAgentSimple *self, const char *path)
|
|||
{
|
||||
NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (self);
|
||||
GList *requests, *iter;
|
||||
GError *error;
|
||||
gs_free char *path_full = NULL;
|
||||
|
||||
if (g_strcmp0 (path, priv->path) != 0) {
|
||||
/* The path is only used to match a request_id with the current
|
||||
* connection. Since the request_id is "${CONNECTION_PATH}/${SETTING}",
|
||||
* add a trailing '/' to the path to match the full connection path.
|
||||
*/
|
||||
path_full = path ? g_strdup_printf ("%s/", path) : NULL;
|
||||
|
||||
if (g_strcmp0 (path_full, priv->path) != 0) {
|
||||
g_free (priv->path);
|
||||
priv->path = g_strdup (path);
|
||||
priv->path = path_full;
|
||||
path_full = NULL;
|
||||
}
|
||||
|
||||
if (priv->enabled)
|
||||
|
|
@ -752,21 +771,9 @@ nm_secret_agent_simple_enable (NMSecretAgentSimple *self, const char *path)
|
|||
|
||||
/* Service pending secret requests. */
|
||||
requests = g_hash_table_get_values (priv->requests);
|
||||
for (iter = requests; iter; iter = g_list_next (iter)) {
|
||||
NMSecretAgentSimpleRequest *request = iter->data;
|
||||
for (iter = requests; iter; iter = g_list_next (iter))
|
||||
request_secrets_from_ui (iter->data);
|
||||
|
||||
if (g_str_has_prefix (request->request_id, priv->path)) {
|
||||
request_secrets_from_ui (request);
|
||||
} else {
|
||||
/* We only handle requests for connection with @path if set. */
|
||||
error = g_error_new (NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_FAILED,
|
||||
"Request for %s secrets doesn't match path %s",
|
||||
request->request_id, priv->path);
|
||||
request->callback (NM_SECRET_AGENT_OLD (self), request->connection, NULL, error, request->callback_data);
|
||||
g_hash_table_remove (priv->requests, request->request_id);
|
||||
g_error_free (error);
|
||||
}
|
||||
}
|
||||
g_list_free (requests);
|
||||
}
|
||||
|
||||
|
|
@ -807,7 +814,7 @@ nm_secret_agent_simple_class_init (NMSecretAgentSimpleClass *klass)
|
|||
* When the dialog is complete, the app must call
|
||||
* nm_secret_agent_simple_response() with the results.
|
||||
*/
|
||||
signals[REQUEST_SECRETS] = g_signal_new ("request-secrets",
|
||||
signals[REQUEST_SECRETS] = g_signal_new (NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS,
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
0, 0, NULL, NULL, NULL,
|
||||
G_TYPE_NONE,
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@
|
|||
#define NM_IS_SECRET_AGENT_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SECRET_AGENT_SIMPLE))
|
||||
#define NM_SECRET_AGENT_SIMPLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimpleClass))
|
||||
|
||||
/* Signals */
|
||||
#define NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS "request-secrets"
|
||||
|
||||
typedef struct {
|
||||
NMSecretAgentOld parent;
|
||||
|
||||
|
|
|
|||
|
|
@ -239,7 +239,10 @@ activate_connection (NMConnection *connection,
|
|||
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (agent),
|
||||
nm_object_get_path (NM_OBJECT (connection)));
|
||||
}
|
||||
g_signal_connect (agent, "request-secrets", G_CALLBACK (secrets_requested), connection);
|
||||
g_signal_connect (agent,
|
||||
NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS,
|
||||
G_CALLBACK (secrets_requested),
|
||||
connection);
|
||||
}
|
||||
|
||||
specific_object_path = specific_object ? nm_object_get_path (specific_object) : NULL;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue