traffic_replay: Make packet generation work on a pre-populated DB again
authorTim Beale <timbeale@catalyst.net.nz>
Mon, 5 Nov 2018 22:14:41 +0000 (11:14 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 7 Nov 2018 16:55:09 +0000 (17:55 +0100)
Generate separate machine accounts for populating a large DB vs
replaying network traffic.

We want to use different userAccountControl flags in each of the above
cases (i.e. commit 3338a3e257fa9f28). However, this means that once you
use the --generate-users-only option, you can't replay network packets
against the machine accounts.

We can avoid this problem by creating separate machine accounts for each
of 2 different cases, e.g. STGM-0-x machines for traffic-replay, and
PC-0-x machines for padding out the database.

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/emulate/traffic.py

index 77a1862f1a8090188cd0dd32f7e54bf4f176b344..9ac8775ed6050400196db6bbf2cc388891951a20 100644 (file)
@@ -1747,9 +1747,19 @@ def generate_users(ldb, instance_id, number, password):
     return users
 
 
-def machine_name(instance_id, i):
+def machine_name(instance_id, i, traffic_account=True):
     """Generate a machine account name from instance id."""
-    return "STGM-%d-%d" % (instance_id, i)
+    if traffic_account:
+        # traffic accounts correspond to a given user, and use different
+        # userAccountControl flags to ensure packets get processed correctly
+        # by the DC
+        return "STGM-%d-%d" % (instance_id, i)
+    else:
+        # Otherwise we're just generating computer accounts to simulate a
+        # semi-realistic network. These use the default computer
+        # userAccountControl flags, so we use a different account name so that
+        # we don't try to use them when generating packets
+        return "PC-%d-%d" % (instance_id, i)
 
 
 def generate_machine_accounts(ldb, instance_id, number, password,
@@ -1758,7 +1768,7 @@ def generate_machine_accounts(ldb, instance_id, number, password,
     existing_objects = search_objectclass(ldb, objectclass='computer')
     added = 0
     for i in range(number, 0, -1):
-        name = machine_name(instance_id, i)
+        name = machine_name(instance_id, i, traffic_account)
         if name + "$" not in existing_objects:
             create_machine_account(ldb, instance_id, name, password,
                                    traffic_account)