]> git.saurik.com Git - apple/security.git/blame - OSX/libsecurity_codesigning/gke/gkclear
Security-57336.1.9.tar.gz
[apple/security.git] / OSX / libsecurity_codesigning / gke / gkclear
CommitLineData
b1ab9ed8
A
1#!/usr/bin/python
2#
3# gkclear - clear system state for Gatekeeper recording sessions
4#
5# This removes DetachedSignatures, resets SystemPolicy, and removes existing gke files.
6#
7import sys
8import os
9import signal
10import errno
11import subprocess
12import shutil
13
14
15#
16# Usage and fail
17#
18def usage():
19 print >>sys.stderr, "Usage: %s" % sys.argv[0]
20 sys.exit(2)
21
22def fail(whatever):
23 print >>sys.stderr, "%s: %s" % (sys.argv[0], whatever)
24 sys.exit(1)
25
26
27#
28# Argument processing
29#
30if len(sys.argv) != 1:
31 usage()
32
33
34#
35# Places and things
36#
37db = "/var/db/"
38detachedsignatures = db + "DetachedSignatures"
39gkeauth = db + "gke.auth"
40gkesigs = db + "gke.sigs"
41policydb = db + "SystemPolicy"
42policydb_default = db + ".SystemPolicy-default"
43
44
45# must be root
46if os.getuid() != 0:
47 fail("Must have root privileges")
48
49
50#
51# Make sure Gatekeeper is disabled
52#
53subprocess.check_call(["/usr/sbin/spctl", "--master-disable"])
54
55
56#
57# Clear detached signatures database
58#
59for file in [detachedsignatures, gkeauth, gkesigs]:
60 try:
61 os.remove(file)
62 except OSError, e:
63 if e[0] != errno.ENOENT:
64 raise
65
66
67#
68# Reset system policy to default values
69#
70shutil.copyfile(policydb_default, policydb)
71
72
73#
74# Kill any extant syspolicyd to flush state
75#
76null = open("/dev/null", "w")
77subprocess.call(["/usr/bin/killall", "syspolicyd"], stderr=null)
78
79
80#
81# Done
82#
83print "System state has been reset."
84sys.exit(0)