summaryrefslogtreecommitdiff
path: root/command/ls.c
diff options
context:
space:
mode:
authorTyler Murphy <tylerm@tylerm.dev>2023-05-12 17:38:41 -0400
committerTyler Murphy <tylerm@tylerm.dev>2023-05-12 17:38:41 -0400
commitc6446e178bf8f4a53511e5ae1e0f3feeb921197c (patch)
treef13384c1d4f6f085d0856c253996c7b9000bcb7b /command/ls.c
parentrefactor (diff)
downloadlazysphere-c6446e178bf8f4a53511e5ae1e0f3feeb921197c.tar.gz
lazysphere-c6446e178bf8f4a53511e5ae1e0f3feeb921197c.tar.bz2
lazysphere-c6446e178bf8f4a53511e5ae1e0f3feeb921197c.zip
chown, chmod
Diffstat (limited to 'command/ls.c')
-rw-r--r--command/ls.c45
1 files changed, 28 insertions, 17 deletions
diff --git a/command/ls.c b/command/ls.c
index 8ed796f..bbfedfb 100644
--- a/command/ls.c
+++ b/command/ls.c
@@ -133,35 +133,46 @@ static bool get_file_info(const char* file_name, struct FileInfo* info) {
info->mode[1] = (s.st_mode & S_IRUSR) ? 'r' : '-';
info->mode[2] = (s.st_mode & S_IWUSR) ? 'w' : '-';
- if (s.st_mode & S_IXUSR) {
- if (s.st_mode & S_ISUID) {
- info->mode[3] = 's';
- info->set_uid = true;
- } else {
- info->mode[3] = 'x';
- }
- if (!info->exec) info->exec = s.st_uid == uid;
+ if (s.st_mode & S_IXUSR && s.st_mode & S_ISUID) {
+ info->mode[3] = 's';
+ info->set_uid = true;
+ if (!info->exec) info->exec = info->usr->pw_uid == uid;
+ } else if (s.st_mode & S_ISUID) {
+ info->mode[3] = 'S';
+ info->set_uid = true;
+ } else if (s.st_mode & S_IXUSR) {
+ info->mode[3] = 'x';
+ if (!info->exec) info->exec = info->usr->pw_uid == uid;
} else {
info->mode[3] = '-';
}
info->mode[4] = (s.st_mode & S_IRGRP) ? 'r' : '-';
info->mode[5] = (s.st_mode & S_IWGRP) ? 'w' : '-';
- if (s.st_mode & S_IXGRP) {
- if (s.st_mode & S_ISGID) {
- info->mode[6] = 's';
- info->set_gid = true;
- } else {
- info->mode[6] = 'x';
- }
- if (!info->exec) info->exec = s.st_gid == gid;
+ if (s.st_mode & S_IXGRP && s.st_mode & S_ISGID) {
+ info->mode[6] = 's';
+ info->set_gid = true;
+ if (!info->exec) info->exec = info->grp->gr_gid == gid;
+ } else if (s.st_mode & S_ISGID) {
+ info->mode[6] = 'S';
+ info->set_gid = true;
+ } else if (s.st_mode & S_IXGRP) {
+ info->mode[6] = 'x';
+ if (!info->exec) info->exec = info->grp->gr_gid == gid;
} else {
info->mode[6] = '-';
}
info->mode[7] = (s.st_mode & S_IROTH) ? 'r' : '-';
info->mode[8] = (s.st_mode & S_IWOTH) ? 'w' : '-';
- if (s.st_mode & S_IXOTH) {
+ if (s.st_mode & S_IXOTH && s.st_mode & S_ISVTX) {
+ info->mode[9] = 't';
+ info->set_gid = true;
+ info->exec = true;
+ } else if (s.st_mode & S_ISVTX) {
+ info->mode[9] = 'T';
+ info->set_gid = true;
+ } else if (s.st_mode & S_IXOTH) {
info->mode[9] = 'x';
info->exec = true;
} else {