security_manager.h 7.8 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 65 66 67 68 69
/**
 * 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
(*virSecurityManagerDACChownCallback)(virStorageSourcePtr src,
                                      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
void *virSecurityManagerGetPrivateData(virSecurityManagerPtr mgr);

81
const char *virSecurityManagerGetDriver(virSecurityManagerPtr mgr);
82 83
const char *virSecurityManagerGetDOI(virSecurityManagerPtr mgr);
const char *virSecurityManagerGetModel(virSecurityManagerPtr mgr);
84 85
const char *virSecurityManagerGetBaseLabel(virSecurityManagerPtr mgr, int virtType);

86
bool virSecurityManagerGetAllowDiskFormatProbing(virSecurityManagerPtr mgr);
87 88
bool virSecurityManagerGetDefaultConfined(virSecurityManagerPtr mgr);
bool virSecurityManagerGetRequireConfined(virSecurityManagerPtr mgr);
89
bool virSecurityManagerGetPrivileged(virSecurityManagerPtr mgr);
90

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

153 154 155 156 157 158 159
int virSecurityManagerSetImageLabel(virSecurityManagerPtr mgr,
                                    virDomainDefPtr vm,
                                    virStorageSourcePtr src);
int virSecurityManagerRestoreImageLabel(virSecurityManagerPtr mgr,
                                        virDomainDefPtr vm,
                                        virStorageSourcePtr src);

160 161 162
int virSecurityManagerDomainSetPathLabel(virSecurityManagerPtr mgr,
                                         virDomainDefPtr vm,
                                         const char *path);
163

164
#endif /* VIR_SECURITY_MANAGER_H__ */