protected override void BeginProcessing()
		{
			WSManHelper wSManHelper = new WSManHelper(this);
			if (this.computername == null)
			{
				this.computername = "localhost";
			}
			if (base.SessionState.Path.CurrentProviderLocation("WSMan").Path.StartsWith(string.Concat("WSMan:", (char)92, this.computername), StringComparison.CurrentCultureIgnoreCase))
			{
				wSManHelper.AssertError(wSManHelper.GetResourceMsgFromResourcetext("DisconnectFailure"), false, this.computername);
			}
			if (this.computername.Equals("localhost", StringComparison.CurrentCultureIgnoreCase))
			{
				wSManHelper.AssertError(wSManHelper.GetResourceMsgFromResourcetext("LocalHost"), false, this.computername);
			}
			object obj = wSManHelper.RemoveFromDictionary(this.computername);
			if (obj == null)
			{
				wSManHelper.AssertError(wSManHelper.GetResourceMsgFromResourcetext("InvalidComputerName"), false, this.computername);
				return;
			}
			else
			{
				this.Dispose(obj);
				return;
			}
		}
Beispiel #2
0
 /// <summary>
 /// BeginProcessing method.
 /// </summary>
 protected override void BeginProcessing()
 {
     //If not running elevated, then throw an "elevation required" error message.
     WSManHelper.ThrowIfNotAdministrator();
     helper = new WSManHelper(this);
     String query = helper.GetResourceMsgFromResourcetext("QuickConfigContinueQuery");
     String caption = helper.GetResourceMsgFromResourcetext("QuickConfigContinueCaption");
     if (!force && !ShouldContinue(query, caption))
     {
         return;
     }
     QuickConfigRemoting(true);
     QuickConfigRemoting(false);
 }//End BeginProcessing()
		protected override void BeginProcessing()
		{
			WSManHelper.ThrowIfNotAdministrator();
			this.helper = new WSManHelper(this);
			if (Environment.OSVersion.Version.Major >= 6)
			{
				WSManHelper.ThrowIfNotAdministrator();
				if (this.delegatecomputer == null || base.Role.Equals("Client", StringComparison.OrdinalIgnoreCase))
				{
					if (!base.Role.Equals("Client", StringComparison.OrdinalIgnoreCase) || this.delegatecomputer != null)
					{
						if (base.Role.Equals("Client", StringComparison.OrdinalIgnoreCase))
						{
							this.EnableClientSideSettings();
						}
						if (base.Role.Equals("Server", StringComparison.OrdinalIgnoreCase))
						{
							this.EnableServerSideSettings();
						}
						return;
					}
					else
					{
						object[] objArray = new object[3];
						objArray[0] = "DelegateComputer";
						objArray[1] = "Role";
						objArray[2] = "Client";
						string str = this.helper.FormatResourceMsgFromResourcetext("CredSSPClientAndDelegateMustBeSpecified", objArray);
						throw new InvalidOperationException(str);
					}
				}
				else
				{
					object[] role = new object[4];
					role[0] = "DelegateComputer";
					role[1] = "Role";
					role[2] = base.Role;
					role[3] = "Client";
					string str1 = this.helper.FormatResourceMsgFromResourcetext("CredSSPRoleAndDelegateCannotBeSpecified", role);
					throw new InvalidOperationException(str1);
				}
			}
			else
			{
				string str2 = this.helper.FormatResourceMsgFromResourcetext("CmdletNotAvailable", new object[0]);
				throw new InvalidOperationException(str2);
			}
		}
		protected override void BeginProcessing()
		{
			WSManHelper.ThrowIfNotAdministrator();
			this.helper = new WSManHelper(this);
			string resourceMsgFromResourcetext = this.helper.GetResourceMsgFromResourcetext("QuickConfigContinueQuery");
			string str = this.helper.GetResourceMsgFromResourcetext("QuickConfigContinueCaption");
			if (this.force || base.ShouldContinue(resourceMsgFromResourcetext, str))
			{
				this.QuickConfigRemoting(true);
				this.QuickConfigRemoting(false);
				return;
			}
			else
			{
				return;
			}
		}
		protected override void BeginProcessing()
		{
			if (Environment.OSVersion.Version.Major >= 6)
			{
				WSManHelper.ThrowIfNotAdministrator();
				if (base.Role.Equals("Client", StringComparison.OrdinalIgnoreCase))
				{
					this.DisableClientSideSettings();
				}
				if (base.Role.Equals("Server", StringComparison.OrdinalIgnoreCase))
				{
					this.DisableServerSideSettings();
				}
				return;
			}
			else
			{
				WSManHelper wSManHelper = new WSManHelper(this);
				string str = wSManHelper.FormatResourceMsgFromResourcetext("CmdletNotAvailable", new object[0]);
				throw new InvalidOperationException(str);
			}
		}
Beispiel #6
0
 protected override void BeginProcessing()
 {
     this.helper         = new WSManHelper(this);
     this.helper.WSManOp = "invoke";
     this.connectionStr  = this.helper.CreateConnectionString(this.connectionuri, this.port, this.computername, this.applicationname);
 }
		protected override void ProcessRecord()
		{
			WSManHelper wSManHelper = new WSManHelper(this);
			IWSManEx wSManClass = (IWSManEx)(new WSManClass());
			wSManHelper.WSManOp = "remove";
			IWSManSession wSManSession = null;
			try
			{
				string str = wSManHelper.CreateConnectionString(this.connectionuri, this.port, this.computername, this.applicationname);
				if (this.connectionuri != null)
				{
					try
					{
						string[] strArrays = new string[1];
						object[] objArray = new object[4];
						objArray[0] = ":";
						objArray[1] = this.port;
						objArray[2] = "/";
						objArray[3] = this.applicationname;
						strArrays[0] = string.Concat(objArray);
						string[] strArrays1 = this.connectionuri.OriginalString.Split(strArrays, StringSplitOptions.None);
						string[] strArrays2 = new string[1];
						strArrays2[0] = "//";
						string[] strArrays3 = strArrays1[0].Split(strArrays2, StringSplitOptions.None);
						this.computername = strArrays3[1].Trim();
					}
					catch (IndexOutOfRangeException indexOutOfRangeException)
					{
						wSManHelper.AssertError(wSManHelper.GetResourceMsgFromResourcetext("NotProperURI"), false, this.connectionuri);
					}
				}
				wSManHelper.InitializeResourceLocator(this.optionset, this.selectorset, null, null, wSManClass, this.resourceuri);
				wSManSession = wSManHelper.CreateSessionObject(wSManClass, this.Authentication, this.sessionoption, this.Credential, str, this.CertificateThumbprint, this.usessl.IsPresent);
				string uRIWithFilter = wSManHelper.GetURIWithFilter(this.resourceuri.ToString(), null, this.selectorset, wSManHelper.WSManOp);
				try
				{
					wSManSession.Delete(uRIWithFilter, 0);
				}
				catch (Exception exception1)
				{
					Exception exception = exception1;
					wSManHelper.AssertError(exception.Message, false, this.computername);
				}
			}
			finally
			{
				if (!string.IsNullOrEmpty(wSManSession.Error))
				{
					wSManHelper.AssertError(wSManSession.Error, true, this.resourceuri);
				}
				if (!string.IsNullOrEmpty(wSManClass.Error))
				{
					wSManHelper.AssertError(wSManClass.Error, true, this.resourceuri);
				}
				if (wSManSession != null)
				{
					this.Dispose(wSManSession);
				}
			}
		}
Beispiel #8
0
        /// <summary>
        /// begin processing method.
        /// </summary>
        protected override void BeginProcessing()
        {
#if !CORECLR
            if (Environment.OSVersion.Version.Major < 6)
            {
                //OS is XP/Win2k3. Throw error.
                WSManHelper helper = new WSManHelper(this);
                string message = helper.FormatResourceMsgFromResourcetext("CmdletNotAvailable");
                throw new InvalidOperationException(message);
            }
#endif
            //If not running elevated, then throw an "elevation required" error message.
            WSManHelper.ThrowIfNotAdministrator();

            if (Role.Equals(Client, StringComparison.OrdinalIgnoreCase))
            {
                DisableClientSideSettings();
            }

            if (Role.Equals(Server, StringComparison.OrdinalIgnoreCase))
            {
                DisableServerSideSettings();
            }
        }//End BeginProcessing()
Beispiel #9
0
        private void DisableServerSideSettings()
        {
            WSManHelper helper = new WSManHelper(this);
            IWSManSession m_SessionObj = CreateWSManSession();
            if (null == m_SessionObj)
            {
                return;
            }

            try
            {
                string result = m_SessionObj.Get(helper.Service_CredSSP_Uri, 0);
                XmlDocument resultopxml = new XmlDocument();
                string inputXml = null;
                resultopxml.LoadXml(result);

                XmlNamespaceManager nsmgr = new XmlNamespaceManager(resultopxml.NameTable);
                nsmgr.AddNamespace("cfg", helper.Service_CredSSP_XMLNmsp);
                XmlNode xNode = resultopxml.SelectSingleNode(helper.CredSSP_SNode, nsmgr);
                if (!(xNode == null))
                {
                    inputXml = string.Format(CultureInfo.InvariantCulture,
                        @"<cfg:Auth xmlns:cfg=""{0}""><cfg:CredSSP>false</cfg:CredSSP></cfg:Auth>",
                        helper.Service_CredSSP_XMLNmsp);
                }
                else
                {
                    InvalidOperationException ex = new InvalidOperationException();
                    ErrorRecord er = new ErrorRecord(ex, 
                        helper.GetResourceMsgFromResourcetext("WinrmNotConfigured"), 
                        ErrorCategory.InvalidOperation, null);
                    WriteError(er);
                    return;
                }

                m_SessionObj.Put(helper.Service_CredSSP_Uri, inputXml, 0);
            }
            finally
            {
                if (!String.IsNullOrEmpty(m_SessionObj.Error))
                {
                    helper.AssertError(m_SessionObj.Error, true, null);
                }

                if (m_SessionObj != null)
                {
                    Dispose(m_SessionObj);
                }
            }
        }
		protected override void BeginProcessing()
		{
			WSManHelper wSManHelper = new WSManHelper(this);
			if ((this.proxyauthentication.Equals(ProxyAuthentication.Basic) || this.proxyauthentication.Equals(ProxyAuthentication.Digest)) && this._proxycredential == null)
			{
				InvalidOperationException invalidOperationException = new InvalidOperationException(wSManHelper.GetResourceMsgFromResourcetext("NewWSManSessionOptionCred"));
				ErrorRecord errorRecord = new ErrorRecord(invalidOperationException, "InvalidOperationException", ErrorCategory.InvalidOperation, null);
				base.WriteError(errorRecord);
				return;
			}
			else
			{
				if (this._proxycredential == null || this.proxyauthentication != 0)
				{
					SessionOption sessionOption = new SessionOption();
					sessionOption.SPNPort = this.spnport;
					sessionOption.UseUtf16 = this.useutf16;
					sessionOption.SkipCNCheck = this.skipcncheck;
					sessionOption.SkipCACheck = this.skipcacheck;
					sessionOption.OperationTimeout = this.operationtimeout;
					sessionOption.SkipRevocationCheck = this.skiprevocationcheck;
					sessionOption.ProxyAccessType = this._proxyacesstype;
					sessionOption.ProxyAuthentication = this.proxyauthentication;
					if (this.noencryption)
					{
						sessionOption.UseEncryption = false;
					}
					if (this._proxycredential != null)
					{
						NetworkCredential networkCredential = this._proxycredential.GetNetworkCredential();
						sessionOption.ProxyCredential = networkCredential;
					}
					base.WriteObject(sessionOption);
					return;
				}
				else
				{
					InvalidOperationException invalidOperationException1 = new InvalidOperationException(wSManHelper.GetResourceMsgFromResourcetext("NewWSManSessionOptionAuth"));
					ErrorRecord errorRecord1 = new ErrorRecord(invalidOperationException1, "InvalidOperationException", ErrorCategory.InvalidOperation, null);
					base.WriteError(errorRecord1);
					return;
				}
			}
		}
Beispiel #11
0
        /// <summary>
        /// BeginProcessing method.
        /// </summary>
        protected override void BeginProcessing()
        {

            WSManHelper helper = new WSManHelper(this);
            if (connectionuri != null)
            {
                try
                {
                    //always in the format http://server:port/applicationname
                    string[] constrsplit = connectionuri.OriginalString.Split(new string[] { ":" + port + "/" + applicationname }, StringSplitOptions.None);
                    string[] constrsplit1 = constrsplit[0].Split(new string[] { "//" }, StringSplitOptions.None);
                    computername = constrsplit1[1].Trim();
                }
                catch (IndexOutOfRangeException)
                {
                    helper.AssertError(helper.GetResourceMsgFromResourcetext("NotProperURI"), false, connectionuri);
                }
            }
            string crtComputerName = computername;
            if (crtComputerName == null)
            {
                crtComputerName = "localhost";
            }
            if (this.SessionState.Path.CurrentProviderLocation(WSManStringLiterals.rootpath).Path.StartsWith(this.SessionState.Drive.Current.Name + ":" + WSManStringLiterals.DefaultPathSeparator + crtComputerName, StringComparison.CurrentCultureIgnoreCase))
            {
                helper.AssertError(helper.GetResourceMsgFromResourcetext("ConnectFailure"), false, computername);
            }
            helper.CreateWsManConnection(ParameterSetName, connectionuri, port, computername, applicationname, usessl.IsPresent, Authentication, sessionoption, Credential, CertificateThumbprint);
        }//End BeginProcessing()    
Beispiel #12
0
        /// <summary>
        /// BeginProcessing method.
        /// </summary>
        protected override void BeginProcessing()
        {
            helper = new WSManHelper(this);

            helper.WSManOp = "invoke";

            //create the connection string
            connectionStr = helper.CreateConnectionString(connectionuri, port, computername, applicationname);


        }
Beispiel #13
0
 internal void ValidateSpecifiedAuthentication()
 {
     WSManHelper.ValidateSpecifiedAuthentication(this.Authentication, this.Credential, this.CertificateThumbprint);
 }
Beispiel #14
0
        /// <summary>
        /// ProcessRecord method.
        /// </summary>
        protected override void ProcessRecord()
        {
            IWSManEx m_wsmanObject = (IWSManEx)new WSManClass();
            helper = new WSManHelper(this);
            helper.WSManOp = "set";
            IWSManSession m_session = null;


            if (dialect != null)
            {
                if (dialect.ToString().Equals(helper.ALIAS_WQL, StringComparison.CurrentCultureIgnoreCase))
                    dialect = new Uri(helper.URI_WQL_DIALECT);
                if (dialect.ToString().Equals(helper.ALIAS_SELECTOR, StringComparison.CurrentCultureIgnoreCase))
                    dialect = new Uri(helper.URI_SELECTOR_DIALECT);
                if (dialect.ToString().Equals(helper.ALIAS_ASSOCIATION, StringComparison.CurrentCultureIgnoreCase))
                    dialect = new Uri(helper.URI_ASSOCIATION_DIALECT);
            }

            try
            {
                string connectionStr = String.Empty;
                connectionStr = helper.CreateConnectionString(connectionuri, port, computername, applicationname);
                if (connectionuri != null)
                {
                    try
                    {
                        //in the format http(s)://server[:port/applicationname]
                        string[] constrsplit = connectionuri.OriginalString.Split(new string[] { ":" + port + "/" + applicationname }, StringSplitOptions.None);
                        string[] constrsplit1 = constrsplit[0].Split(new string[] { "//" }, StringSplitOptions.None);
                        computername = constrsplit1[1].Trim();
                    }
                    catch (IndexOutOfRangeException)
                    {
                        helper.AssertError(helper.GetResourceMsgFromResourcetext("NotProperURI"), false, connectionuri);
                    }

                }
                IWSManResourceLocator m_resource = helper.InitializeResourceLocator(optionset, selectorset, fragment, dialect, m_wsmanObject, resourceuri);
                m_session = helper.CreateSessionObject(m_wsmanObject, Authentication, sessionoption, Credential, connectionStr, CertificateThumbprint, usessl.IsPresent);
                string rootNode = helper.GetRootNodeName(helper.WSManOp, m_resource.ResourceUri, null);
                string input = helper.ProcessInput(m_wsmanObject, filepath, helper.WSManOp, rootNode, valueset, m_resource, m_session);

                XmlDocument xmldoc = new XmlDocument();
                try
                {
                    xmldoc.LoadXml(m_session.Put(m_resource, input, 0));
                }
                catch(XmlException ex)
                {
                    helper.AssertError(ex.Message, false, computername);
                }

                if (!string.IsNullOrEmpty(fragment))
                {
                    if (xmldoc.DocumentElement.ChildNodes.Count > 0)
                    {
                        foreach (XmlNode node in xmldoc.DocumentElement.ChildNodes)
                        {
                            if (node.Name.Equals(fragment, StringComparison.CurrentCultureIgnoreCase))
                                WriteObject(node.Name + " = " + node.InnerText);
                        }
                    }
                }
                else
                    WriteObject(xmldoc.DocumentElement);

            }
            finally
            {
                if (!String.IsNullOrEmpty(m_wsmanObject.Error))
                {
                    helper.AssertError(m_wsmanObject.Error, true, resourceuri);
                }
                if (!String.IsNullOrEmpty(m_session.Error))
                {
                    helper.AssertError(m_session.Error, true, resourceuri);
                }
                if (m_session != null)
                    Dispose(m_session);
            }
        }//End ProcessRecord()
Beispiel #15
0
        /// <summary>
        /// ProcessRecord method.
        /// </summary>
        protected override void ProcessRecord()
        {
            IWSManSession m_session = null;
            IWSManEx m_wsmanObject = (IWSManEx)new WSManClass();
            helper = new WSManHelper(this);
            helper.WSManOp = "Get";
            string connectionStr = null;
            connectionStr = helper.CreateConnectionString(connectionuri, port, computername, applicationname);
            if (connectionuri != null)
            {
                try
                {
                    //in the format http(s)://server[:port/applicationname]
                    string[] constrsplit = connectionuri.OriginalString.Split(new string[] { ":" + port + "/" + applicationname }, StringSplitOptions.None);
                    string[] constrsplit1 = constrsplit[0].Split(new string[] { "//" }, StringSplitOptions.None);
                    computername = constrsplit1[1].Trim();
                }
                catch (IndexOutOfRangeException)
                {
                    helper.AssertError(helper.GetResourceMsgFromResourcetext("NotProperURI"), false, connectionuri);
                }

            }
            try
            {
                IWSManResourceLocator m_resource = helper.InitializeResourceLocator(optionset, selectorset, fragment, dialect, m_wsmanObject, resourceuri);
                m_session = helper.CreateSessionObject(m_wsmanObject, Authentication, sessionoption, Credential, connectionStr, CertificateThumbprint, usessl.IsPresent);

                if (!enumerate)
                {
                    XmlDocument xmldoc = new XmlDocument();
                    try
                    {
                        xmldoc.LoadXml(m_session.Get(m_resource, 0));
                    }
                    catch(XmlException ex)
                    {
                        helper.AssertError(ex.Message, false, computername);
                    }

                    if (!string.IsNullOrEmpty(fragment))
                    {
                        WriteObject(xmldoc.FirstChild.LocalName + "=" + xmldoc.FirstChild.InnerText);
                    }
                    else
                    {
                        WriteObject(xmldoc.FirstChild);
                    }
                }
                else
                {
                    try
                    {
                        ReturnEnumeration(m_wsmanObject, m_resource, m_session);
                    }
                    catch (Exception ex)
                    {
                        helper.AssertError(ex.Message, false, computername);
                    }
                }

            }
            finally
            {
                if (!String.IsNullOrEmpty(m_wsmanObject.Error))
                {
                    helper.AssertError(m_wsmanObject.Error, true, resourceuri);
                }
                if (!String.IsNullOrEmpty(m_session.Error))
                {
                    helper.AssertError(m_session.Error, true, resourceuri);
                }
                if (m_session != null)
                    Dispose(m_session);
            }
        }
Beispiel #16
0
        /// <summary>
        /// BeginProcessing method.
        /// </summary>
        protected override void BeginProcessing()
        {
            helper = new WSManHelper(this );
            helper.WSManOp = "new";
            connectionStr = helper.CreateConnectionString(connectionuri, port, computername, applicationname);
            if (connectionuri != null)
            {
                try
                {
                    //in the format http(s)://server[:port/applicationname]
                    string[] constrsplit = connectionuri.OriginalString.Split(new string[] { ":" + port + "/" + applicationname }, StringSplitOptions.None);
                    string[] constrsplit1 = constrsplit[0].Split(new string[] { "//" }, StringSplitOptions.None);
                    computername = constrsplit1[1].Trim();
                }
                catch (IndexOutOfRangeException)
                {
                    helper.AssertError(helper.GetResourceMsgFromResourcetext("NotProperURI"), false, connectionuri);
                }

            }

        }//End BeginProcessing()
Beispiel #17
0
        /// <summary>
        /// ProcessRecord method.
        /// </summary>
        protected override void ProcessRecord()
        {
            WSManHelper helper = new WSManHelper(this);
            IWSManEx m_wsmanObject = (IWSManEx)new WSManClass();
            helper.WSManOp = "remove";
            IWSManSession m_session = null;
            try
            {
                string connectionStr = String.Empty;
                connectionStr = helper.CreateConnectionString(connectionuri, port, computername, applicationname);
                if (connectionuri != null)
                {
                    try
                    {
                        //in the format http(s)://server[:port/applicationname]
                        string[] constrsplit = connectionuri.OriginalString.Split(new string[] { ":" + port + "/" + applicationname }, StringSplitOptions.None);
                        string[] constrsplit1 = constrsplit[0].Split(new string[] { "//" }, StringSplitOptions.None);
                        computername = constrsplit1[1].Trim();
                    }
                    catch (IndexOutOfRangeException)
                    {
                        helper.AssertError(helper.GetResourceMsgFromResourcetext("NotProperURI"), false, connectionuri);
                    }

                }
                IWSManResourceLocator m_resource = helper.InitializeResourceLocator(optionset, selectorset, null, null, m_wsmanObject, resourceuri);
                m_session = helper.CreateSessionObject(m_wsmanObject, Authentication, sessionoption, Credential, connectionStr, CertificateThumbprint, usessl.IsPresent);
                string ResourceURI = helper.GetURIWithFilter(resourceuri.ToString(), null, selectorset, helper.WSManOp);
                try
                {
                    ((IWSManSession)m_session).Delete(ResourceURI, 0);
                }
                catch (Exception ex)
                {
                    helper.AssertError(ex.Message, false, computername);
                }

            }
            finally
            {
                if (!String.IsNullOrEmpty(m_session.Error))
                {
                    helper.AssertError(m_session.Error, true, resourceuri);
                }
                if (!String.IsNullOrEmpty(m_wsmanObject.Error))
                {
                    helper.AssertError(m_wsmanObject.Error, true, resourceuri);
                }
                if (m_session != null)
                    Dispose(m_session);

            }

        }//End ProcessRecord()
