aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-03-08 13:37:43 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-03-08 13:37:43 +0000
commitcd27c42552b57a517a7abbe836eea0c52a896630 (patch)
tree6ce3089a3a06284296cf079a6499da9034626539
parent6c939e0cb41a366e901063ede1672434886fc9c5 (diff)
downloadbusybox-w32-cd27c42552b57a517a7abbe836eea0c52a896630.tar.gz
busybox-w32-cd27c42552b57a517a7abbe836eea0c52a896630.tar.bz2
busybox-w32-cd27c42552b57a517a7abbe836eea0c52a896630.zip
chown: support -H -L -P if ENABLE_DESKTOP
chmod: cosmetic fixes expr: smallish help for dumb compilers
-rw-r--r--coreutils/chmod.c13
-rw-r--r--coreutils/chown.c108
-rw-r--r--coreutils/expr.c16
3 files changed, 109 insertions, 28 deletions
diff --git a/coreutils/chmod.c b/coreutils/chmod.c
index 74788bbbe..11c6731a1 100644
--- a/coreutils/chmod.c
+++ b/coreutils/chmod.c
@@ -118,10 +118,12 @@ int chmod_main(int argc, char **argv)
118/* 118/*
119Security: chmod is too important and too subtle. 119Security: chmod is too important and too subtle.
120This is a test script (busybox chmod versus coreutils). 120This is a test script (busybox chmod versus coreutils).
121Run it in empty dir. Probably requires bash. 121Run it in empty directory.
122 122
123#!/bin/sh 123#!/bin/sh
124function create() { 124t1="/tmp/busybox chmod"
125t2="/usr/bin/chmod"
126create() {
125 rm -rf $1; mkdir $1 127 rm -rf $1; mkdir $1
126 ( 128 (
127 cd $1 || exit 1 129 cd $1 || exit 1
@@ -134,17 +136,16 @@ function create() {
134 ln -s ../up dir/up 136 ln -s ../up dir/up
135 ) 137 )
136} 138}
137function tst() { 139tst() {
138 (cd test1; $t1 $1) 140 (cd test1; $t1 $1)
139 (cd test2; $t2 $1) 141 (cd test2; $t2 $1)
140 (cd test1; ls -lR) >out1 142 (cd test1; ls -lR) >out1
141 (cd test2; ls -lR) >out2 143 (cd test2; ls -lR) >out2
142 echo "chmod $1" >out.diff 144 echo "chmod $1" >out.diff
143 if ! diff -u out1 out2 >>out.diff; then exit 1; fi 145 if ! diff -u out1 out2 >>out.diff; then exit 1; fi
144 mv out.diff out1.diff 146 rm out.diff
145} 147}
146t1="/tmp/busybox chmod" 148echo "If script produced 'out.diff' file, then at least one testcase failed"
147t2="/usr/bin/chmod"
148create test1; create test2 149create test1; create test2
149tst "a+w file" 150tst "a+w file"
150tst "a-w dir" 151tst "a-w dir"
diff --git a/coreutils/chown.c b/coreutils/chown.c
index 3380677bc..439b62ac8 100644
--- a/coreutils/chown.c
+++ b/coreutils/chown.c
@@ -17,25 +17,31 @@ static struct bb_uidgid_t ugid = { -1, -1 };
17 17
18static int (*chown_func)(const char *, uid_t, gid_t) = chown; 18static int (*chown_func)(const char *, uid_t, gid_t) = chown;
19 19
20#define OPT_STR ("Rh" USE_DESKTOP("vcfLHP"))
21#define BIT_RECURSE 1
22#define BIT_NODEREF 2
23#define BIT_TRAVERSE 0x20
24#define BIT_TRAVERSETOP (0x20|0x40)
20#define OPT_RECURSE (option_mask32 & 1) 25#define OPT_RECURSE (option_mask32 & 1)
21#define OPT_NODEREF (option_mask32 & 2) 26#define OPT_NODEREF (option_mask32 & 2)
22#define OPT_VERBOSE (USE_DESKTOP(option_mask32 & 4) SKIP_DESKTOP(0)) 27#define OPT_VERBOSE (USE_DESKTOP(option_mask32 & 0x04) SKIP_DESKTOP(0))
23#define OPT_CHANGED (USE_DESKTOP(option_mask32 & 8) SKIP_DESKTOP(0)) 28#define OPT_CHANGED (USE_DESKTOP(option_mask32 & 0x08) SKIP_DESKTOP(0))
24#define OPT_QUIET (USE_DESKTOP(option_mask32 & 0x10) SKIP_DESKTOP(0)) 29#define OPT_QUIET (USE_DESKTOP(option_mask32 & 0x10) SKIP_DESKTOP(0))
25#define OPT_STR ("Rh" USE_DESKTOP("vcf")) 30/* POSIX options
26
27/* TODO:
28 * -H if a command line argument is a symbolic link to a directory, traverse it
29 * -L traverse every symbolic link to a directory encountered 31 * -L traverse every symbolic link to a directory encountered
32 * -H if a command line argument is a symbolic link to a directory, traverse it
30 * -P do not traverse any symbolic links (default) 33 * -P do not traverse any symbolic links (default)
31 */ 34 * We do not conform to the following:
35 * "Specifying more than one of -H, -L, and -P is not an error.
36 * The last option specified shall determine the behavior of the utility." */
37/* -L */
38#define OPT_TRAVERSE (USE_DESKTOP(option_mask32 & BIT_TRAVERSE) SKIP_DESKTOP(0))
39/* -H or -L */
40#define OPT_TRAVERSETOP (USE_DESKTOP(option_mask32 & BIT_TRAVERSETOP) SKIP_DESKTOP(0))
32 41
33static int fileAction(const char *fileName, struct stat *statbuf, 42static int fileAction(const char *fileName, struct stat *statbuf,
34 void ATTRIBUTE_UNUSED *junk, int depth) 43 void ATTRIBUTE_UNUSED *junk, int depth)
35{ 44{
36 // TODO: -H/-L/-P
37 // if (depth ... && S_ISLNK(statbuf->st_mode)) ....
38
39 if (!chown_func(fileName, 45 if (!chown_func(fileName,
40 (ugid.uid == (uid_t)-1) ? statbuf->st_uid : ugid.uid, 46 (ugid.uid == (uid_t)-1) ? statbuf->st_uid : ugid.uid,
41 (ugid.gid == (gid_t)-1) ? statbuf->st_gid : ugid.gid) 47 (ugid.gid == (gid_t)-1) ? statbuf->st_gid : ugid.gid)
@@ -62,16 +68,31 @@ int chown_main(int argc, char **argv)
62 getopt32(argc, argv, OPT_STR); 68 getopt32(argc, argv, OPT_STR);
63 argv += optind; 69 argv += optind;
64 70
65 if (OPT_NODEREF) chown_func = lchown; 71 /* This matches coreutils behavior (almost - see below) */
72 if (OPT_NODEREF
73 /* || (OPT_RECURSE && !OPT_TRAVERSETOP): */
74 USE_DESKTOP( || (option_mask32 & (BIT_RECURSE|BIT_TRAVERSETOP)) == BIT_RECURSE)
75 ) {
76 chown_func = lchown;
77 }
66 78
67 parse_chown_usergroup_or_die(&ugid, argv[0]); 79 parse_chown_usergroup_or_die(&ugid, argv[0]);
68 80
69 /* Ok, ready to do the deed now */ 81 /* Ok, ready to do the deed now */
70 argv++; 82 argv++;
71 do { 83 do {
72 if (!recursive_action(*argv, 84 char *arg = *argv;
73 OPT_RECURSE, // recurse 85
74 FALSE, // follow links: TODO: -H/-L/-P 86 if (OPT_TRAVERSETOP) {
87 /* resolves symlink (even recursive) */
88 arg = xmalloc_realpath(arg);
89 if (!arg)
90 continue;
91 }
92
93 if (!recursive_action(arg,
94 OPT_RECURSE, // recurse
95 OPT_TRAVERSE, // follow links if -L
75 FALSE, // depth first 96 FALSE, // depth first
76 fileAction, // file action 97 fileAction, // file action
77 fileAction, // dir action 98 fileAction, // dir action
@@ -80,7 +101,66 @@ int chown_main(int argc, char **argv)
80 ) { 101 ) {
81 retval = EXIT_FAILURE; 102 retval = EXIT_FAILURE;
82 } 103 }
104
105 if (OPT_TRAVERSETOP)
106 free(arg);
83 } while (*++argv); 107 } while (*++argv);
84 108
85 return retval; 109 return retval;
86} 110}
111
112/*
113Testcase. Run in empty directory.
114
115#!/bin/sh
116t1="/tmp/busybox chown"
117t2="/usr/bin/chown"
118create() {
119 rm -rf $1; mkdir $1
120 (
121 cd $1 || exit 1
122 mkdir dir dir2
123 >up
124 >file
125 >dir/file
126 >dir2/file
127 ln -s dir linkdir
128 ln -s file linkfile
129 ln -s ../up dir/linkup
130 ln -s ../dir2 dir/linkupdir2
131 )
132 chown -R 0:0 $1
133}
134tst() {
135 create test1
136 create test2
137 (cd test1; $t1 $1)
138 (cd test2; $t2 $1)
139 (cd test1; ls -lnR) >out1
140 (cd test2; ls -lnR) >out2
141 echo "chown $1" >out.diff
142 if ! diff -u out1 out2 >>out.diff; then exit 1; fi
143 rm out.diff
144}
145tst_for_each() {
146 tst "$1 1:1 file"
147 tst "$1 1:1 dir"
148 tst "$1 1:1 linkdir"
149 tst "$1 1:1 linkfile"
150}
151echo "If script produced 'out.diff' file, then at least one testcase failed"
152# These match coreutils 6.8:
153tst_for_each ""
154tst_for_each "-R"
155tst_for_each "-RP"
156tst_for_each "-RL"
157tst_for_each "-RH"
158tst_for_each "-h"
159tst_for_each "-hR"
160tst_for_each "-hRP"
161# Below: with "chown linkdir" coreutils 6.8 will chown linkdir _target_,
162# we lchown _the link_. I believe we are "more correct".
163#tst_for_each "-hRL"
164#tst_for_each "-hRH"
165
166*/
diff --git a/coreutils/expr.c b/coreutils/expr.c
index 62d1f3a8f..b7e33de49 100644
--- a/coreutils/expr.c
+++ b/coreutils/expr.c
@@ -136,8 +136,8 @@ static int null(VALUE * v)
136{ 136{
137 if (v->type == integer) 137 if (v->type == integer)
138 return v->u.i == 0; 138 return v->u.i == 0;
139 else /* string: */ 139 /* string: */
140 return v->u.s[0] == '\0' || LONE_CHAR(v->u.s, '0'); 140 return v->u.s[0] == '\0' || LONE_CHAR(v->u.s, '0');
141} 141}
142 142
143/* Coerce V to a string value (can't fail). */ 143/* Coerce V to a string value (can't fail). */
@@ -194,16 +194,16 @@ static int cmp_common(VALUE * l, VALUE * r, int op)
194 cmpval = l->u.i - r->u.i; 194 cmpval = l->u.i - r->u.i;
195 if (op == '<') 195 if (op == '<')
196 return cmpval < 0; 196 return cmpval < 0;
197 else if (op == ('L' + 'E')) 197 if (op == ('L' + 'E'))
198 return cmpval <= 0; 198 return cmpval <= 0;
199 else if (op == '=') 199 if (op == '=')
200 return cmpval == 0; 200 return cmpval == 0;
201 else if (op == '!') 201 if (op == '!')
202 return cmpval != 0; 202 return cmpval != 0;
203 else if (op == '>') 203 if (op == '>')
204 return cmpval > 0; 204 return cmpval > 0;
205 else /* >= */ 205 /* >= */
206 return cmpval >= 0; 206 return cmpval >= 0;
207} 207}
208 208
209/* The arithmetic operator handling functions. */ 209/* The arithmetic operator handling functions. */