Skip to content

Commit b88fa02

Browse files
committed
Service updates: Default the windows service to a dedicated config file for compatibility with the GUI. Have the service change it's start up type on run so it will automatically start on system reboot, go back to manual when stopped. Documentation updates.
1 parent 1095cfa commit b88fa02

File tree

7 files changed

+95
-8
lines changed

7 files changed

+95
-8
lines changed

ChangeLog

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
* 2020-04- : Version 0.3.1
2-
* Remove the secure.eu entries in the stubby config file as the service is shutting down
3-
as of 30th April
1+
*2020- : Version 0.4.0
2+
* Add ability to run Stubby as a full Windows service
3+
* Update IPs for dot1.applied-privacy.net
4+
* Remove the secure.eu entries in the stubby config file
5+
* Bugfix: Make `run_in_foreground = 1` the default again
46

57
* 2020-02-28: Version 0.3.0
68
* Correct the applied-privacy.net details and remove ibksturm server in stubby.yml.example.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ Or via the GUI:
191191

192192
## Windows 8 and later
193193

194+
See the file windows/README.txt for a detailed description of building and using Stubby on windows.
195+
194196
Powershell scripts are provided in the the windows directory of the source code that can be used to update the system resolvers.
195197
Instructions for how to update the resolvers manually are provided are also provided - see https://dnsprivacy.org/wiki/display/DP/Windows+installer+for+Stubby
196198
Stubby has been reported to work on Windows 7, but we don't officially support it.

src/configfile.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@ char *system_config_file(void)
105105
return folder_config_file(CSIDL_PROGRAM_FILES);
106106
}
107107

108+
char *system_service_config_file(void)
109+
{
110+
int csidl = CSIDL_PROGRAM_FILES;
111+
TCHAR szPath[MAX_PATH];
112+
113+
if (!SUCCEEDED(SHGetFolderPath(NULL,
114+
csidl | CSIDL_FLAG_CREATE, NULL, 0, szPath)))
115+
return NULL;
116+
117+
return make_config_file_path(szPath, "\\Stubby\\stubbyservice.yml");
118+
}
119+
108120
#else
109121

110122
char *home_config_file(void)

src/configfile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232

3333
char *home_config_file(void);
3434
char *system_config_file(void);
35+
#if defined(STUBBY_ON_WINDOWS)
36+
char *system_service_config_file(void);
37+
#endif
3538

3639
void init_config(getdns_context *context);
3740
void delete_config(void);

src/windows/service.c

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ VOID SvcInstall(void)
382382
schService = CreateService(
383383
schSCManager, // SCM database
384384
SVCNAME, // name of service
385-
"Stubby DNS Privacy Proxy", // service name to display
385+
"Stubby DNS Privacy stub resolver", // service name to display
386386
SERVICE_ALL_ACCESS, // desired access
387387
SERVICE_WIN32_OWN_PROCESS, // service type
388388
SERVICE_DEMAND_START, // start type
@@ -401,7 +401,7 @@ VOID SvcInstall(void)
401401
winlasterr("Create service");
402402
}
403403

404-
description.lpDescription = TEXT("Enable performing DNS name lookups over secure channels.");
404+
description.lpDescription = TEXT("Enable performing DNS name lookups over encrypted channels.");
405405
ChangeServiceConfig2(schService, SERVICE_CONFIG_DESCRIPTION,
406406
(LPVOID) &description);
407407

@@ -602,6 +602,50 @@ int SvcStatus(void)
602602
}
603603
}
604604

605+
static void set_startup(DWORD start_type) {
606+
607+
SC_HANDLE schSCManager;
608+
SC_HANDLE schService;
609+
stubby_debug("set_startup");
610+
611+
schSCManager = OpenSCManager(
612+
NULL, // local computer
613+
NULL, // ServicesActive database
614+
GENERIC_WRITE); // modify service
615+
616+
if (NULL == schSCManager)
617+
winlasterr("Open service manager");
618+
619+
schService = OpenService(
620+
schSCManager, // SCM database
621+
SVCNAME, // name of service
622+
SERVICE_CHANGE_CONFIG); // intention
623+
624+
if (schService == NULL)
625+
{
626+
CloseServiceHandle(schSCManager);
627+
winlasterr("Open service");
628+
}
629+
630+
631+
if (! ChangeServiceConfig(
632+
schService, // service handle
633+
SERVICE_NO_CHANGE, // service type
634+
start_type, // start type
635+
SERVICE_NO_CHANGE, // error control type
636+
NULL, // path to service's binary
637+
NULL, // no load ordering group
638+
NULL, // no tag identifier
639+
NULL, // no dependencies
640+
NULL, // account name: no change
641+
NULL, // password: no change
642+
NULL) ) // display name: no change
643+
{
644+
stubby_debug("ChangeServiceConfig failed (%d)\n", GetLastError());
645+
}
646+
else stubby_debug("Service start type changed successfully.\n");
647+
}
648+
605649
VOID WINAPI SvcMain(DWORD dwArgc, LPTSTR *lpszArgv)
606650
{
607651
stubby_set_log_funcs(report_verror, report_vlog);
@@ -620,6 +664,7 @@ VOID WINAPI SvcMain(DWORD dwArgc, LPTSTR *lpszArgv)
620664
gSvcStatus.dwServiceSpecificExitCode = 0;
621665
ReportSvcStatus(SERVICE_START_PENDING, 0, 3000);
622666

667+
set_startup(SERVICE_AUTO_START);
623668
SvcInit(dwArgc, lpszArgv);
624669
}
625670

@@ -665,6 +710,9 @@ VOID SvcInit(DWORD dwArgc, LPTSTR* lpszArgv)
665710
stubby_set_getdns_logging(context, lpszArgv[1][0] - '0');
666711
if ( dwArgc > 2 )
667712
config_file = lpszArgv[2];
713+
else
714+
// have the service default to a dedicated file in its own directory
715+
config_file = system_service_config_file();
668716

669717
init_config(context);
670718
ReportSvcStatus(SERVICE_START_PENDING, 0, 1010);
@@ -709,6 +757,7 @@ VOID SvcInit(DWORD dwArgc, LPTSTR* lpszArgv)
709757
default:
710758
more = 0;
711759
stubby_debug("Stop object signalled");
760+
set_startup(SERVICE_DEMAND_START);
712761
break;
713762
}
714763

windows/README.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ tested on Windows 10 and Windows 8. There is limited support for Windows 7
66
welcomed via github!
77
https://github.com/getdnsapi/stubby
88

9+
A development version of a Windows GUI for Stubby is also available, see
10+
https://dnsprivacy.org/wiki/display/DP/DNS+Privacy+Daemon+-+Stubby
11+
912
Installation
1013
--------------------
1114
Download and run the installer.
@@ -61,7 +64,7 @@ for details of available levels).
6164
A different location for the configuration file can be specified by adding:
6265
-C "<full path to stubby.yml>"
6366

64-
We are working on support for running stubby as a service on Windows 10
67+
See below for details of running stubby as a service on Windows 10
6568

6669
Test Stubby
6770
--------------------
@@ -122,6 +125,19 @@ task just run
122125

123126
schtasks /create /tn Stubby /XML "C:\Program Files\Stubby\stubby.xml" /RU <you_user_name>
124127

128+
Running as a Windows service
129+
----------------------------
130+
Stubby can now also be installed as a windows service by using the command
131+
132+
stubby -w install
133+
134+
It can then be controlled via the Windows Service Manager or directly on the command
135+
line by replacing 'install' with 'start', 'stop' or 'remove' in the above command.
136+
The start command can take 2 parameters, the logging level and a custom configuration file.
137+
138+
NOTE: When running as a service, stubby will read its default configuration from
139+
140+
C:\Program Files\Stubby\stubbyservice.yml
125141

126142
Known Issues
127143
--------------------

windows/stubby-feature.wxs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
<Component Id="stubby.exe">
1919
<File Id="stubby.exe" Source="Stubby/stubby.exe" KeyPath="yes" Checksum="yes"/>
2020
<ServiceInstall Id="ServiceInstaller" Type="ownProcess"
21-
Name="Stubby" DisplayName="Stubby DNS Privacy Proxy"
22-
Description="Enable performing DNS name lookups over secure channels."
21+
Name="Stubby" DisplayName="Stubby DNS Privacy stub resolver"
22+
Description="Enable performing DNS name lookups over encrypted channels."
2323
Start="demand"
2424
ErrorControl="normal"
2525
Arguments="-w service">
@@ -53,6 +53,9 @@
5353
<Component Id="stubby.yml">
5454
<File Id="stubby.yml" Source="Stubby/stubby.yml" KeyPath="yes" Checksum="yes" />
5555
</Component>
56+
<Component Id="stubbyservice.yml">
57+
<File Id="stubbyservice.yml" Name="stubbyservice.yml" Source="Stubby/stubby.yml" KeyPath="yes" Checksum="yes" />
58+
</Component>
5659
<Component Id="README.txt">
5760
<File Id="README.txt" Source="Stubby/README.txt" KeyPath="yes" Checksum="yes"/>
5861
</Component>

0 commit comments

Comments
 (0)