From ec396b64b629a1bd600f47a6f9485b46ed1c7bca Mon Sep 17 00:00:00 2001 From: Ruixin Bao Date: Fri, 29 Jun 2018 19:59:43 +0000 Subject: [PATCH] app: add temp test command, note, this is mainly for testing As tilte. This adds a 'temp-convert' command to rpm-ostree. The main goal of this command is to convert the AH's /usr/lib/passwd and /usr/lib/group for testing purposes. This can be useful to find whether your output for conversion is correct when testing on real-world entries --- Makefile-rpm-ostree.am | 3 +- src/app/main.c | 3 ++ src/app/rpmostree-builtin-temp-convert.c | 53 ++++++++++++++++++++++++ src/app/rpmostree-builtins.h | 1 + 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/app/rpmostree-builtin-temp-convert.c diff --git a/Makefile-rpm-ostree.am b/Makefile-rpm-ostree.am index 924478ca93..bd3e33d0a7 100644 --- a/Makefile-rpm-ostree.am +++ b/Makefile-rpm-ostree.am @@ -57,7 +57,8 @@ rpm_ostree_SOURCES = src/app/main.c \ src/app/rpmostree-polkit-agent.c \ src/app/rpmostree-polkit-agent.h \ src/app/rpmostree-builtin-kargs.c \ - $(NULL) + src/app/rpmostree-builtin-temp-convert.c \ + $(NULL) if BUILDOPT_COMPOSE_TOOLING rpm_ostree_SOURCES += \ diff --git a/src/app/main.c b/src/app/main.c index 7c1ac82194..09f7cc88cd 100644 --- a/src/app/main.c +++ b/src/app/main.c @@ -89,6 +89,9 @@ static RpmOstreeCommand commands[] = { { "refresh-md", 0, "Generate rpm repo metadata", rpmostree_builtin_refresh_md }, + { "temp-convert", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD, + "temp command to convert passwd/group conversion", + rpmostree_builtin_temp_convert }, /* Legacy aliases */ { "pkg-add", RPM_OSTREE_BUILTIN_FLAG_HIDDEN, NULL, rpmostree_builtin_install }, diff --git a/src/app/rpmostree-builtin-temp-convert.c b/src/app/rpmostree-builtin-temp-convert.c new file mode 100644 index 0000000000..1fc00bae61 --- /dev/null +++ b/src/app/rpmostree-builtin-temp-convert.c @@ -0,0 +1,53 @@ +#include "config.h" +#include "libglnx.h" +#include "rpmostree-util.h" +#include "rpmostree-json-parsing.h" +#include "rpmostree-passwd-util.h" +#include "rpmostree-builtins.h" + +static char *opt_conversion_location; + + +static GOptionEntry conversion_option_entries[] = { + { "conversion_dir", 0, 0, G_OPTION_ARG_STRING, &opt_conversion_location, "Directory to convert", "CONVERSION_DIR"}, + { NULL } +}; + +// Temporarily take one argument --> mainly to convert the entries from /usr/lib/passwd into +// entries into sysusers.d +gboolean rpmostree_builtin_temp_convert (int argc, + char **argv, + RpmOstreeCommandInvocation *invocation, + GCancellable *cancellable, + GError **error) +{ + g_autoptr(GOptionContext) context = g_option_context_new (""); + if (!rpmostree_option_context_parse (context, + conversion_option_entries, + &argc, &argv, + invocation, + cancellable, + NULL, NULL, NULL, NULL, NULL, error)) + return FALSE; + g_print("Hi, this is a test\n"); + + /* Test the output for conversion, right now we can already convert the content into one string conten. The next step would just be to write a function to write sysusers entries to a new place */ + const char* passwd_content = glnx_file_get_contents_utf8_at (AT_FDCWD, "/usr/lib/passwd", NULL, cancellable, error); + const char* group_content = glnx_file_get_contents_utf8_at (AT_FDCWD, "/usr/lib/group", NULL, cancellable, error); + + g_print ("%s\n", passwd_content); + g_print ("%s\n", group_content); + // g_autoptr(GPtrArray) converted_ents = + g_autoptr(GPtrArray) passwd_ents = rpmostree_passwd_data2passwdents (passwd_content); + g_autoptr(GPtrArray) group_ents = rpmostree_passwd_data2groupents (group_content); + g_autoptr(GPtrArray) sysusers_entries = NULL; + rpmostree_passwdents2sysusers (passwd_ents, &sysusers_entries, error); + rpmostree_groupents2sysusers (group_ents, &sysusers_entries, error); + + g_autofree char* sysuser_converted_content = NULL; + rpmostree_passwd_sysusers2char (sysusers_entries, &sysuser_converted_content, error); + + g_print("%s", sysuser_converted_content); + + return TRUE; +} diff --git a/src/app/rpmostree-builtins.h b/src/app/rpmostree-builtins.h index 99b6793381..e1721cbe16 100644 --- a/src/app/rpmostree-builtins.h +++ b/src/app/rpmostree-builtins.h @@ -50,6 +50,7 @@ BUILTINPROTO(uninstall); BUILTINPROTO(override); BUILTINPROTO(start_daemon); BUILTINPROTO(ex); +BUILTINPROTO(temp_convert); #undef BUILTINPROTO