/* Automatically generated from /build/libvirt/src/libvirt-8.5.0/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)
{
    virAccessManager *mgr;
    int rv;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

