From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11810 invoked from network); 21 Aug 2007 22:57:13 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.1 (2007-05-02) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.6 required=5.0 tests=AWL,BAYES_00,FAKE_REPLY_C autolearn=no version=3.2.1 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 21 Aug 2007 22:57:13 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 36183 invoked from network); 21 Aug 2007 22:57:07 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 21 Aug 2007 22:57:07 -0000 Received: (qmail 8561 invoked by alias); 21 Aug 2007 22:57:05 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 23788 Received: (qmail 8552 invoked from network); 21 Aug 2007 22:57:04 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 21 Aug 2007 22:57:04 -0000 Received: (qmail 35949 invoked from network); 21 Aug 2007 22:57:04 -0000 Received: from acolyte.scowler.net (216.254.112.45) by a.mx.sunsite.dk with SMTP; 21 Aug 2007 22:57:01 -0000 Received: by acolyte.scowler.net (Postfix, from userid 1000) id E477C5CEDC; Tue, 21 Aug 2007 18:57:00 -0400 (EDT) Date: Tue, 21 Aug 2007 18:57:00 -0400 From: Clint Adams To: zsh-workers@sunsite.dk Cc: vincent@vinc17.org, 439036-forwarded@bugs.debian.org Subject: Re: Bug#439036: chgrp builtin from zsh/files does not dereference symlinks (non-POSIX) Message-ID: <20070821225700.GA32489@scowler.net> Mail-Followup-To: zsh-workers@sunsite.dk, vincent@vinc17.org, 439036-forwarded@bugs.debian.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.16 (2007-06-11) On Tue, Aug 21, 2007 at 09:31:11PM +0200, Vincent Lefevre wrote: > The chgrp builtin (and chown?) does not dereference symlinks, though > POSIX requires symlinks to be dereferenced by default. Moreover, the > behavior on symlinks is not documented in the zshmodules(1) man page. > > There are still missing features (options) compared to POSIX chgrp, > but I think that at least the default behavior and supported options > should be the same as in POSIX. I think this sabotages -s . POSIX's -H, -L, -P options are still missing. Index: Doc/Zsh/mod_files.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/mod_files.yo,v retrieving revision 1.2 diff -u -r1.2 mod_files.yo --- Doc/Zsh/mod_files.yo 3 Jul 2007 17:06:04 -0000 1.2 +++ Doc/Zsh/mod_files.yo 21 Aug 2007 22:47:47 -0000 @@ -6,12 +6,12 @@ startitem() findex(chgrp) -item(tt(chgrp) [ tt(-Rs) ] var(group) var(filename) ...)( +item(tt(chgrp) [ tt(-hRs) ] var(group) var(filename) ...)( Changes group of files specified. This is equivalent to tt(chown) with a var(user-spec) argument of `tt(:)var(group)'. ) findex(chown) -item(tt(chown) [ tt(-Rs) ] var(user-spec) var(filename) ...)( +item(tt(chown) [ tt(-hRs) ] var(user-spec) var(filename) ...)( Changes ownership and group of files specified. The var(user-spec) can be in four forms: @@ -33,6 +33,9 @@ appropriate) or a decimal user ID (group ID). Interpretation as a name takes precedence, if there is an all-numeric username (or group name). +If the target is a symbolic link, the tt(-h) option causes tt(chown) to set +the ownership of the link instead of its target. + The tt(-R) option causes tt(chown) to recursively descend into directories, changing the ownership of all files in the directory after changing the ownership of the directory itself. Index: Src/Modules/files.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Modules/files.c,v retrieving revision 1.17 diff -u -r1.17 files.c --- Src/Modules/files.c 6 Jul 2007 21:52:40 -0000 1.17 +++ Src/Modules/files.c 21 Aug 2007 22:47:48 -0000 @@ -593,6 +593,19 @@ { struct chownmagic *chm = magic; + if(chown(rp, chm->uid, chm->gid)) { + zwarnnam(chm->nam, "%s: %e", arg, errno); + return 1; + } + return 0; +} + +/**/ +static int +chown_dolchown(char *arg, char *rp, UNUSED(struct stat const *sp), void *magic) +{ + struct chownmagic *chm = magic; + if(lchown(rp, chm->uid, chm->gid)) { zwarnnam(chm->nam, "%s: %e", arg, errno); return 1; @@ -600,6 +613,7 @@ return 0; } + /**/ static unsigned long getnumeric(char *p, int *errp) { @@ -684,7 +698,8 @@ } free(uspec); return recursivecmd(nam, 0, OPT_ISSET(ops,'R'), OPT_ISSET(ops,'s'), - args + 1, chown_dochown, recurse_donothing, chown_dochown, &chm); + args + 1, OPT_ISSET(ops, 'h') ? chown_dolchown : chown_dochown, recurse_donothing, + OPT_ISSET(ops, 'h') ? chown_dolchown : chown_dochown, &chm); } /* module paraphernalia */ @@ -696,8 +711,8 @@ #endif static struct builtin bintab[] = { - BUILTIN("chgrp", 0, bin_chown, 2, -1, BIN_CHGRP, "Rs", NULL), - BUILTIN("chown", 0, bin_chown, 2, -1, BIN_CHOWN, "Rs", NULL), + BUILTIN("chgrp", 0, bin_chown, 2, -1, BIN_CHGRP, "hRs", NULL), + BUILTIN("chown", 0, bin_chown, 2, -1, BIN_CHOWN, "hRs", NULL), BUILTIN("ln", 0, bin_ln, 1, -1, BIN_LN, LN_OPTS, NULL), BUILTIN("mkdir", 0, bin_mkdir, 1, -1, 0, "pm:", NULL), BUILTIN("mv", 0, bin_ln, 2, -1, BIN_MV, "fi", NULL),