2020-12-23 22:21:36 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2019-09-25 13:13:40 +02:00
|
|
|
/*
|
2014-08-14 13:34:57 +02:00
|
|
|
* Copyright (C) 2014 Red Hat, Inc.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-02-04 18:04:13 +01:00
|
|
|
#include "src/core/nm-default-daemon.h"
|
2014-11-13 10:07:02 -05:00
|
|
|
|
2014-08-14 13:34:57 +02:00
|
|
|
#include "nm-auth-manager.h"
|
|
|
|
|
|
2018-04-06 16:40:23 +02:00
|
|
|
#include "c-list/src/c-list.h"
|
2021-02-18 17:37:47 +01:00
|
|
|
#include "libnm-glib-aux/nm-dbus-aux.h"
|
core: drop all remaining core-internal error domains
A number of classes in core had their own error domains that aren't
really necessary.
In the case of NMDcbError, NMDhcpManagerError, NMDnsManagerError,
NMDnsmasqManagerError, NMPppManagerError, and NMSessionMonitorError,
most of the codes they defined weren't even being used, and at any
rate, the errors were always returned into contexts where they would
just have their message extracted and then get thrown away without
anyone ever looking at the domain or code. So all uses of those
domains can just be replaced with NM_MANAGER_ERROR_FAILED without any
loss of information.
NMAuthManagerError only had 1 error code, and it just indicated
"something went wrong", so it can be replaced with
NM_MANAGER_ERROR_FAILED without loss of information.
(nm-auth-manager.c has also been fixed to return
NM_MANAGER_ERROR_FAILED when the CheckAuthorization D-Bus call fails,
rather than returning whatever error domain/code the D-Bus call
returned.)
NMVpnManagerError used 2 of its 4 error codes, and they could actually
end up getting returned across D-Bus in some cases. But there are
NMManagerError codes that are semantically similar enough to make the
NMVpnManagerError ones unnecessary.
2014-10-16 16:51:22 -04:00
|
|
|
#include "nm-errors.h"
|
2021-02-12 15:01:09 +01:00
|
|
|
#include "libnm-core-intern/nm-core-internal.h"
|
2019-05-04 11:03:35 +02:00
|
|
|
#include "nm-dbus-manager.h"
|
2015-07-24 15:45:46 +02:00
|
|
|
#include "NetworkManagerUtils.h"
|
2014-08-14 13:34:57 +02:00
|
|
|
|
|
|
|
|
#define POLKIT_SERVICE "org.freedesktop.PolicyKit1"
|
|
|
|
|
#define POLKIT_OBJECT_PATH "/org/freedesktop/PolicyKit1/Authority"
|
|
|
|
|
#define POLKIT_INTERFACE "org.freedesktop.PolicyKit1.Authority"
|
|
|
|
|
|
2018-04-09 13:27:03 +02:00
|
|
|
#define CANCELLATION_ID_PREFIX "cancellation-id-"
|
|
|
|
|
#define CANCELLATION_TIMEOUT_MS 5000
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
/*****************************************************************************/
|
2014-08-14 13:34:57 +02:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_POLKIT_ENABLED, );
|
2014-08-14 13:34:57 +02:00
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
CHANGED_SIGNAL,
|
|
|
|
|
LAST_SIGNAL,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = {0};
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2018-04-09 13:27:03 +02:00
|
|
|
CList calls_lst_head;
|
2019-05-04 12:46:17 +02:00
|
|
|
GDBusConnection *dbus_connection;
|
2021-11-09 13:28:54 +01:00
|
|
|
GCancellable *main_cancellable;
|
|
|
|
|
char *name_owner;
|
2018-04-09 13:27:03 +02:00
|
|
|
guint64 call_numid_counter;
|
2020-04-11 08:17:56 +02:00
|
|
|
guint changed_id;
|
|
|
|
|
guint name_owner_changed_id;
|
2018-04-09 13:27:03 +02:00
|
|
|
bool disposing : 1;
|
|
|
|
|
bool shutting_down : 1;
|
2020-04-11 08:17:56 +02:00
|
|
|
bool got_name_owner : 1;
|
2019-12-10 08:51:03 +01:00
|
|
|
NMAuthPolkitMode auth_polkit_mode : 3;
|
2014-08-14 13:34:57 +02:00
|
|
|
} NMAuthManagerPrivate;
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
struct _NMAuthManager {
|
|
|
|
|
GObject parent;
|
|
|
|
|
NMAuthManagerPrivate _priv;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct _NMAuthManagerClass {
|
|
|
|
|
GObjectClass parent;
|
|
|
|
|
};
|
2014-08-14 13:34:57 +02:00
|
|
|
|
|
|
|
|
G_DEFINE_TYPE(NMAuthManager, nm_auth_manager, G_TYPE_OBJECT)
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
#define NM_AUTH_MANAGER_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMAuthManager, NM_IS_AUTH_MANAGER)
|
|
|
|
|
|
|
|
|
|
NM_DEFINE_SINGLETON_REGISTER(NMAuthManager);
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#define _NMLOG_PREFIX_NAME "auth"
|
|
|
|
|
#define _NMLOG_DOMAIN LOGD_CORE
|
|
|
|
|
#define _NMLOG(level, ...) \
|
|
|
|
|
G_STMT_START \
|
|
|
|
|
{ \
|
|
|
|
|
if (nm_logging_enabled((level), (_NMLOG_DOMAIN))) { \
|
|
|
|
|
char __prefix[30] = _NMLOG_PREFIX_NAME; \
|
|
|
|
|
\
|
|
|
|
|
if ((self) != singleton_instance) \
|
|
|
|
|
g_snprintf(__prefix, \
|
|
|
|
|
sizeof(__prefix), \
|
|
|
|
|
""_NMLOG_PREFIX_NAME \
|
|
|
|
|
"[%p]", \
|
|
|
|
|
(self)); \
|
2017-03-01 10:20:01 +00:00
|
|
|
_nm_log((level), \
|
|
|
|
|
(_NMLOG_DOMAIN), \
|
|
|
|
|
0, \
|
|
|
|
|
NULL, \
|
|
|
|
|
NULL, \
|
2016-09-29 13:49:01 +02:00
|
|
|
"%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
|
|
|
|
|
__prefix _NM_UTILS_MACRO_REST(__VA_ARGS__)); \
|
|
|
|
|
} \
|
|
|
|
|
} \
|
|
|
|
|
G_STMT_END
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-04-09 13:27:03 +02:00
|
|
|
#define _NMLOG2(level, call_id, ...) \
|
|
|
|
|
G_STMT_START \
|
|
|
|
|
{ \
|
|
|
|
|
if (nm_logging_enabled((level), (_NMLOG_DOMAIN))) { \
|
|
|
|
|
NMAuthManagerCallId *_call_id = (call_id); \
|
|
|
|
|
char __prefix[30] = _NMLOG_PREFIX_NAME; \
|
|
|
|
|
\
|
|
|
|
|
if (_call_id->self != singleton_instance) \
|
|
|
|
|
g_snprintf(__prefix, \
|
|
|
|
|
sizeof(__prefix), \
|
|
|
|
|
""_NMLOG_PREFIX_NAME \
|
|
|
|
|
"[%p]", \
|
|
|
|
|
_call_id->self); \
|
|
|
|
|
_nm_log((level), \
|
|
|
|
|
(_NMLOG_DOMAIN), \
|
|
|
|
|
0, \
|
|
|
|
|
NULL, \
|
|
|
|
|
NULL, \
|
|
|
|
|
"%s: call[%" G_GUINT64_FORMAT "]: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
|
|
|
|
|
__prefix, \
|
|
|
|
|
_call_id->call_numid _NM_UTILS_MACRO_REST(__VA_ARGS__)); \
|
|
|
|
|
} \
|
|
|
|
|
} \
|
|
|
|
|
G_STMT_END
|
|
|
|
|
|
2014-08-14 13:34:57 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
nm_auth_manager_get_polkit_enabled(NMAuthManager *self)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail(NM_IS_AUTH_MANAGER(self), FALSE);
|
|
|
|
|
|
2019-05-04 12:46:17 +02:00
|
|
|
return NM_AUTH_MANAGER_GET_PRIVATE(self)->dbus_connection != NULL;
|
2014-08-14 13:34:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-11 08:17:56 +02:00
|
|
|
static void
|
|
|
|
|
_emit_changed_signal(NMAuthManager *self)
|
|
|
|
|
{
|
|
|
|
|
g_signal_emit(self, signals[CHANGED_SIGNAL], 0);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-14 13:34:57 +02:00
|
|
|
typedef enum {
|
|
|
|
|
POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE = 0,
|
|
|
|
|
POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION = (1 << 0),
|
|
|
|
|
} PolkitCheckAuthorizationFlags;
|
|
|
|
|
|
2018-04-09 13:27:03 +02:00
|
|
|
struct _NMAuthManagerCallId {
|
|
|
|
|
CList calls_lst;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMAuthManager *self;
|
|
|
|
|
GCancellable *dbus_cancellable;
|
2018-04-09 13:27:03 +02:00
|
|
|
NMAuthManagerCheckAuthorizationCallback callback;
|
|
|
|
|
gpointer user_data;
|
|
|
|
|
guint64 call_numid;
|
|
|
|
|
guint idle_id;
|
2019-12-10 08:51:03 +01:00
|
|
|
bool idle_is_authorized : 1;
|
2018-04-09 13:27:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define cancellation_id_to_str_a(call_numid) \
|
2019-05-04 12:46:17 +02:00
|
|
|
nm_sprintf_bufa(NM_STRLEN(CANCELLATION_ID_PREFIX) + 60, \
|
2018-04-09 13:27:03 +02:00
|
|
|
CANCELLATION_ID_PREFIX "%" G_GUINT64_FORMAT, \
|
|
|
|
|
(call_numid))
|
2014-08-14 13:34:57 +02:00
|
|
|
|
|
|
|
|
static void
|
2018-04-09 13:27:03 +02:00
|
|
|
_call_id_free(NMAuthManagerCallId *call_id)
|
2014-08-14 13:34:57 +02:00
|
|
|
{
|
2018-04-09 13:27:03 +02:00
|
|
|
c_list_unlink(&call_id->calls_lst);
|
|
|
|
|
nm_clear_g_source(&call_id->idle_id);
|
|
|
|
|
|
|
|
|
|
if (call_id->dbus_cancellable) {
|
|
|
|
|
/* we have a pending D-Bus call. We keep the call-id instance alive
|
|
|
|
|
* for _call_check_authorize_cb() */
|
|
|
|
|
g_cancellable_cancel(call_id->dbus_cancellable);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_unref(call_id->self);
|
|
|
|
|
g_slice_free(NMAuthManagerCallId, call_id);
|
2014-08-14 13:34:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2018-04-09 13:27:03 +02:00
|
|
|
_call_id_invoke_callback(NMAuthManagerCallId *call_id,
|
|
|
|
|
gboolean is_authorized,
|
|
|
|
|
gboolean is_challenge,
|
2021-11-09 13:28:54 +01:00
|
|
|
GError *error)
|
2014-08-14 13:34:57 +02:00
|
|
|
{
|
2018-04-09 13:27:03 +02:00
|
|
|
c_list_unlink(&call_id->calls_lst);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
|
|
|
|
call_id
|
2018-04-09 13:27:03 +02:00
|
|
|
->callback(call_id->self, call_id, is_authorized, is_challenge, error, call_id->user_data);
|
|
|
|
|
_call_id_free(call_id);
|
2014-08-14 13:34:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2019-05-04 12:46:17 +02:00
|
|
|
cancel_check_authorization_cb(GObject *source, GAsyncResult *res, gpointer user_data)
|
2014-08-14 13:34:57 +02:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMAuthManagerCallId *call_id = user_data;
|
|
|
|
|
gs_unref_variant GVariant *value = NULL;
|
|
|
|
|
gs_free_error GError *error = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-05-04 12:46:17 +02:00
|
|
|
value = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), res, &error);
|
2018-04-09 13:27:03 +02:00
|
|
|
if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
|
|
|
|
_LOG2T(call_id, "cancel request was cancelled");
|
|
|
|
|
else if (error)
|
|
|
|
|
_LOG2T(call_id, "cancel request failed: %s", error->message);
|
|
|
|
|
else
|
|
|
|
|
_LOG2T(call_id, "cancel request succeeded");
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-04-09 13:27:03 +02:00
|
|
|
_call_id_free(call_id);
|
2014-08-14 13:34:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2018-04-09 13:27:03 +02:00
|
|
|
_call_check_authorize_cb(GObject *proxy, GAsyncResult *res, gpointer user_data)
|
2014-08-14 13:34:57 +02:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMAuthManagerCallId *call_id = user_data;
|
|
|
|
|
NMAuthManager *self;
|
|
|
|
|
NMAuthManagerPrivate *priv;
|
|
|
|
|
gs_unref_variant GVariant *value = NULL;
|
|
|
|
|
gs_free_error GError *error = NULL;
|
|
|
|
|
gboolean is_authorized = FALSE;
|
|
|
|
|
gboolean is_challenge = FALSE;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-04-09 13:27:03 +02:00
|
|
|
/* we need to clear the cancelable, to signal for _call_id_free() that we
|
|
|
|
|
* are not in a pending call.
|
|
|
|
|
*
|
|
|
|
|
* Note how _call_id_free() kept call-id alive, even if the request was
|
|
|
|
|
* already cancelled. */
|
|
|
|
|
g_clear_object(&call_id->dbus_cancellable);
|
2014-08-14 13:34:57 +02:00
|
|
|
|
2018-04-09 13:27:03 +02:00
|
|
|
self = call_id->self;
|
|
|
|
|
priv = NM_AUTH_MANAGER_GET_PRIVATE(self);
|
|
|
|
|
|
2019-05-04 12:46:17 +02:00
|
|
|
value = g_dbus_connection_call_finish(G_DBUS_CONNECTION(proxy), res, &error);
|
2020-04-11 08:17:56 +02:00
|
|
|
|
|
|
|
|
if (nm_utils_error_is_cancelled(error)) {
|
2018-04-09 13:27:03 +02:00
|
|
|
/* call_id was cancelled externally, but _call_id_free() kept call_id
|
|
|
|
|
* alive (and it has still the reference on @self. */
|
|
|
|
|
|
2020-04-11 08:17:56 +02:00
|
|
|
if (!priv->main_cancellable) {
|
2018-04-09 13:27:03 +02:00
|
|
|
/* we do a forced shutdown. There is no more time for cancelling... */
|
|
|
|
|
_call_id_free(call_id);
|
|
|
|
|
|
|
|
|
|
/* this shouldn't really happen, because:
|
2020-04-11 08:17:56 +02:00
|
|
|
* nm_auth_manager_check_authorization() only scheduled the D-Bus request at a time when
|
|
|
|
|
* main_cancellable was still set. It means, somebody called force-shutdown
|
2018-04-09 13:27:03 +02:00
|
|
|
* after call-id was schedule.
|
|
|
|
|
* force-shutdown should only be called after:
|
|
|
|
|
* - cancel all pending requests
|
|
|
|
|
* - give enough time to cancel the request and schedule a D-Bus call
|
|
|
|
|
* to CancelCheckAuthorization (below), before issuing force-shutdown. */
|
|
|
|
|
g_return_if_reached();
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-05-04 12:46:17 +02:00
|
|
|
g_dbus_connection_call(priv->dbus_connection,
|
|
|
|
|
POLKIT_SERVICE,
|
|
|
|
|
POLKIT_OBJECT_PATH,
|
|
|
|
|
POLKIT_INTERFACE,
|
|
|
|
|
"CancelCheckAuthorization",
|
|
|
|
|
g_variant_new("(s)", cancellation_id_to_str_a(call_id->call_numid)),
|
|
|
|
|
G_VARIANT_TYPE("()"),
|
|
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
|
CANCELLATION_TIMEOUT_MS,
|
2020-04-11 08:17:56 +02:00
|
|
|
priv->main_cancellable,
|
2019-05-04 12:46:17 +02:00
|
|
|
cancel_check_authorization_cb,
|
|
|
|
|
call_id);
|
2018-04-09 13:27:03 +02:00
|
|
|
return;
|
2014-08-14 13:34:57 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-04-09 13:27:03 +02:00
|
|
|
if (!error) {
|
|
|
|
|
g_variant_get(value, "((bb@a{ss}))", &is_authorized, &is_challenge, NULL);
|
|
|
|
|
_LOG2T(call_id, "completed: authorized=%d, challenge=%d", is_authorized, is_challenge);
|
|
|
|
|
} else
|
|
|
|
|
_LOG2T(call_id, "completed: failed: %s", error->message);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-04-09 13:27:03 +02:00
|
|
|
_call_id_invoke_callback(call_id, is_authorized, is_challenge, error);
|
2014-08-14 13:34:57 +02:00
|
|
|
}
|
|
|
|
|
|
2018-04-09 13:27:03 +02:00
|
|
|
static gboolean
|
2018-04-09 16:04:46 +02:00
|
|
|
_call_on_idle(gpointer user_data)
|
2018-04-09 13:27:03 +02:00
|
|
|
{
|
|
|
|
|
NMAuthManagerCallId *call_id = user_data;
|
2019-12-10 08:51:03 +01:00
|
|
|
gboolean is_authorized;
|
2018-04-09 16:04:46 +02:00
|
|
|
gboolean is_challenge = FALSE;
|
2018-04-09 13:27:03 +02:00
|
|
|
|
2019-12-10 08:51:03 +01:00
|
|
|
is_authorized = call_id->idle_is_authorized;
|
2018-04-09 13:27:03 +02:00
|
|
|
call_id->idle_id = 0;
|
2018-04-09 16:04:46 +02:00
|
|
|
|
2019-08-10 10:36:17 +02:00
|
|
|
_LOG2T(call_id,
|
|
|
|
|
"completed: authorized=%d, challenge=%d (simulated)",
|
|
|
|
|
is_authorized,
|
|
|
|
|
is_challenge);
|
|
|
|
|
|
|
|
|
|
_call_id_invoke_callback(call_id, is_authorized, is_challenge, NULL);
|
2018-04-09 13:27:03 +02:00
|
|
|
return G_SOURCE_REMOVE;
|
2014-08-14 13:34:57 +02:00
|
|
|
}
|
|
|
|
|
|
2018-04-09 12:36:06 +02:00
|
|
|
/*
|
|
|
|
|
* @callback must never be invoked synchronously.
|
2018-04-09 13:27:03 +02:00
|
|
|
*
|
|
|
|
|
* @callback is always invoked exactly once, and never synchronously.
|
|
|
|
|
* You may cancel the invocation with nm_auth_manager_check_authorization_cancel(),
|
|
|
|
|
* but: you may only do so exactly once, and only before @callback is
|
|
|
|
|
* invoked. Even if you cancel the request, @callback will still be invoked
|
|
|
|
|
* (synchronously, during the _cancel() callback).
|
|
|
|
|
*
|
|
|
|
|
* The request keeps @self alive (it needs to do so, because when cancelling a
|
|
|
|
|
* request we might need to do an additional CancelCheckAuthorization call, for
|
|
|
|
|
* which @self must be live long enough).
|
2018-04-09 12:36:06 +02:00
|
|
|
*/
|
2018-04-09 13:27:03 +02:00
|
|
|
NMAuthManagerCallId *
|
2021-11-09 13:28:54 +01:00
|
|
|
nm_auth_manager_check_authorization(NMAuthManager *self,
|
|
|
|
|
NMAuthSubject *subject,
|
|
|
|
|
const char *action_id,
|
2018-04-09 13:27:03 +02:00
|
|
|
gboolean allow_user_interaction,
|
|
|
|
|
NMAuthManagerCheckAuthorizationCallback callback,
|
|
|
|
|
gpointer user_data)
|
2014-08-14 13:34:57 +02:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMAuthManagerPrivate *priv;
|
2018-04-09 13:27:03 +02:00
|
|
|
PolkitCheckAuthorizationFlags flags;
|
2014-08-14 13:34:57 +02:00
|
|
|
char subject_buf[64];
|
2021-11-09 13:28:54 +01:00
|
|
|
NMAuthManagerCallId *call_id;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-04-09 13:27:03 +02:00
|
|
|
g_return_val_if_fail(NM_IS_AUTH_MANAGER(self), NULL);
|
2018-04-09 16:04:46 +02:00
|
|
|
g_return_val_if_fail(NM_IN_SET(nm_auth_subject_get_subject_type(subject),
|
|
|
|
|
NM_AUTH_SUBJECT_TYPE_INTERNAL,
|
|
|
|
|
NM_AUTH_SUBJECT_TYPE_UNIX_PROCESS),
|
|
|
|
|
NULL);
|
2018-04-09 13:27:03 +02:00
|
|
|
g_return_val_if_fail(action_id, NULL);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-08-14 13:34:57 +02:00
|
|
|
priv = NM_AUTH_MANAGER_GET_PRIVATE(self);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-04-09 13:27:03 +02:00
|
|
|
g_return_val_if_fail(!priv->disposing, NULL);
|
|
|
|
|
g_return_val_if_fail(!priv->shutting_down, NULL);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-08-14 13:34:57 +02:00
|
|
|
flags = allow_user_interaction ? POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION
|
|
|
|
|
: POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-05-04 11:00:31 +02:00
|
|
|
call_id = g_slice_new(NMAuthManagerCallId);
|
|
|
|
|
*call_id = (NMAuthManagerCallId){
|
2019-12-10 08:51:03 +01:00
|
|
|
.self = g_object_ref(self),
|
|
|
|
|
.callback = callback,
|
|
|
|
|
.user_data = user_data,
|
|
|
|
|
.call_numid = ++priv->call_numid_counter,
|
|
|
|
|
.idle_is_authorized = TRUE,
|
2019-05-04 11:00:31 +02:00
|
|
|
};
|
2018-04-09 13:27:03 +02:00
|
|
|
c_list_link_tail(&priv->calls_lst_head, &call_id->calls_lst);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-12-17 20:36:18 +01:00
|
|
|
if (nm_auth_subject_get_subject_type(subject) == NM_AUTH_SUBJECT_TYPE_INTERNAL) {
|
2018-04-09 16:04:46 +02:00
|
|
|
_LOG2T(call_id,
|
|
|
|
|
"CheckAuthorization(%s), subject=%s (succeeding for internal request)",
|
|
|
|
|
action_id,
|
|
|
|
|
nm_auth_subject_to_string(subject, subject_buf, sizeof(subject_buf)));
|
|
|
|
|
call_id->idle_id = g_idle_add(_call_on_idle, call_id);
|
|
|
|
|
} else if (nm_auth_subject_get_unix_process_uid(subject) == 0) {
|
|
|
|
|
_LOG2T(call_id,
|
|
|
|
|
"CheckAuthorization(%s), subject=%s (succeeding for root)",
|
|
|
|
|
action_id,
|
|
|
|
|
nm_auth_subject_to_string(subject, subject_buf, sizeof(subject_buf)));
|
|
|
|
|
call_id->idle_id = g_idle_add(_call_on_idle, call_id);
|
2019-12-10 08:51:03 +01:00
|
|
|
} else if (priv->auth_polkit_mode != NM_AUTH_POLKIT_MODE_USE_POLKIT) {
|
|
|
|
|
_LOG2T(call_id,
|
|
|
|
|
"CheckAuthorization(%s), subject=%s (PolicyKit disabled and always %s authorization "
|
|
|
|
|
"to non-root user)",
|
|
|
|
|
action_id,
|
|
|
|
|
nm_auth_subject_to_string(subject, subject_buf, sizeof(subject_buf)),
|
|
|
|
|
priv->auth_polkit_mode == NM_AUTH_POLKIT_MODE_ALLOW_ALL ? "grant" : "deny");
|
|
|
|
|
call_id->idle_is_authorized = (priv->auth_polkit_mode == NM_AUTH_POLKIT_MODE_ALLOW_ALL);
|
|
|
|
|
call_id->idle_id = g_idle_add(_call_on_idle, call_id);
|
2014-08-14 13:34:57 +02:00
|
|
|
} else {
|
2021-11-09 13:28:54 +01:00
|
|
|
GVariant *parameters;
|
2019-05-04 12:46:17 +02:00
|
|
|
GVariantBuilder builder;
|
2021-11-09 13:28:54 +01:00
|
|
|
GVariant *subject_value;
|
|
|
|
|
GVariant *details_value;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-12-17 20:36:18 +01:00
|
|
|
subject_value = nm_auth_subject_unix_to_polkit_gvariant(subject);
|
2018-04-09 13:27:03 +02:00
|
|
|
nm_assert(g_variant_is_floating(subject_value));
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-04-09 13:27:03 +02:00
|
|
|
/* ((PolkitDetails *)NULL) */
|
|
|
|
|
g_variant_builder_init(&builder, G_VARIANT_TYPE("a{ss}"));
|
|
|
|
|
details_value = g_variant_builder_end(&builder);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-05-04 12:46:17 +02:00
|
|
|
parameters = g_variant_new("(@(sa{sv})s@a{ss}us)",
|
|
|
|
|
subject_value,
|
|
|
|
|
action_id,
|
|
|
|
|
details_value,
|
|
|
|
|
(guint32) flags,
|
|
|
|
|
cancellation_id_to_str_a(call_id->call_numid));
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-05-04 12:46:17 +02:00
|
|
|
_LOG2T(call_id,
|
|
|
|
|
"CheckAuthorization(%s), subject=%s",
|
|
|
|
|
action_id,
|
|
|
|
|
nm_auth_subject_to_string(subject, subject_buf, sizeof(subject_buf)));
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-05-04 12:46:17 +02:00
|
|
|
call_id->dbus_cancellable = g_cancellable_new();
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-04-11 08:17:56 +02:00
|
|
|
nm_assert(priv->main_cancellable);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-05-04 12:46:17 +02:00
|
|
|
g_dbus_connection_call(priv->dbus_connection,
|
|
|
|
|
POLKIT_SERVICE,
|
|
|
|
|
POLKIT_OBJECT_PATH,
|
|
|
|
|
POLKIT_INTERFACE,
|
|
|
|
|
"CheckAuthorization",
|
|
|
|
|
parameters,
|
|
|
|
|
G_VARIANT_TYPE("((bba{ss}))"),
|
|
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
|
G_MAXINT, /* no timeout */
|
|
|
|
|
call_id->dbus_cancellable,
|
|
|
|
|
_call_check_authorize_cb,
|
|
|
|
|
call_id);
|
2014-08-14 13:34:57 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-04-09 13:27:03 +02:00
|
|
|
return call_id;
|
2014-08-14 13:34:57 +02:00
|
|
|
}
|
|
|
|
|
|
2018-04-09 13:27:03 +02:00
|
|
|
void
|
|
|
|
|
nm_auth_manager_check_authorization_cancel(NMAuthManagerCallId *call_id)
|
2014-08-14 13:34:57 +02:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMAuthManager *self;
|
2018-04-09 13:27:03 +02:00
|
|
|
gs_free_error GError *error = NULL;
|
2014-08-14 13:34:57 +02:00
|
|
|
|
2018-04-09 13:27:03 +02:00
|
|
|
g_return_if_fail(call_id);
|
2014-08-14 13:34:57 +02:00
|
|
|
|
2018-04-09 13:27:03 +02:00
|
|
|
self = call_id->self;
|
2014-08-14 13:34:57 +02:00
|
|
|
|
2018-04-09 13:27:03 +02:00
|
|
|
g_return_if_fail(NM_IS_AUTH_MANAGER(self));
|
|
|
|
|
g_return_if_fail(!c_list_is_empty(&call_id->calls_lst));
|
|
|
|
|
|
|
|
|
|
nm_assert(
|
|
|
|
|
c_list_contains(&NM_AUTH_MANAGER_GET_PRIVATE(self)->calls_lst_head, &call_id->calls_lst));
|
2014-08-14 13:34:57 +02:00
|
|
|
|
2018-04-09 13:27:03 +02:00
|
|
|
nm_utils_error_set_cancelled(&error, FALSE, "NMAuthManager");
|
|
|
|
|
_LOG2T(call_id, "completed: failed due to call cancelled");
|
|
|
|
|
_call_id_invoke_callback(call_id, FALSE, FALSE, error);
|
2014-08-14 13:34:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2019-05-04 12:46:17 +02:00
|
|
|
static void
|
|
|
|
|
changed_signal_cb(GDBusConnection *connection,
|
2021-11-09 13:28:54 +01:00
|
|
|
const char *sender_name,
|
|
|
|
|
const char *object_path,
|
|
|
|
|
const char *interface_name,
|
|
|
|
|
const char *signal_name,
|
|
|
|
|
GVariant *parameters,
|
2019-05-04 12:46:17 +02:00
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMAuthManager *self = user_data;
|
2020-04-11 08:17:56 +02:00
|
|
|
NMAuthManagerPrivate *priv = NM_AUTH_MANAGER_GET_PRIVATE(self);
|
|
|
|
|
gboolean valid_sender;
|
2018-04-09 13:27:03 +02:00
|
|
|
|
2020-04-11 08:17:56 +02:00
|
|
|
nm_assert(nm_streq0(signal_name, "Changed"));
|
|
|
|
|
|
|
|
|
|
valid_sender = nm_streq0(priv->name_owner, sender_name);
|
|
|
|
|
|
|
|
|
|
_LOGD("dbus-signal: \"Changed\" notification%s", valid_sender ? "" : " (ignore)");
|
|
|
|
|
|
|
|
|
|
if (valid_sender)
|
|
|
|
|
_emit_changed_signal(self);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_name_owner_changed(NMAuthManager *self, const char *name_owner, gboolean is_initial)
|
|
|
|
|
{
|
|
|
|
|
NMAuthManagerPrivate *priv = NM_AUTH_MANAGER_GET_PRIVATE(self);
|
|
|
|
|
gboolean is_changed;
|
2021-11-09 13:28:54 +01:00
|
|
|
gs_free char *old_name_owner = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-04-11 08:17:56 +02:00
|
|
|
if (is_initial)
|
|
|
|
|
priv->got_name_owner = TRUE;
|
|
|
|
|
else {
|
|
|
|
|
if (!priv->got_name_owner)
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-04-11 08:17:56 +02:00
|
|
|
name_owner = nm_str_not_empty(name_owner);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-04-11 08:17:56 +02:00
|
|
|
is_changed = !nm_streq0(priv->name_owner, name_owner);
|
|
|
|
|
if (is_changed) {
|
|
|
|
|
old_name_owner = g_steal_pointer(&priv->name_owner);
|
|
|
|
|
priv->name_owner = g_strdup(name_owner);
|
|
|
|
|
} else {
|
|
|
|
|
if (!is_initial)
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-04-11 08:17:56 +02:00
|
|
|
if (!priv->name_owner) {
|
|
|
|
|
if (is_initial)
|
|
|
|
|
_LOGT("name-owner: polkit not running");
|
|
|
|
|
else
|
|
|
|
|
_LOGT("name-owner: polkit stopped (was %s)", old_name_owner);
|
|
|
|
|
} else {
|
|
|
|
|
if (is_initial)
|
|
|
|
|
_LOGT("name-owner: polkit is running (now %s)", priv->name_owner);
|
|
|
|
|
else if (old_name_owner)
|
|
|
|
|
_LOGT("name-owner: polkit restarted (now %s, was %s)",
|
|
|
|
|
priv->name_owner,
|
|
|
|
|
old_name_owner);
|
|
|
|
|
else
|
|
|
|
|
_LOGT("name-owner: polkit started (now %s)", priv->name_owner);
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-04-11 08:17:56 +02:00
|
|
|
if (priv->name_owner)
|
|
|
|
|
_emit_changed_signal(self);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_name_owner_changed_cb(GDBusConnection *connection,
|
2021-11-09 13:28:54 +01:00
|
|
|
const char *sender_name,
|
|
|
|
|
const char *object_path,
|
|
|
|
|
const char *interface_name,
|
|
|
|
|
const char *signal_name,
|
|
|
|
|
GVariant *parameters,
|
2020-04-11 08:17:56 +02:00
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMAuthManager *self = user_data;
|
2021-11-09 13:28:54 +01:00
|
|
|
const char *new_owner;
|
2020-04-11 08:17:56 +02:00
|
|
|
|
|
|
|
|
if (!g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sss)")))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
g_variant_get(parameters, "(&s&s&s)", NULL, NULL, &new_owner);
|
|
|
|
|
|
|
|
|
|
_name_owner_changed(self, new_owner, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_name_owner_get_cb(const char *name_owner, GError *error, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
if (!nm_utils_error_is_cancelled(error))
|
|
|
|
|
_name_owner_changed(user_data, name_owner, TRUE);
|
2014-08-14 13:34:57 +02:00
|
|
|
}
|
2014-08-19 18:56:23 +02:00
|
|
|
|
2014-08-14 13:34:57 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
NMAuthManager *
|
|
|
|
|
nm_auth_manager_get()
|
|
|
|
|
{
|
2015-01-05 18:26:26 +01:00
|
|
|
g_return_val_if_fail(singleton_instance, NULL);
|
2014-08-14 13:34:57 +02:00
|
|
|
|
2015-01-05 18:26:26 +01:00
|
|
|
return singleton_instance;
|
2014-08-14 13:34:57 +02:00
|
|
|
}
|
|
|
|
|
|
2018-04-09 13:27:03 +02:00
|
|
|
void
|
|
|
|
|
nm_auth_manager_force_shutdown(NMAuthManager *self)
|
|
|
|
|
{
|
|
|
|
|
NMAuthManagerPrivate *priv;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail(NM_IS_AUTH_MANAGER(self));
|
|
|
|
|
|
|
|
|
|
priv = NM_AUTH_MANAGER_GET_PRIVATE(self);
|
|
|
|
|
|
2020-04-11 08:17:56 +02:00
|
|
|
/* FIXME(shutdown): ensure we properly call this API during shutdown as
|
|
|
|
|
* described next. */
|
|
|
|
|
|
2018-04-09 13:27:03 +02:00
|
|
|
/* while we have pending requests (NMAuthManagerCallId), the instance
|
|
|
|
|
* is kept alive.
|
|
|
|
|
*
|
2020-04-11 08:17:56 +02:00
|
|
|
* Even if the caller cancels all pending call-ids, we still need to keep
|
2018-04-09 13:27:03 +02:00
|
|
|
* a reference to self, in order to handle pending CancelCheckAuthorization
|
|
|
|
|
* requests.
|
|
|
|
|
*
|
2020-04-11 08:17:56 +02:00
|
|
|
* To do a coordinated shutdown, do the following:
|
2018-04-09 13:27:03 +02:00
|
|
|
* - cancel all pending NMAuthManagerCallId requests.
|
|
|
|
|
* - ensure everybody unrefs the NMAuthManager instance. If by that, the instance
|
|
|
|
|
* gets destroyed, the shutdown already completed successfully.
|
|
|
|
|
* - Otherwise, the object is kept alive by pending CancelCheckAuthorization requests.
|
|
|
|
|
* wait a certain timeout (1 second) for all requests to complete (by watching
|
|
|
|
|
* for destruction of NMAuthManager).
|
|
|
|
|
* - if that doesn't happen within timeout, issue nm_auth_manager_force_shutdown() and
|
|
|
|
|
* wait longer. After that, soon the instance should be destroyed and you
|
|
|
|
|
* did a successful shutdown.
|
|
|
|
|
* - if the instance was still not destroyed within a short timeout, you leaked
|
|
|
|
|
* resources. You cannot properly shutdown.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
priv->shutting_down = TRUE;
|
2020-04-11 08:17:56 +02:00
|
|
|
nm_clear_g_cancellable(&priv->main_cancellable);
|
2018-04-09 13:27:03 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-14 13:34:57 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
|
|
|
|
{
|
2020-02-14 10:50:25 +01:00
|
|
|
NMAuthManagerPrivate *priv = NM_AUTH_MANAGER_GET_PRIVATE(object);
|
2019-12-10 08:51:03 +01:00
|
|
|
int v_int;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-08-14 13:34:57 +02:00
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_POLKIT_ENABLED:
|
2017-01-15 12:15:58 +01:00
|
|
|
/* construct-only */
|
2019-12-10 08:51:03 +01:00
|
|
|
v_int = g_value_get_int(value);
|
|
|
|
|
g_return_if_fail(NM_IN_SET(v_int,
|
|
|
|
|
NM_AUTH_POLKIT_MODE_ROOT_ONLY,
|
|
|
|
|
NM_AUTH_POLKIT_MODE_ALLOW_ALL,
|
|
|
|
|
NM_AUTH_POLKIT_MODE_USE_POLKIT));
|
|
|
|
|
priv->auth_polkit_mode = v_int;
|
|
|
|
|
nm_assert(priv->auth_polkit_mode == v_int);
|
2014-08-14 13:34:57 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2014-08-14 13:34:57 +02:00
|
|
|
static void
|
|
|
|
|
nm_auth_manager_init(NMAuthManager *self)
|
|
|
|
|
{
|
2018-04-09 13:27:03 +02:00
|
|
|
NMAuthManagerPrivate *priv = NM_AUTH_MANAGER_GET_PRIVATE(self);
|
|
|
|
|
|
|
|
|
|
c_list_init(&priv->calls_lst_head);
|
2019-12-10 08:51:03 +01:00
|
|
|
priv->auth_polkit_mode = NM_AUTH_POLKIT_MODE_ROOT_ONLY;
|
2014-08-14 13:34:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
constructed(GObject *object)
|
|
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMAuthManager *self = NM_AUTH_MANAGER(object);
|
2014-08-14 13:34:57 +02:00
|
|
|
NMAuthManagerPrivate *priv = NM_AUTH_MANAGER_GET_PRIVATE(self);
|
2019-05-04 11:03:35 +02:00
|
|
|
NMLogLevel logl = LOGL_DEBUG;
|
2021-11-09 13:28:54 +01:00
|
|
|
const char *create_message;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-08-14 13:34:57 +02:00
|
|
|
G_OBJECT_CLASS(nm_auth_manager_parent_class)->constructed(object);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-12-10 08:51:03 +01:00
|
|
|
if (priv->auth_polkit_mode != NM_AUTH_POLKIT_MODE_USE_POLKIT) {
|
|
|
|
|
if (priv->auth_polkit_mode == NM_AUTH_POLKIT_MODE_ROOT_ONLY)
|
|
|
|
|
create_message = "polkit disabled, root-only";
|
|
|
|
|
else
|
|
|
|
|
create_message = "polkit disabled, allow-all";
|
2019-05-04 11:03:35 +02:00
|
|
|
goto out;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-05-04 12:46:17 +02:00
|
|
|
priv->dbus_connection = nm_g_object_ref(NM_MAIN_DBUS_CONNECTION_GET);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-05-04 12:46:17 +02:00
|
|
|
if (!priv->dbus_connection) {
|
2019-05-04 11:03:35 +02:00
|
|
|
/* This warrants an info level message. */
|
|
|
|
|
logl = LOGL_INFO;
|
2019-12-10 08:51:03 +01:00
|
|
|
create_message =
|
|
|
|
|
"D-Bus connection not available. Polkit is disabled and only root will be authorized.";
|
|
|
|
|
priv->auth_polkit_mode = NM_AUTH_POLKIT_MODE_ROOT_ONLY;
|
2019-05-04 11:03:35 +02:00
|
|
|
goto out;
|
2014-08-14 13:34:57 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-04-11 08:17:56 +02:00
|
|
|
priv->main_cancellable = g_cancellable_new();
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-04-11 08:17:56 +02:00
|
|
|
priv->name_owner_changed_id =
|
|
|
|
|
nm_dbus_connection_signal_subscribe_name_owner_changed(priv->dbus_connection,
|
|
|
|
|
POLKIT_SERVICE,
|
|
|
|
|
_name_owner_changed_cb,
|
|
|
|
|
self,
|
|
|
|
|
NULL);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-04-11 08:17:56 +02:00
|
|
|
priv->changed_id = g_dbus_connection_signal_subscribe(priv->dbus_connection,
|
|
|
|
|
POLKIT_SERVICE,
|
|
|
|
|
POLKIT_INTERFACE,
|
|
|
|
|
"Changed",
|
|
|
|
|
POLKIT_OBJECT_PATH,
|
|
|
|
|
NULL,
|
|
|
|
|
G_DBUS_SIGNAL_FLAGS_NONE,
|
|
|
|
|
changed_signal_cb,
|
|
|
|
|
self,
|
|
|
|
|
NULL);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-04-11 08:17:56 +02:00
|
|
|
nm_dbus_connection_call_get_name_owner(priv->dbus_connection,
|
|
|
|
|
POLKIT_SERVICE,
|
|
|
|
|
-1,
|
|
|
|
|
priv->main_cancellable,
|
|
|
|
|
_name_owner_get_cb,
|
|
|
|
|
self);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-05-04 11:03:35 +02:00
|
|
|
create_message = "polkit enabled";
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
_NMLOG(logl, "create auth-manager: %s", create_message);
|
2014-08-14 13:34:57 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
NMAuthManager *
|
2019-12-10 08:51:03 +01:00
|
|
|
nm_auth_manager_setup(NMAuthPolkitMode auth_polkit_mode)
|
2016-09-29 13:49:01 +02:00
|
|
|
{
|
|
|
|
|
NMAuthManager *self;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail(!singleton_instance, singleton_instance);
|
2019-12-10 08:51:03 +01:00
|
|
|
nm_assert(NM_IN_SET(auth_polkit_mode,
|
|
|
|
|
NM_AUTH_POLKIT_MODE_ROOT_ONLY,
|
|
|
|
|
NM_AUTH_POLKIT_MODE_ALLOW_ALL,
|
|
|
|
|
NM_AUTH_POLKIT_MODE_USE_POLKIT));
|
2016-09-29 13:49:01 +02:00
|
|
|
|
|
|
|
|
self = g_object_new(NM_TYPE_AUTH_MANAGER,
|
2019-12-10 08:51:03 +01:00
|
|
|
NM_AUTH_MANAGER_POLKIT_ENABLED,
|
|
|
|
|
(int) auth_polkit_mode,
|
2016-09-29 13:49:01 +02:00
|
|
|
NULL);
|
|
|
|
|
_LOGD("set instance");
|
|
|
|
|
|
|
|
|
|
singleton_instance = self;
|
|
|
|
|
nm_singleton_instance_register();
|
|
|
|
|
|
2019-05-05 15:40:04 +02:00
|
|
|
nm_log_dbg(LOGD_CORE,
|
|
|
|
|
"setup %s singleton (" NM_HASH_OBFUSCATE_PTR_FMT ")",
|
|
|
|
|
"NMAuthManager",
|
|
|
|
|
NM_HASH_OBFUSCATE_PTR(singleton_instance));
|
2016-09-29 13:49:01 +02:00
|
|
|
|
|
|
|
|
return self;
|
|
|
|
|
}
|
2014-08-14 13:34:57 +02:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
dispose(GObject *object)
|
|
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMAuthManager *self = NM_AUTH_MANAGER(object);
|
2014-08-14 13:34:57 +02:00
|
|
|
NMAuthManagerPrivate *priv = NM_AUTH_MANAGER_GET_PRIVATE(self);
|
|
|
|
|
|
|
|
|
|
_LOGD("dispose");
|
|
|
|
|
|
2018-04-17 16:01:36 +02:00
|
|
|
nm_assert(c_list_is_empty(&priv->calls_lst_head));
|
2018-04-09 13:27:03 +02:00
|
|
|
|
|
|
|
|
priv->disposing = TRUE;
|
2014-08-14 13:34:57 +02:00
|
|
|
|
2020-04-11 08:17:56 +02:00
|
|
|
nm_clear_g_cancellable(&priv->main_cancellable);
|
2014-08-14 13:34:57 +02:00
|
|
|
|
2019-05-04 12:46:17 +02:00
|
|
|
nm_clear_g_dbus_connection_signal(priv->dbus_connection, &priv->name_owner_changed_id);
|
2020-04-11 08:17:56 +02:00
|
|
|
|
|
|
|
|
nm_clear_g_dbus_connection_signal(priv->dbus_connection, &priv->changed_id);
|
2014-08-14 13:34:57 +02:00
|
|
|
|
|
|
|
|
G_OBJECT_CLASS(nm_auth_manager_parent_class)->dispose(object);
|
2019-05-04 12:46:17 +02:00
|
|
|
|
|
|
|
|
g_clear_object(&priv->dbus_connection);
|
2020-04-11 08:17:56 +02:00
|
|
|
|
|
|
|
|
nm_clear_g_free(&priv->name_owner);
|
2014-08-14 13:34:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
nm_auth_manager_class_init(NMAuthManagerClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS(klass);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-08-14 13:34:57 +02:00
|
|
|
object_class->set_property = set_property;
|
|
|
|
|
object_class->constructed = constructed;
|
|
|
|
|
object_class->dispose = dispose;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
obj_properties[PROP_POLKIT_ENABLED] =
|
2019-12-10 08:51:03 +01:00
|
|
|
g_param_spec_int(NM_AUTH_MANAGER_POLKIT_ENABLED,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
NM_AUTH_POLKIT_MODE_ROOT_ONLY,
|
|
|
|
|
NM_AUTH_POLKIT_MODE_USE_POLKIT,
|
|
|
|
|
NM_AUTH_POLKIT_MODE_USE_POLKIT,
|
|
|
|
|
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-08-14 13:34:57 +02:00
|
|
|
signals[CHANGED_SIGNAL] = g_signal_new(NM_AUTH_MANAGER_SIGNAL_CHANGED,
|
|
|
|
|
NM_TYPE_AUTH_MANAGER,
|
|
|
|
|
G_SIGNAL_RUN_LAST,
|
2018-04-09 13:27:03 +02:00
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
2014-08-14 13:34:57 +02:00
|
|
|
g_cclosure_marshal_VOID__VOID,
|
2018-04-09 13:27:03 +02:00
|
|
|
G_TYPE_NONE,
|
|
|
|
|
0);
|
2014-08-14 13:34:57 +02:00
|
|
|
}
|