mirror of
https://github.com/gravitational/teleport
synced 2024-10-19 16:53:57 +00:00
Removed shell parsing for scp code as well.
This commit is contained in:
parent
1dbbf669ca
commit
f5c90a02e6
5
Godeps/Godeps.json
generated
5
Godeps/Godeps.json
generated
|
@ -366,11 +366,6 @@
|
||||||
"ImportPath": "github.com/mailgun/ttlmap",
|
"ImportPath": "github.com/mailgun/ttlmap",
|
||||||
"Rev": "16b258d86efc53ac5cf3e550604f566c32624fab"
|
"Rev": "16b258d86efc53ac5cf3e550604f566c32624fab"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/mattn/go-shellwords",
|
|
||||||
"Comment": "v1.0.2",
|
|
||||||
"Rev": "005a0944d84452842197c2108bd9168ced206f78"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/mdp/rsc/gf256",
|
"ImportPath": "github.com/mdp/rsc/gf256",
|
||||||
"Rev": "90f07065088deccf50b28eb37c93dad3078c0f3c"
|
"Rev": "90f07065088deccf50b28eb37c93dad3078c0f3c"
|
||||||
|
|
|
@ -40,7 +40,6 @@ import (
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/kardianos/osext"
|
"github.com/kardianos/osext"
|
||||||
"github.com/mattn/go-shellwords"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -79,11 +78,8 @@ func parseExecRequest(req *ssh.Request, ctx *ctx) (*execResponse, error) {
|
||||||
return nil, trace.BadParameter("failed to parse exec request, error: %v", err)
|
return nil, trace.BadParameter("failed to parse exec request, error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// split up command like a shell would do for us
|
// split up command by space to grab the first word
|
||||||
args, err := shellwords.Parse(e.Command)
|
args := strings.Split(e.Command, " ")
|
||||||
if err != nil {
|
|
||||||
return nil, trace.Wrap(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
_, f := filepath.Split(args[0])
|
_, f := filepath.Split(args[0])
|
||||||
|
|
8
vendor/github.com/mattn/go-shellwords/.travis.yml
generated
vendored
8
vendor/github.com/mattn/go-shellwords/.travis.yml
generated
vendored
|
@ -1,8 +0,0 @@
|
||||||
language: go
|
|
||||||
go:
|
|
||||||
- tip
|
|
||||||
before_install:
|
|
||||||
- go get github.com/mattn/goveralls
|
|
||||||
- go get golang.org/x/tools/cmd/cover
|
|
||||||
script:
|
|
||||||
- $HOME/gopath/bin/goveralls -repotoken 2FMhp57u8LcstKL9B190fLTcEnBtAAiEL
|
|
47
vendor/github.com/mattn/go-shellwords/README.md
generated
vendored
47
vendor/github.com/mattn/go-shellwords/README.md
generated
vendored
|
@ -1,47 +0,0 @@
|
||||||
# go-shellwords
|
|
||||||
|
|
||||||
[![Coverage Status](https://coveralls.io/repos/mattn/go-shellwords/badge.png?branch=master)](https://coveralls.io/r/mattn/go-shellwords?branch=master)
|
|
||||||
[![Build Status](https://travis-ci.org/mattn/go-shellwords.svg?branch=master)](https://travis-ci.org/mattn/go-shellwords)
|
|
||||||
|
|
||||||
Parse line as shell words.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```go
|
|
||||||
args, err := shellwords.Parse("./foo --bar=baz")
|
|
||||||
// args should be ["./foo", "--bar=baz"]
|
|
||||||
```
|
|
||||||
|
|
||||||
```go
|
|
||||||
os.Setenv("FOO", "bar")
|
|
||||||
p := shellwords.NewParser()
|
|
||||||
p.ParseEnv = true
|
|
||||||
args, err := p.Parse("./foo $FOO")
|
|
||||||
// args should be ["./foo", "bar"]
|
|
||||||
```
|
|
||||||
|
|
||||||
```go
|
|
||||||
p := shellwords.NewParser()
|
|
||||||
p.ParseBacktick = true
|
|
||||||
args, err := p.Parse("./foo `echo $SHELL`")
|
|
||||||
// args should be ["./foo", "/bin/bash"]
|
|
||||||
```
|
|
||||||
|
|
||||||
```go
|
|
||||||
shellwords.ParseBacktick = true
|
|
||||||
p := shellwords.NewParser()
|
|
||||||
args, err := p.Parse("./foo `echo $SHELL`")
|
|
||||||
// args should be ["./foo", "/bin/bash"]
|
|
||||||
```
|
|
||||||
|
|
||||||
# Thanks
|
|
||||||
|
|
||||||
This is based on cpan module [Parse::CommandLine](https://metacpan.org/pod/Parse::CommandLine).
|
|
||||||
|
|
||||||
# License
|
|
||||||
|
|
||||||
under the MIT License: http://mattn.mit-license.org/2014
|
|
||||||
|
|
||||||
# Author
|
|
||||||
|
|
||||||
Yasuhiro Matsumoto (a.k.a mattn)
|
|
145
vendor/github.com/mattn/go-shellwords/shellwords.go
generated
vendored
145
vendor/github.com/mattn/go-shellwords/shellwords.go
generated
vendored
|
@ -1,145 +0,0 @@
|
||||||
package shellwords
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"os"
|
|
||||||
"regexp"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
ParseEnv bool = false
|
|
||||||
ParseBacktick bool = false
|
|
||||||
)
|
|
||||||
|
|
||||||
var envRe = regexp.MustCompile(`\$({[a-zA-Z0-9_]+}|[a-zA-Z0-9_]+)`)
|
|
||||||
|
|
||||||
func isSpace(r rune) bool {
|
|
||||||
switch r {
|
|
||||||
case ' ', '\t', '\r', '\n':
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func replaceEnv(s string) string {
|
|
||||||
return envRe.ReplaceAllStringFunc(s, func(s string) string {
|
|
||||||
s = s[1:]
|
|
||||||
if s[0] == '{' {
|
|
||||||
s = s[1 : len(s)-1]
|
|
||||||
}
|
|
||||||
return os.Getenv(s)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
type Parser struct {
|
|
||||||
ParseEnv bool
|
|
||||||
ParseBacktick bool
|
|
||||||
Position int
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewParser() *Parser {
|
|
||||||
return &Parser{ParseEnv, ParseBacktick, 0}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Parser) Parse(line string) ([]string, error) {
|
|
||||||
args := []string{}
|
|
||||||
buf := ""
|
|
||||||
var escaped, doubleQuoted, singleQuoted, backQuote bool
|
|
||||||
backtick := ""
|
|
||||||
|
|
||||||
pos := -1
|
|
||||||
got := false
|
|
||||||
|
|
||||||
loop:
|
|
||||||
for i, r := range line {
|
|
||||||
if escaped {
|
|
||||||
buf += string(r)
|
|
||||||
escaped = false
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if r == '\\' {
|
|
||||||
if singleQuoted {
|
|
||||||
buf += string(r)
|
|
||||||
} else {
|
|
||||||
escaped = true
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if isSpace(r) {
|
|
||||||
if singleQuoted || doubleQuoted || backQuote {
|
|
||||||
buf += string(r)
|
|
||||||
backtick += string(r)
|
|
||||||
} else if got {
|
|
||||||
if p.ParseEnv {
|
|
||||||
buf = replaceEnv(buf)
|
|
||||||
}
|
|
||||||
args = append(args, buf)
|
|
||||||
buf = ""
|
|
||||||
got = false
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
switch r {
|
|
||||||
case '`':
|
|
||||||
if !singleQuoted && !doubleQuoted {
|
|
||||||
if p.ParseBacktick {
|
|
||||||
if backQuote {
|
|
||||||
out, err := shellRun(backtick)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
buf = out
|
|
||||||
}
|
|
||||||
backtick = ""
|
|
||||||
backQuote = !backQuote
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
backtick = ""
|
|
||||||
backQuote = !backQuote
|
|
||||||
}
|
|
||||||
case '"':
|
|
||||||
if !singleQuoted {
|
|
||||||
doubleQuoted = !doubleQuoted
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
case '\'':
|
|
||||||
if !doubleQuoted {
|
|
||||||
singleQuoted = !singleQuoted
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
case ';', '&', '|', '<', '>':
|
|
||||||
if !(escaped || singleQuoted || doubleQuoted || backQuote) {
|
|
||||||
pos = i
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
got = true
|
|
||||||
buf += string(r)
|
|
||||||
if backQuote {
|
|
||||||
backtick += string(r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if got {
|
|
||||||
if p.ParseEnv {
|
|
||||||
buf = replaceEnv(buf)
|
|
||||||
}
|
|
||||||
args = append(args, buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
if escaped || singleQuoted || doubleQuoted || backQuote {
|
|
||||||
return nil, errors.New("invalid command line string")
|
|
||||||
}
|
|
||||||
|
|
||||||
p.Position = pos
|
|
||||||
|
|
||||||
return args, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func Parse(line string) ([]string, error) {
|
|
||||||
return NewParser().Parse(line)
|
|
||||||
}
|
|
19
vendor/github.com/mattn/go-shellwords/util_posix.go
generated
vendored
19
vendor/github.com/mattn/go-shellwords/util_posix.go
generated
vendored
|
@ -1,19 +0,0 @@
|
||||||
// +build !windows
|
|
||||||
|
|
||||||
package shellwords
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func shellRun(line string) (string, error) {
|
|
||||||
shell := os.Getenv("SHELL")
|
|
||||||
b, err := exec.Command(shell, "-c", line).Output()
|
|
||||||
if err != nil {
|
|
||||||
return "", errors.New(err.Error() + ":" + string(b))
|
|
||||||
}
|
|
||||||
return strings.TrimSpace(string(b)), nil
|
|
||||||
}
|
|
17
vendor/github.com/mattn/go-shellwords/util_windows.go
generated
vendored
17
vendor/github.com/mattn/go-shellwords/util_windows.go
generated
vendored
|
@ -1,17 +0,0 @@
|
||||||
package shellwords
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func shellRun(line string) (string, error) {
|
|
||||||
shell := os.Getenv("COMSPEC")
|
|
||||||
b, err := exec.Command(shell, "/c", line).Output()
|
|
||||||
if err != nil {
|
|
||||||
return "", errors.New(err.Error() + ":" + string(b))
|
|
||||||
}
|
|
||||||
return strings.TrimSpace(string(b)), nil
|
|
||||||
}
|
|
Loading…
Reference in a new issue