protected static void FixAd(Pool pool, List <Host> hostsToAdConfigure, Func <Host, AdUserAndPassword> getAdCredentials) { if (hostsToAdConfigure.Count == 0) { return; } Host poolMaster = Helpers.GetMaster(pool); AsyncAction action; bool success = true; do { success = true; AdUserAndPassword adUserAndPassword = getAdCredentials(poolMaster); try { foreach (Host h in hostsToAdConfigure) { action = new EnableAdAction(h.Connection, poolMaster.external_auth_service_name, adUserAndPassword.Username, adUserAndPassword.Password) { Host = h }; action.RunExternal(null); } } catch (EnableAdAction.CredentialsFailure) { success = false; } } while (!success); }
protected static void FixAd(Pool pool, List<Host> hostsToAdConfigure, Func<Host, AdUserAndPassword> getAdCredentials) { if (hostsToAdConfigure.Count == 0) return; Host poolMaster = Helpers.GetMaster(pool); AsyncAction action; bool success = true; do { success = true; AdUserAndPassword adUserAndPassword = getAdCredentials(poolMaster); try { foreach (Host h in hostsToAdConfigure) { action = new EnableAdAction(Helpers.GetPoolOfOne(h.Connection), poolMaster.external_auth_service_name,adUserAndPassword.Username, adUserAndPassword.Password) {Host = h}; action.RunExternal(null); } } catch (EnableAdAction.CredentialsFailure) { success = false; } } while (!success); }
private void buttonJoinLeave_Click(object sender, EventArgs e) { Program.AssertOnEventThread(); if (buttonJoinLeave.Text == Messages.AD_JOIN_DOMAIN) { // We're enabling AD // Obtain domain, username and password joinPrompt.ShowDialog(this); // Blocking for a long time, check we haven't had the dialog disposed under us if (Disposing || IsDisposed) return; if (joinPrompt.DialogResult == DialogResult.Cancel) { joinPrompt.ClearPassword(); return; } EnableAdAction action = new EnableAdAction(pool, joinPrompt.Domain, joinPrompt.Username, joinPrompt.Password); if (pool.name_label.Length > 0) action.Pool = pool; else action.Host = Helpers.GetMaster(pool.Connection); action.RunAsync(); joinPrompt.ClearPassword(); } else { // We're disabling AD // Warn if the user will boot himself out by disabling AD Session session = pool.Connection.Session; if (session == null) return; if (session.IsLocalSuperuser) { // User is authenticated using local root account. Confirm anyway. string msg = string.Format(Messages.AD_LEAVE_CONFIRM, Helpers.GetName(pool).Ellipsise(50).EscapeAmpersands(), Domain); DialogResult r = new ThreeButtonDialog( new ThreeButtonDialog.Details( null, msg, Messages.AD_FEATURE_NAME), ThreeButtonDialog.ButtonYes, new ThreeButtonDialog.TBDButton(Messages.NO_BUTTON_CAPTION, DialogResult.No, ThreeButtonDialog.ButtonType.CANCEL, true)).ShowDialog(this); //CA-64818: DialogResult can be No if the No button has been hit //or Cancel if the dialog has been closed from the control box if (r != DialogResult.Yes) return; } else { // Warn user will be booted out. string msg = string.Format(pool.name_label.Length > 0 ? Messages.AD_LEAVE_WARNING : Messages.AD_LEAVE_WARNING_HOST, Helpers.GetName(pool).Ellipsise(50), Domain); DialogResult r = new ThreeButtonDialog( new ThreeButtonDialog.Details(SystemIcons.Warning, msg, Messages.ACTIVE_DIRECTORY_TAB_TITLE), ThreeButtonDialog.ButtonYes, new ThreeButtonDialog.TBDButton(Messages.NO_BUTTON_CAPTION, DialogResult.No, ThreeButtonDialog.ButtonType.CANCEL, true)).ShowDialog(this); //CA-64818: DialogResult can be No if the No button has been hit //or Cancel if the dialog has been closed from the control box if (r != DialogResult.Yes) return; } Host master = Helpers.GetMaster(pool.Connection); if (master == null) { // Really shouldn't happen unless we have been very slow with the cache log.Error("Could not retrieve master when trying to look up domain.."); throw new Exception(Messages.CONNECTION_IO_EXCEPTION); } AdPasswordPrompt passPrompt = new AdPasswordPrompt(false, master.external_auth_service_name); DialogResult result = passPrompt.ShowDialog(Program.MainWindow); if (result == DialogResult.Cancel) return; Dictionary<string, string> creds = new Dictionary<string, string>(); if (result != DialogResult.Ignore) { creds.Add(DisableAdAction.KEY_USER, passPrompt.Username); creds.Add(DisableAdAction.KEY_PASSWORD, passPrompt.Password); } DisableAdAction action = new DisableAdAction(pool, creds); if (pool.name_label.Length > 0) action.Pool = pool; else action.Host = Helpers.GetMaster(pool.Connection); action.RunAsync(); } }