summaryrefslogtreecommitdiff
path: root/internal/authentication/ldap_control_types.go
blob: c7f4bd5cf8d40ee867d4bc8b2719bcaee27b5ffa (plain)
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
package authentication

import (
	ber "github.com/go-asn1-ber/asn1-ber"
)

type controlMsftServerPolicyHints struct {
	oid string
}

// GetControlType implements ldap.Control.
func (c *controlMsftServerPolicyHints) GetControlType() string {
	return c.oid
}

// Encode implements ldap.Control.
func (c *controlMsftServerPolicyHints) Encode() (packet *ber.Packet) {
	seq := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "PolicyHintsRequestValue")
	seq.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, 1, "Flags"))

	controlValue := ber.Encode(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, nil, "Control Value (Policy Hints)")
	controlValue.AppendChild(seq)

	packet = ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Control")
	packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, c.GetControlType(), "Control Type (LDAP_SERVER_POLICY_HINTS_OID)"))
	packet.AppendChild(ber.NewBoolean(ber.ClassUniversal, ber.TypePrimitive, ber.TagBoolean, true, "Criticality"))

	packet.AppendChild(controlValue)

	return packet
}

// String implements ldap.Control.
func (c *controlMsftServerPolicyHints) String() string {
	return "Enforce the password history length constraint (MS-SAMR section 3.1.1.7.1) during password set: " + c.GetControlType()
}