Commit Graph

87 Commits

Author SHA1 Message Date
FRIGN
7d2683ddf2 Sort includes and more cleanup and fixes in util/ 2014-11-14 10:54:10 +00:00
sin
5773a8f22b Implement concat() using read(2) and write(2)
This forces the data to be read as soon as they are available
and a simple cat(1) when stdin is referring to a tty works as
expected.
2014-11-13 14:56:06 +00:00
Hiltjo Posthuma
6d410168b8 style fix: fix indentation (double) 2014-11-10 23:56:10 +00:00
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
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
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
0c5b7b9155 Stop using EXIT_{SUCCESS,FAILURE} 2014-10-02 23:46:59 +01:00
Hiltjo Posthuma
0cbafaecb6 cp: print error to stderr and continue 2014-08-02 13:46:00 +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
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
Hiltjo Posthuma
8b3a9c1971 cp: add -a, -d, -p 2014-07-10 11:23:21 +01:00
sin
a62eda512c Don't require two C-d to exit the loop 2014-07-04 16:52:17 +01:00
sin
75382abbf3 Add some error checking to util/recurse.c
Some more stylistic changes and simplification.
2014-06-30 16:05:51 +01:00
Hiltjo Posthuma
2ab2d2ee3b remove afgets
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-06-01 18:03:20 +01:00
Hiltjo Posthuma
fab4b384e7 use agetline instead of agets
also use agetline where fgets with a static buffer was used previously.

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-06-01 18:03:10 +01:00
Hiltjo Posthuma
eac0f658cf check snprintf error aswell, handle as truncation error
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-06-01 18:02:55 +01:00
Hiltjo Posthuma
953ebf3573 code style
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-06-01 18:02:30 +01:00
Hiltjo Posthuma
d12e953f18 add agetline, separate estrtod to util
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-06-01 18:01:45 +01:00
Hiltjo Posthuma
2dbb694932 strlcat, strlcpy style
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-06-01 18:01:19 +01:00
sin
69cde23703 Proper copyright header for strlcpy and strlcat 2014-05-28 11:15:59 +01:00
sin
9694305e05 Chop one level of indentation
eprintf() will exit the program, no need to use the else construct.
2014-05-05 15:12:20 +01:00
sin
b257f7a05f cp: Don't try to open the file twice in case we did not provide -f 2014-05-05 15:06:23 +01:00
sin
02918a46e8 Implement cp -f 2014-05-05 15:02:03 +01:00
Daniel Bainton
c323f6f233 Support reading checksums from stdin 2014-05-05 10:05:48 +01:00
Hiltjo Posthuma
bd99b92e91 parsemode: rework
- for octal input: reset mode to 0.
- take umask into account.
- make '=rwx' etc work.
- we wont support crazy but valid modes like "a+rw,g=x,o=g"
- uudecode: use parsemode, mask is 0.

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-04-24 11:51:33 +01:00
sin
02d91696b4 Fix char **argv to char *argv[] 2014-04-18 11:54:44 +01:00
Hiltjo Posthuma
560340341f make parsemode() generic
use for uudecode and chmod

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-04-09 15:40:32 +01:00
sin
81f9cf2a33 Fix style issue in crypt.c 2014-04-04 11:10:18 +01:00
sin
24a5006f57 Prefix error/warning messages with program name if DEBUG is defined 2014-03-28 16:00:01 +00:00
sin
897efd5f13 Remove "WARNING: " prefix from messages 2014-03-23 18:59:14 +00:00
Hiltjo Posthuma
dd7eb63869 crypt: free line and tiny cleanup
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-03-23 18:02:46 +00:00
Hiltjo Posthuma
04f32f4d9a checksum tools: implement -c
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-03-23 18:02:39 +00:00
Hiltjo Posthuma
18b6e40161 crypt: error status code if an error occured in a file series
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-03-23 12:27:24 +00:00
Hiltjo Posthuma
7727530b53 crypt: dont error out if a file in a series fails
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-03-23 12:27:17 +00:00
sin
fe62ed0d48 Preserve permissions when copying files 2014-02-18 16:51:54 +00:00
sin
c96fc3a382 Forgot to include these before 2014-01-30 21:51:01 +00:00
sin
94e97f19cd No need to use enprintf() with EXIT_FAILURE
eprintf() does just that.
2014-01-30 14:55:26 +00:00
sin
fb12183c52 Add strlcpy()/strlcat()
Refactor recurse() routine in preparation to moving tar(1) over
to use it instead of the ftw() interface.
2014-01-30 14:55:05 +00:00
sin
b58951b4f0 snprintf() returns the # of chars printed *excluding* '\0' 2014-01-24 16:23:13 +00:00
sin
0b6b84886c Add newline at end of file 2013-12-04 17:42:33 +00:00
sin
38ca9a24c2 Be a bit more consistent and use uint8_t instead of unsigned char 2013-11-30 20:59:09 +00:00
sin
078fce3f77 Always print the program name
This is generally very useful for sbase, especially when we
hit some case that is not implemented and we want to know which
program failed.
2013-11-14 19:00:28 +00:00
sin
b8edf3b4ee Add weprintf() and replace fprintf(stderr, ...) calls
There is still some programs left to be updated for this.

Many of these programs would stop on the first file that they
could not open.
2013-11-13 11:41:43 +00:00
sin
80c5ab46ba Fix style for function definitions 2013-11-12 13:37:38 +00:00
sin
5b5f062184 Add license file details at top of files 2013-10-07 17:03:34 +01:00
sin
b5a511dacf Exit with EXIT_SUCCESS/EXIT_FAILURE instead of 0 and 1
Fixed for consistency purposes.
2013-10-07 16:44:22 +01:00
sin
573d1954b2 Add cryptmain() and factor out the code from the crypt tools 2013-10-05 13:51:45 +01:00
sin
582511d57b Fix some warnings about strcpy() etc. on OpenBSD 2013-10-05 13:50:57 +01:00
sin
9e5718282a Add sha512sum(1) 2013-08-04 11:00:34 -04:00