Exemplo n.º 1
0
        // Token: 0x060006F3 RID: 1779 RVA: 0x00019DB0 File Offset: 0x00017FB0
        internal static string GetRemoteServerForADUser(ADUser user, Task.TaskVerboseLoggingDelegate writeVerbose, out int serverVersion)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            string result = null;

            serverVersion = Server.E15MinVersion;
            BackEndServer backEndServer = null;
            Exception     ex            = null;

            try
            {
                backEndServer = BackEndLocator.GetBackEndServer(user);
            }
            catch (Exception ex2)
            {
                ex = ex2;
            }
            if (backEndServer == null)
            {
                if (writeVerbose != null)
                {
                    writeVerbose(Strings.VerboseCannotGetRemoteServerForUser(user.Id.ToString(), user.PrimarySmtpAddress.ToString(), (ex == null) ? "" : ex.ToString()));
                }
                return(null);
            }
            serverVersion = backEndServer.Version;
            if (serverVersion < Server.E15MinVersion)
            {
                Uri uri = null;
                try
                {
                    uri = BackEndLocator.GetBackEndWebServicesUrl(user);
                }
                catch (Exception ex3)
                {
                    ex = ex3;
                }
                if (uri != null)
                {
                    result = uri.DnsSafeHost;
                }
                else if (writeVerbose != null)
                {
                    writeVerbose(Strings.VerboseCannotGetRemoteServiceUriForUser(user.Id.ToString(), user.PrimarySmtpAddress.ToString(), (ex == null) ? "" : ex.ToString()));
                }
            }
            else
            {
                result = backEndServer.Fqdn;
            }
            return(result);
        }
Exemplo n.º 2
0
 public static bool IsKnownExceptionHandler(Exception exception, Task.TaskVerboseLoggingDelegate writeVerbose)
 {
     if (exception is MapiRetryableException || exception is MapiPermanentException)
     {
         return(true);
     }
     if (exception is MailboxReplicationPermanentException || exception is MailboxReplicationTransientException || exception is ConfigurationSettingsException)
     {
         writeVerbose(CommonUtils.FullExceptionMessage(exception));
         return(true);
     }
     return(false);
 }
Exemplo n.º 3
0
        private static void SetAces(Task.TaskVerboseLoggingDelegate verboseLogger, Task.TaskWarningLoggingDelegate warningLogger, Task.ErrorLoggerDelegate errorLogger, ADObject obj, bool remove, params ActiveDirectoryAccessRule[] aces)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            RawSecurityDescriptor rawSecurityDescriptor = obj.ReadSecurityDescriptor();

            rawSecurityDescriptor = DirectoryCommon.ApplyAcesOnSd(verboseLogger, warningLogger, errorLogger, obj.Id, rawSecurityDescriptor, remove, aces);
            if (rawSecurityDescriptor != null)
            {
                obj.SaveSecurityDescriptor(rawSecurityDescriptor);
            }
        }
        internal static DatabaseCopy GetDatabaseCopyOfPreference1(Task.TaskVerboseLoggingDelegate writeVerbose, Database owningDatabase, DatabaseCopy databaseCopy)
        {
            DatabaseCopy databaseCopy2 = null;

            KeyValuePair <ADObjectId, int>[] activationPreference = owningDatabase.ActivationPreference;
            ADObjectId highestpriority = activationPreference.FirstOrDefault((KeyValuePair <ADObjectId, int> kvp) => !kvp.Key.Equals(databaseCopy.Id)).Key;

            if (highestpriority != null)
            {
                databaseCopy2 = owningDatabase.DatabaseCopies.FirstOrDefault((DatabaseCopy dbCopy) => dbCopy.HostServer.Equals(highestpriority));
                writeVerbose(Strings.OtherDatabaseCopyHasHighestPreference(databaseCopy2.Name));
            }
            return(databaseCopy2);
        }
Exemplo n.º 5
0
        private static RawSecurityDescriptor ApplyAcesOnSd(Task.TaskVerboseLoggingDelegate verboseLogger, Task.TaskWarningLoggingDelegate warningLogger, Task.ErrorLoggerDelegate errorLogger, ADObjectId id, RawSecurityDescriptor rsd, bool remove, params ActiveDirectoryAccessRule[] aces)
        {
            if (rsd == null)
            {
                throw new SecurityDescriptorAccessDeniedException(id.DistinguishedName);
            }
            ActiveDirectorySecurity activeDirectorySecurity = new ActiveDirectorySecurity();

            byte[] array = new byte[rsd.BinaryLength];
            rsd.GetBinaryForm(array, 0);
            activeDirectorySecurity.SetSecurityDescriptorBinaryForm(array);
            if (DirectoryCommon.ApplyAcesOnAcl(verboseLogger, warningLogger, errorLogger, id.DistinguishedName, activeDirectorySecurity, remove, aces))
            {
                return(new RawSecurityDescriptor(activeDirectorySecurity.GetSecurityDescriptorBinaryForm(), 0));
            }
            return(null);
        }
Exemplo n.º 6
0
 public AutoDiscoverClient(string componentId, Task.TaskVerboseLoggingDelegate verbose, CredentialsImpersonator credentialsImpersonator, string emailAddress, string url, bool reportErrors, params string[] optionalHeaders)
 {
     this.verboseDelegate         = verbose;
     this.credentialsImpersonator = credentialsImpersonator;
     this.url          = url;
     this.emailAddress = emailAddress;
     this.reportErrors = reportErrors;
     this.componentId  = componentId;
     if (optionalHeaders.Length % 2 != 0)
     {
         throw new ArgumentException("optionalHeaders");
     }
     this.additionalHeaders = new Dictionary <string, string>();
     for (int i = 0; i < optionalHeaders.Length; i += 2)
     {
         this.additionalHeaders.Add(optionalHeaders[i], optionalHeaders[i + 1]);
     }
 }
        // Token: 0x06000DE9 RID: 3561 RVA: 0x0002993C File Offset: 0x00027B3C
        internal static string GetFriendlyUserName(IdentityReference sid, Task.TaskVerboseLoggingDelegate verboseLogger)
        {
            if (null == sid)
            {
                throw new ArgumentNullException("sid");
            }
            string result;

            try
            {
                result = sid.Translate(typeof(NTAccount)).ToString();
            }
            catch (IdentityNotMappedException ex)
            {
                TaskLogger.Trace("Couldn't resolve the following sid '{0}': {1}", new object[]
                {
                    sid.ToString(),
                    ex.Message
                });
                if (verboseLogger != null)
                {
                    verboseLogger(Strings.VerboseCannotResolveSid(sid.ToString(), ex.Message));
                }
                result = sid.ToString();
            }
            catch (SystemException ex2)
            {
                TaskLogger.Trace("Couldn't resolve the following sid '{0}': {1}", new object[]
                {
                    sid.ToString(),
                    ex2.Message
                });
                if (verboseLogger != null)
                {
                    verboseLogger(Strings.VerboseCannotResolveSid(sid.ToString(), ex2.Message));
                }
                result = sid.ToString();
            }
            return(result);
        }
