diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2017-02-04 21:03:59 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2017-02-04 21:05:39 -0500 |
commit | 9f1863d45fe596e258596a4b4cc9a4064bcb11d3 (patch) | |
tree | 4a627b699f52f03eabd145852891c2aef7c5cb76 | |
parent | 538e4b2054e9802ebc860943e0a43baf2ee46741 (diff) | |
download | bfs-9f1863d45fe596e258596a4b4cc9a4064bcb11d3.tar.xz |
Implement -nouser and -nogroup
-rw-r--r-- | bfs.h | 2 | ||||
-rw-r--r-- | eval.c | 26 | ||||
-rw-r--r-- | parse.c | 16 | ||||
-rwxr-xr-x | tests.sh | 19 | ||||
-rw-r--r-- | tests/test_0128.out | 0 | ||||
-rw-r--r-- | tests/test_0129.out | 0 |
6 files changed, 62 insertions, 1 deletions
@@ -288,6 +288,8 @@ bool eval_used(const struct expr *expr, struct eval_state *state); bool eval_gid(const struct expr *expr, struct eval_state *state); bool eval_uid(const struct expr *expr, struct eval_state *state); +bool eval_nogroup(const struct expr *expr, struct eval_state *state); +bool eval_nouser(const struct expr *expr, struct eval_state *state); bool eval_depth(const struct expr *expr, struct eval_state *state); bool eval_empty(const struct expr *expr, struct eval_state *state); @@ -18,6 +18,8 @@ #include <errno.h> #include <fcntl.h> #include <fnmatch.h> +#include <grp.h> +#include <pwd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -226,6 +228,30 @@ bool eval_uid(const struct expr *expr, struct eval_state *state) { } /** + * -nogroup test. + */ +bool eval_nogroup(const struct expr *expr, struct eval_state *state) { + const struct stat *statbuf = fill_statbuf(state); + if (!statbuf) { + return false; + } + + return getgrgid(statbuf->st_gid) == NULL; +} + +/** + * -nouser test. + */ +bool eval_nouser(const struct expr *expr, struct eval_state *state) { + const struct stat *statbuf = fill_statbuf(state); + if (!statbuf) { + return false; + } + + return getpwuid(statbuf->st_uid) == NULL; +} + +/** * -delete action. */ bool eval_delete(const struct expr *expr, struct eval_state *state) { @@ -1206,6 +1206,13 @@ static struct expr *parse_newerxy(struct parser_state *state, int arg1, int arg2 } /** + * Parse -nogroup. + */ +static struct expr *parse_nogroup(struct parser_state *state, int arg1, int arg2) { + return parse_nullary_test(state, eval_nogroup); +} + +/** * Parse -nohidden. */ static struct expr *parse_nohidden(struct parser_state *state, int arg1, int arg2) { @@ -1226,6 +1233,13 @@ static struct expr *parse_noleaf(struct parser_state *state, int arg1, int arg2) } /** + * Parse -nouser. + */ +static struct expr *parse_nouser(struct parser_state *state, int arg1, int arg2) { + return parse_nullary_test(state, eval_nouser); +} + +/** * Parse a permission mode like chmod(1). */ static int parse_mode(const struct parser_state *state, const char *mode, struct expr *expr) { @@ -1857,10 +1871,12 @@ static const struct table_entry parse_table[] = { {"newer", false, parse_acnewer, MTIME}, {"newer", true, parse_newerxy}, {"nocolor", false, parse_color, false}, + {"nogroup", false, parse_nogroup}, {"nohidden", false, parse_nohidden}, {"noignore_readdir_race", false, parse_ignore_races, false}, {"noleaf", false, parse_noleaf}, {"not"}, + {"nouser", false, parse_nouser}, {"nowarn", false, parse_warn, false}, {"o"}, {"ok", false, parse_exec, EXEC_CONFIRM}, @@ -787,9 +787,26 @@ function test_0127() { bfs_diff basic -inum "$inode" } +function test_0127() { + [ "$BSD" -o "$GNU" ] || return 0 + + local inode="$(ls -id basic/k/foo/bar | cut -f1 -d' ')" + bfs_diff basic -inum "$inode" +} + +function test_0128() { + [ "$BSD" -o "$GNU" ] || return 0 + bfs_diff basic -nogroup +} + +function test_0129() { + [ "$BSD" -o "$GNU" ] || return 0 + bfs_diff basic -nouser +} + result=0 -for i in {1..127}; do +for i in {1..129}; do test="test_$(printf '%04d' $i)" if [ -t 1 ]; then diff --git a/tests/test_0128.out b/tests/test_0128.out new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/test_0128.out diff --git a/tests/test_0129.out b/tests/test_0129.out new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/test_0129.out |