devel-getncchange: try to find the dest_dsa automatically
authorMatthieu Patou <mat@matws.net>
Wed, 24 Oct 2012 05:12:08 +0000 (22:12 -0700)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 21 Jan 2013 21:31:20 +0000 (22:31 +0100)
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/scripting/devel/getncchanges

index d401c82869f16b283c0b9f1cda6c5dba74fc8918..cf4c0801b5ac84f52e93b40ec031b7170afc8b07 100755 (executable)
@@ -13,6 +13,7 @@ import samba.getopt as options
 from samba.dcerpc import drsuapi, misc
 from samba.samdb import SamDB
 from samba.auth import system_session
+from samba.ndr import ndr_unpack
 
 def do_DsBind(drs):
     '''make a DsBind call, returning the binding handle'''
@@ -102,8 +103,7 @@ if __name__ == "__main__":
     parser.add_option("", "--pas", dest="use_pas", action='store_true', default=False,
                       help="send partial attribute set",)
     parser.add_option("", "--nb-iter", type='int', help="Number of getncchange iterations")
-    parser.add_option("", "--dest-dsa", type='str',
-                      default='"9c637462-5b8c-4467-aef2-bdb1f57bc4ef"', help="destination DSA GUID")
+    parser.add_option("", "--dest-dsa", type='str', help="destination DSA GUID")
     parser.add_option("", "--replica-flags", type='int',
                       default=drsuapi.DRSUAPI_DRS_INIT_SYNC |
                       drsuapi.DRSUAPI_DRS_PER_SYNC |
@@ -148,8 +148,24 @@ if __name__ == "__main__":
     else:
         exop = int(opts.exop)
 
+    dest_dsa = opts.dest_dsa
+    if not dest_dsa:
+        print "no dest_dsa specified trying to figure out from ldap"
+        msgs = samdb.search(controls=["search_options:1:2"],
+                           expression='(objectclass=ntdsdsa)')
+        if len(msgs) == 1:
+            dest_dsa = str(ndr_unpack(misc.GUID,  msgs[0]["invocationId"][0]))
+            print "Found this dsa: %s" % dest_dsa
+        else:
+            # TODO fixme
+            pass
+        if not dest_dsa:
+            print "Unable to find the dest_dsa automatically please specify it"
+            import sys
+            sys.exit(1)
+
     null_guid = misc.GUID()
-    req8.destination_dsa_guid               = misc.GUID(opts.dest_dsa)
+    req8.destination_dsa_guid               = misc.GUID(dest_dsa)
     req8.source_dsa_invocation_id          = misc.GUID(samdb.get_invocation_id())
     req8.naming_context                            = drsuapi.DsReplicaObjectIdentifier()
     req8.naming_context.dn                  = opts.dn.decode("utf-8")