security_driver.h 11.8 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 57 58
typedef int (*virSecurityDriverTransactionStart) (virSecurityManagerPtr mgr);
typedef int (*virSecurityDriverTransactionCommit) (virSecurityManagerPtr mgr,
                                                   pid_t pid);
typedef void (*virSecurityDriverTransactionAbort) (virSecurityManagerPtr mgr);

59 60 61
typedef int (*virSecurityDomainRestoreDiskLabel) (virSecurityManagerPtr mgr,
                                                  virDomainDefPtr def,
                                                  virDomainDiskDefPtr disk);
62
typedef int (*virSecurityDomainSetDaemonSocketLabel)(virSecurityManagerPtr mgr,
63
                                                     virDomainDefPtr vm);
64
typedef int (*virSecurityDomainSetSocketLabel) (virSecurityManagerPtr mgr,
65
                                                virDomainDefPtr def);
66
typedef int (*virSecurityDomainClearSocketLabel)(virSecurityManagerPtr mgr,
67
                                                virDomainDefPtr def);
68 69 70
typedef int (*virSecurityDomainSetDiskLabel) (virSecurityManagerPtr mgr,
                                              virDomainDefPtr def,
                                              virDomainDiskDefPtr disk);
71
typedef int (*virSecurityDomainRestoreHostdevLabel) (virSecurityManagerPtr mgr,
72
                                                     virDomainDefPtr def,
73 74
                                                     virDomainHostdevDefPtr dev,
                                                     const char *vroot);
75
typedef int (*virSecurityDomainSetHostdevLabel) (virSecurityManagerPtr mgr,
76
                                                 virDomainDefPtr def,
77 78
                                                 virDomainHostdevDefPtr dev,
                                                 const char *vroot);
79
typedef int (*virSecurityDomainSetSavedStateLabel) (virSecurityManagerPtr mgr,
80
                                                    virDomainDefPtr def,
81
                                                    const char *savefile);
82
typedef int (*virSecurityDomainRestoreSavedStateLabel) (virSecurityManagerPtr mgr,
83
                                                        virDomainDefPtr def,
84
                                                        const char *savefile);
85
typedef int (*virSecurityDomainGenLabel) (virSecurityManagerPtr mgr,
86
                                          virDomainDefPtr sec);
87
typedef int (*virSecurityDomainReserveLabel) (virSecurityManagerPtr mgr,
88 89
                                              virDomainDefPtr sec,
                                              pid_t pid);
90
typedef int (*virSecurityDomainReleaseLabel) (virSecurityManagerPtr mgr,
91
                                              virDomainDefPtr sec);
92
typedef int (*virSecurityDomainSetAllLabel) (virSecurityManagerPtr mgr,
93
                                             virDomainDefPtr sec,
94 95
                                             const char *stdin_path,
                                             bool chardevStdioLogd);
96
typedef int (*virSecurityDomainRestoreAllLabel) (virSecurityManagerPtr mgr,
97
                                                 virDomainDefPtr def,
98 99
                                                 bool migrated,
                                                 bool chardevStdioLogd);
100
typedef int (*virSecurityDomainGetProcessLabel) (virSecurityManagerPtr mgr,
101 102
                                                 virDomainDefPtr def,
                                                 pid_t pid,
103
                                                 virSecurityLabelPtr sec);
104
typedef int (*virSecurityDomainSetProcessLabel) (virSecurityManagerPtr mgr,
105
                                                 virDomainDefPtr def);
106 107 108
typedef int (*virSecurityDomainSetChildProcessLabel) (virSecurityManagerPtr mgr,
                                                      virDomainDefPtr def,
                                                      virCommandPtr cmd);
109 110
typedef int (*virSecurityDomainSecurityVerify) (virSecurityManagerPtr mgr,
                                                virDomainDefPtr def);
111
typedef int (*virSecurityDomainSetImageFDLabel) (virSecurityManagerPtr mgr,
112
                                                 virDomainDefPtr def,
113
                                                 int fd);
114 115 116
typedef int (*virSecurityDomainSetTapFDLabel) (virSecurityManagerPtr mgr,
                                               virDomainDefPtr def,
                                               int fd);
117
typedef char *(*virSecurityDomainGetMountOptions) (virSecurityManagerPtr mgr,
118
                                                   virDomainDefPtr def);
119
typedef int (*virSecurityDomainSetHugepages) (virSecurityManagerPtr mgr,
120 121
                                              virDomainDefPtr def,
                                              const char *path);
122 123 124 125 126 127
typedef int (*virSecurityDomainSetImageLabel) (virSecurityManagerPtr mgr,
                                               virDomainDefPtr def,
                                               virStorageSourcePtr src);
typedef int (*virSecurityDomainRestoreImageLabel) (virSecurityManagerPtr mgr,
                                                   virDomainDefPtr def,
                                                   virStorageSourcePtr src);
128 129 130 131 132 133
typedef int (*virSecurityDomainSetMemoryLabel) (virSecurityManagerPtr mgr,
                                                virDomainDefPtr def,
                                                virDomainMemoryDefPtr mem);
typedef int (*virSecurityDomainRestoreMemoryLabel) (virSecurityManagerPtr mgr,
                                                    virDomainDefPtr def,
                                                    virDomainMemoryDefPtr mem);