Exemplo n.º 8
0
        private static void SetAces(Task.TaskVerboseLoggingDelegate verboseLogger, Task.TaskWarningLoggingDelegate warningLogger, Task.ErrorLoggerDelegate errorLogger, IDirectorySession session, ADObjectId id, bool remove, params ActiveDirectoryAccessRule[] aces)
        {
            if (verboseLogger != null)
            {
                verboseLogger(Strings.InfoSetAces(id.DistinguishedName));
            }
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            RawSecurityDescriptor rawSecurityDescriptor = session.ReadSecurityDescriptor(id);

            rawSecurityDescriptor = DirectoryCommon.ApplyAcesOnSd(verboseLogger, warningLogger, errorLogger, id, rawSecurityDescriptor, remove, aces);
            if (rawSecurityDescriptor != null)
            {
                session.SaveSecurityDescriptor(id, rawSecurityDescriptor);
            }
        }
Exemplo n.º 9
0
        public static ActiveDirectorySecurity ReadMailboxSecurityDescriptor(ADUser mailbox, IConfigurationSession adSession, Task.TaskVerboseLoggingDelegate logVerbose, Task.ErrorLoggerDelegate logError)
        {
            TaskLogger.LogEnter();
            RawSecurityDescriptor exchangeSecurityDescriptor = mailbox.ExchangeSecurityDescriptor;
            RawSecurityDescriptor rawSecurityDescriptor;

            if (mailbox.RecipientType == RecipientType.SystemAttendantMailbox)
            {
                rawSecurityDescriptor = exchangeSecurityDescriptor;
            }
            else
            {
                RawSecurityDescriptor rawSecurityDescriptor2 = adSession.ReadSecurityDescriptor(mailbox.Database);
                if (rawSecurityDescriptor2 == null)
                {
                    logError(new TaskInvalidOperationException(Strings.ErrorReadDatabaseSecurityDescriptor(mailbox.Database.ToString())), ExchangeErrorCategory.ServerOperation, null);
                    return(null);
                }
                rawSecurityDescriptor = MailboxSecurity.CreateMailboxSecurityDescriptor(SecurityDescriptor.FromRawSecurityDescriptor(rawSecurityDescriptor2), SecurityDescriptor.FromRawSecurityDescriptor(exchangeSecurityDescriptor)).ToRawSecurityDescriptor();
                if (rawSecurityDescriptor == null)
                {
                    logError(new TaskInvalidOperationException(Strings.ErrorReadMailboxSecurityDescriptor(mailbox.DistinguishedName)), ExchangeErrorCategory.ServerOperation, mailbox.Identity);
                    return(null);
                }
            }
            ActiveDirectorySecurity result = SecurityDescriptorConverter.ConvertToActiveDirectorySecurity(rawSecurityDescriptor);

            TaskLogger.LogExit();
            return(result);
        }
Exemplo n.º 10
0
 public static void SetDelegation(ADUser principalUser, ADRecipient delegateRecipient, IConfigDataProvider writableAdSession, Task.TaskVerboseLoggingDelegate verboseLogger, bool remove)
 {
     if (!principalUser.ExchangeVersion.IsOlderThan(ADMailboxRecipientSchema.DelegateListLink.VersionAdded))
     {
         LocalizedString message;
         if (remove)
         {
             if (principalUser.DelegateListLink.Contains(delegateRecipient.Id))
             {
                 principalUser.DelegateListLink.Remove(delegateRecipient.Id);
                 writableAdSession.Save(principalUser);
                 message = Strings.VerboseMailboxDelegateRemoved(delegateRecipient.ToString(), principalUser.ToString());
             }
             else
             {
                 message = Strings.VerboseMailboxDelegateNotExits(delegateRecipient.ToString(), principalUser.ToString());
             }
         }
         else if (!principalUser.DelegateListLink.Contains(delegateRecipient.Id))
         {
             principalUser.DelegateListLink.Add(delegateRecipient.Id);
             writableAdSession.Save(principalUser);
             message = Strings.VerboseMailboxDelegateAdded(delegateRecipient.ToString(), principalUser.ToString());
         }
         else
         {
             message = Strings.VerboseMailboxDelegateAlreadyExists(delegateRecipient.ToString(), principalUser.ToString());
         }
         verboseLogger(message);
     }
 }
Exemplo n.º 11
0
 private static void SaveAdSecurityDescriptor(ADUser mailbox, IConfigDataProvider writableAdSession, RawSecurityDescriptor rawSd, Task.TaskVerboseLoggingDelegate logVerbose, Task.ErrorLoggerDelegate logError)
 {
     if (writableAdSession != null)
     {
         ADUser aduser = mailbox;
         if (mailbox.IsReadOnly)
         {
             aduser = (ADUser)writableAdSession.Read <ADUser>(mailbox.Id);
         }
         if (aduser != null)
         {
             aduser.ExchangeSecurityDescriptor = rawSd;
             logVerbose(Strings.VerboseSaveADSecurityDescriptor(aduser.Id.ToString()));
             writableAdSession.Save(aduser);
             return;
         }
         logError(new DirectoryObjectNotFoundException(mailbox.Id.DistinguishedName), ExchangeErrorCategory.ServerOperation, null);
     }
 }
