security_manager.h 8.5 KB
Newer Older
1 2 3
/*
 * security_manager.h: Internal security manager API
 *
4
 * Copyright (C) 2010-2013 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14 15 16
 *
 * 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.
 *
 * 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
17
 * License along with this library.  If not, see
O
Osier Yang 已提交
18
 * <http://www.gnu.org/licenses/>.
19 20 21 22 23 24 25
 *
 * Author: Daniel P. Berrange <berrange@redhat.com>
 */

#ifndef VIR_SECURITY_MANAGER_H__
# define VIR_SECURITY_MANAGER_H__

26
# include "domain_conf.h"
27
# include "vircommand.h"
28
# include "virstoragefile.h"
29

30 31 32
typedef struct _virSecurityManager virSecurityManager;
typedef virSecurityManager *virSecurityManagerPtr;

33 34 35 36 37 38 39 40 41 42 43 44 45 46
typedef enum {
    VIR_SECURITY_MANAGER_ALLOW_DISK_PROBE   = 1 << 0,
    VIR_SECURITY_MANAGER_DEFAULT_CONFINED   = 1 << 1,
    VIR_SECURITY_MANAGER_REQUIRE_CONFINED   = 1 << 2,
    VIR_SECURITY_MANAGER_PRIVILEGED         = 1 << 3,
    VIR_SECURITY_MANAGER_DYNAMIC_OWNERSHIP  = 1 << 4,
} virSecurityManagerNewFlags;

# define VIR_SECURITY_MANAGER_NEW_MASK  \
    (VIR_SECURITY_MANAGER_ALLOW_DISK_PROBE  | \
     VIR_SECURITY_MANAGER_DEFAULT_CONFINED  | \
     VIR_SECURITY_MANAGER_REQUIRE_CONFINED  | \
     VIR_SECURITY_MANAGER_PRIVILEGED)

47
virSecurityManagerPtr virSecurityManagerNew(const char *name,
48
                                            const char *virtDriver,
49
                                            unsigned int flags);
50

51 52 53
virSecurityManagerPtr virSecurityManagerNewStack(virSecurityManagerPtr primary);
int virSecurityManagerStackAddNested(virSecurityManagerPtr stack,
                                     virSecurityManagerPtr nested);
54

55 56 57 58 59 60 61 62 63 64
/**
 * virSecurityManagerDACChownCallback:
 * @src: Storage file to chown
 * @uid: target uid
 * @gid: target gid
 *
 * A function callback to chown image files described by the disk source struct
 * @src. The callback shall return 0 on success, -1 on error and errno set (no
 * libvirt error reported) OR -2 and a libvirt error reported. */
typedef int
65
(*virSecurityManagerDACChownCallback)(const virStorageSource *src,
66 67 68 69
                                      uid_t uid,
                                      gid_t gid);


70 71
virSecurityManagerPtr virSecurityManagerNewDAC(const char *virtDriver,
                                               uid_t user,
72
                                               gid_t group,
73
                                               unsigned int flags,
74
                                               virSecurityManagerDACChownCallback chownCallback);
75

76
int virSecurityManagerPreFork(virSecurityManagerPtr mgr);
77 78
void virSecurityManagerPostFork(virSecurityManagerPtr mgr);

79 80 81 82 83
int virSecurityManagerTransactionStart(virSecurityManagerPtr mgr);
int virSecurityManagerTransactionCommit(virSecurityManagerPtr mgr,
                                        pid_t pid);
void virSecurityManagerTransactionAbort(virSecurityManagerPtr mgr);

84 85
void *virSecurityManagerGetPrivateData(virSecurityManagerPtr mgr);

86
const char *virSecurityManagerGetDriver(virSecurityManagerPtr mgr);
87 88
const char *virSecurityManagerGetDOI(virSecurityManagerPtr mgr);
const char *virSecurityManagerGetModel(virSecurityManagerPtr mgr);
89 90
const char *virSecurityManagerGetBaseLabel(virSecurityManagerPtr mgr, int virtType);

91
bool virSecurityManagerGetAllowDiskFormatProbing(virSecurityManagerPtr mgr);
92 93
bool virSecurityManagerGetDefaultConfined(virSecurityManagerPtr mgr);
bool virSecurityManagerGetRequireConfined(virSecurityManagerPtr mgr);
94
bool virSecurityManagerGetPrivileged(virSecurityManagerPtr mgr);
95

96 97 98
int virSecurityManagerRestoreDiskLabel(virSecurityManagerPtr mgr,
                                       virDomainDefPtr def,
                                       virDomainDiskDefPtr disk);
