core: add nm-secrets-flags.h for secret agent flags typedef

Make it clearer what's going on instead of using flags here and there
and numbers elsewhere.
This commit is contained in:
Dan Williams
2011-03-29 22:53:22 -05:00
parent ee259ff79a
commit 4e4bfeb499
15 changed files with 72 additions and 40 deletions

View File

@@ -5,7 +5,8 @@ EXTRA_DIST = \
nm-dbus-glib-types.h \ nm-dbus-glib-types.h \
nm-glib-compat.h \ nm-glib-compat.h \
nm-test-helpers.h \ nm-test-helpers.h \
nm-version.h.in nm-version.h.in \
nm-settings-flags.h
NetworkManagerincludedir=$(includedir)/NetworkManager NetworkManagerincludedir=$(includedir)/NetworkManager

View File

@@ -0,0 +1,34 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2011 Red Hat, Inc.
*/
#ifndef NM_SETTINGS_FLAGS_H
#define NM_SETTINGS_FLAGS_H
/* NOTE: these values should match the NM_SECRET_AGENT_GET_SECRETS_FLAGS in
* the nm-secret-agent.xml introspection file.
*/
typedef enum {
NM_SETTINGS_GET_SECRETS_FLAG_NONE = 0x0,
NM_SETTINGS_GET_SECRETS_FLAG_ALLOW_INTERACTION = 0x1,
NM_SETTINGS_GET_SECRETS_FLAG_REQUEST_NEW = 0x2
} NMSettingsGetSecretsFlags;
#endif /* NM_SETTINGS_FLAGS_H */

View File

@@ -514,12 +514,12 @@ nm_modem_get_secrets (NMModem *self,
const char *hint) const char *hint)
{ {
NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self); NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self);
guint32 flags = NM_ACT_REQUEST_GET_SECRETS_FLAG_ALLOW_INTERACTION; NMSettingsGetSecretsFlags flags = NM_SETTINGS_GET_SECRETS_FLAG_ALLOW_INTERACTION;
cancel_get_secrets (self); cancel_get_secrets (self);
if (request_new) if (request_new)
flags |= NM_ACT_REQUEST_GET_SECRETS_FLAG_REQUEST_NEW; flags |= NM_SETTINGS_GET_SECRETS_FLAG_REQUEST_NEW;
priv->secrets_id = nm_act_request_get_secrets (priv->act_request, priv->secrets_id = nm_act_request_get_secrets (priv->act_request,
setting_name, setting_name,
flags, flags,
@@ -552,7 +552,7 @@ nm_modem_act_stage1_prepare (NMModem *self,
NMActStageReturn ret; NMActStageReturn ret;
GPtrArray *hints = NULL; GPtrArray *hints = NULL;
const char *setting_name = NULL; const char *setting_name = NULL;
guint32 flags = NM_ACT_REQUEST_GET_SECRETS_FLAG_ALLOW_INTERACTION; NMSettingsGetSecretsFlags flags = NM_SETTINGS_GET_SECRETS_FLAG_ALLOW_INTERACTION;
if (priv->act_request) if (priv->act_request)
g_object_unref (priv->act_request); g_object_unref (priv->act_request);
@@ -565,7 +565,7 @@ nm_modem_act_stage1_prepare (NMModem *self,
reason); reason);
if ((ret == NM_ACT_STAGE_RETURN_POSTPONE) && setting_name) { if ((ret == NM_ACT_STAGE_RETURN_POSTPONE) && setting_name) {
if (priv->secrets_tries++) if (priv->secrets_tries++)
flags |= NM_ACT_REQUEST_GET_SECRETS_FLAG_REQUEST_NEW; flags |= NM_SETTINGS_GET_SECRETS_FLAG_REQUEST_NEW;
priv->secrets_id = nm_act_request_get_secrets (req, priv->secrets_id = nm_act_request_get_secrets (req,
setting_name, setting_name,

View File

@@ -123,7 +123,7 @@ get_secrets_cb (NMSettingsConnection *connection,
guint32 guint32
nm_act_request_get_secrets (NMActRequest *self, nm_act_request_get_secrets (NMActRequest *self,
const char *setting_name, const char *setting_name,
guint32 flags, NMSettingsGetSecretsFlags flags,
const char *hint, const char *hint,
NMActRequestSecretsFunc callback, NMActRequestSecretsFunc callback,
gpointer callback_data) gpointer callback_data)

View File

@@ -25,6 +25,7 @@
#include <glib-object.h> #include <glib-object.h>
#include "nm-connection.h" #include "nm-connection.h"
#include "nm-active-connection.h" #include "nm-active-connection.h"
#include "nm-settings-flags.h"
#define NM_TYPE_ACT_REQUEST (nm_act_request_get_type ()) #define NM_TYPE_ACT_REQUEST (nm_act_request_get_type ())
#define NM_ACT_REQUEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_ACT_REQUEST, NMActRequest)) #define NM_ACT_REQUEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_ACT_REQUEST, NMActRequest))
@@ -91,18 +92,9 @@ typedef void (*NMActRequestSecretsFunc) (NMActRequest *req,
GError *error, GError *error,
gpointer user_data); gpointer user_data);
/* NOTE: these values should match the NM_SECRET_AGENT_GET_SECRETS_FLAGS in
* the nm-secret-agent.xml introspection file.
*/
enum {
NM_ACT_REQUEST_GET_SECRETS_FLAG_NONE = 0x0,
NM_ACT_REQUEST_GET_SECRETS_FLAG_ALLOW_INTERACTION = 0x1,
NM_ACT_REQUEST_GET_SECRETS_FLAG_REQUEST_NEW = 0x2
};
guint32 nm_act_request_get_secrets (NMActRequest *req, guint32 nm_act_request_get_secrets (NMActRequest *req,
const char *setting_name, const char *setting_name,
guint32 flags, NMSettingsGetSecretsFlags flags,
const char *hint, const char *hint,
NMActRequestSecretsFunc callback, NMActRequestSecretsFunc callback,
gpointer callback_data); gpointer callback_data);

View File

@@ -1055,7 +1055,7 @@ link_timeout_cb (gpointer user_data)
nm_device_state_changed (dev, NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT); nm_device_state_changed (dev, NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT);
nm_act_request_get_secrets (req, nm_act_request_get_secrets (req,
setting_name, setting_name,
NM_ACT_REQUEST_GET_SECRETS_FLAG_REQUEST_NEW, NM_SETTINGS_GET_SECRETS_FLAG_REQUEST_NEW,
NULL, NULL,
wired_secrets_cb, wired_secrets_cb,
self); self);
@@ -1236,13 +1236,13 @@ handle_auth_or_fail (NMDeviceEthernet *self,
nm_connection_clear_secrets (connection); nm_connection_clear_secrets (connection);
setting_name = nm_connection_need_secrets (connection, NULL); setting_name = nm_connection_need_secrets (connection, NULL);
if (setting_name) { if (setting_name) {
guint32 flags = NM_ACT_REQUEST_GET_SECRETS_FLAG_ALLOW_INTERACTION; NMSettingsGetSecretsFlags flags = NM_SETTINGS_GET_SECRETS_FLAG_ALLOW_INTERACTION;
/* If the caller doesn't necessarily want completely new secrets, /* If the caller doesn't necessarily want completely new secrets,
* only ask for new secrets after the first failure. * only ask for new secrets after the first failure.
*/ */
if (new_secrets || tries) if (new_secrets || tries)
flags |= NM_ACT_REQUEST_GET_SECRETS_FLAG_REQUEST_NEW; flags |= NM_SETTINGS_GET_SECRETS_FLAG_REQUEST_NEW;
nm_act_request_get_secrets (req, setting_name, flags, NULL, wired_secrets_cb, self); nm_act_request_get_secrets (req, setting_name, flags, NULL, wired_secrets_cb, self);
g_object_set_data (G_OBJECT (connection), WIRED_SECRETS_TRIES, GUINT_TO_POINTER (++tries)); g_object_set_data (G_OBJECT (connection), WIRED_SECRETS_TRIES, GUINT_TO_POINTER (++tries));

View File

@@ -2489,7 +2489,7 @@ link_timeout_cb (gpointer user_data)
nm_device_state_changed (dev, NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT); nm_device_state_changed (dev, NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT);
nm_act_request_get_secrets (req, nm_act_request_get_secrets (req,
setting_name, setting_name,
NM_ACT_REQUEST_GET_SECRETS_FLAG_REQUEST_NEW, NM_SETTINGS_GET_SECRETS_FLAG_REQUEST_NEW,
NULL, NULL,
wifi_secrets_cb, wifi_secrets_cb,
self); self);
@@ -2728,13 +2728,14 @@ handle_auth_or_fail (NMDeviceWifi *self,
nm_connection_clear_secrets (connection); nm_connection_clear_secrets (connection);
setting_name = nm_connection_need_secrets (connection, NULL); setting_name = nm_connection_need_secrets (connection, NULL);
if (setting_name) { if (setting_name) {
guint32 flags = NM_ACT_REQUEST_GET_SECRETS_FLAG_ALLOW_INTERACTION; NMSettingsGetSecretsFlags flags = NM_SETTINGS_GET_SECRETS_FLAG_ALLOW_INTERACTION;
/* If the caller doesn't necessarily want completely new secrets, /* If the caller doesn't necessarily want completely new secrets,
* only ask for new secrets after the first failure. * only ask for new secrets after the first failure.
*/ */
g_message ("%s: new secrets %d, tries %d", __func__, new_secrets, tries);
if (new_secrets || tries) if (new_secrets || tries)
flags |= NM_ACT_REQUEST_GET_SECRETS_FLAG_REQUEST_NEW; flags |= NM_SETTINGS_GET_SECRETS_FLAG_REQUEST_NEW;
nm_act_request_get_secrets (req, setting_name, flags, NULL, wifi_secrets_cb, self); nm_act_request_get_secrets (req, setting_name, flags, NULL, wifi_secrets_cb, self);
g_object_set_data (G_OBJECT (connection), WIRELESS_SECRETS_TRIES, GUINT_TO_POINTER (++tries)); g_object_set_data (G_OBJECT (connection), WIRELESS_SECRETS_TRIES, GUINT_TO_POINTER (++tries));

View File

@@ -442,7 +442,7 @@ impl_ppp_manager_need_secrets (NMPPPManager *manager,
guint32 tries; guint32 tries;
GPtrArray *hints = NULL; GPtrArray *hints = NULL;
GError *error = NULL; GError *error = NULL;
guint32 flags = NM_ACT_REQUEST_GET_SECRETS_FLAG_ALLOW_INTERACTION; NMSettingsGetSecretsFlags flags = NM_SETTINGS_GET_SECRETS_FLAG_ALLOW_INTERACTION;
connection = nm_act_request_get_connection (priv->act_req); connection = nm_act_request_get_connection (priv->act_req);
@@ -468,7 +468,7 @@ impl_ppp_manager_need_secrets (NMPPPManager *manager,
*/ */
tries = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (connection), PPP_MANAGER_SECRET_TRIES)); tries = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (connection), PPP_MANAGER_SECRET_TRIES));
if (tries > 1) if (tries > 1)
flags |= NM_ACT_REQUEST_GET_SECRETS_FLAG_REQUEST_NEW; flags |= NM_SETTINGS_GET_SECRETS_FLAG_REQUEST_NEW;
priv->secrets_id = nm_act_request_get_secrets (priv->act_req, priv->secrets_id = nm_act_request_get_secrets (priv->act_req,
setting_name, setting_name,

View File

@@ -343,7 +343,7 @@ struct _Request {
gboolean filter_by_uid; gboolean filter_by_uid;
gulong uid_filter; gulong uid_filter;
char *setting_name; char *setting_name;
guint32 flags; NMSettingsGetSecretsFlags flags;
char *hint; char *hint;
/* Current agent being asked for secrets */ /* Current agent being asked for secrets */
@@ -384,7 +384,7 @@ request_new_get (NMConnection *connection,
gulong uid_filter, gulong uid_filter,
GHashTable *existing_secrets, GHashTable *existing_secrets,
const char *setting_name, const char *setting_name,
guint32 flags, NMSettingsGetSecretsFlags flags,
const char *hint, const char *hint,
NMAgentSecretsResultFunc callback, NMAgentSecretsResultFunc callback,
gpointer callback_data, gpointer callback_data,
@@ -856,7 +856,8 @@ get_next_cb (Request *req)
* secrets to the agent. We shouldn't leak system-owned secrets to * secrets to the agent. We shouldn't leak system-owned secrets to
* unprivileged users. * unprivileged users.
*/ */
if ((req->flags != 0) && (req->existing_secrets || has_system_secrets (req->connection))) { if ( (req->flags != NM_SETTINGS_GET_SECRETS_FLAG_NONE)
&& (req->existing_secrets || has_system_secrets (req->connection))) {
nm_log_dbg (LOGD_AGENTS, "(%p/%s) request has system secrets; checking agent %s for MODIFY", nm_log_dbg (LOGD_AGENTS, "(%p/%s) request has system secrets; checking agent %s for MODIFY",
req, req->setting_name, agent_dbus_owner); req, req->setting_name, agent_dbus_owner);
@@ -984,7 +985,7 @@ nm_agent_manager_get_secrets (NMAgentManager *self,
gulong uid_filter, gulong uid_filter,
GHashTable *existing_secrets, GHashTable *existing_secrets,
const char *setting_name, const char *setting_name,
guint32 flags, NMSettingsGetSecretsFlags flags,
const char *hint, const char *hint,
NMAgentSecretsResultFunc callback, NMAgentSecretsResultFunc callback,
gpointer callback_data, gpointer callback_data,

View File

@@ -24,6 +24,7 @@
#include <glib.h> #include <glib.h>
#include <glib-object.h> #include <glib-object.h>
#include <nm-connection.h> #include <nm-connection.h>
#include "nm-settings-flags.h"
#define NM_TYPE_AGENT_MANAGER (nm_agent_manager_get_type ()) #define NM_TYPE_AGENT_MANAGER (nm_agent_manager_get_type ())
#define NM_AGENT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_AGENT_MANAGER, NMAgentManager)) #define NM_AGENT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_AGENT_MANAGER, NMAgentManager))
@@ -50,7 +51,7 @@ typedef void (*NMAgentSecretsResultFunc) (NMAgentManager *manager,
const char *agent_dbus_owner, const char *agent_dbus_owner,
gboolean agent_has_modify, gboolean agent_has_modify,
const char *setting_name, const char *setting_name,
guint32 flags, NMSettingsGetSecretsFlags flags,
GHashTable *secrets, GHashTable *secrets,
GError *error, GError *error,
gpointer user_data, gpointer user_data,
@@ -63,7 +64,7 @@ guint32 nm_agent_manager_get_secrets (NMAgentManager *manager,
gulong uid, gulong uid,
GHashTable *existing_secrets, GHashTable *existing_secrets,
const char *setting_name, const char *setting_name,
guint32 flags, NMSettingsGetSecretsFlags flags,
const char *hint, const char *hint,
NMAgentSecretsResultFunc callback, NMAgentSecretsResultFunc callback,
gpointer callback_data, gpointer callback_data,

View File

@@ -172,7 +172,7 @@ nm_secret_agent_get_secrets (NMSecretAgent *self,
NMConnection *connection, NMConnection *connection,
const char *setting_name, const char *setting_name,
const char *hint, const char *hint,
guint32 flags, NMSettingsGetSecretsFlags flags,
NMSecretAgentCallback callback, NMSecretAgentCallback callback,
gpointer callback_data) gpointer callback_data)
{ {

View File

@@ -28,6 +28,7 @@
#include <nm-connection.h> #include <nm-connection.h>
#include "nm-dbus-manager.h" #include "nm-dbus-manager.h"
#include "nm-settings-flags.h"
#define NM_TYPE_SECRET_AGENT (nm_secret_agent_get_type ()) #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(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SECRET_AGENT, NMSecretAgent))
@@ -71,7 +72,7 @@ gconstpointer nm_secret_agent_get_secrets (NMSecretAgent *agent,
NMConnection *connection, NMConnection *connection,
const char *setting_name, const char *setting_name,
const char *hint, const char *hint,
guint32 flags, NMSettingsGetSecretsFlags flags,
NMSecretAgentCallback callback, NMSecretAgentCallback callback,
gpointer callback_data); gpointer callback_data);

View File

@@ -488,7 +488,7 @@ agent_secrets_done_cb (NMAgentManager *manager,
const char *agent_dbus_owner, const char *agent_dbus_owner,
gboolean agent_has_modify, gboolean agent_has_modify,
const char *setting_name, const char *setting_name,
guint32 flags, NMSettingsGetSecretsFlags flags,
GHashTable *secrets, GHashTable *secrets,
GError *error, GError *error,
gpointer user_data, gpointer user_data,
@@ -540,7 +540,7 @@ agent_secrets_done_cb (NMAgentManager *manager,
*/ */
for_each_secret (NM_CONNECTION (self), secrets, has_system_owned_secrets, &agent_had_system); for_each_secret (NM_CONNECTION (self), secrets, has_system_owned_secrets, &agent_had_system);
if (agent_had_system) { if (agent_had_system) {
if (flags == 0) { /* ie SECRETS_FLAG_NONE */ if (flags == NM_SETTINGS_GET_SECRETS_FLAG_NONE) {
/* No user interaction was allowed when requesting secrets; the /* No user interaction was allowed when requesting secrets; the
* agent is being bad. Remove system-owned secrets. * agent is being bad. Remove system-owned secrets.
*/ */
@@ -578,7 +578,7 @@ agent_secrets_done_cb (NMAgentManager *manager,
/* If no user interaction was allowed, make sure that no "unsaved" secrets /* If no user interaction was allowed, make sure that no "unsaved" secrets
* came back. Unsaved secrets by definition require user interaction. * came back. Unsaved secrets by definition require user interaction.
*/ */
if (flags == 0) /* ie SECRETS_FLAG_NONE */ if (flags == NM_SETTINGS_GET_SECRETS_FLAG_NONE)
for_each_secret (NM_CONNECTION (self), secrets, clear_unsaved_secrets, NULL); for_each_secret (NM_CONNECTION (self), secrets, clear_unsaved_secrets, NULL);
/* Update the connection with our existing secrets from backing storage */ /* Update the connection with our existing secrets from backing storage */
@@ -660,7 +660,7 @@ nm_settings_connection_get_secrets (NMSettingsConnection *self,
gboolean filter_by_uid, gboolean filter_by_uid,
gulong uid, gulong uid,
const char *setting_name, const char *setting_name,
guint32 flags, NMSettingsGetSecretsFlags flags,
const char *hint, const char *hint,
NMSettingsConnectionSecretsFunc callback, NMSettingsConnectionSecretsFunc callback,
gpointer callback_data, gpointer callback_data,
@@ -1213,7 +1213,7 @@ dbus_secrets_auth_cb (NMSettingsConnection *self,
TRUE, TRUE,
sender_uid, sender_uid,
setting_name, setting_name,
0, /* GET_SECRETS_FLAG_NONE */ NM_SETTINGS_GET_SECRETS_FLAG_NONE,
NULL, NULL,
dbus_get_agent_secrets_cb, dbus_get_agent_secrets_cb,
context, context,

View File

@@ -23,6 +23,7 @@
#define NM_SETTINGS_CONNECTION_H #define NM_SETTINGS_CONNECTION_H
#include <nm-connection.h> #include <nm-connection.h>
#include "nm-settings-flags.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@@ -101,7 +102,7 @@ guint32 nm_settings_connection_get_secrets (NMSettingsConnection *connection,
gboolean filter_by_uid, gboolean filter_by_uid,
gulong uid, gulong uid,
const char *setting_name, const char *setting_name,
guint32 flags, NMSettingsGetSecretsFlags flags,
const char *hint, const char *hint,
NMSettingsConnectionSecretsFunc callback, NMSettingsConnectionSecretsFunc callback,
gpointer callback_data, gpointer callback_data,

View File

@@ -820,7 +820,7 @@ connection_need_secrets_cb (DBusGProxy *proxy,
priv->user_requested, priv->user_requested,
priv->user_uid, priv->user_uid,
setting_name, setting_name,
NM_ACT_REQUEST_GET_SECRETS_FLAG_ALLOW_INTERACTION, NM_SETTINGS_GET_SECRETS_FLAG_ALLOW_INTERACTION,
NULL, NULL,
vpn_secrets_cb, vpn_secrets_cb,
self, self,
@@ -886,7 +886,7 @@ get_existing_secrets (NMVPNConnection *self)
priv->user_requested, priv->user_requested,
priv->user_uid, priv->user_uid,
NM_SETTING_VPN_SETTING_NAME, NM_SETTING_VPN_SETTING_NAME,
NM_ACT_REQUEST_GET_SECRETS_FLAG_NONE, NM_SETTINGS_GET_SECRETS_FLAG_NONE,
NULL, NULL,
existing_secrets_cb, existing_secrets_cb,
self, self,