예제 #1
0
        private void DisableClientSideSettings()
        {
            WSManHelper   helper       = new WSManHelper(this);
            IWSManSession m_SessionObj = CreateWSManSession();

            if (m_SessionObj is null)
            {
                return;
            }

            try
            {
                string      result      = m_SessionObj.Get(helper.CredSSP_RUri, 0);
                XmlDocument resultopxml = new XmlDocument();
                string      inputXml    = null;
                resultopxml.LoadXml(result);
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(resultopxml.NameTable);
                nsmgr.AddNamespace("cfg", helper.CredSSP_XMLNmsp);
                XmlNode xNode = resultopxml.SelectSingleNode(helper.CredSSP_SNode, nsmgr);
                if (!(xNode is null))
                {
                    inputXml = @"<cfg:Auth xmlns:cfg=""http://schemas.microsoft.com/wbem/wsman/1/config/client/auth""><cfg:CredSSP>false</cfg:CredSSP></cfg:Auth>";
                }
                else
                {
                    InvalidOperationException ex = new InvalidOperationException();
                    ErrorRecord er = new ErrorRecord(ex, helper.GetResourceMsgFromResourcetext("WinrmNotConfigured"), ErrorCategory.InvalidOperation, null);
                    WriteError(er);
                    return;
                }

                m_SessionObj.Put(helper.CredSSP_RUri, inputXml, 0);

                if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
                {
                    this.DeleteUserDelegateSettings();
                }
                else
                {
                    ThreadStart start  = new ThreadStart(this.DeleteUserDelegateSettings);
                    Thread      thread = new Thread(start);
                    thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();
                    thread.Join();
                }

                if (!helper.ValidateCreadSSPRegistryRetry(false, null, applicationname))
                {
                    helper.AssertError(helper.GetResourceMsgFromResourcetext("DisableCredSSPPolicyValidateError"), false, null);
                }
            }
예제 #2
0
        /// <summary>
        /// </summary>
        /// <exception cref="InvalidOperationException">
        /// </exception>
        private void EnableClientSideSettings()
        {
            string query   = helper.GetResourceMsgFromResourcetext("CredSSPContinueQuery");
            string caption = helper.GetResourceMsgFromResourcetext("CredSSPContinueCaption");

            if (!force && !ShouldContinue(query, caption))
            {
                return;
            }

            IWSManSession m_SessionObj = CreateWSManSession();

            if (m_SessionObj == null)
            {
                return;
            }

            try
            {
                // get the credssp node to check if wsman is configured on this machine
                string  result = m_SessionObj.Get(helper.CredSSP_RUri, 0);
                XmlNode node   = helper.GetXmlNode(result, helper.CredSSP_SNode, helper.CredSSP_XMLNmsp);

                if (node == null)
                {
                    InvalidOperationException ex = new InvalidOperationException();
                    ErrorRecord er = new ErrorRecord(ex, helper.GetResourceMsgFromResourcetext("WinrmNotConfigured"), ErrorCategory.InvalidOperation, null);
                    WriteError(er);
                    return;
                }

                const string newxmlcontent = @"<cfg:Auth xmlns:cfg=""http://schemas.microsoft.com/wbem/wsman/1/config/client/auth""><cfg:CredSSP>true</cfg:CredSSP></cfg:Auth>";
                try
                {
                    XmlDocument xmldoc = new XmlDocument();
                    // push the xml string with credssp enabled
                    xmldoc.LoadXml(m_SessionObj.Put(helper.CredSSP_RUri, newxmlcontent, 0));

                    // set the Registry using GroupPolicyObject
                    if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
                    {
                        this.UpdateCurrentUserRegistrySettings();
                    }
                    else
                    {
                        ThreadStart start  = new ThreadStart(this.UpdateCurrentUserRegistrySettings);
                        Thread      thread = new Thread(start);
                        thread.SetApartmentState(ApartmentState.STA);
                        thread.Start();
                        thread.Join();
                    }

                    if (helper.ValidateCreadSSPRegistryRetry(true, delegatecomputer, applicationname))
                    {
                        WriteObject(xmldoc.FirstChild);
                    }
                    else
                    {
                        helper.AssertError(helper.GetResourceMsgFromResourcetext("EnableCredSSPPolicyValidateError"), false, delegatecomputer);
                    }
                }
                catch (COMException)
                {
                    helper.AssertError(m_SessionObj.Error, true, delegatecomputer);
                }
            }
            finally
            {
                if (!string.IsNullOrEmpty(m_SessionObj.Error))
                {
                    helper.AssertError(m_SessionObj.Error, true, delegatecomputer);
                }

                if (m_SessionObj != null)
                {
                    Dispose(m_SessionObj);
                }
            }
        }
예제 #3
0
파일: CredSSP.cs 프로젝트: 40a/PowerShell
        private void DisableClientSideSettings()
        {
            WSManHelper helper = new WSManHelper(this);
            IWSManSession m_SessionObj = CreateWSManSession();
            if (null == m_SessionObj)
            {
                return;
            }

            try
            {
                string result = m_SessionObj.Get(helper.CredSSP_RUri, 0);
                XmlDocument resultopxml = new XmlDocument();
                string inputXml = null;
                resultopxml.LoadXml(result);
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(resultopxml.NameTable);
                nsmgr.AddNamespace("cfg", helper.CredSSP_XMLNmsp);
                XmlNode xNode = resultopxml.SelectSingleNode(helper.CredSSP_SNode, nsmgr);
                if (!(xNode == null))
                {
                    inputXml = @"<cfg:Auth xmlns:cfg=""http://schemas.microsoft.com/wbem/wsman/1/config/client/auth""><cfg:CredSSP>false</cfg:CredSSP></cfg:Auth>";
                }
                else
                {
                    InvalidOperationException ex = new InvalidOperationException();
                    ErrorRecord er = new ErrorRecord(ex, helper.GetResourceMsgFromResourcetext("WinrmNotConfigured"), ErrorCategory.InvalidOperation, null);
                    WriteError(er);
                    return;
                }
                m_SessionObj.Put(helper.CredSSP_RUri, inputXml, 0);
               
#if !CORECLR
                if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
                {
                    this.DeleteUserDelegateSettings();
                }
                else
                {
                    ThreadStart start = new ThreadStart(this.DeleteUserDelegateSettings);
                    Thread thread = new Thread(start);
                    thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();
                    thread.Join();
                }
#else
                {
                    ThreadStart start = new ThreadStart(this.DeleteUserDelegateSettings);
                    Thread thread = new Thread(start);
                    thread.Start();
                    thread.Join();
                }
#endif

                if (!helper.ValidateCreadSSPRegistryRetry(false, null, applicationname))
                {
                    helper.AssertError(helper.GetResourceMsgFromResourcetext("DisableCredSSPPolicyValidateError"), false, null);
                }
            }
            catch (System.Xml.XPath.XPathException ex)
            {
                ErrorRecord er = new ErrorRecord(ex, "XpathException", ErrorCategory.InvalidOperation, null);
                WriteError(er);
            }
            finally
            {
                if (!String.IsNullOrEmpty(m_SessionObj.Error))
                {
                    helper.AssertError(m_SessionObj.Error, true, null);
                }

                if (m_SessionObj != null)
                    Dispose(m_SessionObj);
            }
        }
        private void DisableClientSideSettings()
        {
            WSManHelper   wSManHelper  = new WSManHelper(this);
            IWSManSession wSManSession = base.CreateWSManSession();

            if (wSManSession != null)
            {
                try
                {
                    try
                    {
                        string      str         = wSManSession.Get(wSManHelper.CredSSP_RUri, 0);
                        XmlDocument xmlDocument = new XmlDocument();
                        xmlDocument.LoadXml(str);
                        XmlNamespaceManager xmlNamespaceManagers = new XmlNamespaceManager(xmlDocument.NameTable);
                        xmlNamespaceManagers.AddNamespace("cfg", wSManHelper.CredSSP_XMLNmsp);
                        XmlNode xmlNodes = xmlDocument.SelectSingleNode(wSManHelper.CredSSP_SNode, xmlNamespaceManagers);
                        if (xmlNodes == null)
                        {
                            InvalidOperationException invalidOperationException = new InvalidOperationException();
                            ErrorRecord errorRecord = new ErrorRecord(invalidOperationException, wSManHelper.GetResourceMsgFromResourcetext("WinrmNotConfigured"), ErrorCategory.InvalidOperation, null);
                            base.WriteError(errorRecord);
                            return;
                        }
                        else
                        {
                            string str1 = "<cfg:Auth xmlns:cfg=\"http://schemas.microsoft.com/wbem/wsman/1/config/client/auth\"><cfg:CredSSP>false</cfg:CredSSP></cfg:Auth>";
                            wSManSession.Put(wSManHelper.CredSSP_RUri, str1, 0);
                            if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
                            {
                                ThreadStart threadStart = new ThreadStart(this.DeleteUserDelegateSettings);
                                Thread      thread      = new Thread(threadStart);
                                thread.SetApartmentState(ApartmentState.STA);
                                thread.Start();
                                thread.Join();
                            }
                            else
                            {
                                this.DeleteUserDelegateSettings();
                            }
                            if (!wSManHelper.ValidateCreadSSPRegistryRetry(false, null, "wsman"))
                            {
                                wSManHelper.AssertError(wSManHelper.GetResourceMsgFromResourcetext("DisableCredSSPPolicyValidateError"), false, null);
                            }
                        }
                    }
                    catch (XPathException xPathException1)
                    {
                        XPathException xPathException = xPathException1;
                        ErrorRecord    errorRecord1   = new ErrorRecord(xPathException, "XpathException", ErrorCategory.InvalidOperation, null);
                        base.WriteError(errorRecord1);
                    }
                }
                finally
                {
                    if (!string.IsNullOrEmpty(wSManSession.Error))
                    {
                        wSManHelper.AssertError(wSManSession.Error, true, null);
                    }
                    if (wSManSession != null)
                    {
                        this.Dispose(wSManSession);
                    }
                }
                return;
            }
            else
            {
                return;
            }
        }
예제 #5
0
		private void DisableClientSideSettings()
		{
			WSManHelper wSManHelper = new WSManHelper(this);
			IWSManSession wSManSession = base.CreateWSManSession();
			if (wSManSession != null)
			{
				try
				{
					try
					{
						string str = wSManSession.Get(wSManHelper.CredSSP_RUri, 0);
						XmlDocument xmlDocument = new XmlDocument();
						xmlDocument.LoadXml(str);
						XmlNamespaceManager xmlNamespaceManagers = new XmlNamespaceManager(xmlDocument.NameTable);
						xmlNamespaceManagers.AddNamespace("cfg", wSManHelper.CredSSP_XMLNmsp);
						XmlNode xmlNodes = xmlDocument.SelectSingleNode(wSManHelper.CredSSP_SNode, xmlNamespaceManagers);
						if (xmlNodes == null)
						{
							InvalidOperationException invalidOperationException = new InvalidOperationException();
							ErrorRecord errorRecord = new ErrorRecord(invalidOperationException, wSManHelper.GetResourceMsgFromResourcetext("WinrmNotConfigured"), ErrorCategory.InvalidOperation, null);
							base.WriteError(errorRecord);
							return;
						}
						else
						{
							string str1 = "<cfg:Auth xmlns:cfg=\"http://schemas.microsoft.com/wbem/wsman/1/config/client/auth\"><cfg:CredSSP>false</cfg:CredSSP></cfg:Auth>";
							wSManSession.Put(wSManHelper.CredSSP_RUri, str1, 0);
							if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
							{
								ThreadStart threadStart = new ThreadStart(this.DeleteUserDelegateSettings);
								Thread thread = new Thread(threadStart);
								thread.SetApartmentState(ApartmentState.STA);
								thread.Start();
								thread.Join();
							}
							else
							{
								this.DeleteUserDelegateSettings();
							}
							if (!wSManHelper.ValidateCreadSSPRegistryRetry(false, null, "wsman"))
							{
								wSManHelper.AssertError(wSManHelper.GetResourceMsgFromResourcetext("DisableCredSSPPolicyValidateError"), false, null);
							}
						}
					}
					catch (XPathException xPathException1)
					{
						XPathException xPathException = xPathException1;
						ErrorRecord errorRecord1 = new ErrorRecord(xPathException, "XpathException", ErrorCategory.InvalidOperation, null);
						base.WriteError(errorRecord1);
					}
				}
				finally
				{
					if (!string.IsNullOrEmpty(wSManSession.Error))
					{
						wSManHelper.AssertError(wSManSession.Error, true, null);
					}
					if (wSManSession != null)
					{
						this.Dispose(wSManSession);
					}
				}
				return;
			}
			else
			{
				return;
			}
		}