X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=rpc%2Fdial.go;h=0782ab08e617933e4e2c369651253d11324e355f;hb=5d6cc7f14a4bacc36bf3a23cd735a75ad4a90f1d;hp=d8a63386333d2c76c27affca33418d3378bcc4dc;hpb=3840c3fe7fab425ef7d20d2f686884b404bb5e62;p=safcm%2Fsafcm.git diff --git a/rpc/dial.go b/rpc/dial.go index d8a6338..0782ab0 100644 --- a/rpc/dial.go +++ b/rpc/dial.go @@ -32,7 +32,7 @@ import ( "ruderich.org/simon/safcm/remote" ) -func (c *Conn) DialSSH(user, host string) error { +func (c *Conn) DialSSH(user, host, sshConfig string) error { if c.events == nil { return fmt.Errorf("cannot reuse Conn") } @@ -48,8 +48,14 @@ func (c *Conn) DialSSH(user, host string) error { // Help debugging by showing executed shell commands opts += "x" } - c.cmd = exec.Command("ssh", remote, "/bin/sh", opts) - c.remote = remote + + c.sshRemote = remote + if sshConfig != "" { + c.sshOpts = append(c.sshOpts, "-F", sshConfig) + } + c.cmd = exec.Command("ssh", + append(append([]string{}, c.sshOpts...), + c.sshRemote, "/bin/sh", opts)...) stdin, err := c.cmd.StdinPipe() if err != nil { @@ -135,13 +141,13 @@ compat_sha512sum() { // // The target directory must no permit other users to delete our files // or symlink attacks and arbitrary code execution is possible. For - // /tmp this is guaranteed by the sticky bit. Make sure it has the - // proper permissions. + // /tmp this is guaranteed by the sticky bit. The code verifies the + // directory has the proper permissions. // // We cannot use `test -f && test -O` because this is open to TOCTOU // attacks. `stat` gives use the full file state. If the file is owned - // by us and not a symlink then it's safe to use (assuming sticky or - // directory not writable by others). + // by us and not a symlink then it's safe to use (assuming sticky + // directory or directory not writable by others). // // `test -e` is only used to prevent error messages if the file // doesn't exist. It does not guard against any races. @@ -251,12 +257,14 @@ f path = strings.TrimSuffix(path, "\n") c.debugf("DialSSH: uploading new remote to %q at %q", - c.remote, path) + c.sshRemote, path) - cmd := exec.Command("ssh", c.remote, - fmt.Sprintf("cat > %q", path)) + cmd := exec.Command("ssh", + append(append([]string{}, c.sshOpts...), + c.sshRemote, + fmt.Sprintf("cat > %q", path))...) cmd.Stdin = bytes.NewReader(helper) - err = c.handleStderrAsEvents(cmd) + err = c.handleStderrAsEvents(cmd) // cmd.Stderr if err != nil { return err }