/* Automatically generated from /build/libvirt/src/libvirt/src/remote/qemu_protocol.x by gendispatch.pl.
 * Do not edit this file.  Any changes you make will be lost.
 */
#include <config.h>
#include "viraccessapicheckqemu.h"
#include "access/viraccessmanager.h"
#include "datatypes.h"
#include "virerror.h"

#define VIR_FROM_THIS VIR_FROM_ACCESS

/* Returns: -1 on error/denied, 0 on allowed */
int virConnectDomainQemuMonitorEventDeregisterEnsureACL(virConnectPtr conn)
{
    g_autoptr(virAccessManager) mgr = NULL;
    int rv;

    if (!(mgr = virAccessManagerGetDefault())) {
        return -1;
    }

    if ((rv = virAccessManagerCheckConnect(mgr, conn->driver->name, VIR_ACCESS_PERM_CONNECT_WRITE)) <= 0) {
        if (rv == 0)
            virReportError(VIR_ERR_ACCESS_DENIED,
                            _("'%1$s' denied access"), conn->driver->name);
        return -1;
    }

    return 0;
}

/* Returns: -1 on error/denied, 0 on allowed */
int virConnectDomainQemuMonitorEventRegisterEnsureACL(virConnectPtr conn)
{
    g_autoptr(virAccessManager) mgr = NULL;
    int rv;

    if (!(mgr = virAccessManagerGetDefault())) {
        return -1;
    }

    if ((rv = virAccessManagerCheckConnect(mgr, conn->driver->name, VIR_ACCESS_PERM_CONNECT_SEARCH_DOMAINS)) <= 0) {
        if (rv == 0)
            virReportError(VIR_ERR_ACCESS_DENIED,
                            _("'%1$s' denied access"), conn->driver->name);
        return -1;
    }

    if ((rv = virAccessManagerCheckConnect(mgr, conn->driver->name, VIR_ACCESS_PERM_CONNECT_WRITE)) <= 0) {
        if (rv == 0)
            virReportError(VIR_ERR_ACCESS_DENIED,
                            _("'%1$s' denied access"), conn->driver->name);
        return -1;
    }

    return 0;
}

/* Returns: false on error/denied, true on allowed */
bool virConnectDomainQemuMonitorEventRegisterCheckACL(virConnectPtr conn, virDomainDef * domain)
{
    g_autoptr(virAccessManager) mgr = NULL;
    int rv;

    if (!(mgr = virAccessManagerGetDefault())) {
        virResetLastError();
        return false;
    }

    if ((rv = virAccessManagerCheckDomain(mgr, conn->driver->name, domain, VIR_ACCESS_PERM_DOMAIN_GETATTR)) <= 0) {
        virResetLastError();
        return false;
    }

    return true;
}

/* Returns: -1 on error/denied, 0 on allowed */
int virDomainQemuAgentCommandEnsureACL(virConnectPtr conn, virDomainDef * domain)
{
    g_autoptr(virAccessManager) mgr = NULL;
    int rv;

    if (!(mgr = virAccessManagerGetDefault())) {
        return -1;
    }

    if ((rv = virAccessManagerCheckDomain(mgr, conn->driver->name, domain, VIR_ACCESS_PERM_DOMAIN_WRITE)) <= 0) {
        if (rv == 0)
            virReportError(VIR_ERR_ACCESS_DENIED,
                            _("'%1$s' denied access"), conn->driver->name);
        return -1;
    }

    return 0;
}

/* Returns: -1 on error/denied, 0 on allowed */
int virDomainQemuAttachEnsureACL(virConnectPtr conn, virDomainDef * domain)
{
    g_autoptr(virAccessManager) mgr = NULL;
    int rv;

    if (!(mgr = virAccessManagerGetDefault())) {
        return -1;
    }

    if ((rv = virAccessManagerCheckDomain(mgr, conn->driver->name, domain, VIR_ACCESS_PERM_DOMAIN_START)) <= 0) {
        if (rv == 0)
            virReportError(VIR_ERR_ACCESS_DENIED,
                            _("'%1$s' denied access"), conn->driver->name);
        return -1;
    }

    if ((rv = virAccessManagerCheckDomain(mgr, conn->driver->name, domain, VIR_ACCESS_PERM_DOMAIN_WRITE)) <= 0) {
        if (rv == 0)
            virReportError(VIR_ERR_ACCESS_DENIED,
                            _("'%1$s' denied access"), conn->driver->name);
        return -1;
    }

    return 0;
}

/* Returns: -1 on error/denied, 0 on allowed */
int virDomainQemuMonitorCommandEnsureACL(virConnectPtr conn, virDomainDef * domain)
{
    g_autoptr(virAccessManager) mgr = NULL;
    int rv;

    if (!(mgr = virAccessManagerGetDefault())) {
        return -1;
    }

    if ((rv = virAccessManagerCheckDomain(mgr, conn->driver->name, domain, VIR_ACCESS_PERM_DOMAIN_WRITE)) <= 0) {
        if (rv == 0)
            virReportError(VIR_ERR_ACCESS_DENIED,
                            _("'%1$s' denied access"), conn->driver->name);
        return -1;
    }

    return 0;
}

/* Returns: -1 on error/denied, 0 on allowed */
int virDomainQemuMonitorCommandWithFilesEnsureACL(virConnectPtr conn, virDomainDef * domain)
{
    g_autoptr(virAccessManager) mgr = NULL;
    int rv;

    if (!(mgr = virAccessManagerGetDefault())) {
        return -1;
    }

    if ((rv = virAccessManagerCheckDomain(mgr, conn->driver->name, domain, VIR_ACCESS_PERM_DOMAIN_WRITE)) <= 0) {
        if (rv == 0)
            virReportError(VIR_ERR_ACCESS_DENIED,
                            _("'%1$s' denied access"), conn->driver->name);
        return -1;
    }

    return 0;
}

