Compare commits

..

4 Commits

Author SHA1 Message Date
Eugene Burkov
3918789ca7 aghnet: imp permissions logic 2023-02-06 16:11:55 +03:00
Eugene Burkov
da1b53a3b4 Merge branch 'master' into 4728-cap-check 2023-02-06 15:45:10 +03:00
Ainar Garipov
6a032bb821 Pull request: 5433-league-icon
Updates #5433.

Squashed commit of the following:

commit 4190845e5edb7f3a5f6970ec1d739aabf0a87f57
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Feb 2 18:01:10 2023 +0300

    filtering: fix league of legends icon
2023-02-02 18:06:01 +03:00
yscialom
b82c67405f Fix #4714: correctly check thread can bind to privileged ports 2022-07-09 17:21:56 +02:00
7 changed files with 48 additions and 7 deletions

View File

@@ -23,6 +23,12 @@ See also the [v0.107.24 GitHub milestone][ms-v0.107.24].
NOTE: Add new changes BELOW THIS COMMENT. NOTE: Add new changes BELOW THIS COMMENT.
--> -->
### Fixed
- The icon for League Of Legends on the Blocked services page ([#5433]).
[#5433]: https://github.com/AdguardTeam/AdGuardHome/issues/5433
<!-- <!--
NOTE: Add new changes ABOVE THIS COMMENT. NOTE: Add new changes ABOVE THIS COMMENT.
--> -->

View File

@@ -80,6 +80,11 @@ func CanBindPrivilegedPorts() (can bool, err error) {
return canBindPrivilegedPorts() return canBindPrivilegedPorts()
} }
// AcquirePermissions tries to acquire permissions to bind to privileged ports.
func AcquirePermissions() (err error) {
return acquirePermissions()
}
// NetInterface represents an entry of network interfaces map. // NetInterface represents an entry of network interfaces map.
type NetInterface struct { type NetInterface struct {
// Addresses are the network interface addresses. // Addresses are the network interface addresses.

View File

@@ -7,3 +7,7 @@ import "github.com/AdguardTeam/AdGuardHome/internal/aghos"
func canBindPrivilegedPorts() (can bool, err error) { func canBindPrivilegedPorts() (can bool, err error) {
return aghos.HaveAdminRights() return aghos.HaveAdminRights()
} }
func acquirePermissions() (err error) {
return nil
}

View File

@@ -23,17 +23,17 @@ const dhcpcdConf = "etc/dhcpcd.conf"
func canBindPrivilegedPorts() (can bool, err error) { func canBindPrivilegedPorts() (can bool, err error) {
res, err := unix.PrctlRetInt( res, err := unix.PrctlRetInt(
unix.PR_CAP_AMBIENT, unix.PR_CAPBSET_READ,
unix.PR_CAP_AMBIENT_IS_SET,
unix.CAP_NET_BIND_SERVICE, unix.CAP_NET_BIND_SERVICE,
0, 0,
0, 0,
0,
) )
if err != nil { if err != nil {
if errors.Is(err, unix.EINVAL) { if errors.Is(err, unix.EINVAL) {
// Older versions of Linux kernel do not support this. Print a // Older versions of Linux kernel do not support this. Print a
// warning and check admin rights. // warning and check admin rights.
log.Info("warning: cannot check capability cap_net_bind_service: %s", err) log.Info("warning: cannot check cap_net_bind_service: %s", err)
} else { } else {
return false, err return false, err
} }
@@ -45,6 +45,21 @@ func canBindPrivilegedPorts() (can bool, err error) {
return res == 1 || adm, nil return res == 1 || adm, nil
} }
func acquirePermissions() (err error) {
_, err = unix.PrctlRetInt(
unix.PR_CAP_AMBIENT,
unix.PR_CAP_AMBIENT_RAISE,
unix.CAP_NET_BIND_SERVICE,
0,
0,
)
if err != nil {
return fmt.Errorf("raising cap_net_bind_service: %w", err)
}
return nil
}
// dhcpcdStaticConfig checks if interface is configured by /etc/dhcpcd.conf to // dhcpcdStaticConfig checks if interface is configured by /etc/dhcpcd.conf to
// have a static IP. // have a static IP.
func (n interfaceName) dhcpcdStaticConfig(r io.Reader) (subsources []string, cont bool, err error) { func (n interfaceName) dhcpcdStaticConfig(r io.Reader) (subsources []string, cont bool, err error) {

View File

@@ -43,3 +43,7 @@ func closePortChecker(c io.Closer) (err error) {
func isAddrInUse(err syscall.Errno) (ok bool) { func isAddrInUse(err syscall.Errno) (ok bool) {
return errors.Is(err, windows.WSAEADDRINUSE) return errors.Is(err, windows.WSAEADDRINUSE)
} }
func acquirePermissions() (err error) {
return nil
}

View File

@@ -1283,7 +1283,7 @@ var blockedServices = []blockedService{{
}, { }, {
ID: "leagueoflegends", ID: "leagueoflegends",
Name: "League of Legends", Name: "League of Legends",
IconSVG: []byte("<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 30 30\" width=\"60px\" height=\"60px\"><path d=\"M 7 4 L 9 7.25 L 9 22.75 L 6.875 26 L 21.957031 26 L 25 22 L 14 22 L 14 4 L 7 4 z M 16 4.0507812 L 16 6.0585938 C 20.493 6.5575937 24 10.375 24 15 C 24 16.849 23.438516 18.569 22.478516 20 L 24.785156 20 C 25.556156 18.498 26 16.801 26 15 C 26 9.272 21.598 4.5577812 16 4.0507812 z M 6.8730469 7.6113281 C 5.0940469 9.5663281 4 12.155 4 15 C 4 17.837 5.0884219 20.418094 6.8574219 22.371094 L 7 22.154297 L 7 19.105469 C 6.365 17.872469 6 16.479 6 15 C 6 13.521 6.365 12.127531 7 10.894531 L 7 7.8164062 L 6.8730469 7.6113281 z\"/></svg>"), IconSVG: []byte("<svg xmlns=\"http://www.w3.org/2000/svg\" fill=\"currentColor\" viewBox=\"0 0 30 30\"><path d=\"M 7 4 L 9 7.25 L 9 22.75 L 6.875 26 L 21.957031 26 L 25 22 L 14 22 L 14 4 L 7 4 z M 16 4.0507812 L 16 6.0585938 C 20.493 6.5575937 24 10.375 24 15 C 24 16.849 23.438516 18.569 22.478516 20 L 24.785156 20 C 25.556156 18.498 26 16.801 26 15 C 26 9.272 21.598 4.5577812 16 4.0507812 z M 6.8730469 7.6113281 C 5.0940469 9.5663281 4 12.155 4 15 C 4 17.837 5.0884219 20.418094 6.8574219 22.371094 L 7 22.154297 L 7 19.105469 C 6.365 17.872469 6 16.479 6 15 C 6 13.521 6.365 12.127531 7 10.894531 L 7 7.8164062 L 6.8730469 7.6113281 z\"/></svg>"),
Rules: []string{ Rules: []string{
"||leagueoflegends.co.kr^", "||leagueoflegends.co.kr^",
"||leagueoflegends.com^", "||leagueoflegends.com^",

View File

@@ -570,14 +570,21 @@ func startMods() (err error) {
func checkPermissions() { func checkPermissions() {
log.Info("Checking if AdGuard Home has necessary permissions") log.Info("Checking if AdGuard Home has necessary permissions")
if ok, err := aghnet.CanBindPrivilegedPorts(); !ok || err != nil { err := aghnet.AcquirePermissions()
log.Fatal("This is the first launch of AdGuard Home. You must run it as Administrator.") if err != nil {
log.Debug("acquiring necessary permissions: %s", err)
var ok bool
if ok, err = aghnet.CanBindPrivilegedPorts(); !ok || err != nil {
log.Fatal("This is the first launch of AdGuard Home. You must run it as Administrator.")
}
} }
// We should check if AdGuard Home is able to bind to port 53 // We should check if AdGuard Home is able to bind to port 53
err := aghnet.CheckPort("tcp", netip.AddrPortFrom(netutil.IPv4Localhost(), defaultPortDNS)) err = aghnet.CheckPort("tcp", netip.AddrPortFrom(netutil.IPv4Localhost(), defaultPortDNS))
if err != nil { if err != nil {
if errors.Is(err, os.ErrPermission) { if errors.Is(err, os.ErrPermission) {
log.Debug("checking permissions via binding: %v", err)
log.Fatal(`Permission check failed. log.Fatal(`Permission check failed.
AdGuard Home is not allowed to bind to privileged ports (for instance, port 53). AdGuard Home is not allowed to bind to privileged ports (for instance, port 53).