mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 06:40:54 +03:00
subsystem mode: add base-home-dir flag
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
logJournalD = false
|
logJournalD = false
|
||||||
preserveHomeDir = false
|
preserveHomeDir = false
|
||||||
|
baseHomeDir = ""
|
||||||
subsystemCmd = &cobra.Command{
|
subsystemCmd = &cobra.Command{
|
||||||
Use: "startsubsys",
|
Use: "startsubsys",
|
||||||
Short: "Use SFTPGo as SFTP file transfer subsystem",
|
Short: "Use SFTPGo as SFTP file transfer subsystem",
|
||||||
@@ -54,8 +55,8 @@ Command-line flags should be specified in the Subsystem declaration.
|
|||||||
}
|
}
|
||||||
username := osUser.Username
|
username := osUser.Username
|
||||||
homedir := osUser.HomeDir
|
homedir := osUser.HomeDir
|
||||||
logger.Info(logSender, connectionID, "starting SFTPGo %v as subsystem, user %#v home dir %#v config dir %#v",
|
logger.Info(logSender, connectionID, "starting SFTPGo %v as subsystem, user %#v home dir %#v config dir %#v base home dir %#v",
|
||||||
version.Get(), username, homedir, configDir)
|
version.Get(), username, homedir, configDir, baseHomeDir)
|
||||||
err = config.LoadConfig(configDir, configFile)
|
err = config.LoadConfig(configDir, configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(logSender, connectionID, "unable to load configuration: %v", err)
|
logger.Error(logSender, connectionID, "unable to load configuration: %v", err)
|
||||||
@@ -95,7 +96,12 @@ Command-line flags should be specified in the Subsystem declaration.
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
user.Username = username
|
user.Username = username
|
||||||
user.HomeDir = homedir
|
if baseHomeDir != "" && filepath.IsAbs(baseHomeDir) {
|
||||||
|
user.HomeDir = filepath.Join(baseHomeDir, username)
|
||||||
|
} else {
|
||||||
|
user.HomeDir = filepath.Clean(homedir)
|
||||||
|
}
|
||||||
|
logger.Debug(logSender, connectionID, "home dir for new user %#v", user.HomeDir)
|
||||||
user.Password = connectionID
|
user.Password = connectionID
|
||||||
user.Permissions = make(map[string][]string)
|
user.Permissions = make(map[string][]string)
|
||||||
user.Permissions["/"] = []string{dataprovider.PermAny}
|
user.Permissions["/"] = []string{dataprovider.PermAny}
|
||||||
@@ -119,6 +125,13 @@ Command-line flags should be specified in the Subsystem declaration.
|
|||||||
func init() {
|
func init() {
|
||||||
subsystemCmd.Flags().BoolVarP(&preserveHomeDir, "preserve-home", "p", false, `If the user already exists, the existing home
|
subsystemCmd.Flags().BoolVarP(&preserveHomeDir, "preserve-home", "p", false, `If the user already exists, the existing home
|
||||||
directory will not be changed`)
|
directory will not be changed`)
|
||||||
|
subsystemCmd.Flags().StringVarP(&baseHomeDir, "base-home-dir", "d", "", `If the user does not exist specify an alternate
|
||||||
|
starting directory. The home directory for a new
|
||||||
|
user will be:
|
||||||
|
|
||||||
|
<base-home-dir>/<username>
|
||||||
|
|
||||||
|
base-home-dir must be an absolute path.`)
|
||||||
subsystemCmd.Flags().BoolVarP(&logJournalD, "log-to-journald", "j", false, `Send logs to journald. Only available on Linux.
|
subsystemCmd.Flags().BoolVarP(&logJournalD, "log-to-journald", "j", false, `Send logs to journald. Only available on Linux.
|
||||||
Use:
|
Use:
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,13 @@ Usage:
|
|||||||
sftpgo startsubsys [flags]
|
sftpgo startsubsys [flags]
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
|
-d, --base-home-dir string If the user does not exist specify an alternate
|
||||||
|
starting directory. The home directory for a new
|
||||||
|
user will be:
|
||||||
|
|
||||||
|
<base-home-dir>/<username>
|
||||||
|
|
||||||
|
base-home-dir must be an absolute path.
|
||||||
-c, --config-dir string Location for SFTPGo config dir. This directory
|
-c, --config-dir string Location for SFTPGo config dir. This directory
|
||||||
should contain the "sftpgo" configuration file
|
should contain the "sftpgo" configuration file
|
||||||
or the configured config-file and it is used as
|
or the configured config-file and it is used as
|
||||||
|
|||||||
Reference in New Issue
Block a user