2

I'm searching for a command that essentially would do the following: check which rights a user has on a file/dir (including ACL) and return it.

E.g. say you have the following directory:

-rw-r--r-- 1 user1 group1 [snip] file1
-rw-rw-r-- 1 user2 group1 [snip] file2
drwxrwx--- 1 user2 group2 [snip] dir1

Then the commands & output should be (if user1 is a member of only group1):

rights user1 file1 => r-- or 4
rights user1 file2 => rw- or 6
rights user1 dir1 => --- or 0

Is there such a command available or which tools/commands can't be used to construct a script which would do it?

1 Answer 1

1

I elaborate the following bash code

#!/bin/bash
# Use: $0 user files

user="$1"
shift
sudo -u "$user" bash -c 'for f; do
      [[ -r "$f" ]] && printf 'r' || printf '-'
      [[ -w "$f" ]] && printf 'w' || printf '-'
      [[ -x "$f" ]] && printf 'x' || printf '-'
      printf " %s\\n" "$f"
  done' _ "$@"

This should automatically take into account acl, if available, but the drawback is the use of sudo (or alternatively su) to become $user.

5
  • I had thought of this, but doesn't this create an enormous security leak? The executing user would need sudo rights...
    – dtech
    Sep 3, 2011 at 17:21
  • I realised that shortly after commenting, see my edited comment
    – dtech
    Sep 3, 2011 at 17:28
  • What if calling user do not have access to those files parent directories? It cannot in any way determine access rights for another user.
    – enzotib
    Sep 3, 2011 at 17:33
  • If the calling user doesn't have access it should return false or an error (I'd like to use it as an additional layer of access control, the service can't even serve anything it doesn't have access to)
    – dtech
    Sep 3, 2011 at 17:39
  • @dtech: I do not have a clear idea on how to do, so I hope someone else get in with a better answer.
    – enzotib
    Sep 3, 2011 at 17:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .