When producing a ls-style permissions string, also handle
authorMartin Pool <mbp@samba.org>
Tue, 27 Nov 2001 07:05:33 +0000 (07:05 +0000)
committerMartin Pool <mbp@samba.org>
Tue, 27 Nov 2001 07:05:33 +0000 (07:05 +0000)
sticky/setuid/setgid bits the same way as GNU ls.

lib/permstring.c

index 4275dfe..525a9ac 100644 (file)
@@ -37,6 +37,19 @@ void permstring(char *perms,
        for (i=0;i<9;i++) {
                if (mode & (1<<i)) perms[9-i] = perm_map[8-i];
        }
+
+       /* Handle setuid/sticky bits.  You might think the indices are
+        * off by one, but remember there's a type char at the
+        * start.  */
+       if (mode & S_ISUID)
+               perms[3] = (mode & S_IXUSR) ? 's' : 'S';
+
+       if (mode & S_ISGID)
+               perms[6] = (mode & S_IXGRP) ? 's' : 'S';
+       
+       if (mode & S_ISVTX)
+               perms[9] = (mode & S_IXOTH) ? 't' : 'T';
+               
        if (S_ISLNK(mode)) perms[0] = 'l';
        if (S_ISDIR(mode)) perms[0] = 'd';
        if (S_ISBLK(mode)) perms[0] = 'b';