Exemplo n.º 12
0
        private static string GetUrlFromScp(ITopologyConfigurationSession configSession, string domainName, Task.TaskVerboseLoggingDelegate verboseDelegate)
        {
            QueryFilter filter = ExchangeScpObjects.AutodiscoverUrlKeyword.Filter;

            IConfigurable[] array = configSession.Find <ADServiceConnectionPoint>(filter, null, true, null);
            string          empty = string.Empty;

            if (array != null && array.Length > 0)
            {
                string item = "Domain=" + domainName;
                ADServiceConnectionPoint adserviceConnectionPoint = null;
                foreach (IConfigurable configurable in array)
                {
                    ADServiceConnectionPoint adserviceConnectionPoint2 = configurable as ADServiceConnectionPoint;
                    if (adserviceConnectionPoint2.Keywords.Contains("67661d7F-8FC4-4fa7-BFAC-E1D7794C1F68") && AutoDiscoverHelper.IsE14OrLater(configSession, adserviceConnectionPoint2))
                    {
                        verboseDelegate(Strings.TowsFoundScpByDomain(adserviceConnectionPoint2.Identity.ToString(), domainName, adserviceConnectionPoint2.ServiceBindingInformation[0]));
                        if (adserviceConnectionPoint2.Keywords.Contains(item))
                        {
                            return(adserviceConnectionPoint2.ServiceBindingInformation[0]);
                        }
                    }
                    else if (adserviceConnectionPoint2.Keywords.Count == 1 && adserviceConnectionPoint == null)
                    {
                        adserviceConnectionPoint = adserviceConnectionPoint2;
                    }
                }
                string siteName = NativeHelpers.GetSiteName(false);
                string item2    = "Site=" + siteName;
                ADServiceConnectionPoint adserviceConnectionPoint3 = null;
                foreach (IConfigurable configurable2 in array)
                {
                    ADServiceConnectionPoint adserviceConnectionPoint4 = configurable2 as ADServiceConnectionPoint;
                    if (adserviceConnectionPoint4.Keywords.Contains("77378F46-2C66-4aa9-A6A6-3E7A48B19596") && adserviceConnectionPoint4.Keywords.Contains(item2) && AutoDiscoverHelper.IsE14OrLater(configSession, adserviceConnectionPoint4))
                    {
                        verboseDelegate(Strings.TowsFoundScpBySite(adserviceConnectionPoint4.Identity.ToString(), siteName, adserviceConnectionPoint4.ServiceBindingInformation[0]));
                        return(adserviceConnectionPoint4.ServiceBindingInformation[0]);
                    }
                    if (adserviceConnectionPoint3 == null)
                    {
                        adserviceConnectionPoint3 = adserviceConnectionPoint4;
                    }
                }
                if (adserviceConnectionPoint3 != null)
                {
                    return(adserviceConnectionPoint3.ServiceBindingInformation[0]);
                }
                if (adserviceConnectionPoint != null)
                {
                    return(adserviceConnectionPoint.ServiceBindingInformation[0]);
                }
            }
            return(null);
        }
Exemplo n.º 13
0
        public static void DiscoverBegin(string componentId, string emailAddress, CredentialsImpersonator credentialsImpersonator, ITopologyConfigurationSession configSession, Task.TaskVerboseLoggingDelegate verboseDelegate, AsyncCallback asyncCallback, params string[] optionalHeaders)
        {
            if (string.IsNullOrEmpty(componentId))
            {
                throw new ArgumentNullException("componentId");
            }
            if (string.IsNullOrEmpty(emailAddress))
            {
                throw new ArgumentNullException("emailAddress");
            }
            if (credentialsImpersonator == null)
            {
                throw new ArgumentNullException("credentialsImpersonator");
            }
            if (configSession == null)
            {
                throw new ArgumentNullException("configSession");
            }
            if (configSession == null)
            {
                throw new ArgumentNullException("verboseDelegate");
            }
            if (asyncCallback == null)
            {
                throw new ArgumentNullException("asyncCallback");
            }
            string autoDiscoverEndpoint = AutoDiscoverHelper.GetAutoDiscoverEndpoint(emailAddress, configSession, verboseDelegate);

            verboseDelegate(Strings.TowsAutodiscoverUrl(autoDiscoverEndpoint));
            if (!string.IsNullOrEmpty(autoDiscoverEndpoint))
            {
                AutoDiscoverClient autoDiscoverClient = new AutoDiscoverClient(componentId, verboseDelegate, credentialsImpersonator, emailAddress, autoDiscoverEndpoint, true, optionalHeaders);
                autoDiscoverClient.BeginInvoke(asyncCallback);
            }
        }
Exemplo n.º 14
0
        internal static string GenerateUniqueAliasForSiteMailbox(IRecipientSession recipientSession, OrganizationId organizationId, string preferredAlias, string prefix, bool isMicrosoftHostedOnlyDatacenter, Task.TaskVerboseLoggingDelegate logHandler, Task.ErrorLoggerDelegate writeError)
        {
            string text = WindowsLiveIDLocalPartConstraint.RemoveInvalidPartOfWindowsLiveID(preferredAlias);

            if (!string.IsNullOrEmpty(text) && text.Length > 3)
            {
                logHandler(Strings.VerboseGenerateAliasBySiteDisplayName(preferredAlias));
                text = RecipientTaskHelper.GenerateUniqueAlias(recipientSession, organizationId, (!string.IsNullOrEmpty(prefix)) ? (prefix + text) : text, logHandler, 63);
            }
            else
            {
                int num = 1000;
                if (string.IsNullOrEmpty(prefix))
                {
                    prefix = (isMicrosoftHostedOnlyDatacenter ? "SMO-" : "SM-");
                }
                do
                {
                    text = TeamMailboxHelper.GenerateRandomString();
                    text = prefix + text;
                    logHandler(Strings.VerboseGenerateAliasByRandomString(preferredAlias, text));
                    if (RecipientTaskHelper.IsAliasUnique(recipientSession, organizationId, null, text, logHandler, writeError, ExchangeErrorCategory.Client))
                    {
                        break;
                    }
                    text = string.Empty;
                }while (num-- > 0);
            }
            if (string.IsNullOrEmpty(text))
            {
                writeError(new ErrorCannotGenerateSiteMailboxAliasException(), ExchangeErrorCategory.Client, null);
            }
            return(text);
        }
Exemplo n.º 15
0
 public static void SetResolveUsers(AdminAuditLogSearch searchObject, DataAccessHelper.GetDataObjectDelegate getDataObject, Task.TaskVerboseLoggingDelegate writeVerbose, Task.TaskWarningLoggingDelegate writeWarning)
 {
     if (searchObject.UserIdsUserInput != null && searchObject.UserIdsUserInput.Count > 0)
     {
         writeVerbose(Strings.VerboseStartResolvingUsers);
         ADObjectId        rootOrgContainerIdForLocalForest = ADSystemConfigurationSession.GetRootOrgContainerIdForLocalForest();
         ADSessionSettings sessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopes(rootOrgContainerIdForLocalForest, searchObject.OrganizationId, null, false);
         IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.PartiallyConsistent, sessionSettings, 515, "SetResolveUsers", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\AdminAuditLog\\AdminAuditLogHelper.cs");
         tenantOrRootOrgRecipientSession.UseConfigNC = false;
         searchObject.UserIds       = new MultiValuedProperty <string>();
         searchObject.ResolvedUsers = new MultiValuedProperty <string>();
         foreach (SecurityPrincipalIdParameter securityPrincipalIdParameter in searchObject.UserIdsUserInput)
         {
             searchObject.UserIds.Add(securityPrincipalIdParameter.RawIdentity);
             bool flag = false;
             try
             {
                 ADRecipient adrecipient = (ADRecipient)getDataObject(securityPrincipalIdParameter, tenantOrRootOrgRecipientSession, null, null, new LocalizedString?(Strings.WarningSearchUserNotFound(securityPrincipalIdParameter.ToString())), new LocalizedString?(Strings.ErrorSearchUserNotUnique(securityPrincipalIdParameter.ToString())));
                 if (adrecipient.Id != null && adrecipient.Id.DomainId != null && !string.IsNullOrEmpty(adrecipient.Id.DomainId.Name))
                 {
                     string text = (string)adrecipient.propertyBag[IADSecurityPrincipalSchema.SamAccountName];
                     if (!string.IsNullOrEmpty(text))
                     {
                         searchObject.ResolvedUsers.Add(adrecipient.Id.DomainId.Name + "\\" + text);
                         flag = true;
                         writeVerbose(Strings.DebugResolvingDomainAccount(securityPrincipalIdParameter.ToString(), adrecipient.Id.DomainId.Name, text));
                     }
                 }
                 if (adrecipient.propertyBag[IADSecurityPrincipalSchema.Sid] != null)
                 {
                     string value = ((SecurityIdentifier)adrecipient.propertyBag[IADSecurityPrincipalSchema.Sid]).Value;
                     if (!string.IsNullOrEmpty(value))
                     {
                         searchObject.ResolvedUsers.Add(value);
                         flag = true;
                         writeVerbose(Strings.DebugResolvingUserSid(securityPrincipalIdParameter.ToString(), value));
                     }
                 }
                 if (adrecipient.Id != null && !string.IsNullOrEmpty(adrecipient.Id.ToString()))
                 {
                     searchObject.ResolvedUsers.Add(adrecipient.Id.ToString());
                     flag = true;
                     writeVerbose(Strings.DebugResolvingUserCN(securityPrincipalIdParameter.ToString(), adrecipient.Id.ToString()));
                 }
                 if (!flag)
                 {
                     writeWarning(Strings.WarningCannotResolveUser(securityPrincipalIdParameter.ToString()));
                     searchObject.ResolvedUsers.Add(securityPrincipalIdParameter.ToString());
                 }
             }
             catch (ManagementObjectNotFoundException)
             {
                 writeWarning(Strings.WarningSearchUserNotFound(securityPrincipalIdParameter.ToString()));
                 searchObject.ResolvedUsers.Add(securityPrincipalIdParameter.ToString());
             }
         }
     }
 }
Exemplo n.º 16
0
        internal static MailboxData DiscoverTestMailbox(IIdentityParameter identity, IRecipientSession adSession, ADServerSettings serverSettings, DataAccessHelper.CategorizedGetDataObjectDelegate getDataObject, Task.TaskVerboseLoggingDelegate writeVerbose, Task.ErrorLoggerDelegate writeError)
        {
            if (identity == null)
            {
                MigrationADProvider migrationADProvider = new MigrationADProvider(adSession);
                return(migrationADProvider.GetMailboxDataForManagementMailbox());
            }
            ADUser      aduser      = RequestTaskHelper.ResolveADUser(adSession, adSession, serverSettings, identity, null, null, getDataObject, writeVerbose, writeError, true);
            MailboxData mailboxData = new MailboxData(aduser.ExchangeGuid, new Fqdn(aduser.ServerName), aduser.LegacyExchangeDN, aduser.Id, aduser.ExchangeObjectId);

            mailboxData.Update(identity.RawIdentity, aduser.OrganizationId);
            return(mailboxData);
        }
Exemplo n.º 17
0
        internal static MailboxData DiscoverPublicFolderTestMailbox(IIdentityParameter identity, IConfigurationSession configurationSession, IRecipientSession recipientSession, ADServerSettings serverSettings, DataAccessHelper.CategorizedGetDataObjectDelegate getDataObject, Task.TaskVerboseLoggingDelegate writeVerbose, Task.ErrorLoggerDelegate writeError)
        {
            if (identity == null)
            {
                Organization orgContainer = configurationSession.GetOrgContainer();
                if (orgContainer.DefaultPublicFolderMailbox.HierarchyMailboxGuid != default(Guid))
                {
                    identity = new MailboxIdParameter(orgContainer.DefaultPublicFolderMailbox.HierarchyMailboxGuid.ToString());
                }
                else
                {
                    writeError(new MigrationPermanentException(Strings.ErrorUnableToFindValidPublicFolderMailbox), ExchangeErrorCategory.Client, null);
                }
            }
            ADUser aduser = RequestTaskHelper.ResolveADUser(recipientSession, recipientSession, serverSettings, identity, new OptionalIdentityData(), null, getDataObject, writeVerbose, writeError, true);

            if (aduser.RecipientTypeDetails != RecipientTypeDetails.PublicFolderMailbox)
            {
                writeError(new MigrationPermanentException(Strings.ErrorNotPublicFolderMailbox(identity.RawIdentity)), ExchangeErrorCategory.Client, null);
            }
            return(MailboxData.CreateFromADUser(aduser));
        }
Exemplo n.º 18
0
 internal ClientAccessArrayTaskHelper(Task.TaskVerboseLoggingDelegate writeVerbose, Task.TaskErrorLoggingDelegate writeError)
 {
     this.writeVerbose = writeVerbose;
     this.writeError   = writeError;
 }
Exemplo n.º 19
0
 private static void XCopyEntireFoldersWithOverwrite(string fromFolder, string toFolder, Task.TaskVerboseLoggingDelegate logger)
 {
     if (string.IsNullOrEmpty(fromFolder))
     {
         throw new ArgumentNullException("fromFolder");
     }
     if (string.IsNullOrEmpty(toFolder))
     {
         throw new ArgumentNullException("toFolder");
     }
     if (logger == null)
     {
         throw new ArgumentNullException("logger");
     }
     logger(Strings.VerboseCopyDirectory("localhost", fromFolder, toFolder));
     if (!Directory.Exists(fromFolder))
     {
         return;
     }
     if (!Directory.Exists(toFolder))
     {
         logger(Strings.VerboseCreateDirectory("localhost", toFolder));
         Directory.CreateDirectory(toFolder);
     }
     foreach (string text in Directory.GetFiles(fromFolder))
     {
         string text2 = Path.Combine(toFolder, Path.GetFileName(text));
         logger(Strings.VerboseCopyFile("localhost", text, text2));
         File.Copy(text, text2, true);
     }
     foreach (string text3 in Directory.GetDirectories(fromFolder))
     {
         string toFolder2 = Path.Combine(toFolder, Path.GetFileName(text3));
         UpdateOwaVirtualDirectory.XCopyEntireFoldersWithOverwrite(text3, toFolder2, logger);
     }
 }
Exemplo n.º 20
0
 public VerboseObjectErrorReporter(Task.TaskVerboseLoggingDelegate verboseLoggingDelegate)
 {
     this.verboseLoggingDelegate = verboseLoggingDelegate;
 }
Exemplo n.º 21
0
        public static string GetAutoDiscoverEndpoint(string emailAddress, ITopologyConfigurationSession configSession, Task.TaskVerboseLoggingDelegate verboseDelegate)
        {
            if (string.IsNullOrEmpty(emailAddress))
            {
                throw new ArgumentNullException("emailAddress");
            }
            if (configSession == null)
            {
                throw new ArgumentNullException("configSession");
            }
            if (verboseDelegate == null)
            {
                throw new ArgumentNullException("verboseDelegate");
            }
            SmtpAddress smtpAddress = new SmtpAddress(emailAddress);
            string      domain      = smtpAddress.Domain;
            string      text        = AutoDiscoverHelper.GetUrlFromScp(configSession, domain, verboseDelegate);

            if (!string.IsNullOrEmpty(text) && text.StartsWith("LDAP", StringComparison.OrdinalIgnoreCase))
            {
                verboseDelegate(Strings.TowsXForest(emailAddress, text));
                text = null;
            }
            string text2 = "AutoDiscover." + domain;

            if (string.IsNullOrEmpty(text) && AutoDiscoverHelper.ValidateDns(text2))
            {
                text = string.Format("https://{0}/AutoDiscover/AutoDiscover.xml", text2);
            }
            if (string.IsNullOrEmpty(text) && AutoDiscoverHelper.ValidateDns(domain))
            {
                text = string.Format("https://{0}/AutoDiscover/AutoDiscover.xml", domain);
            }
            return(text);
        }
Exemplo n.º 22
0
        internal static object ConvertPSObjectToOriginalType(PSObject psObject, int remoteServerVersion, Task.TaskVerboseLoggingDelegate writeVerbose)
        {
            if (psObject == null)
            {
                throw new ArgumentNullException("psObject");
            }
            Type type = MonadCommand.ResolveType(psObject);

            if (remoteServerVersion >= Server.E15MinVersion)
            {
                if (psObject.Members["SerializationData"] == null || psObject.Members["SerializationData"].Value == null)
                {
                    if (writeVerbose != null)
                    {
                        writeVerbose(Strings.VerboseSerializationDataNotExist);
                    }
                }
                else
                {
                    try
                    {
                        return(ProxyHelper.TypeConvertor.ConvertFrom(psObject, type, null, true));
                    }
                    catch (Exception ex)
                    {
                        if (writeVerbose != null)
                        {
                            writeVerbose(Strings.VerboseFailedToDeserializePSObject(ex.Message));
                        }
                    }
                }
            }
            return(MockObjectInformation.TranslateToMockObject(type, psObject));
        }
Exemplo n.º 23
0
        private static void SaveArchiveSecurityDescriptor(ADUser mailbox, IConfigDataProvider writableAdSession, RawSecurityDescriptor rawSd, Task.TaskVerboseLoggingDelegate logVerbose, Task.ErrorLoggerDelegate logError)
        {
            ADObjectId adobjectId = mailbox.ArchiveDatabase ?? mailbox.Database;
            MailboxId  mailboxId  = new MailboxId(MapiTaskHelper.ConvertDatabaseADObjectIdToDatabaseId(adobjectId), mailbox.ArchiveGuid);

            try
            {
                ActiveManager        activeManagerInstance = ActiveManager.GetActiveManagerInstance();
                DatabaseLocationInfo serverForDatabase     = activeManagerInstance.GetServerForDatabase(adobjectId.ObjectGuid);
                using (MapiMessageStoreSession mapiMessageStoreSession = new MapiMessageStoreSession(serverForDatabase.ServerLegacyDN, PermissionTaskHelper.CalcuteSystemAttendantMailboxLegacyDistingushName(serverForDatabase.ServerLegacyDN), Fqdn.Parse(serverForDatabase.ServerFqdn)))
                {
                    logVerbose(Strings.VerboseSaveStoreMailboxSecurityDescriptor(mailboxId.ToString(), mapiMessageStoreSession.ServerName));
                    mapiMessageStoreSession.ForceStoreToRefreshMailbox(mailboxId);
                }
            }
            catch (FormatException)
            {
                logError(new TaskInvalidOperationException(Strings.ErrorInvalidServerLegacyDistinguishName(mailbox.DistinguishedName.ToString())), ExchangeErrorCategory.ServerOperation, null);
            }
            catch (Microsoft.Exchange.Data.Mapi.Common.MailboxNotFoundException)
            {
                logVerbose(Strings.VerboseArchiveNotExistInStore(mailbox.Name));
                PermissionTaskHelper.SaveAdSecurityDescriptor(mailbox, writableAdSession, rawSd, logVerbose, logError);
            }
            catch (LocalizedException exception)
            {
                logError(new SetArchivePermissionException(mailbox.Name, exception), ExchangeErrorCategory.ServerOperation, null);
            }
        }
Exemplo n.º 24
0
        internal static string GenerateUniqueRoleAssignmentName(IConfigurationSession configurationSession, ADObjectId orgContainerId, string roleName, string roleAssigneeName, RoleAssignmentDelegationType roleAssignmentDelegationType, Task.TaskVerboseLoggingDelegate writeVerbose)
        {
            if (configurationSession == null)
            {
                throw new ArgumentNullException("configurationSession");
            }
            if (orgContainerId == null)
            {
                throw new ArgumentNullException("orgContainerId");
            }
            string text = roleName + "-" + roleAssigneeName;

            if (roleAssignmentDelegationType != RoleAssignmentDelegationType.Regular)
            {
                text += "-Delegating";
            }
            text = text.Trim();
            if (text.Length > 64)
            {
                text = text.Substring(0, 64).Trim();
            }
            if (writeVerbose == null)
            {
                throw new ArgumentNullException("writeVerbose");
            }
            ADObjectId descendantId = orgContainerId.GetDescendantId(ExchangeRoleAssignment.RdnContainer);
            string     text2        = text;

            if (text2.Length > 61)
            {
                text2 = text2.Substring(0, 61).Trim();
            }
            int num = 1;

            for (;;)
            {
                QueryFilter filter = new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.Name, text);
                writeVerbose(TaskVerboseStringHelper.GetFindDataObjectsVerboseString(configurationSession, typeof(ExchangeRoleAssignment), filter, descendantId, false));
                ExchangeRoleAssignment[] array = configurationSession.Find <ExchangeRoleAssignment>(descendantId, QueryScope.OneLevel, filter, null, 1);
                if (array.Length == 0)
                {
                    break;
                }
                text = text2 + "-" + num.ToString();
                num++;
                if (num >= 100)
                {
                    return(text);
                }
            }
            return(text);
        }
