Subject: Re: pkg/34968 ("checkperms" is broken under Mac OS X)
To: None <tv@NetBSD.org, gnats-admin@netbsd.org, pkgsrc-bugs@netbsd.org,>
From: Todd Vierling <tv@netbsd.org>
List: pkgsrc-bugs
Date: 11/06/2006 16:30:02
The following reply was made to PR pkg/34968; it has been noted by GNATS.

From: "Todd Vierling" <tv@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: rillig@netbsd.org, gnats-admin@netbsd.org,
	tron@colwyn.zhadum.org.uk
Subject: Re: pkg/34968 ("checkperms" is broken under Mac OS X)
Date: Mon, 6 Nov 2006 11:29:54 -0500

 On 11/5/06, rillig@netbsd.org <rillig@netbsd.org> wrote:
 > I don't know anything about Interix, so can you please have a try if the
 > sysutils/checkperms package is working there?
 
 I haven't had a chance to test it yet, but most certainly it won't
 work.  Interix has ELF-like behavior, but its binaries are Windows PE
 files.
 
 Attached at bottom is an excerpt from the Interix-supplied
 /usr/share/magic file, and an excerpt of hexdump on one such binary.
 I would advise a very specific check for "Posix-CUI" executable files
 as described below so that the extended NTFS permissions on Win32
 binaries are not clobbered by checkperms.  (chmod(2) will clobber any
 permissions and NT ACLs and replace them with the simple POSIX
 permissions, which is undesirable for non-Interix binaries.)
 
 The quick pseudo description of how to detect these binaries is:
 
 * first two bytes must be "MZ"
 * at offset 60 (decimal) is a 32-bit little-endian number X
 * at offset X must be the four bytes "PE\0\0"
 * at offset X+92 (decimal) must be the little-endian 16-bit number 7
 
 Because of hacks in the way shared library support was shoehorned into
 Interix 3, the definitions for "Interix dynamic shared library" in the
 magic file excerpt below are incorrect, but included here for
 completeness.  The pseudocode description above should correctly match
 all Interix binaries and shlibs.
 
 =====
 
 # Various Microsoft OS. formats
 #------------------------
 #
 # Windows NT magic numbers
 #
 # All NT executable and DLL files have a MS-DOS header stub
 # which has the "MZ" identifiable string
 #
 # The offset to find the PE signature (the string "PE\0\0")
 # is given at address 60.
 # After the signature (4bytes long) is the PE file header.
 #
 #  offset [ (60+offset) ]
 #  ------
 #    0  PE signature  (4 bytes)
 #    4   machine type (2bytes)
 #    ...
 #    22  characteristics (2 bytes)
 #        if 0x2000 bit set, then its a DLL
 #
 #    24  [ Start of optional headers ]
 #
 #    92  subsystem type
 #    94  DLLCharacteristics (NT obsolete)
 #          - but used by Interix GNU ld to indicate shared library
 #
 #
 #
 0       string          MZ
 >(60)   string          PE              Windows NT PE format (EXE),
 # check if a DLL (or a .so) then
 >>(60+22)       short   &0x2000
 >>>(60+94)      short   1               Interix dynamic shared library
 >>>(60+94)      short   0               Windows DLL
 #endif
 # if its not a DLL then print out image characteristics
 >>(60+22)       short   >0
 >>>(60+94)      short   1               dynamically linked
 >>>(60+22)      short   &0x2            executable
 >>>(60+22)      short   ^0x2            incomplete executable
 >>>(60+22)      short   ^0x200          not stripped
 #endif
 >>(60+4)        short           0x14c           Intel
 >>(60+4)        short           0x166           MIPS
 >>(60+4)        short           0x184           Alpha
 >>(60+4)        short           0x1F0           PowerPC
 >>(60+4)        short           0x290           HP-Risc
 >>(60+92)       short           7       Posix-CUI
 >>(60+92)       short           3       Windows-CUI
 >>(60+92)       short           2       Windows-GUI
 >>(60+92)       short           1       NT-native
 
 =====
 
 00000000  4d 5a 90 00 03 00 00 00  04 00 00 00 ff ff 00 00
 00000010  b8 00 00 00 00 00 00 00  40 00 00 00 00 00 00 00
 00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
 00000030  00 00 00 00 00 00 00 00  00 00 00 00 80 00 00 00
 00000040  0e 1f ba 0e 00 b4 09 cd  21 b8 01 4c cd 21 54 68
 00000050  69 73 20 70 72 6f 67 72  61 6d 20 63 61 6e 6e 6f
 00000060  74 20 62 65 20 72 75 6e  20 69 6e 20 44 4f 53 20
 00000070  6d 6f 64 65 2e 0d 0d 0a  24 00 00 00 00 00 00 00
 00000080  50 45 00 00 4c 01 0b 00  59 f4 10 42 00 00 00 00
 00000090  00 00 00 00 e0 00 0f 02  0b 01 02 38 00 fa 05 00
 000000a0  00 ca 08 00 00 3a 01 00  78 10 00 00 00 10 00 00
 000000b0  00 10 06 00 00 00 40 00  00 10 00 00 00 02 00 00
 000000c0  04 00 00 00 01 00 00 00  04 00 00 00 00 00 00 00
 000000d0  00 70 0a 00 00 04 00 00  e7 81 09 00 07 00 01 00
 000000e0  00 00 40 00 00 00 01 00  00 00 10 00 00 10 00 00
 000000f0  00 00 00 00 10 00 00 00  00 00 00 00 00 00 00 00
 
 -- 
 -- Todd Vierling <tv@duh.org> <tv@pobox.com> <todd@vierling.name>