internal static void UpdateMetabase(ExchangeWebAppVirtualDirectory webAppVirtualDirectory, string metabasePath, bool enableAnonymous)
 {
     try
     {
         DirectoryEntry directoryEntry2;
         DirectoryEntry directoryEntry = directoryEntry2 = IisUtility.CreateIISDirectoryEntry(webAppVirtualDirectory.MetabasePath);
         try
         {
             ArrayList arrayList = new ArrayList();
             if (webAppVirtualDirectory.DefaultDomain.Length > 0)
             {
                 arrayList.Add(new MetabaseProperty("DefaultLogonDomain", webAppVirtualDirectory.DefaultDomain, true));
             }
             else if (webAppVirtualDirectory.DefaultDomain == "")
             {
                 directoryEntry.Properties["DefaultLogonDomain"].Clear();
             }
             IisUtility.SetProperties(directoryEntry, arrayList);
             directoryEntry.CommitChanges();
             IisUtility.SetAuthenticationMethod(directoryEntry, AuthenticationMethodFlags.None, true);
             IisUtility.SetAuthenticationMethod(directoryEntry, AuthenticationMethodFlags.Basic, webAppVirtualDirectory.BasicAuthentication);
             IisUtility.SetAuthenticationMethod(directoryEntry, AuthenticationMethodFlags.Digest, webAppVirtualDirectory.DigestAuthentication);
             IisUtility.SetAuthenticationMethod(directoryEntry, AuthenticationMethodFlags.WindowsIntegrated, webAppVirtualDirectory.WindowsAuthentication);
             IisUtility.SetAuthenticationMethod(directoryEntry, AuthenticationMethodFlags.LiveIdFba, webAppVirtualDirectory.LiveIdAuthentication);
             if (webAppVirtualDirectory.FormsAuthentication)
             {
                 OwaIsapiFilter.EnableFba(directoryEntry);
             }
             else
             {
                 OwaIsapiFilter.DisableFba(directoryEntry);
             }
             IisUtility.SetAuthenticationMethod(directoryEntry, MetabasePropertyTypes.AuthFlags.Anonymous, enableAnonymous);
             directoryEntry.CommitChanges();
         }
         finally
         {
             if (directoryEntry2 != null)
             {
                 ((IDisposable)directoryEntry2).Dispose();
             }
         }
         GzipLevel gzipLevel = webAppVirtualDirectory.GzipLevel;
         string    site      = IisUtility.WebSiteFromMetabasePath(webAppVirtualDirectory.MetabasePath);
         Gzip.SetIisGzipLevel(site, GzipLevel.High);
         Gzip.SetVirtualDirectoryGzipLevel(webAppVirtualDirectory.MetabasePath, gzipLevel);
     }
     catch (IISGeneralCOMException ex)
     {
         if (ex.Code == -2147023174)
         {
             throw new IISNotReachableException(IisUtility.GetHostName(webAppVirtualDirectory.MetabasePath), ex.Message);
         }
         throw;
     }
 }
Ejemplo n.º 2
0
        public static void CopyDavVdirsToMetabase(string domainController, string exchangeServerName, string metabaseServerName)
        {
            ADSessionSettings             sessionSettings = ADSessionSettings.FromRootOrgScopeSet();
            ITopologyConfigurationSession topologyConfigurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(domainController, true, ConsistencyMode.PartiallyConsistent, null, sessionSettings, 154, "CopyDavVdirsToMetabase", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\VirtualDirectoryTasks\\OWAVirtualDirectoryHelper.cs");
            Server server = topologyConfigurationSession.FindServerByName(exchangeServerName);
            IConfigDataProvider configDataProvider         = topologyConfigurationSession;
            IEnumerable <ADOwaVirtualDirectory> enumerable = configDataProvider.FindPaged <ADOwaVirtualDirectory>(null, server.Id, true, null, 0);

            OwaVirtualDirectoryHelper.SetWebSvcExtRestrictionList(metabaseServerName);
            foreach (ADOwaVirtualDirectory adowaVirtualDirectory in enumerable)
            {
                if (!adowaVirtualDirectory.IsExchange2007OrLater)
                {
                    string[] array = adowaVirtualDirectory.MetabasePath.Split(new char[]
                    {
                        '/'
                    });
                    if (array.Length == 7)
                    {
                        array[2] = metabaseServerName;
                        MultiValuedProperty <AuthenticationMethod> internalAuthenticationMethods = adowaVirtualDirectory.InternalAuthenticationMethods;
                        adowaVirtualDirectory.WindowsAuthentication = true;
                        string appPoolRootPath = IisUtility.GetAppPoolRootPath(metabaseServerName);
                        string text            = "MSExchangeOWAAppPool";
                        if (!IisUtility.Exists(appPoolRootPath, text, "IIsApplicationPool"))
                        {
                            using (DirectoryEntry directoryEntry = IisUtility.CreateApplicationPool(metabaseServerName, text))
                            {
                                IisUtility.SetProperty(directoryEntry, "AppPoolIdentityType", 0, true);
                                directoryEntry.CommitChanges();
                            }
                        }
                        if (!IisUtility.Exists(string.Join("/", array)))
                        {
                            DirectoryEntry directoryEntry2 = IisUtility.CreateWebDirObject(string.Join("/", array, 0, 6), adowaVirtualDirectory.FolderPathname, array[6]);
                            ArrayList      arrayList       = new ArrayList();
                            arrayList.Add(new MetabaseProperty("LogonMethod", MetabasePropertyTypes.LogonMethod.ClearTextLogon));
                            arrayList.Add(new MetabaseProperty("AccessFlags", MetabasePropertyTypes.AccessFlags.Read | MetabasePropertyTypes.AccessFlags.Write | MetabasePropertyTypes.AccessFlags.Source | MetabasePropertyTypes.AccessFlags.Script));
                            arrayList.Add(new MetabaseProperty("DirBrowseFlags", (MetabasePropertyTypes.DirBrowseFlags) 3221225534U));
                            arrayList.Add(new MetabaseProperty("ScriptMaps", OwaVirtualDirectoryHelper.GetDavScriptMaps(), true));
                            if (adowaVirtualDirectory.VirtualDirectoryType == VirtualDirectoryTypes.Exchweb)
                            {
                                arrayList.Add(new MetabaseProperty("HttpExpires", "D, 0x278d00"));
                            }
                            if (adowaVirtualDirectory.DefaultDomain.Length > 0)
                            {
                                arrayList.Add(new MetabaseProperty("DefaultLogonDomain", adowaVirtualDirectory.DefaultDomain, true));
                            }
                            OwaIsapiFilter.DisableFba(directoryEntry2);
                            uint num = 0U;
                            using (MultiValuedProperty <AuthenticationMethod> .Enumerator enumerator2 = adowaVirtualDirectory.InternalAuthenticationMethods.GetEnumerator())
                            {
                                while (enumerator2.MoveNext())
                                {
                                    switch (enumerator2.Current)
                                    {
                                    case AuthenticationMethod.Basic:
                                        num |= 2U;
                                        break;

                                    case AuthenticationMethod.Digest:
                                        num |= 16U;
                                        break;

                                    case AuthenticationMethod.Ntlm:
                                        num |= 4U;
                                        break;

                                    case AuthenticationMethod.Fba:
                                        OwaIsapiFilter.EnableFba(directoryEntry2);
                                        break;
                                    }
                                }
                            }
                            arrayList.Add(new MetabaseProperty("AuthFlags", num, true));
                            IisUtility.SetProperties(directoryEntry2, arrayList);
                            IisUtility.AssignApplicationPool(directoryEntry2, text);
                        }
                    }
                }
            }
        }