python ldap - 从文件直接添加属性值
有没有办法直接从文件中添加LDAP属性值呢?
我想在LDAP中添加jpegPhoto这个属性。但是用“常规”的OpenLDAP修改方法都不行,比如说:
jpegPhoto: < file:///path/to/file
jpegPhoto: file: /path/to/file
jpegPhoto: /path/to/file
这是我尝试做的事情:
record = [
('objectclass', ['inetOrgPerson','organizationalPerson', 'person'),
('uid', ['jfoe@domain.com'] ),
('cn', ['Joe Foo'] ),
('sn', ['Foo'] ),
('givenName', ['Joe'] ),
('mail', ['jfoe@domain.com'] ),
('jpegPhoto', (any above combination here) )
]
l = ldap.initialize()
l.simple_bind_s()
l.add_s('uid=jfoe@domain.com,ou=tree,dc=organization', record)
1 个回答
0
你首先需要在Python中打开JPEG文件,并读取它的二进制数据(这是一串字符串),然后把这个字符串存储为LDAP服务器上jpegPhoto属性的值。对我来说,这样做是有效的。
#file to use
jpgFile = "testimage01.jpg"
#open the file with parameters read, binary(rb) and "read" the opened file
jpgBin = open(jpgFile,"rb").read()
record = [
('objectclass', ['inetOrgPerson','organizationalPerson', 'person'),
('uid', ['jfoe@domain.com'] ),
('cn', ['Joe Foo'] ),
('sn', ['Foo'] ),
('givenName', ['Joe'] ),
('mail', ['jfoe@domain.com'] ),
('jpegPhoto', [jpgBin] )
]
l = ldap.initialize()
l.simple_bind_s()
l.add_s('uid=jfoe@domain.com,ou=tree,dc=organization', record)