Skip to content

Commit

Permalink
fix error on main rebase, and make the windows name pipe (socket) ava…
Browse files Browse the repository at this point in the history
…ilable to non-administrator users (fix bug in TamtamHero#60)
  • Loading branch information
leopoldhub committed Aug 10, 2024
1 parent cf3e36a commit 480f867
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
32 changes: 30 additions & 2 deletions fanctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import subprocess
import sys
import threading
import traceback
from time import sleep
from abc import ABC, abstractmethod

Expand Down Expand Up @@ -53,7 +54,7 @@ def __init__(self, name, parameters):

class Configuration:
path = None
data: None
data = None

def __init__(self, path):
self.path = path
Expand Down Expand Up @@ -125,6 +126,32 @@ class WindowsSocketController(SocketController, ABC):
LPVOID = ctypes.c_void_p
DWORD = wintypes.DWORD

kernel32 = ctypes.WinDLL("kernel32", use_last_error=True)
advapi32 = ctypes.WinDLL("advapi32", use_last_error=True)

ConvertStringSecurityDescriptorToSecurityDescriptorW = advapi32.ConvertStringSecurityDescriptorToSecurityDescriptorW
ConvertStringSecurityDescriptorToSecurityDescriptorW.argtypes = [wintypes.LPCWSTR, wintypes.DWORD, ctypes.POINTER(wintypes.LPVOID), ctypes.POINTER(wintypes.DWORD)]
ConvertStringSecurityDescriptorToSecurityDescriptorW.restype = wintypes.HANDLE

sddl_string = "D:P(A;;GA;;;WD)"

security_descriptor = wintypes.LPVOID()
ConvertStringSecurityDescriptorToSecurityDescriptorW(sddl_string, 1, ctypes.byref(security_descriptor), None)

class SECURITY_ATTRIBUTES(ctypes.Structure):
from ctypes import wintypes

_fields_ = [
("nLength", wintypes.DWORD),
("lpSecurityDescriptor", wintypes.LPVOID),
("nLength", wintypes.BOOL),
]

security_attributes = SECURITY_ATTRIBUTES()
security_attributes.nLength = ctypes.sizeof(SECURITY_ATTRIBUTES)
security_attributes.lpSecurityDescriptor = security_descriptor
security_attributes.bInheritHandle = False

server_socket = None

def startServerSocket(self, commandCallback=None):
Expand All @@ -138,7 +165,7 @@ def startServerSocket(self, commandCallback=None):
65536, # nOutBufferSize
65536, # nInBufferSize
0, # nDefaultTimeOut
None # lpSecurityAttributes
self.ctypes.byref(self.security_attributes) # lpSecurityAttributes
)
try:
while True:
Expand Down Expand Up @@ -394,6 +421,7 @@ def run(self, debug=True):
print(f"Missing strategy, exiting for safety reasons: {e.args[0]}")
except Exception as e:
print(f"Critical error, exiting for safety reasons: {e}")
traceback.print_exc()
exit(1)


Expand Down
23 changes: 23 additions & 0 deletions install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ GOTO :EOF
set /p "acknowledgement=> "
if not defined acknowledgement (
echo goodbye.
pause
exit /b 2
)
if not "%acknowledgement%" equ "%acknowledgementPhrase%" (
echo wrong acknowledgement phrase [%acknowledgement%] not equal to [%acknowledgementPhrase%], stopping here!
pause
exit /b 2
)
echo:
Expand Down Expand Up @@ -155,6 +157,7 @@ GOTO :EOF
@echo off
if %errorLevel% neq 0 (
echo failed to download 'crosec.zip'
pause
exit /b 1
)

Expand All @@ -164,6 +167,7 @@ GOTO :EOF
@echo off
if %errorLevel% neq 0 (
echo failed to extract 'crosec.zip'
pause
exit /b 2
)

Expand All @@ -176,6 +180,7 @@ GOTO :EOF
if %errorLevel% neq 0 (
cd /d "%~dp0"
echo failed to run the 'crosec' driver installation
pause
exit /b 3
)
cd /d "%~dp0"
Expand All @@ -189,6 +194,7 @@ GOTO :EOF
for %%i in (".temp\test-result.txt") do @set count=%%~zi
if "%count%" == "0" (
echo 'crosec' driver not installed correctly
pause
exit /b 4
)

Expand All @@ -199,6 +205,7 @@ GOTO :EOF
@echo off
if %errorLevel% neq 0 (
echo unable to copy '.temp' to '%ProgramFiles%\ectool'
pause
exit /b 5
)

Expand All @@ -215,6 +222,7 @@ GOTO :EOF
@echo off
if %errorLevel% neq 0 (
echo failed to download 'artifact.zip'
pause
exit /b 1
)

Expand All @@ -224,6 +232,7 @@ GOTO :EOF
@echo off
if %errorLevel% neq 0 (
echo failed to extract 'artifact.zip'
pause
exit /b 2
)

Expand All @@ -234,6 +243,7 @@ GOTO :EOF
@echo off
if %errorLevel% neq 0 (
echo unable to create directory '%ProgramFiles%\ectool'
pause
exit /b 3
)

Expand All @@ -248,6 +258,7 @@ GOTO :EOF
@echo off
if %errorLevel% neq 0 (
echo unable to install 'ectool.exe'
pause
exit /b 3
)

Expand All @@ -264,6 +275,7 @@ GOTO :EOF
@echo off
if %errorLevel% neq 0 (
echo failed to download 'nssm.zip'
pause
exit /b 1
)

Expand All @@ -273,6 +285,7 @@ GOTO :EOF
@echo off
if %errorLevel% neq 0 (
echo failed to extract 'nssm.zip'
pause
exit /b 2
)

Expand All @@ -287,6 +300,7 @@ GOTO :EOF
@echo off
if %errorLevel% neq 0 (
echo unable to install 'nssm.exe'
pause
exit /b 3
)

Expand All @@ -302,6 +316,7 @@ GOTO :EOF
@echo off
if %errorLevel% neq 0 (
echo unable to create directory '%ProgramFiles%\fw-fanctrl'
pause
exit /b 3
)

Expand All @@ -316,6 +331,7 @@ GOTO :EOF
@echo off
if %errorLevel% neq 0 (
echo unable to install 'fanctrl.py'
pause
exit /b 3
)

Expand All @@ -325,6 +341,7 @@ GOTO :EOF
@echo off
if %errorLevel% neq 0 (
echo unable to install '.\services\windows\run-service.bat'
pause
exit /b 4
)

Expand All @@ -334,6 +351,7 @@ GOTO :EOF
@echo off
if %errorLevel% neq 0 (
echo unable to install '.\services\windows\run-service.bat'
pause
exit /b 4
)

Expand All @@ -345,6 +363,7 @@ GOTO :EOF
@echo off
if %errorLevel% neq 0 (
echo unable to install '.\services\windows\fw-fanctrl.bat'
pause
exit /b 4
)

Expand All @@ -362,6 +381,7 @@ GOTO :EOF
"%ProgramFiles%\nssm\nssm" set "fw-fanctrl" Start "SERVICE_DELAYED_AUTO_START"
"%ProgramFiles%\nssm\nssm" set "fw-fanctrl" DisplayName "Framework Fanctrl"
"%ProgramFiles%\nssm\nssm" set "fw-fanctrl" Description "A simple systemd service to better control Framework Laptop's fan(s)"
"%ProgramFiles%\nssm\nssm" set "fw-fanctrl" AppExit "%ProgramFiles%\ectool\ectool autofanctrl"
"%ProgramFiles%\nssm\nssm" set "fw-fanctrl" AppStdout "%ProgramFiles%\fw-fanctrl\out.log"
"%ProgramFiles%\nssm\nssm" set "fw-fanctrl" AppStderr "%ProgramFiles%\fw-fanctrl\out.log"
@echo off
Expand Down Expand Up @@ -410,6 +430,8 @@ GOTO :EOF
echo removing directory '%ProgramFiles%\nssm'
rmdir /s /q "%ProgramFiles%\nssm" 2> nul

GOTO :EOF

:uninstall-ectool
echo removing 'ectool'

Expand Down Expand Up @@ -438,6 +460,7 @@ GOTO :EOF
bcdedit /set {default} testsigning off

GOTO :EOF

GOTO :EOF


Expand Down

0 comments on commit 480f867

Please sign in to comment.