Created
February 14, 2015 16:56
-
-
Save gregneagle/d431b2be358c8e037c8d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# This script removes LocalMCX from opendirectoryd's search path | |
# this version 08 Dec 2014 Greg Neagle | |
import plistlib | |
import subprocess | |
import sys | |
try: | |
output = subprocess.check_output( | |
['/usr/bin/dscl', '-plist', '/Search', 'read', '/', 'CSPSearchPath']) | |
except subprocess.CalledProcessError, err: | |
print >> sys.stderr, "dscl error: %s" % err | |
exit(-1) | |
try: | |
pl = plistlib.readPlistFromString(output) | |
except BaseException, err: | |
print >> sys.stderr, "plist error: %s" % err | |
exit(-1) | |
search_list = pl.get('dsAttrTypeStandard:CSPSearchPath', []) | |
if '/Local/MCX' in search_list: | |
filtered_search_list = [item | |
for item in search_list if item != '/Local/MCX'] | |
if (len(filtered_search_list) | |
and filtered_search_list[0] == '/Local/Default'): | |
cmd = ['/usr/bin/dscl', | |
'/Search', 'create', '/', 'SearchPolicy', 'CSPSearchPath'] | |
try: | |
subprocess.check_call(cmd) | |
except subprocess.CalledProcessError, err: | |
print >> sys.stderr, "dscl error: %s" % err | |
exit(-1) | |
cmd = ['/usr/bin/dscl', '/Search', 'create', '/', 'CSPSearchPath'] | |
cmd.extend(filtered_search_list) | |
try: | |
subprocess.check_call(cmd) | |
except subprocess.CalledProcessError, err: | |
print >> sys.stderr, "dscl error: %s" % err | |
exit(-1) | |
else: | |
print >> sys.stderr, "ds search list error: %s" % filtered_search_list | |
exit(-1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment