@@ -28,15 +28,22 @@ def on_login(self, context, connection):
2828 else :
2929 self .context .log .fail ("No logins found." )
3030
31+ def get_domain_name (self ) -> str :
32+ query = "SELECT DEFAULT_DOMAIN() as domain_name;"
33+ try :
34+ res = self .mssql_conn .sql_query (query )
35+ if res and res [0 ].get ("domain_name" ):
36+ return res [0 ]["domain_name" ].upper ()
37+ return ""
38+ except Exception as e :
39+ self .context .log .debug (f"Error querying domain name: { e } " )
40+ return ""
41+
3142 def get_logins (self ) -> list :
32- """
33- Fetches a list of SQL Server logins with their types.
43+ domain_name = self . get_domain_name ()
44+ domain_prefix = f" { domain_name } \\ " if domain_name else ""
3445
35- Returns
36- -------
37- list: List of tuples containing (login_name, login_type, status).
38- """
39- query = """
46+ query = f"""
4047 SELECT
4148 name,
4249 type,
@@ -45,8 +52,8 @@ def get_logins(self) -> list:
4552 WHEN 'SQL_LOGIN' THEN 'SQL User'
4653 WHEN 'WINDOWS_LOGIN' THEN
4754 CASE
48- WHEN name LIKE 'NT AUTHORITY \\ %' OR name LIKE 'NT SERVICE \\ %' THEN 'Local User'
49- WHEN name LIKE '%\\ %' THEN 'Domain User'
55+ WHEN name LIKE '{ domain_prefix } %' THEN 'Domain User'
56+ WHEN name LIKE '%\\ %' THEN 'Local User'
5057 ELSE 'Local User'
5158 END
5259 WHEN 'WINDOWS_GROUP' THEN 'Windows Group'
@@ -76,4 +83,3 @@ def get_logins(self) -> list:
7683
7784 def options (self , context , module_options ):
7885 pass
79- pass
0 commit comments