mirror of
https://github.com/owntone/owntone-server.git
synced 2025-07-14 19:31:55 -04:00
Update nsi to include svcctrl.exe, update service code in shell to execute the svchelper rather than relying on having admin rights.
This commit is contained in:
parent
7ef720c407
commit
63b49ffd04
@ -4,6 +4,7 @@
|
||||
Version="8.00"
|
||||
Name="FireflyShell"
|
||||
ProjectGUID="{ED38F171-854B-4EA3-B3A0-7681648969FC}"
|
||||
RootNamespace="FireflyShell"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
|
@ -16,21 +16,57 @@
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "ServiceControl.h"
|
||||
#include "DosPath.h"
|
||||
|
||||
bool Service::ExecHelper(const TCHAR *szAction) {
|
||||
PROCESS_INFORMATION pi;
|
||||
STARTUPINFO si;
|
||||
CString commandline;
|
||||
CDosPath path = CDosPath::AppPath();
|
||||
CDosPath filename(_T("svcctrl.exe"));
|
||||
DWORD dwResult;
|
||||
LPTSTR cmd;
|
||||
|
||||
filename |= path;
|
||||
commandline.Format(_T("%s %s \"%s\""),filename.GetPath(),szAction,m_name);
|
||||
cmd = commandline.GetBuffer(commandline.GetLength() + 1);
|
||||
ZeroMemory(&si,sizeof(si));
|
||||
si.cb = sizeof(si);
|
||||
|
||||
ZeroMemory(&pi,sizeof(pi));
|
||||
|
||||
|
||||
BOOL bStarted = CreateProcess(NULL,cmd,NULL,NULL,
|
||||
FALSE,0,NULL,NULL,&si,&pi);
|
||||
|
||||
commandline.ReleaseBuffer();
|
||||
|
||||
if(!bStarted)
|
||||
return false;
|
||||
|
||||
WaitForSingleObject(pi.hProcess, INFINITE);
|
||||
|
||||
GetExitCodeProcess(pi.hProcess,&dwResult);
|
||||
CloseHandle(pi.hProcess);
|
||||
CloseHandle(pi.hThread);
|
||||
|
||||
if(dwResult)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Service::Open(const TCHAR *name)
|
||||
{
|
||||
Close();
|
||||
|
||||
const DWORD ADMIN_ACCESS = SC_MANAGER_ALL_ACCESS;
|
||||
const DWORD USER_ACCESS = SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE | STANDARD_RIGHTS_READ;
|
||||
|
||||
DWORD dwDesiredAccess = ADMIN_ACCESS;
|
||||
DWORD dwDesiredAccess = USER_ACCESS;
|
||||
|
||||
m_sc_manager = ::OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, dwDesiredAccess);
|
||||
if (!m_sc_manager)
|
||||
{
|
||||
dwDesiredAccess = USER_ACCESS;
|
||||
m_sc_manager = ::OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, dwDesiredAccess);
|
||||
m_can_control = false;
|
||||
}
|
||||
else
|
||||
@ -41,9 +77,11 @@ bool Service::Open(const TCHAR *name)
|
||||
if (m_sc_manager)
|
||||
{
|
||||
m_sc_service = ::OpenService(m_sc_manager, name, dwDesiredAccess);
|
||||
if (m_sc_service)
|
||||
if (m_sc_service) {
|
||||
m_name = name;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Close();
|
||||
return false;
|
||||
@ -73,7 +111,7 @@ bool Service::GetStatus(Status *status) const
|
||||
|
||||
bool Service::Start()
|
||||
{
|
||||
if (::StartService(m_sc_service, 0, NULL))
|
||||
if (ExecHelper(_T("start")))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
@ -93,7 +131,7 @@ bool Service::StartAndWait()
|
||||
bool Service::Stop()
|
||||
{
|
||||
Status status;
|
||||
if (::ControlService(m_sc_service, SERVICE_CONTROL_STOP, &status))
|
||||
if (ExecHelper(_T("stop")))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
@ -102,10 +140,8 @@ bool Service::Stop()
|
||||
bool Service::StopAndWait()
|
||||
{
|
||||
Status status;
|
||||
if (::ControlService(m_sc_service, SERVICE_CONTROL_STOP, &status))
|
||||
{
|
||||
if (Stop())
|
||||
return WaitPending(&status, SERVICE_STOP_PENDING);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ class Service
|
||||
SC_HANDLE m_sc_manager;
|
||||
SC_HANDLE m_sc_service;
|
||||
bool m_can_control;
|
||||
CString m_name;
|
||||
|
||||
public:
|
||||
|
||||
@ -125,8 +126,10 @@ public:
|
||||
/// Pass SERVICE_AUTO_START, SERVICE_BOOT_START, SERVICE_DEMAND_START,
|
||||
/// SERVICE_DISABLED or SERVICE_SYSTEM_START.
|
||||
bool ConfigureStartup(DWORD dwStartup);
|
||||
|
||||
DWORD GetStartup() const;
|
||||
|
||||
private:
|
||||
bool ExecHelper(const TCHAR *szAction);
|
||||
};
|
||||
|
||||
class ServiceStatusObserver
|
||||
|
@ -16,8 +16,8 @@
|
||||
|
||||
!define MTDROOT "..\.."
|
||||
!define MTD_SOURCE "${MTDROOT}\win32\Release"
|
||||
!define DLL_SOURCE "${PROJROOT}\win32\dll"
|
||||
!define CONFIG_SOURCE "${MTDROOT}\win32\FireflyShell\Release"
|
||||
!define DLL_SOURCE "${PROJROOT}\win32\dll"
|
||||
!define ADMIN_ROOT "${MTDROOT}\admin-root"
|
||||
!define REDIST_SOURCE "${PROJROOT}\win32\redist"
|
||||
|
||||
@ -171,6 +171,7 @@ NoProgramItems:
|
||||
File "${CONFIG_SOURCE}\FireflyShell-11.dll"
|
||||
File "${CONFIG_SOURCE}\FireflyShell-10.dll"
|
||||
File "${CONFIG_SOURCE}\..\FireflyShell.exe.manifest"
|
||||
File "${CONFIG_SOURCE}\svcctrl.exe"
|
||||
File "${DLL_SOURCE}\gnu_regex.dll"
|
||||
File "${DLL_SOURCE}\pthreadVC2.dll"
|
||||
File "${DLL_SOURCE}\sqlite.dll"
|
||||
|
@ -17,7 +17,7 @@
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
OutputDirectory="$(SolutionDir)FireflyShell\$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2"
|
||||
@ -92,7 +92,7 @@
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
OutputDirectory="$(SolutionDir)FireflyShell\$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2"
|
||||
|
Loading…
x
Reference in New Issue
Block a user