2014-07-24 08:53:33 -04:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
|
|
|
|
/*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
|
* Boston, MA 02110-1301 USA.
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2010 - 2011 Red Hat, Inc.
|
|
|
|
|
*/
|
|
|
|
|
|
all: fix up multiple-include-guard defines
Previously, src/nm-ip4-config.h, libnm/nm-ip4-config.h, and
libnm-glib/nm-ip4-config.h all used "NM_IP4_CONFIG_H" as an include
guard, which meant that nm-test-utils.h could not tell which of them
was being included (and so, eg, if you tried to include
nm-ip4-config.h in a libnm test, it would fail to compile because
nm-test-utils.h was referring to symbols in src/nm-ip4-config.h).
Fix this by changing the include guards in the non-API-stable parts of
the tree:
- libnm-glib/nm-ip4-config.h remains NM_IP4_CONFIG_H
- libnm/nm-ip4-config.h now uses __NM_IP4_CONFIG_H__
- src/nm-ip4-config.h now uses __NETWORKMANAGER_IP4_CONFIG_H__
And likewise for all other headers.
The two non-"nm"-prefixed headers, libnm/NetworkManager.h and
src/NetworkManagerUtils.h are now __NETWORKMANAGER_H__ and
__NETWORKMANAGER_UTILS_H__ respectively, which, while not entirely
consistent with the general scheme, do still mostly make sense in
isolation.
2014-08-13 14:10:11 -04:00
|
|
|
#ifndef __NM_SECRET_AGENT_H__
|
|
|
|
|
#define __NM_SECRET_AGENT_H__
|
2014-07-24 08:53:33 -04:00
|
|
|
|
2014-07-06 16:53:02 -04:00
|
|
|
#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION)
|
|
|
|
|
#error "Only <NetworkManager.h> can be included directly."
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-09-02 21:41:05 -04:00
|
|
|
#include <gio/gio.h>
|
2014-07-24 08:53:33 -04:00
|
|
|
#include <nm-connection.h>
|
|
|
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
|
|
|
|
|
#define NM_SECRET_AGENT_ERROR (nm_secret_agent_error_quark ())
|
|
|
|
|
|
|
|
|
|
GQuark nm_secret_agent_error_quark (void);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* NMSecretAgentError:
|
|
|
|
|
* @NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED: the caller (ie, NetworkManager) is not
|
|
|
|
|
* authorized to make this request
|
|
|
|
|
* @NM_SECRET_AGENT_ERROR_INVALID_CONNECTION: the connection for which secrets
|
|
|
|
|
* were requested could not be found
|
|
|
|
|
* @NM_SECRET_AGENT_ERROR_USER_CANCELED: the request was canceled by the user
|
|
|
|
|
* @NM_SECRET_AGENT_ERROR_AGENT_CANCELED: the agent canceled the request
|
|
|
|
|
* because it was requested to do so by NetworkManager
|
|
|
|
|
* @NM_SECRET_AGENT_ERROR_INTERNAL_ERROR: some internal error in the agent caused
|
|
|
|
|
* the request to fail
|
|
|
|
|
* @NM_SECRET_AGENT_ERROR_NO_SECRETS: the agent cannot find any secrets for this
|
|
|
|
|
* connection
|
|
|
|
|
*
|
|
|
|
|
* #NMSecretAgentError values are passed by secret agents back to NetworkManager
|
|
|
|
|
* when they encounter problems retrieving secrets on behalf of NM.
|
|
|
|
|
*/
|
|
|
|
|
typedef enum {
|
|
|
|
|
NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED = 0, /*< nick=NotAuthorized >*/
|
|
|
|
|
NM_SECRET_AGENT_ERROR_INVALID_CONNECTION, /*< nick=InvalidConnection >*/
|
|
|
|
|
NM_SECRET_AGENT_ERROR_USER_CANCELED, /*< nick=UserCanceled >*/
|
|
|
|
|
NM_SECRET_AGENT_ERROR_AGENT_CANCELED, /*< nick=AgentCanceled >*/
|
|
|
|
|
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR, /*< nick=InternalError >*/
|
|
|
|
|
NM_SECRET_AGENT_ERROR_NO_SECRETS, /*< nick=NoSecrets >*/
|
|
|
|
|
} NMSecretAgentError;
|
|
|
|
|
|
|
|
|
|
#define NM_TYPE_SECRET_AGENT (nm_secret_agent_get_type ())
|
|
|
|
|
#define NM_SECRET_AGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SECRET_AGENT, NMSecretAgent))
|
|
|
|
|
#define NM_SECRET_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SECRET_AGENT, NMSecretAgentClass))
|
|
|
|
|
#define NM_IS_SECRET_AGENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SECRET_AGENT))
|
|
|
|
|
#define NM_IS_SECRET_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SECRET_AGENT))
|
|
|
|
|
#define NM_SECRET_AGENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SECRET_AGENT, NMSecretAgentClass))
|
|
|
|
|
|
|
|
|
|
#define NM_SECRET_AGENT_IDENTIFIER "identifier"
|
|
|
|
|
#define NM_SECRET_AGENT_AUTO_REGISTER "auto-register"
|
|
|
|
|
#define NM_SECRET_AGENT_REGISTERED "registered"
|
|
|
|
|
#define NM_SECRET_AGENT_CAPABILITIES "capabilities"
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
GObject parent;
|
|
|
|
|
} NMSecretAgent;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* NMSecretAgentGetSecretsFunc:
|
|
|
|
|
* @agent: the secret agent object
|
|
|
|
|
* @connection: (transfer none): the connection for which secrets were requested,
|
|
|
|
|
* note that this object will be unrefed after the callback has returned, use
|
|
|
|
|
* g_object_ref()/g_object_unref() if you want to use this object after the callback
|
|
|
|
|
* has returned
|
2014-08-16 10:09:48 -04:00
|
|
|
* @secrets: the #GVariant of type %NM_VARIANT_TYPE_CONNECTION containing the requested
|
|
|
|
|
* secrets (as created by nm_connection_to_dbus() for example). Each key in @secrets
|
2014-07-24 08:53:33 -04:00
|
|
|
* should be the name of a #NMSetting object (like "802-11-wireless-security")
|
2014-08-16 10:09:48 -04:00
|
|
|
* and each value should be an %NM_VARIANT_TYPE_SETTING variant. The sub-dicts
|
|
|
|
|
* map string:value, where the string is the setting property name (like "psk")
|
|
|
|
|
* and the value is the secret
|
2014-07-24 08:53:33 -04:00
|
|
|
* @error: if the secrets request failed, give a descriptive error here
|
|
|
|
|
* @user_data: caller-specific data to be passed to the function
|
|
|
|
|
*
|
|
|
|
|
* Called as a result of a request by NM to retrieve secrets. When the
|
|
|
|
|
* #NMSecretAgent subclass has finished retrieving secrets and is ready to
|
|
|
|
|
* return them, or to return an error, this function should be called with
|
|
|
|
|
* those secrets or the error.
|
|
|
|
|
*
|
2014-08-16 10:09:48 -04:00
|
|
|
* To easily create the dictionary to return the Wi-Fi PSK, you could do
|
2014-07-24 08:53:33 -04:00
|
|
|
* something like this:
|
|
|
|
|
* <example>
|
2014-08-16 10:09:48 -04:00
|
|
|
* <title>Creating a secrets dictionary</title>
|
2014-07-24 08:53:33 -04:00
|
|
|
* <programlisting>
|
|
|
|
|
* NMConnection *secrets;
|
|
|
|
|
* NMSettingWirelessSecurity *s_wsec;
|
2014-08-16 10:09:48 -04:00
|
|
|
* GVariant *secrets_dict;
|
2014-07-24 08:53:33 -04:00
|
|
|
*
|
|
|
|
|
* secrets = nm_connection_new ();
|
|
|
|
|
* s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
|
|
|
|
|
* g_object_set (G_OBJECT (s_wsec),
|
|
|
|
|
* NM_SETTING_WIRELESS_SECURITY_PSK, "my really cool PSK",
|
|
|
|
|
* NULL);
|
|
|
|
|
* nm_connection_add_setting (secrets, NM_SETTING (s_wsec));
|
2014-08-16 10:09:48 -04:00
|
|
|
* secrets_dict = nm_connection_to_dbus (secrets, NM_CONNECTION_SERIALIZE_ALL);
|
2014-07-24 08:53:33 -04:00
|
|
|
*
|
2014-08-16 10:09:48 -04:00
|
|
|
* (call the NMSecretAgentGetSecretsFunc with secrets_dict)
|
2014-07-24 08:53:33 -04:00
|
|
|
*
|
|
|
|
|
* g_object_unref (secrets);
|
2014-08-16 10:09:48 -04:00
|
|
|
* g_variant_unref (secrets_dict);
|
2014-07-24 08:53:33 -04:00
|
|
|
* </programlisting>
|
|
|
|
|
* </example>
|
|
|
|
|
*/
|
|
|
|
|
typedef void (*NMSecretAgentGetSecretsFunc) (NMSecretAgent *agent,
|
|
|
|
|
NMConnection *connection,
|
2014-08-16 10:09:48 -04:00
|
|
|
GVariant *secrets,
|
2014-07-24 08:53:33 -04:00
|
|
|
GError *error,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* NMSecretAgentSaveSecretsFunc:
|
|
|
|
|
* @agent: the secret agent object
|
|
|
|
|
* @connection: (transfer none): the connection for which secrets were to be saved,
|
|
|
|
|
* note that this object will be unrefed after the callback has returned, use
|
|
|
|
|
* g_object_ref()/g_object_unref() if you want to use this object after the callback
|
|
|
|
|
* has returned
|
|
|
|
|
* @error: if the saving secrets failed, give a descriptive error here
|
|
|
|
|
* @user_data: caller-specific data to be passed to the function
|
|
|
|
|
*
|
|
|
|
|
* Called as a result of a request by NM to save secrets. When the
|
|
|
|
|
* #NMSecretAgent subclass has finished saving the secrets, this function
|
|
|
|
|
* should be called.
|
|
|
|
|
*/
|
|
|
|
|
typedef void (*NMSecretAgentSaveSecretsFunc) (NMSecretAgent *agent,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
GError *error,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* NMSecretAgentDeleteSecretsFunc:
|
|
|
|
|
* @agent: the secret agent object
|
|
|
|
|
* @connection: (transfer none): the connection for which secrets were to be deleted,
|
|
|
|
|
* note that this object will be unrefed after the callback has returned, use
|
|
|
|
|
* g_object_ref()/g_object_unref() if you want to use this object after the callback
|
|
|
|
|
* has returned
|
|
|
|
|
* @error: if the deleting secrets failed, give a descriptive error here
|
|
|
|
|
* @user_data: caller-specific data to be passed to the function
|
|
|
|
|
*
|
|
|
|
|
* Called as a result of a request by NM to delete secrets. When the
|
|
|
|
|
* #NMSecretAgent subclass has finished deleting the secrets, this function
|
|
|
|
|
* should be called.
|
|
|
|
|
*/
|
|
|
|
|
typedef void (*NMSecretAgentDeleteSecretsFunc) (NMSecretAgent *agent,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
GError *error,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
GObjectClass parent;
|
|
|
|
|
|
|
|
|
|
/* Virtual methods for subclasses */
|
|
|
|
|
|
|
|
|
|
/* Called when the subclass should retrieve and return secrets. Subclass
|
|
|
|
|
* must copy or reference any arguments it may require after returning from
|
|
|
|
|
* this method, as the arguments will freed (except for 'self', 'callback',
|
|
|
|
|
* and 'user_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 *self,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
const char *connection_path,
|
|
|
|
|
const char *setting_name,
|
|
|
|
|
const char **hints,
|
|
|
|
|
NMSecretAgentGetSecretsFlags flags,
|
|
|
|
|
NMSecretAgentGetSecretsFunc callback,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
|
|
/* Called when the subclass should cancel an outstanding request to
|
|
|
|
|
* get secrets for a given connection. Canceling the request MUST
|
|
|
|
|
* call the callback that was passed along with the initial get_secrets
|
|
|
|
|
* call, sending the NM_SECRET_AGENT_ERROR/NM_SECRET_AGENT_ERROR_AGENT_CANCELED
|
|
|
|
|
* error to that callback.
|
|
|
|
|
*/
|
|
|
|
|
void (*cancel_get_secrets) (NMSecretAgent *self,
|
|
|
|
|
const char *connection_path,
|
|
|
|
|
const char *setting_name);
|
|
|
|
|
|
|
|
|
|
/* Called when the subclass should save the secrets contained in the
|
|
|
|
|
* connection to backing storage. Subclass must copy or reference any
|
|
|
|
|
* arguments it may require after returning from this method, as the
|
|
|
|
|
* arguments will freed (except for 'self', 'callback', and 'user_data'
|
|
|
|
|
* of course).
|
|
|
|
|
*/
|
|
|
|
|
void (*save_secrets) (NMSecretAgent *self,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
const char *connection_path,
|
|
|
|
|
NMSecretAgentSaveSecretsFunc callback,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
|
|
/* Called when the subclass should delete the secrets contained in the
|
|
|
|
|
* connection from backing storage. Subclass must copy or reference any
|
|
|
|
|
* arguments it may require after returning from this method, as the
|
|
|
|
|
* arguments will freed (except for 'self', 'callback', and 'user_data'
|
|
|
|
|
* of course).
|
|
|
|
|
*/
|
|
|
|
|
void (*delete_secrets) (NMSecretAgent *self,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
const char *connection_path,
|
|
|
|
|
NMSecretAgentDeleteSecretsFunc callback,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
2014-05-15 09:55:18 -04:00
|
|
|
/*< private >*/
|
|
|
|
|
gpointer padding[8];
|
2014-07-24 08:53:33 -04:00
|
|
|
} NMSecretAgentClass;
|
|
|
|
|
|
|
|
|
|
GType nm_secret_agent_get_type (void);
|
|
|
|
|
|
2014-09-02 21:41:05 -04:00
|
|
|
gboolean nm_secret_agent_register (NMSecretAgent *self,
|
|
|
|
|
GCancellable *cancellable,
|
|
|
|
|
GError **error);
|
|
|
|
|
void nm_secret_agent_register_async (NMSecretAgent *self,
|
|
|
|
|
GCancellable *cancellable,
|
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
gboolean nm_secret_agent_register_finish (NMSecretAgent *self,
|
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
GError **error);
|
|
|
|
|
|
|
|
|
|
gboolean nm_secret_agent_unregister (NMSecretAgent *self,
|
|
|
|
|
GCancellable *cancellable,
|
|
|
|
|
GError **error);
|
|
|
|
|
void nm_secret_agent_unregister_async (NMSecretAgent *self,
|
|
|
|
|
GCancellable *cancellable,
|
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
gboolean nm_secret_agent_unregister_finish (NMSecretAgent *self,
|
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
GError **error);
|
2014-07-24 08:53:33 -04:00
|
|
|
|
|
|
|
|
gboolean nm_secret_agent_get_registered (NMSecretAgent *self);
|
|
|
|
|
|
|
|
|
|
void nm_secret_agent_get_secrets (NMSecretAgent *self,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
const char *setting_name,
|
|
|
|
|
const char **hints,
|
|
|
|
|
NMSecretAgentGetSecretsFlags flags,
|
|
|
|
|
NMSecretAgentGetSecretsFunc callback,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
|
|
void nm_secret_agent_save_secrets (NMSecretAgent *self,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
NMSecretAgentSaveSecretsFunc callback,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
|
|
void nm_secret_agent_delete_secrets (NMSecretAgent *self,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
NMSecretAgentDeleteSecretsFunc callback,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
|
|
G_END_DECLS
|
|
|
|
|
|
all: fix up multiple-include-guard defines
Previously, src/nm-ip4-config.h, libnm/nm-ip4-config.h, and
libnm-glib/nm-ip4-config.h all used "NM_IP4_CONFIG_H" as an include
guard, which meant that nm-test-utils.h could not tell which of them
was being included (and so, eg, if you tried to include
nm-ip4-config.h in a libnm test, it would fail to compile because
nm-test-utils.h was referring to symbols in src/nm-ip4-config.h).
Fix this by changing the include guards in the non-API-stable parts of
the tree:
- libnm-glib/nm-ip4-config.h remains NM_IP4_CONFIG_H
- libnm/nm-ip4-config.h now uses __NM_IP4_CONFIG_H__
- src/nm-ip4-config.h now uses __NETWORKMANAGER_IP4_CONFIG_H__
And likewise for all other headers.
The two non-"nm"-prefixed headers, libnm/NetworkManager.h and
src/NetworkManagerUtils.h are now __NETWORKMANAGER_H__ and
__NETWORKMANAGER_UTILS_H__ respectively, which, while not entirely
consistent with the general scheme, do still mostly make sense in
isolation.
2014-08-13 14:10:11 -04:00
|
|
|
#endif /* __NM_SECRET_AGENT_H__ */
|