Statistics
| Branch: | Tag: | Revision:

root / autotools / check-tar @ 387863a5

History | View | Annotate | Download (1.5 kB)

1 e627fe09 Michael Hanselmann
#!/usr/bin/python
2 e627fe09 Michael Hanselmann
#
3 e627fe09 Michael Hanselmann
4 e627fe09 Michael Hanselmann
# Copyright (C) 2010 Google Inc.
5 e627fe09 Michael Hanselmann
#
6 e627fe09 Michael Hanselmann
# This program is free software; you can redistribute it and/or modify
7 e627fe09 Michael Hanselmann
# it under the terms of the GNU General Public License as published by
8 e627fe09 Michael Hanselmann
# the Free Software Foundation; either version 2 of the License, or
9 e627fe09 Michael Hanselmann
# (at your option) any later version.
10 e627fe09 Michael Hanselmann
#
11 e627fe09 Michael Hanselmann
# This program is distributed in the hope that it will be useful, but
12 e627fe09 Michael Hanselmann
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 e627fe09 Michael Hanselmann
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 e627fe09 Michael Hanselmann
# General Public License for more details.
15 e627fe09 Michael Hanselmann
#
16 e627fe09 Michael Hanselmann
# You should have received a copy of the GNU General Public License
17 e627fe09 Michael Hanselmann
# along with this program; if not, write to the Free Software
18 e627fe09 Michael Hanselmann
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 e627fe09 Michael Hanselmann
# 02110-1301, USA.
20 e627fe09 Michael Hanselmann
21 e627fe09 Michael Hanselmann
22 e627fe09 Michael Hanselmann
"""Script to check tarball generated by Automake.
23 e627fe09 Michael Hanselmann
24 e627fe09 Michael Hanselmann
"""
25 e627fe09 Michael Hanselmann
26 e627fe09 Michael Hanselmann
import sys
27 e627fe09 Michael Hanselmann
import stat
28 e627fe09 Michael Hanselmann
import tarfile
29 e627fe09 Michael Hanselmann
30 e627fe09 Michael Hanselmann
31 e627fe09 Michael Hanselmann
def ReportError(member, msg):
32 e627fe09 Michael Hanselmann
  print >>sys.stderr, "%s: %s" % (member.name, msg)
33 e627fe09 Michael Hanselmann
34 e627fe09 Michael Hanselmann
35 e627fe09 Michael Hanselmann
def main():
36 e627fe09 Michael Hanselmann
  tf = tarfile.open(fileobj=sys.stdin)
37 e627fe09 Michael Hanselmann
38 e627fe09 Michael Hanselmann
  success = True
39 e627fe09 Michael Hanselmann
40 e627fe09 Michael Hanselmann
  for member in tf.getmembers():
41 e627fe09 Michael Hanselmann
    if member.uid != 0:
42 e627fe09 Michael Hanselmann
      success = False
43 e627fe09 Michael Hanselmann
      ReportError(member, "Owned by UID %s, not UID 0" % member.uid)
44 e627fe09 Michael Hanselmann
45 e627fe09 Michael Hanselmann
    if member.gid != 0:
46 e627fe09 Michael Hanselmann
      success = False
47 e627fe09 Michael Hanselmann
      ReportError(member, "Owned by GID %s, not GID 0" % member.gid)
48 e627fe09 Michael Hanselmann
49 e627fe09 Michael Hanselmann
    if member.mode & (stat.S_IWGRP | stat.S_IWOTH):
50 e627fe09 Michael Hanselmann
      success = False
51 e627fe09 Michael Hanselmann
      ReportError(member, "World or group writeable (mode is %o)" % member.mode)
52 e627fe09 Michael Hanselmann
53 e627fe09 Michael Hanselmann
  if success:
54 e627fe09 Michael Hanselmann
    sys.exit(0)
55 e627fe09 Michael Hanselmann
56 e627fe09 Michael Hanselmann
  sys.exit(1)
57 e627fe09 Michael Hanselmann
58 e627fe09 Michael Hanselmann
59 e627fe09 Michael Hanselmann
if __name__ == "__main__":
60 e627fe09 Michael Hanselmann
  main()