简体   繁体   English

ldap3库:使用多个值修改属性

[英]ldap3 library: modify attribute with multiple values

Trying to modify an ldap attribute that has multiple values, can't seem to figure out the syntax. 试图修改具有多个值的ldap属性,似乎无法弄清楚语法。

I'm using the ldap3 library with python3. 我将ldap3库与python3一起使用。

The documentation gives an example which modifies two attributes of an entry - but each attribute only has one value. 文档提供了一个示例,该示例修改了条目的两个属性-但每个属性只有一个值。

The dictionary from that example is the bit I'm having trouble with: 该示例中的字典是我遇到的麻烦:

c.modify('cn=user1,ou=users,o=company',
     {'givenName': [(MODIFY_REPLACE, [<what do I put here>])]})

Instead of 'givenname' which would have one value I want to modify the memberuid attribute which obviously would have many names as entries. 我要修改memberuid属性,而不是只有一个值的“ givenname”,它显然会有许多名称作为条目。

So I spit all my memberuids into a list, make the modification, and then am trying to feed my new usernames/memberuid list to the MODIFY command. 因此,我将所有成员都吐到一个列表中,进行修改,然后尝试将新的用户名/成员列表提供给MODIFY命令。 Like so: 像这样:

oldval = 'super.man'
newval = 'clark.kent'

existingmembers = ['super.man', 'the.hulk', 'bat.man']
newmemberlist = [newval if x==oldval else x for x in existingmembers]
# newmemberlist = ", ".join(str(x) for x in newmemberlist)

I've tried passing in newmemberlist as a list 我尝试将newmemberlist作为列表传递

'memberuid': [(MODIFY_REPLACE, ['clark.kent', 'the.hulk','bat.man'])] 

which gives me TypeError: 'str' object cannot be interpreted as an integer 这给我TypeError: 'str' object cannot be interpreted as an integer

or various combinations (the commented line) of one long string, separated with spaces, commas, semi colons and anything else I can think of 或一个长字符串的各种组合(注释行),用空格,逗号,半冒号和我能想到的其他任何符号分隔

'memberuid': [(MODIFY_REPLACE, 'clark.kent, the.hulk, bat.man')]

which does the replace but I get one memberuid looking like this 'clark.kent, the.hulk, bat.man' 进行替换,但是我得到一个像这个'clark.kent, the.hulk, bat.man'

You need to ensure you are passing in the DN of the ldapobject you wish to modify. 您需要确保传入您要修改的ldapobject的DN。

c.modify(FULL_DN_OF_OBJECT, {'memberuid': [(MODIFY_REPLACE, ['clark.kent', 'the.hulk','bat.man'])]})

Then you should be able just to pass in newmemberlist instead of ['clark.kent', 'the.hulk','bat.man'] 然后,您应该只能传递newmemberlist而不是['clark.kent','the.hulk','bat.man']

c.modify(FULL_DN_OF_OBJECT, {'memberuid': [(MODIFY_REPLACE, newmemberlist )]})

I believe MODIFY_REPLACE command would not accept multiple values, as it would not understand which values would be replaced with new ones. 我相信MODIFY_REPLACE命令将不接受多个值,因为它不理解哪些值将被新值替换。 Instead you should try doing MODIFY_DELETE old values first and MODIFY_ADD new values afterwards. 相反,您应该尝试先执行MODIFY_DELETE旧值,然后再尝试MODIFY_ADD新值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM