From 2b02ab9606fc82f8c535e4473c522920196bfc32 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Fri, 11 May 2001 15:55:41 +0000 Subject: [PATCH] This patch from Lars Kellogg-Stedman, fixes the behavior of chown to be consistant with GNU chown, so that it follows symlinks (who cares about the perms on a link anyways?) unless the -h option is supplied. -Erik --- chown.c | 14 +++++++++++--- coreutils/chown.c | 14 +++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/chown.c b/chown.c index 011403378..a65607204 100644 --- a/chown.c +++ b/chown.c @@ -36,9 +36,11 @@ static long uid; static long gid; +static int (*chown_func)() = chown; + static int fileAction(const char *fileName, struct stat *statbuf, void* junk) { - if (lchown(fileName, uid, (gid == -1) ? statbuf->st_gid : gid) == 0) { + if (chown_func(fileName, uid, (gid == -1) ? statbuf->st_gid : gid) == 0) { return (TRUE); } perror(fileName); @@ -48,21 +50,27 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk) int chown_main(int argc, char **argv) { int opt; - int recursiveFlag = FALSE; + int recursiveFlag = FALSE, + noderefFlag = FALSE; char *groupName=NULL; char *p=NULL; /* do normal option parsing */ - while ((opt = getopt(argc, argv, "R")) > 0) { + while ((opt = getopt(argc, argv, "Rh")) > 0) { switch (opt) { case 'R': recursiveFlag = TRUE; break; + case 'h': + noderefFlag = TRUE; + break; default: show_usage(); } } + if (noderefFlag) chown_func = lchown; + if (argc > optind && argc > 2 && argv[optind]) { /* First, check if there is a group name here */ groupName = strchr(argv[optind], '.'); diff --git a/coreutils/chown.c b/coreutils/chown.c index 011403378..a65607204 100644 --- a/coreutils/chown.c +++ b/coreutils/chown.c @@ -36,9 +36,11 @@ static long uid; static long gid; +static int (*chown_func)() = chown; + static int fileAction(const char *fileName, struct stat *statbuf, void* junk) { - if (lchown(fileName, uid, (gid == -1) ? statbuf->st_gid : gid) == 0) { + if (chown_func(fileName, uid, (gid == -1) ? statbuf->st_gid : gid) == 0) { return (TRUE); } perror(fileName); @@ -48,21 +50,27 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk) int chown_main(int argc, char **argv) { int opt; - int recursiveFlag = FALSE; + int recursiveFlag = FALSE, + noderefFlag = FALSE; char *groupName=NULL; char *p=NULL; /* do normal option parsing */ - while ((opt = getopt(argc, argv, "R")) > 0) { + while ((opt = getopt(argc, argv, "Rh")) > 0) { switch (opt) { case 'R': recursiveFlag = TRUE; break; + case 'h': + noderefFlag = TRUE; + break; default: show_usage(); } } + if (noderefFlag) chown_func = lchown; + if (argc > optind && argc > 2 && argv[optind]) { /* First, check if there is a group name here */ groupName = strchr(argv[optind], '.'); -- 2.25.1