private void InitPanel() { /// check if the instance is a member of an AD /// bool partOfDomain = false; string domain = null; try { using (ManagementObject comObj = WMIUtil.QueryLocalWMI("Select * from win32_computersystem")) { partOfDomain = (bool)comObj["PartOfDomain"]; domain = (string)comObj["Domain"]; } if (partOfDomain) { labelADStatus.Text = string.Format("domain member of {0}", domain); // buttonUnregister.Enabled = true; // buttonUnregister.Visible = true; } else { labelADStatus.Text = "not a member of a domain"; } } catch (Exception e) { EucaLogger.Exception("Can't determine if the host is a part of domain", e); labelADStatus.Text = "error-AD status could not be determined"; } object tmp = EucaServiceLibraryUtil.GetSvcRegistryValue("ADAddress"); if (tmp != null) { _adConfig.ADAddress = (string)tmp; } tmp = EucaServiceLibraryUtil.GetSvcRegistryValue("ADUsername"); if (tmp != null) { _adConfig.ADUsername = (string)tmp; } tmp = EucaServiceLibraryUtil.GetSvcRegistryValue("ADPassword"); { if (tmp != null) { _adConfig.ADPassword = EucaUtil.Decrypt((string)tmp); } } tmp = EucaServiceLibraryUtil.GetSvcRegistryValue("ADOU"); if (tmp != null) { _adConfig.ADOU = (string)tmp; } if (_adConfig.ADAddress != null) { textBoxADAddress.Text = _adConfig.ADAddress; } if (_adConfig.ADUsername != null) { textBoxADUsername.Text = _adConfig.ADUsername; } if (_adConfig.ADPassword != null) { textBoxADPassword.Text = _adConfig.ADPassword; } if (_adConfig.ADOU != null) { textBoxADOU.Text = _adConfig.ADOU; } /// bring up the list of users/groups that has RD permission on the image string[] rdPermissionUsers = null; try { rdPermissionUsers = this.GetRDPermissionUsers(); } catch (Exception e) { EucaLogger.Exception("Could not enumerate RD users/groups from registry", e); } if (rdPermissionUsers != null) { foreach (string name in rdPermissionUsers) { listBoxRDPermission.Items.Add(name); } } buttonApply.Enabled = false; try { int selected = (int)EucaUtil.GetRegistryValue(Registry.LocalMachine, EUCALYPTUS_REGISTRY_PATH, "FormatDrives"); if (selected == 1) { checkBoxFormatDrives.Checked = true; } else { checkBoxFormatDrives.Checked = false; } } catch (Exception e) { EucaLogger.Exception("Couldn't check 'FormatDrives' option from registry", e); } }
private void buttonApply_Click(object sender, EventArgs e) { string adAddr = textBoxADAddress.Text; if (adAddr != null && adAddr.Length == 0) { adAddr = null; } string adUsername = textBoxADUsername.Text; if (adUsername != null && adUsername.Length == 0) { adUsername = null; } string adPassword = textBoxADPassword.Text; if (adPassword != null && adPassword.Length == 0) { adPassword = null; } string adPasswordConfirm = textBoxPwdConfirm.Text; if (adPasswordConfirm != null && adPasswordConfirm.Length == 0) { adPasswordConfirm = null; } string adOu = textBoxADOU.Text; if (adOu != null && adOu.Length == 0) { adOu = null; } if (!(adAddr == null && adUsername == null && adPassword == null && adOu == null)) {// user has put something in the config window if (adAddr == null || adUsername == null || adPassword == null) { MessageBox.Show("AD address, username, and password are required to enable AD join"); return; } } else { MessageBox.Show("AD address, username, and password are required to enable AD join"); return; } if (adPassword != adPasswordConfirm) { MessageBox.Show("Passwords do not match!"); return; } bool updated = false; if (adAddr.Trim() != (string)EucaServiceLibraryUtil.GetSvcRegistryValue("ADAddress")) { EucaServiceLibraryUtil.SetSvcRegistryValue("ADAddress", adAddr.Trim()); updated = true; } if (adUsername.Trim() != (string)EucaServiceLibraryUtil.GetSvcRegistryValue("ADUsername")) { EucaServiceLibraryUtil.SetSvcRegistryValue("ADUsername", adUsername.Trim()); updated = true; } //encrypt AD password properly if (adPassword.Trim() != (string)EucaServiceLibraryUtil.GetSvcRegistryValue("ADPassword")) { string data = EucaUtil.Encrypt(adPassword.Trim()); EucaServiceLibraryUtil.SetSvcRegistryValue("ADPassword", data); updated = true; } if (adOu != null) { if (adOu.Trim() != (string)EucaServiceLibraryUtil.GetSvcRegistryValue("ADOU")) { EucaServiceLibraryUtil.SetSvcRegistryValue("ADOU", adOu.Trim()); updated = true; } } if (updated) { MessageBox.Show("AD information is updated succesfully"); buttonApply.Enabled = false; } else { MessageBox.Show("No change has been saved"); } }