forked from mavricknz/ldap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
moddn.go
55 lines (46 loc) · 1.65 KB
/
moddn.go
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
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ldap
import (
"github.com/mavricknz/asn1-ber"
)
//ModifyDNRequest ::= [APPLICATION 12] SEQUENCE {
//entry LDAPDN,
//newrdn RelativeLDAPDN,
//deleteoldrdn BOOLEAN,
//newSuperior [0] LDAPDN OPTIONAL }
//
//ModifyDNResponse ::= [APPLICATION 13] LDAPResult
type ModDnRequest struct {
DN string
NewRDN string
DeleteOldDn bool
NewSuperiorDN string
Controls []Control
}
//Untested.
func (l *LDAPConnection) ModDn(req *ModDnRequest) error {
messageID, ok := l.nextMessageID()
if !ok {
return NewLDAPError(ErrorClosing, "MessageID channel is closed.")
}
encodedModDn := encodeModDnRequest(req)
packet, err := requestBuildPacket(messageID, encodedModDn, req.Controls)
if err != nil {
return err
}
return l.sendReqRespPacket(messageID, packet)
}
func encodeModDnRequest(req *ModDnRequest) (p *ber.Packet) {
p = ber.Encode(ber.ClassApplication, ber.TypeConstructed,
ApplicationModifyDNRequest, nil, ApplicationMap[ApplicationModifyDNRequest])
p.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimative, ber.TagOctetString, req.DN, "LDAPDN"))
p.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimative, ber.TagOctetString, req.NewRDN, "NewRDN"))
p.AppendChild(ber.NewBoolean(ber.ClassUniversal, ber.TypePrimative, ber.TagBoolean, req.DeleteOldDn, "deleteoldrdn"))
if len(req.NewSuperiorDN) > 0 {
p.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimative,
ber.TagOctetString, req.NewSuperiorDN, "NewSuperiorDN"))
}
return
}