Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Etc group members #50

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/treefile.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Treefile
set; rpm-ostree will modify the `/etc/nsswitch.conf` in the target
root to ensure that `/usr/lib/passwd` is used.

* `etc-group-members`: Array of strings, optional: Unix groups in this
list will be stored in `/etc/group` instead of `/usr/lib/group`. Use
this option for groups for which humans should be a member.

* `install-langs`: Array of strings, optional. This sets the RPM
_install_langs macro. Set this to e.g. `["en_US", "fr_FR"]`.

Expand Down
30 changes: 2 additions & 28 deletions src/rpmostree-compose-builtin-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1042,34 +1042,8 @@ rpmostree_compose_builtin_tree (int argc,
cancellable, error))
goto out;

{
const char *boot_location_str = NULL;
RpmOstreePostprocessBootLocation boot_location =
RPMOSTREE_POSTPROCESS_BOOT_LOCATION_BOTH;

if (!_rpmostree_jsonutil_object_get_optional_string_member (treefile, "boot_location",
&boot_location_str, error))
goto out;

if (boot_location_str != NULL)
{
if (strcmp (boot_location_str, "legacy") == 0)
boot_location = RPMOSTREE_POSTPROCESS_BOOT_LOCATION_LEGACY;
else if (strcmp (boot_location_str, "both") == 0)
boot_location = RPMOSTREE_POSTPROCESS_BOOT_LOCATION_BOTH;
else if (strcmp (boot_location_str, "new") == 0)
boot_location = RPMOSTREE_POSTPROCESS_BOOT_LOCATION_NEW;
else
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Invalid boot location '%s'", boot_location_str);
goto out;
}
}

if (!rpmostree_prepare_rootfs_for_commit (yumroot, boot_location, cancellable, error))
goto out;
}
if (!rpmostree_prepare_rootfs_for_commit (yumroot, treefile, cancellable, error))
goto out;

{
const char *gpgkey;
Expand Down
17 changes: 17 additions & 0 deletions src/rpmostree-json-parsing.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,20 @@ _rpmostree_jsonutil_append_string_array_to (JsonObject *object,

return TRUE;
}

GHashTable *
_rpmostree_jsonutil_jsarray_strings_to_set (JsonArray *array)
{
GHashTable *ret = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
guint i;
guint len = json_array_get_length (array);

for (i = 0; i < len; i++)
{
const char *elt = json_array_get_string_element (array, i);
char *duped = g_strdup (elt);
g_hash_table_insert (ret, duped, duped);
}

return ret;
}
3 changes: 3 additions & 0 deletions src/rpmostree-json-parsing.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ _rpmostree_jsonutil_append_string_array_to (JsonObject *object,
GCancellable *cancellable,
GError **error);

GHashTable *
_rpmostree_jsonutil_jsarray_strings_to_set (JsonArray *array);


72 changes: 63 additions & 9 deletions src/rpmostree-postprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
#include "rpmostree-util.h"
#include "rpmostree-treepkgdiff.h"

typedef enum {
RPMOSTREE_POSTPROCESS_BOOT_LOCATION_LEGACY,
RPMOSTREE_POSTPROCESS_BOOT_LOCATION_BOTH,
RPMOSTREE_POSTPROCESS_BOOT_LOCATION_NEW
} RpmOstreePostprocessBootLocation;

static gboolean
move_to_dir (GFile *src,
GFile *dest_dir,
Expand Down Expand Up @@ -590,6 +596,7 @@ typedef enum {
static gboolean
migrate_passwd_file_except_root (GFile *rootfs,
MigrateKind kind,
GHashTable *preserve,
GCancellable *cancellable,
GError **error)
{
Expand Down Expand Up @@ -621,6 +628,8 @@ migrate_passwd_file_except_root (GFile *rootfs,
struct group *gr = NULL;
FILE *deststream;
int r;
guint32 id;
const char *name;

if (kind == MIGRATE_PASSWD)
pw = fgetpwent (src_stream);
Expand All @@ -639,11 +648,21 @@ migrate_passwd_file_except_root (GFile *rootfs,
break;
}

if ((pw && pw->pw_uid == 0) ||
(gr && gr->gr_gid == 0))
deststream = etcdest_stream;
deststream = usrdest_stream;

if (pw)
{
id = pw->pw_uid;
name = pw->pw_name;
}
else
deststream = usrdest_stream;
{
id = gr->gr_gid;
name = gr->gr_name;
}

if (id == 0 || (preserve && g_hash_table_contains (preserve, name)))
deststream = etcdest_stream;

if (pw)
r = putpwent (pw, deststream);
Expand Down Expand Up @@ -812,14 +831,15 @@ migrate_rpm_and_yumdb (GFile *targetroot,
/* Prepare a root filesystem, taking mainly the contents of /usr from yumroot */
static gboolean
create_rootfs_from_yumroot_content (GFile *targetroot,
RpmOstreePostprocessBootLocation boot_location,
GFile *yumroot,
JsonObject *treefile,
GCancellable *cancellable,
GError **error)
{
gboolean ret = FALSE;
gs_unref_object GFile *kernel_path = NULL;
gs_unref_object GFile *initramfs_path = NULL;
gs_unref_hashtable GHashTable *preserve_groups_set = NULL;

g_print ("Preparing kernel\n");
if (!do_kernel_prep (yumroot, cancellable, error))
Expand All @@ -830,10 +850,19 @@ create_rootfs_from_yumroot_content (GFile *targetroot,
goto out;

g_print ("Migrating /etc/passwd to /usr/lib/\n");
if (!migrate_passwd_file_except_root (yumroot, MIGRATE_PASSWD, cancellable, error))
if (!migrate_passwd_file_except_root (yumroot, MIGRATE_PASSWD, NULL,
cancellable, error))
goto out;

if (json_object_has_member (treefile, "etc-group-members"))
{
JsonArray *etc_group_members = json_object_get_array_member (treefile, "etc-group-members");
preserve_groups_set = _rpmostree_jsonutil_jsarray_strings_to_set (etc_group_members);
}

g_print ("Migrating /etc/group to /usr/lib/\n");
if (!migrate_passwd_file_except_root (yumroot, MIGRATE_GROUP, cancellable, error))
if (!migrate_passwd_file_except_root (yumroot, MIGRATE_GROUP, preserve_groups_set,
cancellable, error))
goto out;

/* NSS configuration to look at the new files */
Expand Down Expand Up @@ -915,7 +944,31 @@ create_rootfs_from_yumroot_content (GFile *targetroot,
g_file_resolve_relative_path (targetroot, "usr/lib");
gs_unref_object GFile *target_usrlib_ostree_boot =
g_file_resolve_relative_path (target_usrlib, "ostree-boot");
RpmOstreePostprocessBootLocation boot_location =
RPMOSTREE_POSTPROCESS_BOOT_LOCATION_BOTH;
const char *boot_location_str = NULL;

if (!_rpmostree_jsonutil_object_get_optional_string_member (treefile,
"boot_location",
&boot_location_str, error))
goto out;

if (boot_location_str != NULL)
{
if (strcmp (boot_location_str, "legacy") == 0)
boot_location = RPMOSTREE_POSTPROCESS_BOOT_LOCATION_LEGACY;
else if (strcmp (boot_location_str, "both") == 0)
boot_location = RPMOSTREE_POSTPROCESS_BOOT_LOCATION_BOTH;
else if (strcmp (boot_location_str, "new") == 0)
boot_location = RPMOSTREE_POSTPROCESS_BOOT_LOCATION_NEW;
else
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Invalid boot location '%s'", boot_location_str);
goto out;
}
}

if (!gs_file_ensure_directory (target_usrlib, TRUE, cancellable, error))
goto out;

Expand Down Expand Up @@ -1259,7 +1312,7 @@ rpmostree_treefile_postprocessing (GFile *yumroot,
*/
gboolean
rpmostree_prepare_rootfs_for_commit (GFile *rootfs,
RpmOstreePostprocessBootLocation boot_location,
JsonObject *treefile,
GCancellable *cancellable,
GError **error)
{
Expand All @@ -1273,7 +1326,8 @@ rpmostree_prepare_rootfs_for_commit (GFile *rootfs,
if (!gs_shutil_rm_rf (rootfs_tmp, cancellable, error))
goto out;

if (!create_rootfs_from_yumroot_content (rootfs_tmp, boot_location, rootfs, cancellable, error))
if (!create_rootfs_from_yumroot_content (rootfs_tmp, rootfs, treefile,
cancellable, error))
goto out;

if (!gs_shutil_rm_rf (rootfs, cancellable, error))
Expand Down
8 changes: 1 addition & 7 deletions src/rpmostree-postprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@

#include <ostree.h>

typedef enum {
RPMOSTREE_POSTPROCESS_BOOT_LOCATION_LEGACY,
RPMOSTREE_POSTPROCESS_BOOT_LOCATION_BOTH,
RPMOSTREE_POSTPROCESS_BOOT_LOCATION_NEW
} RpmOstreePostprocessBootLocation;

gboolean
rpmostree_treefile_postprocessing (GFile *rootfs,
GFile *context_directory,
Expand All @@ -38,7 +32,7 @@ rpmostree_treefile_postprocessing (GFile *rootfs,

gboolean
rpmostree_prepare_rootfs_for_commit (GFile *rootfs,
RpmOstreePostprocessBootLocation boot_style,
JsonObject *treefile,
GCancellable *cancellable,
GError **error);

Expand Down