mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-21 19:02:25 +00:00
security_dac: Resolve virSecurityDACSetOwnershipInternal const correctness
The code at the very bottom of the DAC secdriver that calls chown() should be fine with read-only data. If something needs to be prepared it should have been done beforehand. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
feeaa015c1
commit
39779eb195
@ -329,10 +329,11 @@ qemuAutostartDomains(virQEMUDriverPtr driver)
|
||||
|
||||
|
||||
static int
|
||||
qemuSecurityChownCallback(virStorageSourcePtr src,
|
||||
qemuSecurityChownCallback(const virStorageSource *src,
|
||||
uid_t uid,
|
||||
gid_t gid)
|
||||
{
|
||||
virStorageSourcePtr cpy = NULL;
|
||||
struct stat sb;
|
||||
int save_errno = 0;
|
||||
int ret = -1;
|
||||
@ -354,22 +355,28 @@ qemuSecurityChownCallback(virStorageSourcePtr src,
|
||||
}
|
||||
}
|
||||
|
||||
return chown(src->path, uid, gid);
|
||||
}
|
||||
if (chown(src->path, uid, gid) < 0)
|
||||
goto cleanup;
|
||||
} else {
|
||||
if (!(cpy = virStorageSourceCopy(src, false)))
|
||||
goto cleanup;
|
||||
|
||||
/* storage file init reports errors, return -2 on failure */
|
||||
if (virStorageFileInit(src) < 0)
|
||||
return -2;
|
||||
/* src file init reports errors, return -2 on failure */
|
||||
if (virStorageFileInit(cpy) < 0) {
|
||||
ret = -2;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virStorageFileChown(src, uid, gid) < 0) {
|
||||
save_errno = errno;
|
||||
goto cleanup;
|
||||
if (virStorageFileChown(cpy, uid, gid) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
virStorageFileDeinit(src);
|
||||
save_errno = errno;
|
||||
virStorageFileDeinit(cpy);
|
||||
virStorageSourceFree(cpy);
|
||||
errno = save_errno;
|
||||
|
||||
return ret;
|
||||
|
@ -279,8 +279,8 @@ virSecurityDACPreFork(virSecurityManagerPtr mgr)
|
||||
}
|
||||
|
||||
static int
|
||||
virSecurityDACSetOwnershipInternal(virSecurityDACDataPtr priv,
|
||||
virStorageSourcePtr src,
|
||||
virSecurityDACSetOwnershipInternal(const virSecurityDACData *priv,
|
||||
const virStorageSource *src,
|
||||
const char *path,
|
||||
uid_t uid,
|
||||
gid_t gid)
|
||||
|
@ -62,7 +62,7 @@ int virSecurityManagerStackAddNested(virSecurityManagerPtr stack,
|
||||
* @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,
|
||||
(*virSecurityManagerDACChownCallback)(const virStorageSource *src,
|
||||
uid_t uid,
|
||||
gid_t gid);
|
||||
|
||||
|
@ -285,7 +285,7 @@ typedef int
|
||||
int mode);
|
||||
|
||||
typedef int
|
||||
(*virStorageFileBackendChown)(virStorageSourcePtr src,
|
||||
(*virStorageFileBackendChown)(const virStorageSource *src,
|
||||
uid_t uid,
|
||||
gid_t gid);
|
||||
|
||||
|
@ -1600,7 +1600,7 @@ virStorageFileBackendFileAccess(virStorageSourcePtr src,
|
||||
|
||||
|
||||
static int
|
||||
virStorageFileBackendFileChown(virStorageSourcePtr src,
|
||||
virStorageFileBackendFileChown(const virStorageSource *src,
|
||||
uid_t uid,
|
||||
gid_t gid)
|
||||
{
|
||||
|
@ -809,7 +809,7 @@ virStorageFileBackendGlusterGetUniqueIdentifier(virStorageSourcePtr src)
|
||||
|
||||
|
||||
static int
|
||||
virStorageFileBackendGlusterChown(virStorageSourcePtr src,
|
||||
virStorageFileBackendGlusterChown(const virStorageSource *src,
|
||||
uid_t uid,
|
||||
gid_t gid)
|
||||
{
|
||||
|
@ -2848,7 +2848,7 @@ int storageRegister(void)
|
||||
|
||||
/* ----------- file handlers cooperating with storage driver --------------- */
|
||||
static bool
|
||||
virStorageFileIsInitialized(virStorageSourcePtr src)
|
||||
virStorageFileIsInitialized(const virStorageSource *src)
|
||||
{
|
||||
return src && src->drv;
|
||||
}
|
||||
@ -2888,7 +2888,7 @@ virStorageFileSupportsBackingChainTraversal(virStorageSourcePtr src)
|
||||
* driver to perform labelling
|
||||
*/
|
||||
bool
|
||||
virStorageFileSupportsSecurityDriver(virStorageSourcePtr src)
|
||||
virStorageFileSupportsSecurityDriver(const virStorageSource *src)
|
||||
{
|
||||
int actualType;
|
||||
virStorageFileBackendPtr backend;
|
||||
@ -3179,7 +3179,7 @@ virStorageFileAccess(virStorageSourcePtr src,
|
||||
* by libvirt storage backend.
|
||||
*/
|
||||
int
|
||||
virStorageFileChown(virStorageSourcePtr src,
|
||||
virStorageFileChown(const virStorageSource *src,
|
||||
uid_t uid,
|
||||
gid_t gid)
|
||||
{
|
||||
|
@ -44,9 +44,9 @@ ssize_t virStorageFileReadHeader(virStorageSourcePtr src,
|
||||
char **buf);
|
||||
const char *virStorageFileGetUniqueIdentifier(virStorageSourcePtr src);
|
||||
int virStorageFileAccess(virStorageSourcePtr src, int mode);
|
||||
int virStorageFileChown(virStorageSourcePtr src, uid_t uid, gid_t gid);
|
||||
int virStorageFileChown(const virStorageSource *src, uid_t uid, gid_t gid);
|
||||
|
||||
bool virStorageFileSupportsSecurityDriver(virStorageSourcePtr src);
|
||||
bool virStorageFileSupportsSecurityDriver(const virStorageSource *src);
|
||||
|
||||
int virStorageFileGetMetadata(virStorageSourcePtr src,
|
||||
uid_t uid, gid_t gid,
|
||||
|
@ -2082,7 +2082,7 @@ virStorageSourceGetActualType(const virStorageSource *def)
|
||||
|
||||
|
||||
bool
|
||||
virStorageSourceIsLocalStorage(virStorageSourcePtr src)
|
||||
virStorageSourceIsLocalStorage(const virStorageSource *src)
|
||||
{
|
||||
virStorageType type = virStorageSourceGetActualType(src);
|
||||
|
||||
|
@ -349,7 +349,7 @@ int virStorageSourceInitChainElement(virStorageSourcePtr newelem,
|
||||
void virStorageSourcePoolDefFree(virStorageSourcePoolDefPtr def);
|
||||
void virStorageSourceClear(virStorageSourcePtr def);
|
||||
int virStorageSourceGetActualType(const virStorageSource *def);
|
||||
bool virStorageSourceIsLocalStorage(virStorageSourcePtr src);
|
||||
bool virStorageSourceIsLocalStorage(const virStorageSource *src);
|
||||
bool virStorageSourceIsEmpty(virStorageSourcePtr src);
|
||||
bool virStorageSourceIsBlockLocal(const virStorageSource *src);
|
||||
void virStorageSourceFree(virStorageSourcePtr def);
|
||||
|
Loading…
x
Reference in New Issue
Block a user