misc/scripts/ldap_change_base_dn.py
changeset 5968 2e039d1e150c
child 5969 caea22e82d83
equal deleted inserted replaced
5967:8deedfeb7846 5968:2e039d1e150c
       
     1 from base64 import b64decode, b64encode
       
     2 try:
       
     3     uri, newdn = __args__
       
     4 except ValueError:
       
     5     print 'USAGE: cubicweb-ctl shell <instance> ldap_change_base_dn.py -- <ldap source uri> <new dn>'
       
     6     print
       
     7     print 'you should not have updated your sources file yet'
       
     8 
       
     9 olddn = repo.config.sources()[uri]['user-base-dn']
       
    10 
       
    11 assert olddn != newdn
       
    12 
       
    13 raw_input("Ensure you've stopped the instance, type enter when done.")
       
    14 
       
    15 for eid, extid in sql("SELECT eid, extid FROM entities WHERE source='%s'" % uri):
       
    16     olduserdn = b64decode(extid)
       
    17     newuserdn = olduserdn.replace(olddn, newdn)
       
    18     if newuserdn != olduserdn:
       
    19         print olduserdn, '->', newuserdn
       
    20         sql("UPDATE entities SET extid='%s' WHERE eid=%s" % (b64encode(newdn), eid))
       
    21 
       
    22 commit()
       
    23 
       
    24 print 'you can now update the sources file to the new dn and restart the instance'