mirror of
				https://github.com/yggdrasil-network/water.git
				synced 2025-11-04 03:05:10 +03:00 
			
		
		
		
	linux: Refactors Owner/Group to DevicePermissions
This commit is contained in:
		
							parent
							
								
									15d1b3ddbb
								
							
						
					
					
						commit
						937f6ba955
					
				
					 2 changed files with 24 additions and 20 deletions
				
			
		| 
						 | 
					@ -2,6 +2,18 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package water
 | 
					package water
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type DevicePermissions struct {
 | 
				
			||||||
 | 
						// ID of the user which will be granted ownership of the device.
 | 
				
			||||||
 | 
						// If set to a negative value, the owner value will not be changed.
 | 
				
			||||||
 | 
						// By default, Linux sets the owner to -1, which allows any user.
 | 
				
			||||||
 | 
						Owner uint
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// ID of the group which will be granted access to the device.
 | 
				
			||||||
 | 
						// If set to a negative value, the group value will not be changed.
 | 
				
			||||||
 | 
						// By default, Linux sets the group to -1, which allows any group.
 | 
				
			||||||
 | 
						Group uint
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// PlatformSpecificParams defines parameters in Config that are specific to
 | 
					// PlatformSpecificParams defines parameters in Config that are specific to
 | 
				
			||||||
// Linux. A zero-value of such type is valid, yielding an interface
 | 
					// Linux. A zero-value of such type is valid, yielding an interface
 | 
				
			||||||
// with OS defined name.
 | 
					// with OS defined name.
 | 
				
			||||||
| 
						 | 
					@ -15,20 +27,12 @@ type PlatformSpecificParams struct {
 | 
				
			||||||
	// Enable or disable persistence mode for the interface device.
 | 
						// Enable or disable persistence mode for the interface device.
 | 
				
			||||||
	Persist bool
 | 
						Persist bool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// ID of the user which will be granted ownership of the device.
 | 
						// Owner and Group permissions for the device.
 | 
				
			||||||
	// If set to a negative value, the owner value will not be changed.
 | 
						// A zero-value of this field, i.e. nil, indicates that no changes to owner
 | 
				
			||||||
	// By default, Linux sets the owner to -1, which allows any user.
 | 
						// or group will be made.
 | 
				
			||||||
	Owner int
 | 
						Permissions *DevicePermissions
 | 
				
			||||||
 | 
					 | 
				
			||||||
	// ID of the group which will be granted access to the device.
 | 
					 | 
				
			||||||
	// If set to a negative value, the group value will not be changed.
 | 
					 | 
				
			||||||
	// By default, Linux sets the group to -1, which allows any group.
 | 
					 | 
				
			||||||
	Group int
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func defaultPlatformSpecificParams() PlatformSpecificParams {
 | 
					func defaultPlatformSpecificParams() PlatformSpecificParams {
 | 
				
			||||||
	return PlatformSpecificParams{
 | 
						return PlatformSpecificParams{}
 | 
				
			||||||
		Owner: -1,
 | 
					 | 
				
			||||||
		Group: -1,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -81,16 +81,16 @@ func createInterface(fd uintptr, ifName string, flags uint16) (createdIFName str
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func setDeviceOptions(fd uintptr, config Config) (err error) {
 | 
					func setDeviceOptions(fd uintptr, config Config) (err error) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Set Device Owner
 | 
						// Device Permissions
 | 
				
			||||||
	if config.Owner >= 0 {
 | 
						if config.Permissions != nil {
 | 
				
			||||||
		if err = ioctl(fd, syscall.TUNSETOWNER, uintptr(config.Owner)); err != nil {
 | 
					
 | 
				
			||||||
 | 
							// Set Owner
 | 
				
			||||||
 | 
							if err = ioctl(fd, syscall.TUNSETOWNER, uintptr(config.Permissions.Owner)); err != nil {
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Set Device Group
 | 
							// Set Group
 | 
				
			||||||
	if config.Group >= 0 {
 | 
							if err = ioctl(fd, syscall.TUNSETGROUP, uintptr(config.Permissions.Group)); err != nil {
 | 
				
			||||||
		if err = ioctl(fd, syscall.TUNSETGROUP, uintptr(config.Group)); err != nil {
 | 
					 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue