[aklug] Re: test effective permissions?

From: Leif Sawyer <lsawyer@gci.com>
Date: Mon Sep 12 2016 - 13:37:05 AKDT

That works fine, and you could build it out thusly, albeit ugly-ly...

cat testme.sh
#!/bin/bash
USERS="joemama"
FILES="/etc/passwd /etc/shadow /tmp/foobargeewiz"

for user in ${USERS}; do
  echo "user: $user"
  for file in ${FILES}; do
    READ=$(sudo -u ${USER} test -r ${file} && echo " ")
    WRITE=$(sudo -u ${USER} test -w ${file} && echo " ")
    EXEC=$(sudo -u ${USER} test -x ${file} && echo " ")

    echo "$file: ${READ:-un}readable ${WRITE:-un}writeable ${EXEC:-un}executable"
  done
done

root~# . testme.sh
user: jomama
/etc/passwd: readable unwriteable unexecutable
/etc/shadow: unreadable unwriteable unexecutable
/tmp/foobargeewiz: unreadable unwriteable unexecutable



-----Original Message-----
From: aklug-bounce@aklug.org [mailto:aklug-bounce@aklug.org] On Behalf Of Christopher Howard
Sent: Sunday, September 11, 2016 7:55 PM
To: AKLUG
Subject: [aklug] test effective permissions?

[External Email]

Hi list. I was trying to find a quick and easy way to test the effective
permissions for any given user on a file. By "effective permissions", I
mean the resulting access after traditional and ACL permissions are
taken into account. Like, I think I could do this:

$ sudo -u someuser test -r somefile; echo $?
0
$ sudo -u someuser test -w somefile; echo $?
1
$ sudo -u someuser test -x somefile; echo $?
0

... provided I reverse the 0 and 1 in my mind. I'm sure I could turn
that into a nice script, but I was curious if there is already a script
or program in the wild designed to do that.

--
https://qlfiles.net
My PGP public key ID is 0x340EA95A (pgp.mit.edu).

---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.

N‹§²æìr¸›zǧu隊[hjIn‚·ª¹ë-jIn‚ŠàÂ+aº{.nÇ+‰·¢žØ^™ë,j›
Received on Mon Sep 12 13:37:56 2016

This archive was generated by hypermail 2.1.8 : Mon Sep 12 2016 - 13:37:56 AKDT