mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-31 11:52:10 +00:00
Merge branch 'dev' of github.com:gogits/gogs into dev
Conflicts: conf/app.ini
This commit is contained in:
commit
061a879cea
20 changed files with 659 additions and 48 deletions
|
@ -22,6 +22,7 @@ import (
|
|||
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/modules/process"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -119,23 +120,30 @@ func CheckPublicKeyString(content string) (bool, error) {
|
|||
tmpFile.WriteString(content)
|
||||
tmpFile.Close()
|
||||
|
||||
// … see if ssh-keygen recognizes its contents
|
||||
// Check if ssh-keygen recognizes its contents.
|
||||
stdout, stderr, err := process.Exec("CheckPublicKeyString", "ssh-keygen", "-l", "-f", tmpPath)
|
||||
if err != nil {
|
||||
return false, errors.New("ssh-keygen -l -f: " + stderr)
|
||||
} else if len(stdout) < 2 {
|
||||
return false, errors.New("ssh-keygen returned not enough output to evaluate the key")
|
||||
}
|
||||
|
||||
// The ssh-keygen in Windows does not print key type, so no need go further.
|
||||
if setting.IsWindows {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
sshKeygenOutput := strings.Split(stdout, " ")
|
||||
if len(sshKeygenOutput) < 4 {
|
||||
return false, errors.New("Not enough fields returned by ssh-keygen -l -f")
|
||||
}
|
||||
|
||||
// Check if key type and key size match.
|
||||
keySize, err := com.StrTo(sshKeygenOutput[0]).Int()
|
||||
if err != nil {
|
||||
return false, errors.New("Cannot get key size of the given key")
|
||||
}
|
||||
keyType := strings.TrimSpace(sshKeygenOutput[len(sshKeygenOutput)-1])
|
||||
|
||||
if minimumKeySize := MinimumKeySize[keyType]; minimumKeySize == 0 {
|
||||
return false, errors.New("Sorry, unrecognized public key type")
|
||||
} else if keySize < minimumKeySize {
|
||||
|
@ -160,10 +168,14 @@ func saveAuthorizedKeyFile(key *PublicKey) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if finfo.Mode().Perm() > 0600 {
|
||||
log.Error(4, "authorized_keys file has unusual permission flags: %s - setting to -rw-------", finfo.Mode().Perm().String())
|
||||
if err = f.Chmod(0600); err != nil {
|
||||
return err
|
||||
|
||||
// FIXME: following command does not support in Windows.
|
||||
if !setting.IsWindows {
|
||||
if finfo.Mode().Perm() > 0600 {
|
||||
log.Error(4, "authorized_keys file has unusual permission flags: %s - setting to -rw-------", finfo.Mode().Perm().String())
|
||||
if err = f.Chmod(0600); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -95,8 +95,13 @@ func NewRepoContext() {
|
|||
if err != nil {
|
||||
log.Fatal(4, "Fail to get Git version: %v", err)
|
||||
}
|
||||
if ver.Major < 2 && ver.Minor < 8 {
|
||||
log.Fatal(4, "Gogs requires Git version greater or equal to 1.8.0")
|
||||
|
||||
reqVer, err := git.ParseVersion("1.7.1")
|
||||
if err != nil {
|
||||
log.Fatal(4, "Fail to parse required Git version: %v", err)
|
||||
}
|
||||
if ver.LessThan(reqVer) {
|
||||
log.Fatal(4, "Gogs requires Git version greater or equal to 1.7.1")
|
||||
}
|
||||
|
||||
// Check if server has basic git setting and set if not.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue