auth log: Add windows event codes
[amitay/samba.git] / python / samba / tests / auth_log.py
index 2b280bc..08c8b64 100644 (file)
@@ -28,6 +28,10 @@ from samba.credentials import DONT_USE_KERBEROS, MUST_USE_KERBEROS
 from samba import NTSTATUSError
 from subprocess import call
 from ldb import LdbError
+from samba.dcerpc.windows_event_ids import (
+    EVT_ID_SUCCESSFUL_LOGON,
+    EVT_ID_UNSUCCESSFUL_LOGON
+)
 import re
 
 
@@ -92,6 +96,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
         msg = messages[0]
         self.assertEquals("Authentication", msg["type"])
         self.assertEquals("NT_STATUS_OK", msg["Authentication"]["status"])
+        self.assertEquals(
+            EVT_ID_SUCCESSFUL_LOGON, msg["Authentication"]["eventId"])
         self._assert_ncacn_np_serviceDescription(binding,
                                                  msg["Authentication"]["serviceDescription"])
         self.assertEquals(authTypes[1],
@@ -121,6 +127,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
 
             self.assertEquals(authTypes[3],
                               msg["Authentication"]["authDescription"])
+            self.assertEquals(
+                EVT_ID_SUCCESSFUL_LOGON, msg["Authentication"]["eventId"])
 
     def rpc_ncacn_np_krb5_check(
             self,
@@ -145,6 +153,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                           msg["Authentication"]["serviceDescription"])
         self.assertEquals(authTypes[1],
                           msg["Authentication"]["authDescription"])
+        self.assertEquals(
+            EVT_ID_SUCCESSFUL_LOGON, msg["Authentication"]["eventId"])
 
         # Check the second message it should be an Authentication
         # This this the TCP Authentication in response to the message too big
@@ -156,6 +166,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                           msg["Authentication"]["serviceDescription"])
         self.assertEquals(authTypes[2],
                           msg["Authentication"]["authDescription"])
+        self.assertEquals(
+            EVT_ID_SUCCESSFUL_LOGON, msg["Authentication"]["eventId"])
 
         # Check the third message it should be an Authorization
         msg = messages[2]
@@ -303,6 +315,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                           msg["Authentication"]["serviceDescription"])
         self.assertEquals(authTypes[2],
                           msg["Authentication"]["authDescription"])
+        self.assertEquals(
+            EVT_ID_SUCCESSFUL_LOGON, msg["Authentication"]["eventId"])
 
     def rpc_ncacn_ip_tcp_krb5_check(self, messages, authTypes, service,
                                     binding, protection):
@@ -329,6 +343,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                           msg["Authentication"]["serviceDescription"])
         self.assertEquals(authTypes[2],
                           msg["Authentication"]["authDescription"])
+        self.assertEquals(
+            EVT_ID_SUCCESSFUL_LOGON, msg["Authentication"]["eventId"])
 
         # Check the third message it should be an Authentication
         msg = messages[2]
@@ -338,6 +354,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                           msg["Authentication"]["serviceDescription"])
         self.assertEquals(authTypes[2],
                           msg["Authentication"]["authDescription"])
+        self.assertEquals(
+            EVT_ID_SUCCESSFUL_LOGON, msg["Authentication"]["eventId"])
 
     def test_rpc_ncacn_ip_tcp_ntlm_dns_sign(self):
         creds = self.insta_creds(template=self.get_credentials(),
@@ -441,6 +459,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
         self.assertEquals("ENC-TS Pre-authentication",
                           msg["Authentication"]["authDescription"])
         self.assertTrue(msg["Authentication"]["duration"] > 0)
+        self.assertEquals(
+            EVT_ID_SUCCESSFUL_LOGON, msg["Authentication"]["eventId"])
 
         # Check the second message it should be an Authentication
         msg = messages[1]
@@ -451,6 +471,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
         self.assertEquals("ENC-TS Pre-authentication",
                           msg["Authentication"]["authDescription"])
         self.assertTrue(msg["Authentication"]["duration"] > 0)
+        self.assertEquals(
+            EVT_ID_SUCCESSFUL_LOGON, msg["Authentication"]["eventId"])
 
     def test_ldap_ntlm(self):
 
@@ -476,6 +498,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                           msg["Authentication"]["serviceDescription"])
         self.assertEquals("NTLMSSP", msg["Authentication"]["authDescription"])
         self.assertTrue(msg["Authentication"]["duration"] > 0)
+        self.assertEquals(
+            EVT_ID_SUCCESSFUL_LOGON, msg["Authentication"]["eventId"])
 
     def test_ldap_simple_bind(self):
         def isLastExpectedMessage(msg):
