public IEnumerable <DSAccount> GetAccounts(ReplicationCookie cookie) { Validator.AssertNotNull(cookie, "cookie"); // Set Schema var schema = BasicSchemaFactory.CreateSchema(); ReplicationResult result; do { result = this.drsConnection.ReplicateAllObjects(cookie); foreach (var obj in result.Objects) { obj.Schema = schema; if (!obj.IsAccount) { continue; } var account = new DSAccount(obj, this.SecretDecryptor); yield return(account); } /* We are modifying the original cookie. Originally, the cookie was immutable, * but the new value could not be returned because iterators do not support out/ref. * This is probably a poor design and it might be done in a more elegant way. */ cookie.Assign(result.Cookie); } while (result.HasMoreData); }
/// <summary> /// This method is used to get the password hash of the ad user /// </summary> /// <param name="distinguishedName">distinguished name of the user</param> /// <param name="userName">User name</param> /// <param name="password">Password</param> /// <param name="domain">domain name</param> /// <param name="serverName">server name</param> /// <returns>string that represents the password hash of the ad user</returns> static string GetPasswordHash(string distinguishedName, string userName, string password, string domain, string serverName) { try { if (string.IsNullOrEmpty(serverName)) { serverName = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).HostName; } System.Net.NetworkCredential domainCredential = null; if (!string.IsNullOrEmpty(userName)) { domainCredential = new System.Net.NetworkCredential(userName, password, domain); } //Create client connection to the AD server. DirectoryReplicationClient client = new DirectoryReplicationClient(serverName, RpcProtocol.TCP, domainCredential); // Get the account based on the distinguished name. DSAccount acc = client.GetAccount(distinguishedName); // Hash byte[] hash = acc.NTHash; return(hash.ToHex()); } catch (Exception ex) { new ExceptionHandler("Distinguished Name - " + distinguishedName + Environment.NewLine + "Error Message - " + ex.Message); return(""); } }
protected override void ProcessRecord() { DSAccount account = null; switch (this.ParameterSetName) { case "AccountName": if (this.DomainName == null) { this.DomainName = Environment.GetEnvironmentVariable("UserDomain"); } account = this.client.GetAccount(new NTAccount(this.DomainName, this.AccountName)); break; case "Upn": account = this.client.GetAccountByUPN(this.Upn); break; case "Sid": account = this.client.GetAccount(new SecurityIdentifier(this.Sid)); break; } if (account == null) { throw new InvalidOperationException("The account could not be found"); } if (account.NTHash == null) { if (!this.OutputCompromisedHashOnMatch.IsPresent) { this.WriteObject(false); } return; } bool result = Global.Store.IsInStore(account.NTHash, StoreType.Password); if (this.OutputCompromisedHashOnMatch.IsPresent) { if (result) { this.WriteObject(account.NTHash.ToHexString()); } } else { this.WriteObject(result); } }
public IEnumerable <DSAccount> GetAccounts() { using (var searcher = new DirectorySearcher(this.searchRoot, AccountsFilter, AccountPropertiesToLoad, SearchScope.Subtree)) { using (var searchResults = searcher.FindAll()) { foreach (var searchResult in searchResults.Cast <SearchResult>()) { var obj = new AdsiObjectAdapter(searchResult); var account = new DSAccount(obj, this.NetBIOSDomainName, null); yield return(account); } } } }
public IEnumerable <DSAccount> GetAccounts(ReplicationCookie initialCookie, ReplicationProgressHandler progressReporter = null) { Validator.AssertNotNull(initialCookie, nameof(initialCookie)); // Create AD schema var schema = BasicSchemaFactory.CreateSchema(); var currentCookie = initialCookie; ReplicationResult result; int processedObjectCount = 0; do { // Perform one replication cycle result = this.drsConnection.ReplicateAllObjects(currentCookie); // Report replication progress if (progressReporter != null) { processedObjectCount += result.Objects.Count; progressReporter(result.Cookie, processedObjectCount, result.TotalObjectCount); } // Process the returned objects foreach (var obj in result.Objects) { obj.Schema = schema; if (!obj.IsAccount) { continue; } var account = new DSAccount(obj, this.SecretDecryptor); yield return(account); } // Update the position of the replication cursor currentCookie = result.Cookie; } while (result.HasMoreData); }
protected void ReloadTablesAndGraph() { _dataserverAccounts = GetAccounts(_startDate, _endDate, MyCountries.SelectedValue, MyProfiles.SelectedValue, MyAccounts.SelectedValue); if (_dataserverAccounts != null) { DataTable IncomeTable; IncomeTable = SummaryTable(true, true, "Income"); gvIncome.DataSource = IncomeTable; gvIncome.DataBind(); SetColumnWidth(ref gvIncome, System.Drawing.Color.Blue, true); DataTable IncomeGLSummaryTable; IncomeGLSummaryTable = SummaryTable(true, false); gvIncomeGLSummary.DataSource = IncomeGLSummaryTable; gvIncomeGLSummary.DataBind(); SetColumnWidth(ref gvIncomeGLSummary, System.Drawing.Color.Black); DataTable ExpensesTable; ExpensesTable = SummaryTable(false, true, "Expenses"); if ((ExpensesTable != null) && (ExpensesTable.Rows.Count != 0)) { gvExpenses.DataSource = ExpensesTable; } gvExpenses.DataBind(); SetColumnWidth(ref gvExpenses, System.Drawing.Color.Red, true); DataTable ExpensesGLSummaryTable; ExpensesGLSummaryTable = SummaryTable(false, false); if ((ExpensesGLSummaryTable != null) && (ExpensesGLSummaryTable.Rows.Count != 0)) { gvExpensesGLSummary.DataSource = ExpensesGLSummaryTable; } gvExpensesGLSummary.DataBind(); SetColumnWidth(ref gvExpensesGLSummary, System.Drawing.Color.Black); if (_dataserverAccounts.FinancialAccount != null) { StartingBalance.Text = _dataserverAccounts.FinancialAccount.Where(a => (a.Code == MyAccounts.SelectedValue || MyAccounts.SelectedValue == "All Accounts")).Sum(b => b.BeginningBalance).ToString("0.00"); EndingBalance.Text = _dataserverAccounts.FinancialAccount.Where(a => (a.Code == MyAccounts.SelectedValue || MyAccounts.SelectedValue == "All Accounts")).Sum(b => b.EndingBalance).ToString("0.00"); DataTable BalanceTable = new DataTable(); BalanceTable.Columns.Add("Balance"); DateTime i = _startDate; while (i < _endDate.AddMonths(0)) { BalanceTable.Columns.Add(i.Year.ToString() + " - " + i.Month.ToString()); i = i.AddMonths(1); } i = _startDate; double balCounter = Convert.ToDouble(StartingBalance.Text); BalanceTable.Rows.Add(); foreach (DataColumn col in BalanceTable.Columns) { int index = BalanceTable.Columns.IndexOf(col); if (BalanceTable.Columns.IndexOf(col) == 0) { BalanceTable.Rows[0][col.ColumnName] = "Balance"; } else { balCounter += Convert.ToDouble(IncomeTable.Rows[0][index]) - Convert.ToDouble(ExpensesTable.Rows[0][index]); BalanceTable.Rows[0][index] = balCounter; _googleGraph += "data.addRow(['" + GetMonth(index - 13) + "', " + (string)IncomeTable.Rows[0][index] + ", " + (string)ExpensesTable.Rows[0][index] + ", " + (string)BalanceTable.Rows[0][index] + "]);" + Environment.NewLine; } } if ((BalanceTable != null) && (BalanceTable.Rows.Count != 0)) { gvBalance.DataSource = BalanceTable; gvBalance.DataBind(); SetColumnWidth(ref gvBalance, (System.Drawing.Color)System.Drawing.ColorTranslator.FromHtml("#FF9900"), true); } saveTransactions(); } } }
protected void ReloadTablesAndGraph() { _dataserverAccounts = GetAccounts(_startDate, _endDate, MyCountries.SelectedValue, MyProfiles.SelectedValue, MyAccounts.SelectedValue); if (_dataserverAccounts != null ) { DataTable IncomeTable; IncomeTable = SummaryTable(true, true, "Income"); gvIncome.DataSource = IncomeTable; gvIncome.DataBind(); SetColumnWidth(ref gvIncome, System.Drawing.Color.Blue, true); DataTable IncomeGLSummaryTable; IncomeGLSummaryTable = SummaryTable(true, false); gvIncomeGLSummary.DataSource = IncomeGLSummaryTable; gvIncomeGLSummary.DataBind(); SetColumnWidth(ref gvIncomeGLSummary, System.Drawing.Color.Black); DataTable ExpensesTable; ExpensesTable = SummaryTable(false, true, "Expenses"); if ((ExpensesTable != null) && (ExpensesTable.Rows.Count != 0)) gvExpenses.DataSource = ExpensesTable; gvExpenses.DataBind(); SetColumnWidth(ref gvExpenses, System.Drawing.Color.Red, true); DataTable ExpensesGLSummaryTable; ExpensesGLSummaryTable = SummaryTable(false, false); if ((ExpensesGLSummaryTable != null) && (ExpensesGLSummaryTable.Rows.Count != 0)) gvExpensesGLSummary.DataSource = ExpensesGLSummaryTable; gvExpensesGLSummary.DataBind(); SetColumnWidth(ref gvExpensesGLSummary, System.Drawing.Color.Black); if (_dataserverAccounts.FinancialAccount != null ) { StartingBalance.Text = _dataserverAccounts.FinancialAccount.Where(a => (a.Code == MyAccounts.SelectedValue || MyAccounts.SelectedValue == "All Accounts")).Sum(b => b.BeginningBalance).ToString("0.00"); EndingBalance.Text = _dataserverAccounts.FinancialAccount.Where(a => (a.Code == MyAccounts.SelectedValue || MyAccounts.SelectedValue == "All Accounts")).Sum(b => b.EndingBalance).ToString("0.00"); DataTable BalanceTable = new DataTable(); BalanceTable.Columns.Add("Balance"); DateTime i = _startDate; while (i < _endDate.AddMonths(0)) { BalanceTable.Columns.Add(i.Year.ToString() + " - " + i.Month.ToString()); i = i.AddMonths(1); } i = _startDate; double balCounter = Convert.ToDouble(StartingBalance.Text); BalanceTable.Rows.Add(); foreach (DataColumn col in BalanceTable.Columns) { int index = BalanceTable.Columns.IndexOf(col); if (BalanceTable.Columns.IndexOf(col) == 0) BalanceTable.Rows[0][col.ColumnName] = "Balance"; else { balCounter += Convert.ToDouble(IncomeTable.Rows[0][index]) - Convert.ToDouble(ExpensesTable.Rows[0][index]); BalanceTable.Rows[0][index] = balCounter; _googleGraph += "data.addRow(['" + GetMonth(index-13) + "', " + (string)IncomeTable.Rows[0][index] + ", " + (string)ExpensesTable.Rows[0][index] + ", " + (string)BalanceTable.Rows[0][index] + "]);" + Environment.NewLine; } } if ((BalanceTable != null) && (BalanceTable.Rows.Count != 0)) { gvBalance.DataSource = BalanceTable; gvBalance.DataBind(); SetColumnWidth(ref gvBalance, (System.Drawing.Color)System.Drawing.ColorTranslator.FromHtml("#FF9900"), true); } saveTransactions(); } } }