Commit Graph

852 Commits

Author SHA1 Message Date
Michael Forney
6164445cce Fix symbolic mode parsing in parsemode
I found quite a lot of bugs, so I ended up pretty much rewriting as I
followed the spec¹.

Now, it works as follows:

- Determine a mask (who) of bits that can be modified for the subsequent
  operations. If none are specified, select all file mode bits.
- In a loop, determine which operation (+, -, =) to apply.
- If the next character is a permcopy (u, g, o), set the new permissions
  (perm) corresponding to the bits set in the user, group or other parts
  of the existing mode.
- Otherwise, set the new permissions by looping through the next r, w,
  x, s, t characters.
- Now, the set of bits we want to add or remove is (who & perm). Set or
  remove these bits according the the operation (first clearing the
  appropriate bits if the operation is =).
- Continue from the top if the next character is a comma, otherwise,
  process the next operation.

I tested this on some made up inputs, and I believe it is working
correctly now:

  parsemode("g+w", 0644, 0),    before: 0606, now: 0664, fixed
  parsemode("u+rx", 0222, 0),   before: 0077, now: 0722, fixed
  parsemode("+x", 0644, 023),   before: 0754, now: 0754, still works
  parsemode("+w", 0444, 022),   before: 0644, now: 0644, still works
  parsemode("+w", 0444, 0),     before: 0666, now: 0666, still works
  parsemode("+s", 0755, 0),     before: 0755, now: 6755, fixed
  parsemode("u+s", 0755, 0),    before: 0055, now: 4755, fixed
  parsemode("g+s", 0755, 0),    before: 0705, now: 2755, fixed
  parsemode("g=u", 0700, 0),    before: 0000, now: 0770, fixed
  parsemode("go=u-w", 0700, 0), before: 0000, now: 0755, fixed
  parsemode("o+u-g", 0641, 0),  before: 0000, now: 0643, fixed
  parsemode("u=rx,o+w,g-r", 0654, 0) before: error, now: 0516, fixed
  parsemode(",", 0654, 0), before: error, now: error, still works

¹ http://pubs.opengroup.org/onlinepubs/9699919799/utilities/chmod.html
2014-11-03 10:15:29 +00:00
Michael Forney
6327290cf2 grep: Fix -c flag 2014-11-02 09:46:52 +00:00
Michael Forney
1ca8a314f8 grep: Remove newlines before matching a line
Otherwise, a pattern with a '$' anchor will never match and POSIX says that

  "By default, an input line shall be selected if any pattern ... matches any
   part of the line excluding the terminating <newline>"
2014-11-02 09:46:46 +00:00
Michael Forney
7ed4866556 tar: Implement -m flag
This changes the default behavior to adjust mtimes to what is present in
the file header.
2014-11-01 22:34:29 +00:00
Michael Forney
e1f87da43e tar: Handle archives with the prefix field
Also, handle names and prefixes that fill the entire field (and have no
NUL byte) by using a precision specifier.
2014-11-01 22:34:19 +00:00
Michael Forney
0e8a8c9426 tar: Support typeflag '\0' when extracting
POSIX recommends that "For backwards-compatibility, a typeflag value of
binary zero ( '\0' ) should be recognized as meaning a regular file when
extracting files from the archive".
2014-11-01 22:34:08 +00:00
Michael Forney
453ce96d44 tar: Don't crash when get{pw,gr}uid fails 2014-11-01 22:33:55 +00:00
sin
73115682ed Mention programs that were imported from OpenBSD
These need replacing or cleaning up at some point.
2014-10-21 17:50:43 +01:00
sin
d364a813be Remove misleading line in README
We try to follow POSIX as much as possible.
2014-10-19 13:20:51 +01:00
Hiltjo Posthuma
4d4e2608c1 ls: add -h flag
for util/human don't show "B" for bytes.
2014-10-19 12:54:19 +01:00
Hiltjo Posthuma
2cf82f4c16 du: add -d flag to specify the max depth to show files or directories
we don't allow to use it with -s (like GNU du). busybox allows it.
2014-10-18 23:57:00 +01:00
Hiltjo Posthuma
b6b8fe9591 separate humansize into a util function
also show 1 decimal of human size string like: 4M -> 4.4M
2014-10-18 23:56:51 +01:00
sin
ff93350289 Fix col(1) -f
patch taken from openbsd.

Ingo Schwarze says:

If you call the col(1) utility with the -f option, permitting forward
half-line feeds in the output stream, and the input stream actually
contains half-line feeds in either direction, you end up with corrupt
output, containing meaningless escape-digitnine sequences instead of
the required escape-tab sequences.

   $ hexdump -C half.txt
  00000000  61 1b 09 62 1b 09 63 0a                    |a..b..c.|
  00000008
   $ col -f < half.txt | hexdump -C
  00000000  61 1b 39 0d 20 62 1b 39  0d 20 20 63 0a    |a.9. b.9.  c.|
  0000000d

Note how the third character changes from 0x09 to 0x39.

OK to commit the following fix?  Don't worry, it isn't dangerous,
it only changes two *bits*, only a quarter of a byte.

The bug was introduced by the original author, Michael Rendell,
and committed by Keith Bostic on May 22, 1990 (SCCS rev. 5.1).

The following operating systems are affected:

 * 4.3BSD Reno, BSD Net/2, 4.4BSD, 4.4BSD Lite1, 4.4BSD Lite2
 * All versions of 386BSD, NetBSD, OpenBSD, FreeBSD and DragonFly
 * All versions of Debian GNU/Linux and probably many other Linuxes
