diff --git a/src/admc/console_impls/all_policies_folder_impl.cpp b/src/admc/console_impls/all_policies_folder_impl.cpp index ea39182c..3d23350d 100644 --- a/src/admc/console_impls/all_policies_folder_impl.cpp +++ b/src/admc/console_impls/all_policies_folder_impl.cpp @@ -126,8 +126,7 @@ void AllPoliciesFolderImpl::create_policy() { "group policy creation is prohibited by the setting. " "Connect to PDC-Emulator?")); if (answer == QMessageBox::Yes) { - connect_host_with_role(ad, FSMORole_PDCEmulation); - g_status->add_message(tr("PDC-Emulator is connected"), StatusType_Success); + connect_to_PDC_emulator(ad, console); return; } else { diff --git a/src/admc/console_impls/policy_impl.cpp b/src/admc/console_impls/policy_impl.cpp index e95cfff1..850bd3e9 100755 --- a/src/admc/console_impls/policy_impl.cpp +++ b/src/admc/console_impls/policy_impl.cpp @@ -373,8 +373,7 @@ void console_policy_edit(ConsoleWidget *console, const int item_type, const int "group policy editing is prohibited by the setting. " "Connect to PDC-Emulator?")); if (answer == QMessageBox::Yes) { - connect_host_with_role(ad, FSMORole_PDCEmulation); - g_status->add_message(QObject::tr("PDC-Emulator is connected"), StatusType_Success); + connect_to_PDC_emulator(ad, console); return; } else { @@ -592,8 +591,7 @@ void console_policy_delete(const QList &console_list, PolicyRes "group policy deletion is prohibited by the setting. " "Connect to PDC-Emulator?")); if (answer == QMessageBox::Yes) { - connect_host_with_role(ad, FSMORole_PDCEmulation); - g_status->add_message(QObject::tr("PDC-Emulator is connected"), StatusType_Success); + connect_to_PDC_emulator(ad, console_list[0]); return; } else { diff --git a/src/admc/console_impls/policy_ou_impl.cpp b/src/admc/console_impls/policy_ou_impl.cpp index a0092d1a..04e34eae 100755 --- a/src/admc/console_impls/policy_ou_impl.cpp +++ b/src/admc/console_impls/policy_ou_impl.cpp @@ -272,8 +272,7 @@ void PolicyOUImpl::create_and_link_gpo() { "group policy creation is prohibited by the setting. " "Connect to PDC-Emulator?")); if (answer == QMessageBox::Yes) { - connect_host_with_role(ad, FSMORole_PDCEmulation); - g_status->add_message(tr("PDC-Emulator is connected"), StatusType_Success); + connect_to_PDC_emulator(ad, console); return; } else { diff --git a/src/admc/fsmo/fsmo_dialog.cpp b/src/admc/fsmo/fsmo_dialog.cpp index 6c919b6c..df0f48b3 100644 --- a/src/admc/fsmo/fsmo_dialog.cpp +++ b/src/admc/fsmo/fsmo_dialog.cpp @@ -61,6 +61,7 @@ FSMODialog::FSMODialog(AdInterface &ad, QWidget *parent) auto tab = new FSMOTab(title, role_dn); ui->tab_widget->add_tab(tab, title); tab->load(ad); + connect(tab, &FSMOTab::master_changed, this, &FSMODialog::master_changed); } ui->warning_widget->setVisible(false); diff --git a/src/admc/fsmo/fsmo_dialog.h b/src/admc/fsmo/fsmo_dialog.h index 73545f34..16fc739b 100644 --- a/src/admc/fsmo/fsmo_dialog.h +++ b/src/admc/fsmo/fsmo_dialog.h @@ -27,6 +27,7 @@ #include + class AdInterface; namespace Ui { @@ -44,6 +45,9 @@ public: private slots: void gpo_edit_PDC_check_toggled(bool is_checked); + +signals: + void master_changed(const QString &new_master_dn, const QString &string_fsmo_role); }; #endif /* FSMO_DIALOG_H */ diff --git a/src/admc/fsmo/fsmo_tab.cpp b/src/admc/fsmo/fsmo_tab.cpp index 247089c3..8ef28a46 100644 --- a/src/admc/fsmo/fsmo_tab.cpp +++ b/src/admc/fsmo/fsmo_tab.cpp @@ -27,6 +27,7 @@ #include "utils.h" #include "fsmo/fsmo_utils.h" + FSMOTab::FSMOTab(const QString &title, const QString &role_dn_arg) { ui = new Ui::FSMOTab(); ui->setupUi(this); @@ -67,12 +68,8 @@ void FSMOTab::change_master() { return; } - const QString new_master_service = [&]() { - const AdObject rootDSE = ad.search_object(""); - const QString out = rootDSE.get_string(ATTRIBUTE_DS_SERVICE_NAME); - - return out; - }(); + const AdObject rootDSE = ad.search_object(""); + const QString new_master_service = rootDSE.get_string(ATTRIBUTE_DS_SERVICE_NAME); const bool success = ad.attribute_replace_string(role_dn, ATTRIBUTE_FSMO_ROLE_OWNER, new_master_service); @@ -80,5 +77,7 @@ void FSMOTab::change_master() { if (success) { load(ad); + const QString new_master_dn = rootDSE.get_string(ATTRIBUTE_SERVER_NAME); + emit master_changed(new_master_dn, fsmo_string_from_dn(role_dn)); } } diff --git a/src/admc/fsmo/fsmo_tab.h b/src/admc/fsmo/fsmo_tab.h index 2bf2c165..1dc5e25c 100644 --- a/src/admc/fsmo/fsmo_tab.h +++ b/src/admc/fsmo/fsmo_tab.h @@ -44,6 +44,10 @@ private: QString role_dn; void change_master(); + +signals: + // TODO: Remove tabs and use signal from fsmo_dialog directly + void master_changed(const QString &new_master_dn, const QString &string_fsmo_role); }; #endif /* FSMO_TAB_H */ diff --git a/src/admc/fsmo/fsmo_utils.cpp b/src/admc/fsmo/fsmo_utils.cpp index 5c774a1c..c882ca52 100644 --- a/src/admc/fsmo/fsmo_utils.cpp +++ b/src/admc/fsmo/fsmo_utils.cpp @@ -5,8 +5,11 @@ #include "adldap.h" #include "utils.h" #include "settings.h" +#include "console_widget/console_widget.h" +#include "status.h" #include +#include bool gpo_edit_without_PDC_disabled = true; @@ -49,9 +52,48 @@ bool current_dc_is_master_for_role(AdInterface &ad, FSMORole role) void connect_host_with_role(AdInterface &ad, FSMORole role) { - QString role_dn = dn_from_role(role); - QString current_master = current_master_for_role_dn(ad, role_dn); + QString current_master = current_master_for_role(ad, role); settings_set_variant(SETTING_host, current_master); AdInterface::set_dc(current_master); ad.update_dc(); } + +void connect_to_PDC_emulator(AdInterface &ad, ConsoleWidget *console) +{ + connect_host_with_role(ad, FSMORole_PDCEmulation); + console->refresh_scope(console->domain_info_index()); + g_status->add_message(QObject::tr("PDC-Emulator is connected"), StatusType_Success); +} + +QString current_master_for_role(AdInterface &ad, FSMORole role) +{ + QString role_dn = dn_from_role(role); + return current_master_for_role_dn(ad, role_dn); +} + +QString string_fsmo_role(FSMORole role) +{ + switch (role) { + case FSMORole_DomainDNS: return "Domain DNS"; + case FSMORole_ForestDNS: return "Forest DNS"; + case FSMORole_PDCEmulation: return "PDC Emulator"; + case FSMORole_Schema: return "Schema master"; + case FSMORole_DomainNaming: return "Domain naming master"; + case FSMORole_Infrastructure: return "Infrastructure master"; + case FSMORole_RidAllocation: return "RID master"; + + case FSMORole_COUNT: break; + }; + + return QString(); +} + +QString fsmo_string_from_dn(const QString &fsmo_role_dn) +{ + for (int role = 0; role < FSMORole_COUNT; ++role) { + if (dn_from_role(FSMORole(role)) == fsmo_role_dn) { + return string_fsmo_role(FSMORole(role)); + } + } + return QString(); +} diff --git a/src/admc/fsmo/fsmo_utils.h b/src/admc/fsmo/fsmo_utils.h index 8448265a..88e3c34b 100644 --- a/src/admc/fsmo/fsmo_utils.h +++ b/src/admc/fsmo/fsmo_utils.h @@ -3,6 +3,7 @@ class QString; class AdInterface; +class ConsoleWidget; extern bool gpo_edit_without_PDC_disabled; @@ -18,10 +19,18 @@ enum FSMORole { FSMORole_COUNT, }; +QString string_fsmo_role(FSMORole role); + +QString fsmo_string_from_dn(const QString &fsmo_role_dn); + // Returns the DN of the object that // store's role's master in it's attributes QString dn_from_role(FSMORole role); +FSMORole fsmo_role_from_dn(const QString &role_dn); + +QString current_master_for_role(AdInterface &ad, FSMORole role); + // Returns dns host name of role's master object (DC) QString current_master_for_role_dn(AdInterface &ad, QString role_dn); @@ -29,4 +38,6 @@ bool current_dc_is_master_for_role(AdInterface &ad, FSMORole role); void connect_host_with_role(AdInterface &ad, FSMORole role); +void connect_to_PDC_emulator(AdInterface &ad, ConsoleWidget *console); + #endif // FSMO_UTILS_H