From 24b1e9c0acd6778e156b667348f4cf922aac013c Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 17 Mar 2014 12:28:36 -0400 Subject: [PATCH] Add "ostree admin instutil", move selinux-ensure-labeled there There are going to be a few utilities that are only useful for installers and disk image creation tools. Let's not expose them all at the toplevel; instead, hide them under "instutil". --- Makefile-ostree.am | 4 +- src/ostree/ot-admin-builtin-instutil.c | 153 ++++++++++++++++++ src/ostree/ot-admin-builtins.h | 1 + ...instutil-builtin-selinux-ensure-labeled.c} | 5 +- src/ostree/ot-admin-instutil-builtins.h | 30 ++++ src/ostree/ot-builtin-admin.c | 4 +- 6 files changed, 190 insertions(+), 7 deletions(-) create mode 100644 src/ostree/ot-admin-builtin-instutil.c rename src/ostree/{ot-admin-builtin-selinux-ensure-labeled.c => ot-admin-instutil-builtin-selinux-ensure-labeled.c} (97%) create mode 100644 src/ostree/ot-admin-instutil-builtins.h diff --git a/Makefile-ostree.am b/Makefile-ostree.am index 8537b195..d96b577b 100644 --- a/Makefile-ostree.am +++ b/Makefile-ostree.am @@ -56,13 +56,15 @@ ostree_SOURCES += \ src/ostree/ot-admin-builtin-diff.c \ src/ostree/ot-admin-builtin-deploy.c \ src/ostree/ot-admin-builtin-undeploy.c \ + src/ostree/ot-admin-builtin-instutil.c \ src/ostree/ot-admin-builtin-cleanup.c \ src/ostree/ot-admin-builtin-os-init.c \ - src/ostree/ot-admin-builtin-selinux-ensure-labeled.c \ src/ostree/ot-admin-builtin-status.c \ src/ostree/ot-admin-builtin-switch.c \ src/ostree/ot-admin-builtin-upgrade.c \ src/ostree/ot-admin-builtins.h \ + src/ostree/ot-admin-instutil-builtin-selinux-ensure-labeled.c \ + src/ostree/ot-admin-instutil-builtins.h \ src/ostree/ot-admin-functions.h \ src/ostree/ot-admin-functions.c \ $(NULL) diff --git a/src/ostree/ot-admin-builtin-instutil.c b/src/ostree/ot-admin-builtin-instutil.c new file mode 100644 index 00000000..aa59b7ab --- /dev/null +++ b/src/ostree/ot-admin-builtin-instutil.c @@ -0,0 +1,153 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * + * Copyright (C) 2011,2014 Colin Walters + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include "ot-builtins.h" +#include "ot-admin-instutil-builtins.h" +#include "ot-admin-builtins.h" +#include "ot-admin-functions.h" +#include "ot-main.h" +#include "ostree.h" +#include "libgsystem.h" + +#include + +typedef struct { + const char *name; + gboolean (*fn) (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error); +} OstreeAdminInstUtilCommand; + +static OstreeAdminInstUtilCommand admin_instutil_subcommands[] = { +#ifdef HAVE_SELINUX + { "selinux-ensure-labeled", ot_admin_instutil_builtin_selinux_ensure_labeled }, +#endif + { NULL, NULL } +}; + +gboolean +ot_admin_builtin_instutil (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error) +{ + gboolean ret = FALSE; + OstreeAdminInstUtilCommand *subcommand; + const char *subcommand_name = NULL; + gboolean want_help = FALSE; + int in, out, i; + gboolean skip; + + for (in = 1, out = 1; in < argc; in++, out++) + { + /* The non-option is the command, take it out of the arguments */ + if (argv[in][0] != '-') + { + skip = (subcommand_name == NULL); + if (subcommand_name == NULL) + subcommand_name = argv[in]; + } + + /* The global long options */ + else if (argv[in][1] == '-') + { + skip = FALSE; + + if (g_str_equal (argv[in], "--")) + { + break; + } + else if (g_str_equal (argv[in], "--help")) + { + want_help = TRUE; + } + else if (subcommand_name == NULL) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, + "Unknown or invalid admin instutil option: %s", argv[in]); + goto out; + } + } + + /* The global short options */ + else + { + skip = FALSE; + for (i = 1; argv[in][i] != '\0'; i++) + { + switch (argv[in][i]) + { + case 'h': + want_help = TRUE; + break; + + default: + if (subcommand_name == NULL) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, + "Unknown or invalid admin instutil option: %s", argv[in]); + goto out; + } + break; + } + } + } + + /* Skipping this argument? */ + if (skip) + out--; + else + argv[out] = argv[in]; + } + + argc = out; + + if (subcommand_name == NULL || want_help) + { + subcommand = admin_instutil_subcommands; + g_print ("usage: ostree admin instutil COMMAND [options]\n"); + g_print ("Builtin commands:\n"); + while (subcommand->name) + { + g_print (" %s\n", subcommand->name); + subcommand++; + } + return subcommand_name == NULL ? 1 : 0; + } + + subcommand = admin_instutil_subcommands; + while (subcommand->name) + { + if (g_strcmp0 (subcommand_name, subcommand->name) == 0) + break; + subcommand++; + } + + if (!subcommand->name) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, + "Unknown admin instutil command '%s'", subcommand_name); + goto out; + } + + if (!subcommand->fn (argc, argv, sysroot, cancellable, error)) + goto out; + + ret = TRUE; + out: + return ret; +} diff --git a/src/ostree/ot-admin-builtins.h b/src/ostree/ot-admin-builtins.h index 2ccf2e60..a4e5754f 100644 --- a/src/ostree/ot-admin-builtins.h +++ b/src/ostree/ot-admin-builtins.h @@ -29,6 +29,7 @@ G_BEGIN_DECLS gboolean ot_admin_builtin_selinux_ensure_labeled (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error); gboolean ot_admin_builtin_os_init (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error); gboolean ot_admin_builtin_install (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error); +gboolean ot_admin_builtin_instutil (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error); gboolean ot_admin_builtin_init_fs (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error); gboolean ot_admin_builtin_undeploy (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error); gboolean ot_admin_builtin_deploy (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error); diff --git a/src/ostree/ot-admin-builtin-selinux-ensure-labeled.c b/src/ostree/ot-admin-instutil-builtin-selinux-ensure-labeled.c similarity index 97% rename from src/ostree/ot-admin-builtin-selinux-ensure-labeled.c rename to src/ostree/ot-admin-instutil-builtin-selinux-ensure-labeled.c index 4fc671e8..6bc80475 100644 --- a/src/ostree/ot-admin-builtin-selinux-ensure-labeled.c +++ b/src/ostree/ot-admin-instutil-builtin-selinux-ensure-labeled.c @@ -23,8 +23,7 @@ #include #include -#include "ot-admin-builtins.h" -#include "ot-admin-functions.h" +#include "ot-admin-instutil-builtins.h" #include "otutil.h" @@ -175,7 +174,7 @@ selinux_relabel_dir (OstreeSePolicy *sepolicy, } gboolean -ot_admin_builtin_selinux_ensure_labeled (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error) +ot_admin_instutil_builtin_selinux_ensure_labeled (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; const char *policy_name; diff --git a/src/ostree/ot-admin-instutil-builtins.h b/src/ostree/ot-admin-instutil-builtins.h new file mode 100644 index 00000000..1fe08ee3 --- /dev/null +++ b/src/ostree/ot-admin-instutil-builtins.h @@ -0,0 +1,30 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * + * Copyright (C) 2014 Colin Walters + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +gboolean ot_admin_instutil_builtin_selinux_ensure_labeled (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error); + +G_END_DECLS + diff --git a/src/ostree/ot-builtin-admin.c b/src/ostree/ot-builtin-admin.c index 7ba4fc5c..9da8f77b 100644 --- a/src/ostree/ot-builtin-admin.c +++ b/src/ostree/ot-builtin-admin.c @@ -38,11 +38,9 @@ typedef struct { } OstreeAdminCommand; static OstreeAdminCommand admin_subcommands[] = { -#ifdef HAVE_SELINUX - { "selinux-ensure-labeled", ot_admin_builtin_selinux_ensure_labeled }, -#endif { "os-init", ot_admin_builtin_os_init }, { "init-fs", ot_admin_builtin_init_fs }, + { "instutil", ot_admin_builtin_instutil }, { "deploy", ot_admin_builtin_deploy }, { "undeploy", ot_admin_builtin_undeploy }, { "upgrade", ot_admin_builtin_upgrade },