forked from mavricknz/ldap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.go
50 lines (40 loc) · 1.22 KB
/
delete.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
// Copyright 2011 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"
)
type DeleteRequest struct {
DN string
Controls []Control
}
func (req *DeleteRequest) RecordType() uint8 {
return DeleteRecord
}
/*
Simple delete
*/
func (l *LDAPConnection) Delete(delReq *DeleteRequest) (error error) {
messageID, ok := l.nextMessageID()
if !ok {
return NewLDAPError(ErrorClosing, "MessageID channel is closed.")
}
encodedDelete := ber.NewString(ber.ClassApplication, ber.TypePrimative, ApplicationDelRequest, delReq.DN, ApplicationMap[ApplicationDelRequest])
packet, err := requestBuildPacket(messageID, encodedDelete, delReq.Controls)
if err != nil {
return err
}
return l.sendReqRespPacket(messageID, packet)
}
func NewDeleteRequest(dn string) (delReq *DeleteRequest) {
delReq = &DeleteRequest{DN: dn, Controls: make([]Control, 0)}
return
}
// TDDO make generic for mod/del/search via interface.
func (delReq *DeleteRequest) AddControl(control Control) {
if delReq.Controls == nil {
delReq.Controls = make([]Control, 0)
}
delReq.Controls = append(delReq.Controls, control)
}