"strconv"
"golang.org/x/crypto/ssh"
+
+ "git.tizen.org/tools/slav/logger"
)
// installPublicKey marshals and stores key in a proper location to be read by ssh daemon.
func installPublicKey(key *ssh.PublicKey, homedir, uid, gid string) error {
+ logger.WithProperty("method", "installPublicKey").
+ WithProperty("PublicKey", key).
+ WithProperty("homedir", homedir).
+ WithProperty("uid", uid).
+ WithProperty("gid", gid).
+ Debug("Start.")
if key == nil {
+ logger.WithProperty("method", "installPublicKey").
+ WithProperty("PublicKey", key).
+ Error("Empty public ssh key provided.")
return errors.New("empty public key")
}
sshDir := path.Join(homedir, ".ssh")
err := os.MkdirAll(sshDir, 0755)
if err != nil {
+ logger.WithProperty("method", "installPublicKey").
+ WithProperty("PublicKey", key).
+ Error("Failed to create ssh directory.")
return err
}
f, err := os.OpenFile(path.Join(sshDir, "authorized_keys"),
os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
+ logger.WithProperty("method", "installPublicKey").
+ WithProperty("PublicKey", key).
+ Errorf("Failed to open %v/authorized_keys file.", sshDir)
return err
}
defer f.Close()
err = updateOwnership(f, sshDir, uid, gid)
if err != nil {
+ logger.WithProperty("method", "installPublicKey").
+ WithProperty("PublicKey", key).
+ Error("Failed to update ownership of authorized_keys file.")
return err
}
_, err = f.Write(ssh.MarshalAuthorizedKey(*key))
"git.tizen.org/tools/boruta"
"git.tizen.org/tools/muxpi/sw/nanopi/stm"
+ "git.tizen.org/tools/slav/logger"
"golang.org/x/crypto/ssh"
)
// Otherwise it may make it unusable for other STM users. It is closed
// when blinkMaintenanceLED exits.
func (r *Rusalka) PutInMaintenance(msg string) error {
+ logger.WithProperty("type", "Rusalka").WithProperty("method", "PutInMaintenance").
+ WithProperty("Message", msg).
+ Debug("Start.")
err := r.stm.printMessage(msg)
if err != nil {
+ logger.WithProperty("type", "Rusalka").WithProperty("method", "PutInMaintenance").
+ WithProperty("Message", msg).WithError(err).
+ Error("Failed to print on stm display.")
return err
}
var ctx context.Context
// Prepare is part of implementation of Dryad interface. Call to Prepare stops LED blinking.
func (r *Rusalka) Prepare(key *ssh.PublicKey) (err error) {
+ logger.WithProperty("type", "Rusalka").WithProperty("method", "Prepare").
+ WithProperty("SSH public key", key).
+ Debug("Start.")
// Stop maintenance.
if r.cancelMaintenance != nil {
r.cancelMaintenance()
// Remove/Add user.
err = r.dryadUser.delete()
if err != nil {
+ logger.WithProperty("type", "Rusalka").WithProperty("method", "Prepare").
+ WithProperty("SSH public key", key).WithError(err).
+ Error("User removal failed")
return fmt.Errorf("user removal failed: %s", err)
}
err = r.dryadUser.add()
if err != nil {
+ logger.WithProperty("type", "Rusalka").WithProperty("method", "Prepare").
+ WithProperty("SSH public key", key).WithError(err).
+ Error("User creation failed")
return fmt.Errorf("user creation failed: %s", err)
}
// Verify user's existance.
err = r.dryadUser.update()
if err != nil {
+ logger.WithProperty("type", "Rusalka").WithProperty("method", "Prepare").
+ WithProperty("SSH public key", key).WithError(err).
+ Error("user information update failed")
return fmt.Errorf("user information update failed: %s", err)
}
return r.dryadUser.installKey(key)