grim/hgkeeper
Clone
Summary
Browse
Changes
Graph
Remove the explicit write access of admins to the hgkeeper repo.
23 months ago, Gary Kramlich
5389b17b4002
Remove the explicit write access of admins to the hgkeeper repo.
Fixes HGKEEPER-21
package
ssh
import
(
"errors"
"io/ioutil"
"path/filepath"
log
"github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh"
)
func
(
s
*
Server
)
setHostKeysPath
(
hostKeysPath
string
)
error
{
files
,
err
:=
ioutil
.
ReadDir
(
hostKeysPath
)
if
err
!=
nil
{
return
err
}
found
:=
false
for
_
,
file
:=
range
files
{
if
!
file
.
Mode
().
IsDir
()
{
path
:=
filepath
.
Join
(
hostKeysPath
,
file
.
Name
())
data
,
err
:=
ioutil
.
ReadFile
(
path
)
if
err
!=
nil
{
log
.
Warnf
(
"failed to read %s"
,
path
)
continue
}
key
,
err
:=
ssh
.
ParsePrivateKey
(
data
)
if
err
!=
nil
{
log
.
Warnf
(
"%s is not an ssh private key"
,
path
)
continue
}
s
.
server
.
AddHostKey
(
key
)
found
=
true
log
.
Infof
(
"added host key from %s"
,
path
)
}
}
if
!
found
{
return
errors
.
New
(
"failed to find a usable host key"
)
}
return
nil
}