areguera / rpms / cockpit

Forked from rpms/cockpit 4 years ago
Clone
Blob Blame History Raw
From 3dc5e03c549e9d374e0b606870b18305b009f83c Mon Sep 17 00:00:00 2001
From: petervo <petervo@redhat.com>
Date: Wed, 30 Aug 2017 15:23:52 -0700
Subject: [PATCH 21/23] ws: Only set certificate group if current we have one

This is necessary to be able to build Cockpit in an nspawn-enabled mock
(which RHEL 7.4 now enables by default). Otherwise the unit tests fail
with

    Message: couldn't lookup group: mockbuild: Success
    ERROR:src/ws/test-remotectlcertificate.c:127:test_combine_good: assertion failed (test->ret == 0): (1 == 0)

as that group doesn't seem to exist in mock's nspawn.

Cherry-picked from b186e4c233ac (PR #7594)
---
 src/ws/remotectl-certificate.c     |  2 +-
 src/ws/test-remotectlcertificate.c | 11 +++++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/ws/remotectl-certificate.c b/src/ws/remotectl-certificate.c
index 8fc71d7..3abb2ae 100644
--- a/src/ws/remotectl-certificate.c
+++ b/src/ws/remotectl-certificate.c
@@ -115,7 +115,7 @@ set_cert_attributes (const gchar *path,
       g_message ("couldn't set certificate permissions: %s: %s", path, g_strerror (errno));
       goto out;
     }
-  if (chown (path, pwd->pw_uid, gr ? gr->gr_gid : 0) < 0)
+  if (chown (path, pwd->pw_uid, gr ? gr->gr_gid : -1) < 0)
     {
       g_message ("couldn't set certificate ownership: %s: %s", path, g_strerror (errno));
       goto out;
diff --git a/src/ws/test-remotectlcertificate.c b/src/ws/test-remotectlcertificate.c
index c9c9d3e..36c7c1f 100644
--- a/src/ws/test-remotectlcertificate.c
+++ b/src/ws/test-remotectlcertificate.c
@@ -29,6 +29,7 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
+#include <grp.h>
 
 const gchar *config_dir = BUILDDIR "/test-configdir";
 
@@ -81,6 +82,7 @@ setup (TestCase *tc,
   const TestFixture *fix = data;
   const gchar *old_val = g_getenv ("XDG_CONFIG_DIRS");
   gint i;
+  struct group *gr = NULL;
 
   g_setenv ("XDG_CONFIG_DIRS", config_dir, TRUE);
   tc->cert_dir = g_build_filename (config_dir, "cockpit", "ws-certs.d", NULL);
@@ -91,8 +93,13 @@ setup (TestCase *tc,
   g_ptr_array_add (ptr, "certificate");
   g_ptr_array_add (ptr, "--user");
   g_ptr_array_add (ptr, (gchar *) g_get_user_name ());
-  g_ptr_array_add (ptr, "--group");
-  g_ptr_array_add (ptr, (gchar *) g_get_user_name ());
+
+  gr = getgrnam (g_get_user_name ());
+  if (gr != NULL)
+    {
+      g_ptr_array_add (ptr, "--group");
+      g_ptr_array_add (ptr, (gchar *) g_get_user_name ());
+    }
 
   for (i = 0; fix->files[i] != NULL; i++)
     g_ptr_array_add (ptr, (gchar *) fix->files[i]);
-- 
2.13.5