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); } } }); }
// Token: 0x06000737 RID: 1847 RVA: 0x0001ACB0 File Offset: 0x00018EB0 internal void DoNativeServiceTask(string serviceName, ServiceAccessFlags serviceAccessFlags, ManageServiceBase.NativeServiceTaskDelegate task) { IntPtr intPtr = IntPtr.Zero; IntPtr intPtr2 = IntPtr.Zero; try { intPtr = NativeMethods.OpenSCManager(null, null, ServiceControlManagerAccessFlags.AllAccess); if (IntPtr.Zero == intPtr) { base.WriteError(TaskWin32Exception.FromErrorCodeAndVerbose(Marshal.GetLastWin32Error(), Strings.ErrorCannotOpenServiceControllerManager), ErrorCategory.ReadError, null); } intPtr2 = NativeMethods.OpenService(intPtr, serviceName, serviceAccessFlags); if (IntPtr.Zero == intPtr2) { base.WriteError(TaskWin32Exception.FromErrorCodeAndVerbose(Marshal.GetLastWin32Error(), Strings.ErrorCannotOpenService(serviceName)), ErrorCategory.ReadError, null); } task(intPtr2); } finally { if (IntPtr.Zero != intPtr2 && !NativeMethods.CloseServiceHandle(intPtr2)) { this.WriteError(TaskWin32Exception.FromErrorCodeAndVerbose(Marshal.GetLastWin32Error(), Strings.ErrorCloseServiceHandle), ErrorCategory.InvalidOperation, null, false); } if (IntPtr.Zero != intPtr && !NativeMethods.CloseServiceHandle(intPtr)) { this.WriteError(TaskWin32Exception.FromErrorCodeAndVerbose(Marshal.GetLastWin32Error(), Strings.ErrorCloseServiceHandle), ErrorCategory.InvalidOperation, null, false); } } }
// 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); } }); }
protected void ConfigureServiceSidType() { base.DoNativeServiceTask(this.Name, ServiceAccessFlags.AllAccess, delegate(IntPtr service) { ServiceSidActions serviceSidActions = default(ServiceSidActions); serviceSidActions.serviceSidType = 0U; if (!NativeMethods.ChangeServiceConfig2(service, ServiceConfigInfoLevels.ServiceSid, ref serviceSidActions)) { base.WriteError(TaskWin32Exception.FromErrorCodeAndVerbose(Marshal.GetLastWin32Error(), Strings.ErrorChangeServiceConfig2(this.Name)), ErrorCategory.WriteError, null); } }); }
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); } }); }
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); } } }); }