winrmhelper

package
v0.0.0-...-03c656d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2021 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetString

func GetString(v interface{}) string

func SanitiseString

func SanitiseString(key string) string

SanitiseString returns the value of a string after some basic sanitisation checks to protect ourselves from command injection

func SanitiseTFInput

func SanitiseTFInput(d *schema.ResourceData, key string) string

SanitiseTFInput returns the value of a resource field after passing it through SanitiseString

func SetMachineExtensionNames

func SetMachineExtensionNames(client *winrm.Client, gpoDN, value string, execLocally bool) error

SetMachineExtensionName will add the necessary GUIDs to the GPO's gPCMachineExtensionNames attribute. These are required for the security settings part of a GPO to work.

func SortInnerSlice

func SortInnerSlice(m map[string]interface{}) map[string]interface{}

custom attributes can be single valued or multi valued. Multi-value attribute values are represented by a json array that gets converted to a list. It's not guaranteed that the order of the values returned by windows will match the order set by the user in the config, so we just check the members of the custom attributes map and if a slice is found then it's sorted before we compare it.

Types

type PSOutput

type PSOutput struct {
	PSStrings []psString `xml:"S"`
}

PSOutput is used to unmarshall CLIXML output Right now we are only using this to extract error messages, but it can be extended to unpack more elements if required.

func (*PSOutput) String

func (p *PSOutput) String() string

String() return a string containing the error message that was serialised in a CLIXML message

type PowerShell

type PowerShell struct {
	// contains filtered or unexported fields
}

PowerShell struct

func NewPS

func NewPS() *PowerShell

NewPS create new local session

func (*PowerShell) ExecutePScmd

func (p *PowerShell) ExecutePScmd(args ...string) (stdout string, stderr string, exitCode int, err error)

ExecutePScmd will execute the powershell command using exec

type SID

type SID struct {
	Value string `json:"Value"`
}

SID is a common structure by all "security principals". This means domains, users, computers, and groups. The structure we get from powershell contains more fields, but we're only interested in the Value.

type User

type User struct {
	GUID                   string `json:"ObjectGUID"`
	SAMAccountName         string `json:"SamAccountName"`
	PrincipalName          string `json:"UserPrincipalName"`
	City                   string
	Company                string
	Country                string
	Department             string
	Description            string
	DisplayName            string `json:"DisplayName"`
	DistinguishedName      string `json:"DistinguishedName"`
	Division               string
	EmailAddress           string
	EmployeeID             string
	EmployeeNumber         string
	Enabled                bool
	Fax                    string
	GivenName              string
	HomeDirectory          string
	HomeDrive              string
	HomePhone              string
	HomePage               string
	Initials               string
	MobilePhone            string
	Office                 string
	OfficePhone            string
	Organization           string
	OtherName              string
	POBox                  string
	PostalCode             string
	SID                    SID `json:"SID"`
	SmartcardLogonRequired bool
	State                  string
	StreetAddress          string
	Surname                string
	Title                  string
	TrustedForDelegation   bool
	UserAccountControl     int64 `json:"userAccountControl"`
	Password               string
	Container              string
	Domain                 string
	Username               string
	PasswordNeverExpires   bool
	CannotChangePassword   bool
	CustomAttributes       map[string]interface{}
}

User represents an AD User

func GetUserFromHost

func GetUserFromHost(client *winrm.Client, guid string, customAttributes []string, execLocally bool) (*User, error)

GetUserFromHost returns a User struct based on data retrieved from the AD Domain Controller.

func GetUserFromResource

func GetUserFromResource(d *schema.ResourceData) (*User, error)

GetUserFromResource returns a user struct built from Resource data

func (*User) DeleteUser

func (u *User) DeleteUser(client *winrm.Client, execLocally bool) error

DeleteUser deletes an AD user by calling Remove-ADUser

func (*User) ModifyUser

func (u *User) ModifyUser(d *schema.ResourceData, client *winrm.Client, execLocally bool) error

ModifyUser updates the AD user's details based on what's changed in the resource.

func (*User) NewUser

func (u *User) NewUser(client *winrm.Client, execLocally bool) (string, error)

NewUser creates the user by running the New-ADUser powershell command

type WinRMResult

type WinRMResult struct {
	Stdout   string
	StdErr   string
	ExitCode int
}

WinRMResult holds the stdout, stderr and exit code of a powershell command

func RunWinRMCommand

func RunWinRMCommand(conn *winrm.Client, cmds []string, json bool, forceArray bool, execLocally bool) (*WinRMResult, error)

RunWinRMCommand will run a powershell command and return the stdout and stderr The output is converted to JSON if the json patameter is set to true.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL