Update Domain Users

Update Domain Users
 1# This example updates all domain (LDAP) users in the database.
 2
 3
 4# Create a local variable for the output toolbox
 5ot = impact.gui.output_toolbox
 6db = impact.active_database
 7
 8# Retrieve the users from the DB
 9users = db.users
10
11
12def describe_user(user):
13    ot.add("  LoginID: " + str(user.login_id))
14    ot.add("  Formatted Name: " + str(user.formatted_name))
15    ot.add("  User Group: " + str(user.user_group))
16    ot.add("  Email: " + str(user.email))
17
18
19# Clear the output toolbox
20ot.clear()
21
22# Connect to LDAP Service when updating multiple items to improve performance
23if db.connect_to_ldap_service():
24    ot.add("Successfully connected to LDAP Service")
25
26    for i in range(1, users.count  + 1):
27        user = users.item(i)
28
29        if user.ldap_enabled:
30            if user.connected:
31                ot.add("Should not attempt to update a currently connected user")
32            else:
33                db.errors.clear()
34
35                # Update user from LDAP user attributes
36                if user.ldap_update():
37                    ot.add("Successfully updated LDAP user attributes")
38                    describe_user(user)
39                else:
40                    ot.add("Failed to update LDAP user attributes. " + str(db.errors.last.description))
41
42    # Remember to disconnect
43    db.disconnect_from_ldap_service()
44
45else:
46    ot.add("Failed to connect to LDAP service: " + str(db.errors.last.description))