diff options
author | Emily <[email protected]> | 2023-06-25 02:25:02 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2023-06-24 18:25:02 -0600 |
commit | 119e8794bcbda80ca337c1bb6164718e1490cc4f (patch) | |
tree | e277458cf998cb446a4f55296feae3822007813d | |
parent | 22927e278dc29c9d1804c20f483510ec569f23ed (diff) | |
download | caddy-119e8794bcbda80ca337c1bb6164718e1490cc4f.tar.gz caddy-119e8794bcbda80ca337c1bb6164718e1490cc4f.zip |
core: Skip `chmod` for abstract unix sockets (#5596)
because those aren't real paths on the filesystem and thus can't be `chmod`ed
-rw-r--r-- | listeners.go | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/listeners.go b/listeners.go index cbce68d61..a12d67f27 100644 --- a/listeners.go +++ b/listeners.go @@ -151,6 +151,7 @@ func (na NetworkAddress) listen(ctx context.Context, portOffset uint, config net var err error var address string var unixFileMode fs.FileMode + var isAbtractUnixSocket bool // split unix socket addr early so lnKey // is independent of permissions bits @@ -160,6 +161,7 @@ func (na NetworkAddress) listen(ctx context.Context, portOffset uint, config net if err != nil { return nil, err } + isAbtractUnixSocket = strings.HasPrefix(address, "@") } else { address = na.JoinHostPort(portOffset) } @@ -167,8 +169,11 @@ func (na NetworkAddress) listen(ctx context.Context, portOffset uint, config net // if this is a unix socket, see if we already have it open, // force socket permissions on it and return early if socket, err := reuseUnixSocket(na.Network, address); socket != nil || err != nil { - if err := os.Chmod(address, unixFileMode); err != nil { - return nil, fmt.Errorf("unable to set permissions (%s) on %s: %v", unixFileMode, address, err) + if !isAbtractUnixSocket { + if err := os.Chmod(address, unixFileMode); err != nil { + return nil, fmt.Errorf("unable to set permissions (%s) on %s: %v", unixFileMode, address, err) + } + } return socket, err } @@ -211,8 +216,10 @@ func (na NetworkAddress) listen(ctx context.Context, portOffset uint, config net } if IsUnixNetwork(na.Network) { - if err := os.Chmod(address, unixFileMode); err != nil { - return nil, fmt.Errorf("unable to set permissions (%s) on %s: %v", unixFileMode, address, err) + if !isAbtractUnixSocket { + if err := os.Chmod(address, unixFileMode); err != nil { + return nil, fmt.Errorf("unable to set permissions (%s) on %s: %v", unixFileMode, address, err) + } } } |