99
int virSecurityManagerSetDaemonSocketLabel(virSecurityManagerPtr mgr,
100
                                           virDomainDefPtr vm);
101
int virSecurityManagerSetSocketLabel(virSecurityManagerPtr mgr,
102
                                     virDomainDefPtr def);
103
int virSecurityManagerClearSocketLabel(virSecurityManagerPtr mgr,
104
                                       virDomainDefPtr def);
105 106 107
int virSecurityManagerSetDiskLabel(virSecurityManagerPtr mgr,
                                   virDomainDefPtr def,
                                   virDomainDiskDefPtr disk);
108
int virSecurityManagerRestoreHostdevLabel(virSecurityManagerPtr mgr,
109
                                          virDomainDefPtr def,
110 111
                                          virDomainHostdevDefPtr dev,
                                          const char *vroot);
112
int virSecurityManagerSetHostdevLabel(virSecurityManagerPtr mgr,
113
                                      virDomainDefPtr def,
114 115
                                      virDomainHostdevDefPtr dev,
                                      const char *vroot);
116
int virSecurityManagerSetSavedStateLabel(virSecurityManagerPtr mgr,
117
                                         virDomainDefPtr def,
118 119
                                         const char *savefile);
int virSecurityManagerRestoreSavedStateLabel(virSecurityManagerPtr mgr,
120
                                             virDomainDefPtr def,
121 122
                                             const char *savefile);
int virSecurityManagerGenLabel(virSecurityManagerPtr mgr,
123
                               virDomainDefPtr sec);
124
int virSecurityManagerReserveLabel(virSecurityManagerPtr mgr,
125 126
                                   virDomainDefPtr sec,
                                   pid_t pid);
127
int virSecurityManagerReleaseLabel(virSecurityManagerPtr mgr,
128
                                   virDomainDefPtr sec);
129 130
int virSecurityManagerCheckAllLabel(virSecurityManagerPtr mgr,
                                    virDomainDefPtr sec);
131
int virSecurityManagerSetAllLabel(virSecurityManagerPtr mgr,
132
                                  virDomainDefPtr sec,
133 134
                                  const char *stdin_path);
int virSecurityManagerRestoreAllLabel(virSecurityManagerPtr mgr,
135
                                      virDomainDefPtr def,
136
                                      bool migrated);
137
int virSecurityManagerGetProcessLabel(virSecurityManagerPtr mgr,
138 139
                                      virDomainDefPtr def,
                                      pid_t pid,
140 141
                                      virSecurityLabelPtr sec);
int virSecurityManagerSetProcessLabel(virSecurityManagerPtr mgr,
142
                                      virDomainDefPtr def);
143 144 145
int virSecurityManagerSetChildProcessLabel(virSecurityManagerPtr mgr,
                                           virDomainDefPtr def,
                                           virCommandPtr cmd);
146 147
int virSecurityManagerVerify(virSecurityManagerPtr mgr,
                             virDomainDefPtr def);
148
int virSecurityManagerSetImageFDLabel(virSecurityManagerPtr mgr,
149
                                      virDomainDefPtr def,
150
                                      int fd);
151 152 153
int virSecurityManagerSetTapFDLabel(virSecurityManagerPtr mgr,
                                    virDomainDefPtr vm,
                                    int fd);
154
char *virSecurityManagerGetMountOptions(virSecurityManagerPtr mgr,
155 156
                                        virDomainDefPtr vm);
virSecurityManagerPtr* virSecurityManagerGetNested(virSecurityManagerPtr mgr);
157

158 159 160 161 162 163 164
int virSecurityManagerSetImageLabel(virSecurityManagerPtr mgr,
                                    virDomainDefPtr vm,
                                    virStorageSourcePtr src);
int virSecurityManagerRestoreImageLabel(virSecurityManagerPtr mgr,
                                        virDomainDefPtr vm,
                                        virStorageSourcePtr src);

165 166 167 168 169 170 171
int virSecurityManagerSetMemoryLabel(virSecurityManagerPtr mgr,
                                     virDomainDefPtr vm,
                                     virDomainMemoryDefPtr mem);
int virSecurityManagerRestoreMemoryLabel(virSecurityManagerPtr mgr,
                                        virDomainDefPtr vm,
                                        virDomainMemoryDefPtr mem);

172 173 174
int virSecurityManagerDomainSetPathLabel(virSecurityManagerPtr mgr,
                                         virDomainDefPtr vm,
                                         const char *path);
175

176
#endif /* VIR_SECURITY_MANAGER_H__ */