private bool PromptForTargetForest(IViewAware owner, out string targetServer) { targetServer = null; SelectForestViewModel vm = new SelectForestViewModel(); ExternalDialogWindow w = new ExternalDialogWindow { Title = "Select forest", DataContext = vm, SaveButtonName = "Next...", SizeToContent = SizeToContent.WidthAndHeight, SaveButtonIsDefault = true }; foreach (Forest forest in this.domainTrustProvider.GetForests()) { vm.AvailableForests.Add(forest.Name); } vm.SelectedForest = vm.AvailableForests.FirstOrDefault(); if (vm.AvailableForests.Count > 1) { w.Owner = owner.GetWindow(); if (!w.ShowDialog() ?? false) { return(false); } } targetServer = this.discoveryServices.GetDomainController(vm.SelectedForest ?? Forest.GetCurrentForest().Name); return(true); }
public async Task AddAllowedPrincipal() { try { ExternalDialogWindow w = new ExternalDialogWindow(); w.Title = "Select forest"; var vm = new SelectForestViewModel(); w.DataContext = vm; w.SaveButtonName = "Next..."; w.SaveButtonIsDefault = true; vm.AvailableForests = new List <string>(); var domain = Domain.GetCurrentDomain(); vm.AvailableForests.Add(domain.Forest.Name); vm.SelectedForest = domain.Forest.Name; foreach (var trust in domain.Forest.GetAllTrustRelationships().OfType <TrustRelationshipInformation>()) { if (trust.TrustDirection == TrustDirection.Inbound || trust.TrustDirection == TrustDirection.Bidirectional) { vm.AvailableForests.Add(trust.TargetName); } } w.Owner = this.GetWindow(); if (!w.ShowDialog() ?? false) { return; } DsopScopeInitInfo scope = new DsopScopeInitInfo(); scope.Filter = new DsFilterFlags(); scope.Filter.UpLevel.BothModeFilter = DsopObjectFilterFlags.DSOP_FILTER_DOMAIN_LOCAL_GROUPS_SE | DsopObjectFilterFlags.DSOP_FILTER_GLOBAL_GROUPS_SE | DsopObjectFilterFlags.DSOP_FILTER_UNIVERSAL_GROUPS_SE | DsopObjectFilterFlags.DSOP_FILTER_USERS | DsopObjectFilterFlags.DSOP_FILTER_WELL_KNOWN_PRINCIPALS; scope.ScopeType = DsopScopeTypeFlags.DSOP_SCOPE_TYPE_ENTERPRISE_DOMAIN | DsopScopeTypeFlags.DSOP_SCOPE_TYPE_USER_ENTERED_UPLEVEL_SCOPE | DsopScopeTypeFlags.DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN; scope.InitInfo = DsopScopeInitInfoFlags.DSOP_SCOPE_FLAG_DEFAULT_FILTER_GROUPS | DsopScopeInitInfoFlags.DSOP_SCOPE_FLAG_STARTING_SCOPE; string target = vm.SelectedForest == domain.Forest.Name ? null : vm.SelectedForest; var result = NativeMethods.ShowObjectPickerDialog(this.GetHandle(), target, scope, "objectClass", "objectSid").FirstOrDefault(); if (result != null) { byte[] sidraw = result.Attributes["objectSid"] as byte[]; if (sidraw == null) { return; } SecurityIdentifierViewModel sidvm = new SecurityIdentifierViewModel(); var sid = new SecurityIdentifier(sidraw, 0); sidvm.Sid = sid.ToString(); if (this.model.AllowedPrincipals.Any(t => string.Equals(t, sidvm.Sid, StringComparison.OrdinalIgnoreCase))) { return; } sidvm.DisplayName = this.GetSidDisplayName(sid); this.model.AllowedPrincipals.Add(sidvm.Sid); this.AllowedPrincipals.Add(sidvm); } } catch (Exception ex) { this.logger.LogError(EventIDs.UIGenericError, ex, "Select group error"); await this.dialogCoordinator.ShowMessageAsync(this, "Error", $"An error occurred when processing the request\r\n{ex.Message}"); } }