security_driver.h 8.9 KB
Newer Older
1
/*
2
 * Copyright (C) 2008, 2010-2013 Red Hat, Inc.
3 4 5 6 7 8
 *
 * 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.
 *
O
Osier Yang 已提交
9 10 11 12 13 14
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
15
 * License along with this library.  If not, see
O
Osier Yang 已提交
16 17
 * <http://www.gnu.org/licenses/>.
 *
18 19 20 21 22
 * Authors:
 *     James Morris <jmorris@namei.org>
 *
 */
#ifndef __VIR_SECURITY_H__
23
# define __VIR_SECURITY_H__
24

25 26
# include "internal.h"
# include "domain_conf.h"
27

28 29
# include "security_manager.h"

30 31 32 33 34 35 36 37 38 39 40 41
/*
 * 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;
42

43
typedef virSecurityDriverStatus (*virSecurityDriverProbe) (const char *virtDriver);
44 45 46 47 48
typedef int (*virSecurityDriverOpen) (virSecurityManagerPtr mgr);
typedef int (*virSecurityDriverClose) (virSecurityManagerPtr mgr);

typedef const char *(*virSecurityDriverGetModel) (virSecurityManagerPtr mgr);
typedef const char *(*virSecurityDriverGetDOI) (virSecurityManagerPtr mgr);
49 50
typedef const char *(*virSecurityDriverGetBaseLabel) (virSecurityManagerPtr mgr,
                                                      int virtType);
51

52 53
typedef int (*virSecurityDriverPreFork) (virSecurityManagerPtr mgr);

54 55 56
typedef int (*virSecurityDomainRestoreDiskLabel) (virSecurityManagerPtr mgr,
                                                  virDomainDefPtr def,
                                                  virDomainDiskDefPtr disk);
57
typedef int (*virSecurityDomainSetDaemonSocketLabel)(virSecurityManagerPtr mgr,
58
                                                     virDomainDefPtr vm);
59
typedef int (*virSecurityDomainSetSocketLabel) (virSecurityManagerPtr mgr,
60
                                                virDomainDefPtr def);
61
typedef int (*virSecurityDomainClearSocketLabel)(virSecurityManagerPtr mgr,
62
                                                virDomainDefPtr def);
63 64 65
typedef int (*virSecurityDomainSetDiskLabel) (virSecurityManagerPtr mgr,
                                              virDomainDefPtr def,
                                              virDomainDiskDefPtr disk);
66
typedef int (*virSecurityDomainRestoreHostdevLabel) (virSecurityManagerPtr mgr,
67
                                                     virDomainDefPtr def,
68 69
                                                     virDomainHostdevDefPtr dev,
                                                     const char *vroot);
70
typedef int (*virSecurityDomainSetHostdevLabel) (virSecurityManagerPtr mgr,
71
                                                 virDomainDefPtr def,
72 73
                                                 virDomainHostdevDefPtr dev,
                                                 const char *vroot);
74
typedef int (*virSecurityDomainSetSavedStateLabel) (virSecurityManagerPtr mgr,
75
                                                    virDomainDefPtr def,
76
                                                    const char *savefile);
77
typedef int (*virSecurityDomainRestoreSavedStateLabel) (virSecurityManagerPtr mgr,
78
                                                        virDomainDefPtr def,
79
                                                        const char *savefile);
80
typedef int (*virSecurityDomainGenLabel) (virSecurityManagerPtr mgr,
81
                                          virDomainDefPtr sec);
82
typedef int (*virSecurityDomainReserveLabel) (virSecurityManagerPtr mgr,
83 84
                                              virDomainDefPtr sec,
                                              pid_t pid);
85
typedef int (*virSecurityDomainReleaseLabel) (virSecurityManagerPtr mgr,
86
                                              virDomainDefPtr sec);
87
typedef int (*virSecurityDomainSetAllLabel) (virSecurityManagerPtr mgr,
88
                                             virDomainDefPtr sec,
89
                                             const char *stdin_path);
90
typedef int (*virSecurityDomainRestoreAllLabel) (virSecurityManagerPtr mgr,
91
                                                 virDomainDefPtr def,
92
                                                 bool migrated);
93
typedef int (*virSecurityDomainGetProcessLabel) (virSecurityManagerPtr mgr,
94 95
                                                 virDomainDefPtr def,
                                                 pid_t pid,
96
                                                 virSecurityLabelPtr sec);
97
typedef int (*virSecurityDomainSetProcessLabel) (virSecurityManagerPtr mgr,
98
                                                 virDomainDefPtr def);
99 100 101
typedef int (*virSecurityDomainSetChildProcessLabel) (virSecurityManagerPtr mgr,
                                                      virDomainDefPtr def,
                                                      virCommandPtr cmd);
102 103
typedef int (*virSecurityDomainSecurityVerify) (virSecurityManagerPtr mgr,
                                                virDomainDefPtr def);
104
typedef int (*virSecurityDomainSetImageFDLabel) (virSecurityManagerPtr mgr,
105
                                                 virDomainDefPtr def,
106
                                                 int fd);
107 108 109
typedef int (*virSecurityDomainSetTapFDLabel) (virSecurityManagerPtr mgr,
                                               virDomainDefPtr def,
                                               int fd);
110
typedef char *(*virSecurityDomainGetMountOptions) (virSecurityManagerPtr mgr,
111
                                                   virDomainDefPtr def);
112
typedef int (*virSecurityDomainSetHugepages) (virSecurityManagerPtr mgr,
113 114
                                              virDomainDefPtr def,
                                              const char *path);
115 116 117 118 119 120
typedef int (*virSecurityDomainSetImageLabel) (virSecurityManagerPtr mgr,
                                               virDomainDefPtr def,
                                               virStorageSourcePtr src);
typedef int (*virSecurityDomainRestoreImageLabel) (virSecurityManagerPtr mgr,
                                                   virDomainDefPtr def,
                                                   virStorageSourcePtr src);
121 122 123
typedef int (*virSecurityDomainSetDirLabel) (virSecurityManagerPtr mgr,
                                             virDomainDefPtr def,
                                             const char *path);
124

125 126

struct _virSecurityDriver {
127
    size_t privateDataLen;
128 129 130
    const char *name;
    virSecurityDriverProbe probe;
    virSecurityDriverOpen open;
131 132 133 134 135
    virSecurityDriverClose close;

    virSecurityDriverGetModel getModel;
    virSecurityDriverGetDOI getDOI;

136 137
    virSecurityDriverPreFork preFork;

138
    virSecurityDomainSecurityVerify domainSecurityVerify;
139

140
    virSecurityDomainSetDiskLabel domainSetSecurityDiskLabel;
141
    virSecurityDomainRestoreDiskLabel domainRestoreSecurityDiskLabel;
142

143 144 145
    virSecurityDomainSetImageLabel domainSetSecurityImageLabel;
    virSecurityDomainRestoreImageLabel domainRestoreSecurityImageLabel;

146
    virSecurityDomainSetDaemonSocketLabel domainSetSecurityDaemonSocketLabel;
147
    virSecurityDomainSetSocketLabel domainSetSecuritySocketLabel;
148
    virSecurityDomainClearSocketLabel domainClearSecuritySocketLabel;
149

150
    virSecurityDomainGenLabel domainGenSecurityLabel;
151
    virSecurityDomainReserveLabel domainReserveSecurityLabel;
152
    virSecurityDomainReleaseLabel domainReleaseSecurityLabel;
153

154 155
    virSecurityDomainGetProcessLabel domainGetSecurityProcessLabel;
    virSecurityDomainSetProcessLabel domainSetSecurityProcessLabel;
156
    virSecurityDomainSetChildProcessLabel domainSetSecurityChildProcessLabel;
157

158 159
    virSecurityDomainSetAllLabel domainSetSecurityAllLabel;
    virSecurityDomainRestoreAllLabel domainRestoreSecurityAllLabel;
160

161
    virSecurityDomainSetHostdevLabel domainSetSecurityHostdevLabel;
162 163
    virSecurityDomainRestoreHostdevLabel domainRestoreSecurityHostdevLabel;

164 165
    virSecurityDomainSetSavedStateLabel domainSetSavedStateLabel;
    virSecurityDomainRestoreSavedStateLabel domainRestoreSavedStateLabel;
166

167
    virSecurityDomainSetImageFDLabel domainSetSecurityImageFDLabel;
168
    virSecurityDomainSetTapFDLabel domainSetSecurityTapFDLabel;
169 170

    virSecurityDomainGetMountOptions domainGetSecurityMountOptions;
171
    virSecurityDomainSetHugepages domainSetSecurityHugepages;
172 173

    virSecurityDriverGetBaseLabel getBaseLabel;
174 175

    virSecurityDomainSetDirLabel domainSetDirLabel;
176 177
};

178 179
virSecurityDriverPtr virSecurityDriverLookup(const char *name,
                                             const char *virtDriver);
180 181

#endif /* __VIR_SECURITY_H__ */