forked from toolshed/abra
		
	chore: bump deps
This commit is contained in:
		
							
								
								
									
										44
									
								
								vendor/github.com/docker/go-connections/sockets/unix_socket.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										44
									
								
								vendor/github.com/docker/go-connections/sockets/unix_socket.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @ -1,5 +1,3 @@ | ||||
| //go:build !windows | ||||
|  | ||||
| /* | ||||
| Package sockets is a simple unix domain socket wrapper. | ||||
|  | ||||
| @ -57,26 +55,6 @@ import ( | ||||
| // SockOption sets up socket file's creating option | ||||
| type SockOption func(string) error | ||||
|  | ||||
| // WithChown modifies the socket file's uid and gid | ||||
| func WithChown(uid, gid int) SockOption { | ||||
| 	return func(path string) error { | ||||
| 		if err := os.Chown(path, uid, gid); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		return nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // WithChmod modifies socket file's access mode. | ||||
| func WithChmod(mask os.FileMode) SockOption { | ||||
| 	return func(path string) error { | ||||
| 		if err := os.Chmod(path, mask); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		return nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // NewUnixSocketWithOpts creates a unix socket with the specified options. | ||||
| // By default, socket permissions are 0000 (i.e.: no access for anyone); pass | ||||
| // WithChmod() and WithChown() to set the desired ownership and permissions. | ||||
| @ -90,22 +68,7 @@ func NewUnixSocketWithOpts(path string, opts ...SockOption) (net.Listener, error | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	// net.Listen does not allow for permissions to be set. As a result, when | ||||
| 	// specifying custom permissions ("WithChmod()"), there is a short time | ||||
| 	// between creating the socket and applying the permissions, during which | ||||
| 	// the socket permissions are Less restrictive than desired. | ||||
| 	// | ||||
| 	// To work around this limitation of net.Listen(), we temporarily set the | ||||
| 	// umask to 0777, which forces the socket to be created with 000 permissions | ||||
| 	// (i.e.: no access for anyone). After that, WithChmod() must be used to set | ||||
| 	// the desired permissions. | ||||
| 	// | ||||
| 	// We don't use "defer" here, to reset the umask to its original value as soon | ||||
| 	// as possible. Ideally we'd be able to detect if WithChmod() was passed as | ||||
| 	// an option, and skip changing umask if default permissions are used. | ||||
| 	origUmask := syscall.Umask(0o777) | ||||
| 	l, err := net.Listen("unix", path) | ||||
| 	syscall.Umask(origUmask) | ||||
| 	l, err := listenUnix(path) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| @ -119,8 +82,3 @@ func NewUnixSocketWithOpts(path string, opts ...SockOption) (net.Listener, error | ||||
|  | ||||
| 	return l, nil | ||||
| } | ||||
|  | ||||
| // NewUnixSocket creates a unix socket with the specified path and group. | ||||
| func NewUnixSocket(path string, gid int) (net.Listener, error) { | ||||
| 	return NewUnixSocketWithOpts(path, WithChown(0, gid), WithChmod(0o660)) | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user