subsystem mode: add base-home-dir flag

This commit is contained in:
Nicola Murino 2020-11-05 12:12:11 +01:00
parent 1d5d184720
commit 36151d1ba9
No known key found for this signature in database
GPG key ID: 2F1FB59433D5A8CB
2 changed files with 53 additions and 33 deletions

View file

@ -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:

View file

@ -16,38 +16,45 @@ Usage:
sftpgo startsubsys [flags] sftpgo startsubsys [flags]
Flags: Flags:
-c, --config-dir string Location for SFTPGo config dir. This directory -d, --base-home-dir string If the user does not exist specify an alternate
should contain the "sftpgo" configuration file starting directory. The home directory for a new
or the configured config-file and it is used as user will be:
the base for files with a relative path (eg. the
private keys for the SFTP server, the SQLite
database if you use SQLite as data provider).
This flag can be set using SFTPGO_CONFIG_DIR
env var too. (default ".")
-f, --config-file string Name for SFTPGo configuration file. It must be
the name of a file stored in config-dir not the
absolute path to the configuration file. The
specified file name must have no extension we
automatically load JSON, YAML, TOML, HCL and
Java properties. Therefore if you set "sftpgo"
then "sftpgo.json", "sftpgo.yaml" and so on
are searched.
This flag can be set using SFTPGO_CONFIG_FILE
env var too. (default "sftpgo")
-h, --help help for startsubsys
-j, --log-to-journald Send logs to journald. Only available on Linux.
Use:
$ journalctl -o verbose -f <base-home-dir>/<username>
To see full logs. base-home-dir must be an absolute path.
If not set, the logs will be sent to the standard -c, --config-dir string Location for SFTPGo config dir. This directory
error should contain the "sftpgo" configuration file
-v, --log-verbose Enable verbose logs. This flag can be set or the configured config-file and it is used as
using SFTPGO_LOG_VERBOSE env var too. the base for files with a relative path (eg. the
(default true) private keys for the SFTP server, the SQLite
-p, --preserve-home If the user already exists, the existing home database if you use SQLite as data provider).
directory will not be changed This flag can be set using SFTPGO_CONFIG_DIR
env var too. (default ".")
-f, --config-file string Name for SFTPGo configuration file. It must be
the name of a file stored in config-dir not the
absolute path to the configuration file. The
specified file name must have no extension we
automatically load JSON, YAML, TOML, HCL and
Java properties. Therefore if you set "sftpgo"
then "sftpgo.json", "sftpgo.yaml" and so on
are searched.
This flag can be set using SFTPGO_CONFIG_FILE
env var too. (default "sftpgo")
-h, --help help for startsubsys
-j, --log-to-journald Send logs to journald. Only available on Linux.
Use:
$ journalctl -o verbose -f
To see full logs.
If not set, the logs will be sent to the standard
error
-v, --log-verbose Enable verbose logs. This flag can be set
using SFTPGO_LOG_VERBOSE env var too.
(default true)
-p, --preserve-home If the user already exists, the existing home
directory will not be changed
``` ```
In this mode `bolt` and `sqlite` providers are not usable as the same database file cannot be shared among multiple processes, if one of these provider is configured it will be automatically changed to `memory` provider. In this mode `bolt` and `sqlite` providers are not usable as the same database file cannot be shared among multiple processes, if one of these provider is configured it will be automatically changed to `memory` provider.