Beispiel #1
0
 protected void ConfigureFailureActions()
 {
     base.DoNativeServiceTask(this.Name, ServiceAccessFlags.AllAccess, delegate(IntPtr service)
     {
         IntPtr intPtr = IntPtr.Zero;
         TaskLogger.Trace("Configuring failure actions...", new object[0]);
         try
         {
             ServiceFailureActions serviceFailureActions = default(ServiceFailureActions);
             serviceFailureActions.resetPeriod           = this.FailureResetPeriod;
             serviceFailureActions.rebootMessage         = null;
             serviceFailureActions.command     = null;
             serviceFailureActions.actionCount = 3U;
             int num = Marshal.SizeOf(typeof(ServiceAction));
             intPtr  = Marshal.AllocHGlobal((int)((long)num * (long)((ulong)serviceFailureActions.actionCount)));
             serviceFailureActions.actions = intPtr;
             this.ConfigureFailureAction(intPtr, num, 0, this.firstFailureActionType, this.firstFailureActionDelay);
             this.ConfigureFailureAction(intPtr, num, 1, this.secondFailureActionType, this.secondFailureActionDelay);
             this.ConfigureFailureAction(intPtr, num, 2, this.allOtherFailuresActionType, this.allOtherFailuresActionDelay);
             if (!NativeMethods.ChangeServiceConfig2(service, ServiceConfigInfoLevels.FailureActions, ref serviceFailureActions))
             {
                 base.WriteError(TaskWin32Exception.FromErrorCodeAndVerbose(Marshal.GetLastWin32Error(), Strings.ErrorChangeServiceConfig2(this.Name)), ErrorCategory.WriteError, null);
             }
         }
         finally
         {
             if (IntPtr.Zero != intPtr)
             {
                 Marshal.FreeHGlobal(intPtr);
             }
         }
     });
 }
Beispiel #2
0
 // Token: 0x06000739 RID: 1849 RVA: 0x0001ADF8 File Offset: 0x00018FF8
 protected void UpdateExecutable(string serviceName, string executablePath)
 {
     TaskLogger.Trace("Updating executable...", new object[0]);
     this.DoNativeServiceTask(serviceName, ServiceAccessFlags.AllAccess, delegate(IntPtr service)
     {
         if (!NativeMethods.ChangeServiceConfig(service, 4294967295U, 4294967295U, 4294967295U, executablePath, null, null, null, null, null, null))
         {
             this.WriteError(TaskWin32Exception.FromErrorCodeAndVerbose(Marshal.GetLastWin32Error(), Strings.ErrorChangeServiceConfig2(serviceName)), ErrorCategory.WriteError, null);
         }
     });
 }
Beispiel #3
0
        protected void Uninstall()
        {
            TaskLogger.LogEnter();
            if (!ServiceControllerUtils.IsInstalled(this.Name))
            {
                base.WriteVerbose(Strings.ServiceNotInstalled(this.Name));
                return;
            }
            base.WriteVerbose(Strings.WillUninstallInstalledService(this.Name));
            try
            {
                this.serviceProcessInstaller.Uninstall(null);
            }
            catch (Win32Exception ex)
            {
                if (ex.NativeErrorCode == 1060)
                {
                    this.WriteWarning(Strings.ServiceAlreadyNotInstalled(this.Name));
                }
                else
                {
                    base.WriteError(new ServiceUninstallFailureException(this.Name, ex.Message, ex), ErrorCategory.InvalidOperation, null);
                }
            }
            catch (InstallException ex2)
            {
                base.WriteError(new ServiceUninstallFailureException(this.Name, ex2.Message, ex2), ErrorCategory.InvalidOperation, null);
            }
            if (this.serviceFirewallRules.Count > 0)
            {
                using (List <ExchangeFirewallRule> .Enumerator enumerator = this.serviceFirewallRules.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ExchangeFirewallRule exchangeFirewallRule = enumerator.Current;
                        TaskLogger.Trace("Removing Windows Firewall Rule for Service {0}", new object[]
                        {
                            this.Name
                        });
                        exchangeFirewallRule.Remove();
                    }
                    return;
                }
            }
            string fullPath = this.serviceProcessInstaller.Context.Parameters["assemblypath"];

            TaskLogger.Trace("Removing Service {0} from windows firewall exception", new object[]
            {
                this.Name
            });
            ManageService.RemoveAssemblyFromFirewallExceptions(this.Name, fullPath, new Task.TaskErrorLoggingDelegate(base.WriteError));
            TaskLogger.LogExit();
        }
Beispiel #4
0
 protected void ConfigureFailureActionsFlag()
 {
     base.DoNativeServiceTask(this.Name, ServiceAccessFlags.AllAccess, delegate(IntPtr service)
     {
         TaskLogger.Trace("Configuring failure actions flag...", new object[0]);
         ServiceFailureActionsFlag serviceFailureActionsFlag         = default(ServiceFailureActionsFlag);
         serviceFailureActionsFlag.fFailureActionsOnNonCrashFailures = this.failureActionsFlag;
         if (!NativeMethods.ChangeServiceConfig2(service, ServiceConfigInfoLevels.FailureActionsFlag, ref serviceFailureActionsFlag))
         {
             base.WriteError(TaskWin32Exception.FromErrorCodeAndVerbose(Marshal.GetLastWin32Error(), Strings.ErrorChangeServiceConfig2(this.Name)), ErrorCategory.WriteError, null);
         }
     });
 }
Beispiel #5
0
        private void ExecuteEventHandler <T>(T e, Delegate handler) where T : EventArgs
        {
            Type   declaringType = handler.Method.DeclaringType;
            string str           = (declaringType == null) ? "Global" : declaringType.Name;
            string name          = handler.Method.Name;
            string text          = str + "." + name;

            TaskLogger.Trace(Strings.LogFunctionEnter(declaringType, name, string.Join <ParameterInfo>(",", handler.Method.GetParameters())));
            using (new CmdletMonitoredScope(this.taskContext.UniqueId, "TaskModuleLatency", text, LoggerHelper.CmdletPerfMonitors))
            {
                ICriticalFeature feature = handler.Target as ICriticalFeature;
                feature.Execute(delegate
                {
                    ((EventHandler <T>)handler)(this, e);
                }, this.taskContext, text);
            }
            TaskLogger.Trace(Strings.LogFunctionExit(declaringType, name));
        }
        // Token: 0x06000337 RID: 823 RVA: 0x0000CA98 File Offset: 0x0000AC98
        public bool Match(Condition conditionToMatch)
        {
            TaskLogger.LogEnter(new object[]
            {
                this,
                conditionToMatch
            });
            if (conditionToMatch == null)
            {
                throw new ArgumentNullException("conditionToMatch");
            }
            bool result = false;

            if (base.GetType() != conditionToMatch.GetType())
            {
                TaskLogger.Trace(Strings.LogConditionMatchingTypeMismacth(base.GetType(), conditionToMatch.GetType()));
            }
            else
            {
                foreach (PropertyInfo propertyInfo in base.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
                {
                    object obj  = propertyInfo.GetGetMethod().Invoke(this, null);
                    object obj2 = propertyInfo.GetGetMethod().Invoke(conditionToMatch, null);
                    TaskLogger.Trace("{0}.{1}: {2} ?=? {3}", new object[]
                    {
                        base.GetType().FullName,
                        propertyInfo.Name,
                        obj,
                        obj2
                    });
                    if ((obj != null || obj2 != null) && (obj == null || !obj.Equals(obj2)))
                    {
                        TaskLogger.Trace(Strings.LogConditionMatchingPropertyMismatch(base.GetType(), propertyInfo.Name, obj, obj2));
                        goto IL_106;
                    }
                }
                result = true;
            }
IL_106:
            TaskLogger.LogExit();
            return(result);
        }
Beispiel #7
0
 private void CheckVerboseDebugParameter()
 {
     if (this.context.SessionState != null && ExchangePropertyContainer.IsContainerInitialized(this.context.SessionState))
     {
         ExchangeRunspaceConfiguration exchangeRunspaceConfiguration = ExchangePropertyContainer.GetExchangeRunspaceConfiguration(this.context.SessionState);
         if (exchangeRunspaceConfiguration != null && this.context.InvocationInfo != null)
         {
             if (!exchangeRunspaceConfiguration.IsVerboseEnabled(this.context.InvocationInfo.CommandName))
             {
                 this.verboseDisabled = true;
                 TaskLogger.Trace("The cmdlet does not have Verbose parameter by RBAC check. WriteVerbose is disabled.", new object[0]);
             }
             if (!exchangeRunspaceConfiguration.IsDebugEnabled(this.context.InvocationInfo.CommandName))
             {
                 this.debugDisabled = true;
                 TaskLogger.Trace("The cmdlet does not have Debug parameter by RBAC check. WriteDebug is disabled.", new object[0]);
             }
         }
     }
 }
        // Token: 0x06000DE9 RID: 3561 RVA: 0x0002993C File Offset: 0x00027B3C
        internal static string GetFriendlyUserName(IdentityReference sid, Task.TaskVerboseLoggingDelegate verboseLogger)
        {
            if (null == sid)
            {
                throw new ArgumentNullException("sid");
            }
            string result;

            try
            {
                result = sid.Translate(typeof(NTAccount)).ToString();
            }
            catch (IdentityNotMappedException ex)
            {
                TaskLogger.Trace("Couldn't resolve the following sid '{0}': {1}", new object[]
                {
                    sid.ToString(),
                    ex.Message
                });
                if (verboseLogger != null)
                {
                    verboseLogger(Strings.VerboseCannotResolveSid(sid.ToString(), ex.Message));
                }
                result = sid.ToString();
            }
            catch (SystemException ex2)
            {
                TaskLogger.Trace("Couldn't resolve the following sid '{0}': {1}", new object[]
                {
                    sid.ToString(),
                    ex2.Message
                });
                if (verboseLogger != null)
                {
                    verboseLogger(Strings.VerboseCannotResolveSid(sid.ToString(), ex2.Message));
                }
                result = sid.ToString();
            }
            return(result);
        }
Beispiel #9
0
        protected void LockdownServiceAccess()
        {
            TaskLogger.Trace("Modifying service ACL to remove Network Logon ACE.", new object[0]);
            ServiceAccessFlags serviceAccessFlags = ServiceAccessFlags.ReadControl | ServiceAccessFlags.WriteDac;

            base.DoNativeServiceTask(this.Name, serviceAccessFlags, delegate(IntPtr service)
            {
                string name    = this.Name;
                IntPtr intPtr  = IntPtr.Zero;
                IntPtr intPtr2 = IntPtr.Zero;
                try
                {
                    int num = 65536;
                    intPtr  = Marshal.AllocHGlobal(num);
                    int num2;
                    if (!NativeMethods.QueryServiceObjectSecurity(service, SecurityInfos.DiscretionaryAcl, intPtr, num, out num2))
                    {
                        base.WriteError(TaskWin32Exception.FromErrorCodeAndVerbose(Marshal.GetLastWin32Error(), Strings.ErrorQueryServiceObjectSecurity(name)), ErrorCategory.InvalidOperation, null);
                    }
                    byte[] array = new byte[num2];
                    Marshal.Copy(intPtr, array, 0, num2);
                    RawSecurityDescriptor rawSecurityDescriptor       = new RawSecurityDescriptor(array, 0);
                    CommonSecurityDescriptor commonSecurityDescriptor = new CommonSecurityDescriptor(false, false, rawSecurityDescriptor);
                    CommonAce commonAce      = null;
                    SecurityIdentifier right = new SecurityIdentifier("S-1-5-11");
                    for (int i = 0; i < commonSecurityDescriptor.DiscretionaryAcl.Count; i++)
                    {
                        CommonAce commonAce2 = (CommonAce)commonSecurityDescriptor.DiscretionaryAcl[i];
                        if (commonAce2.SecurityIdentifier == right)
                        {
                            commonAce = commonAce2;
                            break;
                        }
                    }
                    if (commonAce == null)
                    {
                        TaskLogger.Trace("Service ACL was not modified as Network Logon SID is not found.", new object[0]);
                    }
                    else
                    {
                        commonSecurityDescriptor.DiscretionaryAcl.RemoveAccess(AccessControlType.Allow, commonAce.SecurityIdentifier, commonAce.AccessMask, commonAce.InheritanceFlags, commonAce.PropagationFlags);
                        int binaryLength = commonSecurityDescriptor.BinaryLength;
                        byte[] array2    = new byte[binaryLength];
                        commonSecurityDescriptor.GetBinaryForm(array2, 0);
                        intPtr2 = Marshal.AllocHGlobal(binaryLength);
                        Marshal.Copy(array2, 0, intPtr2, binaryLength);
                        if (!NativeMethods.SetServiceObjectSecurity(service, SecurityInfos.DiscretionaryAcl, intPtr2))
                        {
                            base.WriteError(TaskWin32Exception.FromErrorCodeAndVerbose(Marshal.GetLastWin32Error(), Strings.ErrorSetServiceObjectSecurity(name)), ErrorCategory.InvalidOperation, null);
                        }
                        TaskLogger.Trace("Service ACL modified - Network Logon ACE removed.", new object[0]);
                    }
                }
                finally
                {
                    if (IntPtr.Zero != intPtr)
                    {
                        Marshal.FreeHGlobal(intPtr);
                    }
                    if (IntPtr.Zero != intPtr2)
                    {
                        Marshal.FreeHGlobal(intPtr2);
                    }
                }
            });
        }
Beispiel #10
0
        protected void Install()
        {
            TaskLogger.LogEnter(new object[]
            {
                this.Name
            });
            Hashtable hashtable = new Hashtable();

            if (!ServiceControllerUtils.IsInstalled(this.Name))
            {
                try
                {
                    TaskLogger.Trace("Installing service", new object[0]);
                    this.serviceProcessInstaller.Install(hashtable);
                }
                catch (Win32Exception ex)
                {
                    if (1072 == ex.NativeErrorCode)
                    {
                        Thread.Sleep(10000);
                        hashtable = new Hashtable();
                        this.serviceProcessInstaller.Install(hashtable);
                    }
                    else
                    {
                        base.WriteError(new TaskWin32Exception(ex), ErrorCategory.WriteError, null);
                    }
                }
                base.ConfigureServiceSidType();
                if (this.serviceFirewallRules.Count > 0)
                {
                    foreach (ExchangeFirewallRule exchangeFirewallRule in this.serviceFirewallRules)
                    {
                        TaskLogger.Trace("Adding Windows Firewall Rule for Service {0}", new object[]
                        {
                            this.Name
                        });
                        exchangeFirewallRule.Add();
                    }
                }
                this.serviceProcessInstaller.Commit(hashtable);
            }
            else
            {
                TaskLogger.Trace("Service is already installed.", new object[0]);
            }
            if (this.Description != null)
            {
                try
                {
                    using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(ManageService.serviceRegPath + this.Name, true))
                    {
                        registryKey.SetValue(ManageService.descriptionSubKeyName, this.Description);
                    }
                    goto IL_197;
                }
                catch (SecurityException inner)
                {
                    base.WriteError(new SecurityException(Strings.ErrorOpenKeyDeniedForWrite(ManageService.serviceRegPath + this.Name), inner), ErrorCategory.WriteError, null);
                    goto IL_197;
                }
            }
            TaskLogger.Trace("No service description", new object[0]);
IL_197:
            if (this.EventMessageFile != null)
            {
                RegistryKey registryKey2 = null;
                try
                {
                    try
                    {
                        registryKey2 = Registry.LocalMachine.OpenSubKey(ManageService.eventLogRegPath + this.Name, true);
                        if (registryKey2 == null)
                        {
                            registryKey2 = Registry.LocalMachine.CreateSubKey(ManageService.eventLogRegPath + this.Name, RegistryKeyPermissionCheck.ReadWriteSubTree);
                        }
                        registryKey2.SetValue(ManageService.eventMessageFileSubKeyName, this.EventMessageFile);
                        registryKey2.SetValue(ManageService.categoryMessageFileSubKeyName, this.EventMessageFile);
                        registryKey2.SetValue(ManageService.categoryCountSubKeyName, this.CategoryCount);
                        registryKey2.SetValue(ManageService.typesSupportedSubKeyName, 7);
                    }
                    catch (SecurityException inner2)
                    {
                        base.WriteError(new SecurityException(Strings.ErrorOpenKeyDeniedForWrite(ManageService.serviceRegPath + this.Name), inner2), ErrorCategory.WriteError, null);
                    }
                    goto IL_281;
                }
                finally
                {
                    if (registryKey2 != null)
                    {
                        registryKey2.Close();
                        registryKey2 = null;
                    }
                }
            }
            TaskLogger.Trace("No event message file", new object[0]);
IL_281:
            if (base.FirstFailureActionType != ServiceActionType.None)
            {
                base.ConfigureFailureActions();
                base.ConfigureFailureActionsFlag();
            }
            else
            {
                TaskLogger.Trace("No failure actions", new object[0]);
            }
            TaskLogger.LogExit();
        }