0

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

2 Answers 2

1

Try installing pyobjc-framework-opendirectory with:

python3 -m pip install pyobjc-framework-opendirectory

I have the same issue since MacOS 12.3+. I am keeping my systems on 12.2 until I myself figure this out. The code looks the way it is suppose to look prior to 12.3 and based on Google's recommendations.

So far all I could dig up is that of the OpenDirectory modules being updated on 12.3+

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, thank you for your reply. I have version 8.5 of pyobjc-framework-OpenDirector, still doesn't work. I'm using MacOS 12.4.
0

Try to use request.appendData_(NSData.dataWithBytes_length_(str.encode(CONFIG), len(CONFIG))). For me it works. I advise you to read something about python 2 and 3 differences. Good Luck!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.