mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-09-09 17:44:57 +03:00
Compare commits
9 Commits
v8.0.0
...
v1.2.19-ma
Author | SHA1 | Date | |
---|---|---|---|
|
7d3b95b038 | ||
|
4e16e7a3fc | ||
|
38d5c57b9a | ||
|
69548d2004 | ||
|
10d659cc9b | ||
|
3606f62fab | ||
|
e0025d2967 | ||
|
8b1d84e640 | ||
|
3468542f06 |
@@ -1077,9 +1077,7 @@ virDomainRestoreFlags(virConnectPtr conn, const char *from, const char *dxml,
|
||||
* previously by virDomainSave() or virDomainSaveFlags().
|
||||
*
|
||||
* No security-sensitive data will be included unless @flags contains
|
||||
* VIR_DOMAIN_XML_SECURE; this flag is rejected on read-only
|
||||
* connections. For this API, @flags should not contain either
|
||||
* VIR_DOMAIN_XML_INACTIVE or VIR_DOMAIN_XML_UPDATE_CPU.
|
||||
* VIR_DOMAIN_XML_SECURE.
|
||||
*
|
||||
* Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of
|
||||
* error. The caller must free() the returned value.
|
||||
@@ -1095,12 +1093,7 @@ virDomainSaveImageGetXMLDesc(virConnectPtr conn, const char *file,
|
||||
|
||||
virCheckConnectReturn(conn, NULL);
|
||||
virCheckNonNullArgGoto(file, error);
|
||||
|
||||
if ((conn->flags & VIR_CONNECT_RO) && (flags & VIR_DOMAIN_XML_SECURE)) {
|
||||
virReportError(VIR_ERR_OPERATION_DENIED, "%s",
|
||||
_("virDomainSaveImageGetXMLDesc with secure flag"));
|
||||
goto error;
|
||||
}
|
||||
virCheckReadOnlyGoto(conn->flags, error);
|
||||
|
||||
if (conn->driver->domainSaveImageGetXMLDesc) {
|
||||
char *ret;
|
||||
@@ -11124,6 +11117,7 @@ virConnectGetDomainCapabilities(virConnectPtr conn,
|
||||
virResetLastError();
|
||||
|
||||
virCheckConnectReturn(conn, NULL);
|
||||
virCheckReadOnlyGoto(conn->flags, error);
|
||||
|
||||
if (conn->driver->connectGetDomainCapabilities) {
|
||||
char *ret;
|
||||
|
@@ -1462,6 +1462,7 @@ virFileSanitizePath;
|
||||
virFileSkipRoot;
|
||||
virFileStripSuffix;
|
||||
virFileTouch;
|
||||
virFileUnlink;
|
||||
virFileUnlock;
|
||||
virFileUpdatePerm;
|
||||
virFileWaitForDevices;
|
||||
|
@@ -6878,7 +6878,7 @@ qemuDomainSaveImageGetXMLDesc(virConnectPtr conn, const char *path,
|
||||
if (fd < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainSaveImageGetXMLDescEnsureACL(conn, def, flags) < 0)
|
||||
if (virDomainSaveImageGetXMLDescEnsureACL(conn, def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = qemuDomainDefFormatXML(driver, def, flags);
|
||||
|
@@ -4028,6 +4028,7 @@ qemuDomainChangeGraphicsPasswords(virQEMUDriverPtr driver,
|
||||
time_t now = time(NULL);
|
||||
char expire_time [64];
|
||||
const char *connected = NULL;
|
||||
const char *password;
|
||||
int ret = -1;
|
||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||
|
||||
@@ -4035,16 +4036,14 @@ qemuDomainChangeGraphicsPasswords(virQEMUDriverPtr driver,
|
||||
ret = 0;
|
||||
goto cleanup;
|
||||
}
|
||||
password = auth->passwd ? auth->passwd : defaultPasswd;
|
||||
|
||||
if (auth->connected)
|
||||
connected = virDomainGraphicsAuthConnectedTypeToString(auth->connected);
|
||||
|
||||
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
|
||||
goto cleanup;
|
||||
ret = qemuMonitorSetPassword(priv->mon,
|
||||
type,
|
||||
auth->passwd ? auth->passwd : defaultPasswd,
|
||||
connected);
|
||||
ret = qemuMonitorSetPassword(priv->mon, type, password, connected);
|
||||
|
||||
if (ret == -2) {
|
||||
if (type != VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
|
||||
@@ -4052,14 +4051,15 @@ qemuDomainChangeGraphicsPasswords(virQEMUDriverPtr driver,
|
||||
_("Graphics password only supported for VNC"));
|
||||
ret = -1;
|
||||
} else {
|
||||
ret = qemuMonitorSetVNCPassword(priv->mon,
|
||||
auth->passwd ? auth->passwd : defaultPasswd);
|
||||
ret = qemuMonitorSetVNCPassword(priv->mon, password);
|
||||
}
|
||||
}
|
||||
if (ret != 0)
|
||||
goto end_job;
|
||||
|
||||
if (auth->expires) {
|
||||
if (password[0] == '\0') {
|
||||
snprintf(expire_time, sizeof(expire_time), "now");
|
||||
} else if (auth->expires) {
|
||||
time_t lifetime = auth->validTo - now;
|
||||
if (lifetime <= 0)
|
||||
snprintf(expire_time, sizeof(expire_time), "now");
|
||||
|
@@ -546,10 +546,6 @@ remoteClientCloseFunc(virNetClientPtr client ATTRIBUTE_UNUSED,
|
||||
cbdata->freeCallback = NULL;
|
||||
}
|
||||
virObjectUnlock(cbdata);
|
||||
|
||||
/* free the connection reference that comes along with the callback
|
||||
* registration */
|
||||
virObjectUnref(cbdata->conn);
|
||||
}
|
||||
|
||||
/* helper macro to ease extraction of arguments from the URI */
|
||||
|
@@ -4907,8 +4907,7 @@ enum remote_procedure {
|
||||
/**
|
||||
* @generate: both
|
||||
* @priority: high
|
||||
* @acl: domain:read
|
||||
* @acl: domain:read_secure:VIR_DOMAIN_XML_SECURE
|
||||
* @acl: domain:write
|
||||
*/
|
||||
REMOTE_PROC_DOMAIN_SAVE_IMAGE_GET_XML_DESC = 235,
|
||||
|
||||
|
@@ -486,6 +486,7 @@ virStorageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
int fd = -1;
|
||||
int operation_flags;
|
||||
bool reflink_copy = false;
|
||||
mode_t open_mode = VIR_STORAGE_DEFAULT_VOL_PERM_MODE;
|
||||
|
||||
virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA |
|
||||
VIR_STORAGE_VOL_CREATE_REFLINK,
|
||||
@@ -518,11 +519,12 @@ virStorageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
if (pool->def->type == VIR_STORAGE_POOL_NETFS)
|
||||
operation_flags |= VIR_FILE_OPEN_FORK;
|
||||
|
||||
if (vol->target.perms->mode != (mode_t) -1)
|
||||
open_mode = vol->target.perms->mode;
|
||||
|
||||
if ((fd = virFileOpenAs(vol->target.path,
|
||||
O_RDWR | O_CREAT | O_EXCL,
|
||||
(vol->target.perms->mode ?
|
||||
VIR_STORAGE_DEFAULT_VOL_PERM_MODE :
|
||||
vol->target.perms->mode),
|
||||
open_mode,
|
||||
vol->target.perms->uid,
|
||||
vol->target.perms->gid,
|
||||
operation_flags)) < 0) {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* storage_backend_fs.c: storage backend for FS and directory handling
|
||||
*
|
||||
* Copyright (C) 2007-2014 Red Hat, Inc.
|
||||
* Copyright (C) 2007-2015 Red Hat, Inc.
|
||||
* Copyright (C) 2007-2008 Daniel P. Berrange
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@@ -1057,6 +1057,14 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
else
|
||||
vol->type = VIR_STORAGE_VOL_FILE;
|
||||
|
||||
/* Volumes within a directory pools are not recursive; do not
|
||||
* allow escape to ../ or a subdir */
|
||||
if (strchr(vol->name, '/')) {
|
||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||
_("volume name '%s' cannot contain '/'"), vol->name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
VIR_FREE(vol->target.path);
|
||||
if (virAsprintf(&vol->target.path, "%s/%s",
|
||||
pool->def->target.path,
|
||||
@@ -1203,7 +1211,8 @@ virStorageBackendFileSystemVolDelete(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
|
||||
switch ((virStorageVolType) vol->type) {
|
||||
case VIR_STORAGE_VOL_FILE:
|
||||
if (unlink(vol->target.path) < 0) {
|
||||
if (virFileUnlink(vol->target.path, vol->target.perms->uid,
|
||||
vol->target.perms->gid) < 0) {
|
||||
/* Silently ignore failures where the vol has already gone away */
|
||||
if (errno != ENOENT) {
|
||||
virReportSystemError(errno,
|
||||
|
@@ -1867,8 +1867,12 @@ storageVolCreateXML(virStoragePoolPtr obj,
|
||||
}
|
||||
|
||||
if (backend->refreshVol &&
|
||||
backend->refreshVol(obj->conn, pool, voldef) < 0)
|
||||
backend->refreshVol(obj->conn, pool, voldef) < 0) {
|
||||
storageVolDeleteInternal(volobj, backend, pool, voldef,
|
||||
0, false);
|
||||
voldef = NULL;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Update pool metadata ignoring the disk backend since
|
||||
* it updates the pool values.
|
||||
|
@@ -2306,6 +2306,112 @@ virFileOpenAs(const char *path, int openflags, mode_t mode,
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* virFileUnlink:
|
||||
* @path: file to unlink
|
||||
* @uid: uid that was used to create the file (not required)
|
||||
* @gid: gid that was used to create the file (not required)
|
||||
*
|
||||
* If a file/volume was created in an NFS root-squash environment,
|
||||
* then we must 'unlink' the file in the same environment. Unlike
|
||||
* the virFileOpenAs[Forked] and virDirCreate[NoFork], this code
|
||||
* takes no extra flags and does not bother with EACCES failures
|
||||
* from the child.
|
||||
*/
|
||||
int
|
||||
virFileUnlink(const char *path,
|
||||
uid_t uid,
|
||||
gid_t gid)
|
||||
{
|
||||
pid_t pid;
|
||||
int waitret;
|
||||
int status, ret = 0;
|
||||
gid_t *groups;
|
||||
int ngroups;
|
||||
|
||||
/* If not running as root or if a non explicit uid/gid was being used for
|
||||
* the file/volume, then use unlink directly
|
||||
*/
|
||||
if ((geteuid() != 0) ||
|
||||
((uid == (uid_t) -1) && (gid == (gid_t) -1)))
|
||||
return unlink(path);
|
||||
|
||||
/* Otherwise, we have to deal with the NFS root-squash craziness
|
||||
* to run under the uid/gid that created the volume in order to
|
||||
* perform the unlink of the volume.
|
||||
*/
|
||||
if (uid == (uid_t) -1)
|
||||
uid = geteuid();
|
||||
if (gid == (gid_t) -1)
|
||||
gid = getegid();
|
||||
|
||||
ngroups = virGetGroupList(uid, gid, &groups);
|
||||
if (ngroups < 0)
|
||||
return -errno;
|
||||
|
||||
pid = virFork();
|
||||
|
||||
if (pid < 0) {
|
||||
ret = -errno;
|
||||
VIR_FREE(groups);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (pid) { /* parent */
|
||||
/* wait for child to complete, and retrieve its exit code */
|
||||
VIR_FREE(groups);
|
||||
|
||||
while ((waitret = waitpid(pid, &status, 0)) == -1 && errno == EINTR);
|
||||
if (waitret == -1) {
|
||||
ret = -errno;
|
||||
virReportSystemError(errno,
|
||||
_("failed to wait for child unlinking '%s'"),
|
||||
path);
|
||||
goto parenterror;
|
||||
}
|
||||
|
||||
/*
|
||||
* If waitpid succeeded, but if the child exited abnormally or
|
||||
* reported non-zero status, report failure
|
||||
*/
|
||||
if (!WIFEXITED(status) || (WEXITSTATUS(status)) != 0) {
|
||||
char *msg = virProcessTranslateStatus(status);
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("child failed to unlink '%s': %s"),
|
||||
path, msg);
|
||||
VIR_FREE(msg);
|
||||
if (WIFEXITED(status))
|
||||
ret = -WEXITSTATUS(status);
|
||||
else
|
||||
ret = -EACCES;
|
||||
}
|
||||
|
||||
parenterror:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* child */
|
||||
|
||||
/* set desired uid/gid, then attempt to unlink the file */
|
||||
if (virSetUIDGID(uid, gid, groups, ngroups) < 0) {
|
||||
ret = errno;
|
||||
goto childerror;
|
||||
}
|
||||
|
||||
if (unlink(path) < 0) {
|
||||
ret = errno;
|
||||
goto childerror;
|
||||
}
|
||||
|
||||
childerror:
|
||||
if ((ret & 0xff) != ret) {
|
||||
VIR_WARN("unable to pass desired return value %d", ret);
|
||||
ret = 0xff;
|
||||
}
|
||||
_exit(ret);
|
||||
}
|
||||
|
||||
|
||||
/* return -errno on failure, or 0 on success */
|
||||
static int
|
||||
virDirCreateNoFork(const char *path,
|
||||
|
@@ -219,6 +219,7 @@ int virFileOpenAs(const char *path, int openflags, mode_t mode,
|
||||
uid_t uid, gid_t gid,
|
||||
unsigned int flags)
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
|
||||
int virFileUnlink(const char *path, uid_t uid, gid_t gid);
|
||||
|
||||
enum {
|
||||
VIR_DIR_CREATE_NONE = 0,
|
||||
|
@@ -2552,8 +2552,8 @@ vshReadlineInit(vshControl *ctl)
|
||||
char *name_capitalized = NULL;
|
||||
int max_history = 500;
|
||||
int ret = -1;
|
||||
char *histsize_env = NULL;
|
||||
const char *histsize_str = NULL;
|
||||
const char *histsize_env = NULL;
|
||||
const char *strings[] = {
|
||||
name_capitalized,
|
||||
"HISTSIZE",
|
||||
@@ -2613,6 +2613,7 @@ vshReadlineInit(vshControl *ctl)
|
||||
cleanup:
|
||||
VIR_FREE(userdir);
|
||||
VIR_FREE(name_capitalized);
|
||||
VIR_FREE(histsize_env);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user