comparison contrib/fixpax.py @ 23940:d0ef40776999 stable

osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081) The packages has to be installed by root but they would be installed insecurely, owned by the uid of the unprivileged user that made the package. The local user with that uid could thus write to /usr/local/bin/hg . bdist_mpkg calls out to pax to create the package, but pax do apparently not have the power to control what it is writing. Instead, patch the pax files and set their uid fields to 0 before they are wrapped in a dmg.
author Mads Kiilerich <madski@unity3d.com>
date Fri, 23 Jan 2015 06:28:28 +0100
parents
children 58eb1c5bba58
comparison
equal deleted inserted replaced
23939:33d1b81c6ef0 23940:d0ef40776999
1 # fixpax - fix ownership in bdist_mpkg output
2 #
3 # Copyright 2015 Matt Mackall <mpm@selenic.com>
4 #
5 # This software may be used and distributed according to the terms of the
6 # MIT license (http://opensource.org/licenses/MIT)
7
8 """Set file ownership to 0 in an Archive.pax.gz.
9 Suitable for fixing files bdist_mpkg output:
10 *.mpkg/Contents/Packages/*.pkg/Contents/Archive.pax.gz
11 """
12
13 import sys, os, gzip
14
15 def fixpax(iname, oname):
16 i = gzip.GzipFile(iname)
17 o = gzip.GzipFile(oname, "w")
18
19 while True:
20 magic = i.read(6)
21 dev = i.read(6)
22 ino = i.read(6)
23 mode = i.read(6)
24 i.read(6) # uid
25 i.read(6) # gid
26 nlink = i.read(6)
27 rdev = i.read(6)
28 mtime = i.read(11)
29 namesize = i.read(6)
30 filesize = i.read(11)
31 name = i.read(int(namesize, 8))
32 data = i.read(int(filesize, 8))
33
34 o.write(magic)
35 o.write(dev)
36 o.write(ino)
37 o.write(mode)
38 o.write("000000")
39 o.write("000000")
40 o.write(nlink)
41 o.write(rdev)
42 o.write(mtime)
43 o.write(namesize)
44 o.write(filesize)
45 o.write(name)
46 o.write(data)
47
48 if name.startswith("TRAILER!!!"):
49 o.write(i.read())
50 break
51
52 o.close()
53 i.close()
54
55 if __name__ == '__main__':
56 for iname in sys.argv[1:]:
57 print 'fixing file ownership in %s' % iname
58 oname = sys.argv[1] + '.tmp'
59 fixpax(iname, oname)
60 os.rename(oname, iname)