]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemusecuritymock: Allow some paths to be not restored
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 18 Apr 2019 09:05:18 +0000 (11:05 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 3 Jul 2019 06:36:04 +0000 (08:36 +0200)
Some paths will not be restored. Because we can't possibly know
if they are still in use or not. Reflect this in the test so that
we can test more domains. Also see next commit for more detailed
explanation.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
tests/qemusecuritymock.c
tests/qemusecuritytest.c
tests/qemusecuritytest.h

index e219a9f023fe967efd5f81b661ea84c733ea3642..2a9095e1bf934ac2c1889691ee735e1ed2b3a42e 100644 (file)
@@ -353,20 +353,28 @@ int virFileUnlock(int fd ATTRIBUTE_UNUSED,
 }
 
 
+typedef struct _checkOwnerData checkOwnerData;
+struct _checkOwnerData {
+    const char **paths;
+    bool chown_fail;
+};
+
+
 static int
 checkOwner(void *payload,
            const void *name,
-           void *data)
+           void *opaque)
 {
-    bool *chown_fail = data;
+    checkOwnerData *data = opaque;
     uint32_t owner = *((uint32_t*) payload);
 
-    if (owner % 16 != DEFAULT_UID ||
-        owner >> 16 != DEFAULT_GID) {
+    if ((owner % 16 != DEFAULT_UID ||
+         owner >> 16 != DEFAULT_GID) &&
+        !virStringListHasString(data->paths, name)) {
         fprintf(stderr,
                 "Path %s wasn't restored back to its original owner\n",
                 (const char *) name);
-        *chown_fail = true;
+        data->chown_fail = true;
     }
 
     return 0;
@@ -391,22 +399,40 @@ printXATTR(void *payload,
 }
 
 
-int checkPaths(void)
+/**
+ * checkPaths:
+ * @paths: a NULL terminated list of paths expected not to be restored
+ *
+ * Check if all paths were restored and if no XATTR was left
+ * behind. Since restore is not done on all domain's paths, some
+ * paths are expected to be not restored. A list of such paths
+ * can be passed in @paths argument. If a path is not restored
+ * but it's on the list no error is indicated.
+ */
+int checkPaths(const char **paths)
 {
     int ret = -1;
-    bool chown_fail = false;
+    checkOwnerData data = { .paths = paths, .chown_fail = false };
     bool xattr_fail = false;
+    size_t i;
 
     virMutexLock(&m);
     init_hash();
 
-    if ((virHashForEach(chown_paths, checkOwner, &chown_fail)) < 0)
+    for (i = 0; paths && paths[i]; i++) {
+        if (!virHashLookup(chown_paths, paths[i])) {
+            fprintf(stderr, "Unexpected path restored: %s\n", paths[i]);
+            goto cleanup;
+        }
+    }
+
+    if ((virHashForEach(chown_paths, checkOwner, &data)) < 0)
         goto cleanup;
 
     if ((virHashForEach(xattr_paths, printXATTR, &xattr_fail)) < 0)
         goto cleanup;
 
-    if (chown_fail || xattr_fail)
+    if (data.chown_fail || xattr_fail)
         goto cleanup;
 
     ret = 0;
index 86347f862533278a35c439f3a3c19bc4aabafc5f..65e08b45033b6227acb1e5dd47b3b766ab1db5df 100644 (file)
@@ -100,7 +100,7 @@ testDomain(const void *opaque)
 
     qemuSecurityRestoreAllLabel(data->driver, vm, false);
 
-    if (checkPaths() < 0)
+    if (checkPaths(NULL) < 0)
         goto cleanup;
 
     ret = 0;
index 812d73f073f8147778d43bf0d9b02bf6985e4100..cc3918ddf5aec078456f06758ef496af68fefdee 100644 (file)
@@ -20,6 +20,6 @@
 
 #define ENVVAR "LIBVIRT_QEMU_SECURITY_TEST"
 
-extern int checkPaths(void);
+extern int checkPaths(const char **paths);
 
 extern void freePaths(void);