Exemplo n.º 25
0
        public static void SetMailboxAces(ADUser mailbox, IConfigDataProvider writableAdSession, Task.TaskVerboseLoggingDelegate logVerbose, Task.TaskWarningLoggingDelegate logWarning, Task.ErrorLoggerDelegate logError, IConfigurationSession adSession, ref MapiMessageStoreSession storeSession, bool remove, params ActiveDirectoryAccessRule[] aces)
        {
            ActiveDirectorySecurity activeDirectorySecurity = PermissionTaskHelper.ReadMailboxSecurityDescriptor(mailbox, adSession, logVerbose, logError);

            if (activeDirectorySecurity != null)
            {
                DirectoryCommon.ApplyAcesOnAcl(logVerbose, logWarning, null, mailbox.DistinguishedName, activeDirectorySecurity, remove, aces);
                PermissionTaskHelper.SaveMailboxSecurityDescriptor(mailbox, activeDirectorySecurity, writableAdSession, ref storeSession, logVerbose, logError);
            }
        }
Exemplo n.º 26
0
        internal static ADSystemMailbox SaveSystemMailbox(MailboxDatabase mdb, Server owningServer, ADObjectId rootOrgContainerId, ITopologyConfigurationSession configSession, IRecipientSession recipientSession, ADObjectId[] forcedReplicationSites, Task.TaskWarningLoggingDelegate writeWarning, Task.TaskVerboseLoggingDelegate writeVerbose)
        {
            TaskLogger.LogEnter();
            bool               useConfigNC        = configSession.UseConfigNC;
            bool               useGlobalCatalog   = configSession.UseGlobalCatalog;
            string             text               = "SystemMailbox" + mdb.Guid.ToString("B");
            SecurityIdentifier securityIdentifier = new SecurityIdentifier("SY");
            ADSystemMailbox    adsystemMailbox    = new ADSystemMailbox();

            adsystemMailbox.StampPersistableDefaultValues();
            adsystemMailbox.Name        = text;
            adsystemMailbox.DisplayName = text;
            adsystemMailbox.Alias       = text;
            adsystemMailbox.HiddenFromAddressListsEnabled = true;
            adsystemMailbox.Database = mdb.Id;
            if (owningServer == null)
            {
                throw new InvalidOperationException(Strings.ErrorDBOwningServerNotFound(mdb.Identity.ToString()));
            }
            adsystemMailbox.ServerLegacyDN = owningServer.ExchangeLegacyDN;
            adsystemMailbox.ExchangeGuid   = Guid.NewGuid();
            AcceptedDomain defaultAcceptedDomain = configSession.GetDefaultAcceptedDomain();

            if (defaultAcceptedDomain == null || defaultAcceptedDomain.DomainName == null || defaultAcceptedDomain.DomainName.Domain == null)
            {
                throw new ManagementObjectNotFoundException(Strings.ErrorNoDefaultAcceptedDomainFound(mdb.Identity.ToString()));
            }
            adsystemMailbox.EmailAddresses.Add(ProxyAddress.Parse("SMTP:" + adsystemMailbox.Alias + "@" + defaultAcceptedDomain.DomainName.Domain.ToString()));
            adsystemMailbox.WindowsEmailAddress         = adsystemMailbox.PrimarySmtpAddress;
            adsystemMailbox.SendModerationNotifications = TransportModerationNotificationFlags.Never;
            Organization organization = configSession.Read <Organization>(rootOrgContainerId);

            if (organization == null)
            {
                throw new ManagementObjectNotFoundException(Strings.ErrorOrganizationNotFound(rootOrgContainerId.Name));
            }
            string parentLegacyDN = string.Format(CultureInfo.InvariantCulture, "{0}/ou={1}/cn=Recipients", new object[]
            {
                organization.LegacyExchangeDN,
                configSession.GetAdministrativeGroupId().Name
            });

            adsystemMailbox.LegacyExchangeDN = LegacyDN.GenerateLegacyDN(parentLegacyDN, adsystemMailbox);
            ADComputer adcomputer;

            try
            {
                configSession.UseConfigNC      = false;
                configSession.UseGlobalCatalog = true;
                adcomputer = configSession.FindComputerByHostName(owningServer.Name);
            }
            finally
            {
                configSession.UseConfigNC      = useConfigNC;
                configSession.UseGlobalCatalog = useGlobalCatalog;
            }
            if (adcomputer == null)
            {
                throw new ManagementObjectNotFoundException(Strings.ErrorDBOwningServerNotFound(mdb.Identity.ToString()));
            }
            ADObjectId adobjectId = adcomputer.Id.DomainId;

            adobjectId = adobjectId.GetChildId("Microsoft Exchange System Objects");
            adsystemMailbox.SetId(adobjectId.GetChildId(text));
            GenericAce[] aces = new GenericAce[]
            {
                new CommonAce(AceFlags.None, AceQualifier.AccessAllowed, 131075, securityIdentifier, false, null)
            };
            DirectoryCommon.SetAclOnAlternateProperty(adsystemMailbox, aces, ADSystemAttendantMailboxSchema.ExchangeSecurityDescriptor, securityIdentifier, securityIdentifier);
            recipientSession.LinkResolutionServer = mdb.OriginatingServer;
            bool enforceDefaultScope = recipientSession.EnforceDefaultScope;

            try
            {
                writeVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(adsystemMailbox, recipientSession, typeof(ADSystemMailbox)));
                recipientSession.EnforceDefaultScope = false;
                recipientSession.Save(adsystemMailbox);
            }
            catch (ADConstraintViolationException ex)
            {
                IConfigurationSession tenantOrTopologyConfigurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(ex.Server, false, ConsistencyMode.PartiallyConsistent, configSession.SessionSettings, 705, "SaveSystemMailbox", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\database\\NewMailboxDatabase.cs");
                if (!tenantOrTopologyConfigurationSession.ReplicateSingleObjectToTargetDC(mdb, ex.Server))
                {
                    throw;
                }
                writeVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(adsystemMailbox, recipientSession, typeof(ADSystemMailbox)));
                recipientSession.Save(adsystemMailbox);
            }
            finally
            {
                writeVerbose(TaskVerboseStringHelper.GetSourceVerboseString(recipientSession));
                recipientSession.EnforceDefaultScope = enforceDefaultScope;
            }
            if (forcedReplicationSites != null)
            {
                DagTaskHelper.ForceReplication(recipientSession, adsystemMailbox, forcedReplicationSites, mdb.Name, writeWarning, writeVerbose);
            }
            TaskLogger.LogExit();
            return(adsystemMailbox);
        }
Exemplo n.º 27
0
        internal static IConfigurable ResolveDataObject(IConfigDataProvider readOnlySession, IConfigDataProvider readOnlyConfigurationSession, IConfigDataProvider globalCatalogSession, IIdentityParameter identity, DataAccessHelper.GetDataObjectDelegate getDataObjectHandler, Task.TaskVerboseLoggingDelegate logHandler)
        {
            IConfigurable configurable   = null;
            ADObjectId    adobjectId     = null;
            ADObjectId    rootID         = RecipientTaskHelper.IsValidDistinguishedName(identity, out adobjectId) ? adobjectId.Parent : null;
            Exception     innerException = null;

            if (readOnlySession != null)
            {
                try
                {
                    configurable = getDataObjectHandler(identity, readOnlySession, rootID, null, null, new LocalizedString?(Strings.ErrorObjectNotUnique(identity.ToString())));
                }
                catch (ADTransientException ex)
                {
                    innerException = ex;
                    logHandler(Strings.VerboseCannotReadObject(identity.ToString(), readOnlySession.Source, ex.Message));
                }
                catch (ManagementObjectNotFoundException ex2)
                {
                    innerException = ex2;
                    logHandler(Strings.VerboseCannotReadObject(identity.ToString(), readOnlySession.Source, ex2.Message));
                }
            }
            if (configurable == null && readOnlyConfigurationSession != null)
            {
                try
                {
                    configurable = getDataObjectHandler(identity, readOnlyConfigurationSession, rootID, null, null, new LocalizedString?(Strings.ErrorObjectNotUnique(identity.ToString())));
                }
                catch (ADTransientException ex3)
                {
                    innerException = ex3;
                    logHandler(Strings.VerboseCannotReadObject(identity.ToString(), readOnlyConfigurationSession.Source, ex3.Message));
                }
                catch (ManagementObjectNotFoundException ex4)
                {
                    innerException = ex4;
                    logHandler(Strings.VerboseCannotReadObject(identity.ToString(), readOnlyConfigurationSession.Source, ex4.Message));
                }
            }
            if (configurable == null && globalCatalogSession != null)
            {
                try
                {
                    configurable = getDataObjectHandler(identity, globalCatalogSession, rootID, null, null, new LocalizedString?(Strings.ErrorObjectNotUnique(identity.ToString())));
                }
                catch (ADTransientException ex5)
                {
                    innerException = ex5;
                    logHandler(Strings.VerboseCannotReadObject(identity.ToString(), globalCatalogSession.Source, ex5.Message));
                }
                catch (ManagementObjectNotFoundException ex6)
                {
                    innerException = ex6;
                    logHandler(Strings.VerboseCannotReadObject(identity.ToString(), globalCatalogSession.Source, ex6.Message));
                }
            }
            if (configurable == null)
            {
                throw new ManagementObjectNotFoundException(Strings.ErrorObjectNotFound(identity.ToString()), innerException);
            }
            return(configurable);
        }
Exemplo n.º 28
0
 internal static string GetFriendlyNameOfSecurityIdentifier(SecurityIdentifier sid, IRecipientSession session, Task.TaskErrorLoggingDelegate errorLogger, Task.TaskVerboseLoggingDelegate verboseLogger)
 {
     if (!RecipientPermissionTaskHelper.sidToName.ContainsKey(sid))
     {
         ADRecipient adrecipient = (ADRecipient)SecurityPrincipalIdParameter.GetSecurityPrincipal(session, new SecurityPrincipalIdParameter(sid), errorLogger, verboseLogger);
         if (adrecipient != null)
         {
             if (adrecipient.Id != null)
             {
                 RecipientPermissionTaskHelper.sidToName[sid] = adrecipient.Id.ToString();
             }
             else
             {
                 RecipientPermissionTaskHelper.sidToName[sid] = SecurityPrincipalIdParameter.GetFriendlyUserName(sid, verboseLogger);
             }
         }
     }
     return(RecipientPermissionTaskHelper.sidToName[sid]);
 }
Exemplo n.º 29
0
        public static void SaveMailboxSecurityDescriptor(ADUser mailbox, ActiveDirectorySecurity adSecurity, IConfigDataProvider writableAdSession, ref MapiMessageStoreSession storeSession, Task.TaskVerboseLoggingDelegate logVerbose, Task.ErrorLoggerDelegate logError)
        {
            if (writableAdSession == null)
            {
                throw new ArgumentException("writableAdSession");
            }
            RawSecurityDescriptor rawSd = new RawSecurityDescriptor(adSecurity.GetSecurityDescriptorBinaryForm(), 0);

            PermissionTaskHelper.SaveAdSecurityDescriptor(mailbox, writableAdSession, rawSd, logVerbose, logError);
            string text = null;

            try
            {
                ActiveManager        activeManagerInstance = ActiveManager.GetActiveManagerInstance();
                DatabaseLocationInfo serverForDatabase     = activeManagerInstance.GetServerForDatabase(mailbox.Database.ObjectGuid);
                text = serverForDatabase.ServerFqdn;
                if (storeSession == null)
                {
                    storeSession = new MapiMessageStoreSession(serverForDatabase.ServerLegacyDN, PermissionTaskHelper.CalcuteSystemAttendantMailboxLegacyDistingushName(serverForDatabase.ServerLegacyDN), Fqdn.Parse(serverForDatabase.ServerFqdn));
                }
                else
                {
                    storeSession.RedirectServer(serverForDatabase.ServerLegacyDN, Fqdn.Parse(serverForDatabase.ServerFqdn));
                }
                MailboxId mailboxId = new MailboxId(MapiTaskHelper.ConvertDatabaseADObjectIdToDatabaseId(mailbox.Database), mailbox.ExchangeGuid);
                logVerbose(Strings.VerboseSaveStoreMailboxSecurityDescriptor(mailboxId.ToString(), storeSession.ServerName));
                storeSession.Administration.PurgeCachedMailboxObject(mailboxId.MailboxGuid);
            }
            catch (DatabaseNotFoundException)
            {
                logVerbose(Strings.ErrorMailboxDatabaseNotFound(mailbox.Database.ToString()));
            }
            catch (MapiExceptionNetworkError)
            {
                logVerbose(Strings.ErrorFailedToConnectToStore((text != null) ? text : string.Empty));
            }
            catch (FormatException)
            {
                logVerbose(Strings.ErrorInvalidServerLegacyDistinguishName(mailbox.DistinguishedName.ToString()));
            }
            catch (Microsoft.Exchange.Data.Mapi.Common.MailboxNotFoundException)
            {
                logVerbose(Strings.VerboseMailboxNotExistInStore(mailbox.DistinguishedName));
            }
            if (mailbox.HasLocalArchive)
            {
                PermissionTaskHelper.SaveArchiveSecurityDescriptor(mailbox, writableAdSession, rawSd, logVerbose, logError);
            }
        }
Exemplo n.º 30
0
        // Token: 0x06001644 RID: 5700 RVA: 0x00053BE8 File Offset: 0x00051DE8
        private void ProxyCmdletExecution(CmdletProxyInfo cmdletProxyInfo)
        {
            ExAssert.RetailAssert(this.context.ExchangeRunspaceConfig != null, "this.context.ExchangeRunspaceConfig should not be null.");
            string remoteServerFqdn           = cmdletProxyInfo.RemoteServerFqdn;
            int    remoteServerVersion        = cmdletProxyInfo.RemoteServerVersion;
            string friendlyVersionInformation = ProxyHelper.GetFriendlyVersionInformation(remoteServerVersion);

            CmdletProxyInfo.ChangeCmdletProxyParametersDelegate changeCmdletProxyParameters = cmdletProxyInfo.ChangeCmdletProxyParameters;
            if (Microsoft.Exchange.Diagnostics.Components.Tasks.ExTraceGlobals.FaultInjectionTracer.IsTraceEnabled(TraceType.FaultInjection))
            {
                Microsoft.Exchange.Diagnostics.Components.Tasks.ExTraceGlobals.FaultInjectionTracer.TraceTest <string>(3720752445U, ref remoteServerFqdn);
                UserToken userToken = this.context.ExchangeRunspaceConfig.ConfigurationSettings.UserToken;
                ProxyHelper.FaultInjection_UserSid(ref userToken);
                Microsoft.Exchange.Diagnostics.Components.Tasks.ExTraceGlobals.FaultInjectionTracer.TraceTest <int>(3452316989U, ref remoteServerVersion);
            }
            string text = this.GeneratePswsProxyCmdlet(changeCmdletProxyParameters);

            ExchangeRunspaceConfigurationSettings.ProxyMethod proxyMethod = this.DetermineProxyMethod(remoteServerVersion);
            if (this.context.CommandShell != null)
            {
                this.context.CommandShell.WriteVerbose(Strings.VerboseCmdletProxiedToAnotherServer(text, remoteServerFqdn, friendlyVersionInformation, proxyMethod.ToString()));
            }
            Guid uniqueId = this.context.UniqueId;

            CmdletLogger.SafeAppendColumn(uniqueId, RpsCmdletMetadata.CmdletProxyRemoteServer, this.proxiedObjectCount.ToString(), remoteServerFqdn);
            CmdletLogger.SafeAppendColumn(uniqueId, RpsCmdletMetadata.CmdletProxyRemoteServerVersion, this.proxiedObjectCount.ToString(), friendlyVersionInformation.ToString());
            CmdletLogger.SafeAppendColumn(uniqueId, RpsCmdletMetadata.CmdletProxyMethod, this.proxiedObjectCount.ToString(), proxyMethod.ToString());
            try
            {
                IEnumerable <PSObject> enumerable;
                if (proxyMethod == ExchangeRunspaceConfigurationSettings.ProxyMethod.RPS)
                {
                    PSCommand command = this.GenerateProxyCmdlet(changeCmdletProxyParameters);
                    Task.TaskWarningLoggingDelegate writeWarning = null;
                    if (this.context.CommandShell != null)
                    {
                        writeWarning = new Task.TaskWarningLoggingDelegate(this.context.CommandShell.WriteWarning);
                    }
                    enumerable = ProxyHelper.RPSProxyExecution(this.context.UniqueId, command, remoteServerFqdn, this.context.ExchangeRunspaceConfig, remoteServerVersion, cmdletProxyInfo.ShouldAsyncProxy, writeWarning);
                }
                else
                {
                    enumerable = CommandInvocation.Invoke(this.context.UniqueId, ProxyHelper.GetPSWSProxySiteUri(remoteServerFqdn), text, CredentialCache.DefaultNetworkCredentials, ProxyHelper.GetPSWSProxyRequestHeaders(this.context.ExchangeRunspaceConfig), this.context.ExchangeRunspaceConfig.TypeTable);
                }
                foreach (PSObject psobject in enumerable)
                {
                    object sendToPipeline = psobject;
                    if (psobject.BaseObject != null && !(psobject.BaseObject is PSCustomObject))
                    {
                        sendToPipeline = psobject.BaseObject;
                    }
                    else if (this.context.ExchangeRunspaceConfig != null)
                    {
                        if (this.context.ExchangeRunspaceConfig.ConfigurationSettings.ClientApplication != ExchangeRunspaceConfigurationSettings.ExchangeApplication.ECP)
                        {
                            if (this.context.ExchangeRunspaceConfig.ConfigurationSettings.ClientApplication != ExchangeRunspaceConfigurationSettings.ExchangeApplication.OSP)
                            {
                                goto IL_2CB;
                            }
                        }
                        try
                        {
                            Task.TaskVerboseLoggingDelegate writeVerbose = null;
                            if (this.context.CommandShell != null)
                            {
                                writeVerbose = new Task.TaskVerboseLoggingDelegate(this.context.CommandShell.WriteWarning);
                            }
                            sendToPipeline = ProxyHelper.ConvertPSObjectToOriginalType(psobject, remoteServerVersion, writeVerbose);
                        }
                        catch (Exception ex)
                        {
                            CmdletLogger.SafeAppendGenericError(uniqueId, "ConvertPSObjectToOriginalTyp", ex, new Func <Exception, bool>(TaskHelper.IsTaskUnhandledException));
                            Diagnostics.ReportException(ex, Constants.CoreEventLogger, TaskEventLogConstants.Tuple_UnhandledException, null, null, Microsoft.Exchange.Diagnostics.Components.Configuration.Core.ExTraceGlobals.InstrumentationTracer, "Exception from ProxyHelper.ConvertPSObjectToOriginalType : {0}");
                        }
                    }
IL_2CB:
                    if (this.context.CommandShell != null)
                    {
                        this.context.CommandShell.WriteObject(sendToPipeline);
                    }
                }
            }
            catch (Exception ex2)
            {
                CmdletLogger.SafeAppendGenericError(this.context.UniqueId, "ProxyCmdletExecution", ex2, new Func <Exception, bool>(TaskHelper.IsTaskUnhandledException));
                if (this.context.CommandShell != null)
                {
                    this.context.CommandShell.WriteError(new CmdletProxyException(text, remoteServerFqdn, friendlyVersionInformation, proxyMethod.ToString(), ex2.Message), ExchangeErrorCategory.ServerOperation, null);
                }
            }
        }