-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull request 56: AGDNS-2244 Darwin service
Updates #2. Squashed commit of the following: commit f403747 Author: Eugene Burkov <[email protected]> Date: Mon Jun 24 19:46:31 2024 +0300 README: imp doc commit 1c15e76 Author: Eugene Burkov <[email protected]> Date: Mon Jun 24 17:11:40 2024 +0300 all: imp code commit 8fcfd5e Author: Eugene Burkov <[email protected]> Date: Mon Jun 24 16:45:59 2024 +0300 all: imp docs commit 40da1bc Author: Eugene Burkov <[email protected]> Date: Mon Jun 24 16:39:21 2024 +0300 all: imp docs commit ff804fd Author: Eugene Burkov <[email protected]> Date: Mon Jun 24 15:21:49 2024 +0300 all: require darwin service exec path
- Loading branch information
1 parent
97642d4
commit da3b068
Showing
8 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Package agdcos contains utilities for functions requiring system calls and | ||
// other OS-specific APIs. | ||
package agdcos | ||
|
||
// ValidateExecPath returns an error if the path to the executable is not valid | ||
// for the current platform. | ||
func ValidateExecPath(execPath string) (err error) { | ||
return validateExecPath(execPath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//go:build darwin | ||
|
||
package agdcos | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/AdguardTeam/golibs/errors" | ||
) | ||
|
||
// errBadExecPath is returned when the executable is installed into an invalid | ||
// location. | ||
const errBadExecPath errors.Error = "bad executable path for service" | ||
|
||
// validateExecPath returns an error if execPath is not a valid executable's | ||
// location, i.e. is not within the /Applications directory. | ||
// | ||
// TODO(e.burkov): Consider allowing the executable to be installed in other | ||
// directories owned by root. | ||
func validateExecPath(execPath string) (err error) { | ||
execPath, err = filepath.EvalSymlinks(execPath) | ||
if err != nil { | ||
return fmt.Errorf("evaluating executable path symlinks: %v", err) | ||
} | ||
|
||
execPath, err = filepath.Abs(execPath) | ||
if err != nil { | ||
return fmt.Errorf("getting absolute path of %q: %v", execPath, err) | ||
} | ||
|
||
if !strings.HasPrefix(execPath, "/Applications/") { | ||
return errBadExecPath | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//go:build !darwin | ||
|
||
package agdcos | ||
|
||
// validateExecPath is a no-op on non-Darwin platforms. | ||
func validateExecPath(_ string) (err error) { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters