public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
From: Petr Lautrbach <lautrbach@redhat.com>
To: git-commits@fedoraproject.org
Subject: [tests/selinux] pr775-checkpolicy-revdeps: Update a file context and relabel
Date: Fri, 11 Sep 2026 13:22:18 GMT	[thread overview]
Message-ID: <178913293801.1.16616314105977981102.tests-selinux-c225414cf39d@fedoraproject.org> (raw)

            A new commit has been pushed.

            Repo   : tests/selinux
            Branch : pr775-checkpolicy-revdeps
            Commit : c225414cf39df742f1aa4069c20a69575c48c782
            Author : Petr Lautrbach <lautrbach@redhat.com>
            Date   : 2025-01-27T20:08:29+01:00
            Stats  : +58/-0 in 3 file(s)
            URL    : https://src.fedoraproject.org/tests/selinux/c/c225414cf39df742f1aa4069c20a69575c48c782?branch=pr775-checkpolicy-revdeps

            Log:
            Update a file context and relabel

Verifies: https://issues.redhat.com/browse/RHEL-73348

---
diff --git a/libsemanage/semanage_setfiles-selinux_restorecon/main.fmf b/libsemanage/semanage_setfiles-selinux_restorecon/main.fmf
new file mode 100644
index 0000000..9ed4f56
--- /dev/null
+++ b/libsemanage/semanage_setfiles-selinux_restorecon/main.fmf
@@ -0,0 +1,9 @@
+summary: Update a file context and relabel
+test: ./test.sh
+framework: beakerlib
+require:
+  - python3-policycoreutils
+  - policycoreutils-python-utils
+  - python3-libsemanage
+link:
+  - verifies: https://issues.redhat.com/browse/RHEL-73348

diff --git a/libsemanage/semanage_setfiles-selinux_restorecon/test.sh b/libsemanage/semanage_setfiles-selinux_restorecon/test.sh
new file mode 100755
index 0000000..788c938
--- /dev/null
+++ b/libsemanage/semanage_setfiles-selinux_restorecon/test.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
+. /usr/share/beakerlib/beakerlib.sh || exit 1
+
+rlJournalStart
+    rlPhaseStartSetup
+        rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory"
+        rlRun "set -o pipefail"
+    rlPhaseEnd
+
+    rlPhaseStartTest
+        rlRun "mkdir -p $tmp/test/subtest | cut -d ' ' -f 1"
+        rlRun "ls -Zd $tmp/test $tmp/test/subtest | cut -d ' ' -f 1"
+
+        rlRun "python3 update_context.py $tmp/test pki_tomcat_etc_rw_t"
+        LABEL=system_u:object_r:pki_tomcat_etc_rw_t:s0
+        LABEL_TEST=$(ls -Zd $tmp/test | cut -d ' ' -f 1)
+        LABEL_SUBTEST=$(ls -Zd $tmp/test/subtest | cut -d ' ' -f 1)
+        rlRun "ls -Zd $tmp/test $tmp/test/subtest"
+        rlAssertEquals "Is $tmp/test $LABEL?" "$LABEL_TEST" "$LABEL"
+        rlAssertEquals "Is $tmp/test/subtest $LABEL?" "$LABEL_SUBTEST" "$LABEL"
+    rlPhaseEnd
+
+    rlPhaseStartCleanup
+        rlRun "semanage fcontext -D"
+        rlRun "rm -r $tmp" 0 "Remove tmp directory"
+    rlPhaseEnd
+rlJournalEnd

diff --git a/libsemanage/semanage_setfiles-selinux_restorecon/update_context.py b/libsemanage/semanage_setfiles-selinux_restorecon/update_context.py
new file mode 100755
index 0000000..6d2538a
--- /dev/null
+++ b/libsemanage/semanage_setfiles-selinux_restorecon/update_context.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python3
+
+import sys
+import selinux
+import seobject
+
+def update_context(file_dir, new_context):
+    suffix = '(/.*)?'
+    trans = seobject.semanageRecords('targeted')
+    trans.start()
+
+    fcon = seobject.fcontextRecords(trans)
+    fcon.add(
+            file_dir + suffix,
+            new_context, '', 's0', '')
+    trans.finish()
+    selinux.restorecon(file_dir, True, True, True)
+
+
+if __name__ == "__main__":
+    update_context(sys.argv[1], sys.argv[2])

                 reply	other threads:[~2026-09-11 13:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=178913293801.1.16616314105977981102.tests-selinux-c225414cf39d@fedoraproject.org \
    --to=lautrbach@redhat.com \
    --cc=git-commits@fedoraproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox