summaryrefslogtreecommitdiffstats
path: root/models/ssh_key.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-12-19 21:43:32 -0500
committerUnknwon <u@gogs.io>2015-12-19 21:43:32 -0500
commit53eb37d5292942e8f6d667f9a6fb9d35455d2967 (patch)
treea5386fe64d7dfd31767423b613dcd765893f4d99 /models/ssh_key.go
parent3bcdb3855cffb916944923e7442c929ff94d4574 (diff)
downloadgitea-53eb37d5292942e8f6d667f9a6fb9d35455d2967.tar.gz
gitea-53eb37d5292942e8f6d667f9a6fb9d35455d2967.zip
fix #1436
Diffstat (limited to 'models/ssh_key.go')
-rw-r--r--models/ssh_key.go28
1 files changed, 5 insertions, 23 deletions
diff --git a/models/ssh_key.go b/models/ssh_key.go
index e213d083c1..f0db4de430 100644
--- a/models/ssh_key.go
+++ b/models/ssh_key.go
@@ -33,24 +33,6 @@ const (
)
var sshOpLocker = sync.Mutex{}
-var SSHPath string // SSH directory.
-
-// homeDir returns the home directory of current user.
-func homeDir() string {
- home, err := com.HomeDir()
- if err != nil {
- log.Fatal(4, "Fail to get home directory: %v", err)
- }
- return home
-}
-
-func init() {
- // Determine and create .ssh path.
- SSHPath = filepath.Join(homeDir(), ".ssh")
- if err := os.MkdirAll(SSHPath, 0700); err != nil {
- log.Fatal(4, "fail to create '%s': %v", SSHPath, err)
- }
-}
type KeyType int
@@ -233,7 +215,7 @@ func saveAuthorizedKeyFile(keys ...*PublicKey) error {
sshOpLocker.Lock()
defer sshOpLocker.Unlock()
- fpath := filepath.Join(SSHPath, "authorized_keys")
+ fpath := filepath.Join(setting.SSHRootPath, "authorized_keys")
f, err := os.OpenFile(fpath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)
if err != nil {
return err
@@ -449,8 +431,8 @@ func deletePublicKey(e *xorm.Session, keyID int64) error {
return nil
}
- fpath := filepath.Join(SSHPath, "authorized_keys")
- tmpPath := filepath.Join(SSHPath, "authorized_keys.tmp")
+ fpath := filepath.Join(setting.SSHRootPath, "authorized_keys")
+ tmpPath := filepath.Join(setting.SSHRootPath, "authorized_keys.tmp")
if err = rewriteAuthorizedKeys(key, fpath, tmpPath); err != nil {
return err
} else if err = os.Remove(fpath); err != nil {
@@ -492,7 +474,7 @@ func RewriteAllPublicKeys() error {
sshOpLocker.Lock()
defer sshOpLocker.Unlock()
- tmpPath := filepath.Join(SSHPath, "authorized_keys.tmp")
+ tmpPath := filepath.Join(setting.SSHRootPath, "authorized_keys.tmp")
f, err := os.OpenFile(tmpPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return err
@@ -508,7 +490,7 @@ func RewriteAllPublicKeys() error {
return err
}
- fpath := filepath.Join(SSHPath, "authorized_keys")
+ fpath := filepath.Join(setting.SSHRootPath, "authorized_keys")
if com.IsExist(fpath) {
if err = os.Remove(fpath); err != nil {
return err