aboutsummaryrefslogtreecommitdiffstats
path: root/package/compcache/files/compcache.init
blob: 5939d9f61ca4a7badc493c431f7a5f8fc39a1c0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
id='n68' href='#n68'>68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
/******************************************************************************
 * acm_ops.c
 *
 * Copyright (C) 2005 IBM Corporation
 *
 * Author:
 * Reiner Sailer <sailer@watson.ibm.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, version 2 of the
 * License.
 *
 * Process acm command requests from guest OS.
 */

#include <xen/config.h>
#include <xen/types.h>
#include <xen/lib.h>
#include <xen/mm.h>
#include <public/xsm/acm.h>
#include <public/xsm/acm_ops.h>
#include <xen/sched.h>
#include <xen/event.h>
#include <xen/trace.h>
#include <xen/console.h>
#include <xen/guest_access.h>
#include <xsm/acm/acm_hooks.h>

#ifndef ACM_SECURITY

long do_acm_op(int cmd, XEN_GUEST_HANDLE(void) arg)
{
    return -ENOSYS;
}

#else

int acm_authorize_acm_ops(struct domain *d)
{
    /* currently, policy management functions are restricted to privileged domains */
    return (IS_PRIV(d) ? 0 : -EPERM);
}


long do_acm_op(XEN_GUEST_HANDLE(xen_acmctl_t) u_acmctl)
{
    long rc = -EFAULT;
    struct xen_acmctl curop, *op = &curop;

    if (acm_authorize_acm_ops(current->domain))
        return -EPERM;

    if ( copy_from_guest(op, u_acmctl, 1) )
        return -EFAULT;

    if (op->interface_version != ACM_INTERFACE_VERSION)
        return -EACCES;

    switch ( op->cmd )
    {

    case ACMOP_setpolicy: {
        rc = acm_set_policy(op->u.setpolicy.pushcache,
                            op->u.setpolicy.pushcache_size);
        break;
    }

    case ACMOP_getpolicy: {
        rc = acm_get_policy(op->u.getpolicy.pullcache,
                            op->u.getpolicy.pullcache_size);
        break;
    }

    case ACMOP_dumpstats: {
        rc = acm_dump_statistics(op->u.dumpstats.pullcache,
                                 op->u.dumpstats.pullcache_size);
        break;
    }

    case ACMOP_getssid: {
        ssidref_t ssidref;

        if (op->u.getssid.get_ssid_by == ACM_GETBY_ssidref)
            ssidref = op->u.getssid.id.ssidref;
        else if (op->u.getssid.get_ssid_by == ACM_GETBY_domainid)
        {
            struct domain *subj = rcu_lock_domain_by_id(op->u.getssid.id.domainid);
            if (!subj)
            {
                rc = -ESRCH; /* domain not found */
                break;
            }
            if (subj->ssid == NULL)
            {
                rcu_unlock_domain(subj);
                rc = -ESRCH;
                break;
            }
            ssidref = ((struct acm_ssid_domain *)(subj->ssid))->ssidref;
            rcu_unlock_domain(subj);
        }
        else
        {
            rc = -ESRCH;
            break;
        }
        rc = acm_get_ssid(ssidref, op->u.getssid.ssidbuf,
                          op->u.getssid.ssidbuf_size);
        break;
    }

    case ACMOP_getdecision: {
        ssidref_t ssidref1, ssidref2;

        if (op->u.getdecision.get_decision_by1 == ACM_GETBY_ssidref)
            ssidref1 = op->u.getdecision.id1.ssidref;
        else if (op->u.getdecision.get_decision_by1 == ACM_GETBY_domainid)
        {
            struct domain *subj = rcu_lock_domain_by_id(op->u.getdecision.id1.domainid);
            if (!subj)
            {
                rc = -ESRCH; /* domain not found */
                break;
            }
            if (subj->ssid == NULL)
            {
                rcu_unlock_domain(subj);
                rc = -ESRCH;
                break;
            }
            ssidref1 = ((struct acm_ssid_domain *)(subj->ssid))->ssidref;
            rcu_unlock_domain(subj);
        }
        else
        {
            rc = -ESRCH;
            break;
        }
        if (op->u.getdecision.get_decision_by2 == ACM_GETBY_ssidref)
            ssidref2 = op->u.getdecision.id2.ssidref;
        else if (op->u.getdecision.get_decision_by2 == ACM_GETBY_domainid)
        {
            struct domain *subj = rcu_lock_domain_by_id(op->u.getdecision.id2.domainid);
            if (!subj)
            {
                rc = -ESRCH; /* domain not found */
                break;
            }
            if (subj->ssid == NULL)
            {
                rcu_unlock_domain(subj);
                rc = -ESRCH;
                break;
            }
            ssidref2 = ((struct acm_ssid_domain *)(subj->ssid))->ssidref;
            rcu_unlock_domain(subj);
        }
        else
        {
            rc = -ESRCH;
            break;
        }
        rc = acm_get_decision(ssidref1, ssidref2, op->u.getdecision.hook);

        if (rc == ACM_ACCESS_PERMITTED)
        {
            op->u.getdecision.acm_decision = ACM_ACCESS_PERMITTED;
            rc = 0;
        }
        else if  (rc == ACM_ACCESS_DENIED)
        {
            op->u.getdecision.acm_decision = ACM_ACCESS_DENIED;
            rc = 0;
        }
        else
            rc = -ESRCH;

        if ( (rc == 0) && (copy_to_guest(u_acmctl, op, 1) != 0) )
            rc = -EFAULT;
        break;
    }

    case ACMOP_chgpolicy: {
        rc = acm_change_policy(&op->u.change_policy);
        break;
    }

    case ACMOP_relabeldoms: {
        rc = acm_relabel_domains(&op->u.relabel_doms);
        break;
    }

    default:
        rc = -ENOSYS;
        break;
    }

    return rc;
}

#endif

/*
 * Local variables:
 * mode: C
 * c-set-style: "BSD"
 * c-basic-offset: 4
 * tab-width: 4
 * indent-tabs-mode: nil
 * End:
 */