Beispiel #18
0
		protected override void BeginProcessing()
		{
			WSManHelper wSManHelper = new WSManHelper(this);
			if (this.connectionuri != null)
			{
				try
				{
					string[] strArrays = new string[1];
					object[] objArray = new object[4];
					objArray[0] = ":";
					objArray[1] = this.port;
					objArray[2] = "/";
					objArray[3] = this.applicationname;
					strArrays[0] = string.Concat(objArray);
					string[] strArrays1 = this.connectionuri.OriginalString.Split(strArrays, StringSplitOptions.None);
					string[] strArrays2 = new string[1];
					strArrays2[0] = "//";
					string[] strArrays3 = strArrays1[0].Split(strArrays2, StringSplitOptions.None);
					this.computername = strArrays3[1].Trim();
				}
				catch (IndexOutOfRangeException indexOutOfRangeException)
				{
					wSManHelper.AssertError(wSManHelper.GetResourceMsgFromResourcetext("NotProperURI"), false, this.connectionuri);
				}
			}
			string str = this.computername;
			if (str == null)
			{
				str = "localhost";
			}
			object[] name = new object[4];
			name[0] = base.SessionState.Drive.Current.Name;
			name[1] = ":";
			name[2] = (char)92;
			name[3] = str;
			if (base.SessionState.Path.CurrentProviderLocation("WSMan").Path.StartsWith(string.Concat(name), StringComparison.CurrentCultureIgnoreCase))
			{
				wSManHelper.AssertError(wSManHelper.GetResourceMsgFromResourcetext("ConnectFailure"), false, this.computername);
			}
			wSManHelper.CreateWsManConnection(base.ParameterSetName, this.connectionuri, this.port, this.computername, this.applicationname, this.usessl.IsPresent, this.Authentication, this.sessionoption, this.Credential, this.CertificateThumbprint);
		}
		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;
			}
		}
		private void DisableServerSideSettings()
		{
			WSManHelper wSManHelper = new WSManHelper(this);
			IWSManSession wSManSession = base.CreateWSManSession();
			if (wSManSession != null)
			{
				try
				{
					string str = wSManSession.Get(wSManHelper.Service_CredSSP_Uri, 0);
					XmlDocument xmlDocument = new XmlDocument();
					xmlDocument.LoadXml(str);
					XmlNamespaceManager xmlNamespaceManagers = new XmlNamespaceManager(xmlDocument.NameTable);
					xmlNamespaceManagers.AddNamespace("cfg", wSManHelper.Service_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);
					}
					else
					{
						object[] serviceCredSSPXMLNmsp = new object[1];
						serviceCredSSPXMLNmsp[0] = wSManHelper.Service_CredSSP_XMLNmsp;
						string str1 = string.Format(CultureInfo.InvariantCulture, "<cfg:Auth xmlns:cfg=\"{0}\"><cfg:CredSSP>false</cfg:CredSSP></cfg:Auth>", serviceCredSSPXMLNmsp);
						wSManSession.Put(wSManHelper.Service_CredSSP_Uri, str1, 0);
					}
				}
				finally
				{
					if (!string.IsNullOrEmpty(wSManSession.Error))
					{
						wSManHelper.AssertError(wSManSession.Error, true, null);
					}
					if (wSManSession != null)
					{
						this.Dispose(wSManSession);
					}
				}
				return;
			}
			else
			{
				return;
			}
		}
		protected override void BeginProcessing()
		{
			this.helper = new WSManHelper(this);
			this.helper.WSManOp = "new";
			this.connectionStr = this.helper.CreateConnectionString(this.connectionuri, this.port, this.computername, this.applicationname);
			if (this.connectionuri != null)
			{
				try
				{
					string[] strArrays = new string[1];
					object[] objArray = new object[4];
					objArray[0] = ":";
					objArray[1] = this.port;
					objArray[2] = "/";
					objArray[3] = this.applicationname;
					strArrays[0] = string.Concat(objArray);
					string[] strArrays1 = this.connectionuri.OriginalString.Split(strArrays, StringSplitOptions.None);
					string[] strArrays2 = new string[1];
					strArrays2[0] = "//";
					string[] strArrays3 = strArrays1[0].Split(strArrays2, StringSplitOptions.None);
					this.computername = strArrays3[1].Trim();
				}
				catch (IndexOutOfRangeException indexOutOfRangeException)
				{
					this.helper.AssertError(this.helper.GetResourceMsgFromResourcetext("NotProperURI"), false, this.connectionuri);
				}
			}
		}
		private void DeleteDelegateSettings(string applicationname, RegistryKey rootKey, string Registry_Path, IGroupPolicyObject GPO)
		{
			WSManHelper wSManHelper = new WSManHelper(this);
			int num = 0;
			bool flag = false;
			try
			{
				string str = string.Concat(Registry_Path, "\\CredentialsDelegation");
				RegistryKey registryKey = rootKey.OpenSubKey(string.Concat(str, "\\", wSManHelper.Key_Allow_Fresh_Credentials), true);
				if (registryKey != null)
				{
					string[] valueNames = registryKey.GetValueNames();
					if ((int)valueNames.Length > 0)
					{
						Collection<string> strs = new Collection<string>();
						string[] strArrays = valueNames;
						for (int i = 0; i < (int)strArrays.Length; i++)
						{
							string str1 = strArrays[i];
							object value = registryKey.GetValue(str1);
							if (value != null && !value.ToString().StartsWith(applicationname, StringComparison.OrdinalIgnoreCase))
							{
								strs.Add(value.ToString());
								flag = true;
							}
							registryKey.DeleteValue(str1);
						}
						foreach (string str2 in strs)
						{
							registryKey.SetValue(Convert.ToString(num + 1, CultureInfo.InvariantCulture), str2, RegistryValueKind.String);
							num++;
						}
					}
				}
				if (!flag)
				{
					RegistryKey registryKey1 = rootKey.OpenSubKey(str, true);
					if (registryKey1 != null)
					{
						object obj = registryKey1.GetValue(wSManHelper.Key_Allow_Fresh_Credentials);
						if (obj != null)
						{
							registryKey1.DeleteValue(wSManHelper.Key_Allow_Fresh_Credentials, false);
						}
						object value1 = registryKey1.GetValue(wSManHelper.Key_Concatenate_Defaults_AllowFresh);
						if (value1 != null)
						{
							registryKey1.DeleteValue(wSManHelper.Key_Concatenate_Defaults_AllowFresh, false);
						}
						if (registryKey1.OpenSubKey(wSManHelper.Key_Allow_Fresh_Credentials) != null)
						{
							registryKey1.DeleteSubKeyTree(wSManHelper.Key_Allow_Fresh_Credentials);
						}
					}
				}
				GPO.Save(true, true, new Guid("35378EAC-683F-11D2-A89A-00C04FBBCFA2"), new Guid("6AD20875-336C-4e22-968F-C709ACB15814"));
			}
			catch (InvalidOperationException invalidOperationException1)
			{
				InvalidOperationException invalidOperationException = invalidOperationException1;
				ErrorRecord errorRecord = new ErrorRecord(invalidOperationException, "InvalidOperation", ErrorCategory.InvalidOperation, null);
				base.WriteError(errorRecord);
			}
			catch (ArgumentException argumentException1)
			{
				ArgumentException argumentException = argumentException1;
				ErrorRecord errorRecord1 = new ErrorRecord(argumentException, "InvalidArgument", ErrorCategory.InvalidArgument, null);
				base.WriteError(errorRecord1);
			}
			catch (SecurityException securityException1)
			{
				SecurityException securityException = securityException1;
				ErrorRecord errorRecord2 = new ErrorRecord(securityException, "SecurityException", ErrorCategory.SecurityError, null);
				base.WriteError(errorRecord2);
			}
			catch (UnauthorizedAccessException unauthorizedAccessException1)
			{
				UnauthorizedAccessException unauthorizedAccessException = unauthorizedAccessException1;
				ErrorRecord errorRecord3 = new ErrorRecord(unauthorizedAccessException, "UnauthorizedAccess", ErrorCategory.SecurityError, null);
				base.WriteError(errorRecord3);
			}
		}
