diff options
author | Colin Walters <walters@verbum.org> | 2023-05-03 08:24:21 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-03 08:24:21 -0400 |
commit | 8a2993a9d01cc358e4c2d936ca132174aabdc714 (patch) | |
tree | 5402001ab710dadfd51ba3e9071b044016030e3e /src/ostree/ot-admin-instutil-builtin-selinux-ensure-labeled.c | |
parent | dd70c9b78cc34ccc7e638eda4c2df1ddd8ee3add (diff) | |
parent | c1044a02b28982ef6dd58af98b23a40482d26487 (diff) | |
download | ostree-8a2993a9d01cc358e4c2d936ca132174aabdc714.tar.gz |
Merge pull request #2565 from cgwalters/clang-format
Add .clang-format file + tree-wide: Run `clang-format`
Diffstat (limited to 'src/ostree/ot-admin-instutil-builtin-selinux-ensure-labeled.c')
-rw-r--r-- | src/ostree/ot-admin-instutil-builtin-selinux-ensure-labeled.c | 111 |
1 files changed, 44 insertions, 67 deletions
diff --git a/src/ostree/ot-admin-instutil-builtin-selinux-ensure-labeled.c b/src/ostree/ot-admin-instutil-builtin-selinux-ensure-labeled.c index e324da9e..bc226fb7 100644 --- a/src/ostree/ot-admin-instutil-builtin-selinux-ensure-labeled.c +++ b/src/ostree/ot-admin-instutil-builtin-selinux-ensure-labeled.c @@ -17,16 +17,16 @@ #include "config.h" -#include <string.h> #include <glib-unix.h> +#include <string.h> -#include "ot-main.h" #include "ot-admin-instutil-builtins.h" +#include "ot-main.h" #include "otutil.h" static char * -ptrarray_path_join (GPtrArray *path) +ptrarray_path_join (GPtrArray *path) { GString *path_buf; @@ -50,58 +50,44 @@ ptrarray_path_join (GPtrArray *path) } static gboolean -relabel_one_path (OstreeSePolicy *sepolicy, - GFile *path, - GFileInfo *info, - GPtrArray *path_parts, - GCancellable *cancellable, - GError **error) +relabel_one_path (OstreeSePolicy *sepolicy, GFile *path, GFileInfo *info, GPtrArray *path_parts, + GCancellable *cancellable, GError **error) { gboolean ret = FALSE; g_autofree char *relpath = NULL; g_autofree char *new_label = NULL; relpath = ptrarray_path_join (path_parts); - if (!ostree_sepolicy_restorecon (sepolicy, relpath, - info, path, - OSTREE_SEPOLICY_RESTORECON_FLAGS_ALLOW_NOLABEL | - OSTREE_SEPOLICY_RESTORECON_FLAGS_KEEP_EXISTING, - &new_label, - cancellable, error)) + if (!ostree_sepolicy_restorecon (sepolicy, relpath, info, path, + OSTREE_SEPOLICY_RESTORECON_FLAGS_ALLOW_NOLABEL + | OSTREE_SEPOLICY_RESTORECON_FLAGS_KEEP_EXISTING, + &new_label, cancellable, error)) { g_prefix_error (error, "Setting context of %s: ", gs_file_get_path_cached (path)); goto out; } if (new_label) - g_print ("Set label of '%s' (as '%s') to '%s'\n", - gs_file_get_path_cached (path), - relpath, + g_print ("Set label of '%s' (as '%s') to '%s'\n", gs_file_get_path_cached (path), relpath, new_label); ret = TRUE; - out: +out: return ret; } static gboolean -relabel_recursively (OstreeSePolicy *sepolicy, - GFile *dir, - GFileInfo *dir_info, - GPtrArray *path_parts, - GCancellable *cancellable, - GError **error) +relabel_recursively (OstreeSePolicy *sepolicy, GFile *dir, GFileInfo *dir_info, + GPtrArray *path_parts, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; - g_autoptr(GFileEnumerator) direnum = NULL; + g_autoptr (GFileEnumerator) direnum = NULL; - if (!relabel_one_path (sepolicy, dir, dir_info, path_parts, - cancellable, error)) + if (!relabel_one_path (sepolicy, dir, dir_info, path_parts, cancellable, error)) goto out; direnum = g_file_enumerate_children (dir, OSTREE_GIO_FAST_QUERYINFO, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - cancellable, error); + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!direnum) goto out; @@ -111,25 +97,22 @@ relabel_recursively (OstreeSePolicy *sepolicy, GFile *child; GFileType ftype; - if (!g_file_enumerator_iterate (direnum, &file_info, &child, - cancellable, error)) + if (!g_file_enumerator_iterate (direnum, &file_info, &child, cancellable, error)) goto out; if (file_info == NULL) break; - g_ptr_array_add (path_parts, (char*)g_file_info_get_name (file_info)); + g_ptr_array_add (path_parts, (char *)g_file_info_get_name (file_info)); ftype = g_file_info_get_file_type (file_info); if (ftype == G_FILE_TYPE_DIRECTORY) { - if (!relabel_recursively (sepolicy, child, file_info, path_parts, - cancellable, error)) + if (!relabel_recursively (sepolicy, child, file_info, path_parts, cancellable, error)) goto out; } else { - if (!relabel_one_path (sepolicy, child, file_info, path_parts, - cancellable, error)) + if (!relabel_one_path (sepolicy, child, file_info, path_parts, cancellable, error)) goto out; } @@ -137,70 +120,65 @@ relabel_recursively (OstreeSePolicy *sepolicy, } ret = TRUE; - out: +out: return ret; } static gboolean -selinux_relabel_dir (OstreeSePolicy *sepolicy, - GFile *dir, - const char *prefix, - GCancellable *cancellable, - GError **error) +selinux_relabel_dir (OstreeSePolicy *sepolicy, GFile *dir, const char *prefix, + GCancellable *cancellable, GError **error) { gboolean ret = FALSE; - g_autoptr(GPtrArray) path_parts = g_ptr_array_new (); - g_autoptr(GFileInfo) root_info = NULL; + g_autoptr (GPtrArray) path_parts = g_ptr_array_new (); + g_autoptr (GFileInfo) root_info = NULL; root_info = g_file_query_info (dir, OSTREE_GIO_FAST_QUERYINFO, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - cancellable, error); + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!root_info) goto out; - g_ptr_array_add (path_parts, (char*)prefix); - if (!relabel_recursively (sepolicy, dir, root_info, path_parts, - cancellable, error)) + g_ptr_array_add (path_parts, (char *)prefix); + if (!relabel_recursively (sepolicy, dir, root_info, path_parts, cancellable, error)) { g_prefix_error (error, "Relabeling /%s: ", prefix); goto out; } ret = TRUE; - out: +out: return ret; } -static GOptionEntry options[] = { - { NULL } -}; +static GOptionEntry options[] = { { NULL } }; gboolean -ot_admin_instutil_builtin_selinux_ensure_labeled (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_admin_instutil_builtin_selinux_ensure_labeled (int argc, char **argv, + OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { gboolean ret = FALSE; const char *policy_name; - g_autoptr(GFile) subpath = NULL; + g_autoptr (GFile) subpath = NULL; const char *prefix = NULL; - g_autoptr(OstreeSePolicy) sepolicy = NULL; - g_autoptr(GPtrArray) deployments = NULL; + g_autoptr (OstreeSePolicy) sepolicy = NULL; + g_autoptr (GPtrArray) deployments = NULL; OstreeDeployment *first_deployment; - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeSysroot) sysroot = NULL; - g_autoptr(GFile) deployment_path = NULL; + g_autoptr (GOptionContext) context = NULL; + g_autoptr (OstreeSysroot) sysroot = NULL; + g_autoptr (GFile) deployment_path = NULL; context = g_option_context_new ("[SUBPATH PREFIX]"); if (!ostree_admin_option_context_parse (context, options, &argc, &argv, - OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, + OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER + | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, invocation, &sysroot, cancellable, error)) goto out; deployments = ostree_sysroot_get_deployments (sysroot); if (deployments->len == 0) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Unable to find a deployment in sysroot"); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unable to find a deployment in sysroot"); goto out; } first_deployment = deployments->pdata[0]; @@ -225,8 +203,7 @@ ot_admin_instutil_builtin_selinux_ensure_labeled (int argc, char **argv, OstreeC if (policy_name) { g_print ("Relabeling using policy '%s'\n", policy_name); - if (!selinux_relabel_dir (sepolicy, subpath, prefix, - cancellable, error)) + if (!selinux_relabel_dir (sepolicy, subpath, prefix, cancellable, error)) goto out; } else @@ -234,6 +211,6 @@ ot_admin_instutil_builtin_selinux_ensure_labeled (int argc, char **argv, OstreeC gs_file_get_path_cached (deployment_path)); ret = TRUE; - out: +out: return ret; } |