1#!/bin/sh 2# Make sure "chown USER:GROUP FILE" works, and similar tests with separators. 3 4# Copyright (C) 2004-2023 Free Software Foundation, Inc. 5 6# This program is free software: you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation, either version 3 of the License, or 9# (at your option) any later version. 10 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15 16# You should have received a copy of the GNU General Public License 17# along with this program. If not, see <https://www.gnu.org/licenses/>. 18 19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src 20print_ver_ chown 21 22id_u=$(id -u) || framework_failure_ 23test -n "$id_u" || framework_failure_ 24 25id_un=$(id -un) || framework_failure_ 26test -n "$id_un" || framework_failure_ 27 28id_g=$(id -g) || framework_failure_ 29test -n "$id_g" || framework_failure_ 30 31id_gn=$(id -gn) || framework_failure_ 32test -n "$id_gn" || framework_failure_ 33 34# Systems with both local and external groups with conflicting IDs, 35# were seen to fail this test erroneously with EPERM errors. 36test $(getent group | grep "^$id_gn:" | wc -l) = 1 || 37 skip_ "group '$id_gn' not unique: " \ 38 "$(getent group | grep "^$id_gn:" | tr '\n' ',')" 39 40# FreeBSD 6.x's getgrnam fails to look up a group name containing 41# a space. On such a system, skip this test if the group name contains 42# a byte not in the portable filename character set. 43case $host_triplet in 44 *-freebsd6.*) 45 case $id_gn in 46 *[^a-zA-Z0-9._-]*) skip_ "invalid group name: $id_gn";; 47 esac;; 48 *) ;; 49esac 50 51 52chown '' . || fail=1 53 54for u in $id_u "$id_un" ''; do 55 for g in $id_g "$id_gn" ''; do 56 case $u$g in 57 *.*) seps=':' ;; 58 *) seps=': .' ;; 59 esac 60 for sep in $seps; do 61 case $u$sep$g in 62 [0-9]*$sep) returns_ 1 chown "$u$sep$g" . 2>/dev/null || fail=1 ;; 63 *) chown "$u$sep$g" . || fail=1 ;; 64 esac 65 done 66 done 67done 68 69Exit $fail 70