简体   繁体   中英

Script to find the user who does not have uid (User ID) in LDAP server

I wrote a python script to find out the users who does not have uid (User ID) in the ldap server but I am getting weird results.

from ldap3 import Server, Connection, ALL
import csv

server = Server('server', get_info=ALL)
conn = Connection(server, 'uid=idmsa,ou=people,ou=auth,o=csun', 'password', auto_bind=True)
# Fetches the given attributes
conn.search('o=csun', '(&(objectclass=person)(!(uid=*)))', attributes=['uidNumber'])

conn.entries

Output:

DN: cn=proxy,ou=Auth,o=csun - STATUS: Read - READ TIME: 2021-12-16T02:42:03.581983
, DN: cn=replica,ou=Auth,o=csun - STATUS: Read - READ TIME: 2021-12-16T02:42:03.582261
, DN: cn=anricd,ou=Proxies,ou=Auth,o=CSUN - STATUS: Read - READ TIME: 2021-12-16T02:42:03.582403
, DN: cn=bind,ou=proxies,ou=auth,o=csun - STATUS: Read - READ TIME: 2021-12-16T02:42:03.582494
, DN: cn=ciscovoip,ou=Proxies,ou=Auth,o=CSUN - STATUS: Read - READ TIME: 2021-12-16T02:42:03.582578
, DN: cn=ecs samba,ou=Proxies,ou=Auth,o=CSUN - STATUS: Read - READ TIME: 2021-12-
]

Could you try this?

from ldap3 import Server, Connection, ALL
import csv


# In[5]:
LDAP_SERVER ="ipa.demo1.freeipa.org"
LDAP_USER ="uid=admin,cn=users,cn=accounts,dc=demo1,dc=freeipa,dc=org"
LDAP_PASSWORD ="Secret123"
server = Server(LDAP_SERVER, get_info=ALL)


# In[19]:
conn = Connection(server, LDAP_USER, LDAP_PASSWORD, auto_bind=True)

# In[23]:
conn.search('dc=demo1,dc=freeipa,dc=org', '(&(objectclass=person)(&(uid=*)))', attributes=['uidNumber'])
conn.entries

Here is the result:

[DN: uid=admin,cn=users,cn=accounts,dc=demo1,dc=freeipa,dc=org - STATUS: Read - READ TIME: 2021-12-16T10:03:14.011458
     uidNumber: 613800000,
 DN: uid=manager,cn=users,cn=accounts,dc=demo1,dc=freeipa,dc=org - STATUS: Read - READ TIME: 2021-12-16T10:03:14.011458
     uidNumber: 613800001,
 DN: uid=employee,cn=users,cn=accounts,dc=demo1,dc=freeipa,dc=org - STATUS: Read - READ TIME: 2021-12-16T10:03:14.011458
     uidNumber: 613800003,
 DN: uid=helpdesk,cn=users,cn=accounts,dc=demo1,dc=freeipa,dc=org - STATUS: Read - READ TIME: 2021-12-16T10:03:14.011458
     uidNumber: 613800004]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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