core: add nm_bus_manager_ensure_root() helper
This commit is contained in:

committed by
Beniamino Galvani

parent
3d30004710
commit
d23f43f2b9
@@ -533,6 +533,36 @@ nm_bus_manager_get_caller_info_from_message (NMBusManager *self,
|
||||
return _get_caller_info (self, NULL, connection, message, out_sender, out_uid, out_pid);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_bus_manager_ensure_root (NMBusManager *self,
|
||||
GDBusMethodInvocation *context,
|
||||
GQuark error_domain,
|
||||
int error_code)
|
||||
{
|
||||
gulong caller_uid;
|
||||
GError *error = NULL;
|
||||
|
||||
g_return_val_if_fail (NM_IS_BUS_MANAGER (self), FALSE);
|
||||
g_return_val_if_fail (G_IS_DBUS_METHOD_INVOCATION (context), FALSE);
|
||||
|
||||
if (!nm_bus_manager_get_caller_info (self, context, NULL, &caller_uid, NULL)) {
|
||||
error = g_error_new_literal (error_domain,
|
||||
error_code,
|
||||
"Unable to determine request UID.");
|
||||
g_dbus_method_invocation_take_error (context, error);
|
||||
return FALSE;
|
||||
}
|
||||
if (caller_uid != 0) {
|
||||
error = g_error_new_literal (error_domain,
|
||||
error_code,
|
||||
"Permission denied");
|
||||
g_dbus_method_invocation_take_error (context, error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_bus_manager_get_unix_user (NMBusManager *self,
|
||||
const char *sender,
|
||||
|
@@ -68,6 +68,11 @@ gboolean nm_bus_manager_get_caller_info (NMBusManager *self,
|
||||
gulong *out_uid,
|
||||
gulong *out_pid);
|
||||
|
||||
gboolean nm_bus_manager_ensure_root (NMBusManager *self,
|
||||
GDBusMethodInvocation *context,
|
||||
GQuark error_domain,
|
||||
int error_code);
|
||||
|
||||
const char *nm_bus_manager_connection_get_private_name (NMBusManager *self,
|
||||
GDBusConnection *connection);
|
||||
|
||||
|
@@ -1512,31 +1512,6 @@ impl_settings_add_connection_unsaved (NMSettings *self,
|
||||
impl_settings_add_connection_helper (self, context, settings, FALSE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
ensure_root (NMBusManager *dbus_mgr,
|
||||
GDBusMethodInvocation *context)
|
||||
{
|
||||
gulong caller_uid;
|
||||
GError *error = NULL;
|
||||
|
||||
if (!nm_bus_manager_get_caller_info (dbus_mgr, context, NULL, &caller_uid, NULL)) {
|
||||
error = g_error_new_literal (NM_SETTINGS_ERROR,
|
||||
NM_SETTINGS_ERROR_PERMISSION_DENIED,
|
||||
"Unable to determine request UID.");
|
||||
g_dbus_method_invocation_take_error (context, error);
|
||||
return FALSE;
|
||||
}
|
||||
if (caller_uid != 0) {
|
||||
error = g_error_new_literal (NM_SETTINGS_ERROR,
|
||||
NM_SETTINGS_ERROR_PERMISSION_DENIED,
|
||||
"Permission denied");
|
||||
g_dbus_method_invocation_take_error (context, error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
impl_settings_load_connections (NMSettings *self,
|
||||
GDBusMethodInvocation *context,
|
||||
@@ -1547,7 +1522,8 @@ impl_settings_load_connections (NMSettings *self,
|
||||
GSList *iter;
|
||||
int i;
|
||||
|
||||
if (!ensure_root (nm_bus_manager_get (), context))
|
||||
if (!nm_bus_manager_ensure_root (nm_bus_manager_get (), context,
|
||||
NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_PERMISSION_DENIED))
|
||||
return;
|
||||
|
||||
failures = g_ptr_array_new ();
|
||||
@@ -1583,7 +1559,8 @@ impl_settings_reload_connections (NMSettings *self,
|
||||
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
|
||||
GSList *iter;
|
||||
|
||||
if (!ensure_root (nm_bus_manager_get (), context))
|
||||
if (!nm_bus_manager_ensure_root (nm_bus_manager_get (), context,
|
||||
NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_PERMISSION_DENIED))
|
||||
return;
|
||||
|
||||
for (iter = priv->plugins; iter; iter = g_slist_next (iter)) {
|
||||
|
Reference in New Issue
Block a user