event: move event filtering to daemon (regression fix)

https://bugzilla.redhat.com/show_bug.cgi?id=1058839

Commit f9f56340 for CVE-2014-0028 almost had the right idea - we
need to check the ACL rules to filter which events to send.  But
it overlooked one thing: the event dispatch queue is running in
the main loop thread, and therefore does not normally have a
current virIdentityPtr.  But filter checks can be based on current
identity, so when libvirtd.conf contains access_drivers=["polkit"],
we ended up rejecting access for EVERY event due to failure to
look up the current identity, even if it should have been allowed.

Furthermore, even for events that are triggered by API calls, it
is important to remember that the point of events is that they can
be copied across multiple connections, which may have separate
identities and permissions.  So even if events were dispatched
from a context where we have an identity, we must change to the
correct identity of the connection that will be receiving the
event, rather than basing a decision on the context that triggered
the event, when deciding whether to filter an event to a
particular connection.

If there were an easy way to get from virConnectPtr to the
appropriate virIdentityPtr, then object_event.c could adjust the
identity prior to checking whether to dispatch an event.  But
setting up that back-reference is a bit invasive.  Instead, it
is easier to delay the filtering check until lower down the
stack, at the point where we have direct access to the RPC
client object that owns an identity.  As such, this patch ends
up reverting a large portion of the framework of commit f9f56340.
We also have to teach 'make check' to special-case the fact that
the event registration filtering is done at the point of dispatch,
rather than the point of registration.  Note that even though we
don't actually use virConnectDomainEventRegisterCheckACL (because
the RegisterAny variant is sufficient), we still generate the
function for the purposes of documenting that the filtering
takes place.

Also note that I did not entirely delete the notion of a filter
from object_event.c; I still plan on using that for my upcoming
patch series for qemu monitor events in libvirt-qemu.so.  In
other words, while this patch changes ACL filtering to live in
remote.c and therefore we have no current client of the filtering
in object_event.c, the notion of filtering in object_event.c is
still useful down the road.

* src/check-aclrules.pl: Exempt event registration from having to
pass checkACL filter down call stack.
* daemon/remote.c (remoteRelayDomainEventCheckACL)
(remoteRelayNetworkEventCheckACL): New functions.
(remoteRelay*Event*): Use new functions.
* src/conf/domain_event.h (virDomainEventStateRegister)
(virDomainEventStateRegisterID): Drop unused parameter.
* src/conf/network_event.h (virNetworkEventStateRegisterID):
Likewise.
* src/conf/domain_event.c (virDomainEventFilter): Delete unused
function.
* src/conf/network_event.c (virNetworkEventFilter): Likewise.
* src/libxl/libxl_driver.c: Adjust caller.
* src/lxc/lxc_driver.c: Likewise.
* src/network/bridge_driver.c: Likewise.
* src/qemu/qemu_driver.c: Likewise.
* src/remote/remote_driver.c: Likewise.
* src/test/test_driver.c: Likewise.
* src/uml/uml_driver.c: Likewise.
* src/vbox/vbox_tmpl.c: Likewise.
* src/xen/xen_driver.c: Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 11f20e43f1)

Conflicts:
	daemon/remote.c - not backporting network events
	src/conf/network_event.c - likewise
	src/conf/network_event.h - likewise
	src/network/bridge_driver.c - likewise
	src/conf/domain_event.c - revert back to pre-CVE state
	src/conf/domain_event.h - likewise
	src/libxl/libxl_driver.c - likewise
	src/lxc/lxc_driver.c - likewise
	src/remote/remote_driver.c - likewise
	src/test/test_driver.c - likewise
	src/uml/uml_driver.c - likewise
	src/xen/xen_driver.c - likewise
This commit is contained in:
Eric Blake 2014-01-28 14:50:02 -07:00
parent f3aa956f32
commit b19f326964
12 changed files with 153 additions and 177 deletions

View File

