diff --git a/actor/src/udsactor/linux/service.py b/actor/src/udsactor/linux/service.py index e967ba16c..152a73e07 100644 --- a/actor/src/udsactor/linux/service.py +++ b/actor/src/udsactor/linux/service.py @@ -51,7 +51,7 @@ class UDSActorSvc(daemon.Daemon, CommonService): signal.signal(signal.SIGINT, self.markForExit) signal.signal(signal.SIGTERM, self.markForExit) - def markForExit(self, signum, frame) -> None: + def markForExit(self, signum, frame) -> None: # pylint: disable=unused-argument self._isAlive = False def joinDomain( # pylint: disable=unused-argument, too-many-arguments diff --git a/actor/src/udsactor/log.py b/actor/src/udsactor/log.py index 0114393d5..547e52304 100644 --- a/actor/src/udsactor/log.py +++ b/actor/src/udsactor/log.py @@ -25,10 +25,10 @@ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ''' @author: Adolfo Gómez, dkmaster at dkmon dot com ''' +# pylint: disable=invalid-name import traceback import sys import typing diff --git a/actor/src/udsactor/service.py b/actor/src/udsactor/service.py index 391ce80ea..a4ca39aaa 100644 --- a/actor/src/udsactor/service.py +++ b/actor/src/udsactor/service.py @@ -55,7 +55,7 @@ from .http import registry, server # else: # logger.setLevel(20000) -class CommonService: +class CommonService: # pylint: disable=too-many-instance-attributes _isAlive: bool = True _rebootRequested: bool = False _loggedIn = False @@ -87,8 +87,11 @@ class CommonService: self._certificate = types.CertificateInfoType('', '', '') self._http = None - # Initialzies loglevel + # Initialzies loglevel and serviceLogger logger.setLevel(self._cfg.log_level * 10000) + # If windows, enable service logger + if logger.localLogger.windows: + logger.localLogger.serviceLogger = True socket.setdefaulttimeout(20) diff --git a/actor/src/udsactor/windows/operations.py b/actor/src/udsactor/windows/operations.py index eef990164..1ecd40a20 100644 --- a/actor/src/udsactor/windows/operations.py +++ b/actor/src/udsactor/windows/operations.py @@ -184,7 +184,7 @@ def changeUserPassword(user: str, oldPassword: str, newPassword: str) -> None: # Try to set new password "a las bravas", ignoring old one. This will not work with domain users res = win32net.NetUserSetInfo(None, user, 1003, {'password': newPassword}) - if res != 0: + if res: # Log the error, and raise exception to parent error = getErrorMessage(res) raise Exception('Error changing password for user {}: {} {}'.format(user, res, error)) diff --git a/actor/src/udsactor/windows/runner.py b/actor/src/udsactor/windows/runner.py index e4bbd6266..25deb6614 100644 --- a/actor/src/udsactor/windows/runner.py +++ b/actor/src/udsactor/windows/runner.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (c) 2014 Virtual Cable S.L. +# Copyright (c) 2019 Virtual Cable S.L. # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, @@ -29,9 +29,18 @@ @author: Adolfo Gómez, dkmaster at dkmon dot com ''' # pylint: disable=invalid-name +import sys import win32serviceutil +import servicemanager + +import win32timezone # pylint: disable=unused-import from .service import UDSActorSvc def run() -> None: - win32serviceutil.HandleCommandLine(UDSActorSvc) + if len(sys.argv) == 1: + servicemanager.Initialize() + servicemanager.PrepareToHostSingle(UDSActorSvc) + servicemanager.StartServiceCtrlDispatcher() + else: + win32serviceutil.HandleCommandLine(UDSActorSvc) diff --git a/actor/src/udsactor/windows/service.py b/actor/src/udsactor/windows/service.py index 8cfc91520..03f9401ee 100644 --- a/actor/src/udsactor/windows/service.py +++ b/actor/src/udsactor/windows/service.py @@ -30,9 +30,6 @@ ''' # pylint: disable=invalid-name import struct -import subprocess -import os -import stat import typing import win32serviceutil @@ -84,7 +81,7 @@ class UDSActorSvc(win32serviceutil.ServiceFramework, CommonService): def SvcStop(self) -> None: self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) self._isAlive = False - win32event.SetEvent(self.hWaitStop) + win32event.SetEvent(self._hWaitStop) SvcShutdown = SvcStop @@ -93,7 +90,7 @@ class UDSActorSvc(win32serviceutil.ServiceFramework, CommonService): super().notifyStop() def doWait(self, miliseconds: int) -> None: - win32event.WaitForSingleObject(self.hWaitStop, miliseconds) + win32event.WaitForSingleObject(self._hWaitStop, miliseconds) def oneStepJoin(self, name: str, domain: str, ou: str, account: str, password: str) -> None: ''' @@ -186,7 +183,7 @@ class UDSActorSvc(win32serviceutil.ServiceFramework, CommonService): """ # Compose packet for ov usernameBytes = username.encode() - passwordBytes = username.encode() + passwordBytes = password.encode() packet = struct.pack('!I', len(usernameBytes)) + usernameBytes + struct.pack('!I', len(passwordBytes)) + passwordBytes # Send packet with username/password to ov pipe operations.writeToPipe("\\\\.\\pipe\\VDSMDPipe", packet, True) @@ -211,27 +208,26 @@ class UDSActorSvc(win32serviceutil.ServiceFramework, CommonService): ''' Main service loop ''' - logger.debug('running SvcDoRun') servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE, servicemanager.PYS_SERVICE_STARTED, (self._svc_name_, '')) # call the CoInitialize to allow the registration to run in an other # thread - logger.debug('Initializing com...') + logger.debug('Initializing coms') - pythoncom.CoInitialize() + pythoncom.CoInitialize() # pylint: disable=no-member if not self.initialize(): self.finish() - win32event.WaitForSingleObject(self.hWaitStop, 5000) + win32event.WaitForSingleObject(self._hWaitStop, 5000) return # Stop daemon if initializes told to do so - # ******************************** - # * Registers SENS subscriptions * - # ******************************** - logevent('Registering ISensLogon') + # # ******************************** + # # * Registers SENS subscriptions * + # # ******************************** + logger.debug('Registering isens logon') subscription_guid = '{41099152-498E-11E4-8FD3-10FEED05884B}' sl = SensLogon(self) - subscription_interface = pythoncom.WrapObject(sl) + subscription_interface = pythoncom.WrapObject(sl) # pylint: disable=no-member event_system = win32com.client.Dispatch(PROGID_EventSystem) @@ -253,14 +249,13 @@ class UDSActorSvc(win32serviceutil.ServiceFramework, CommonService): # ********************* # * Main Service loop * # ********************* - # Counter used to check ip changes only once every 10 seconds, for - # example + # Counter used to check ip changes only once every 10 seconds counter = 0 while self._isAlive: counter += 1 try: # Process SENS messages, This will be a bit asyncronous (1 second delay) - pythoncom.PumpWaitingMessages() + pythoncom.PumpWaitingMessages() # pylint: disable=no-member if counter >= 10: # Once every 10 seconds counter = 0 @@ -271,7 +266,7 @@ class UDSActorSvc(win32serviceutil.ServiceFramework, CommonService): # Continue after a while... # In milliseconds, will break if event hWaitStop is set - win32event.WaitForSingleObject(self.hWaitStop, 1000) + win32event.WaitForSingleObject(self._hWaitStop, 1000) logger.debug('Exited main loop, deregistering SENS')