On Sat, 2 Oct 2010, LEVAI Daniel wrote:
> I noticed that executin stat -x on a setuid or setgid file don't display
> the setuid/setgid mode in the numeric Mode: field:
>
> $ /usr/bin/stat -x /usr/bin/passwd
>
> File: "/usr/bin/passwd"
> Size: 22484 FileType: Regular File
> Mode: (0555/-r-sr-xr-x) [...]
> ^
> This patch solves it by removing some format characters:
...
> After this:
> $ /usr/bin/stat -x /usr/bin/passwd
> File: "/usr/bin/passwd"
> Size: 22484 FileType: Regular File
> Mode: (104555/-r-sr-xr-x)
> ^^^
Hmm, that doesn't match the Linux/GNU stat behavior, which doesn't show
the file-type bits, bits which no sane program looks at except via the
macros in <sys/stat.h>. Might I suggest instead this diff?
Philip Guenther
Index: stat.c
===================================================================
RCS file: /cvs/src/usr.bin/stat/stat.c,v
retrieving revision 1.16
diff -u -p -r1.16 stat.c
--- stat.c 1 Sep 2010 06:35:05 -0000 1.16
+++ stat.c 5 Oct 2010 21:44:43 -0000
@@ -60,7 +60,7 @@
#define LINUX_FORMAT \
" File: \"%N\"%n" \
" Size: %-11z FileType: %HT%n" \
- " Mode: (%04OLp/%.10Sp) Uid: (%5u/%8Su) Gid: (%5g/%8Sg)%n" \
+ " Mode: (%01Mp%03OLp/%.10Sp) Uid: (%5u/%8Su) Gid:
(%5g/%8Sg)%n" \
"Device: %Hd,%Ld Inode: %i Links: %l%n" \
"Access: %Sa%n" \
"Modify: %Sm%n" \
$ obj/stat -x /usr/bin/passwd ./foo /dev/null
File: "/usr/bin/passwd"
Size: 26280 FileType: Regular File
Mode: (4555/-r-sr-xr-x) Uid: ( 0/ root) Gid: ( 7/ bin)
Device: 4,6 Inode: 52143 Links: 1
Access: Thu Sep 30 00:02:08 2010
Modify: Thu Sep 30 00:02:08 2010
Change: Thu Sep 30 00:02:08 2010
File: "./foo"
Size: 0 FileType: Regular File
Mode: (4004/---S---r--) Uid: ( 1000/guenther) Gid: ( 9/ wsrc)
Device: 4,7 Inode: 2052736 Links: 1
Access: Tue Oct 5 14:45:33 2010
Modify: Tue Oct 5 14:45:33 2010
Change: Tue Oct 5 14:45:38 2010
File: "/dev/null"
Size: 0 FileType: Character Device
Mode: (0666/crw-rw-rw-) Uid: ( 0/ root) Gid: ( 0/ wheel)
Device: 4,0 Inode: 7913 Links: 1
Access: Tue Oct 5 08:29:49 2010
Modify: Tue Oct 5 11:41:16 2010
Change: Tue Oct 5 11:41:16 2010
$