security_driver.h 4.4 KB
Newer Older
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
/*
 * Copyright (C) 2008 Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Authors:
 *     James Morris <jmorris@namei.org>
 *
 */
#ifndef __VIR_SECURITY_H__
#define __VIR_SECURITY_H__

#include "internal.h"
#include "domain_conf.h"

/*
 * Return values for security driver probing: the driver will determine
 * whether it should be enabled or disabled.
 */
typedef enum {
    SECURITY_DRIVER_ENABLE      = 0,
    SECURITY_DRIVER_ERROR       = -1,
    SECURITY_DRIVER_DISABLE     = -2,
} virSecurityDriverStatus;

typedef struct _virSecurityDriver virSecurityDriver;
typedef virSecurityDriver *virSecurityDriverPtr;
typedef virSecurityDriverStatus (*virSecurityDriverProbe) (void);
32 33
typedef int (*virSecurityDriverOpen) (virSecurityDriverPtr drv);
typedef int (*virSecurityDomainRestoreImageLabel) (virDomainObjPtr vm,
34
                                                   virDomainDiskDefPtr disk);
35
typedef int (*virSecurityDomainSetImageLabel) (virDomainObjPtr vm,
36
                                               virDomainDiskDefPtr disk);
37
typedef int (*virSecurityDomainRestoreHostdevLabel) (virDomainObjPtr vm,
38
                                                     virDomainHostdevDefPtr dev);
39
typedef int (*virSecurityDomainSetHostdevLabel) (virDomainObjPtr vm,
40
                                                 virDomainHostdevDefPtr dev);
41
typedef int (*virSecurityDomainSetSavedStateLabel) (virDomainObjPtr vm,
42
                                                    const char *savefile);
43
typedef int (*virSecurityDomainRestoreSavedStateLabel) (virDomainObjPtr vm,
44
                                                        const char *savefile);
45 46 47 48 49 50
typedef int (*virSecurityDomainGenLabel) (virDomainObjPtr sec);
typedef int (*virSecurityDomainReserveLabel) (virDomainObjPtr sec);
typedef int (*virSecurityDomainReleaseLabel) (virDomainObjPtr sec);
typedef int (*virSecurityDomainSetAllLabel) (virDomainObjPtr sec);
typedef int (*virSecurityDomainRestoreAllLabel) (virDomainObjPtr vm);
typedef int (*virSecurityDomainGetProcessLabel) (virDomainObjPtr vm,
51
                                                 virSecurityLabelPtr sec);
52
typedef int (*virSecurityDomainSetProcessLabel) (virSecurityDriverPtr drv,
53
                                                 virDomainObjPtr vm);
54
typedef int (*virSecurityDomainSecurityVerify) (virDomainDefPtr def);
55 56 57 58 59

struct _virSecurityDriver {
    const char *name;
    virSecurityDriverProbe probe;
    virSecurityDriverOpen open;
60
    virSecurityDomainSecurityVerify domainSecurityVerify;
61 62 63
    virSecurityDomainRestoreImageLabel domainRestoreSecurityImageLabel;
    virSecurityDomainSetImageLabel domainSetSecurityImageLabel;
    virSecurityDomainGenLabel domainGenSecurityLabel;
64
    virSecurityDomainReserveLabel domainReserveSecurityLabel;
65 66 67 68 69
    virSecurityDomainReleaseLabel domainReleaseSecurityLabel;
    virSecurityDomainGetProcessLabel domainGetSecurityProcessLabel;
    virSecurityDomainSetProcessLabel domainSetSecurityProcessLabel;
    virSecurityDomainSetAllLabel domainSetSecurityAllLabel;
    virSecurityDomainRestoreAllLabel domainRestoreSecurityAllLabel;
70 71
    virSecurityDomainRestoreHostdevLabel domainRestoreSecurityHostdevLabel;
    virSecurityDomainSetHostdevLabel domainSetSecurityHostdevLabel;
72 73
    virSecurityDomainSetSavedStateLabel domainSetSavedStateLabel;
    virSecurityDomainRestoreSavedStateLabel domainRestoreSavedStateLabel;
74 75 76 77 78 79 80 81 82 83 84 85 86 87

    /*
     * This is internally managed driver state and should only be accessed
     * via helpers below.
     */
    struct {
        char doi[VIR_SECURITY_DOI_BUFLEN];
    } _private;
};

/* Global methods */
int virSecurityDriverStartup(virSecurityDriverPtr *drv,
                             const char *name);

88
int
89
virSecurityDriverVerify(virDomainDefPtr def);
90

91 92 93
#define virSecurityReportError(code, fmt...)                        \
    virReportErrorHelper(NULL, VIR_FROM_SECURITY, code, __FILE__,   \
                         __FUNCTION__, __LINE__, fmt)
94 95 96

/* Helpers */
void virSecurityDriverInit(virSecurityDriverPtr drv);
97
int virSecurityDriverSetDOI(virSecurityDriverPtr drv,
98 99 100 101 102
                            const char *doi);
const char *virSecurityDriverGetDOI(virSecurityDriverPtr drv);
const char *virSecurityDriverGetModel(virSecurityDriverPtr drv);

#endif /* __VIR_SECURITY_H__ */