I'm trying to run the following script to create a mass configuration deployment. The script should read a plist file and create an LDAP configuration on my Macbook.
#!/usr/bin/python
from OpenDirectory import ODNode, ODSession, kODNodeTypeConfigure
from Foundation import NSMutableData, NSData
import os
import sys
####read plist####
GOOGLELDAPCONFIGFILE = open(sys.argv[1], "r")
CONFIG = GOOGLELDAPCONFIGFILE.read()
GOOGLELDAPCONFIGFILE.close()
####write plist####
od_session = ODSession.defaultSession()
od_conf_node, err = ODNode.nodeWithSession_type_error_(od_session, kODNodeTypeConfigure, None)
request = NSMutableData.dataWithBytes_length_(b'\x00'*32, 32)
request.appendData_(NSData.dataWithBytes_length_(CONFIG, len(CONFIG)))
response, err = od_conf_node.customCall_sendData_error_(99991, request, None)
####Edit the default search path and append the new node to allow for login####
os.system("dscl -q localhost -append /Search CSPSearchPath /LDAPv3/ldap.google.com")
os.system("bash -c 'echo -e \"TLS_IDENTITY\tLDAP Client\" >> /etc/openldap/ldap.conf' ")
However I always get this error:
% sudo python3 ldap.py ldap.plist Password: Traceback (most recent call last): File "/Users/user/Downloads/ldap.py", line 17, in <module> request.appendData_(NSData.dataWithBytes_length_(CONFIG, len(CONFIG))) TypeError: Expecting byte-buffer, got str
Can anybody tell me what's wrong with the code?
Thanks