private void _button_BrowseUsers_Click(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; try { ADObject[] results; ObjectPickerWrapper picker = new ObjectPickerWrapper(); results = picker.ShowObjectPicker(this.Handle); if (results != null) { Debug.Assert(results.Length == 1); for (int i = 0; i <= results.Length - 1; i++) { //do this before creating the user because it will remove m_user in the change event _textBox_User.Text = results[i].SamAccountName; m_user = new Sql.User(results[i].SamAccountName, results[i].Sid, m_loginType, Sql.User.UserSource.ActiveDirectory); } } } catch (Exception ex) { logX.loggerX.Error("Error - Server Access Report unable to browse Domain for Users & Groups", ex); Utility.MsgBox.ShowError(Utility.ErrorMsgs.CantGetUsersCaption, ex); } checkSelections(); Cursor = Cursors.Default; }
private void _cmsi_Users_viewGroupMembers_Click(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; UltraGrid grid = (UltraGrid)((ContextMenuStrip)((ToolStripItem)sender).Owner).SourceControl; Sql.User group = new Sql.User(grid.ActiveRow.Cells[colPrincipalName].Text, new Sid(grid.ActiveRow.Cells[colSid].Value as byte[]), DescriptionHelper.GetEnumDescription(Sql.ServerPrincipalTypes.WindowsGroup), Sql.User.UserSource.Snapshot); int snapshotid = (int)grid.ActiveRow.Cells[colSnapshotId].Value; Sql.User user = Forms.Form_SelectGroupMember.GetUser(snapshotid, group); if (user != null) { string server = grid.ActiveRow.Cells[colConnection].Text; Sql.RegisteredServer registeredServer = Program.gController.Repository.RegisteredServers.Find(server); Program.gController.ShowRootView(new Utility.NodeTag(new Data.PermissionExplorer(registeredServer, snapshotid, user, Views.View_PermissionExplorer.Tab.UserPermissions), Utility.View.PermissionExplorer)); } Cursor = Cursors.Default; }
private void _textBox_User_TextChanged(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; m_user = null; checkSelections(); Cursor = Cursors.Default; }
protected bool verifyActiveDirectoryUser() { bool isCancel = false; // verify user is in the snapshot Sql.User user = Sql.User.GetSnapshotWindowsUser(m_SelectedSnapshotID, m_SelectedUser.Name, false, m_SelectedServer.ServerType);//SQLsecure 3.1 (Tushar)--Fix for issue SQLSECU-1971 if (user == null) { user = Sql.User.GetSnapshotWindowsUser(m_SelectedSnapshotID, m_SelectedUser.Sid, false); if (user == null) { // not found, but no conflict so process on through m_SelectedUser.IsVerified = true; } else { MsgBox.ShowWarning(ErrorMsgs.UserPermissionsCaption, string.Format(ErrorMsgs.UserNameChangedADMsg, m_SelectedUser.Name)); m_SelectedUser.IsVerified = true; } } else { //The name matched, so verify it is the same user by Sid if (m_SelectedUser.Sid.Equals(user.Sid) && String.Compare(m_SelectedUser.Domain, user.Domain, true) == 0) { m_SelectedUser.IsVerified = true; } else { //No Sid match, so ask the user which one switch (MsgBox.ShowQuestion(ErrorMsgs.UserPermissionsCaption, ErrorMsgs.UserNotMatchedADQuestion)) { case DialogResult.Yes: m_SelectedUser.IsVerified = true; break; case DialogResult.No: //set this first because it clears m_user _textBox_User.Text = user.Name; m_SelectedUser = user; m_SelectedUser.IsVerified = true; break; case DialogResult.Cancel: isCancel = true; break; } } } return(isCancel); }
//private void _textBox_Server_Leave(object sender, EventArgs e) //{ // Cursor = Cursors.WaitCursor; // m_database = _textBox_Database.Text; // _button_ShowPermissions.Enabled = checkProcessValid(); // Cursor = Cursors.Default; //} //private void _textBox_Server_TextChanged(object sender, EventArgs e) //{ // Cursor = Cursors.WaitCursor; // if (_textBox_Server.Text.Length > 0 && m_serverInstance != null) // { // if (_textBox_Server.Text != m_serverInstance.ConnectionName) // { // m_serverInstance = Program.gController.Repository.GetServer(_textBox_Server.Text); // } // } // Cursor = Cursors.Default; //} private void _textBox_User_Leave(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; if (m_user == null && !_textBox_User.Text.Length.Equals(0)) { m_user = Sql.User.GetSnapshotUser(m_snapshotId, _textBox_User.Text, m_loginType); } _button_ShowPermissions.Enabled = checkProcessValid(); Cursor = Cursors.Default; }
public PermissionExplorer(Sql.RegisteredServer serverIn, int snapShotId, Sql.User user, Views.View_PermissionExplorer.Tab showTabIn) { Debug.Assert(serverIn != null, "Permission Explorer called with null server"); Debug.Assert(snapShotId != 0, "Permission Explorer called with invalid SnapShotId"); m_ServerInstance = serverIn; m_Name = serverIn.ConnectionName; m_SnapShotId = snapShotId; m_User = user; m_Tab = showTabIn; Program.gController.SetCurrentSnapshot(m_ServerInstance, snapShotId); }
//Start-SQLsecure 3.1 (Tushar)--Added support for Azure SQL Database public static Sql.User GetUser(int snapshotId, string loginType, ServerType serverType) { Form_SelectUser form = new Form_SelectUser(snapshotId, loginType, serverType); form.LoadUsers(serverType); DialogResult rc = form.ShowDialog(); Sql.User user = null; if (rc == DialogResult.OK) { user = new Sql.User(form.SelectedUser, form.SelectedSid, loginType, form.SelectedUserSource); } return(user); }
public Form_SelectGroupMember(int snapshotId, Sql.User user) { InitializeComponent(); _toolStripButton_ColumnChooser.Image = AppIcons.AppImage16(AppIcons.Enum.GridFieldChooser); _toolStripButton_GroupBy.Image = AppIcons.AppImage16(AppIcons.Enum.GridGroupBy); _toolStripButton_Save.Image = AppIcons.AppImage16(AppIcons.Enum.GridSaveToExcel); _toolStripButton_Print.Image = AppIcons.AppImage16(AppIcons.Enum.Print); _grid.DisplayLayout.FilterDropDownButtonImage = AppIcons.AppImage16(AppIcons.Enum.GridFilter); _grid.DisplayLayout.GroupByBox.Hidden = Utility.Constants.InitialState_GroupByBoxHidden; m_Snapshot = Snapshot.GetSnapShot(snapshotId); m_user = user; _label_Group.Text = @"Group " + m_user.Name; }
private void _button_BrowseUsers_Click(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; //Start-SQLsecure 3.1 (Tushar)--Added support for Azure SQL Database Sql.User user = Forms.Form_SelectUser.GetUser(m_SelectedSnapshotID, m_loginType, m_SelectedServer.ServerType); if (user != null) { _textBox_User.Text = user.Name; // DO NOT put this before the textBox update because it clears m_user in the TextChanged event m_SelectedUser = user; } SelectUserPage_CheckAllowNext(); Cursor = Cursors.Default; }
private void _radioButton_WindowsUser_CheckedChanged(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; if (((RadioButton)sender).Checked) { if (m_loginType != Sql.LoginTypes.WindowsLogin) { _textBox_User.Text = ""; m_user = null; m_loginType = Sql.LoginTypes.WindowsLogin; } } checkSelections(); Cursor = Cursors.Default; }
public static Sql.User GetUser(int snapshotId, Sql.User user, bool osUser) { Sql.User selectedUser = null; Form_SelectGroupMember form = new Form_SelectGroupMember(snapshotId, user); if (form.LoadUsers(osUser)) { DialogResult rc = form.ShowDialog(); if (rc == DialogResult.OK) { selectedUser = new Sql.User(form.SelectedUser, form.SelectedSid, Sql.LoginType.WindowsLogin, User.UserSource.Snapshot); } } return(selectedUser); }
private void _button_BrowseUsers_Click(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; Sql.User user = Forms.Form_SelectUser.GetUser(m_snapshotId, m_loginType); if (user != null) { _textBox_User.Text = user.Name; // DO NOT put this before the textBox update because it clears m_user in the TextChanged event m_user = user; } _button_ShowPermissions.Enabled = checkProcessValid(); checkSelections(); Cursor = Cursors.Default; }
private void _radioButton_SQLLogin_CheckedChanged(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; if (((RadioButton)sender).Checked) { if (m_loginType != Sql.LoginType.SqlLogin) { m_SelectedUser = null; // try to be smart and not clear the user if it was not validated to type previously if (m_SelectedUser != null && m_SelectedUser.Sid != null) { _textBox_User.Text = String.Empty; } m_loginType = Sql.LoginType.SqlLogin; } } Cursor = Cursors.Default; }
/// <summary> /// SQLsecure 3.1 (Anshul Aggarwal) - Initializes user for Azure AD Account. /// </summary> private void _radioButton_AzureADUserOrGroup_CheckedChanged(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; _button_BrowseUsers.Enabled = !((RadioButton)sender).Checked; if (((RadioButton)sender).Checked) { if (m_loginType != Sql.LoginType.AzureADAccount) { // try to be smart and not clear the user if it was not validated to type previously if (m_user != null && m_user.Sid != null) { _textBox_User.Text = string.Empty; m_user = null; } m_loginType = Sql.LoginType.AzureADAccount; } } checkSelections(); Cursor = Cursors.Default; }
private void _cmsi_Users_showPermissions_Click(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; UltraGrid grid = (UltraGrid)((ContextMenuStrip)((ToolStripItem)sender).Owner).SourceControl; string server = grid.ActiveRow.Cells[colConnection].Text; Sql.RegisteredServer registeredServer = Program.gController.Repository.RegisteredServers.Find(server); int snapshotid = (int)grid.ActiveRow.Cells[colSnapshotId].Value; Sql.User user = new Sql.User(grid.ActiveRow.Cells[colPrincipalName].Text, new Sid(grid.ActiveRow.Cells[colSid].Value as byte[]), grid.ActiveRow.Cells[colPrincipalType].Text, Sql.User.UserSource.Snapshot); Program.gController.ShowRootView(new Utility.NodeTag(new Data.PermissionExplorer(registeredServer, snapshotid, user, Views.View_PermissionExplorer.Tab.UserPermissions), Utility.View.PermissionExplorer)); Cursor = Cursors.Default; }
private void _radioButton_WindowsUser_CheckedChanged(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; _button_BrowseUsers.Enabled = ((RadioButton)sender).Checked; if (((RadioButton)sender).Checked) { if (m_loginType != Sql.LoginType.WindowsLogin) { // try to be smart and not clear the user if it was not validated to type previously if (m_user != null && m_user.Sid != null) { _textBox_User.Text = string.Empty; m_user = null; } m_loginType = Sql.LoginType.WindowsLogin; } } Cursor = Cursors.Default; }
/// <summary> /// SQLsecure 3.1 (Anshul Aggarwal) - Change login types radio buttons based on server type. /// </summary> private void RefreshLoginTypesRadioButtons() { string connectionname = _comboBox_Server.SelectedItem as string; if (connectionname != null) { if (connectionname == Utility.Constants.ReportSelect_AllServers) { this.SuspendLayout(); // Suspend changes. this._radioButton_WindowsUser.Location = WINDOWS_RADIO_BUTTON_LOCATION; this._radioButton_SQLLogin.Location = SQL_RADIO_BUTTON_LOCATION; this._radioButton_AzureADUserOrGroup.Location = AZURE_RADIO_BUTTON_LOCATION; this._radioButton_WindowsUser.Visible = true; this._radioButton_SQLLogin.Visible = true; this._radioButton_AzureADUserOrGroup.Visible = true; this.ResumeLayout(); // Resume changes. } else if (_connectionNameToServer.ContainsKey(connectionname)) { var server = _connectionNameToServer[connectionname]; if (server.ServerType == ServerType.AzureSQLDatabase) { this.SuspendLayout(); // Suspend changes. this._radioButton_AzureADUserOrGroup.Location = WINDOWS_RADIO_BUTTON_LOCATION; this._radioButton_SQLLogin.Location = AZURE_RADIO_BUTTON_LOCATION; this._radioButton_WindowsUser.Visible = false; this._radioButton_SQLLogin.Visible = true; this._radioButton_AzureADUserOrGroup.Visible = true; this.ResumeLayout(); // Resume changes. // Change selected button if it does not exist for current server type. if (_radioButton_WindowsUser.Checked) { m_user = null; _radioButton_AzureADUserOrGroup.Checked = true; } } else { this.SuspendLayout(); // Suspend changes. this._radioButton_WindowsUser.Location = WINDOWS_RADIO_BUTTON_LOCATION; this._radioButton_SQLLogin.Location = AZURE_RADIO_BUTTON_LOCATION; this._radioButton_WindowsUser.Visible = true; this._radioButton_SQLLogin.Visible = true; this._radioButton_AzureADUserOrGroup.Visible = false; this.ResumeLayout(); // Resume changes. if (_radioButton_AzureADUserOrGroup.Checked) { m_user = null; _radioButton_WindowsUser.Checked = true; } } } } }
public static Sql.User GetUser(int snapshotId, Sql.User user) { return(GetUser(snapshotId, user, false)); }
private void loadDataSource() { //Debug.Assert(!m_snapshotId.Equals(0)); try { // Open connection to repository and query permissions. DiagLog.LogInfo("Retrieve User Permissions"); using (SqlConnection connection = new SqlConnection(Program.gController.Repository.ConnectionString)) { // Open the connection. connection.Open(); // Setup register server params. SqlParameter paramSnapshotId = new SqlParameter(ParamGetPermissionsSnapshotId, m_snapshotId); SqlParameter paramLoginType = new SqlParameter(ParamGetPermissionsLoginType, m_loginType); SqlParameter paramSid = new SqlParameter(ParamGetPermissionsSid, m_user.Sid.BinarySid); SqlParameter paramSqlLogin = new SqlParameter(ParamGetPermissionsSqlLogin, m_user.Name); SqlParameter paramDatabase = new SqlParameter(ParamGetPermissionsDatabase, m_database); SqlCommand cmd = new SqlCommand(QueryGetPermissions, connection); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandTimeout = 90; // The permissions take > 30 secs on a 2005 server cmd.Parameters.Add(paramSnapshotId); cmd.Parameters.Add(paramLoginType); cmd.Parameters.Add(paramSid); cmd.Parameters.Add(paramSqlLogin); cmd.Parameters.Add(paramDatabase); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); //Build Explicit Permissions datasource this._grid_Explicit.BeginUpdate(); DataView dv_Explicit = new DataView(ds.Tables[0]); dv_Explicit.RowFilter = string.Format(FilterPermissionType, Utility.Permissions.Type.Explicit); this._grid_Explicit.DataSource = dv_Explicit; this._grid_Explicit.DataMember = ""; this._grid_Explicit.EndUpdate(); //Build Effective/Assigned Permissions datasource this._grid_Effective.BeginUpdate(); DataView dv_Effective = new DataView(ds.Tables[0]); dv_Effective.RowFilter = string.Format(FilterPermissionType, Utility.Permissions.Type.Effective); this._grid_Effective.DataSource = dv_Effective; this._grid_Effective.DataMember = ""; this._grid_Effective.EndUpdate(); //Build Server Logins datasource this._grid_Server.BeginUpdate(); DataView dv_Server = new DataView(ds.Tables[0]); dv_Server.RowFilter = string.Format(@"{0} AND {1}", string.Format(FilterPermissionType, Utility.Permissions.Type.Explicit), string.Format(FilterPermissionLevel, Utility.Permissions.Level.Server) ); DataTable dt_Server = dv_Server.ToTable(true, new string[] { colPrincipalName, colPrincipalType }); dv_Server = dt_Server.DefaultView; dv_Server.Sort = colPrincipalName; this._grid_Server.DataSource = dv_Server; this._grid_Server.DataMember = ""; this._grid_Server.DisplayLayout.Bands[0].Columns.Add(); this._grid_Server.EndUpdate(); //Build Database Logins datasource this._grid_Database.BeginUpdate(); DataView dv_Database = new DataView(ds.Tables[0]); dv_Database.RowFilter = string.Format(@"{0} AND {1}", string.Format(FilterPermissionType, Utility.Permissions.Type.Explicit), string.Format(FilterPermissionLevel, Utility.Permissions.Level.Database) ); DataTable dt_Database = dv_Database.ToTable(true, new string[] { colDatabasePrincipalName, colDatabasePrincipalType }); dv_Database = dt_Database.DefaultView; dv_Database.Sort = colDatabasePrincipalName; this._grid_Database.DataSource = dv_Database; this._grid_Database.DataMember = ""; this._grid_Database.DisplayLayout.Bands[0].Columns.Add(); this._grid_Database.EndUpdate(); //Build Raw data grid datasource for use in testing and development this._grid.BeginUpdate(); this._grid.DataSource = ds.Tables[0]; this._grid.DataMember = ""; this._grid.EndUpdate(); m_snapshotId_shown = m_snapshotId; m_loginType_shown = m_loginType; m_user_shown = m_user; m_database_shown = m_database; } } catch (SqlException ex) { DiagLog.LogError(@"Error - Unable to retrieve user permissions", ex); MsgBox.ShowError(Utility.ErrorMsgs.CantGetUserPermissionsCaption, ex.Message); checkSelections(); } }
protected internal override void runReport() { base.runReport(); logX.loggerX.Info(@"Retrieve data for report Server Access"); if (m_user == null) { // SQLsecure 3.1 (Anshul Aggarwal) - Skip domain check for Azure AD Accounts as well. if (m_loginType.Equals(Sql.LoginType.SqlLogin) || m_loginType.Equals(Sql.LoginType.AzureADAccount)) { // if it is a SQL Login, it will not be validated, so just create the m_user without a sid m_user = new Idera.SQLsecure.UI.Console.Sql.User(_textBox_User.Text, null, m_loginType, Sql.User.UserSource.UserEntry); } else { // Check the domain for the user m_user = Idera.SQLsecure.UI.Console.Sql.User.GetDomainUser(_textBox_User.Text, m_loginType, false); if (m_user == null) { // this user is not found anywhere, so alert the user MsgBox.ShowInfo(ErrorMsgs.UserPermissionsCaption, string.Format(ErrorMsgs.WindowsUserNotMatchedMsg, _textBox_User.Text)); _button_RunReport.Enabled = false; return; } } } try { using (SqlConnection connection = new SqlConnection(Program.gController.Repository.ConnectionString)) { // Open the connection. connection.Open(); // Setup stored procedure SqlCommand cmd = new SqlCommand(QueryDataSource, connection); cmd.CommandType = CommandType.StoredProcedure; DataSet ds = new DataSet(); // Build parameters SqlParameter paramLoginType = new SqlParameter(SqlParamLoginType, m_loginType); SqlParameter paramSqlLogin = new SqlParameter(SqlParamUser, m_user.Name); SqlParameter paramRunDate = new SqlParameter(SqlParamRunDate, m_reportDate); SqlParameter paramPolicyid = new SqlParameter(SqlParamPolicyid, m_policyid); SqlParameter paramServerName = new SqlParameter(SqlParamServerName, getServerName(_comboBox_Server.Text)); SqlParameter paramUseBaseline = new SqlParameter(SqlParamUsebaseline, m_useBaseline); cmd.Parameters.Add(paramRunDate); cmd.Parameters.Add(paramLoginType); cmd.Parameters.Add(paramSqlLogin); cmd.Parameters.Add(paramPolicyid); cmd.Parameters.Add(paramServerName); cmd.Parameters.Add(paramUseBaseline); // Get data SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(ds); ReportDataSource rds = new ReportDataSource(); rds.Name = DataSourceName; rds.Value = ds.Tables[0]; _reportViewer.LocalReport.DataSources.Clear(); _reportViewer.LocalReport.DataSources.Add(rds); } } catch (SqlException ex) { logX.loggerX.Error(@"Error - Unable to get report data", ex); MsgBox.ShowError(m_Title, ErrorMsgs.CantGetReportData, ex); return; } //now show the report panel base.runReport(); //add report parameters ReportParameter[] Param = new ReportParameter[6]; Param[0] = new ReportParameter("ReportTitle", string.Format(Utility.Constants.REPORTS_TITLE_STR, m_Title)); Param[1] = new ReportParameter("UserRange", m_reportDateDisplay); Param[2] = new ReportParameter("userName", m_user.Name); Param[3] = new ReportParameter("logintype", m_loginType); Param[4] = new ReportParameter("serverName", _comboBox_Server.Text); Param[5] = new ReportParameter("Expand_All", _isExpanded.ToString()); _reportViewer.LocalReport.SetParameters(Param); // Make sure _reportViewer is created. // We had issues on some servers where the _reportViewer was not yet created // and this caused a crash. if (!_reportViewer.IsHandleCreated) { if (!_reportViewer.Created) { _reportViewer.CreateControl(); } } _reportViewer.RefreshReport(); }
private void _textBox_User_TextChanged(object sender, EventArgs e) { m_SelectedUser = null; SelectUserPage_CheckAllowNext(); }
private void ValidateUser() { bool isCancel = false; // Validate User if (m_SelectedUser == null) { // Source: User entered a new user // m_user is set to null only by the user changing the value in the textbox _textBox_User.Text = _textBox_User.Text.Trim(); if (_textBox_User.Text.Length == 0) { // there was no user entered, so just alert the user MsgBox.ShowInfo(ErrorMsgs.UserPermissionsCaption, ErrorMsgs.NoUserSelectedMsg); } else { if (m_loginType.Equals(Sql.LoginType.SqlLogin)) { // if it is a SQL Login, it will not be validated, so just create the m_user without a sid m_SelectedUser = new Idera.SQLsecure.UI.Console.Sql.User(_textBox_User.Text, null, m_loginType, Sql.User.UserSource.UserEntry); if (m_SelectedUser != null) { m_SelectedUser.IsVerified = true; } } else { // Check the domain for the user m_SelectedUser = Idera.SQLsecure.UI.Console.Sql.User.GetDomainUser(_textBox_User.Text, m_loginType, false); if (m_SelectedUser == null) { // If not found in domain, check the snapshot m_SelectedUser = Sql.User.GetSnapshotWindowsUser(m_SelectedSnapshotID, _textBox_User.Text, false, m_SelectedServer.ServerType);//SQLsecure 3.1 (Tushar)--Fix for issue SQLSECU-1971 if (m_SelectedUser == null) { // this user is not found anywhere, so alert the user MsgBox.ShowInfo(ErrorMsgs.UserPermissionsCaption, string.Format(ErrorMsgs.WindowsUserNotFoundMsg, _textBox_User.Text)); //m_user = new Sql.User(_textBox_User.Text, new Sid(new byte[] { 0 }), m_loginType, Sql.User.UserSource.UserEntry); } else { // this user was found only in the snapshot, so alert the user if (DialogResult.No == MsgBox.ShowWarningConfirm(ErrorMsgs.UserPermissionsCaption, string.Format(ErrorMsgs.WindowsUserNotFoundDomainMsg, _textBox_User.Text))) { m_SelectedUser = null; return; } } } else { isCancel = verifyActiveDirectoryUser(); } } } } else { if (m_SelectedUser.LoginType == Sql.LoginType.SqlLogin) { // SqlLogin types are processed by name whether valid or not, so it is valid to try it m_SelectedUser.IsVerified = true; } else { Debug.Assert(m_SelectedUser.LoginType == Sql.LoginType.WindowsLogin); // Source: User entered if (!m_SelectedUser.IsVerified) { switch (m_SelectedUser.Source) { case Sql.User.UserSource.ActiveDirectory: isCancel = verifyActiveDirectoryUser(); break; case Sql.User.UserSource.Snapshot: //Validate the user by name Sql.User user = Idera.SQLsecure.UI.Console.Sql.User.GetDomainUser(m_SelectedUser.Name, m_loginType, false); if (user == null) { //If not found by name, then try by Sid user = Idera.SQLsecure.UI.Console.Sql.User.GetDomainUser(m_SelectedUser.Sid, m_loginType, false); if (user == null) { //If not found, there is no mismatch but the user has been // deleted from AD or can't be verified on a reachable DC) m_SelectedUser.IsVerified = true; } else { if (String.Compare(m_SelectedUser.Domain, user.Domain, true) == 0) { // this is only found if the domains match // otherwise, it is probably a well-known account // which uses the same SID on every machine MsgBox.ShowWarning(ErrorMsgs.UserPermissionsCaption, string.Format(ErrorMsgs.UserNameChangedSnapshotMsg, user.Name)); } m_SelectedUser.IsVerified = true; } } else { //The name matched, so verify it is the same user by Sid if (m_SelectedUser.Sid.Equals(user.Sid) && String.Compare(m_SelectedUser.Domain, user.Domain, true) == 0) { m_SelectedUser.IsVerified = true; } else { //No Sid match, so ask the user which one switch (MsgBox.ShowQuestion(ErrorMsgs.UserPermissionsCaption, ErrorMsgs.UserNotMatchedSnapshotQuestion)) { case DialogResult.Yes: m_SelectedUser.IsVerified = true; break; case DialogResult.No: //set this first because it clears m_user _textBox_User.Text = user.Name; m_SelectedUser = user; m_SelectedUser.IsVerified = true; break; case DialogResult.Cancel: isCancel = true; break; } } } break; case Sql.User.UserSource.UserEntry: Debug.Assert(false, @"Unverified existing user-entered user encountered"); //How did we get here ??? break; default: break; } } } } }