![다른 사용자의 파일 접근 권한을 확인하는 명령](https://linux55.com/image/18013/%EB%8B%A4%EB%A5%B8%20%EC%82%AC%EC%9A%A9%EC%9E%90%EC%9D%98%20%ED%8C%8C%EC%9D%BC%20%EC%A0%91%EA%B7%BC%20%EA%B6%8C%ED%95%9C%EC%9D%84%20%ED%99%95%EC%9D%B8%ED%95%98%EB%8A%94%20%EB%AA%85%EB%A0%B9.png)
/
특정 사용자에 대한 유효한 파일 접근 권한을 확인하는 방법을 알아야 하는데 대상 파일이나 디렉터리에서 수동으로 시작하거나 그룹을 확인하는 등의 작업을 수행하는 데 시간이 오래 걸립니다.
답변1
내가 아는 한, 유일한 방법은 설명하는 대로 수행한 다음 유효한 사용자/그룹에 대해 설정된 각 권한을 확인하는 것입니다. 또는 sudo를 실행할 수 있도록 설정해 볼 수도 있습니다 test(1)
.
sudo -u luser test -x ~juser/bin/myprogram
말씀하신 대로 유효한 사용자/그룹 권한을 확인하세요.
:
# called as $0 usertocheck pathname {r|w|x}
# for example, permcheck luser ~juser/bin/myprogrm x
# displays either "root", "user", "groups", "other" or "none"
user=$1
file=$2
smode=$3
# if user has no access from state, an empty string is returned, fuid,
# fgid and fmode would become empty strings as well; the end result is
# always showing 'none' even if $user has access (except $user == 'root')
set -- $(stat -L -c '%u %g %a' $file 2>&-)
awk -f $tmpawk \
-veuid="$(id -u $user)" \
-vgrp="$(id -G $user)" \
-vfuid="$1" \
-vfgid="$2" \
-vfmode="$(echo ibase=8\;$3 | bc)" \
-vsmode="$smode" \
'BEGIN {
if (euid == 0) { print "root"; exit; }
split(grp,Groups);
omode = fmode % 8; gmode = int(fmode / 8 % 8);
umode = int(fmode / 64 % 8);
# set up tests
# these could be function, but not all version of awk has a function
# statement
if (smode == "r") {
utest = int(umode / 4);
gtest = int(gmode / 4);
otest = int(omode / 4);
}
if (smode == "w") {
utest = int(umode / 2 % 2);
gtest = int(gmode / 2 % 2);
otest = int(omode / 2 % 2);
}
if (smode == "x") {
utest = (int(umode >= 4) && umode % 2);
gtest = (int(gmode >= 4) && gmode % 2);
otest = (int(omode >= 4) && omode % 2);
}
if (utest && fuid == euid) { print "user"; exit; }
for (idx in Groups) {
if (gtest && Groups[idx] == fgid) { print "group"; exit; }
}
if (otest) { print "other"; exit; }
print "none";
}
'
내 Ubuntu 11.04 시스템에서 이 스크립트를 실행하는 데 평균 약 16밀리초가 걸립니다. 또한 stat를 읽거나 실행할 필요가 없습니다.
답변2
명령 stat
이 틱됩니까?