uid_t uid,
gid_t gid)
{
- struct stat sb;
int save_errno = 0;
int ret = -1;
int rv;
g_autoptr(virStorageSource) cpy = NULL;
- if (virStorageSourceIsLocalStorage(src)) {
- /* use direct chown for local files so that the file doesn't
- * need to be initialized */
- if (!src->path)
- return 0;
-
- if (stat(src->path, &sb) >= 0) {
- if (sb.st_uid == uid &&
- sb.st_gid == gid) {
- /* It's alright, there's nothing to change anyway. */
- return 0;
- }
- }
-
- if (chown(src->path, uid, gid) < 0)
- return -1;
-
- return 0;
- }
+ if (virStorageSourceIsLocalStorage(src))
+ return -3;
if ((rv = virStorageSourceSupportsSecurityDriver(src)) <= 0)
return rv;
uid_t uid,
gid_t gid)
{
- int rc;
+ int rc = 0;
/* Be aware that this function might run in a separate process.
* Therefore, any driver state changes would be thrown away. */
/* on -2 returned an error was already reported */
if (rc == -2)
return -1;
- } else {
+ }
+
+ if (rc == 0 || rc == -3) {
struct stat sb;
if (!path)
* @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. */
+ * A function callback to chown image files described by the disk
+ * source struct @src. The callback can decide to skip given @src
+ * and thus let DAC driver chown the file instead (signalled by
+ * returning -3).
+ *
+ * Returns: 0 on success,
+ * -1 on error and errno set (no libvirt error reported),
+ * -2 and a libvirt error reported.
+ * -3 if callback did not handle chown
+ */
typedef int
(*virSecurityManagerDACChownCallback)(const virStorageSource *src,
uid_t uid,