Skip to content

Commit

Permalink
ws: Only set certificate group if current we have one
Browse files Browse the repository at this point in the history
Closes #7594
Reviewed-by: Stef Walter <stefw@redhat.com>
  • Loading branch information
petervo authored and stefwalter committed Sep 1, 2017
1 parent b00ac63 commit b186e4c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ws/remotectl-certificate.c
Expand Up @@ -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;
Expand Down
11 changes: 9 additions & 2 deletions src/ws/test-remotectlcertificate.c
Expand Up @@ -29,6 +29,7 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <grp.h>

const gchar *config_dir = BUILDDIR "/test-configdir";

Expand Down Expand Up @@ -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);
Expand All @@ -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]);
Expand Down

0 comments on commit b186e4c

Please sign in to comment.