我尝试使用python-ldap3将用户添加到群组
conn.modify(' cn = dance,ou = test-groups,dc = stand,dc = lsd',{' memberuid':[(MODIFY_REPLACE,[&#39 ; cn = User1,ou = users,dc = stand,dc = lsd'])]})
但是在ActiveDirectory中没有任何变化
出了什么问题?
答案 0 :(得分:2)
Section
答案 1 :(得分:0)
我解决了...
def insert_ldif (firstname, last_name, UserName, password):
host = 'YourldapIP'
user = 'root'
password = 'YourldapPassword'
a=''
b=a+1
uidNumber = str(b)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, 22))
session = Session()
session.handshake(sock)
session.userauth_password(user, password)
channel = session.open_session()
channel.shell()
channel.write('cat > /home/reemplaceusername/gen.ldif <<EOF\n')
channel.write('dn: uid= %s'',ou=MeLi,dc=lnxnet,dc=ldap\n' %UserName)
channel.write('objectClass: inetOrgPerson\n')
channel.write('objectClass: posixAccount\n')
channel.write('objectClass: shadowAccount\n')
channel.write('shadowLastChange: 0\n')
channel.write('uid: %s\n' %firstname)
channel.write('sn: %s\n' %last_name)
channel.write('givenName: %s\n'%firstname)
channel.write('cn: %s'%firstname)
channel.write(' %s\n'%last_name)
channel.write('displayName: %s ' %firstname)
channel.write('%s\n' %last_name)
channel.write('uidNumber: %s\n' %uidNumber)
channel.write('gidNumber: 5000\n')
channel.write('userPassword: %s\n'%password)
channel.write('gecos: %s ' %firstname)
channel.write('%s\n'%last_name)
channel.write('loginShell:/bin/bash\n')
channel.write('homeDirectory: /home/users/%s\n'%UserName)
channel.write('EOF\n')
channel.write('ldapadd -x -D cn=admin,dc=lnxnet,dc=ldap -W -f /home/reemplaceusername/gen.ldif\n')
channel.write('ldappassword\n')
channel.close()
size, data = channel.read()
while size > 0:
print(data.decode())
size, data = channel.read()
channel.close()
print("Exit status: {0}".format(channel.get_exit_status()))