This file is indexed.

/usr/share/gocode/src/github.com/masterzen/winrm/response.go is in golang-github-masterzen-winrm-dev 0.0~git20170601.0.1ca0ba6-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package winrm

import (
	"encoding/base64"
	"fmt"
	"io"
	"strconv"
	"strings"

	"github.com/masterzen/winrm/soap"
	"github.com/masterzen/xmlpath"
)

func first(node *xmlpath.Node, xpath string) (string, error) {
	path, err := xmlpath.CompileWithNamespace(xpath, soap.GetAllNamespaces())
	if err != nil {
		return "", err
	}
	content, _ := path.String(node)
	return content, nil
}

func any(node *xmlpath.Node, xpath string) (bool, error) {
	path, err := xmlpath.CompileWithNamespace(xpath, soap.GetAllNamespaces())
	if err != nil {
		return false, err
	}

	return path.Exists(node), nil

}

func xpath(node *xmlpath.Node, xpath string) ([]xmlpath.Node, error) {
	path, err := xmlpath.CompileWithNamespace(xpath, soap.GetAllNamespaces())
	if err != nil {
		return nil, err
	}

	nodes := make([]xmlpath.Node, 0, 1)
	iter := path.Iter(node)
	for iter.Next() {
		nodes = append(nodes, *(iter.Node()))
	}

	return nodes, nil
}

func ParseOpenShellResponse(response string) (string, error) {
	doc, err := xmlpath.Parse(strings.NewReader(response))
	if err != nil {
		return "", err
	}
	return first(doc, "//w:Selector[@Name='ShellId']")
}

func ParseExecuteCommandResponse(response string) (string, error) {
	doc, err := xmlpath.Parse(strings.NewReader(response))
	if err != nil {
		return "", err
	}
	return first(doc, "//rsp:CommandId")
}

func ParseSlurpOutputErrResponse(response string, stdout, stderr io.Writer) (bool, int, error) {
	var (
		finished bool
		exitCode int
	)

	doc, err := xmlpath.Parse(strings.NewReader(response))

	stdouts, _ := xpath(doc, "//rsp:Stream[@Name='stdout']")
	for _, node := range stdouts {
		content, _ := base64.StdEncoding.DecodeString(node.String())
		stdout.Write(content)
	}
	stderrs, _ := xpath(doc, "//rsp:Stream[@Name='stderr']")
	for _, node := range stderrs {
		content, _ := base64.StdEncoding.DecodeString(node.String())
		stderr.Write(content)
	}

	ended, _ := any(doc, "//*[@State='http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandState/Done']")

	if ended {
		finished = ended
		if exitBool, _ := any(doc, "//rsp:ExitCode"); exitBool {
			exit, _ := first(doc, "//rsp:ExitCode")
			exitCode, _ = strconv.Atoi(exit)
		}
	} else {
		finished = false
	}

	return finished, exitCode, err
}

func ParseSlurpOutputResponse(response string, stream io.Writer, streamType string) (bool, int, error) {
	var (
		finished bool
		exitCode int
	)

	doc, err := xmlpath.Parse(strings.NewReader(response))

	nodes, _ := xpath(doc, fmt.Sprintf("//rsp:Stream[@Name='%s']", streamType))
	for _, node := range nodes {
		content, _ := base64.StdEncoding.DecodeString(node.String())
		stream.Write(content)
	}

	ended, _ := any(doc, "//*[@State='http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandState/Done']")

	if ended {
		finished = ended
		if exitBool, _ := any(doc, "//rsp:ExitCode"); exitBool {
			exit, _ := first(doc, "//rsp:ExitCode")
			exitCode, _ = strconv.Atoi(exit)
		}
	} else {
		finished = false
	}

	return finished, exitCode, err
}