Skip to content

Commit 0d89626

Browse files
committed
Don't run the permissions checks on non-Unix platforms
This is way too annoying on Windows systems.
1 parent cc9774f commit 0d89626

3 files changed

Lines changed: 43 additions & 31 deletions

File tree

dnscrypt-proxy/common.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ import (
66
"errors"
77
"net"
88
"os"
9-
"path"
109
"strconv"
1110
"strings"
1211
"unicode"
13-
14-
"github.com/jedisct1/dlog"
1512
)
1613

1714
type CryptoConstruction uint16
@@ -167,31 +164,3 @@ func ReadTextFile(filename string) (string, error) {
167164
}
168165

169166
func isDigit(b byte) bool { return b >= '0' && b <= '9' }
170-
171-
func maybeWritableByOtherUsers(p string) (bool, string, error) {
172-
p = path.Clean(p)
173-
for p != "/" && p != "." {
174-
st, err := os.Stat(p)
175-
if err != nil {
176-
return false, p, err
177-
}
178-
mode := st.Mode()
179-
if mode.Perm()&2 != 0 && !(st.IsDir() && mode&os.ModeSticky == os.ModeSticky) {
180-
return true, p, nil
181-
}
182-
p = path.Dir(p)
183-
}
184-
return false, "", nil
185-
}
186-
187-
func WarnIfMaybeWritableByOtherUsers(p string) {
188-
if ok, px, err := maybeWritableByOtherUsers(p); ok {
189-
if px == p {
190-
dlog.Criticalf("[%s] is writable by other system users - If this is not intentional, it is recommended to fix the access permissions", p)
191-
} else {
192-
dlog.Warnf("[%s] can be modified by other system users because [%s] is writable by other users - If this is not intentional, it is recommended to fix the access permissions", p, px)
193-
}
194-
} else if err != nil {
195-
dlog.Warnf("Error while checking if [%s] is accessible: [%s] : [%s]", p, px, err)
196-
}
197-
}

dnscrypt-proxy/permcheck_others.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build !unix
2+
3+
package main
4+
5+
func WarnIfMaybeWritableByOtherUsers(p string) {
6+
// No-op
7+
}

dnscrypt-proxy/permcheck_unix.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import (
4+
"os"
5+
"path"
6+
7+
"github.com/jedisct1/dlog"
8+
)
9+
10+
func maybeWritableByOtherUsers(p string) (bool, string, error) {
11+
p = path.Clean(p)
12+
for p != "/" && p != "." {
13+
st, err := os.Stat(p)
14+
if err != nil {
15+
return false, p, err
16+
}
17+
mode := st.Mode()
18+
if mode.Perm()&2 != 0 && !(st.IsDir() && mode&os.ModeSticky == os.ModeSticky) {
19+
return true, p, nil
20+
}
21+
p = path.Dir(p)
22+
}
23+
return false, "", nil
24+
}
25+
26+
func WarnIfMaybeWritableByOtherUsers(p string) {
27+
if ok, px, err := maybeWritableByOtherUsers(p); ok {
28+
if px == p {
29+
dlog.Criticalf("[%s] is writable by other system users - If this is not intentional, it is recommended to fix the access permissions", p)
30+
} else {
31+
dlog.Warnf("[%s] can be modified by other system users because [%s] is writable by other users - If this is not intentional, it is recommended to fix the access permissions", p, px)
32+
}
33+
} else if err != nil {
34+
dlog.Warnf("Error while checking if [%s] is accessible: [%s] : [%s]", p, px, err)
35+
}
36+
}

0 commit comments

Comments
 (0)