aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-05-11 15:55:41 +0000
committerEric Andersen <andersen@codepoet.org>2001-05-11 15:55:41 +0000
commit2b02ab9606fc82f8c535e4473c522920196bfc32 (patch)
tree380b502b99eb028b2027c96f60f27f3eb862468c
parenteb5f433736c80ee6d3909b2803827b5d7af58bcf (diff)
downloadbusybox-w32-2b02ab9606fc82f8c535e4473c522920196bfc32.tar.gz
busybox-w32-2b02ab9606fc82f8c535e4473c522920196bfc32.tar.bz2
busybox-w32-2b02ab9606fc82f8c535e4473c522920196bfc32.zip
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
-rw-r--r--chown.c14
-rw-r--r--coreutils/chown.c14
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 @@
36static long uid; 36static long uid;
37static long gid; 37static long gid;
38 38
39static int (*chown_func)() = chown;
40
39static int fileAction(const char *fileName, struct stat *statbuf, void* junk) 41static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
40{ 42{
41 if (lchown(fileName, uid, (gid == -1) ? statbuf->st_gid : gid) == 0) { 43 if (chown_func(fileName, uid, (gid == -1) ? statbuf->st_gid : gid) == 0) {
42 return (TRUE); 44 return (TRUE);
43 } 45 }
44 perror(fileName); 46 perror(fileName);
@@ -48,21 +50,27 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
48int chown_main(int argc, char **argv) 50int chown_main(int argc, char **argv)
49{ 51{
50 int opt; 52 int opt;
51 int recursiveFlag = FALSE; 53 int recursiveFlag = FALSE,
54 noderefFlag = FALSE;
52 char *groupName=NULL; 55 char *groupName=NULL;
53 char *p=NULL; 56 char *p=NULL;
54 57
55 /* do normal option parsing */ 58 /* do normal option parsing */
56 while ((opt = getopt(argc, argv, "R")) > 0) { 59 while ((opt = getopt(argc, argv, "Rh")) > 0) {
57 switch (opt) { 60 switch (opt) {
58 case 'R': 61 case 'R':
59 recursiveFlag = TRUE; 62 recursiveFlag = TRUE;
60 break; 63 break;
64 case 'h':
65 noderefFlag = TRUE;
66 break;
61 default: 67 default:
62 show_usage(); 68 show_usage();
63 } 69 }
64 } 70 }
65 71
72 if (noderefFlag) chown_func = lchown;
73
66 if (argc > optind && argc > 2 && argv[optind]) { 74 if (argc > optind && argc > 2 && argv[optind]) {
67 /* First, check if there is a group name here */ 75 /* First, check if there is a group name here */
68 groupName = strchr(argv[optind], '.'); 76 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 @@
36static long uid; 36static long uid;
37static long gid; 37static long gid;
38 38
39static int (*chown_func)() = chown;
40
39static int fileAction(const char *fileName, struct stat *statbuf, void* junk) 41static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
40{ 42{
41 if (lchown(fileName, uid, (gid == -1) ? statbuf->st_gid : gid) == 0) { 43 if (chown_func(fileName, uid, (gid == -1) ? statbuf->st_gid : gid) == 0) {
42 return (TRUE); 44 return (TRUE);
43 } 45 }
44 perror(fileName); 46 perror(fileName);
@@ -48,21 +50,27 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
48int chown_main(int argc, char **argv) 50int chown_main(int argc, char **argv)
49{ 51{
50 int opt; 52 int opt;
51 int recursiveFlag = FALSE; 53 int recursiveFlag = FALSE,
54 noderefFlag = FALSE;
52 char *groupName=NULL; 55 char *groupName=NULL;
53 char *p=NULL; 56 char *p=NULL;
54 57
55 /* do normal option parsing */ 58 /* do normal option parsing */
56 while ((opt = getopt(argc, argv, "R")) > 0) { 59 while ((opt = getopt(argc, argv, "Rh")) > 0) {
57 switch (opt) { 60 switch (opt) {
58 case 'R': 61 case 'R':
59 recursiveFlag = TRUE; 62 recursiveFlag = TRUE;
60 break; 63 break;
64 case 'h':
65 noderefFlag = TRUE;
66 break;
61 default: 67 default:
62 show_usage(); 68 show_usage();
63 } 69 }
64 } 70 }
65 71
72 if (noderefFlag) chown_func = lchown;
73
66 if (argc > optind && argc > 2 && argv[optind]) { 74 if (argc > optind && argc > 2 && argv[optind]) {
67 /* First, check if there is a group name here */ 75 /* First, check if there is a group name here */
68 groupName = strchr(argv[optind], '.'); 76 groupName = strchr(argv[optind], '.');