mirror of
https://github.com/safing/portmaster
synced 2025-09-02 02:29:12 +00:00
Fix escaping in Windows Service creation
This commit is contained in:
parent
93cc4a056e
commit
438d62dcc2
1 changed files with 12 additions and 5 deletions
|
@ -82,23 +82,30 @@ func getExePath() (string, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
func getServiceExecCommand(exePath string) []string {
|
func getServiceExecCommand(exePath string, escape bool) []string {
|
||||||
return []string{
|
return []string{
|
||||||
windows.EscapeArg(exePath),
|
maybeEscape(exePath, escape),
|
||||||
"run",
|
"run",
|
||||||
"core-service",
|
"core-service",
|
||||||
"--db",
|
"--db",
|
||||||
windows.EscapeArg(databaseRootDir),
|
maybeEscape(dataRoot.Path, escape),
|
||||||
"--input-signals",
|
"--input-signals",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func maybeEscape(s string, escape bool) string {
|
||||||
|
if escape {
|
||||||
|
return windows.EscapeArg(s)
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
func getServiceConfig(exePath string) mgr.Config {
|
func getServiceConfig(exePath string) mgr.Config {
|
||||||
return mgr.Config{
|
return mgr.Config{
|
||||||
ServiceType: windows.SERVICE_WIN32_OWN_PROCESS,
|
ServiceType: windows.SERVICE_WIN32_OWN_PROCESS,
|
||||||
StartType: mgr.StartAutomatic,
|
StartType: mgr.StartAutomatic,
|
||||||
ErrorControl: mgr.ErrorNormal,
|
ErrorControl: mgr.ErrorNormal,
|
||||||
BinaryPathName: strings.Join(getServiceExecCommand(exePath), " "),
|
BinaryPathName: strings.Join(getServiceExecCommand(exePath, true), " "),
|
||||||
DisplayName: "Portmaster Core",
|
DisplayName: "Portmaster Core",
|
||||||
Description: "Portmaster Application Firewall - Core Service",
|
Description: "Portmaster Application Firewall - Core Service",
|
||||||
}
|
}
|
||||||
|
@ -140,7 +147,7 @@ func installWindowsService(cmd *cobra.Command, args []string) error {
|
||||||
s, err := m.OpenService(serviceName)
|
s, err := m.OpenService(serviceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// create service
|
// create service
|
||||||
cmd := getServiceExecCommand(exePath)
|
cmd := getServiceExecCommand(exePath, false)
|
||||||
s, err = m.CreateService(serviceName, cmd[0], getServiceConfig(exePath), cmd[1:]...)
|
s, err = m.CreateService(serviceName, cmd[0], getServiceConfig(exePath), cmd[1:]...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create service: %s", err)
|
return fmt.Errorf("failed to create service: %s", err)
|
||||||
|
|
Loading…
Add table
Reference in a new issue