@@ -505,6 +529,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                           msg["Authentication"]["serviceDescription"])
         self.assertEquals("simple bind",
                           msg["Authentication"]["authDescription"])
+        self.assertEquals(
+            EVT_ID_SUCCESSFUL_LOGON, msg["Authentication"]["eventId"])
 
     def test_ldap_simple_bind_bad_password(self):
         def isLastExpectedMessage(msg):
@@ -512,7 +538,10 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     msg["Authentication"]["serviceDescription"] == "LDAP" and
                     (msg["Authentication"]["status"] ==
                         "NT_STATUS_WRONG_PASSWORD") and
-                    msg["Authentication"]["authDescription"] == "simple bind")
+                    (msg["Authentication"]["authDescription"] ==
+                        "simple bind") and
+                    (msg["Authentication"]["eventId"] ==
+                        EVT_ID_UNSUCCESSFUL_LOGON))
 
         creds = self.insta_creds(template=self.get_credentials())
         creds.set_password("badPassword")
@@ -539,7 +568,10 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     msg["Authentication"]["serviceDescription"] == "LDAP" and
                     (msg["Authentication"]["status"] ==
                         "NT_STATUS_NO_SUCH_USER") and
-                    msg["Authentication"]["authDescription"] == "simple bind")
+                    (msg["Authentication"]["authDescription"] ==
+                        "simple bind") and
+                    (msg["Authentication"]["eventId"] ==
+                        EVT_ID_UNSUCCESSFUL_LOGON))
 
         creds = self.insta_creds(template=self.get_credentials())
         creds.set_bind_dn("%s\\%s" % (creds.get_domain(), "badUser"))
@@ -564,7 +596,10 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     msg["Authentication"]["serviceDescription"] == "LDAP" and
                     (msg["Authentication"]["status"] ==
                         "NT_STATUS_NO_SUCH_USER") and
-                    msg["Authentication"]["authDescription"] == "simple bind")
+                    (msg["Authentication"]["authDescription"] ==
+                        "simple bind") and
+                    (msg["Authentication"]["eventId"] ==
+                        EVT_ID_UNSUCCESSFUL_LOGON))
 
         creds = self.insta_creds(template=self.get_credentials())
         creds.set_bind_dn("%s\\%s" % (creds.get_domain(), "abdcef"))
@@ -656,6 +691,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                           msg["Authentication"]["serviceDescription"])
         self.assertEquals("ENC-TS Pre-authentication",
                           msg["Authentication"]["authDescription"])
+        self.assertEquals(EVT_ID_SUCCESSFUL_LOGON,
+                          msg["Authentication"]["eventId"])
 
         # Check the second message it should be an Authentication
         msg = messages[1]
@@ -665,6 +702,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                           msg["Authentication"]["serviceDescription"])
         self.assertEquals("ENC-TS Pre-authentication",
                           msg["Authentication"]["authDescription"])
+        self.assertEquals(EVT_ID_SUCCESSFUL_LOGON,
+                          msg["Authentication"]["eventId"])
 
     def test_smb_bad_password(self):
         def isLastExpectedMessage(msg):
@@ -702,7 +741,9 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     (msg["Authentication"]["status"] ==
                         "NT_STATUS_NO_SUCH_USER") and
                     (msg["Authentication"]["authDescription"] ==
-                        "ENC-TS Pre-authentication"))
+                        "ENC-TS Pre-authentication") and
+                    (msg["Authentication"]["eventId"] ==
+                        EVT_ID_UNSUCCESSFUL_LOGON))
 
         creds = self.insta_creds(template=self.get_credentials())
         creds.set_username("badUser")
@@ -752,6 +793,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                           msg["Authentication"]["authDescription"])
         self.assertEquals("No-Password",
                           msg["Authentication"]["passwordType"])
+        self.assertEquals(EVT_ID_UNSUCCESSFUL_LOGON,
+                          msg["Authentication"]["eventId"])
 
         # Check the second message it should be an Authentication
         msg = messages[1]
@@ -766,6 +809,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                           msg["Authentication"]["passwordType"])
         self.assertEquals("ANONYMOUS LOGON",
                           msg["Authentication"]["becameAccount"])
+        self.assertEquals(EVT_ID_SUCCESSFUL_LOGON,
+                          msg["Authentication"]["eventId"])
 
     def test_smb2_anonymous(self):
         def isLastExpectedMessage(msg):
@@ -797,6 +842,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                           msg["Authentication"]["authDescription"])
         self.assertEquals("No-Password",
                           msg["Authentication"]["passwordType"])
+        self.assertEquals(EVT_ID_UNSUCCESSFUL_LOGON,
+                          msg["Authentication"]["eventId"])
 
         # Check the second message it should be an Authentication
         msg = messages[1]
