31
"syscall"
32
"time"
33
34
+ "github.com/caddyserver/caddy/v2/internal"
35
"github.com/quic-go/quic-go"
36
"github.com/quic-go/quic-go/http3"
37
"go.uber.org/zap"
158
// is independent of permissions bits
159
if na.IsUnixNetwork() {
160
var err error
160
- address, unixFileMode, err = splitUnixSocketPermissionsBits(na.Host)
161
+ address, unixFileMode, err = internal.SplitUnixSocketPermissionsBits(na.Host)
162
if err != nil {
163
return nil, err
164
}
320
return strings.HasPrefix(netw, "unix")
321
}
322
322
-// Takes a unix socket address in the unusual "path|bits" format
323
-// (e.g. /run/caddy.sock|0222) and tries to split it into
324
-// socket path (host) and permissions bits (port). Colons (":")
325
-// can't be used as separator, as socket paths on Windows may
326
-// include a drive letter (e.g. `unix/c:\absolute\path.sock`).
327
-// Permission bits will default to 0200 if none are specified.
328
-// Throws an error, if the first carrying bit does not
329
-// include write perms (e.g. `0422` or `022`).
330
-// Symbolic permission representation (e.g. `u=w,g=w,o=w`)
331
-// is not supported and will throw an error for now!
332
-func splitUnixSocketPermissionsBits(addr string) (path string, fileMode fs.FileMode, err error) {
333
- addrSplit := strings.SplitN(addr, "|", 2)
334
-
335
- if len(addrSplit) == 2 {
336
- // parse octal permission bit string as uint32
337
- fileModeUInt64, err := strconv.ParseUint(addrSplit[1], 8, 32)
338
- if err != nil {
339
- return "", 0, fmt.Errorf("could not parse octal permission bits in %s: %v", addr, err)
340
- }
341
- fileMode = fs.FileMode(fileModeUInt64)
342
-
343
- // FileMode.String() returns a string like `-rwxr-xr--` for `u=rwx,g=rx,o=r` (`0754`)
344
- if string(fileMode.String()[2]) != "w" {
345
- return "", 0, fmt.Errorf("owner of the socket requires '-w-' (write, octal: '2') permissions at least; got '%s' in %s", fileMode.String()[1:4], addr)
346
- }
347
-
348
- return addrSplit[0], fileMode, nil
349
- }
350
-
351
- // default to 0200 (symbolic: `u=w,g=,o=`)
352
- // if no permission bits are specified
353
- return addr, 0200, nil
354
-}
355
-
323
// ParseNetworkAddress parses addr into its individual
324
// components. The input string is expected to be of
325
// the form "network/host:port-range" where any part is
344
network = defaultNetwork
345
}
346
if IsUnixNetwork(network) {
380
- _, _, err := splitUnixSocketPermissionsBits(host)
347
+ _, _, err := internal.SplitUnixSocketPermissionsBits(host)
348
return NetworkAddress{
349
Network: network,
350
Host: host,