Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*(home): do not require root privileges on the first run
Instead of requiring root privileges, we now check if AdGuard Home can bind to privileged ports. If it cannot, we suggest either running it with root privileges or grant CAP_NET_BIND_SERVICE capability. Please note, that on Windows we still require root access. Closes: #1699
- Loading branch information
Showing
2 changed files
with
63 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package util | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
) | ||
|
||
// CanBindPort - checks if we can bind to this port or not | ||
func CanBindPort(port int) (bool, error) { | ||
addr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("127.0.0.1:%d", port)) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
l, err := net.ListenTCP("tcp", addr) | ||
if err != nil { | ||
return false, err | ||
} | ||
_ = l.Close() | ||
return true, nil | ||
} |