mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-07 03:48:09 +02:00
libnm-glib: implement agent secrets request cancelation
This commit is contained in:
parent
a2f36e8bd4
commit
30c7308e9d
2 changed files with 61 additions and 25 deletions
|
|
@ -36,6 +36,11 @@ static void impl_secret_agent_get_secrets (NMSecretAgent *self,
|
||||||
gboolean request_new,
|
gboolean request_new,
|
||||||
DBusGMethodInvocation *context);
|
DBusGMethodInvocation *context);
|
||||||
|
|
||||||
|
static void impl_secret_agent_cancel_get_secrets (NMSecretAgent *self,
|
||||||
|
const char *connection_path,
|
||||||
|
const char *setting_name,
|
||||||
|
DBusGMethodInvocation *context);
|
||||||
|
|
||||||
static void impl_secret_agent_save_secrets (NMSecretAgent *self,
|
static void impl_secret_agent_save_secrets (NMSecretAgent *self,
|
||||||
GHashTable *connection_hash,
|
GHashTable *connection_hash,
|
||||||
const char *connection_path,
|
const char *connection_path,
|
||||||
|
|
@ -166,10 +171,12 @@ name_owner_changed (DBusGProxy *proxy,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static NMConnection *
|
static gboolean
|
||||||
verify_request (NMSecretAgent *self,
|
verify_request (NMSecretAgent *self,
|
||||||
DBusGMethodInvocation *context,
|
DBusGMethodInvocation *context,
|
||||||
GHashTable *connection_hash,
|
GHashTable *connection_hash,
|
||||||
|
const char *connection_path,
|
||||||
|
NMConnection **out_connection,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
|
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
|
||||||
|
|
@ -181,8 +188,7 @@ verify_request (NMSecretAgent *self,
|
||||||
uid_t sender_uid = G_MAXUINT;
|
uid_t sender_uid = G_MAXUINT;
|
||||||
GError *local = NULL;
|
GError *local = NULL;
|
||||||
|
|
||||||
g_return_val_if_fail (context != NULL, NULL);
|
g_return_val_if_fail (context != NULL, FALSE);
|
||||||
g_return_val_if_fail (connection_hash != NULL, NULL);
|
|
||||||
|
|
||||||
/* Verify the sender's UID is 0, and that the sender is the same as
|
/* Verify the sender's UID is 0, and that the sender is the same as
|
||||||
* NetworkManager's bus name owner.
|
* NetworkManager's bus name owner.
|
||||||
|
|
@ -245,21 +251,27 @@ verify_request (NMSecretAgent *self,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* And make sure the connection is actually valid */
|
/* And make sure the connection is actually valid */
|
||||||
connection = nm_connection_new_from_hash (connection_hash, &local);
|
if (connection_hash) {
|
||||||
if (!connection) {
|
connection = nm_connection_new_from_hash (connection_hash, &local);
|
||||||
g_set_error (error,
|
if (connection && connection_path) {
|
||||||
NM_SECRET_AGENT_ERROR,
|
nm_connection_set_path (connection, connection_path);
|
||||||
NM_SECRET_AGENT_ERROR_INVALID_CONNECTION,
|
} else {
|
||||||
"Invalid connection: (%d) %s",
|
g_set_error (error,
|
||||||
local ? local->code : -1,
|
NM_SECRET_AGENT_ERROR,
|
||||||
(local && local->message) ? local->message : "(unknown)");
|
NM_SECRET_AGENT_ERROR_INVALID_CONNECTION,
|
||||||
g_clear_error (&local);
|
"Invalid connection: (%d) %s",
|
||||||
|
local ? local->code : -1,
|
||||||
|
(local && local->message) ? local->message : "(unknown)");
|
||||||
|
g_clear_error (&local);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
if (out_connection)
|
||||||
|
*out_connection = connection;
|
||||||
g_free (sender);
|
g_free (sender);
|
||||||
return connection;
|
|
||||||
|
return !!connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -287,11 +299,10 @@ impl_secret_agent_get_secrets (NMSecretAgent *self,
|
||||||
DBusGMethodInvocation *context)
|
DBusGMethodInvocation *context)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
NMConnection *connection;
|
NMConnection *connection = NULL;
|
||||||
|
|
||||||
/* Make sure the request comes from NetworkManager and is valid */
|
/* Make sure the request comes from NetworkManager and is valid */
|
||||||
connection = verify_request (self, context, connection_hash, &error);
|
if (!verify_request (self, context, connection_hash, connection_path, &connection, &error)) {
|
||||||
if (!connection) {
|
|
||||||
dbus_g_method_return_error (context, error);
|
dbus_g_method_return_error (context, error);
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
return;
|
return;
|
||||||
|
|
@ -308,6 +319,24 @@ impl_secret_agent_get_secrets (NMSecretAgent *self,
|
||||||
g_object_unref (connection);
|
g_object_unref (connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
impl_secret_agent_cancel_get_secrets (NMSecretAgent *self,
|
||||||
|
const char *connection_path,
|
||||||
|
const char *setting_name,
|
||||||
|
DBusGMethodInvocation *context)
|
||||||
|
{
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
/* Make sure the request comes from NetworkManager and is valid */
|
||||||
|
if (!verify_request (self, context, NULL, NULL, NULL, &error)) {
|
||||||
|
dbus_g_method_return_error (context, error);
|
||||||
|
g_clear_error (&error);
|
||||||
|
} else {
|
||||||
|
NM_SECRET_AGENT_GET_CLASS (self)->cancel_get_secrets (self, connection_path, setting_name);
|
||||||
|
dbus_g_method_return (context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
save_secrets_cb (NMSecretAgent *self,
|
save_secrets_cb (NMSecretAgent *self,
|
||||||
NMConnection *connection,
|
NMConnection *connection,
|
||||||
|
|
@ -329,11 +358,10 @@ impl_secret_agent_save_secrets (NMSecretAgent *self,
|
||||||
DBusGMethodInvocation *context)
|
DBusGMethodInvocation *context)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
NMConnection *connection;
|
NMConnection *connection = NULL;
|
||||||
|
|
||||||
/* Make sure the request comes from NetworkManager and is valid */
|
/* Make sure the request comes from NetworkManager and is valid */
|
||||||
connection = verify_request (self, context, connection_hash, &error);
|
if (!verify_request (self, context, connection_hash, connection_path, &connection, &error)) {
|
||||||
if (!connection) {
|
|
||||||
dbus_g_method_return_error (context, error);
|
dbus_g_method_return_error (context, error);
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
return;
|
return;
|
||||||
|
|
@ -368,11 +396,10 @@ impl_secret_agent_delete_secrets (NMSecretAgent *self,
|
||||||
DBusGMethodInvocation *context)
|
DBusGMethodInvocation *context)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
NMConnection *connection;
|
NMConnection *connection = NULL;
|
||||||
|
|
||||||
/* Make sure the request comes from NetworkManager and is valid */
|
/* Make sure the request comes from NetworkManager and is valid */
|
||||||
connection = verify_request (self, context, connection_hash, &error);
|
if (!verify_request (self, context, connection_hash, connection_path, &connection, &error)) {
|
||||||
if (!connection) {
|
|
||||||
dbus_g_method_return_error (context, error);
|
dbus_g_method_return_error (context, error);
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
* Boston, MA 02110-1301 USA.
|
* Boston, MA 02110-1301 USA.
|
||||||
*
|
*
|
||||||
* (C) Copyright 2010 Red Hat, Inc.
|
* (C) Copyright 2010 - 2011 Red Hat, Inc.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef NM_SECRET_AGENT_H
|
#ifndef NM_SECRET_AGENT_H
|
||||||
|
|
@ -80,7 +80,9 @@ typedef struct {
|
||||||
/* Called when the subclass should retrieve and return secrets. Subclass
|
/* Called when the subclass should retrieve and return secrets. Subclass
|
||||||
* must copy or reference any arguments it may require after returning from
|
* must copy or reference any arguments it may require after returning from
|
||||||
* this method, as the arguments will freed (except for 'agent', 'callback',
|
* this method, as the arguments will freed (except for 'agent', 'callback',
|
||||||
* and 'callback_data' of course).
|
* and 'callback_data' of course). If the request is canceled, the callback
|
||||||
|
* should still be called, but with the NM_SECRET_AGENT_ERROR_AGENT_CANCELED
|
||||||
|
* error.
|
||||||
*/
|
*/
|
||||||
void (*get_secrets) (NMSecretAgent *agent,
|
void (*get_secrets) (NMSecretAgent *agent,
|
||||||
NMConnection *connection,
|
NMConnection *connection,
|
||||||
|
|
@ -91,6 +93,13 @@ typedef struct {
|
||||||
NMSecretAgentGetSecretsFunc callback,
|
NMSecretAgentGetSecretsFunc callback,
|
||||||
gpointer callback_data);
|
gpointer callback_data);
|
||||||
|
|
||||||
|
/* Called when the subclass should cancel an outstanding request to
|
||||||
|
* get secrets for a given connection.
|
||||||
|
*/
|
||||||
|
void (*cancel_get_secrets) (NMSecretAgent *agent,
|
||||||
|
const char *connection_path,
|
||||||
|
const char *setting_name);
|
||||||
|
|
||||||
/* Called when the subclass should save the secrets contained in the
|
/* Called when the subclass should save the secrets contained in the
|
||||||
* connection to backing storage. Subclass must copy or reference any
|
* connection to backing storage. Subclass must copy or reference any
|
||||||
* arguments it may require after returning from this method, as the
|
* arguments it may require after returning from this method, as the
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue