From fcbea6a67aabed97e3a60530d77ea243c8a19682 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 12 Oct 2018 15:39:03 -0400 Subject: [PATCH] compose: Also port one passwd bit to using Rust treefile I missed this use before in the passwd code which was also parsing the "filename" parameter. Teach this to use the fd that was opened Rust side too. It's really tempting to try oxidizing this whole file but...baby steps. Closes: #1610 Approved by: jlebon --- src/app/rpmostree-compose-builtin-tree.c | 5 ++--- src/libpriv/rpmostree-passwd-util.c | 27 +++++++++++------------- src/libpriv/rpmostree-passwd-util.h | 4 ++-- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/app/rpmostree-compose-builtin-tree.c b/src/app/rpmostree-compose-builtin-tree.c index 349f9228..66638962 100644 --- a/src/app/rpmostree-compose-builtin-tree.c +++ b/src/app/rpmostree-compose-builtin-tree.c @@ -448,7 +448,6 @@ install_packages_in_root (RpmOstreeTreeComposeContext *self, } /* Before we install packages, inject /etc/{passwd,group} if configured. */ - g_autoptr(GFile) treefile_dirpath = g_file_get_parent (self->treefile_path); gboolean generate_from_previous = TRUE; if (!_rpmostree_jsonutil_object_get_optional_boolean_member (treedata, "preserve-passwd", @@ -460,8 +459,8 @@ install_packages_in_root (RpmOstreeTreeComposeContext *self, { const char *dest = opt_unified_core ? "usr/etc/" : "etc/"; if (!rpmostree_generate_passwd_from_previous (self->repo, rootfs_dfd, dest, - treefile_dirpath, - self->previous_root, treedata, + self->treefile_rs, treedata, + self->previous_root, cancellable, error)) return FALSE; } diff --git a/src/libpriv/rpmostree-passwd-util.c b/src/libpriv/rpmostree-passwd-util.c index 9a3089fd..c626be5f 100644 --- a/src/libpriv/rpmostree-passwd-util.c +++ b/src/libpriv/rpmostree-passwd-util.c @@ -1004,7 +1004,7 @@ concat_passwd_file (int rootfs_fd, static gboolean _data_from_json (int rootfs_dfd, const char *dest, - GFile *treefile_dirpath, + RORTreefile *treefile_rs, JsonObject *treedata, RpmOstreePasswdMigrateKind kind, gboolean *out_found, @@ -1034,19 +1034,16 @@ _data_from_json (int rootfs_dfd, if (!filename) return FALSE; - g_autoptr(GFile) source = g_file_resolve_relative_path (treefile_dirpath, filename); - if (!source) - return FALSE; - /* migrate the check data from the specified file to /etc */ - g_autoptr(FILE) src_stream = NULL; - g_autofree char *contents = NULL; - if (!_rpmostree_gfile2stdio (source, &contents, &src_stream, - cancellable, error)) + int fd = passwd ? ror_treefile_get_passwd_fd (treefile_rs) : + ror_treefile_get_group_fd (treefile_rs); + size_t len = 0; + g_autofree char *contents = glnx_fd_readall_utf8 (fd, &len, cancellable, error); + if (!contents) return FALSE; - + g_autoptr(FILE) src_stream = fmemopen (contents, len, "r"); if (!src_stream) - return TRUE; + return glnx_throw_errno_prefix (error, "fmemopen"); /* no matter what we've used the data now */ *out_found = TRUE; @@ -1069,9 +1066,9 @@ gboolean rpmostree_generate_passwd_from_previous (OstreeRepo *repo, int rootfs_dfd, const char *dest, - GFile *treefile_dirpath, - GFile *previous_root, + RORTreefile *treefile_rs, JsonObject *treedata, + GFile *previous_root, GCancellable *cancellable, GError **error) { @@ -1087,7 +1084,7 @@ rpmostree_generate_passwd_from_previous (OstreeRepo *repo, if (!glnx_shutil_mkdir_p_at (rootfs_dfd, dest, 0755, cancellable, error)) return FALSE; - if (!_data_from_json (rootfs_dfd, dest, treefile_dirpath, + if (!_data_from_json (rootfs_dfd, dest, treefile_rs, treedata, RPM_OSTREE_PASSWD_MIGRATE_PASSWD, &found_passwd_data, cancellable, error)) return FALSE; @@ -1101,7 +1098,7 @@ rpmostree_generate_passwd_from_previous (OstreeRepo *repo, cancellable, error)) return FALSE; - if (!_data_from_json (rootfs_dfd, dest, treefile_dirpath, + if (!_data_from_json (rootfs_dfd, dest, treefile_rs, treedata, RPM_OSTREE_PASSWD_MIGRATE_GROUP, &found_groups_data, cancellable, error)) return FALSE; diff --git a/src/libpriv/rpmostree-passwd-util.h b/src/libpriv/rpmostree-passwd-util.h index ead50c50..2130ce56 100644 --- a/src/libpriv/rpmostree-passwd-util.h +++ b/src/libpriv/rpmostree-passwd-util.h @@ -60,9 +60,9 @@ gboolean rpmostree_generate_passwd_from_previous (OstreeRepo *repo, int rootfs_dfd, const char *dest, - GFile *treefile_dirpath, - GFile *previous_root, + RORTreefile *treefile_rs, JsonObject *treedata, + GFile *previous_root, GCancellable *cancellable, GError **error);