| 1 |
#! /bin/sh |
| 2 |
|
| 3 |
# Copyright (C) 2010 Colin Watson. |
| 4 |
# |
| 5 |
# This file is part of binfmt-support. |
| 6 |
# |
| 7 |
# binfmt-support is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by the |
| 9 |
# Free Software Foundation; either version 3 of the License, or (at your |
| 10 |
# option) any later version. |
| 11 |
# |
| 12 |
# binfmt-support is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
| 15 |
# Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License along |
| 18 |
# with binfmt-support; if not, write to the Free Software Foundation, Inc., |
| 19 |
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 |
|
| 21 |
# Test update-binfmts --import and --unimport. |
| 22 |
|
| 23 |
: "${srcdir=.}" |
| 24 |
# shellcheck source-path=SCRIPTDIR |
| 25 |
. "$srcdir/testlib.sh" |
| 26 |
|
| 27 |
init |
| 28 |
fake_proc |
| 29 |
|
| 30 |
cat >"$tmpdir/usr/share/binfmts/test-magic" <<'EOF' |
| 31 |
package testpkg |
| 32 |
interpreter /bin/sh |
| 33 |
magic ABCD |
| 34 |
EOF |
| 35 |
update_binfmts_proc --import test-magic |
| 36 |
report 'magic: import' "$?" |
| 37 |
cat >"$tmpdir/1-admin.exp" <<'EOF' |
| 38 |
testpkg |
| 39 |
magic |
| 40 |
0 |
| 41 |
ABCD |
| 42 |
|
| 43 |
/bin/sh |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
EOF |
| 49 |
expect_files_equal 'magic: admindir entry OK' \ |
| 50 |
"$tmpdir/var/lib/binfmts/test-magic" "$tmpdir/1-admin.exp" |
| 51 |
cat >"$tmpdir/1-proc.exp" <<'EOF' |
| 52 |
enabled |
| 53 |
interpreter /bin/sh |
| 54 |
flags: |
| 55 |
offset 0 |
| 56 |
magic 41424344 |
| 57 |
EOF |
| 58 |
expect_files_equal 'magic: procdir entry OK' \ |
| 59 |
"$tmpdir/proc/test-magic" "$tmpdir/1-proc.exp" |
| 60 |
|
| 61 |
cat >"$tmpdir/usr/share/binfmts/test-magic-mask" <<'EOF' |
| 62 |
package testpkg |
| 63 |
interpreter /bin/sh |
| 64 |
magic ABCD |
| 65 |
mask \x7f\x7f\x7f\x7f |
| 66 |
EOF |
| 67 |
update_binfmts_proc --import |
| 68 |
report 'import all' "$?" |
| 69 |
cat >"$tmpdir/2-admin.exp" <<'EOF' |
| 70 |
testpkg |
| 71 |
magic |
| 72 |
0 |
| 73 |
ABCD |
| 74 |
\x7f\x7f\x7f\x7f |
| 75 |
/bin/sh |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
EOF |
| 81 |
expect_files_equal 'magic with mask: admindir entry OK' \ |
| 82 |
"$tmpdir/var/lib/binfmts/test-magic-mask" "$tmpdir/2-admin.exp" |
| 83 |
cat >"$tmpdir/2-proc.exp" <<'EOF' |
| 84 |
enabled |
| 85 |
interpreter /bin/sh |
| 86 |
flags: |
| 87 |
offset 0 |
| 88 |
magic 41424344 |
| 89 |
mask 7f7f7f7f |
| 90 |
EOF |
| 91 |
expect_files_equal 'magic with mask: procdir entry OK' \ |
| 92 |
"$tmpdir/proc/test-magic-mask" "$tmpdir/2-proc.exp" |
| 93 |
|
| 94 |
update_binfmts_proc --unimport test-magic |
| 95 |
report 'magic: unimport' "$?" |
| 96 |
! test -e "$tmpdir/var/lib/binfmts/test-magic" |
| 97 |
report 'magic: admindir entry gone' "$?" |
| 98 |
! test -e "$tmpdir/proc/test-magic" |
| 99 |
report 'magic: procdir entry gone' "$?" |
| 100 |
expect_files_equal 'magic with mask: admindir entry still OK' \ |
| 101 |
"$tmpdir/var/lib/binfmts/test-magic-mask" "$tmpdir/2-admin.exp" |
| 102 |
expect_files_equal 'magic with mask: procdir entry still OK' \ |
| 103 |
"$tmpdir/proc/test-magic-mask" "$tmpdir/2-proc.exp" |
| 104 |
|
| 105 |
update_binfmts_proc --unimport |
| 106 |
report 'unimport all' "$?" |
| 107 |
! test -e "$tmpdir/var/lib/binfmts/test-magic-mask" |
| 108 |
report 'magic with mask: admindir entry gone' "$?" |
| 109 |
! test -e "$tmpdir/proc/test-magic-mask" |
| 110 |
report 'magic with mask: procdir entry gone' "$?" |
| 111 |
|
| 112 |
finish |