Beispiel #23
0
		protected override void BeginProcessing()
		{
			WSManHelper.ThrowIfNotAdministrator();
			this.helper = new WSManHelper(this);
			if (Environment.OSVersion.Version.Major >= 6)
			{
				WSManHelper.ThrowIfNotAdministrator();
				IWSManSession wSManSession = null;
				try
				{
					try
					{
						IWSManEx wSManClass = (IWSManEx)(new WSManClass());
						wSManSession = (IWSManSession)wSManClass.CreateSession(null, 0, null);
						string str = wSManSession.Get(this.helper.CredSSP_RUri, 0);
						XmlNode xmlNode = this.helper.GetXmlNode(str, this.helper.CredSSP_SNode, this.helper.CredSSP_XMLNmsp);
						if (xmlNode != null)
						{
							string str1 = "wsman";
							string delegateSettings = this.GetDelegateSettings(str1);
							if (!string.IsNullOrEmpty(delegateSettings))
							{
								base.WriteObject(string.Concat(this.helper.GetResourceMsgFromResourcetext("DelegateFreshCred"), delegateSettings));
							}
							else
							{
								base.WriteObject(this.helper.GetResourceMsgFromResourcetext("NoDelegateFreshCred"));
							}
							str = wSManSession.Get(this.helper.Service_CredSSP_Uri, 0);
							xmlNode = this.helper.GetXmlNode(str, this.helper.CredSSP_SNode, this.helper.Service_CredSSP_XMLNmsp);
							if (xmlNode != null)
							{
								if (!xmlNode.InnerText.Equals("true", StringComparison.OrdinalIgnoreCase))
								{
									base.WriteObject(this.helper.GetResourceMsgFromResourcetext("CredSSPServiceNotConfigured"));
								}
								else
								{
									base.WriteObject(this.helper.GetResourceMsgFromResourcetext("CredSSPServiceConfigured"));
								}
							}
							else
							{
								InvalidOperationException invalidOperationException = new InvalidOperationException();
								ErrorRecord errorRecord = new ErrorRecord(invalidOperationException, this.helper.GetResourceMsgFromResourcetext("WinrmNotConfigured"), ErrorCategory.InvalidOperation, null);
								base.WriteError(errorRecord);
								return;
							}
						}
						else
						{
							InvalidOperationException invalidOperationException1 = new InvalidOperationException();
							ErrorRecord errorRecord1 = new ErrorRecord(invalidOperationException1, this.helper.GetResourceMsgFromResourcetext("WinrmNotConfigured"), ErrorCategory.InvalidOperation, null);
							base.WriteError(errorRecord1);
							return;
						}
					}
					catch (UnauthorizedAccessException unauthorizedAccessException1)
					{
						UnauthorizedAccessException unauthorizedAccessException = unauthorizedAccessException1;
						ErrorRecord errorRecord2 = new ErrorRecord(unauthorizedAccessException, "UnauthorizedAccess", ErrorCategory.PermissionDenied, null);
						base.WriteError(errorRecord2);
					}
					catch (SecurityException securityException1)
					{
						SecurityException securityException = securityException1;
						ErrorRecord errorRecord3 = new ErrorRecord(securityException, "SecurityException", ErrorCategory.InvalidOperation, null);
						base.WriteError(errorRecord3);
					}
					catch (ArgumentException argumentException1)
					{
						ArgumentException argumentException = argumentException1;
						ErrorRecord errorRecord4 = new ErrorRecord(argumentException, "InvalidArgument", ErrorCategory.InvalidOperation, null);
						base.WriteError(errorRecord4);
					}
					catch (XPathException xPathException1)
					{
						XPathException xPathException = xPathException1;
						ErrorRecord errorRecord5 = new ErrorRecord(xPathException, "XPathException", ErrorCategory.InvalidOperation, null);
						base.WriteError(errorRecord5);
					}
				}
				finally
				{
					if (!string.IsNullOrEmpty(wSManSession.Error))
					{
						this.helper.AssertError(wSManSession.Error, true, null);
					}
					if (wSManSession != null)
					{
						this.Dispose(wSManSession);
					}
				}
				return;
			}
			else
			{
				string str2 = this.helper.FormatResourceMsgFromResourcetext("CmdletNotAvailable", new object[0]);
				throw new InvalidOperationException(str2);
			}
		}
Beispiel #24
0
        /// <summary>
        /// BeginProcessing method.
        /// </summary>
        protected override void BeginProcessing()
        {
            WSManHelper helper = new WSManHelper(this);
            if (computername == null)
            {
                computername = "localhost";
            }
            if (this.SessionState.Path.CurrentProviderLocation(WSManStringLiterals.rootpath).Path.StartsWith(WSManStringLiterals.rootpath + ":" + WSManStringLiterals.DefaultPathSeparator + computername, StringComparison.CurrentCultureIgnoreCase))
            {
                helper.AssertError(helper.GetResourceMsgFromResourcetext("DisconnectFailure"), false, computername);
            }
            if (computername.Equals("localhost", StringComparison.CurrentCultureIgnoreCase))
            {
                helper.AssertError(helper.GetResourceMsgFromResourcetext("LocalHost"), false, computername);
            }

            object _ws = helper.RemoveFromDictionary(computername);
            if (_ws != null)
            {
                Dispose(_ws);
            }
            else
            {
                helper.AssertError(helper.GetResourceMsgFromResourcetext("InvalidComputerName"), false, computername);
            }
        }//End BeginProcessing()
		protected override void ProcessRecord()
		{
			IWSManSession wSManSession = null;
			IWSManEx wSManClass = (IWSManEx)(new WSManClass());
			this.helper = new WSManHelper(this);
			this.helper.WSManOp = "Get";
			string str = this.helper.CreateConnectionString(this.connectionuri, this.port, this.computername, this.applicationname);
			if (this.connectionuri != null)
			{
				try
				{
					string[] strArrays = new string[1];
					object[] objArray = new object[4];
					objArray[0] = ":";
					objArray[1] = this.port;
					objArray[2] = "/";
					objArray[3] = this.applicationname;
					strArrays[0] = string.Concat(objArray);
					string[] strArrays1 = this.connectionuri.OriginalString.Split(strArrays, StringSplitOptions.None);
					string[] strArrays2 = new string[1];
					strArrays2[0] = "//";
					string[] strArrays3 = strArrays1[0].Split(strArrays2, StringSplitOptions.None);
					this.computername = strArrays3[1].Trim();
				}
				catch (IndexOutOfRangeException indexOutOfRangeException)
				{
					this.helper.AssertError(this.helper.GetResourceMsgFromResourcetext("NotProperURI"), false, this.connectionuri);
				}
			}
			try
			{
				IWSManResourceLocator wSManResourceLocator = this.helper.InitializeResourceLocator(this.optionset, this.selectorset, this.fragment, this.dialect, wSManClass, this.resourceuri);
				wSManSession = this.helper.CreateSessionObject(wSManClass, this.Authentication, this.sessionoption, this.Credential, str, this.CertificateThumbprint, this.usessl.IsPresent);
				if (this.enumerate)
				{
					try
					{
						this.ReturnEnumeration(wSManClass, wSManResourceLocator, wSManSession);
					}
					catch (Exception exception1)
					{
						Exception exception = exception1;
						this.helper.AssertError(exception.Message, false, this.computername);
					}
				}
				else
				{
					XmlDocument xmlDocument = new XmlDocument();
					try
					{
						xmlDocument.LoadXml(wSManSession.Get(wSManResourceLocator, 0));
					}
					catch (XmlException xmlException1)
					{
						XmlException xmlException = xmlException1;
						this.helper.AssertError(xmlException.Message, false, this.computername);
					}
					if (string.IsNullOrEmpty(this.fragment))
					{
						base.WriteObject(xmlDocument.FirstChild);
					}
					else
					{
						base.WriteObject(string.Concat(xmlDocument.FirstChild.LocalName, "=", xmlDocument.FirstChild.InnerText));
					}
				}
			}
			finally
			{
				if (!string.IsNullOrEmpty(wSManClass.Error))
				{
					this.helper.AssertError(wSManClass.Error, true, this.resourceuri);
				}
				if (!string.IsNullOrEmpty(wSManSession.Error))
				{
					this.helper.AssertError(wSManSession.Error, true, this.resourceuri);
				}
				if (wSManSession != null)
				{
					this.Dispose(wSManSession);
				}
			}
		}
Beispiel #26
0
 private void NewItemCreateComputerConnection(string Name)
 {
     this.helper = new WSManHelper(this);
     WSManProviderNewItemComputerParameters dynamicParameters = base.DynamicParameters as WSManProviderNewItemComputerParameters;
     string parameterSetName = "ComputerName";
     if (dynamicParameters != null)
     {
         if (dynamicParameters.ConnectionURI != null)
         {
             parameterSetName = "URI";
         }
         this.helper.CreateWsManConnection(parameterSetName, dynamicParameters.ConnectionURI, dynamicParameters.Port, Name, dynamicParameters.ApplicationName, (bool) dynamicParameters.UseSSL, dynamicParameters.Authentication, dynamicParameters.SessionOption, base.Credential, dynamicParameters.CertificateThumbprint);
         if (dynamicParameters.ConnectionURI != null)
         {
             Name = dynamicParameters.ConnectionURI.OriginalString.Split(new string[] { string.Concat(new object[] { ":", dynamicParameters.Port, "/", dynamicParameters.ApplicationName }) }, StringSplitOptions.None)[0].Split(new string[] { "//" }, StringSplitOptions.None)[1].Trim();
         }
         base.WriteItemObject(this.GetItemPSObjectWithTypeName(Name, "Container", null, null, "ComputerLevel", WsManElementObjectTypes.WSManConfigContainerElement, null), "WSMan" + '\\' + Name, true);
     }
     else
     {
         dynamicParameters = new WSManProviderNewItemComputerParameters();
         this.helper.CreateWsManConnection(parameterSetName, dynamicParameters.ConnectionURI, dynamicParameters.Port, Name, dynamicParameters.ApplicationName, (bool) dynamicParameters.UseSSL, dynamicParameters.Authentication, dynamicParameters.SessionOption, base.Credential, dynamicParameters.CertificateThumbprint);
         base.WriteItemObject(this.GetItemPSObjectWithTypeName(Name, "Container", null, null, "ComputerLevel", WsManElementObjectTypes.WSManConfigContainerElement, null), "WSMan" + '\\' + Name, true);
     }
 }
