public User GetUser(string lanID) { LDAPUserInfo userinfo = new LDAPUserInfo(); User user = userinfo.GetADUser(lanID); return(user); }
public void DeleteSLAData(SLAData slaData) { SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["SLAConnection"].ConnectionString); using (SqlConnection conn = new SqlConnection()) { SqlCommand command = new SqlCommand("usp_DeleteSLAData", connection); command.CommandType = CommandType.StoredProcedure; try { command.Parameters.AddWithValue("@SLADataId", slaData.SLADataId); command.Parameters.AddWithValue("@User", LDAPUserInfo.GetUserLanId()); connection.Open(); command.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { connection.Close(); } } }
public int SaveSLAData(SLAData slaData) { // int parsedInt; int result = 0; SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["SLAConnection"].ConnectionString); using (SqlConnection conn = new SqlConnection()) { SqlCommand command = new SqlCommand("usp_SaveSLAData", connection); command.CommandType = CommandType.StoredProcedure; try { command.Parameters.AddWithValue("@SLADataId", slaData.SLADataId); command.Parameters.AddWithValue("@DashboardId", slaData.DashboardId); command.Parameters.AddWithValue("@SLAId", slaData.SLAId); command.Parameters.AddWithValue("@SLATierId", slaData.SLATierId); command.Parameters.AddWithValue("@SLAYear", slaData.SLAYear); command.Parameters.AddWithValue("@SLAMonth", slaData.SLAMonth); command.Parameters.AddWithValue("@SLAMet", slaData.SLAMet); command.Parameters.AddWithValue("@SLANotMet", slaData.SLANotMet); command.Parameters.AddWithValue("@SLAComment", slaData.SLAComment); command.Parameters.AddWithValue("@User", LDAPUserInfo.GetUserLanId()); connection.Open(); command.Parameters.Add("@ReturnCode", SqlDbType.Int, 2); command.Parameters["@ReturnCode"].Direction = ParameterDirection.Output; command.ExecuteNonQuery(); int x = (int)command.Parameters["@ReturnCode"].Value; if (x == 1) { result = 1; } else { result = 0; } } catch (Exception ex) { throw ex; } finally { connection.Close(); } } return(result); }
public User GetUserData() { try { var user = new User(); var userLanId = LDAPUserInfo.GetUserLanId(); if (!string.IsNullOrWhiteSpace(userLanId)) { user = this.GetUser(userLanId); user.UserId = userLanId; user.IsAdminUser = IsAdminUser(userLanId); } return(user); } catch (Exception ex) { throw ex; } }
private string[] DomainUsernames() { string domainController = this.DomainController(); string bindPath = this.BindPath(domainController); DirectoryEntry directoryObject = new DirectoryEntry(bindPath); if (!String.IsNullOrEmpty(this.credUser)) { string userDomain = String.Format("{0}\\{1}", this.credDomain, this.credUser); if (!this.AreCredentialsValid()) { throw new BruteArgumentException("[X] Credentials supplied for '" + userDomain + "' are invalid!"); } directoryObject.Username = userDomain; directoryObject.Password = this.credPassword; Console.WriteLine("[*] Using alternate creds : {0}\r\n", userDomain); } //user list List <UserInfo> Users = new List <UserInfo>(); DirectorySearcher userSearcher = new DirectorySearcher(directoryObject); userSearcher.Filter = "(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2))"; userSearcher.PropertiesToLoad.Add("sAMAccountName"); userSearcher.PropertiesToLoad.Add("badPwdCount"); userSearcher.PropertiesToLoad.Add("badPasswordTime"); userSearcher.PropertiesToLoad.Add("lockoutTime"); userSearcher.PropertiesToLoad.Add("lockoutDuration"); userSearcher.PropertiesToLoad.Add("pwdLastSet"); userSearcher.SearchScope = SearchScope.Subtree; //pass policy List <LDAPPasswordPolicy> Policies = new List <LDAPPasswordPolicy>(); Policies.Add(Domain.GetDomainPolicy(directoryObject)); var fineGrainedPolicies = Domain.GetFineGrainedPolicies(directoryObject); fineGrainedPolicies.ForEach(x => x.AppliesToUsers = Domain.GetPasswordPolicyUsers(x, directoryObject)); Policies.AddRange(fineGrainedPolicies); try { SearchResultCollection users = userSearcher.FindAll(); ArrayList usernames = new ArrayList(); foreach (SearchResult user in users) { string username = user.Properties["samAccountName"][0].ToString(); usernames.Add(username); LDAPPasswordPolicy policy; var user2 = new LDAPUserInfo(user); policy = user2.GetUserPolicy(Policies); user2 = user2.ClassifyUser(policy); Users.Add(user2); } Console.WriteLine($"Password Policy Count: ({Policies.Count}):"); foreach (var policy in Policies.OrderBy(x => x.PasswordPrecendence)) { Domain.DisplayPolicyDetails(Policies[0], Policies, Users); Console.WriteLine($"-----------------------------------"); } return(Domain.GetList(Policies, Users)); //return usernames.Cast<object>().Select(x => x.ToString()).ToArray(); } catch (System.Runtime.InteropServices.COMException ex) { switch ((uint)ex.ErrorCode) { case 0x8007052E: throw new BruteArgumentException("[X] Login error when retrieving usernames from dc \"" + domainController + "\"! Try it by providing valid /creduser and /credpassword"); case 0x8007203A: throw new BruteArgumentException("[X] Error connecting with the dc \"" + domainController + "\"! Make sure that provided /domain or /dc are valid"); case 0x80072032: throw new BruteArgumentException("[X] Invalid syntax in DN specification! Make sure that /ou is correct"); case 0x80072030: throw new BruteArgumentException("[X] There is no such object on the server! Make sure that /ou is correct"); default: throw ex; } } }