summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Šimerda <psimerda@redhat.com>2014-05-25 15:48:30 +0200
committerThomas Haller <thaller@redhat.com>2014-05-26 11:10:19 +0200
commitcca4a37518958ad1c693c6d35dc2c875b6f682f2 (patch)
treec89845852ce3125ff427ba5a1b73059d8f0ba99f
parent0e1017b6e4d83af8b534e23607c49ad9ab28856e (diff)
downloadNetworkManager-th/review/pavlix/bgo686997_session.tar.gz
core: simplify NMSessionMonitor APIth/review/pavlix/bgo686997_session
https://bugzilla.gnome.org/show_bug.cgi?id=686997 Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r--src/nm-manager-auth.c1
-rw-r--r--src/nm-manager-auth.h1
-rw-r--r--src/nm-manager.c5
-rw-r--r--src/nm-session-monitor.c163
-rw-r--r--src/nm-session-monitor.h33
-rw-r--r--src/settings/nm-agent-manager.c8
-rw-r--r--src/settings/nm-settings-connection.c11
-rw-r--r--src/settings/nm-settings.c2
8 files changed, 56 insertions, 168 deletions
diff --git a/src/nm-manager-auth.c b/src/nm-manager-auth.c
index cf311988b1..852bf3fed3 100644
--- a/src/nm-manager-auth.c
+++ b/src/nm-manager-auth.c
@@ -520,7 +520,6 @@ nm_auth_chain_unref (NMAuthChain *self)
gboolean
nm_auth_uid_in_acl (NMConnection *connection,
- NMSessionMonitor *smon,
gulong uid,
char **out_error_desc)
{
diff --git a/src/nm-manager-auth.h b/src/nm-manager-auth.h
index 43dd639873..32e5cd56b8 100644
--- a/src/nm-manager-auth.h
+++ b/src/nm-manager-auth.h
@@ -96,7 +96,6 @@ void nm_auth_chain_unref (NMAuthChain *chain);
/* Caller must free returned error description */
gboolean nm_auth_uid_in_acl (NMConnection *connection,
- NMSessionMonitor *smon,
gulong uid,
char **out_error_desc);
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 43eb2caf85..41f2893bb2 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -1469,7 +1469,6 @@ device_auth_request_cb (NMDevice *device,
/* Ensure the subject has permissions for this connection */
if (connection && !nm_auth_uid_in_acl (connection,
- nm_session_monitor_get (),
nm_auth_subject_get_uid (subject),
&error_desc)) {
error = g_error_new_literal (NM_MANAGER_ERROR,
@@ -2528,7 +2527,6 @@ _internal_activate_device (NMManager *self, NMActiveConnection *active, GError *
subject = nm_active_connection_get_subject (active);
if (existing_connection &&
!nm_auth_uid_in_acl (existing_connection,
- nm_session_monitor_get (),
nm_auth_subject_get_uid (subject),
&error_desc)) {
g_set_error (error,
@@ -2820,7 +2818,6 @@ nm_manager_activate_connection (NMManager *self,
/* Ensure the subject has permissions for this connection */
if (!nm_auth_uid_in_acl (connection,
- nm_session_monitor_get (),
nm_auth_subject_get_uid (subject),
&error_desc)) {
g_set_error_literal (error,
@@ -2874,7 +2871,6 @@ validate_activation_request (NMManager *self,
/* Ensure the subject has permissions for this connection */
if (!nm_auth_uid_in_acl (connection,
- nm_session_monitor_get (),
nm_auth_subject_get_uid (subject),
&error_desc)) {
g_set_error_literal (error,
@@ -3398,7 +3394,6 @@ impl_manager_deactivate_connection (NMManager *self,
/* Ensure the subject has permissions for this connection */
if (!nm_auth_uid_in_acl (connection,
- nm_session_monitor_get (),
nm_auth_subject_get_uid (subject),
&error_desc)) {
error = g_error_new_literal (NM_MANAGER_ERROR,
diff --git a/src/nm-session-monitor.c b/src/nm-session-monitor.c
index f7a85c3569..cb42ee929c 100644
--- a/src/nm-session-monitor.c
+++ b/src/nm-session-monitor.c
@@ -106,48 +106,6 @@ nm_session_monitor_error_quark (void)
/********************************************************************/
-gboolean
-nm_session_monitor_uid_to_user (uid_t uid, const char **out_user, GError **error)
-{
- struct passwd *pw;
-
- pw = getpwuid (uid);
- if (!pw) {
- g_set_error (error,
- NM_SESSION_MONITOR_ERROR,
- NM_SESSION_MONITOR_ERROR_UNKNOWN_USER,
- "Could not get username for UID %d",
- uid);
- return FALSE;
- }
-
- if (out_user)
- *out_user = pw->pw_name;
- return TRUE;
-}
-
-static gboolean
-nm_session_monitor_user_to_uid (const char *user, uid_t *out_uid, GError **error)
-{
- struct passwd *pw;
-
- pw = getpwnam (user);
- if (!pw) {
- g_set_error (error,
- NM_SESSION_MONITOR_ERROR,
- NM_SESSION_MONITOR_ERROR_UNKNOWN_USER,
- "Could not get UID for username '%s'",
- user);
- return FALSE;
- }
-
- if (out_uid)
- *out_uid = pw->pw_uid;
- return TRUE;
-}
-
-/********************************************************************/
-
#ifdef SESSION_TRACKING_SYSTEMD
typedef struct {
GSource source;
@@ -553,9 +511,31 @@ ck_finalize (NMSessionMonitor *monitor)
/********************************************************************/
+gboolean
+nm_session_monitor_uid_to_user (uid_t uid, const char **out_user, GError **error)
+{
+ struct passwd *pw;
+
+ pw = getpwuid (uid);
+ if (!pw) {
+ g_set_error (error,
+ NM_SESSION_MONITOR_ERROR,
+ NM_SESSION_MONITOR_ERROR_UNKNOWN_USER,
+ "Could not get username for UID %d",
+ uid);
+ return FALSE;
+ }
+
+ if (out_user)
+ *out_user = pw->pw_name;
+ return TRUE;
+}
+
static gboolean
-nm_session_monitor_lookup (NMSessionMonitor *monitor, uid_t uid, gboolean active, GError **error)
+nm_session_monitor_lookup (uid_t uid, gboolean active, GError **error)
{
+ NMSessionMonitor *monitor = nm_session_monitor_get ();
+
#ifdef SESSION_TRACKING_SYSTEMD
if (monitor->sd.source)
return sd_lookup (uid, active, error);
@@ -574,83 +554,7 @@ nm_session_monitor_lookup (NMSessionMonitor *monitor, uid_t uid, gboolean active
}
/**
- * nm_session_monitor_user_has_session:
- * @monitor: A #NMSessionMonitor.
- * @username: A username.
- * @error: Return location for error.
- *
- * Checks whether the given @username is logged into a session or not.
- *
- * Returns: %FALSE if @error is set otherwise %TRUE if the given @username is
- * currently logged into a session.
- */
-gboolean
-nm_session_monitor_user_has_session (NMSessionMonitor *monitor,
- const char *username,
- uid_t *out_uid,
- GError **error)
-{
- uid_t uid;
-
- if (!nm_session_monitor_user_to_uid (username, &uid, error))
- return FALSE;
-
- if (out_uid)
- *out_uid = uid;
-
- return nm_session_monitor_lookup (monitor, uid, FALSE, error);
-}
-
-/**
- * nm_session_monitor_uid_has_session:
- * @monitor: A #NMSessionMonitor.
- * @uid: A user ID.
- * @error: Return location for error.
- *
- * Checks whether the given @uid is logged into a session or not.
- *
- * Returns: %FALSE if @error is set otherwise %TRUE if the given @uid is
- * currently logged into a session.
- */
-gboolean
-nm_session_monitor_uid_has_session (NMSessionMonitor *monitor,
- uid_t uid,
- const char **out_user,
- GError **error)
-{
- if (out_user && !nm_session_monitor_uid_to_user (uid, out_user, error))
- return FALSE;
-
- return nm_session_monitor_lookup (monitor, uid, FALSE, error);
-}
-
-/**
- * nm_session_monitor_user_active:
- * @monitor: A #NMSessionMonitor.
- * @username: A username.
- * @error: Return location for error.
- *
- * Checks whether the given @username is logged into a active session or not.
- *
- * Returns: %FALSE if @error is set otherwise %TRUE if the given @username is
- * logged into an active session.
- */
-gboolean
-nm_session_monitor_user_active (NMSessionMonitor *monitor,
- const char *username,
- GError **error)
-{
- uid_t uid;
-
- if (!nm_session_monitor_user_to_uid (username, &uid, error))
- return FALSE;
-
- return nm_session_monitor_lookup (monitor, uid, TRUE, error);
-}
-
-/**
* nm_session_monitor_uid_active:
- * @monitor: A #NMSessionMonitor.
* @uid: A user ID.
* @error: Return location for error.
*
@@ -660,11 +564,9 @@ nm_session_monitor_user_active (NMSessionMonitor *monitor,
* logged into an active session.
*/
gboolean
-nm_session_monitor_uid_active (NMSessionMonitor *monitor,
- uid_t uid,
- GError **error)
+nm_session_monitor_uid_active (uid_t uid, GError **error)
{
- return nm_session_monitor_lookup (monitor, uid, TRUE, error);
+ return nm_session_monitor_lookup (uid, TRUE, error);
}
/********************************************************************/
@@ -680,6 +582,21 @@ nm_session_monitor_get (void)
return singleton;
}
+gulong
+nm_session_monitor_connect (NMSessionCallback callback, gpointer user_data)
+{
+ return g_signal_connect (nm_session_monitor_get (),
+ NM_SESSION_MONITOR_CHANGED,
+ G_CALLBACK (callback),
+ user_data);
+}
+
+void
+nm_session_monitor_disconnect (gulong handler_id)
+{
+ g_signal_handler_disconnect (nm_session_monitor_get (), handler_id);
+}
+
static void
nm_session_monitor_init (NMSessionMonitor *monitor)
{
diff --git a/src/nm-session-monitor.h b/src/nm-session-monitor.h
index 1ea5f9f30b..9cf6548570 100644
--- a/src/nm-session-monitor.h
+++ b/src/nm-session-monitor.h
@@ -38,32 +38,21 @@ G_BEGIN_DECLS
typedef struct _NMSessionMonitor NMSessionMonitor;
typedef struct _NMSessionMonitorClass NMSessionMonitorClass;
-GType nm_session_monitor_get_type (void) G_GNUC_CONST;
-NMSessionMonitor *nm_session_monitor_get (void);
-
-gboolean nm_session_monitor_uid_to_user (uid_t uid,
- const char **out_user,
- GError **error);
-
-gboolean nm_session_monitor_user_has_session (NMSessionMonitor *monitor,
- const char *username,
- uid_t *out_uid,
- GError **error);
+typedef void (*NMSessionCallback) (NMSessionMonitor *monitor, gpointer user_data);
-gboolean nm_session_monitor_uid_has_session (NMSessionMonitor *monitor,
- uid_t uid,
- const char **out_user,
- GError **error);
+GType nm_session_monitor_get_type (void) G_GNUC_CONST;
-gboolean nm_session_monitor_user_active (NMSessionMonitor *monitor,
- const char *username,
- GError **error);
+NMSessionMonitor *nm_session_monitor_get (void);
+gulong nm_session_monitor_connect (NMSessionCallback callback,
+ gpointer user_data);
+void nm_session_monitor_disconnect (gulong handler_id);
-gboolean nm_session_monitor_uid_active (NMSessionMonitor *monitor,
- uid_t uid,
- GError **error);
+gboolean nm_session_monitor_uid_to_user (uid_t uid,
+ const char **out_user,
+ GError **error);
+gboolean nm_session_monitor_uid_active (uid_t uid,
+ GError **error);
G_END_DECLS
#endif /* NM_SESSION_MONITOR_H */
-
diff --git a/src/settings/nm-agent-manager.c b/src/settings/nm-agent-manager.c
index 77e7f41c6f..dc50719e1c 100644
--- a/src/settings/nm-agent-manager.c
+++ b/src/settings/nm-agent-manager.c
@@ -526,11 +526,9 @@ agent_compare_func (gconstpointer aa, gconstpointer bb, gpointer user_data)
}
/* Prefer agents in active sessions */
- a_active = nm_session_monitor_uid_active (nm_session_monitor_get (),
- nm_secret_agent_get_owner_uid (a),
+ a_active = nm_session_monitor_uid_active (nm_secret_agent_get_owner_uid (a),
NULL);
- b_active = nm_session_monitor_uid_active (nm_session_monitor_get (),
- nm_secret_agent_get_owner_uid (b),
+ b_active = nm_session_monitor_uid_active (nm_secret_agent_get_owner_uid (b),
NULL);
if (a_active && !b_active)
return -1;
@@ -701,7 +699,7 @@ connection_request_add_agent (Request *parent, NMSecretAgent *agent)
/* Ensure the caller's username exists in the connection's permissions,
* or that the permissions is empty (ie, visible by everyone).
*/
- if (!nm_auth_uid_in_acl (req->connection, nm_session_monitor_get (), agent_uid, NULL)) {
+ if (!nm_auth_uid_in_acl (req->connection, agent_uid, NULL)) {
nm_log_dbg (LOGD_AGENTS, "(%s) agent ignored for secrets request %p/%s (not in ACL)",
nm_secret_agent_get_description (agent),
parent, parent->detail);
diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c
index ed212fd881..b594378bf8 100644
--- a/src/settings/nm-settings-connection.c
+++ b/src/settings/nm-settings-connection.c
@@ -92,7 +92,6 @@ typedef struct {
gboolean disposed;
NMAgentManager *agent_mgr;
- NMSessionMonitor *session_monitor;
guint session_changed_id;
/* TRUE if the connection has not yet been saved to disk,
@@ -1037,7 +1036,6 @@ auth_start (NMSettingsConnection *self,
/* Ensure the caller can view this connection */
if (!nm_auth_uid_in_acl (NM_CONNECTION (self),
- priv->session_monitor,
nm_auth_subject_get_uid (subject),
&error_desc)) {
error = g_error_new_literal (NM_SETTINGS_ERROR,
@@ -1345,7 +1343,6 @@ impl_settings_connection_update_helper (NMSettingsConnection *self,
* invisible to yourself.
*/
if (!nm_auth_uid_in_acl (tmp ? tmp : NM_CONNECTION (self),
- priv->session_monitor,
nm_auth_subject_get_uid (subject),
&error_desc)) {
error = g_error_new_literal (NM_SETTINGS_ERROR,
@@ -1982,11 +1979,7 @@ nm_settings_connection_init (NMSettingsConnection *self)
priv->visible = FALSE;
- priv->session_monitor = nm_session_monitor_get ();
- priv->session_changed_id = g_signal_connect (priv->session_monitor,
- NM_SESSION_MONITOR_CHANGED,
- G_CALLBACK (session_changed_cb),
- self);
+ priv->session_changed_id = nm_session_monitor_connect (session_changed_cb, self);
priv->agent_mgr = nm_agent_manager_get ();
@@ -2036,7 +2029,7 @@ dispose (GObject *object)
set_visible (self, FALSE);
if (priv->session_changed_id)
- g_signal_handler_disconnect (priv->session_monitor, priv->session_changed_id);
+ nm_session_monitor_disconnect (priv->session_changed_id);
g_object_unref (priv->agent_mgr);
out:
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c
index b4d9c22ea3..6d75d99619 100644
--- a/src/settings/nm-settings.c
+++ b/src/settings/nm-settings.c
@@ -297,7 +297,6 @@ impl_settings_get_connection_by_uuid (NMSettings *self,
}
if (!nm_auth_uid_in_acl (NM_CONNECTION (connection),
- nm_session_monitor_get (),
nm_auth_subject_get_uid (subject),
&error_desc)) {
error = g_error_new_literal (NM_SETTINGS_ERROR,
@@ -1156,7 +1155,6 @@ nm_settings_add_connection_dbus (NMSettings *self,
* or that the permissions is empty (ie, visible by everyone).
*/
if (!nm_auth_uid_in_acl (connection,
- nm_session_monitor_get (),
nm_auth_subject_get_uid (subject),
&error_desc)) {
error = g_error_new_literal (NM_SETTINGS_ERROR,