134 135 136 137 138 139
typedef int (*virSecurityDomainSetInputLabel) (virSecurityManagerPtr mgr,
                                               virDomainDefPtr def,
                                               virDomainInputDefPtr input);
typedef int (*virSecurityDomainRestoreInputLabel) (virSecurityManagerPtr mgr,
                                                   virDomainDefPtr def,
                                                   virDomainInputDefPtr input);
140 141
typedef int (*virSecurityDomainSetPathLabel) (virSecurityManagerPtr mgr,
                                              virDomainDefPtr def,
142 143
                                              const char *path,
                                              bool allowSubtree);
144 145 146 147 148 149 150 151
typedef int (*virSecurityDomainSetChardevLabel) (virSecurityManagerPtr mgr,
                                                 virDomainDefPtr def,
                                                 virDomainChrSourceDefPtr dev_source,
                                                 bool chardevStdioLogd);
typedef int (*virSecurityDomainRestoreChardevLabel) (virSecurityManagerPtr mgr,
                                                     virDomainDefPtr def,
                                                     virDomainChrSourceDefPtr dev_source,
                                                     bool chardevStdioLogd);
152 153 154 155
typedef int (*virSecurityDomainSetTPMLabels) (virSecurityManagerPtr mgr,
                                              virDomainDefPtr def);
typedef int (*virSecurityDomainRestoreTPMLabels) (virSecurityManagerPtr mgr,
                                                  virDomainDefPtr def);
156

157 158

struct _virSecurityDriver {
159
    size_t privateDataLen;
160 161 162
    const char *name;
    virSecurityDriverProbe probe;
    virSecurityDriverOpen open;
163 164 165 166 167
    virSecurityDriverClose close;

    virSecurityDriverGetModel getModel;
    virSecurityDriverGetDOI getDOI;

168 169
    virSecurityDriverPreFork preFork;

170 171 172 173
    virSecurityDriverTransactionStart transactionStart;
    virSecurityDriverTransactionCommit transactionCommit;
    virSecurityDriverTransactionAbort transactionAbort;

174
    virSecurityDomainSecurityVerify domainSecurityVerify;
175

176
    virSecurityDomainSetDiskLabel domainSetSecurityDiskLabel;
177
    virSecurityDomainRestoreDiskLabel domainRestoreSecurityDiskLabel;
178

179 180 181
    virSecurityDomainSetImageLabel domainSetSecurityImageLabel;
    virSecurityDomainRestoreImageLabel domainRestoreSecurityImageLabel;

182 183 184
    virSecurityDomainSetMemoryLabel domainSetSecurityMemoryLabel;
    virSecurityDomainRestoreMemoryLabel domainRestoreSecurityMemoryLabel;

185 186 187
    virSecurityDomainSetInputLabel domainSetSecurityInputLabel;
    virSecurityDomainRestoreInputLabel domainRestoreSecurityInputLabel;

188
    virSecurityDomainSetDaemonSocketLabel domainSetSecurityDaemonSocketLabel;
189
    virSecurityDomainSetSocketLabel domainSetSecuritySocketLabel;
190
    virSecurityDomainClearSocketLabel domainClearSecuritySocketLabel;
191

192
    virSecurityDomainGenLabel domainGenSecurityLabel;
193
    virSecurityDomainReserveLabel domainReserveSecurityLabel;
194
    virSecurityDomainReleaseLabel domainReleaseSecurityLabel;
195

196 197
    virSecurityDomainGetProcessLabel domainGetSecurityProcessLabel;
    virSecurityDomainSetProcessLabel domainSetSecurityProcessLabel;
198
    virSecurityDomainSetChildProcessLabel domainSetSecurityChildProcessLabel;
199

200 201
    virSecurityDomainSetAllLabel domainSetSecurityAllLabel;
    virSecurityDomainRestoreAllLabel domainRestoreSecurityAllLabel;
202

203
    virSecurityDomainSetHostdevLabel domainSetSecurityHostdevLabel;
204 205
    virSecurityDomainRestoreHostdevLabel domainRestoreSecurityHostdevLabel;

206 207
    virSecurityDomainSetSavedStateLabel domainSetSavedStateLabel;
    virSecurityDomainRestoreSavedStateLabel domainRestoreSavedStateLabel;
208

209
    virSecurityDomainSetImageFDLabel domainSetSecurityImageFDLabel;
210
    virSecurityDomainSetTapFDLabel domainSetSecurityTapFDLabel;
211 212

    virSecurityDomainGetMountOptions domainGetSecurityMountOptions;
213 214

    virSecurityDriverGetBaseLabel getBaseLabel;
215

216
    virSecurityDomainSetPathLabel domainSetPathLabel;
217 218 219

    virSecurityDomainSetChardevLabel domainSetSecurityChardevLabel;
    virSecurityDomainRestoreChardevLabel domainRestoreSecurityChardevLabel;
220 221 222

    virSecurityDomainSetTPMLabels domainSetSecurityTPMLabels;
    virSecurityDomainRestoreTPMLabels domainRestoreSecurityTPMLabels;
223 224
};

225 226
virSecurityDriverPtr virSecurityDriverLookup(const char *name,
                                             const char *virtDriver);
227 228

#endif /* __VIR_SECURITY_H__ */