| 1 | #!/bin/bash |
| 2 | |
| 3 | # This file is part of util-linux. |
| 4 | # |
| 5 | # This file is free software; you can redistribute it and/or modify |
| 6 | # it under the terms of the GNU General Public License as published by |
| 7 | # the Free Software Foundation; either version 2 of the License, or |
| 8 | # (at your option) any later version. |
| 9 | # |
| 10 | # This file is distributed in the hope that it will be useful, |
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | # GNU General Public License for more details. |
| 14 | # |
| 15 | # Copyright (C) 2025 Christian Goeschel Ndjomouo <[email protected]> |
| 16 | |
| 17 | TS_TOPDIR="${0%/*}/../.." |
| 18 | TS_DESC="group" |
| 19 | |
| 20 | . "$TS_TOPDIR/functions.sh" |
| 21 | ts_init "$*" |
| 22 | |
| 23 | ts_skip_nonroot |
| 24 | ts_check_test_command "$TS_CMD_SU" |
| 25 | ts_check_prog "groupadd" |
| 26 | ts_check_prog "groupdel" |
| 27 | ts_check_prog "getent" |
| 28 | |
| 29 | TS_CMD_ID="id" |
| 30 | |
| 31 | username="$(whoami)" |
| 32 | grp_name="ts_grp" |
| 33 | |
| 34 | if ! groupadd --force "$grp_name"; then |
| 35 | ts_skip "could not create group '$grp_name'" |
| 36 | fi |
| 37 | |
| 38 | # Since here '-c' comes after <user> it'll be passed to the actual shell |
| 39 | # instead of being interpreted by su(1). |
| 40 | ts_init_subtest "primary-no-login" |
| 41 | |
| 42 | "$TS_CMD_SU" --group "$grp_name" "$username" \ |
| 43 | -c "$TS_CMD_ID --groups --name" 2>> "$TS_ERRLOG" \ |
| 44 | | grep -o "$grp_name" \ |
| 45 | | uniq >> "$TS_OUTPUT" |
| 46 | |
| 47 | ts_finalize_subtest |
| 48 | |
| 49 | ts_init_subtest "primary-login" |
| 50 | "$TS_CMD_SU" --group "$grp_name" - "$username" \ |
| 51 | -c "$TS_CMD_ID --groups --name" 2>> "$TS_ERRLOG" \ |
| 52 | | grep -o "$grp_name" \ |
| 53 | | uniq >> "$TS_OUTPUT" |
| 54 | |
| 55 | grep -q 'Authentication failure' "$TS_ERRLOG" |
| 56 | [ "$?" -eq 0 ] && ts_skip_subtest "authentication failure" |
| 57 | ts_finalize_subtest |
| 58 | |
| 59 | ts_init_subtest "supplemental-no-login" |
| 60 | "$TS_CMD_SU" --supp-group "$grp_name" "$username" \ |
| 61 | -c "$TS_CMD_ID --groups --name" 2>> "$TS_ERRLOG" \ |
| 62 | | grep -o "$grp_name" \ |
| 63 | | uniq >> "$TS_OUTPUT" |
| 64 | ts_finalize_subtest |
| 65 | |
| 66 | ts_init_subtest "supplemental-login" |
| 67 | "$TS_CMD_SU" --supp-group "$grp_name" - "$username" \ |
| 68 | -c "$TS_CMD_ID --groups --name" 2>> "$TS_ERRLOG" \ |
| 69 | | grep -o "$grp_name" \ |
| 70 | | uniq >> "$TS_OUTPUT" |
| 71 | |
| 72 | grep -q 'Authentication failure' "$TS_ERRLOG" |
| 73 | [ "$?" -eq 0 ] && ts_skip_subtest "authentication failure" |
| 74 | ts_finalize_subtest |
| 75 | |
| 76 | ts_init_subtest "group-id" |
| 77 | |
| 78 | grp_id="$(cat /etc/group | grep -E "^$grp_name" | cut -d: -f 3)" |
| 79 | "$TS_CMD_SU" --group "$grp_id" "$username" \ |
| 80 | -c "$TS_CMD_ID --groups --name" 2>> "$TS_ERRLOG" \ |
| 81 | | grep -o "$grp_name" \ |
| 82 | | uniq >> "$TS_OUTPUT" |
| 83 | |
| 84 | ts_finalize_subtest |
| 85 | |
| 86 | groupdel "$grp_name" |
| 87 | |
| 88 | ts_finalize |