security_driver.h 4.8 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 32 33 34
/*
 * 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);
typedef int (*virSecurityDriverOpen) (virConnectPtr conn,
                                      virSecurityDriverPtr drv);
typedef int (*virSecurityDomainRestoreImageLabel) (virConnectPtr conn,
35
                                                   virDomainObjPtr vm,
36
                                                   virDomainDiskDefPtr disk);
37 38
typedef int (*virSecurityDomainSetImageLabel) (virConnectPtr conn,
                                               virDomainObjPtr vm,
39
                                               virDomainDiskDefPtr disk);
40 41 42 43 44
typedef int (*virSecurityDomainRestoreHostdevLabel) (virConnectPtr conn,
                                                     virDomainHostdevDefPtr dev);
typedef int (*virSecurityDomainSetHostdevLabel) (virConnectPtr conn,
                                                 virDomainObjPtr vm,
                                                 virDomainHostdevDefPtr dev);
45 46 47 48 49
typedef int (*virSecurityDomainSetSavedStateLabel) (virConnectPtr conn,
                                                    virDomainObjPtr vm,
                                                    const char *savefile);
typedef int (*virSecurityDomainRestoreSavedStateLabel) (virConnectPtr conn,
                                                        const char *savefile);
D
Daniel P. Berrange 已提交
50 51
typedef int (*virSecurityDomainGenLabel) (virConnectPtr conn,
                                          virDomainObjPtr sec);
52 53
typedef int (*virSecurityDomainReserveLabel) (virConnectPtr conn,
                                           virDomainObjPtr sec);
54 55 56 57 58 59 60 61
typedef int (*virSecurityDomainGetLabel) (virConnectPtr conn,
                                          virDomainObjPtr vm,
                                          virSecurityLabelPtr sec);
typedef int (*virSecurityDomainRestoreLabel) (virConnectPtr conn,
                                              virDomainObjPtr vm);
typedef int (*virSecurityDomainSetLabel) (virConnectPtr conn,
                                          virSecurityDriverPtr drv,
                                          virDomainObjPtr vm);
62 63
typedef int (*virSecurityDomainSecurityVerify) (virConnectPtr conn,
                                                virDomainDefPtr def);
64 65 66 67 68

struct _virSecurityDriver {
    const char *name;
    virSecurityDriverProbe probe;
    virSecurityDriverOpen open;
69
    virSecurityDomainSecurityVerify domainSecurityVerify;
70 71 72
    virSecurityDomainRestoreImageLabel domainRestoreSecurityImageLabel;
    virSecurityDomainSetImageLabel domainSetSecurityImageLabel;
    virSecurityDomainGenLabel domainGenSecurityLabel;
73
    virSecurityDomainReserveLabel domainReserveSecurityLabel;
74 75 76
    virSecurityDomainGetLabel domainGetSecurityLabel;
    virSecurityDomainSetLabel domainSetSecurityLabel;
    virSecurityDomainRestoreLabel domainRestoreSecurityLabel;
77 78
    virSecurityDomainRestoreHostdevLabel domainRestoreSecurityHostdevLabel;
    virSecurityDomainSetHostdevLabel domainSetSecurityHostdevLabel;
79 80
    virSecurityDomainSetSavedStateLabel domainSetSavedStateLabel;
    virSecurityDomainRestoreSavedStateLabel domainRestoreSavedStateLabel;
81 82 83 84 85 86 87 88 89 90 91 92 93 94

    /*
     * 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);

95 96 97
int
virSecurityDriverVerify(virConnectPtr conn, virDomainDefPtr def);

98 99
void
virSecurityReportError(virConnectPtr conn, int code, const char *fmt, ...)
100
    ATTRIBUTE_FMT_PRINTF(3, 4);
101 102 103 104 105 106 107 108 109 110

/* Helpers */
void virSecurityDriverInit(virSecurityDriverPtr drv);
int virSecurityDriverSetDOI(virConnectPtr conn,
                            virSecurityDriverPtr drv,
                            const char *doi);
const char *virSecurityDriverGetDOI(virSecurityDriverPtr drv);
const char *virSecurityDriverGetModel(virSecurityDriverPtr drv);

#endif /* __VIR_SECURITY_H__ */