# HG changeset patch # User Elliott Hughes # Date 1421228629 21600 # Node ID 88e6a100490e79ae456a29513aa49cc943c90e25 # Parent 45a612fb0ce6423c75e1e8f521898006f98b7340 i found a few problems while manually smoke testing toybox chown versus toolbox (NetBSD) chown... new test: and here's the patch to fix "owner:" ":group" and the ":" special case: diff -r 45a612fb0ce6 -r 88e6a100490e tests/chown.test --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/chown.test Wed Jan 14 03:43:49 2015 -0600 @@ -0,0 +1,41 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +if [ "$(id -u)" -ne 0 ] +then + echo "SKIPPED: chown (not root)" + continue 2>/dev/null + exit +fi + +# We chown between user "root" and the last user in /etc/passwd, +# and group "root" and the last group in /etc/group. + +USR="$(sed -n '$s/:.*//p' /etc/passwd)" +GRP="$(sed -n '$s/:.*//p' /etc/group)" + +# Set up a little testing hierarchy + +rm -rf testdir && +mkdir testdir && +touch testdir/file +F=testdir/file + +# Wrapper to reset groups and return results + +OUT="&& echo \$(ls -l testdir/file | awk '{print \$3,\$4}')" + +#testing "name" "command" "result" "infile" "stdin" + +# Basic smoketest +testing "chown initial" "chown root:root $F $OUT" "root root\n" "" "" +testing "chown usr:grp" "chown $USR:$GRP $F $OUT" "$USR $GRP\n" "" "" +testing "chown root" "chown root $F $OUT" "root $GRP\n" "" "" +# TODO: can we test "owner:"? +testing "chown :grp" "chown root:root $F && chown :$GRP $F $OUT" \ + "root $GRP\n" "" "" +testing "chown :" "chown $USR:$GRP $F && chown : $F $OUT" \ + "$USR $GRP\n" "" "" + +rm -rf testdir diff -r 45a612fb0ce6 -r 88e6a100490e toys/posix/chgrp.c --- a/toys/posix/chgrp.c Wed Jan 14 00:31:06 2015 -0600 +++ b/toys/posix/chgrp.c Wed Jan 14 03:43:49 2015 -0600 @@ -77,6 +77,8 @@ int ischown = toys.which->name[2] == 'o', hl = toys.optflags&(FLAG_H|FLAG_L); char **s, *own; + TT.owner = TT.group = -1; + // Distinguish chown from chgrp if (ischown) { char *grp; @@ -97,7 +99,7 @@ } } else TT.group_name = *toys.optargs; - if (TT.group_name) { + if (TT.group_name && *TT.group_name) { struct group *g; g = getgrnam(TT.group_name); if (!g) g=getgrgid(atoi(TT.group_name));