Пример #1
0
        internal WsatConfiguration(string machineName, string virtualServer, WsatConfiguration previousConfig, bool minimalWrite)
        {
            this.MachineName     = machineName;
            this.minimalWrite    = minimalWrite;
            this.firewallWrapper = new FirewallWrapper();
            this.previousConfig  = previousConfig;
            this.virtualServer   = virtualServer;
            if (previousConfig == null)
            {
                this.allowedCertificates = DefaultX509GlobalAcl;
                this.kerberosGlobalAcl   = DefaultKerberosGlobalAcl;
            }
            else
            {
                CopyConfigurationData(previousConfig, this);
            }

            if (MsdtcClusterUtils.IsClusterServer(MachineName))
            {
                this.hClusterDtcResource = MsdtcClusterUtils.GetTransactionManagerClusterResource(VirtualServer, out clusterNodes);
                if (hClusterDtcResource == null || hClusterDtcResource.IsInvalid)
                {
                    if (!string.IsNullOrEmpty(VirtualServer))
                    {
                        throw new WsatAdminException(WsatAdminErrorCode.CANNOT_FIND_CLUSTER_VIRTUAL_SERVER, SR.GetString(SR.ErrorCanNotFindVirtualServer));
                    }
                }
            }
            InitializeConfigurationProvider();
        }
        static byte[] IssueClusterResourceControl(SafeHResource hResource,
                                                  ClusterResourceControlCode code)
        {
            uint cb = 0;
            uint ret = SafeNativeMethods.ClusterResourceControl(hResource,
                                                                IntPtr.Zero,
                                                                code,
                                                                IntPtr.Zero,
                                                                0,
                                                                null,
                                                                0,
                                                                ref cb);

            if (ret == SafeNativeMethods.ERROR_SUCCESS || ret == SafeNativeMethods.ERROR_MORE_DATA)
            {
                byte[] buffer = new byte[cb];
                ret = SafeNativeMethods.ClusterResourceControl(hResource,
                                                               IntPtr.Zero,
                                                               code,
                                                               IntPtr.Zero,
                                                               0,
                                                               buffer,
                                                               cb,
                                                               ref cb);

                if (ret == SafeNativeMethods.ERROR_SUCCESS)
                {
                    return buffer;
                }
            }

            return null;
        }
        internal WsatConfiguration(string machineName, string virtualServer, WsatConfiguration previousConfig, bool minimalWrite)
        {
            this.MachineName = machineName;
            this.minimalWrite = minimalWrite;
            this.firewallWrapper = new FirewallWrapper();
            this.previousConfig = previousConfig;
            this.virtualServer = virtualServer;
            if (previousConfig == null)
            {
                this.allowedCertificates = DefaultX509GlobalAcl;
                this.kerberosGlobalAcl = DefaultKerberosGlobalAcl;
            }
            else
            {
                CopyConfigurationData(previousConfig, this);
            }

            if (MsdtcClusterUtils.IsClusterServer(MachineName))
            {
                this.hClusterDtcResource = MsdtcClusterUtils.GetTransactionManagerClusterResource(VirtualServer, out clusterNodes);
                if (hClusterDtcResource == null || hClusterDtcResource.IsInvalid)
                {
                    if (!string.IsNullOrEmpty(VirtualServer))
                    {
                        throw new WsatAdminException(WsatAdminErrorCode.CANNOT_FIND_CLUSTER_VIRTUAL_SERVER, SR.GetString(SR.ErrorCanNotFindVirtualServer));
                    }
                }
            }
            InitializeConfigurationProvider();
        }
        static bool IsTransactionManager(SafeHResource hResource)
        {
            Utilities.Log("Entered IsTransactionManager - ");

            string resourceType = GetResourceType(hResource);
            Utilities.Log("Resource type name: " + resourceType);

            return string.CompareOrdinal(resourceType, MsdtcResourceTypeName) == 0;
        }
 internal static extern uint ClusterResourceControl(
     [In] SafeHResource hResource,
     [In] IntPtr hHostNode,  //HNODE hHostNode, never used
     [In] ClusterResourceControlCode dwControlCode,
     [In] IntPtr lpInBuffer, // LPVOID lpInBuffer, never used
     [In] uint cbInBufferSize,
     [In, Out, MarshalAs(UnmanagedType.LPArray)] byte[] buffer,
     [In] uint cbOutBufferSize,
     [In, Out] ref uint lpcbBytesReturned);
        static string IssueClusterResourceControlString(SafeHResource hResource,
                                                        ClusterResourceControlCode code)
        {
            byte[] buffer = IssueClusterResourceControl(hResource, code);
            if (buffer == null)
            {
                return null;
            }

            try
            {
                return Encoding.Unicode.GetString(buffer, 0, buffer.Length - 2);
            }
            catch (ArgumentException)
            {
                return null;
            }
        }
        static string GetResourceNetworkName(SafeHResource hResource)
        {
            // On Vista and above, this API can be called with null and 0 to discover the true length
            // of the return buffer. However, on Win2003 that causes the API to fail with
            // ERROR_DEPENDENCY_NOT_FOUND. To play it safe, we simply pre-allocate a buffer up front
            // that should be enough to catch the two possible cases:
            // - 15-character NetBios names
            // - 63-character DNS labels
            
            uint cch = 64;
            StringBuilder sb = new StringBuilder((int)cch);
#pragma warning suppress 56523
            if (SafeNativeMethods.GetClusterResourceNetworkName(hResource, sb, ref cch))
            {
                return sb.ToString();
            }

            return null;
        }
        internal ClusterRegistryConfigurationProvider(SafeHResource hResource, string key)
        {
            SafeHKey rootKey = SafeNativeMethods.GetClusterResourceKey(hResource,
                                                                       RegistryRights.ReadKey |
                                                                       RegistryRights.EnumerateSubKeys |
                                                                       RegistryRights.QueryValues);

            if (rootKey.IsInvalid)
            {
                int lastError = Marshal.GetLastWin32Error();
                throw new WsatAdminException(WsatAdminErrorCode.REGISTRY_ACCESS, SR.GetString(SR.CannotOpenClusterRegistry, lastError));
            }

            if (string.IsNullOrEmpty(key))
            {
                hKey = rootKey;
            }
            else
            {
                using (rootKey)
                {
                    int disposition;
                    int ret = SafeNativeMethods.ClusterRegCreateKey(rootKey,
                                                                    key,
                                                                    SafeNativeMethods.REG_OPTION_NON_VOLATILE,
                                                                    RegistryRights.FullControl,
                                                                    IntPtr.Zero,
                                                                    out this.hKey,
                                                                    out disposition);
                    if (ret != SafeNativeMethods.ERROR_SUCCESS)
                    {
                        throw new WsatAdminException(WsatAdminErrorCode.REGISTRY_ACCESS, SR.GetString(SR.CannotOpenClusterRegistry, ret));
                    }
                }
            }

            registryExceptionHelper = new RegistryExceptionHelper(key);
            this.registryKey        = key;
            RegistryExceptionHelper.EnsureEndsWithSlash(ref this.registryKey);
        }
Пример #9
0
        static bool GetResourceFromEnumeration(SafeHCluster hCluster,
                                               SafeHClusEnum hEnum,
                                               uint index, out SafeHResource hResource, out string theResourceName)
        {
            uint type, cch = 0;

            hResource       = null;
            theResourceName = string.Empty;

            uint ret = SafeNativeMethods.ClusterEnum(hEnum, index, out type, null, ref cch);

            if (ret == SafeNativeMethods.ERROR_NO_MORE_ITEMS)
            {
                return(false);
            }
            else if (ret == SafeNativeMethods.ERROR_SUCCESS || ret == SafeNativeMethods.ERROR_MORE_DATA)
            {
                StringBuilder sb = new StringBuilder((int)(++cch));
                ret = SafeNativeMethods.ClusterEnum(hEnum, index, out type, sb, ref cch);

                if (ret == SafeNativeMethods.ERROR_SUCCESS)
                {
                    string resourceName = sb.ToString();

#pragma warning suppress 56523
                    hResource = SafeNativeMethods.OpenClusterResource(hCluster, resourceName);
                    if (hResource.IsInvalid)
                    {
                        hResource = null;
                    }
                    else
                    {
                        theResourceName = resourceName;
                    }
                }
            }

            return(true);
        }
        internal ClusterRegistryConfigurationProvider(SafeHResource hResource, string key)
        {            
            SafeHKey rootKey = SafeNativeMethods.GetClusterResourceKey(hResource,
                                                                RegistryRights.ReadKey |
                                                                RegistryRights.EnumerateSubKeys |
                                                                RegistryRights.QueryValues);
            if (rootKey.IsInvalid)
            {
                int lastError = Marshal.GetLastWin32Error();
                throw new WsatAdminException(WsatAdminErrorCode.REGISTRY_ACCESS, SR.GetString(SR.CannotOpenClusterRegistry, lastError));
            }

            if (string.IsNullOrEmpty(key))
            {
                hKey = rootKey;
            }
            else
            {
                using (rootKey)
                {
                    int disposition;
                    int ret = SafeNativeMethods.ClusterRegCreateKey(rootKey,
                                                                    key,
                                                                    SafeNativeMethods.REG_OPTION_NON_VOLATILE,
                                                                    RegistryRights.FullControl,
                                                                    IntPtr.Zero,
                                                                    out this.hKey,
                                                                    out disposition);
                    if (ret != SafeNativeMethods.ERROR_SUCCESS)
                    {
                        throw new WsatAdminException(WsatAdminErrorCode.REGISTRY_ACCESS, SR.GetString(SR.CannotOpenClusterRegistry, ret));
                    }
                }
            }

            registryExceptionHelper = new RegistryExceptionHelper(key);
            this.registryKey = key;
            RegistryExceptionHelper.EnsureEndsWithSlash(ref this.registryKey);
        }
 internal static extern bool GetClusterResourceNetworkName(
     [In] SafeHResource hResource,
     [Out] StringBuilder lpBuffer,
     [In, Out] ref uint nSize);
Пример #12
0
        static string IssueClusterResourceControlString(SafeHResource hResource,
                                                        ClusterResourceControlCode code)
        {
            byte[] buffer = IssueClusterResourceControl(hResource, code);
            if (buffer == null)
            {
                return null;
            }

            try
            {
                return Encoding.Unicode.GetString(buffer, 0, buffer.Length - 2);
            }
            catch (ArgumentException)
            {
                return null;
            }
        }
Пример #13
0
        static byte[] IssueClusterResourceControl(SafeHResource hResource,
                                                  ClusterResourceControlCode code)
        {
            uint cb = 0;
            uint ret = SafeNativeMethods.ClusterResourceControl(hResource,
                                                                IntPtr.Zero,
                                                                code,
                                                                IntPtr.Zero,
                                                                0,
                                                                null,
                                                                0,
                                                                ref cb);

            if (ret == SafeNativeMethods.ERROR_SUCCESS || ret == SafeNativeMethods.ERROR_MORE_DATA)
            {
                byte[] buffer = new byte[cb];
                ret = SafeNativeMethods.ClusterResourceControl(hResource,
                                                               IntPtr.Zero,
                                                               code,
                                                               IntPtr.Zero,
                                                               0,
                                                               buffer,
                                                               cb,
                                                               ref cb);

                if (ret == SafeNativeMethods.ERROR_SUCCESS)
                {
                    return buffer;
                }
            }

            return null;
        }
Пример #14
0
        static bool GetResourceFromEnumeration(SafeHCluster hCluster,
                                               SafeHClusEnum hEnum,
                                               uint index, out SafeHResource hResource, out string theResourceName)
        {
            uint type, cch = 0;
            hResource = null;
            theResourceName = string.Empty;

            uint ret = SafeNativeMethods.ClusterEnum(hEnum, index, out type, null, ref cch);
            if (ret == SafeNativeMethods.ERROR_NO_MORE_ITEMS)
            {
                return false;
            }
            else if (ret == SafeNativeMethods.ERROR_SUCCESS || ret == SafeNativeMethods.ERROR_MORE_DATA)
            {
                StringBuilder sb = new StringBuilder((int)(++cch));
                ret = SafeNativeMethods.ClusterEnum(hEnum, index, out type, sb, ref cch);

                if (ret == SafeNativeMethods.ERROR_SUCCESS)
                {                    
                    string resourceName = sb.ToString();

#pragma warning suppress 56523
                    hResource = SafeNativeMethods.OpenClusterResource(hCluster, resourceName);
                    if (hResource.IsInvalid)
                    {
                        hResource = null;
                    }
                    else
                    {
                        theResourceName = resourceName;
                    }
                }
            }

            return true;
        }
Пример #15
0
        static string GetResourceNetworkName(SafeHResource hResource)
        {
            // On Vista and above, this API can be called with null and 0 to discover the true length
            // of the return buffer. However, on Win2003 that causes the API to fail with
            // ERROR_DEPENDENCY_NOT_FOUND. To play it safe, we simply pre-allocate a buffer up front
            // that should be enough to catch the two possible cases:
            // - 15-character NetBios names
            // - 63-character DNS labels
            
            uint cch = 64;
            StringBuilder sb = new StringBuilder((int)cch);
#pragma warning suppress 56523
            if (SafeNativeMethods.GetClusterResourceNetworkName(hResource, sb, ref cch))
            {
                return sb.ToString();
            }

            return null;
        }
Пример #16
0
 static string GetResourceType(SafeHResource hResource)
 {
     return IssueClusterResourceControlString(hResource, ClusterResourceControlCode.GetResourceType);
 }
Пример #17
0
        static bool IsTransactionManager(SafeHResource hResource)
        {
            Utilities.Log("Entered IsTransactionManager - ");

            string resourceType = GetResourceType(hResource);
            Utilities.Log("Resource type name: " + resourceType);

            return string.CompareOrdinal(resourceType, MsdtcResourceTypeName) == 0;
        }
 internal static extern SafeHKey GetClusterResourceKey(
     [In] SafeHResource hResource,
     [In] RegistryRights samDesired);
 static string GetResourceType(SafeHResource hResource)
 {
     return IssueClusterResourceControlString(hResource, ClusterResourceControlCode.GetResourceType);
 }