Ejemplo n.º 1
0
 public virtual void AddDestinationCredentials(CimCredential credential)
 {
     if (credential != null)
     {
         this.AssertNotDisposed();
         return;
     }
     else
     {
         throw new ArgumentNullException("credential");
     }
 }
Ejemplo n.º 2
0
		public virtual void AddDestinationCredentials(CimCredential credential)
		{
			if (credential != null)
			{
				this.AssertNotDisposed();
				return;
			}
			else
			{
				throw new ArgumentNullException("credential");
			}
		}
Ejemplo n.º 3
0
        /// <summary>
        /// Sets a Proxy Credential
        /// </summary>
        /// <param name="credential"></param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="credential"/> is <c>null</c></exception>
        public void AddProxyCredentials(CimCredential credential)
        {
            if (credential == null)
            {
                throw new ArgumentNullException("credential");
            }
            this.AssertNotDisposed();

            // TODO: Not trivial to port AddProxyCredentials
            //MI_Result result = this.DestinationOptionsHandleOnDemand.AddProxyCredentials(credential.GetCredential());
            //CimException.ThrowIfMiResultFailure(result);
        }
Ejemplo n.º 4
0
 public override void AddDestinationCredentials(CimCredential credential)
 {
     if (credential != null)
     {
         base.AssertNotDisposed();
         MiResult miResult = DestinationOptionsMethods.AddDestinationCredentials(base.DestinationOptionsHandleOnDemand, credential.GetCredential());
         CimException.ThrowIfMiResultFailure(miResult);
         return;
     }
     else
     {
         throw new ArgumentNullException("credential");
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// AddCredentials
        /// </summary>
        /// <param name="optionName"></param>
        /// <param name="optionValue"></param>
        /// <param name="flags"></param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="optionName"/> is <c>null</c></exception>
        public void AddCredentials(string optionName, CimCredential optionValue, UInt32 flags)
        {
            if (string.IsNullOrWhiteSpace(optionName) || optionValue == null)
            {
                throw new ArgumentNullException("optionName");
            }
            if (optionValue == null)
            {
                throw new ArgumentNullException("optionValue");
            }
            this.AssertNotDisposed();

            // TODO: Implement this
            //MI_Result result = this._subscriptionDeliveryOptionsHandle.SubscriptionDeliveryOptionsMethods.AddCredentials(optionName, optionValue.GetCredential(), flags);
            //CimException.ThrowIfMiResultFailure(result);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Sets a Destination Credential
        /// </summary>
        /// <param name="credential"></param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="credential"/> is <c>null</c></exception>
        public void AddDestinationCredentials(CimCredential credential)
        {
            // TODO: Once credentials are working, uncomment and fix

            /*
             *  if (credential == null)
             *  {
             *      throw new ArgumentNullException("credential");
             *  }
             *  this.AssertNotDisposed();
             *
             * MI_UserCredentials nativeCredential;
             * SecureString securePassword = credential.GetSecureString();
             * IntPtr passwordPtr = IntPtr.Zero;
             * if( securePassword != null && securePassword.Length > 0)
             * {
             #if(!_CORECLR)
             * passwordPtr = Marshal.SecureStringToGlobalAllocUnicode(securePassword);
             #else
             * passwordPtr = SecureStringMarshal.SecureStringToCoTaskMemUnicode(securePassword);
             #endif
             * nativeCredential.usernamePassword.password = passwordPtr;
             * }
             * else
             * {
             * nativeCredential.usernamePassword.password = null;
             * }
             *
             * MI_Result result = this.DestinationOptionsHandleOnDemand.AddCredentials("__MI_DESTINATIONOPTIONS_DESTINATION_CREDENTIALS",
             *  nativeCredential,
             *  MI_DestinationOptionFlags.Unused);
             *
             * if ( passwordPtr != IntPtr.Zero )
             * {
             #if(!_CORECLR)
             * Marshal.FreeHGlobal(passwordPtr);
             #else
             * SecureStringMarshal.ZeroFreeCoTaskMemUnicode(passwordPtr);
             #endif
             * }
             *  CimException.ThrowIfMiResultFailure(result);
             */
        }
Ejemplo n.º 7
0
 public void AddCredentials(string optionName, CimCredential optionValue, uint flags)
 {
     if (string.IsNullOrWhiteSpace(optionName) || optionValue == null)
     {
         throw new ArgumentNullException("optionName");
     }
     else
     {
         if (optionValue != null)
         {
             this.AssertNotDisposed();
             MiResult miResult = MiResult.OK;                     //TODO: SubscriptionDeliveryOptionsMethods.AddCredentials(this._subscriptionDeliveryOptionsHandle, optionName, optionValue.GetCredential(), flags);
             CimException.ThrowIfMiResultFailure(miResult);
             return;
         }
         else
         {
             throw new ArgumentNullException("optionValue");
         }
     }
 }
		public void AddCredentials(string optionName, CimCredential optionValue, uint flags)
		{
			if (string.IsNullOrWhiteSpace(optionName) || optionValue == null)
			{
				throw new ArgumentNullException("optionName");
			}
			else
			{
				if (optionValue != null)
				{
					this.AssertNotDisposed();
					MiResult miResult = MiResult.OK; //TODO: SubscriptionDeliveryOptionsMethods.AddCredentials(this._subscriptionDeliveryOptionsHandle, optionName, optionValue.GetCredential(), flags);
					CimException.ThrowIfMiResultFailure(miResult);
					return;
				}
				else
				{
					throw new ArgumentNullException("optionValue");
				}
			}
		}
Ejemplo n.º 9
0
		internal void NewCimSession(NewCimSessionCommand cmdlet, CimSessionOptions sessionOptions, CimCredential credential)
		{
			string localhostComputerName;
			DebugHelper.WriteLogEx();
			IEnumerable<string> computerNames = ConstValue.GetComputerNames(cmdlet.ComputerName);
			foreach (string computerName in computerNames)
			{
				if (sessionOptions == null)
				{
					DebugHelper.WriteLog("Create CimSessionOption due to NewCimSessionCommand has null sessionoption", 1);
					sessionOptions = CimSessionProxy.CreateCimSessionOption(computerName, cmdlet.OperationTimeoutSec, credential);
				}
				CimSessionProxy cimSessionProxyTestConnection = new CimSessionProxyTestConnection(computerName, sessionOptions);
				if (computerName == ConstValue.NullComputerName)
				{
					localhostComputerName = ConstValue.LocalhostComputerName;
				}
				else
				{
					localhostComputerName = computerName;
				}
				string str = localhostComputerName;
				CimSessionWrapper cimSessionWrapper = new CimSessionWrapper(0, Guid.Empty, cmdlet.Name, str, cimSessionProxyTestConnection.CimSession, cimSessionProxyTestConnection.Protocol);
				CimNewSession.CimTestCimSessionContext cimTestCimSessionContext = new CimNewSession.CimTestCimSessionContext(cimSessionProxyTestConnection, cimSessionWrapper);
				cimSessionProxyTestConnection.ContextObject = cimTestCimSessionContext;
				SwitchParameter skipTestConnection = cmdlet.SkipTestConnection;
				if (!skipTestConnection.IsPresent)
				{
					this.cimTestSession.TestCimSession(computerName, cimSessionProxyTestConnection);
				}
				else
				{
					this.AddSessionToCache(cimSessionProxyTestConnection.CimSession, cimTestCimSessionContext, new CmdletOperationBase(cmdlet));
				}
			}
		}
Ejemplo n.º 10
0
        /// <summary>
        /// Create a new <see cref="CimSession"/> base on given cmdlet
        /// and its parameter
        /// </summary>        
        /// <param name="cmdlet"></param>
        /// <param name="sessionOptions"></param>
        /// <param name="credential"></param>
        internal void NewCimSession(NewCimSessionCommand cmdlet,
            CimSessionOptions sessionOptions,
            CimCredential credential)
        {
            DebugHelper.WriteLogEx();

            IEnumerable<string> computerNames = ConstValue.GetComputerNames(cmdlet.ComputerName);
            foreach (string computerName in computerNames)
            {
                CimSessionProxy proxy;
                if (sessionOptions == null)
                {
                    DebugHelper.WriteLog("Create CimSessionOption due to NewCimSessionCommand has null sessionoption", 1);
                    sessionOptions = CimSessionProxy.CreateCimSessionOption(computerName,
                        cmdlet.OperationTimeoutSec, credential);
                }
                proxy = new CimSessionProxyTestConnection(computerName, sessionOptions);
                string computerNameValue = (computerName == ConstValue.NullComputerName) ? ConstValue.LocalhostComputerName : computerName;
                CimSessionWrapper wrapper = new CimSessionWrapper(0, Guid.Empty, cmdlet.Name, computerNameValue, proxy.CimSession, proxy.Protocol);
                CimTestCimSessionContext context = new CimTestCimSessionContext(proxy, wrapper);
                proxy.ContextObject = context;
                // Skip test the connection if user intend to
                if(cmdlet.SkipTestConnection.IsPresent)
                {
                    AddSessionToCache(proxy.CimSession, context, new CmdletOperationBase(cmdlet));
                }
                else
                {
                    //CimSession will be returned as part of TestConnection
                    this.cimTestSession.TestCimSession(computerName, proxy); 
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Create credentials based on given authentication type and PSCredential
        /// </summary>
        /// <param name="psCredentials"></param>
        /// <param name="passwordAuthentication"></param>
        /// <returns></returns>
        internal CimCredential CreateCimCredentials(PSCredential psCredentials,
            PasswordAuthenticationMechanism passwordAuthentication,
            string operationName,
            string parameterName)
        {
            DebugHelper.WriteLogEx("PSCredential:{0}; PasswordAuthenticationMechanism:{1}; operationName:{2}; parameterName:{3}.", 0, psCredentials, passwordAuthentication, operationName, parameterName);

            CimCredential credentials = null;
            if (psCredentials != null)
            {
                NetworkCredential networkCredential = psCredentials.GetNetworkCredential();
                DebugHelper.WriteLog("Domain:{0}; UserName:{1}; Password:{2}.", 1, networkCredential.Domain, networkCredential.UserName, psCredentials.Password);
                credentials = new CimCredential(passwordAuthentication, networkCredential.Domain, networkCredential.UserName, psCredentials.Password);

            }
            else
            {
                ImpersonatedAuthenticationMechanism impersonatedAuthentication;
                switch (passwordAuthentication)
                {
                    case PasswordAuthenticationMechanism.Default:
                        impersonatedAuthentication = ImpersonatedAuthenticationMechanism.None;
                        break;
                    case PasswordAuthenticationMechanism.Negotiate:
                        impersonatedAuthentication = ImpersonatedAuthenticationMechanism.Negotiate;
                        break;
                    case PasswordAuthenticationMechanism.Kerberos:
                        impersonatedAuthentication = ImpersonatedAuthenticationMechanism.Kerberos;
                        break;
                    case PasswordAuthenticationMechanism.NtlmDomain:
                        impersonatedAuthentication = ImpersonatedAuthenticationMechanism.NtlmDomain;
                        break;
                    default:
                        ThrowInvalidAuthenticationTypeError(operationName, parameterName, passwordAuthentication);
                        return null;
                }
                credentials = new CimCredential(impersonatedAuthentication);
            }
            DebugHelper.WriteLogEx("return credential {0}", 1, credentials);
            return credentials;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// <para>
        /// Create <see cref="CimSessionOptions"/> based on the given computerName,
        /// timeout and credential
        /// </para>
        /// </summary>
        /// <param name="computerName"></param>
        /// <param name="timeout"></param>
        /// <param name="credential"></param>
        /// <returns></returns>
        internal static CimSessionOptions CreateCimSessionOption(string computerName,
            UInt32 timeout, CimCredential credential)
        {
            DebugHelper.WriteLogEx();

            CimSessionOptions option;
            if (ConstValue.IsDefaultComputerName(computerName))
            {
                DebugHelper.WriteLog("<<<<<<<<<< Use protocol DCOM  {0}", 1, computerName);
                option = new DComSessionOptions();
            }
            else
            {
                DebugHelper.WriteLog("<<<<<<<<<< Use protocol WSMAN {0}", 1, computerName);
                option = new WSManSessionOptions();
            }
            if (timeout != 0)
            {
                option.Timeout = TimeSpan.FromSeconds((double)timeout);
            }
            if (credential != null)
            {
                option.AddDestinationCredentials(credential);
            }
            DebugHelper.WriteLogEx("returned option :{0}.", 1, option);
            return option;
        }
Ejemplo n.º 13
0
		internal void BuildSessionOptions (out CimSessionOptions outputOptions, out CimCredential outputCredential)
		{
			WSManSessionOptions wSManSessionOption;
			PasswordAuthenticationMechanism authentication;
			DebugHelper.WriteLogEx ();
			CimSessionOptions dComSessionOption = null;

			/* Requires Authentication for Remote Host */
			if (this.credential == null && ComputerName != null) {
				bool requiredAuth = false;
				foreach(var c in ComputerName)
				{
					if (c != null && !c.Equals("localhost", StringComparison.OrdinalIgnoreCase))
					{
						requiredAuth = true;
						break;
					}
				}
				if (requiredAuth)
				{
					TrySetCredentials();
				}
			}

			if (this.SessionOption != null) {
				if (this.SessionOption as WSManSessionOptions == null) {
					dComSessionOption = new DComSessionOptions (this.sessionOption as DComSessionOptions);
				} else {
					dComSessionOption = new WSManSessionOptions (this.sessionOption as WSManSessionOptions);
				}
			}
			outputOptions = null;
			outputCredential = null;
			if (dComSessionOption != null) {
				DComSessionOptions dComSessionOption1 = dComSessionOption as DComSessionOptions;
				if (dComSessionOption1 != null) {
					bool flag = false;
					string empty = string.Empty;
					if (this.CertificateThumbprint != null) {
						flag = true;
						empty = "CertificateThumbprint";
					}
					if (this.portSet) {
						flag = true;
						empty = "Port";
					}
					if (flag) {
						base.ThrowConflictParameterWasSet ("New-CimSession", empty, "DComSessionOptions");
						return;
					}
				}
			}

			if (this.portSet || this.CertificateThumbprint != null) {
				if (dComSessionOption == null) {
					wSManSessionOption = new WSManSessionOptions ();
				} else {
					wSManSessionOption = dComSessionOption as WSManSessionOptions;
				}
				WSManSessionOptions port = wSManSessionOption;
				if (this.portSet) {
					port.DestinationPort = this.Port;
					this.portSet = false;
				}
				if (this.CertificateThumbprint != null) {
					CimCredential cimCredential = new CimCredential (CertificateAuthenticationMechanism.Default, this.CertificateThumbprint);
					port.AddDestinationCredentials (cimCredential);
				}
				dComSessionOption = port;
			}
			if (this.operationTimeoutSet && dComSessionOption != null) {
				dComSessionOption.Timeout = TimeSpan.FromSeconds ((double)((float)this.OperationTimeoutSec));
			}

			if (this.authenticationSet || this.credential != null) {
				if (this.authenticationSet) {
					authentication = this.Authentication;
				} else {
					authentication = PasswordAuthenticationMechanism.Default;
				}
				PasswordAuthenticationMechanism passwordAuthenticationMechanism = authentication;
				if (this.authenticationSet) {
					this.authenticationSet = false;
				}
				CimCredential cimCredential1 = base.CreateCimCredentials (this.Credential, passwordAuthenticationMechanism, "New-CimSession", "Authentication");
				if (cimCredential1 != null) {
					object[] objArray = new object[1];
					objArray [0] = cimCredential1;
					DebugHelper.WriteLog ("Credentials: {0}", 1, objArray);
					outputCredential = cimCredential1;
					if (dComSessionOption != null) {
						object[] objArray1 = new object[1];
						objArray1 [0] = dComSessionOption;
						DebugHelper.WriteLog ("Add credentials to option: {0}", 1, objArray1);
						dComSessionOption.AddDestinationCredentials (cimCredential1);
					}
				} else {
					return;
				}
			}
		
			object[] objArray2 = new object[1];
			objArray2[0] = outputOptions;
			DebugHelper.WriteLogEx("Set outputOptions: {0}", 1, objArray2);
			outputOptions = dComSessionOption;
		}
Ejemplo n.º 14
0
		public override void AddDestinationCredentials(CimCredential credential)
		{
			if (credential != null)
			{
				base.AssertNotDisposed();
				MiResult miResult = DestinationOptionsMethods.AddDestinationCredentials(base.DestinationOptionsHandleOnDemand, credential.GetCredential());
				CimException.ThrowIfMiResultFailure(miResult);
				return;
			}
			else
			{
				throw new ArgumentNullException("credential");
			}
		}
Ejemplo n.º 15
0
		internal CimCredential CreateCimCredentials(PSCredential psCredentials, PasswordAuthenticationMechanism passwordAuthentication, string operationName, string parameterName)
		{
			CimCredential cimCredential;
			ImpersonatedAuthenticationMechanism impersonatedAuthenticationMechanism;
			object[] objArray = new object[4];
			objArray[0] = psCredentials;
			objArray[1] = passwordAuthentication;
			objArray[2] = operationName;
			objArray[3] = parameterName;
			DebugHelper.WriteLogEx("PSCredential:{0}; PasswordAuthenticationMechanism:{1}; operationName:{2}; parameterName:{3}.", 0, objArray);
			if (psCredentials == null)
			{
				PasswordAuthenticationMechanism passwordAuthenticationMechanism = passwordAuthentication;
				if (passwordAuthenticationMechanism == PasswordAuthenticationMechanism.Default)
				{
					impersonatedAuthenticationMechanism = ImpersonatedAuthenticationMechanism.None;
				}
				else if (passwordAuthenticationMechanism == PasswordAuthenticationMechanism.Digest || passwordAuthenticationMechanism == PasswordAuthenticationMechanism.Basic)
				{
					this.ThrowInvalidAuthenticationTypeError(operationName, parameterName, passwordAuthentication);
					return null;
				}
				else if (passwordAuthenticationMechanism == PasswordAuthenticationMechanism.Negotiate)
				{
					impersonatedAuthenticationMechanism = ImpersonatedAuthenticationMechanism.Negotiate;
				}
				else if (passwordAuthenticationMechanism == PasswordAuthenticationMechanism.Kerberos)
				{
					impersonatedAuthenticationMechanism = ImpersonatedAuthenticationMechanism.Kerberos;
				}
				else if (passwordAuthenticationMechanism == PasswordAuthenticationMechanism.NtlmDomain)
				{
					impersonatedAuthenticationMechanism = ImpersonatedAuthenticationMechanism.NtlmDomain;
				}
				else
				{
					this.ThrowInvalidAuthenticationTypeError(operationName, parameterName, passwordAuthentication);
					return null;
				}
				cimCredential = new CimCredential(impersonatedAuthenticationMechanism);
			}
			else
			{
				NetworkCredential networkCredential = psCredentials.GetNetworkCredential();
				/* Send directly PSCredentials SecurePassword if NetworkCredentials password is only encrypted */
				object[] domain = new object[3];
				domain[0] = networkCredential.Domain;
				domain[1] = networkCredential.UserName;
				domain[2] = networkCredential.SecurePassword ?? psCredentials.Password;
				DebugHelper.WriteLog("Domain:{0}; UserName:{1}; Password:{2}.", 1, domain);
				cimCredential = new CimCredential(passwordAuthentication, networkCredential.Domain, networkCredential.UserName, networkCredential.SecurePassword ?? psCredentials.Password);
			}
			object[] objArray1 = new object[1];
			objArray1[0] = cimCredential;
			DebugHelper.WriteLogEx("return credential {0}", 1, objArray1);
			return cimCredential;
			this.ThrowInvalidAuthenticationTypeError(operationName, parameterName, passwordAuthentication);
			return null;
		}
Ejemplo n.º 16
0
 /// <summary>
 /// Create WSMANSessionOptions
 /// </summary>
 /// <returns></returns>
 internal WSManSessionOptions CreateWSMANSessionOptions()
 {
     WSManSessionOptions wsmanoptions = new WSManSessionOptions();
     if (this.noEncryptionSet)
     {
         wsmanoptions.NoEncryption = true;
         this.noEncryptionSet = false;
     }
     else
     {
         wsmanoptions.NoEncryption = false;
     }
     if (this.skipCACheckSet)
     {
         wsmanoptions.CertCACheck = false;
         this.skipCACheckSet = false;
     }
     else
     {
         wsmanoptions.CertCACheck = true;
     }
     if (this.skipCNCheckSet)
     {
         wsmanoptions.CertCNCheck = false;
         this.skipCNCheckSet = false;
     }
     else
     {
         wsmanoptions.CertCNCheck = true;
     }
     if (this.skipRevocationCheckSet)
     {
         wsmanoptions.CertRevocationCheck = false;
         this.skipRevocationCheckSet = false;
     }
     else
     {
         wsmanoptions.CertRevocationCheck = true;
     }
     if (this.encodeportinserviceprincipalnameSet)
     {
         wsmanoptions.EncodePortInServicePrincipalName = this.EncodePortInServicePrincipalName;
         this.encodeportinserviceprincipalnameSet = false;
     }
     else
     {
         wsmanoptions.EncodePortInServicePrincipalName = false;
     }
     if (this.encodingSet)
     {
         wsmanoptions.PacketEncoding = this.Encoding;
     }
     else
     {
         wsmanoptions.PacketEncoding = PacketEncoding.Utf8;
     }
     if (this.HttpPrefix != null)
     {
         wsmanoptions.HttpUrlPrefix = this.HttpPrefix;
     }
     if (this.maxenvelopesizekbSet)
     {
         wsmanoptions.MaxEnvelopeSize = this.MaxEnvelopeSizeKB;
     }
     else
     {
         wsmanoptions.MaxEnvelopeSize = 0;
     }
     if (!String.IsNullOrWhiteSpace(this.ProxyCertificateThumbprint))
     {
         CimCredential credentials = new CimCredential(CertificateAuthenticationMechanism.Default, this.ProxyCertificateThumbprint);
         wsmanoptions.AddProxyCredentials(credentials);
     }
     if (this.proxyauthenticationSet)
     {
         this.proxyauthenticationSet = false;
         DebugHelper.WriteLogEx("create credential", 1);
         CimCredential credentials = CreateCimCredentials(this.ProxyCredential, this.ProxyAuthentication, @"New-CimSessionOption", @"ProxyAuthentication");
         if (credentials != null)
         {
             try
             {
                 DebugHelper.WriteLogEx("Add proxy credential", 1);
                 wsmanoptions.AddProxyCredentials(credentials);
             }
             catch (Exception ex)
             {
                 DebugHelper.WriteLogEx(ex.ToString(), 1);
                 throw ex;
             }
         }
     }
     if (this.proxytypeSet)
     {
         wsmanoptions.ProxyType = this.ProxyType;
         this.proxytypeSet = false;
     }
     else
     {
         wsmanoptions.ProxyType = Options.ProxyType.WinHttp;
     }
     if (this.usesslSet)
     {
         wsmanoptions.UseSsl = this.UseSsl;
         this.usesslSet = false;
     }
     else
     {
         wsmanoptions.UseSsl = false;
     }
     wsmanoptions.DestinationPort = 0;
     return wsmanoptions;
 }
Ejemplo n.º 17
0
        }//End EndProcessing()
        #endregion

        #region helper methods

        /// <summary>
        /// Build a CimSessionOptions, used to create CimSession
        /// </summary>
        /// <returns>Null means no prefer CimSessionOptions</returns>
        internal void BuildSessionOptions(out CimSessionOptions outputOptions, out CimCredential outputCredential)
        {
            DebugHelper.WriteLogEx();

            CimSessionOptions options = null;
            if (this.SessionOption != null)
            {
                // clone the sessionOption object
                if (this.SessionOption is WSManSessionOptions)
                {
                    options = new WSManSessionOptions(this.sessionOption as WSManSessionOptions);
                }
                else
                {
                    options = new DComSessionOptions(this.sessionOption as DComSessionOptions);
                }
            }
            outputOptions = null;
            outputCredential = null;
            if (options != null)
            {
                DComSessionOptions dcomOptions = (options as DComSessionOptions);
                if (dcomOptions != null)
                {
                    bool conflict = false;
                    string parameterName = string.Empty;
                    if (this.CertificateThumbprint != null)
                    {
                        conflict = true;
                        parameterName = @"CertificateThumbprint";
                    }
                    if (portSet)
                    {
                        conflict = true;
                        parameterName = @"Port";
                    }
                    if (conflict)
                    {
                        ThrowConflictParameterWasSet(@"New-CimSession", parameterName, @"DComSessionOptions");
                        return;
                    }
                }
            }
            if (portSet || (this.CertificateThumbprint != null))
            {
                WSManSessionOptions wsmanOptions = (options == null) ? new WSManSessionOptions() : options as WSManSessionOptions;
                if (portSet)
                {
                    wsmanOptions.DestinationPort = this.Port;
                    portSet = false;
                }
                if (this.CertificateThumbprint != null)
                {
                    CimCredential credentials = new CimCredential(CertificateAuthenticationMechanism.Default, this.CertificateThumbprint);
                    wsmanOptions.AddDestinationCredentials(credentials);
                }
                options = wsmanOptions;
            }
            if (this.operationTimeoutSet)
            {
                if (options != null)
                {
                    options.Timeout = TimeSpan.FromSeconds((double)this.OperationTimeoutSec);
                }
            }
            if (this.authenticationSet || (this.credential != null))
            {
                PasswordAuthenticationMechanism authentication = this.authenticationSet ? this.Authentication : PasswordAuthenticationMechanism.Default;
                if (this.authenticationSet)
                {
                    this.authenticationSet = false;
                }
                CimCredential credentials = CreateCimCredentials(this.Credential, authentication, @"New-CimSession", @"Authentication");
                if (credentials == null)
                {
                    return;
                }

                DebugHelper.WriteLog("Credentials: {0}", 1, credentials);
                outputCredential = credentials;
                if (options != null)
                {
                    DebugHelper.WriteLog("Add credentials to option: {0}", 1, options);
                    options.AddDestinationCredentials(credentials);
                }
            }
            DebugHelper.WriteLogEx("Set outputOptions: {0}", 1, outputOptions);
            outputOptions = options;
        }
Ejemplo n.º 18
0
		internal static CimSessionOptions CreateCimSessionOption(string computerName, uint timeout, CimCredential credential)
		{
			CimSessionOptions wSManSessionOption;
			DebugHelper.WriteLogEx();
			if (!ConstValue.IsDefaultComputerName(computerName))
			{
				object[] objArray = new object[1];
				objArray[0] = computerName;
				DebugHelper.WriteLog("<<<<<<<<<< Use protocol WSMAN {0}", 1, objArray);
				wSManSessionOption = new WSManSessionOptions();
			}
			else
			{
				object[] objArray1 = new object[1];
				objArray1[0] = computerName;
				DebugHelper.WriteLog("<<<<<<<<<< Use protocol DCOM  {0}", 1, objArray1);
				wSManSessionOption = new DComSessionOptions();
			}
			if (timeout != 0)
			{
				wSManSessionOption.Timeout = TimeSpan.FromSeconds((double)((float)timeout));
			}
			if (credential != null)
			{
				wSManSessionOption.AddDestinationCredentials(credential);
			}
			object[] objArray2 = new object[1];
			objArray2[0] = wSManSessionOption;
			DebugHelper.WriteLogEx("returned option :{0}.", 1, objArray2);
			return wSManSessionOption;
		}