Beispiel #27
0
        /// <summary>
        /// this method creates the connection to new machine in wsman provider.
        /// This is called from New-Item.
        /// </summary>
        /// <param name="Name"></param>
        private void NewItemCreateComputerConnection(string Name)
        {
            helper = new WSManHelper(this);
            WSManProviderNewItemComputerParameters dynParams = DynamicParameters as WSManProviderNewItemComputerParameters;
            string parametersetName = "ComputerName";
            if (dynParams != null)
            {
                if (dynParams.ConnectionURI != null)
                {
                    parametersetName = "URI";

                }
                helper.CreateWsManConnection(parametersetName, dynParams.ConnectionURI, dynParams.Port, Name, dynParams.ApplicationName, dynParams.UseSSL, dynParams.Authentication, dynParams.SessionOption, this.Credential, dynParams.CertificateThumbprint);
                if (dynParams.ConnectionURI != null)
                {
                    string[] constrsplit = dynParams.ConnectionURI.OriginalString.Split(new string[] { ":" + dynParams.Port + "/" + dynParams.ApplicationName }, StringSplitOptions.None);
                    string[] constrsplit1 = constrsplit[0].Split(new string[] { "//" }, StringSplitOptions.None);
                    Name = constrsplit1[1].Trim();
                }
                WriteItemObject(GetItemPSObjectWithTypeName(Name, WSManStringLiterals.ContainerChildValue, null, null, "ComputerLevel", WsManElementObjectTypes.WSManConfigContainerElement), WSManStringLiterals.rootpath + WSManStringLiterals.DefaultPathSeparator + Name, true);
            }
            else
            {
                dynParams = new WSManProviderNewItemComputerParameters();
                helper.CreateWsManConnection(parametersetName, dynParams.ConnectionURI, dynParams.Port, Name, dynParams.ApplicationName, dynParams.UseSSL, dynParams.Authentication, dynParams.SessionOption, this.Credential, dynParams.CertificateThumbprint);
                WriteItemObject(GetItemPSObjectWithTypeName(Name, WSManStringLiterals.ContainerChildValue, null, null, "ComputerLevel", WsManElementObjectTypes.WSManConfigContainerElement), WSManStringLiterals.rootpath + WSManStringLiterals.DefaultPathSeparator + Name, true);
            }
        }
Beispiel #28
0
        /// <summary>
        /// ProcessRecord method.
        /// </summary>
        protected override void ProcessRecord()
        {

            WSManHelper helper = new WSManHelper(this);
            IWSManEx wsmanObject = (IWSManEx)new WSManClass();
            string connectionStr = String.Empty;
            connectionStr = helper.CreateConnectionString(null, port, computername, applicationname);
            IWSManSession m_SessionObj = null;
            try
            {
                m_SessionObj = helper.CreateSessionObject(wsmanObject, Authentication, null, Credential, connectionStr, CertificateThumbprint, usessl.IsPresent);
                m_SessionObj.Timeout = 1000; //1 sec. we are putting this low so that Test-WSMan can return promptly if the server goes unresponsive. 
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.LoadXml(m_SessionObj.Identify(0));
                WriteObject(xmldoc.DocumentElement);
            }
            catch(Exception)
            {
                try
                {
                    if (!String.IsNullOrEmpty(m_SessionObj.Error))
                    {
                        XmlDocument ErrorDoc = new XmlDocument();
                        ErrorDoc.LoadXml(m_SessionObj.Error);
                        InvalidOperationException ex = new InvalidOperationException(ErrorDoc.OuterXml);
                        ErrorRecord er = new ErrorRecord(ex, "WsManError", ErrorCategory.InvalidOperation, computername);
                        this.WriteError(er);
                    }
                }
                catch(Exception)
                {}
            }
            finally
            {
                if (m_SessionObj != null)
                    Dispose(m_SessionObj);
            }
        }//End BeginProcessing()
Beispiel #29
0
        protected override void ProcessRecord()
        {
            IWSManEx wSManClass = (IWSManEx)(new WSManClass());

            this.helper         = new WSManHelper(this);
            this.helper.WSManOp = "set";
            IWSManSession wSManSession = null;

            if (this.dialect != null)
            {
                if (this.dialect.ToString().Equals(this.helper.ALIAS_WQL, StringComparison.CurrentCultureIgnoreCase))
                {
                    this.dialect = new Uri(this.helper.URI_WQL_DIALECT);
                }
                if (this.dialect.ToString().Equals(this.helper.ALIAS_SELECTOR, StringComparison.CurrentCultureIgnoreCase))
                {
                    this.dialect = new Uri(this.helper.URI_SELECTOR_DIALECT);
                }
                if (this.dialect.ToString().Equals(this.helper.ALIAS_ASSOCIATION, StringComparison.CurrentCultureIgnoreCase))
                {
                    this.dialect = new Uri(this.helper.URI_ASSOCIATION_DIALECT);
                }
            }
            try
            {
                string str = this.helper.CreateConnectionString(this.connectionuri, this.port, this.computername, this.applicationname);
                if (this.connectionuri != null)
                {
                    try
                    {
                        string[] strArrays = new string[1];
                        object[] objArray  = new object[4];
                        objArray[0]  = ":";
                        objArray[1]  = this.port;
                        objArray[2]  = "/";
                        objArray[3]  = this.applicationname;
                        strArrays[0] = string.Concat(objArray);
                        string[] strArrays1 = this.connectionuri.OriginalString.Split(strArrays, StringSplitOptions.None);
                        string[] strArrays2 = new string[1];
                        strArrays2[0] = "//";
                        string[] strArrays3 = strArrays1[0].Split(strArrays2, StringSplitOptions.None);
                        this.computername = strArrays3[1].Trim();
                    }
                    catch (IndexOutOfRangeException indexOutOfRangeException)
                    {
                        this.helper.AssertError(this.helper.GetResourceMsgFromResourcetext("NotProperURI"), false, this.connectionuri);
                    }
                }
                IWSManResourceLocator wSManResourceLocator = this.helper.InitializeResourceLocator(this.optionset, this.selectorset, this.fragment, this.dialect, wSManClass, this.resourceuri);
                wSManSession = this.helper.CreateSessionObject(wSManClass, this.Authentication, this.sessionoption, this.Credential, str, this.CertificateThumbprint, this.usessl.IsPresent);
                string      rootNodeName = this.helper.GetRootNodeName(this.helper.WSManOp, wSManResourceLocator.resourceUri, null);
                string      str1         = this.helper.ProcessInput(wSManClass, this.filepath, this.helper.WSManOp, rootNodeName, this.valueset, wSManResourceLocator, wSManSession);
                XmlDocument xmlDocument  = new XmlDocument();
                try
                {
                    xmlDocument.LoadXml(wSManSession.Put(wSManResourceLocator, str1, 0));
                }
                catch (XmlException xmlException1)
                {
                    XmlException xmlException = xmlException1;
                    this.helper.AssertError(xmlException.Message, false, this.computername);
                }
                if (string.IsNullOrEmpty(this.fragment))
                {
                    base.WriteObject(xmlDocument.DocumentElement);
                }
                else
                {
                    if (xmlDocument.DocumentElement.ChildNodes.Count > 0)
                    {
                        foreach (XmlNode childNode in xmlDocument.DocumentElement.ChildNodes)
                        {
                            if (!childNode.Name.Equals(this.fragment, StringComparison.CurrentCultureIgnoreCase))
                            {
                                continue;
                            }
                            base.WriteObject(string.Concat(childNode.Name, " = ", childNode.InnerText));
                        }
                    }
                }
            }
            finally
            {
                if (!string.IsNullOrEmpty(wSManClass.Error))
                {
                    this.helper.AssertError(wSManClass.Error, true, this.resourceuri);
                }
                if (!string.IsNullOrEmpty(wSManSession.Error))
                {
                    this.helper.AssertError(wSManSession.Error, true, this.resourceuri);
                }
                if (wSManSession != null)
                {
                    this.Dispose(wSManSession);
                }
            }
        }
