Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion api/profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,15 @@ func FullProfilePath(dir string) string {

// defaultProfilePath retrieves the default path of the TSH profile.
func defaultProfilePath() string {
home := os.TempDir()
// start with UserHomeDir, which is the fastest option as it
// relies only on environment variables and does not perform
// a user lookup (which can be very slow on large AD environments)
home, err := os.UserHomeDir()
if err == nil && home != "" {
return home
}

home = os.TempDir()
if u, err := utils.CurrentUser(); err == nil && u.HomeDir != "" {
home = u.HomeDir
}
Expand Down
14 changes: 10 additions & 4 deletions lib/client/db/mysql/optionfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package mysql

import (
"os"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -44,11 +45,16 @@ type OptionFile struct {

func DefaultConfigPath() (string, error) {
// Default location is .my.cnf file in the user's home directory.
usr, err := utils.CurrentUser()
if err != nil {
return "", trace.ConvertSystemError(err)
home, err := os.UserHomeDir()
if err != nil || home == "" {
usr, err := utils.CurrentUser()
if err != nil {
return "", trace.ConvertSystemError(err)
}
home = usr.HomeDir
}
return filepath.Join(usr.HomeDir, mysqlOptionFile), nil

return filepath.Join(home, mysqlOptionFile), nil
}

// Load loads MySQL option file from the default location.
Expand Down
14 changes: 10 additions & 4 deletions lib/client/db/postgres/servicefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package postgres

import (
"os"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -46,11 +47,16 @@ type ServiceFile struct {
func Load() (*ServiceFile, error) {
// Default location is .pg_service.conf file in the user's home directory.
// TODO(r0mant): Check PGSERVICEFILE and PGSYSCONFDIR env vars as well.
user, err := utils.CurrentUser()
if err != nil {
return nil, trace.ConvertSystemError(err)
home, err := os.UserHomeDir()
if err != nil || home == "" {
user, err := utils.CurrentUser()
if err != nil {
return nil, trace.ConvertSystemError(err)
}
home = user.HomeDir
}
return LoadFromPath(filepath.Join(user.HomeDir, pgServiceFile))

return LoadFromPath(filepath.Join(home, pgServiceFile))
}

// LoadFromPath loads Posrtgres connection service file from the specified path.
Expand Down