@@ -811,6 +858,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                           msg["Authentication"]["passwordType"])
         self.assertEquals("ANONYMOUS LOGON",
                           msg["Authentication"]["becameAccount"])
+        self.assertEquals(EVT_ID_SUCCESSFUL_LOGON,
+                          msg["Authentication"]["eventId"])
 
     def test_smb_no_krb_spnego(self):
         def isLastExpectedMessage(msg):
@@ -840,6 +889,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                           msg["Authentication"]["authDescription"])
         self.assertEquals("NTLMv2",
                           msg["Authentication"]["passwordType"])
+        self.assertEquals(EVT_ID_SUCCESSFUL_LOGON,
+                          msg["Authentication"]["eventId"])
 
     def test_smb_no_krb_spnego_bad_password(self):
         def isLastExpectedMessage(msg):
@@ -848,7 +899,9 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     msg["Authentication"]["authDescription"] == "NTLMSSP" and
                     msg["Authentication"]["passwordType"] == "NTLMv2" and
                     (msg["Authentication"]["status"] ==
-                        "NT_STATUS_WRONG_PASSWORD"))
+                        "NT_STATUS_WRONG_PASSWORD") and
+                    (msg["Authentication"]["eventId"] ==
+                        EVT_ID_UNSUCCESSFUL_LOGON))
 
         creds = self.insta_creds(template=self.get_credentials(),
                                  kerberos_state=DONT_USE_KERBEROS)
@@ -876,7 +929,9 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     msg["Authentication"]["authDescription"] == "NTLMSSP" and
                     msg["Authentication"]["passwordType"] == "NTLMv2" and
                     (msg["Authentication"]["status"] ==
-                        "NT_STATUS_NO_SUCH_USER"))
+                        "NT_STATUS_NO_SUCH_USER") and
+                    (msg["Authentication"]["eventId"] ==
+                        EVT_ID_UNSUCCESSFUL_LOGON))
 
         creds = self.insta_creds(template=self.get_credentials(),
                                  kerberos_state=DONT_USE_KERBEROS)
@@ -927,6 +982,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                           msg["Authentication"]["authDescription"])
         self.assertEquals("NTLMv1",
                           msg["Authentication"]["passwordType"])
+        self.assertEquals(EVT_ID_SUCCESSFUL_LOGON,
+                          msg["Authentication"]["eventId"])
 
     def test_smb_no_krb_no_spnego_no_ntlmv2_bad_password(self):
         def isLastExpectedMessage(msg):
@@ -935,7 +992,9 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     msg["Authentication"]["authDescription"] == "bare-NTLM" and
                     msg["Authentication"]["passwordType"] == "NTLMv1" and
                     (msg["Authentication"]["status"] ==
-                        "NT_STATUS_WRONG_PASSWORD"))
+                        "NT_STATUS_WRONG_PASSWORD") and
+                    (msg["Authentication"]["eventId"] ==
+                        EVT_ID_UNSUCCESSFUL_LOGON))
 
         creds = self.insta_creds(template=self.get_credentials(),
                                  kerberos_state=DONT_USE_KERBEROS)
@@ -965,7 +1024,9 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     msg["Authentication"]["authDescription"] == "bare-NTLM" and
                     msg["Authentication"]["passwordType"] == "NTLMv1" and
                     (msg["Authentication"]["status"] ==
-                        "NT_STATUS_NO_SUCH_USER"))
+                        "NT_STATUS_NO_SUCH_USER") and
+                    (msg["Authentication"]["eventId"] ==
+                        EVT_ID_UNSUCCESSFUL_LOGON))
 
         creds = self.insta_creds(template=self.get_credentials(),
                                  kerberos_state=DONT_USE_KERBEROS)
@@ -1000,7 +1061,9 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                         "interactive") and
                     msg["Authentication"]["status"] == "NT_STATUS_OK" and
                     (msg["Authentication"]["workstation"] ==
-                        r"\\%s" % workstation))
+                        r"\\%s" % workstation) and
+                    (msg["Authentication"]["eventId"] ==
+                        EVT_ID_SUCCESSFUL_LOGON))
 
         server   = os.environ["SERVER"]
         user     = os.environ["USERNAME"]
@@ -1029,7 +1092,9 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     (msg["Authentication"]["status"] ==
                         "NT_STATUS_WRONG_PASSWORD") and
                     (msg["Authentication"]["workstation"] ==
-                        r"\\%s" % workstation))
+                        r"\\%s" % workstation) and
+                    (msg["Authentication"]["eventId"] ==
+                        EVT_ID_UNSUCCESSFUL_LOGON))
 
         server   = os.environ["SERVER"]
         user     = os.environ["USERNAME"]
@@ -1058,7 +1123,9 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     (msg["Authentication"]["status"] ==
                         "NT_STATUS_NO_SUCH_USER") and
                     (msg["Authentication"]["workstation"] ==
-                        r"\\%s" % workstation))
+                        r"\\%s" % workstation) and
+                    (msg["Authentication"]["eventId"] ==
+                        EVT_ID_UNSUCCESSFUL_LOGON))
 
         server   = os.environ["SERVER"]
         user     = "badUser"
@@ -1085,7 +1152,9 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     msg["Authentication"]["authDescription"] == "network" and
                     msg["Authentication"]["status"] == "NT_STATUS_OK" and
                     (msg["Authentication"]["workstation"] ==
-                        r"\\%s" % workstation))
+                        r"\\%s" % workstation) and
+                    (msg["Authentication"]["eventId"] ==
+                        EVT_ID_SUCCESSFUL_LOGON))
 
         server   = os.environ["SERVER"]
         user     = os.environ["USERNAME"]
@@ -1113,7 +1182,9 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     (msg["Authentication"]["status"] ==
                         "NT_STATUS_WRONG_PASSWORD") and
                     (msg["Authentication"]["workstation"] ==
-                        r"\\%s" % workstation))
+                        r"\\%s" % workstation) and
+                    (msg["Authentication"]["eventId"] ==
+                        EVT_ID_UNSUCCESSFUL_LOGON))
 
         server   = os.environ["SERVER"]
         user     = os.environ["USERNAME"]
@@ -1141,7 +1212,9 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     (msg["Authentication"]["status"] ==
                         "NT_STATUS_NO_SUCH_USER") and
                     (msg["Authentication"]["workstation"] ==
-                        r"\\%s" % workstation))
+                        r"\\%s" % workstation) and
+                    (msg["Authentication"]["eventId"] ==
+                        EVT_ID_UNSUCCESSFUL_LOGON))
 
         server   = os.environ["SERVER"]
         user     = "badUser"
@@ -1169,7 +1242,9 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     (msg["Authentication"]["status"] == "NT_STATUS_OK") and
                     (msg["Authentication"]["passwordType"] == "MSCHAPv2") and
                     (msg["Authentication"]["workstation"] ==
-                        r"\\%s" % workstation))
+                        r"\\%s" % workstation) and
+                    (msg["Authentication"]["eventId"] ==
+                        EVT_ID_SUCCESSFUL_LOGON))
 
         server   = os.environ["SERVER"]
         user     = os.environ["USERNAME"]
@@ -1199,7 +1274,9 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                         "NT_STATUS_WRONG_PASSWORD") and
                     (msg["Authentication"]["passwordType"] == "MSCHAPv2") and
                     (msg["Authentication"]["workstation"] ==
-                        r"\\%s" % workstation))
+                        r"\\%s" % workstation) and
+                    (msg["Authentication"]["eventId"] ==
+                        EVT_ID_UNSUCCESSFUL_LOGON))
 
         server   = os.environ["SERVER"]
         user     = os.environ["USERNAME"]
@@ -1229,7 +1306,9 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                         "NT_STATUS_NO_SUCH_USER") and
                     (msg["Authentication"]["passwordType"] == "MSCHAPv2") and
                     (msg["Authentication"]["workstation"] ==
-                        r"\\%s" % workstation))
+                        r"\\%s" % workstation) and
+                    (msg["Authentication"]["eventId"] ==
+                        EVT_ID_UNSUCCESSFUL_LOGON))
 
         server   = os.environ["SERVER"]
         user     = "badUser"
@@ -1257,7 +1336,9 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     (msg["Authentication"]["authDescription"] == "network") and
                     (msg["Authentication"]["status"] == "NT_STATUS_OK") and
                     (msg["Authentication"]["workstation"] ==
-                        r"\\%s" % workstation))
+                        r"\\%s" % workstation) and
+                    (msg["Authentication"]["eventId"] ==
+                        EVT_ID_SUCCESSFUL_LOGON))
 
         server   = os.environ["SERVER"]
         user     = os.environ["USERNAME"]
@@ -1295,7 +1376,9 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     (msg["Authentication"]["authDescription"] == "network") and
                     (msg["Authentication"]["status"] == "NT_STATUS_OK") and
                     (msg["Authentication"]["workstation"] ==
-                        r"\\%s" % workstation))
+                        r"\\%s" % workstation) and
+                    (msg["Authentication"]["eventId"] ==
+                        EVT_ID_SUCCESSFUL_LOGON))
 
         server   = os.environ["SERVER"]
         user     = os.environ["USERNAME"]