mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-12 07:23:24 -05: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"
|
Version="8.00"
|
||||||
Name="FireflyShell"
|
Name="FireflyShell"
|
||||||
ProjectGUID="{ED38F171-854B-4EA3-B3A0-7681648969FC}"
|
ProjectGUID="{ED38F171-854B-4EA3-B3A0-7681648969FC}"
|
||||||
|
RootNamespace="FireflyShell"
|
||||||
Keyword="Win32Proj"
|
Keyword="Win32Proj"
|
||||||
>
|
>
|
||||||
<Platforms>
|
<Platforms>
|
||||||
|
@ -1,36 +1,72 @@
|
|||||||
/*
|
/*
|
||||||
*(C) 2006 Roku LLC
|
*(C) 2006 Roku LLC
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
* under the terms of the GNU General Public License Version 2 as published
|
* under the terms of the GNU General Public License Version 2 as published
|
||||||
* by the Free Software Foundation.
|
* by the Free Software Foundation.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* without any warranty; without even the implied warranty of
|
* without any warranty; without even the implied warranty of
|
||||||
* merchantability or fitness for a particular purpose. See the GNU General
|
* merchantability or fitness for a particular purpose. See the GNU General
|
||||||
* Public License for more details.
|
* Public License for more details.
|
||||||
*
|
*
|
||||||
* Please read README.txt in the same directory as this source file for
|
* Please read README.txt in the same directory as this source file for
|
||||||
* further license information.
|
* further license information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "ServiceControl.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)
|
bool Service::Open(const TCHAR *name)
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
|
|
||||||
const DWORD ADMIN_ACCESS = SC_MANAGER_ALL_ACCESS;
|
|
||||||
const DWORD USER_ACCESS = SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE | STANDARD_RIGHTS_READ;
|
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);
|
m_sc_manager = ::OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, dwDesiredAccess);
|
||||||
if (!m_sc_manager)
|
if (!m_sc_manager)
|
||||||
{
|
{
|
||||||
dwDesiredAccess = USER_ACCESS;
|
|
||||||
m_sc_manager = ::OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, dwDesiredAccess);
|
|
||||||
m_can_control = false;
|
m_can_control = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -41,9 +77,11 @@ bool Service::Open(const TCHAR *name)
|
|||||||
if (m_sc_manager)
|
if (m_sc_manager)
|
||||||
{
|
{
|
||||||
m_sc_service = ::OpenService(m_sc_manager, name, dwDesiredAccess);
|
m_sc_service = ::OpenService(m_sc_manager, name, dwDesiredAccess);
|
||||||
if (m_sc_service)
|
if (m_sc_service) {
|
||||||
|
m_name = name;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
return false;
|
return false;
|
||||||
@ -73,7 +111,7 @@ bool Service::GetStatus(Status *status) const
|
|||||||
|
|
||||||
bool Service::Start()
|
bool Service::Start()
|
||||||
{
|
{
|
||||||
if (::StartService(m_sc_service, 0, NULL))
|
if (ExecHelper(_T("start")))
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
@ -93,7 +131,7 @@ bool Service::StartAndWait()
|
|||||||
bool Service::Stop()
|
bool Service::Stop()
|
||||||
{
|
{
|
||||||
Status status;
|
Status status;
|
||||||
if (::ControlService(m_sc_service, SERVICE_CONTROL_STOP, &status))
|
if (ExecHelper(_T("stop")))
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
@ -102,10 +140,8 @@ bool Service::Stop()
|
|||||||
bool Service::StopAndWait()
|
bool Service::StopAndWait()
|
||||||
{
|
{
|
||||||
Status status;
|
Status status;
|
||||||
if (::ControlService(m_sc_service, SERVICE_CONTROL_STOP, &status))
|
if (Stop())
|
||||||
{
|
|
||||||
return WaitPending(&status, SERVICE_STOP_PENDING);
|
return WaitPending(&status, SERVICE_STOP_PENDING);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
*(C) 2006 Roku LLC
|
*(C) 2006 Roku LLC
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
* under the terms of the GNU General Public License Version 2 as published
|
* under the terms of the GNU General Public License Version 2 as published
|
||||||
* by the Free Software Foundation.
|
* by the Free Software Foundation.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* without any warranty; without even the implied warranty of
|
* without any warranty; without even the implied warranty of
|
||||||
* merchantability or fitness for a particular purpose. See the GNU General
|
* merchantability or fitness for a particular purpose. See the GNU General
|
||||||
* Public License for more details.
|
* Public License for more details.
|
||||||
*
|
*
|
||||||
* Please read README.txt in the same directory as this source file for
|
* Please read README.txt in the same directory as this source file for
|
||||||
* further license information.
|
* further license information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SERVICECONTROL_H
|
#ifndef SERVICECONTROL_H
|
||||||
#define SERVICECONTROL_H
|
#define SERVICECONTROL_H
|
||||||
@ -22,6 +22,7 @@ class Service
|
|||||||
SC_HANDLE m_sc_manager;
|
SC_HANDLE m_sc_manager;
|
||||||
SC_HANDLE m_sc_service;
|
SC_HANDLE m_sc_service;
|
||||||
bool m_can_control;
|
bool m_can_control;
|
||||||
|
CString m_name;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -125,8 +126,10 @@ public:
|
|||||||
/// Pass SERVICE_AUTO_START, SERVICE_BOOT_START, SERVICE_DEMAND_START,
|
/// Pass SERVICE_AUTO_START, SERVICE_BOOT_START, SERVICE_DEMAND_START,
|
||||||
/// SERVICE_DISABLED or SERVICE_SYSTEM_START.
|
/// SERVICE_DISABLED or SERVICE_SYSTEM_START.
|
||||||
bool ConfigureStartup(DWORD dwStartup);
|
bool ConfigureStartup(DWORD dwStartup);
|
||||||
|
|
||||||
DWORD GetStartup() const;
|
DWORD GetStartup() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool ExecHelper(const TCHAR *szAction);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ServiceStatusObserver
|
class ServiceStatusObserver
|
||||||
|
@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
!define MTDROOT "..\.."
|
!define MTDROOT "..\.."
|
||||||
!define MTD_SOURCE "${MTDROOT}\win32\Release"
|
!define MTD_SOURCE "${MTDROOT}\win32\Release"
|
||||||
!define DLL_SOURCE "${PROJROOT}\win32\dll"
|
|
||||||
!define CONFIG_SOURCE "${MTDROOT}\win32\FireflyShell\Release"
|
!define CONFIG_SOURCE "${MTDROOT}\win32\FireflyShell\Release"
|
||||||
|
!define DLL_SOURCE "${PROJROOT}\win32\dll"
|
||||||
!define ADMIN_ROOT "${MTDROOT}\admin-root"
|
!define ADMIN_ROOT "${MTDROOT}\admin-root"
|
||||||
!define REDIST_SOURCE "${PROJROOT}\win32\redist"
|
!define REDIST_SOURCE "${PROJROOT}\win32\redist"
|
||||||
|
|
||||||
@ -171,6 +171,7 @@ NoProgramItems:
|
|||||||
File "${CONFIG_SOURCE}\FireflyShell-11.dll"
|
File "${CONFIG_SOURCE}\FireflyShell-11.dll"
|
||||||
File "${CONFIG_SOURCE}\FireflyShell-10.dll"
|
File "${CONFIG_SOURCE}\FireflyShell-10.dll"
|
||||||
File "${CONFIG_SOURCE}\..\FireflyShell.exe.manifest"
|
File "${CONFIG_SOURCE}\..\FireflyShell.exe.manifest"
|
||||||
|
File "${CONFIG_SOURCE}\svcctrl.exe"
|
||||||
File "${DLL_SOURCE}\gnu_regex.dll"
|
File "${DLL_SOURCE}\gnu_regex.dll"
|
||||||
File "${DLL_SOURCE}\pthreadVC2.dll"
|
File "${DLL_SOURCE}\pthreadVC2.dll"
|
||||||
File "${DLL_SOURCE}\sqlite.dll"
|
File "${DLL_SOURCE}\sqlite.dll"
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
<Configurations>
|
<Configurations>
|
||||||
<Configuration
|
<Configuration
|
||||||
Name="Debug|Win32"
|
Name="Debug|Win32"
|
||||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
OutputDirectory="$(SolutionDir)FireflyShell\$(ConfigurationName)"
|
||||||
IntermediateDirectory="$(ConfigurationName)"
|
IntermediateDirectory="$(ConfigurationName)"
|
||||||
ConfigurationType="1"
|
ConfigurationType="1"
|
||||||
CharacterSet="2"
|
CharacterSet="2"
|
||||||
@ -92,7 +92,7 @@
|
|||||||
</Configuration>
|
</Configuration>
|
||||||
<Configuration
|
<Configuration
|
||||||
Name="Release|Win32"
|
Name="Release|Win32"
|
||||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
OutputDirectory="$(SolutionDir)FireflyShell\$(ConfigurationName)"
|
||||||
IntermediateDirectory="$(ConfigurationName)"
|
IntermediateDirectory="$(ConfigurationName)"
|
||||||
ConfigurationType="1"
|
ConfigurationType="1"
|
||||||
CharacterSet="2"
|
CharacterSet="2"
|
||||||
|
Loading…
Reference in New Issue
Block a user