Maint: set PUID and PGID in openvpn configurator
This commit is contained in:
@@ -7,11 +7,11 @@ import (
|
||||
)
|
||||
|
||||
type AuthWriter interface {
|
||||
WriteAuthFile(user, password string, puid, pgid int) error
|
||||
WriteAuthFile(user, password string) error
|
||||
}
|
||||
|
||||
// WriteAuthFile writes the OpenVPN auth file to disk with the right permissions.
|
||||
func (c *configurator) WriteAuthFile(user, password string, puid, pgid int) error {
|
||||
func (c *configurator) WriteAuthFile(user, password string) error {
|
||||
file, err := os.Open(c.authFilePath)
|
||||
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
@@ -28,7 +28,7 @@ func (c *configurator) WriteAuthFile(user, password string, puid, pgid int) erro
|
||||
_ = file.Close()
|
||||
return err
|
||||
}
|
||||
err = file.Chown(puid, pgid)
|
||||
err = file.Chown(c.puid, c.pgid)
|
||||
if err != nil {
|
||||
_ = file.Close()
|
||||
return err
|
||||
@@ -60,7 +60,7 @@ func (c *configurator) WriteAuthFile(user, password string, puid, pgid int) erro
|
||||
_ = file.Close()
|
||||
return err
|
||||
}
|
||||
err = file.Chown(puid, pgid)
|
||||
err = file.Chown(c.puid, c.pgid)
|
||||
if err != nil {
|
||||
_ = file.Close()
|
||||
return err
|
||||
|
||||
@@ -32,8 +32,6 @@ type Loop struct {
|
||||
state state.Manager
|
||||
// Fixed parameters
|
||||
username string
|
||||
puid int
|
||||
pgid int
|
||||
buildInfo models.BuildInformation
|
||||
versionInfo bool
|
||||
// Configurators
|
||||
@@ -67,8 +65,7 @@ const (
|
||||
)
|
||||
|
||||
func NewLoop(openVPNSettings configuration.OpenVPN,
|
||||
providerSettings configuration.Provider,
|
||||
username string, puid, pgid int,
|
||||
providerSettings configuration.Provider, username string,
|
||||
allServers models.AllServers, conf Configurator,
|
||||
fw firewallConfigurer, routing routing.VPNGetter,
|
||||
portForward portforward.StartStopper,
|
||||
@@ -87,8 +84,6 @@ func NewLoop(openVPNSettings configuration.OpenVPN,
|
||||
statusManager: statusManager,
|
||||
state: state,
|
||||
username: username,
|
||||
puid: puid,
|
||||
pgid: pgid,
|
||||
buildInfo: buildInfo,
|
||||
versionInfo: versionInfo,
|
||||
conf: conf,
|
||||
|
||||
@@ -20,14 +20,17 @@ type configurator struct {
|
||||
cmder command.RunStarter
|
||||
configPath string
|
||||
authFilePath string
|
||||
puid, pgid int
|
||||
}
|
||||
|
||||
func NewConfigurator(logger logging.Logger,
|
||||
cmder command.RunStarter) Configurator {
|
||||
cmder command.RunStarter, puid, pgid int) Configurator {
|
||||
return &configurator{
|
||||
logger: logger,
|
||||
cmder: cmder,
|
||||
configPath: constants.OpenVPNConf,
|
||||
authFilePath: constants.OpenVPNAuthConf,
|
||||
puid: puid,
|
||||
pgid: pgid,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
|
||||
|
||||
if openVPNSettings.User != "" {
|
||||
err := l.conf.WriteAuthFile(
|
||||
openVPNSettings.User, openVPNSettings.Password, l.puid, l.pgid)
|
||||
openVPNSettings.User, openVPNSettings.Password)
|
||||
if err != nil {
|
||||
l.signalOrSetStatus(constants.Crashed)
|
||||
l.logAndWait(ctx, err)
|
||||
|
||||
Reference in New Issue
Block a user