@ -49,6 +49,8 @@
#include "qemu_protocol.h" #include "qemu_protocol.h"
#include "lxc_protocol.h" #include "lxc_protocol.h"
#include "virstring.h" #include "virstring.h"
#include "domain_conf.h"
#include "viraccessapicheck.h"
#define VIR_FROM_THIS VIR_FROM_RPC #define VIR_FROM_THIS VIR_FROM_RPC
@ -114,16 +116,45 @@ remoteDispatchDomainEventSend(virNetServerClientPtr client,
xdrproc_t proc, xdrproc_t proc,
void *data); void *data);
static int remoteRelayDomainEventLifecycle(virConnectPtr conn ATTRIBUTE_UNUSED,
virDomainPtr dom, static bool
int event, remoteRelayDomainEventCheckACL(virNetServerClientPtr client,
int detail, virConnectPtr conn, virDomainPtr dom)
void *opaque) {
virDomainDef def;
virIdentityPtr identity = NULL;
bool ret = false;
/* For now, we just create a virDomainDef with enough contents to
* satisfy what viraccessdriverpolkit.c references. This is a bit
* fragile, but I don't know of anything better. */
def.name = dom->name;
memcpy(def.uuid, dom->uuid, VIR_UUID_BUFLEN);
if (!(identity = virNetServerClientGetIdentity(client)))
goto cleanup;
if (virIdentitySetCurrent(identity) < 0)
goto cleanup;
ret = virConnectDomainEventRegisterAnyCheckACL(conn, &def);
cleanup:
ignore_value(virIdentitySetCurrent(NULL));
virObjectUnref(identity);
return ret;
}
static int
remoteRelayDomainEventLifecycle(virConnectPtr conn,
virDomainPtr dom,
int event,
int detail,
void *opaque)
{ {
virNetServerClientPtr client = opaque; virNetServerClientPtr client = opaque;
remote_domain_event_lifecycle_msg data; remote_domain_event_lifecycle_msg data;
if (!client) if (!client || !remoteRelayDomainEventCheckACL(client, conn, dom))
return -1; return -1;
VIR_DEBUG("Relaying domain lifecycle event %d %d", event, detail); VIR_DEBUG("Relaying domain lifecycle event %d %d", event, detail);
@ -141,14 +172,15 @@ static int remoteRelayDomainEventLifecycle(virConnectPtr conn ATTRIBUTE_UNUSED,
return 0; return 0;
} }
static int remoteRelayDomainEventReboot(virConnectPtr conn ATTRIBUTE_UNUSED, static int
virDomainPtr dom, remoteRelayDomainEventReboot(virConnectPtr conn,
void *opaque) virDomainPtr dom,
void *opaque)
{ {
virNetServerClientPtr client = opaque; virNetServerClientPtr client = opaque;
remote_domain_event_reboot_msg data; remote_domain_event_reboot_msg data;
if (!client) if (!client || !remoteRelayDomainEventCheckACL(client, conn, dom))
return -1; return -1;
VIR_DEBUG("Relaying domain reboot event %s %d", dom->name, dom->id); VIR_DEBUG("Relaying domain reboot event %s %d", dom->name, dom->id);
@ -165,15 +197,16 @@ static int remoteRelayDomainEventReboot(virConnectPtr conn ATTRIBUTE_UNUSED,
} }
static int remoteRelayDomainEventRTCChange(virConnectPtr conn ATTRIBUTE_UNUSED, static int
virDomainPtr dom, remoteRelayDomainEventRTCChange(virConnectPtr conn,
long long offset, virDomainPtr dom,
void *opaque) long long offset,
void *opaque)
{ {
virNetServerClientPtr client = opaque; virNetServerClientPtr client = opaque;
remote_domain_event_rtc_change_msg data; remote_domain_event_rtc_change_msg data;
if (!client) if (!client || !remoteRelayDomainEventCheckACL(client, conn, dom))
return -1; return -1;
VIR_DEBUG("Relaying domain rtc change event %s %d %lld", dom->name, dom->id, offset); VIR_DEBUG("Relaying domain rtc change event %s %d %lld", dom->name, dom->id, offset);
@ -191,15 +224,16 @@ static int remoteRelayDomainEventRTCChange(virConnectPtr conn ATTRIBUTE_UNUSED,
} }
static int remoteRelayDomainEventWatchdog(virConnectPtr conn ATTRIBUTE_UNUSED, static int
virDomainPtr dom, remoteRelayDomainEventWatchdog(virConnectPtr conn,
int action, virDomainPtr dom,
void *opaque) int action,
void *opaque)
{ {
virNetServerClientPtr client = opaque; virNetServerClientPtr client = opaque;
remote_domain_event_watchdog_msg data; remote_domain_event_watchdog_msg data;
if (!client) if (!client || !remoteRelayDomainEventCheckACL(client, conn, dom))
return -1; return -1;
VIR_DEBUG("Relaying domain watchdog event %s %d %d", dom->name, dom->id, action); VIR_DEBUG("Relaying domain watchdog event %s %d %d", dom->name, dom->id, action);
@ -217,17 +251,18 @@ static int remoteRelayDomainEventWatchdog(virConnectPtr conn ATTRIBUTE_UNUSED,
} }
static int remoteRelayDomainEventIOError(virConnectPtr conn ATTRIBUTE_UNUSED, static int
virDomainPtr dom, remoteRelayDomainEventIOError(virConnectPtr conn,
const char *srcPath, virDomainPtr dom,
const char *devAlias, const char *srcPath,
int action, const char *devAlias,
void *opaque) int action,
void *opaque)
{ {
virNetServerClientPtr client = opaque; virNetServerClientPtr client = opaque;
remote_domain_event_io_error_msg data; remote_domain_event_io_error_msg data;
if (!client) if (!client || !remoteRelayDomainEventCheckACL(client, conn, dom))
return -1; return -1;
VIR_DEBUG("Relaying domain io error %s %d %s %s %d", dom->name, dom->id, srcPath, devAlias, action); VIR_DEBUG("Relaying domain io error %s %d %s %s %d", dom->name, dom->id, srcPath, devAlias, action);
@ -252,18 +287,19 @@ error:
} }
static int remoteRelayDomainEventIOErrorReason(virConnectPtr conn ATTRIBUTE_UNUSED, static int
virDomainPtr dom, remoteRelayDomainEventIOErrorReason(virConnectPtr conn,
const char *srcPath, virDomainPtr dom,
const char *devAlias, const char *srcPath,
int action, const char *devAlias,
const char *reason, int action,
void *opaque) const char *reason,
void *opaque)
{ {
virNetServerClientPtr client = opaque; virNetServerClientPtr client = opaque;
remote_domain_event_io_error_reason_msg data; remote_domain_event_io_error_reason_msg data;
if (!client) if (!client || !remoteRelayDomainEventCheckACL(client, conn, dom))
return -1; return -1;
VIR_DEBUG("Relaying domain io error %s %d %s %s %d %s", VIR_DEBUG("Relaying domain io error %s %d %s %s %d %s",
@ -293,20 +329,21 @@ error:
} }
static int remoteRelayDomainEventGraphics(virConnectPtr conn ATTRIBUTE_UNUSED, static int
virDomainPtr dom, remoteRelayDomainEventGraphics(virConnectPtr conn,
int phase, virDomainPtr dom,
virDomainEventGraphicsAddressPtr local, int phase,
virDomainEventGraphicsAddressPtr remote, virDomainEventGraphicsAddressPtr local,
const char *authScheme, virDomainEventGraphicsAddressPtr remote,
virDomainEventGraphicsSubjectPtr subject, const char *authScheme,
void *opaque) virDomainEventGraphicsSubjectPtr subject,
void *opaque)
{ {
virNetServerClientPtr client = opaque; virNetServerClientPtr client = opaque;
remote_domain_event_graphics_msg data; remote_domain_event_graphics_msg data;
size_t i; size_t i;
if (!client) if (!client || !remoteRelayDomainEventCheckACL(client, conn, dom))
return -1; return -1;
VIR_DEBUG("Relaying domain graphics event %s %d %d - %d %s %s - %d %s %s - %s", dom->name, dom->id, phase, VIR_DEBUG("Relaying domain graphics event %s %d %d - %d %s %s - %d %s %s - %s", dom->name, dom->id, phase,
@ -364,17 +401,18 @@ error:
return -1; return -1;
} }
static int remoteRelayDomainEventBlockJob(virConnectPtr conn ATTRIBUTE_UNUSED, static int
virDomainPtr dom, remoteRelayDomainEventBlockJob(virConnectPtr conn,
const char *path, virDomainPtr dom,
int type, const char *path,
int status, int type,
void *opaque) int status,
void *opaque)
{ {
virNetServerClientPtr client = opaque; virNetServerClientPtr client = opaque;
remote_domain_event_block_job_msg data; remote_domain_event_block_job_msg data;
if (!client) if (!client || !remoteRelayDomainEventCheckACL(client, conn, dom))
return -1; return -1;
VIR_DEBUG("Relaying domain block job event %s %d %s %i, %i", VIR_DEBUG("Relaying domain block job event %s %d %s %i, %i",
@ -399,14 +437,15 @@ error:
} }
static int remoteRelayDomainEventControlError(virConnectPtr conn ATTRIBUTE_UNUSED, static int
virDomainPtr dom, remoteRelayDomainEventControlError(virConnectPtr conn,
void *opaque) virDomainPtr dom,
void *opaque)
{ {
virNetServerClientPtr client = opaque; virNetServerClientPtr client = opaque;
remote_domain_event_control_error_msg data; remote_domain_event_control_error_msg data;
if (!client) if (!client || !remoteRelayDomainEventCheckACL(client, conn, dom))
return -1; return -1;
VIR_DEBUG("Relaying domain control error %s %d", dom->name, dom->id); VIR_DEBUG("Relaying domain control error %s %d", dom->name, dom->id);
@ -423,19 +462,20 @@ static int remoteRelayDomainEventControlError(virConnectPtr conn ATTRIBUTE_UNUSE
} }
static int remoteRelayDomainEventDiskChange(virConnectPtr conn ATTRIBUTE_UNUSED, static int
virDomainPtr dom, remoteRelayDomainEventDiskChange(virConnectPtr conn,
const char *oldSrcPath, virDomainPtr dom,
const char *newSrcPath, const char *oldSrcPath,
const char *devAlias, const char *newSrcPath,
int reason, const char *devAlias,
void *opaque) int reason,
void *opaque)
{ {
virNetServerClientPtr client = opaque; virNetServerClientPtr client = opaque;
remote_domain_event_disk_change_msg data; remote_domain_event_disk_change_msg data;
char **oldSrcPath_p = NULL, **newSrcPath_p = NULL; char **oldSrcPath_p = NULL, **newSrcPath_p = NULL;
if (!client) if (!client || !remoteRelayDomainEventCheckACL(client, conn, dom))
return -1; return -1;
VIR_DEBUG("Relaying domain %s %d disk change %s %s %s %d", VIR_DEBUG("Relaying domain %s %d disk change %s %s %s %d",
@ -474,15 +514,17 @@ error:
} }
static int remoteRelayDomainEventTrayChange(virConnectPtr conn ATTRIBUTE_UNUSED, static int
virDomainPtr dom, remoteRelayDomainEventTrayChange(virConnectPtr conn,
const char *devAlias, virDomainPtr dom,
int reason, const char *devAlias,
void *opaque) { int reason,
void *opaque)
{
virNetServerClientPtr client = opaque; virNetServerClientPtr client = opaque;
remote_domain_event_tray_change_msg data; remote_domain_event_tray_change_msg data;
if (!client) if (!client || !remoteRelayDomainEventCheckACL(client, conn, dom))
return -1; return -1;
VIR_DEBUG("Relaying domain %s %d tray change devAlias: %s reason: %d", VIR_DEBUG("Relaying domain %s %d tray change devAlias: %s reason: %d",
@ -504,14 +546,16 @@ static int remoteRelayDomainEventTrayChange(virConnectPtr conn ATTRIBUTE_UNUSED,
return 0; return 0;
} }
static int remoteRelayDomainEventPMWakeup(virConnectPtr conn ATTRIBUTE_UNUSED, static int
virDomainPtr dom, remoteRelayDomainEventPMWakeup(virConnectPtr conn,
int reason ATTRIBUTE_UNUSED, virDomainPtr dom,
void *opaque) { int reason ATTRIBUTE_UNUSED,
void *opaque)
{
virNetServerClientPtr client = opaque; virNetServerClientPtr client = opaque;
remote_domain_event_pmwakeup_msg data; remote_domain_event_pmwakeup_msg data;
if (!client) if (!client || !remoteRelayDomainEventCheckACL(client, conn, dom))
return -1; return -1;
VIR_DEBUG("Relaying domain %s %d system pmwakeup", dom->name, dom->id); VIR_DEBUG("Relaying domain %s %d system pmwakeup", dom->name, dom->id);
@ -527,14 +571,16 @@ static int remoteRelayDomainEventPMWakeup(virConnectPtr conn ATTRIBUTE_UNUSED,
return 0; return 0;
} }
static int remoteRelayDomainEventPMSuspend(virConnectPtr conn ATTRIBUTE_UNUSED, static int
virDomainPtr dom, remoteRelayDomainEventPMSuspend(virConnectPtr conn,
int reason ATTRIBUTE_UNUSED, virDomainPtr dom,
void *opaque) { int reason ATTRIBUTE_UNUSED,
void *opaque)
{
virNetServerClientPtr client = opaque; virNetServerClientPtr client = opaque;
remote_domain_event_pmsuspend_msg data; remote_domain_event_pmsuspend_msg data;
if (!client) if (!client || !remoteRelayDomainEventCheckACL(client, conn, dom))
return -1; return -1;
VIR_DEBUG("Relaying domain %s %d system pmsuspend", dom->name, dom->id); VIR_DEBUG("Relaying domain %s %d system pmsuspend", dom->name, dom->id);
@ -551,7 +597,7 @@ static int remoteRelayDomainEventPMSuspend(virConnectPtr conn ATTRIBUTE_UNUSED,
} }
static int static int
remoteRelayDomainEventBalloonChange(virConnectPtr conn ATTRIBUTE_UNUSED, remoteRelayDomainEventBalloonChange(virConnectPtr conn,
virDomainPtr dom, virDomainPtr dom,
unsigned long long actual, unsigned long long actual,
void *opaque) void *opaque)
@ -559,7 +605,7 @@ remoteRelayDomainEventBalloonChange(virConnectPtr conn ATTRIBUTE_UNUSED,
virNetServerClientPtr client = opaque; virNetServerClientPtr client = opaque;
remote_domain_event_balloon_change_msg data; remote_domain_event_balloon_change_msg data;
if (!client) if (!client || !remoteRelayDomainEventCheckACL(client, conn, dom))
return -1; return -1;
VIR_DEBUG("Relaying domain balloon change event %s %d %lld", dom->name, dom->id, actual); VIR_DEBUG("Relaying domain balloon change event %s %d %lld", dom->name, dom->id, actual);
@ -577,14 +623,16 @@ remoteRelayDomainEventBalloonChange(virConnectPtr conn ATTRIBUTE_UNUSED,
} }
static int remoteRelayDomainEventPMSuspendDisk(virConnectPtr conn ATTRIBUTE_UNUSED, static int
virDomainPtr dom, remoteRelayDomainEventPMSuspendDisk(virConnectPtr conn,
int reason ATTRIBUTE_UNUSED, virDomainPtr dom,
void *opaque) { int reason ATTRIBUTE_UNUSED,
void *opaque)
{
virNetServerClientPtr client = opaque; virNetServerClientPtr client = opaque;
remote_domain_event_pmsuspend_disk_msg data; remote_domain_event_pmsuspend_disk_msg data;
if (!client) if (!client || !remoteRelayDomainEventCheckACL(client, conn, dom))
return -1; return -1;
VIR_DEBUG("Relaying domain %s %d system pmsuspend-disk", dom->name, dom->id); VIR_DEBUG("Relaying domain %s %d system pmsuspend-disk", dom->name, dom->id);
@ -601,7 +649,7 @@ static int remoteRelayDomainEventPMSuspendDisk(virConnectPtr conn ATTRIBUTE_UNUS
} }
static int static int
remoteRelayDomainEventDeviceRemoved(virConnectPtr conn ATTRIBUTE_UNUSED, remoteRelayDomainEventDeviceRemoved(virConnectPtr conn,
virDomainPtr dom, virDomainPtr dom,
const char *devAlias, const char *devAlias,
void *opaque) void *opaque)
@ -609,7 +657,7 @@ remoteRelayDomainEventDeviceRemoved(virConnectPtr conn ATTRIBUTE_UNUSED,
virNetServerClientPtr client = opaque; virNetServerClientPtr client = opaque;
remote_domain_event_device_removed_msg data; remote_domain_event_device_removed_msg data;
if (!client) if (!client || !remoteRelayDomainEventCheckACL(client, conn, dom))
return -1; return -1;
VIR_DEBUG("Relaying domain device removed event %s %d %s", VIR_DEBUG("Relaying domain device removed event %s %d %s",

View File

@ -1,6 +1,6 @@
#!/usr/bin/perl #!/usr/bin/perl
# #
# Copyright (C) 2013 Red Hat, Inc. # Copyright (C) 2013-2014 Red Hat, Inc.
# #
# This library is free software; you can redistribute it and/or # This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public # modify it under the terms of the GNU Lesser General Public
@ -140,7 +140,10 @@ while (<PROTO>) {
} elsif ($filtered && } elsif ($filtered &&
m,REMOTE_PROC_(.*)\s+=\s*\d+,) { m,REMOTE_PROC_(.*)\s+=\s*\d+,) {
my $api = name_to_ProcName($1); my $api = name_to_ProcName($1);
$filtered{$api} = 1; # Event filtering is handled in daemon/remote.c instead of drivers
if (! m,_EVENT_REGISTER,) {
$filtered{$api} = 1;
}
$incomment = 0; $incomment = 0;
} }
} }

View File

@ -32,20 +32,6 @@
#define VIR_FROM_THIS VIR_FROM_NONE #define VIR_FROM_THIS VIR_FROM_NONE
/**
* virObjectEventCallbackFilter:
* @conn: the connection pointer
* @event: the event about to be dispatched
* @opaque: opaque data registered with the filter
*
* Callback to do final filtering for a reason not tracked directly by
* virObjectEventStateRegisterID(). Return false if @event must not
* be sent to @conn.
*/
typedef bool (*virObjectEventCallbackFilter)(virConnectPtr conn,
virDomainEventPtr event,
void *opaque);
struct _virDomainMeta { struct _virDomainMeta {
int id; int id;
char *name; char *name;
@ -82,8 +68,6 @@ struct _virDomainEventCallback {
int eventID; int eventID;
virConnectPtr conn; virConnectPtr conn;
virDomainMetaPtr dom; virDomainMetaPtr dom;
virObjectEventCallbackFilter filter;
void *filter_opaque;
virConnectDomainEventGenericCallback cb; virConnectDomainEventGenericCallback cb;
void *opaque; void *opaque;
virFreeCallback freecb; virFreeCallback freecb;
@ -360,9 +344,6 @@ virDomainEventCallbackListPurgeMarked(virDomainEventCallbackListPtr cbList)
* virDomainEventCallbackListAddID: * virDomainEventCallbackListAddID:
* @conn: pointer to the connection * @conn: pointer to the connection
* @cbList: the list * @cbList: the list
* @dom: optional domain to filter on
* @filter optional last-ditch filter callback
* @filter_opaque: opaque data to pass to @filter
* @eventID: the event ID * @eventID: the event ID
* @callback: the callback to add * @callback: the callback to add
* @opaque: opaque data tio pass to callback * @opaque: opaque data tio pass to callback
@ -374,8 +355,6 @@ static int
virDomainEventCallbackListAddID(virConnectPtr conn, virDomainEventCallbackListAddID(virConnectPtr conn,
virDomainEventCallbackListPtr cbList, virDomainEventCallbackListPtr cbList,
virDomainPtr dom, virDomainPtr dom,
virObjectEventCallbackFilter filter,
void *filter_opaque,
int eventID, int eventID,
virConnectDomainEventGenericCallback callback, virConnectDomainEventGenericCallback callback,
void *opaque, void *opaque,
@ -422,8 +401,6 @@ virDomainEventCallbackListAddID(virConnectPtr conn,
memcpy(event->dom->uuid, dom->uuid, VIR_UUID_BUFLEN); memcpy(event->dom->uuid, dom->uuid, VIR_UUID_BUFLEN);
event->dom->id = dom->id; event->dom->id = dom->id;
} }
event->filter = filter;
event->filter_opaque = filter_opaque;
/* Make space on list */ /* Make space on list */
if (VIR_REALLOC_N(cbList->callbacks, cbList->count + 1) < 0) if (VIR_REALLOC_N(cbList->callbacks, cbList->count + 1) < 0)
@ -463,8 +440,6 @@ error:
* virDomainEventCallbackListAdd: * virDomainEventCallbackListAdd:
* @conn: pointer to the connection * @conn: pointer to the connection
* @cbList: the list * @cbList: the list
* @filter optional last-ditch filter callback
* @filter_opaque: opaque data to pass to @filter
* @callback: the callback to add * @callback: the callback to add
* @opaque: opaque data tio pass to callback * @opaque: opaque data tio pass to callback
* *
@ -473,14 +448,11 @@ error:
static int static int
virDomainEventCallbackListAdd(virConnectPtr conn, virDomainEventCallbackListAdd(virConnectPtr conn,
virDomainEventCallbackListPtr cbList, virDomainEventCallbackListPtr cbList,
virObjectEventCallbackFilter filter,
void *filter_opaque,
virConnectDomainEventCallback callback, virConnectDomainEventCallback callback,
void *opaque, void *opaque,
virFreeCallback freecb) virFreeCallback freecb)
{ {
return virDomainEventCallbackListAddID(conn, cbList, NULL, return virDomainEventCallbackListAddID(conn, cbList, NULL,
filter, filter_opaque,
VIR_DOMAIN_EVENT_ID_LIFECYCLE, VIR_DOMAIN_EVENT_ID_LIFECYCLE,
VIR_DOMAIN_EVENT_CALLBACK(callback), VIR_DOMAIN_EVENT_CALLBACK(callback),
opaque, freecb, NULL); opaque, freecb, NULL);
@ -708,32 +680,6 @@ static virDomainEventPtr virDomainEventNewInternal(int eventID,
return event; return event;
} }
/**
* virDomainEventFilter:
* @conn: pointer to the connection
* @event: the event to check
* @opaque: opaque data holding ACL filter to use
*
* Internal function to run ACL filtering before dispatching an event
*/
static bool
virDomainEventFilter(virConnectPtr conn, virDomainEventPtr event,
void *opaque)
{
virDomainDef dom;
virDomainObjListFilter filter = opaque;
/* For now, we just create a virDomainDef with enough contents to
* satisfy what viraccessdriverpolkit.c references. This is a bit
* fragile, but I don't know of anything better. */
dom.name = event->dom.name;
memcpy(dom.uuid, event->dom.uuid, VIR_UUID_BUFLEN);
return (filter)(conn, &dom);
}
virDomainEventPtr virDomainEventNew(int id, const char *name, virDomainEventPtr virDomainEventNew(int id, const char *name,
const unsigned char *uuid, const unsigned char *uuid,
int type, int detail) int type, int detail)
@ -1435,9 +1381,6 @@ static int virDomainEventDispatchMatchCallback(virDomainEventPtr event,
if (cb->eventID != event->eventID) if (cb->eventID != event->eventID)
return 0; return 0;
if (cb->filter && !(cb->filter)(cb->conn, event, cb->filter_opaque))
return 0;
if (cb->dom) { if (cb->dom) {
/* Deliberately ignoring 'id' for matching, since that /* Deliberately ignoring 'id' for matching, since that
* will cause problems when a domain switches between * will cause problems when a domain switches between
@ -1567,7 +1510,6 @@ virDomainEventStateFlush(virDomainEventStatePtr state)
* virDomainEventStateRegister: * virDomainEventStateRegister:
* @conn: connection to associate with callback * @conn: connection to associate with callback
* @state: domain event state * @state: domain event state
* @filter: optional ACL filter to limit which events can be sent
* @callback: function to remove from event * @callback: function to remove from event
* @opaque: data blob to pass to callback * @opaque: data blob to pass to callback
* @freecb: callback to free @opaque * @freecb: callback to free @opaque
@ -1580,7 +1522,6 @@ virDomainEventStateFlush(virDomainEventStatePtr state)
int int
virDomainEventStateRegister(virConnectPtr conn, virDomainEventStateRegister(virConnectPtr conn,
virDomainEventStatePtr state, virDomainEventStatePtr state,
virDomainObjListFilter filter,
virConnectDomainEventCallback callback, virConnectDomainEventCallback callback,
void *opaque, void *opaque,
virFreeCallback freecb) virFreeCallback freecb)
@ -1601,8 +1542,7 @@ virDomainEventStateRegister(virConnectPtr conn,
} }
ret = virDomainEventCallbackListAdd(conn, state->callbacks, ret = virDomainEventCallbackListAdd(conn, state->callbacks,
filter ? virDomainEventFilter : NULL, callback, opaque, freecb);
filter, callback, opaque, freecb);
if (ret == -1 && if (ret == -1 &&
state->callbacks->count == 0 && state->callbacks->count == 0 &&
@ -1621,7 +1561,6 @@ cleanup:
* virDomainEventStateRegisterID: * virDomainEventStateRegisterID:
* @conn: connection to associate with callback * @conn: connection to associate with callback
* @state: domain event state * @state: domain event state
* @filter: optional ACL filter to limit which events can be sent
* @eventID: ID of the event type to register for * @eventID: ID of the event type to register for
* @cb: function to remove from event * @cb: function to remove from event
* @opaque: data blob to pass to callback * @opaque: data blob to pass to callback
@ -1636,7 +1575,6 @@ cleanup:
int int
virDomainEventStateRegisterID(virConnectPtr conn, virDomainEventStateRegisterID(virConnectPtr conn,
virDomainEventStatePtr state, virDomainEventStatePtr state,
virDomainObjListFilter filter,
virDomainPtr dom, virDomainPtr dom,
int eventID, int eventID,
virConnectDomainEventGenericCallback cb, virConnectDomainEventGenericCallback cb,
@ -1659,9 +1597,8 @@ virDomainEventStateRegisterID(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
ret = virDomainEventCallbackListAddID(conn, state->callbacks, dom, ret = virDomainEventCallbackListAddID(conn, state->callbacks,
filter ? virDomainEventFilter : NULL, dom, eventID, cb, opaque, freecb,
filter, eventID, cb, opaque, freecb,
callbackID); callbackID);
if (ret == -1 && if (ret == -1 &&

View File

@ -1,7 +1,7 @@
/* /*
* domain_event.h: domain event queue processing helpers * domain_event.h: domain event queue processing helpers
* *
* Copyright (C) 2012-2014 Red Hat, Inc. * Copyright (C) 2012 Red Hat, Inc.
* Copyright (C) 2008 VirtualIron * Copyright (C) 2008 VirtualIron
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
@ -149,21 +149,19 @@ virDomainEventStateQueue(virDomainEventStatePtr state,
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int virDomainEventStateRegister(virConnectPtr conn, int virDomainEventStateRegister(virConnectPtr conn,
virDomainEventStatePtr state, virDomainEventStatePtr state,
virDomainObjListFilter filter,
virConnectDomainEventCallback callback, virConnectDomainEventCallback callback,
void *opaque, void *opaque,
virFreeCallback freecb) virFreeCallback freecb)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
int virDomainEventStateRegisterID(virConnectPtr conn, int virDomainEventStateRegisterID(virConnectPtr conn,
virDomainEventStatePtr state, virDomainEventStatePtr state,
virDomainObjListFilter filter,
virDomainPtr dom, virDomainPtr dom,
int eventID, int eventID,
virConnectDomainEventGenericCallback cb, virConnectDomainEventGenericCallback cb,
void *opaque, void *opaque,
virFreeCallback freecb, virFreeCallback freecb,
int *callbackID) int *callbackID)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(6); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5);
int int
virDomainEventStateDeregister(virConnectPtr conn, virDomainEventStateDeregister(virConnectPtr conn,
virDomainEventStatePtr state, virDomainEventStatePtr state,

View File

@ -3529,7 +3529,6 @@ libxlConnectDomainEventRegister(virConnectPtr conn,
ret = virDomainEventStateRegister(conn, ret = virDomainEventStateRegister(conn,
driver->domainEventState, driver->domainEventState,
virConnectDomainEventRegisterCheckACL,
callback, opaque, freecb); callback, opaque, freecb);
return ret; return ret;
@ -4129,7 +4128,6 @@ libxlConnectDomainEventRegisterAny(virConnectPtr conn, virDomainPtr dom, int eve
if (virDomainEventStateRegisterID(conn, if (virDomainEventStateRegisterID(conn,
driver->domainEventState, driver->domainEventState,
virConnectDomainEventRegisterAnyCheckACL,
dom, eventID, callback, opaque, dom, eventID, callback, opaque,
freecb, &ret) < 0) freecb, &ret) < 0)
ret = -1; ret = -1;

View File

@ -1300,7 +1300,6 @@ lxcConnectDomainEventRegister(virConnectPtr conn,
ret = virDomainEventStateRegister(conn, ret = virDomainEventStateRegister(conn,
driver->domainEventState, driver->domainEventState,
virConnectDomainEventRegisterCheckACL,
callback, opaque, freecb); callback, opaque, freecb);
return ret; return ret;
@ -1341,7 +1340,6 @@ lxcConnectDomainEventRegisterAny(virConnectPtr conn,
if (virDomainEventStateRegisterID(conn, if (virDomainEventStateRegisterID(conn,
driver->domainEventState, driver->domainEventState,
virConnectDomainEventRegisterAnyCheckACL,
dom, eventID, dom, eventID,
callback, opaque, freecb, &ret) < 0) callback, opaque, freecb, &ret) < 0)
ret = -1; ret = -1;

View File

@ -9892,7 +9892,6 @@ qemuConnectDomainEventRegister(virConnectPtr conn,
if (virDomainEventStateRegister(conn, if (virDomainEventStateRegister(conn,
driver->domainEventState, driver->domainEventState,
virConnectDomainEventRegisterCheckACL,
callback, opaque, freecb) < 0) callback, opaque, freecb) < 0)
goto cleanup; goto cleanup;
@ -9941,7 +9940,6 @@ qemuConnectDomainEventRegisterAny(virConnectPtr conn,
if (virDomainEventStateRegisterID(conn, if (virDomainEventStateRegisterID(conn,
driver->domainEventState, driver->domainEventState,
virConnectDomainEventRegisterAnyCheckACL,
dom, eventID, dom, eventID,
callback, opaque, freecb, &ret) < 0) callback, opaque, freecb, &ret) < 0)
ret = -1; ret = -1;

View File

@ -4320,7 +4320,7 @@ static int remoteConnectDomainEventRegister(virConnectPtr conn,
remoteDriverLock(priv); remoteDriverLock(priv);
if ((count = virDomainEventStateRegister(conn, priv->domainEventState, NULL, if ((count = virDomainEventStateRegister(conn, priv->domainEventState,
callback, opaque, freecb)) < 0) { callback, opaque, freecb)) < 0) {
virReportError(VIR_ERR_RPC, "%s", _("adding cb to list")); virReportError(VIR_ERR_RPC, "%s", _("adding cb to list"));
goto done; goto done;
@ -5106,7 +5106,7 @@ static int remoteConnectDomainEventRegisterAny(virConnectPtr conn,
remoteDriverLock(priv); remoteDriverLock(priv);
if ((count = virDomainEventStateRegisterID(conn, if ((count = virDomainEventStateRegisterID(conn,
priv->domainEventState, NULL, priv->domainEventState,
dom, eventID, dom, eventID,
callback, opaque, freecb, callback, opaque, freecb,
&callbackID)) < 0) { &callbackID)) < 0) {

View File

@ -5963,7 +5963,7 @@ testConnectDomainEventRegister(virConnectPtr conn,
testDriverLock(driver); testDriverLock(driver);
ret = virDomainEventStateRegister(conn, ret = virDomainEventStateRegister(conn,
driver->domainEventState, NULL, driver->domainEventState,
callback, opaque, freecb); callback, opaque, freecb);
testDriverUnlock(driver); testDriverUnlock(driver);
@ -6001,7 +6001,7 @@ testConnectDomainEventRegisterAny(virConnectPtr conn,
testDriverLock(driver); testDriverLock(driver);
if (virDomainEventStateRegisterID(conn, if (virDomainEventStateRegisterID(conn,
driver->domainEventState, NULL, driver->domainEventState,
dom, eventID, dom, eventID,
callback, opaque, freecb, &ret) < 0) callback, opaque, freecb, &ret) < 0)
ret = -1; ret = -1;

View File

@ -2622,7 +2622,6 @@ umlConnectDomainEventRegister(virConnectPtr conn,
umlDriverLock(driver); umlDriverLock(driver);
ret = virDomainEventStateRegister(conn, ret = virDomainEventStateRegister(conn,
driver->domainEventState, driver->domainEventState,
virConnectDomainEventRegisterCheckACL,
callback, opaque, freecb); callback, opaque, freecb);
umlDriverUnlock(driver); umlDriverUnlock(driver);
@ -2665,7 +2664,6 @@ umlConnectDomainEventRegisterAny(virConnectPtr conn,
umlDriverLock(driver); umlDriverLock(driver);
if (virDomainEventStateRegisterID(conn, if (virDomainEventStateRegisterID(conn,
driver->domainEventState, driver->domainEventState,
virConnectDomainEventRegisterAnyCheckACL,
dom, eventID, dom, eventID,
callback, opaque, freecb, &ret) < 0) callback, opaque, freecb, &ret) < 0)
ret = -1; ret = -1;

View File

@ -7326,7 +7326,7 @@ static int vboxConnectDomainEventRegister(virConnectPtr conn,
* later you can iterate over them * later you can iterate over them
*/ */
ret = virDomainEventStateRegister(conn, data->domainEvents, NULL, ret = virDomainEventStateRegister(conn, data->domainEvents,
callback, opaque, freecb); callback, opaque, freecb);
VIR_DEBUG("virDomainEventStateRegister (ret = %d) (conn: %p, " VIR_DEBUG("virDomainEventStateRegister (ret = %d) (conn: %p, "
"callback: %p, opaque: %p, " "callback: %p, opaque: %p, "
@ -7418,7 +7418,7 @@ static int vboxConnectDomainEventRegisterAny(virConnectPtr conn,
* later you can iterate over them * later you can iterate over them
*/ */
if (virDomainEventStateRegisterID(conn, data->domainEvents, NULL, if (virDomainEventStateRegisterID(conn, data->domainEvents,
dom, eventID, dom, eventID,
callback, opaque, freecb, &ret) < 0) callback, opaque, freecb, &ret) < 0)
ret = -1; ret = -1;

View File

@ -2326,7 +2326,6 @@ xenUnifiedConnectDomainEventRegister(virConnectPtr conn,
} }
ret = virDomainEventStateRegister(conn, priv->domainEvents, ret = virDomainEventStateRegister(conn, priv->domainEvents,
virConnectDomainEventRegisterCheckACL,
callback, opaque, freefunc); callback, opaque, freefunc);
xenUnifiedUnlock(priv); xenUnifiedUnlock(priv);
@ -2384,7 +2383,6 @@ xenUnifiedConnectDomainEventRegisterAny(virConnectPtr conn,
} }
if (virDomainEventStateRegisterID(conn, priv->domainEvents, if (virDomainEventStateRegisterID(conn, priv->domainEvents,
virConnectDomainEventRegisterAnyCheckACL,
dom, eventID, dom, eventID,
callback, opaque, freefunc, &ret) < 0) callback, opaque, freefunc, &ret) < 0)
ret = -1; ret = -1;