Beispiel #30
0
        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);
            }
        }
Beispiel #31
0
        private void DeleteDelegateSettings(string applicationname, RegistryKey rootKey, string Registry_Path, IGroupPolicyObject GPO)
        {
            WSManHelper helper = new WSManHelper(this);
            RegistryKey rKey;
            int         i         = 0;
            bool        otherkeys = false;

            try
            {
                string      Registry_Path_Credentials_Delegation = Registry_Path + @"\CredentialsDelegation";
                RegistryKey Allow_Fresh_Credential_Key           = rootKey.OpenSubKey(Registry_Path_Credentials_Delegation + @"\" + helper.Key_Allow_Fresh_Credentials, true);
                if (Allow_Fresh_Credential_Key != null)
                {
                    string[] valuenames = Allow_Fresh_Credential_Key.GetValueNames();
                    if (valuenames.Length > 0)
                    {
                        Collection <string> KeyCollection = new Collection <string>();
                        foreach (string value in valuenames)
                        {
                            object keyvalue = Allow_Fresh_Credential_Key.GetValue(value);
                            if (keyvalue != null)
                            {
                                if (!keyvalue.ToString().StartsWith(applicationname, StringComparison.OrdinalIgnoreCase))
                                {
                                    KeyCollection.Add(keyvalue.ToString());
                                    otherkeys = true;
                                }
                            }

                            Allow_Fresh_Credential_Key.DeleteValue(value);
                        }

                        foreach (string keyvalue in KeyCollection)
                        {
                            Allow_Fresh_Credential_Key.SetValue(Convert.ToString(i + 1, CultureInfo.InvariantCulture), keyvalue, RegistryValueKind.String);
                            i++;
                        }
                    }
                }

                if (!otherkeys)
                {
                    rKey = rootKey.OpenSubKey(Registry_Path_Credentials_Delegation, true);
                    if (rKey != null)
                    {
                        object regval1 = rKey.GetValue(helper.Key_Allow_Fresh_Credentials);
                        if (regval1 != null)
                        {
                            rKey.DeleteValue(helper.Key_Allow_Fresh_Credentials, false);
                        }

                        object regval2 = rKey.GetValue(helper.Key_Concatenate_Defaults_AllowFresh);
                        if (regval2 != null)
                        {
                            rKey.DeleteValue(helper.Key_Concatenate_Defaults_AllowFresh, false);
                        }

                        if (rKey.OpenSubKey(helper.Key_Allow_Fresh_Credentials) != null)
                        {
                            rKey.DeleteSubKeyTree(helper.Key_Allow_Fresh_Credentials);
                        }
                    }
                }

                GPO.Save(true, true, new Guid("35378EAC-683F-11D2-A89A-00C04FBBCFA2"), new Guid("6AD20875-336C-4e22-968F-C709ACB15814"));
            }
            catch (InvalidOperationException ex)
            {
                ErrorRecord er = new ErrorRecord(ex, "InvalidOperation", ErrorCategory.InvalidOperation, null);
                WriteError(er);
            }
            catch (ArgumentException ex)
            {
                ErrorRecord er = new ErrorRecord(ex, "InvalidArgument", ErrorCategory.InvalidArgument, null);
                WriteError(er);
            }
            catch (SecurityException ex)
            {
                ErrorRecord er = new ErrorRecord(ex, "SecurityException", ErrorCategory.SecurityError, null);
                WriteError(er);
            }
            catch (UnauthorizedAccessException ex)
            {
                ErrorRecord er = new ErrorRecord(ex, "UnauthorizedAccess", ErrorCategory.SecurityError, null);
                WriteError(er);
            }
        }
Beispiel #32
0
 private void DeleteDelegateSettings(string applicationname, RegistryKey rootKey, string Registry_Path, IGroupPolicyObject GPO)
 {
     WSManHelper helper = new WSManHelper(this);
     RegistryKey rKey;
     int i = 0;
     bool otherkeys = false;
     try
     {
         
         string Registry_Path_Credentials_Delegation = Registry_Path + @"\CredentialsDelegation";
         RegistryKey Allow_Fresh_Credential_Key = rootKey.OpenSubKey(Registry_Path_Credentials_Delegation + @"\" + helper.Key_Allow_Fresh_Credentials, true);
         if (Allow_Fresh_Credential_Key != null)
         {
             string[] valuenames = Allow_Fresh_Credential_Key.GetValueNames();
             if (valuenames.Length > 0)
             {
                 Collection<string> KeyCollection = new Collection<string>();
                 foreach (string value in valuenames)
                 {
                     object keyvalue = Allow_Fresh_Credential_Key.GetValue(value);
                     if (keyvalue != null)
                     {
                         if (!keyvalue.ToString().StartsWith(applicationname, StringComparison.OrdinalIgnoreCase))
                         {
                             KeyCollection.Add(keyvalue.ToString());
                             otherkeys = true;
                         }
                     }
                     Allow_Fresh_Credential_Key.DeleteValue(value);
                 }
                 foreach (string keyvalue in KeyCollection)
                 {
                     Allow_Fresh_Credential_Key.SetValue(Convert.ToString(i + 1, CultureInfo.InvariantCulture), keyvalue, RegistryValueKind.String);
                     i++;
                 }
             }
         }
         if (!otherkeys)
         {
             rKey = rootKey.OpenSubKey(Registry_Path_Credentials_Delegation, true);
             if (rKey != null)
             {
                 object regval1 = rKey.GetValue(helper.Key_Allow_Fresh_Credentials);
                 if (regval1 != null)
                 {
                     rKey.DeleteValue(helper.Key_Allow_Fresh_Credentials, false);
                 }
                 object regval2 = rKey.GetValue(helper.Key_Concatenate_Defaults_AllowFresh);
                 if (regval2 != null)
                 {
                     rKey.DeleteValue(helper.Key_Concatenate_Defaults_AllowFresh, false);
                 }
                 if (rKey.OpenSubKey(helper.Key_Allow_Fresh_Credentials) != null)
                 {
                     rKey.DeleteSubKeyTree(helper.Key_Allow_Fresh_Credentials);
                 }
             }
         }
         GPO.Save(true, true, new Guid("35378EAC-683F-11D2-A89A-00C04FBBCFA2"), new Guid("6AD20875-336C-4e22-968F-C709ACB15814"));
     }
     catch (InvalidOperationException ex)
     {
         ErrorRecord er = new ErrorRecord(ex, "InvalidOperation", ErrorCategory.InvalidOperation, null);
         WriteError(er);
     }
     catch (ArgumentException ex)
     {
         ErrorRecord er = new ErrorRecord(ex, "InvalidArgument", ErrorCategory.InvalidArgument, null);
         WriteError(er);
     }
     catch (SecurityException ex)
     {
         ErrorRecord er = new ErrorRecord(ex, "SecurityException", ErrorCategory.SecurityError, null);
         WriteError(er);
     }
     catch (UnauthorizedAccessException ex)
     {
         ErrorRecord er = new ErrorRecord(ex, "UnauthorizedAccess", ErrorCategory.SecurityError, null);
         WriteError(er);
     }
 }
Beispiel #33
0
        /// <summary>
        /// Method to begin processing.
        /// </summary>
        protected override void BeginProcessing()
        {
            // If not running elevated, then throw an "elevation required" error message.
            WSManHelper.ThrowIfNotAdministrator();
            helper = new WSManHelper(this);
            IWSManSession m_SessionObj = null;

            try
            {
                IWSManEx wsmanObject = (IWSManEx) new WSManClass();
                m_SessionObj = (IWSManSession)wsmanObject.CreateSession(null, 0, null);
                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;
                }
                // The application name MUST be "wsman" as wsman got approval from security
                // folks who suggested to register the SPN with name "wsman".
                string applicationname = "wsman";
                string credsspResult   = GetDelegateSettings(applicationname);
                if (string.IsNullOrEmpty(credsspResult))
                {
                    WriteObject(helper.GetResourceMsgFromResourcetext("NoDelegateFreshCred"));
                }
                else
                {
                    WriteObject(helper.GetResourceMsgFromResourcetext("DelegateFreshCred") + credsspResult);
                }

                // Get the server side settings
                result = m_SessionObj.Get(helper.Service_CredSSP_Uri, 0);
                node   = helper.GetXmlNode(result, helper.CredSSP_SNode, helper.Service_CredSSP_XMLNmsp);
                if (node == null)
                {
                    InvalidOperationException ex = new InvalidOperationException();
                    ErrorRecord er = new ErrorRecord(ex, helper.GetResourceMsgFromResourcetext("WinrmNotConfigured"), ErrorCategory.InvalidOperation, null);
                    WriteError(er);
                    return;
                }

                if (node.InnerText.Equals("true", StringComparison.OrdinalIgnoreCase))
                {
                    WriteObject(helper.GetResourceMsgFromResourcetext("CredSSPServiceConfigured"));
                }
                else
                {
                    WriteObject(helper.GetResourceMsgFromResourcetext("CredSSPServiceNotConfigured"));
                }
            }
            catch (UnauthorizedAccessException ex)
            {
                ErrorRecord er = new ErrorRecord(ex, "UnauthorizedAccess", ErrorCategory.PermissionDenied, null);
                WriteError(er);
            }
            catch (SecurityException ex)
            {
                ErrorRecord er = new ErrorRecord(ex, "SecurityException", ErrorCategory.InvalidOperation, null);
                WriteError(er);
            }
            catch (ArgumentException ex)
            {
                ErrorRecord er = new ErrorRecord(ex, "InvalidArgument", ErrorCategory.InvalidOperation, null);
                WriteError(er);
            }
            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);
                }
            }
        }
