Blame SOURCES/0021-ws-Only-set-certificate-group-if-current-we-have-one.patch

ce15b8
From 3dc5e03c549e9d374e0b606870b18305b009f83c Mon Sep 17 00:00:00 2001
ce15b8
From: petervo <petervo@redhat.com>
ce15b8
Date: Wed, 30 Aug 2017 15:23:52 -0700
ce15b8
Subject: [PATCH 21/23] ws: Only set certificate group if current we have one
ce15b8
ce15b8
This is necessary to be able to build Cockpit in an nspawn-enabled mock
ce15b8
(which RHEL 7.4 now enables by default). Otherwise the unit tests fail
ce15b8
with
ce15b8
ce15b8
    Message: couldn't lookup group: mockbuild: Success
ce15b8
    ERROR:src/ws/test-remotectlcertificate.c:127:test_combine_good: assertion failed (test->ret == 0): (1 == 0)
ce15b8
ce15b8
as that group doesn't seem to exist in mock's nspawn.
ce15b8
ce15b8
Cherry-picked from b186e4c233ac (PR #7594)
ce15b8
---
ce15b8
 src/ws/remotectl-certificate.c     |  2 +-
ce15b8
 src/ws/test-remotectlcertificate.c | 11 +++++++++--
ce15b8
 2 files changed, 10 insertions(+), 3 deletions(-)
ce15b8
ce15b8
diff --git a/src/ws/remotectl-certificate.c b/src/ws/remotectl-certificate.c
ce15b8
index 8fc71d7..3abb2ae 100644
ce15b8
--- a/src/ws/remotectl-certificate.c
ce15b8
+++ b/src/ws/remotectl-certificate.c
ce15b8
@@ -115,7 +115,7 @@ set_cert_attributes (const gchar *path,
ce15b8
       g_message ("couldn't set certificate permissions: %s: %s", path, g_strerror (errno));
ce15b8
       goto out;
ce15b8
     }
ce15b8
-  if (chown (path, pwd->pw_uid, gr ? gr->gr_gid : 0) < 0)
ce15b8
+  if (chown (path, pwd->pw_uid, gr ? gr->gr_gid : -1) < 0)
ce15b8
     {
ce15b8
       g_message ("couldn't set certificate ownership: %s: %s", path, g_strerror (errno));
ce15b8
       goto out;
ce15b8
diff --git a/src/ws/test-remotectlcertificate.c b/src/ws/test-remotectlcertificate.c
ce15b8
index c9c9d3e..36c7c1f 100644
ce15b8
--- a/src/ws/test-remotectlcertificate.c
ce15b8
+++ b/src/ws/test-remotectlcertificate.c
ce15b8
@@ -29,6 +29,7 @@
ce15b8
 #include <errno.h>
ce15b8
 #include <stdlib.h>
ce15b8
 #include <string.h>
ce15b8
+#include <grp.h>
ce15b8
 
ce15b8
 const gchar *config_dir = BUILDDIR "/test-configdir";
ce15b8
 
ce15b8
@@ -81,6 +82,7 @@ setup (TestCase *tc,
ce15b8
   const TestFixture *fix = data;
ce15b8
   const gchar *old_val = g_getenv ("XDG_CONFIG_DIRS");
ce15b8
   gint i;
ce15b8
+  struct group *gr = NULL;
ce15b8
 
ce15b8
   g_setenv ("XDG_CONFIG_DIRS", config_dir, TRUE);
ce15b8
   tc->cert_dir = g_build_filename (config_dir, "cockpit", "ws-certs.d", NULL);
ce15b8
@@ -91,8 +93,13 @@ setup (TestCase *tc,
ce15b8
   g_ptr_array_add (ptr, "certificate");
ce15b8
   g_ptr_array_add (ptr, "--user");
ce15b8
   g_ptr_array_add (ptr, (gchar *) g_get_user_name ());
ce15b8
-  g_ptr_array_add (ptr, "--group");
ce15b8
-  g_ptr_array_add (ptr, (gchar *) g_get_user_name ());
ce15b8
+
ce15b8
+  gr = getgrnam (g_get_user_name ());
ce15b8
+  if (gr != NULL)
ce15b8
+    {
ce15b8
+      g_ptr_array_add (ptr, "--group");
ce15b8
+      g_ptr_array_add (ptr, (gchar *) g_get_user_name ());
ce15b8
+    }
ce15b8
 
ce15b8
   for (i = 0; fix->files[i] != NULL; i++)
ce15b8
     g_ptr_array_add (ptr, (gchar *) fix->files[i]);
ce15b8
-- 
ce15b8
2.13.5
ce15b8