Skip to content

Commit a75d3c9

Browse files
regedajohnweldon
authored andcommitted
Examples appear in the documentation (#251)
1 parent 5c8e362 commit a75d3c9

21 files changed

+59
-395
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
# Basic LDAP v3 functionality for the GO programming language.
55

6+
The library implements the following specifications:
7+
- https://tools.ietf.org/html/rfc4511 for basic operations
8+
- https://tools.ietf.org/html/rfc3062 for password modify operation
9+
- https://tools.ietf.org/html/rfc4514 for distinguished names parsing
10+
611
## Features:
712

813
- Connecting to LDAP server (non-TLS, TLS, STARTTLS)
@@ -15,11 +20,6 @@
1520
- Delete Requests / Responses
1621
- Modify DN Requests / Responses
1722

18-
## Examples:
19-
20-
- search
21-
- modify
22-
2323
## Go Modules:
2424

2525
`go get github.com/go-ldap/ldap/v3`

add.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
//
2-
// https://tools.ietf.org/html/rfc4511
3-
//
4-
// AddRequest ::= [APPLICATION 8] SEQUENCE {
5-
// entry LDAPDN,
6-
// attributes AttributeList }
7-
//
8-
// AttributeList ::= SEQUENCE OF attribute Attribute
9-
101
package ldap
112

123
import (

compare.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
1-
// File contains Compare functionality
2-
//
3-
// https://tools.ietf.org/html/rfc4511
4-
//
5-
// CompareRequest ::= [APPLICATION 14] SEQUENCE {
6-
// entry LDAPDN,
7-
// ava AttributeValueAssertion }
8-
//
9-
// AttributeValueAssertion ::= SEQUENCE {
10-
// attributeDesc AttributeDescription,
11-
// assertionValue AssertionValue }
12-
//
13-
// AttributeDescription ::= LDAPString
14-
// -- Constrained to <attributedescription>
15-
// -- [RFC4512]
16-
//
17-
// AttributeValue ::= OCTET STRING
18-
//
19-
201
package ldap
212

223
import (

del.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
//
2-
// https://tools.ietf.org/html/rfc4511
3-
//
4-
// DelRequest ::= [APPLICATION 10] LDAPDN
5-
61
package ldap
72

83
import (

dn.go

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,3 @@
1-
// File contains DN parsing functionality
2-
//
3-
// https://tools.ietf.org/html/rfc4514
4-
//
5-
// distinguishedName = [ relativeDistinguishedName
6-
// *( COMMA relativeDistinguishedName ) ]
7-
// relativeDistinguishedName = attributeTypeAndValue
8-
// *( PLUS attributeTypeAndValue )
9-
// attributeTypeAndValue = attributeType EQUALS attributeValue
10-
// attributeType = descr / numericoid
11-
// attributeValue = string / hexstring
12-
//
13-
// ; The following characters are to be escaped when they appear
14-
// ; in the value to be encoded: ESC, one of <escaped>, leading
15-
// ; SHARP or SPACE, trailing SPACE, and NULL.
16-
// string = [ ( leadchar / pair ) [ *( stringchar / pair )
17-
// ( trailchar / pair ) ] ]
18-
//
19-
// leadchar = LUTF1 / UTFMB
20-
// LUTF1 = %x01-1F / %x21 / %x24-2A / %x2D-3A /
21-
// %x3D / %x3F-5B / %x5D-7F
22-
//
23-
// trailchar = TUTF1 / UTFMB
24-
// TUTF1 = %x01-1F / %x21 / %x23-2A / %x2D-3A /
25-
// %x3D / %x3F-5B / %x5D-7F
26-
//
27-
// stringchar = SUTF1 / UTFMB
28-
// SUTF1 = %x01-21 / %x23-2A / %x2D-3A /
29-
// %x3D / %x3F-5B / %x5D-7F
30-
//
31-
// pair = ESC ( ESC / special / hexpair )
32-
// special = escaped / SPACE / SHARP / EQUALS
33-
// escaped = DQUOTE / PLUS / COMMA / SEMI / LANGLE / RANGLE
34-
// hexstring = SHARP 1*hexpair
35-
// hexpair = HEX HEX
36-
//
37-
// where the productions <descr>, <numericoid>, <COMMA>, <DQUOTE>,
38-
// <EQUALS>, <ESC>, <HEX>, <LANGLE>, <NULL>, <PLUS>, <RANGLE>, <SEMI>,
39-
// <SPACE>, <SHARP>, and <UTFMB> are defined in [RFC4512].
40-
//
41-
421
package ldap
432

443
import (
@@ -48,7 +7,7 @@ import (
487
"fmt"
498
"strings"
509

51-
"github.com/go-asn1-ber/asn1-ber"
10+
ber "github.com/go-asn1-ber/asn1-ber"
5211
)
5312

5413
// AttributeTypeAndValue represents an attributeTypeAndValue from https://tools.ietf.org/html/rfc4514
@@ -69,7 +28,8 @@ type DN struct {
6928
RDNs []*RelativeDN
7029
}
7130

72-
// ParseDN returns a distinguishedName or an error
31+
// ParseDN returns a distinguishedName or an error.
32+
// The function respects https://tools.ietf.org/html/rfc4514
7333
func ParseDN(str string) (*DN, error) {
7434
dn := new(DN)
7535
dn.RDNs = make([]*RelativeDN, 0)

moddn_test.go renamed to examples_moddn_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"log"
55
)
66

7-
// ExampleConn_ModifyDN_renameNoMove shows how to rename an entry without moving it
7+
// This example shows how to rename an entry without moving it
88
func ExampleConn_ModifyDN_renameNoMove() {
9-
conn, err := Dial("tcp", "ldap.example.org:389")
9+
conn, err := DialURL("ldap://ldap.example.org:389")
1010
if err != nil {
1111
log.Fatalf("Failed to connect: %s\n", err)
1212
}
@@ -26,9 +26,9 @@ func ExampleConn_ModifyDN_renameNoMove() {
2626
}
2727
}
2828

29-
// ExampleConn_ModifyDN_renameAndMove shows how to rename an entry and moving it to a new base
29+
// This example shows how to rename an entry and moving it to a new base
3030
func ExampleConn_ModifyDN_renameAndMove() {
31-
conn, err := Dial("tcp", "ldap.example.org:389")
31+
conn, err := DialURL("ldap://ldap.example.org:389")
3232
if err != nil {
3333
log.Fatalf("Failed to connect: %s\n", err)
3434
}
@@ -50,9 +50,9 @@ func ExampleConn_ModifyDN_renameAndMove() {
5050
}
5151
}
5252

53-
// ExampleConn_ModifyDN_moveOnly shows how to move an entry to a new base without renaming the RDN
53+
// This example shows how to move an entry to a new base without renaming the RDN
5454
func ExampleConn_ModifyDN_moveOnly() {
55-
conn, err := Dial("tcp", "ldap.example.org:389")
55+
conn, err := DialURL("ldap://ldap.example.org:389")
5656
if err != nil {
5757
log.Fatalf("Failed to connect: %s\n", err)
5858
}

example_test.go renamed to examples_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import (
66
"log"
77
)
88

9-
// ExampleConn_Bind demonstrates how to bind a connection to an ldap user
9+
// This example demonstrates how to bind a connection to an ldap user
1010
// allowing access to restricted attributes that user has access to
1111
func ExampleConn_Bind() {
12-
l, err := Dial("tcp", fmt.Sprintf("%s:%d", "ldap.example.com", 389))
12+
l, err := DialURL("ldap://ldap.example.com:389")
1313
if err != nil {
1414
log.Fatal(err)
1515
}
@@ -21,9 +21,9 @@ func ExampleConn_Bind() {
2121
}
2222
}
2323

24-
// ExampleConn_Search demonstrates how to use the search interface
24+
// This example demonstrates how to use the search interface
2525
func ExampleConn_Search() {
26-
l, err := Dial("tcp", fmt.Sprintf("%s:%d", "ldap.example.com", 389))
26+
l, err := DialURL("ldap://ldap.example.com:389")
2727
if err != nil {
2828
log.Fatal(err)
2929
}
@@ -47,9 +47,9 @@ func ExampleConn_Search() {
4747
}
4848
}
4949

50-
// ExampleStartTLS demonstrates how to start a TLS connection
50+
// This example demonstrates how to start a TLS connection
5151
func ExampleConn_StartTLS() {
52-
l, err := Dial("tcp", fmt.Sprintf("%s:%d", "ldap.example.com", 389))
52+
l, err := DialURL("ldap://ldap.example.com:389")
5353
if err != nil {
5454
log.Fatal(err)
5555
}
@@ -64,9 +64,9 @@ func ExampleConn_StartTLS() {
6464
// Operations via l are now encrypted
6565
}
6666

67-
// ExampleConn_Compare demonstrates how to compare an attribute with a value
67+
// This example demonstrates how to compare an attribute with a value
6868
func ExampleConn_Compare() {
69-
l, err := Dial("tcp", fmt.Sprintf("%s:%d", "ldap.example.com", 389))
69+
l, err := DialURL("ldap://ldap.example.com:389")
7070
if err != nil {
7171
log.Fatal(err)
7272
}
@@ -81,7 +81,7 @@ func ExampleConn_Compare() {
8181
}
8282

8383
func ExampleConn_PasswordModify_admin() {
84-
l, err := Dial("tcp", fmt.Sprintf("%s:%d", "ldap.example.com", 389))
84+
l, err := DialURL("ldap://ldap.example.com:389")
8585
if err != nil {
8686
log.Fatal(err)
8787
}
@@ -101,7 +101,7 @@ func ExampleConn_PasswordModify_admin() {
101101
}
102102

103103
func ExampleConn_PasswordModify_generatedPassword() {
104-
l, err := Dial("tcp", fmt.Sprintf("%s:%d", "ldap.example.com", 389))
104+
l, err := DialURL("ldap://ldap.example.com:389")
105105
if err != nil {
106106
log.Fatal(err)
107107
}
@@ -123,7 +123,7 @@ func ExampleConn_PasswordModify_generatedPassword() {
123123
}
124124

125125
func ExampleConn_PasswordModify_setNewPassword() {
126-
l, err := Dial("tcp", fmt.Sprintf("%s:%d", "ldap.example.com", 389))
126+
l, err := DialURL("ldap://ldap.example.com:389")
127127
if err != nil {
128128
log.Fatal(err)
129129
}
@@ -143,7 +143,7 @@ func ExampleConn_PasswordModify_setNewPassword() {
143143
}
144144

145145
func ExampleConn_Modify() {
146-
l, err := Dial("tcp", fmt.Sprintf("%s:%d", "ldap.example.com", 389))
146+
l, err := DialURL("ldap://ldap.example.com:389")
147147
if err != nil {
148148
log.Fatal(err)
149149
}
@@ -160,7 +160,7 @@ func ExampleConn_Modify() {
160160
}
161161
}
162162

163-
// Example User Authentication shows how a typical application can verify a login attempt
163+
// This example shows how a typical application can verify a login attempt
164164
func Example_userAuthentication() {
165165
// The username and password we want to check
166166
username := "someuser"
@@ -169,7 +169,7 @@ func Example_userAuthentication() {
169169
bindusername := "readonly"
170170
bindpassword := "password"
171171

172-
l, err := Dial("tcp", fmt.Sprintf("%s:%d", "ldap.example.com", 389))
172+
l, err := DialURL("ldap://ldap.example.com:389")
173173
if err != nil {
174174
log.Fatal(err)
175175
}
@@ -221,7 +221,7 @@ func Example_userAuthentication() {
221221
}
222222

223223
func Example_beherappolicy() {
224-
l, err := Dial("tcp", fmt.Sprintf("%s:%d", "ldap.example.com", 389))
224+
l, err := DialURL("ldap://ldap.example.com:389")
225225
if err != nil {
226226
log.Fatal(err)
227227
}
@@ -260,7 +260,7 @@ func Example_beherappolicy() {
260260
}
261261

262262
func Example_vchuppolicy() {
263-
l, err := Dial("tcp", fmt.Sprintf("%s:%d", "ldap.example.com", 389))
263+
l, err := DialURL("ldap://ldap.example.com:389")
264264
if err != nil {
265265
log.Fatal(err)
266266
}
@@ -305,7 +305,7 @@ func Example_vchuppolicy() {
305305
// This example demonstrates how to use ControlPaging to manually execute a
306306
// paginated search request instead of using SearchWithPaging.
307307
func ExampleControlPaging_manualPaging() {
308-
conn, err := Dial("tcp", fmt.Sprintf("%s:%d", "ldap.example.com", 389))
308+
conn, err := DialURL("ldap://ldap.example.com:389")
309309
if err != nil {
310310
log.Fatal(err)
311311
}

moddn.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
// Package ldap - moddn.go contains ModifyDN functionality
2-
//
3-
// https://tools.ietf.org/html/rfc4511
4-
// ModifyDNRequest ::= [APPLICATION 12] SEQUENCE {
5-
// entry LDAPDN,
6-
// newrdn RelativeLDAPDN,
7-
// deleteoldrdn BOOLEAN,
8-
// newSuperior [0] LDAPDN OPTIONAL }
9-
//
10-
//
111
package ldap
122

133
import (

modify.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,3 @@
1-
// File contains Modify functionality
2-
//
3-
// https://tools.ietf.org/html/rfc4511
4-
//
5-
// ModifyRequest ::= [APPLICATION 6] SEQUENCE {
6-
// object LDAPDN,
7-
// changes SEQUENCE OF change SEQUENCE {
8-
// operation ENUMERATED {
9-
// add (0),
10-
// delete (1),
11-
// replace (2),
12-
// ... },
13-
// modification PartialAttribute } }
14-
//
15-
// PartialAttribute ::= SEQUENCE {
16-
// type AttributeDescription,
17-
// vals SET OF value AttributeValue }
18-
//
19-
// AttributeDescription ::= LDAPString
20-
// -- Constrained to <attributedescription>
21-
// -- [RFC4512]
22-
//
23-
// AttributeValue ::= OCTET STRING
24-
//
25-
261
package ldap
272

283
import (

passwdmodify.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
// This file contains the password modify extended operation as specified in rfc 3062
2-
//
3-
// https://tools.ietf.org/html/rfc3062
4-
//
5-
61
package ldap
72

83
import (
@@ -61,7 +56,7 @@ func (req *PasswordModifyRequest) appendTo(envelope *ber.Packet) error {
6156

6257
// NewPasswordModifyRequest creates a new PasswordModifyRequest
6358
//
64-
// According to the RFC 3602:
59+
// According to the RFC 3602 (https://tools.ietf.org/html/rfc3062):
6560
// userIdentity is a string representing the user associated with the request.
6661
// This string may or may not be an LDAPDN (RFC 2253).
6762
// If userIdentity is empty then the operation will act on the user associated

0 commit comments

Comments
 (0)