2014-10-17 21:14:00 +01:00
sin
353ac69a93 Fix a completely broken ln(1) 2014-10-17 16:08:16 +01:00
Evan Gates
0cc3beb739 Introduce new test(1) implementation 2014-10-17 15:47:55 +01:00
sin
ebbbc58aad Small style fix 2014-10-17 15:47:50 +01:00
sin
e59cd2e0ce Use puts() instead of printf() for logname(1) 2014-10-17 15:39:46 +01:00
sin
86d12bf0bf Style fix for link(1) 2014-10-17 15:39:41 +01:00
Brandon Mulcahy
7a73da6864 Add logname(1) 2014-10-17 15:36:27 +01:00
Markus Teich
314885836c Add link(1) 2014-10-17 15:36:16 +01:00
sin
1dd2913e33 Update list of tools in README 2014-10-16 12:34:24 +01:00
sin
41d78c398b Staticise symbols 2014-10-16 12:30:52 +01:00
sin
c0b9a8533f Import csplit(1) from OpenBSD
Modified slightly to conform to the sbase style.
2014-10-16 12:22:36 +01:00
sin
d1a1c42eb3 Update only the modified objects in util.a 2014-10-16 11:33:05 +01:00
sin
bae62cda71 Update TODO 2014-10-16 11:20:04 +01:00
sin
4ff6c585f8 Update TODO 2014-10-16 11:01:49 +01:00
sin
8311023781 Fix test(1) semantics
Evan Gates says:

After writing my own test[0] I checked and sbase already has test. I'm
including a patch to remove test from the TODO. I also noticed that
sbase's test handles a few specific cases incorrectly (documentation
at [1]).

test ! = foo
When there are 3 arguments and the second is a valid binary primary
test should perform that binary test. Only if the second argument is
not a valid binary primary and the first is ! should test negate the
two argument test. I've attached a patch that should fix this.

test ! ! !
test ! ! ! !
When there are 3 arguments and the second is not a valid primary and
the first is !, test should return the negation of the remaining two
argument test. In this case sbase's test works correctly for ! and ! !
but fails afterwards as it's not recursive. I don't yet have a patch
for this but I'm working on one.

Then again both of these areas may be places in which worse is better.
[0] 11329f3834/test.c
[1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
2014-10-16 10:13:05 +01:00
sin
4608d91c6d Add human readable output to du(1)
Thanks Jeffrey Picard!
2014-10-16 10:07:17 +01:00
sin
44319a3972 Simplify true(1) and false(1) 2014-10-03 00:03:08 +01:00
sin
a6793ced1b Another EXIT_SUCCESS nuked 2014-10-02 23:49:19 +01:00
sin
0c5b7b9155 Stop using EXIT_{SUCCESS,FAILURE} 2014-10-02 23:46:59 +01:00
sin
7305786244 Add col(1) to README 2014-09-29 19:53:02 +01:00
sin
a48b850d3f Import col(1) from OpenBSD with minor modifications
Remove getopt, use arg.h.
2014-09-29 19:52:31 +01:00
sin
7c6f2f60e6 Add printf.1 2014-09-29 14:35:35 +01:00
sin
d348bb22c9 Add expr.1 2014-09-29 14:22:59 +01:00
sin
a1784b721d Fix build error
Remove __dead.
2014-09-29 14:10:54 +01:00
sin
618aecd2ec Import expr(1) from OpenBSD
Cleanup + manpage to be done.
2014-09-29 13:44:49 +01:00
sin
015cecfd8d Update README for printf(1) and remove from TODO 2014-09-28 15:13:09 +01:00
sin
fe41494ed3 Import printf(1) from OpenBSD 2014-09-28 15:12:15 +01:00
Wolfgang Corcoran-Mathe
7a6af2faba Fix typo breaking functionality in tail 2014-09-17 10:06:12 +01:00
sin
b712ef44ad Fix warning 'array subscript of type char' 2014-09-02 13:32:32 +01:00
Hiltjo Posthuma
0cbafaecb6 cp: print error to stderr and continue 2014-08-02 13:46:00 +01:00
sin
a9c9681f95 Fixup README
This is now consistent with ubase.  The advantage is that it can
be generated very easily with:

for i in $(./sbase-box); do echo $i; done
2014-07-26 15:46:33 +01:00
Hiltjo Posthuma
323c45edb7 cp: improvements
- improve copying block, char devices, fifo and sockets with -a.
- improve exit status code.
2014-07-21 16:44:26 +01:00
Hiltjo Posthuma
35959cd1c4 ls: improve default format
truncate username and group for better alignment for now. in the future
better tabular printing will be implemented.
2014-07-21 16:44:15 +01:00
Hiltjo Posthuma
81bb8422a5 ln: allow with one argument
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-07-21 16:44:06 +01:00
Hiltjo Posthuma
72b909df9c chown: update usage
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-07-21 16:43:54 +01:00
Hiltjo Posthuma
ba8ca986a4 util/enmasse: fix double /
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-07-21 16:43:42 +01:00
Hiltjo Posthuma
f67320ce93 cp: add -v, fix manpage info
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-07-21 16:43:31 +01:00
sin
ac402965d5 Fix comment style and nuke stray whitespace 2014-07-16 20:43:29 +01:00