예제 #1
0
 internal static void GetRegistryStringAttribute(ref string val, ConfigurationElement config, string propName)
 {
     if (HandlerBase.CheckAndReadRegistryValue(ref val, false) == false)
     {
         throw new ConfigurationErrorsException(
                   SR.GetString(SR.Invalid_registry_config),
                   config.ElementInformation.Properties[propName].Source, config.ElementInformation.Properties[propName].LineNumber);
     }
 }
예제 #2
0
        private void ValidateCredentials()
        {
            _username = UserName;
            _password = Password;

            if (HandlerBase.CheckAndReadRegistryValue(ref _username, false) == false)
            {
                throw new ConfigurationErrorsException(
                          SR.GetString(SR.Invalid_registry_config),
                          ElementInformation.Source, ElementInformation.LineNumber);
            }
            if (HandlerBase.CheckAndReadRegistryValue(ref _password, false) == false)
            {
                throw new ConfigurationErrorsException(
                          SR.GetString(SR.Invalid_registry_config),
                          ElementInformation.Source,
                          ElementInformation.LineNumber);
            }

            if (_username != null && _username.Length < 1)
            {
                _username = null;
            }

            if (_username != null && Impersonate)
            {
                if (_password == null)
                {
                    _password = String.Empty;
                }
            }
            else if (_password != null && _username == null && _password.Length > 0 && Impersonate)
            {
                throw new ConfigurationErrorsException(
                          SR.GetString(SR.Invalid_credentials),
                          ElementInformation.Properties["password"].Source,
                          ElementInformation.Properties["password"].LineNumber);
            }
            if (Impersonate && ImpersonateToken == IntPtr.Zero && _username != null)
            {
                if (error.Length > 0)
                {
                    throw new ConfigurationErrorsException(
                              SR.GetString(SR.Invalid_credentials_2, error),
                              ElementInformation.Properties["userName"].Source,
                              ElementInformation.Properties["userName"].LineNumber);
                }
                else
                {
                    throw new ConfigurationErrorsException(
                              SR.GetString(SR.Invalid_credentials),
                              ElementInformation.Properties["userName"].Source,
                              ElementInformation.Properties["userName"].LineNumber);
                }
            }
        }