mirror of
https://github.com/safing/portmaster
synced 2025-09-01 18:19: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
|
||||
}
|
||||
|
||||
func getServiceExecCommand(exePath string) []string {
|
||||
func getServiceExecCommand(exePath string, escape bool) []string {
|
||||
return []string{
|
||||
windows.EscapeArg(exePath),
|
||||
maybeEscape(exePath, escape),
|
||||
"run",
|
||||
"core-service",
|
||||
"--db",
|
||||
windows.EscapeArg(databaseRootDir),
|
||||
maybeEscape(dataRoot.Path, escape),
|
||||
"--input-signals",
|
||||
}
|
||||
}
|
||||
|
||||
func maybeEscape(s string, escape bool) string {
|
||||
if escape {
|
||||
return windows.EscapeArg(s)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func getServiceConfig(exePath string) mgr.Config {
|
||||
return mgr.Config{
|
||||
ServiceType: windows.SERVICE_WIN32_OWN_PROCESS,
|
||||
StartType: mgr.StartAutomatic,
|
||||
ErrorControl: mgr.ErrorNormal,
|
||||
BinaryPathName: strings.Join(getServiceExecCommand(exePath), " "),
|
||||
BinaryPathName: strings.Join(getServiceExecCommand(exePath, true), " "),
|
||||
DisplayName: "Portmaster Core",
|
||||
Description: "Portmaster Application Firewall - Core Service",
|
||||
}
|
||||
|
@ -140,7 +147,7 @@ func installWindowsService(cmd *cobra.Command, args []string) error {
|
|||
s, err := m.OpenService(serviceName)
|
||||
if err != nil {
|
||||
// create service
|
||||
cmd := getServiceExecCommand(exePath)
|
||||
cmd := getServiceExecCommand(exePath, false)
|
||||
s, err = m.CreateService(serviceName, cmd[0], getServiceConfig(exePath), cmd[1:]...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create service: %s", err)
|
||||
|
|
Loading…
Add table
Reference in a new issue