Beispiel #34
0
        /// <summary>
        /// BeginProcessing method.
        /// </summary>      
        protected override void BeginProcessing()
        {
            //If not running elevated, then throw an "elevation required" error message.
            WSManHelper.ThrowIfNotAdministrator();
            helper = new WSManHelper(this);
#if !CORECLR
            if (Environment.OSVersion.Version.Major < 6)
            {
                //OS is XP/Win2k3. Throw error.
                string message = helper.FormatResourceMsgFromResourcetext("CmdletNotAvailable");
                throw new InvalidOperationException(message);
            }
#endif
            //If not running elevated, then throw an "elevation required" error message.
            WSManHelper.ThrowIfNotAdministrator();

            // DelegateComputer cannot be specified when Role is other than client
            if ((delegatecomputer != null) && !Role.Equals(Client, StringComparison.OrdinalIgnoreCase))
            {
                string message = helper.FormatResourceMsgFromResourcetext("CredSSPRoleAndDelegateCannotBeSpecified",
                    "DelegateComputer",
                    "Role",
                    Role,
                    Client);

                throw new InvalidOperationException(message);
            }

            // DelegateComputer must be specified when Role is client
            if (Role.Equals(Client, StringComparison.OrdinalIgnoreCase) && (delegatecomputer == null))
            {
                string message = helper.FormatResourceMsgFromResourcetext("CredSSPClientAndDelegateMustBeSpecified",
                    "DelegateComputer",
                    "Role",
                    Client);

                throw new InvalidOperationException(message);
            }

            if (Role.Equals(Client, StringComparison.OrdinalIgnoreCase))
            {
                EnableClientSideSettings();
            }

            if (Role.Equals(Server, StringComparison.OrdinalIgnoreCase))
            {
                EnableServerSideSettings();
            }
        }//End BeginProcessing()
Beispiel #35
0
        private void DisableClientSideSettings()
        {
            WSManHelper   helper       = new WSManHelper(this);
            IWSManSession m_SessionObj = CreateWSManSession();

            if (m_SessionObj == 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 == 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);
                }
            }
            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);
                }
            }
        }
Beispiel #36
0
        /// <summary>
        /// BeginProcessing method.
        /// </summary>
        protected override void BeginProcessing()
        {
            WSManHelper helper = new WSManHelper(this);

            if (proxyauthentication.Equals(ProxyAuthentication.Basic) || proxyauthentication.Equals(ProxyAuthentication.Digest))
            {
                if (_proxycredential == null)
                {
                    InvalidOperationException ex = new InvalidOperationException(helper.GetResourceMsgFromResourcetext("NewWSManSessionOptionCred"));
                    ErrorRecord er = new ErrorRecord(ex, "InvalidOperationException", ErrorCategory.InvalidOperation, null);
                    WriteError(er);
                    return;
                }
            }

            if ((_proxycredential != null) && (proxyauthentication == 0))
            {
                InvalidOperationException ex = new InvalidOperationException(helper.GetResourceMsgFromResourcetext("NewWSManSessionOptionAuth"));
                ErrorRecord er = new ErrorRecord(ex, "InvalidOperationException", ErrorCategory.InvalidOperation, null);
                WriteError(er);
                return;
            }



            //Creating the Session Object
            SessionOption objSessionOption = new SessionOption();

            objSessionOption.SPNPort = spnport;
            objSessionOption.UseUtf16 = useutf16;
            objSessionOption.SkipCNCheck = skipcncheck;
            objSessionOption.SkipCACheck = skipcacheck;
            objSessionOption.OperationTimeout = operationtimeout;
            objSessionOption.SkipRevocationCheck = skiprevocationcheck;
            //Proxy Settings
            objSessionOption.ProxyAccessType = _proxyacesstype;
            objSessionOption.ProxyAuthentication = proxyauthentication;

            if (noencryption)
            {
                objSessionOption.UseEncryption = false;
            }
            if (_proxycredential != null)
            {
                NetworkCredential nwCredentials = _proxycredential.GetNetworkCredential();
                objSessionOption.ProxyCredential = nwCredentials;
            }
            WriteObject(objSessionOption);

        }//End BeginProcessing()
Beispiel #37
0
        protected override void ProcessRecord()
        {
            WSManHelper wSManHelper = new WSManHelper(this);
            IWSManEx    wSManClass  = (IWSManEx)(new WSManClass());

            wSManHelper.WSManOp = "remove";
            IWSManSession wSManSession = null;

            try
            {
                string str = wSManHelper.CreateConnectionString(this.connectionuri, this.port, this.computername, this.applicationname);
                if (this.connectionuri != null)
                {
                    try
                    {
                        string[] strArrays = new string[1];
                        object[] objArray  = new object[4];
                        objArray[0]  = ":";
                        objArray[1]  = this.port;
                        objArray[2]  = "/";
                        objArray[3]  = this.applicationname;
                        strArrays[0] = string.Concat(objArray);
                        string[] strArrays1 = this.connectionuri.OriginalString.Split(strArrays, StringSplitOptions.None);
                        string[] strArrays2 = new string[1];
                        strArrays2[0] = "//";
                        string[] strArrays3 = strArrays1[0].Split(strArrays2, StringSplitOptions.None);
                        this.computername = strArrays3[1].Trim();
                    }
                    catch (IndexOutOfRangeException indexOutOfRangeException)
                    {
                        wSManHelper.AssertError(wSManHelper.GetResourceMsgFromResourcetext("NotProperURI"), false, this.connectionuri);
                    }
                }
                wSManHelper.InitializeResourceLocator(this.optionset, this.selectorset, null, null, wSManClass, this.resourceuri);
                wSManSession = wSManHelper.CreateSessionObject(wSManClass, this.Authentication, this.sessionoption, this.Credential, str, this.CertificateThumbprint, this.usessl.IsPresent);
                string uRIWithFilter = wSManHelper.GetURIWithFilter(this.resourceuri.ToString(), null, this.selectorset, wSManHelper.WSManOp);
                try
                {
                    wSManSession.Delete(uRIWithFilter, 0);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    wSManHelper.AssertError(exception.Message, false, this.computername);
                }
            }
            finally
            {
                if (!string.IsNullOrEmpty(wSManSession.Error))
                {
                    wSManHelper.AssertError(wSManSession.Error, true, this.resourceuri);
                }
                if (!string.IsNullOrEmpty(wSManClass.Error))
                {
                    wSManHelper.AssertError(wSManClass.Error, true, this.resourceuri);
                }
                if (wSManSession != null)
                {
                    this.Dispose(wSManSession);
                }
            }
        }