paulo repa 1. 1. 2 0 10 1 lightweight directory access protocol paulo repa [email protected]

41
Paulo Repa 1 . 1 . 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa [email protected]

Upload: steven-tate

Post on 19-Jan-2016

227 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

Paulo Repa

1 . 1 . 2 0 10 1

Lightweight Directory Access Protocol

Paulo Repa

[email protected]

Page 2: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

2

LDAP Paulo Repa

What is a directory?

Page 3: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

3

LDAP Paulo Repa

Directory Information Tree

o=acme

ou=Sales ou=Marketing ou=Product Development

cn=Fred cn=Fred cn=Joe

cn=Lotty

cn=Fred,ou=Sales,o=acmeDN for Fred in Sales:

cn=eng_lw3

cn=lpr1

Page 4: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

4

LDAP Paulo Repa

Directory Solutions

Netscape Directory Server (iPlanet)

SCO UnixWare 7

IBM SecureWay (formerly eNetwork)

Novell NDS

OpenLdap (Linux) Recommended

Page 5: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

5

LDAP Paulo Repa

Directory server setup

Schema

ACLs

Data backup and restore

LDIF

UnixWare 7 Directory

Page 6: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

6

LDAP Paulo Repa

Directory Setup

scoadmin ldap

Page 7: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

7

LDAP Paulo Repa

Backend Setup

Page 8: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

8

LDAP Paulo Repa

Directory server setup

Schema

ACLs

Data backup and restore

LDIF

UnixWare 7 Directory

Page 9: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

9

LDAP Paulo Repa

Attribute Schema

Defined in slapd.at.conf

Specifies attribute syntax

attribute jpegphoto bin

attribute telephonenumber tel

attribute userpassword ces

Page 10: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

10

LDAP Paulo Repa

Objectclass Schema

objectclass simplePersonrequires

cn,sn,objectClass

allowsjpegPhoto,mail,telephoneNumber,userPassword,creatorsName,createtimestamp,modifiersname,modifytimestamp

Defines object contents

Defined in slapd.oc.conf

Page 11: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

11

LDAP Paulo Repa

Directory server setup

Schema

ACLs

Data backup and restore

LDIF

UnixWare 7 Directory

Page 12: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

12

LDAP Paulo Repa

ACLs

access to attr=userPassword by self write

by * none

ldapstop -i acme

ldapstart -i acme

Controls access for read, write, search, compare and delete operations

Entry or attribute level

Defined in slapd.acl.conf

Page 13: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

13

LDAP Paulo Repa

Directory server setup

Schema

ACLs

Data backup and restore

LDIF

UnixWare 7 Directory

Page 14: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

14

LDAP Paulo Repa

Data Backup and Restore

ldbmcat -n id2entry.dbb

ldif2ldbm -i data.ldif

Don’t forget directory configuration

Page 15: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

15

LDAP Paulo Repa

Directory server setup

Schema

ACLs

Data backup and restore

LDIF

UnixWare 7 Directory

Page 16: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

16

LDAP Paulo Repa

LDIF

LDAP Data Interchange Format

Portable

Human readable (almost...)

dn: o=acme

objectclass: organization

o: acme

Page 17: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

17

LDAP Paulo Repa

LDIF Update Statements

add

delete

modify (attribute add, delete, replace)

moddn

dn: cn=Joe, ou=Product Development, o=acme

changetype: modify

replace: telephoneNumber

telephoneNumber: 958-1234

Page 18: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

18

LDAP Paulo Repa

LDAP Commands

ldapsearch

ldapmodify

ldapadd

ldapdelete

ldapmodrdn

Page 19: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

19

LDAP Paulo Repa

ldapsearch

ldapsearch -h ldapsvr.acme.com -D “cn=admin” -w “secret” -b “o=acme” -s one “objectclass=*”

Page 20: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

20

LDAP Paulo Repa

ldapmodify

ldapmodify -h ldapsvr.acme.com -D “cn=admin” -w “secret” -f modifications.ldif

dn: cn=Joe, ou=Product Development, o=acme

replace: telephoneNumber

telephoneNumber: 958-1234

Page 21: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

21

LDAP Paulo Repa

ldapadd

ldapmodify -a -h ldapsvr.acme.com -D “cn=admin” -w “secret” -f additions.ldif

ldapadd -h ldapsvr.acme.com -D “cn=admin” -w “secret” -f additions.ldif

Page 22: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

22

LDAP Paulo Repa

ldapdelete

ldapdelete -h ldapsvr.acme.com -D “cn=admin” -w “secret” cn=Fred,ou=Sales,o=acme

Page 23: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

23

LDAP Paulo Repa

ldapmodrdn

ldapmodrdn -h ldapsvr.acme.com -D “cn=admin” -w “secret” -r cn=lpr,ou=Sales,o=acme cn=sales_lw1

Page 24: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

24

LDAP Paulo Repa

Using the UnixWare 7 LDAP API

Library / Binding to the server

Search

Compare

Add

Modify

Asynchronous LDAP calls

Page 25: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

25

LDAP Paulo Repa

LDAP C API

UnixWare 7 ldap package

LDAP C API - RFC1823

LDAP v2 - RFC1777

#include <ldap.h>

#include <lber.h>

cc -o app -lldap -llber -lresolv src.c

Page 26: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

26

LDAP Paulo Repa

Binding to the serverLDAP *ld;

ld = ldap_open(“ldapsvr.acme.com”,LDAP_PORT);

if (ldap_simple_bind_s(ld,“cn=admin”,“secret”) != LDAP_SUCCESS) {

ldap_perror(ld,“bind example”);

return;

}

if (ldap_unbind_s(ld) != LDAP_SUCCESS) {

ldap_perror(ld,“bind example”);

return;

}

…LDAP directory operations (search, modify, ...)

...

Page 27: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

27

LDAP Paulo Repa

Using the UnixWare 7 LDAP API

Library / Binding to the server

Search

Compare

Add

Modify

Asynchronous LDAP calls

Page 28: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

28

LDAP Paulo Repa

Search - API call

LDAPMessage *res, *entry;

BerElement *ber;

char *attr, *dn, **vals, **vp;

if (ldap_search_s(ld, “o=acme”, LDAP_SCOPE_SUBTREE, “telephoneNumber=958*”, 0, &res) != LDAP_SUCCESS) {

ldap_perror(ld, “search example”);

exit(EXIT_FAILURE);

}

Page 29: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

29

LDAP Paulo Repa

Search - Process Data

for (entry = ldap_first_entry(ld, res); entry != NULL;entry = ldap_next_entry(ld, entry)) {

if (dn = ldap_get_dn(ld, entry)) {printf(“dn: %s\n”, dn);free(dn);

} for (attr=ldap_first_attribute(ld, entry, &ber);

attr != NULL; attr=ldap_next_attribute(ld, entry, ber)) {vals = ldap_get_values(ld, entry, attr);for (vp = vals; vp && *vp; vp++) printf(“%s: %s\n”, attr, *vp);ldap_value_free(vals);

} if (ber)

ber_free(ber, 0);}ldap_msgfree(res);

Page 30: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

30

LDAP Paulo Repa

Using the UnixWare 7 LDAP API

Library / Binding to the server

Search

Compare

Add

Modify

Asynchronous LDAP calls

Page 31: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

31

LDAP Paulo Repa

Compare - API call

Matches for an attribute type of “tel” syntax

if ((res = ldap_compare_s(ld, “cn=Fred, ou=Sales, o=acme”, “telephoneNumber”, “9589876”)) == -1) {

ldap_perror(ld, “compare example”);

exit(EXIT_FAILURE);

}

if (res = LDAP_COMPARE_TRUE)

// Attribute type and value found

else

// Not found

dn: cn=Fred, ou=Sales, o=acme

objectclass: simplePerson

cn: Fred

sn: Jones

telephoneNumber: 958-9876

Page 32: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

32

LDAP Paulo Repa

Using the UnixWare 7 LDAP API

Library / Binding to the server

Search

Compare

Add

Modify

Asynchronous LDAP calls

Page 33: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

33

LDAP Paulo Repa

LDAPMod structure

One structure per attribute type

Add, delete and replace operations

Text or binary data

Multiple values

mod_op

mod_type

mod_values

LDAP_MOD_ADD

“mailAliasMembers”

“Joe”

“Lotty”

Page 34: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

34

LDAP Paulo Repa

char *cnvals[]={"John", NULL}, *snvals[]={"Smith", NULL};char *objvals[]={”simplePerson", NULL};LDAPMod mod[3], *mods[4];

mod[0].mod_op = LDAP_MOD_ADD;mod[0].mod_type = "cn";mod[0].mod_values = cnvals;mod[1].mod_op = LDAP_MOD_ADD;mod[1].mod_type = "sn";mod[1].mod_values = snvals;mod[2].mod_op = LDAP_MOD_ADD;mod[2].mod_type = "objectClass";mod[2].mod_values = objvals;

for (i=0; i < sizeof(mod) / sizeof(LDAPMod); i++)mods[i] = &mod[i];

mods[i] = NULL;

Add Entry - Data

Page 35: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

35

LDAP Paulo Repa

if (ldap_add_s(ld, “cn=John,ou=Marketing,o=acme”,&mods[0]) != LDAP_SUCCESS) {

ldap_perror(ld, “add example”);exit(EXIT_FAILURE);

}

Add Entry - API call

dn: cn=John, ou=Marketing, o=acme

objectclass: simplePerson

cn: John

sn: Smith

Page 36: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

36

LDAP Paulo Repa

Using the UnixWare 7 LDAP API

Library / Binding to the server

Search

Compare

Add

Modify

Asynchronous LDAP calls

Page 37: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

37

LDAP Paulo Repa

char *snvals[] = { “Smithe”, NULL};char *telvals[] = { “958-2357”, NULL};LDAPMod mod[2], *mods[3];

mod[0].mod_op = LDAP_MOD_REPLACE;mod[0].mod_type = "sn";mod[0].mod_values = snvals;

mod[1].mod_op = LDAP_MOD_ADD;mod[1].mod_type = ”telephoneNumber";mod[1].mod_values = telvals;

for (i=0; i < sizeof(mod) / sizeof(LDAPMod); i++)mods[i] = &mod[i];

mods[i] = NULL;

Modify Entry - Data

Page 38: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

38

LDAP Paulo Repa

if (ldap_modify_s(ld,“cn=John,ou=Marketing,o=acme”,&mods[0]) != LDAP_SUCCESS) {

ldap_perror(ld, “modify example”);exit(EXIT_FAILURE);

}

Modify Entry - API call

dn: cn=John, ou=Marketing, o=acme

objectclass: simplePerson

cn: John

sn: Smithe

telephoneNumber: 958-2357

Page 39: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

39

LDAP Paulo Repa

Using the UnixWare 7 LDAP API

Library / Binding to the server

Search

Compare

Add

Modify

Asynchronous LDAP calls

Page 40: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

40

LDAP Paulo Repa

Asynchronous LDAP calls Client need not block Operations may be multiplexed on a connection Function names omit “_s”

int msgid, rc;

if ((msgid = ldap_search(ld, “o=acme”, LDAP_SCOPE_SUBTREE, “objectclass=*”, NULL, 0)) == -1)

error_handler();

while ((rc = ldap_result(ld, msgid, 0, NULL, &result)) ==

LDAP_RES_SEARCH_ENTRY) {

process_results(result);

ldap_msgfree(result);

}

Page 41: Paulo Repa 1. 1. 2 0 10 1 Lightweight Directory Access Protocol Paulo Repa repapaul@gmail.com

41

LDAP Paulo Repa

Bibliography

LDAP: Programming Directory-Enabled Applications with Lightweight Directory Access Protocol

– Howes, Smith RFC1777 - Lightweight Directory Access Protocol RFC1823 - The LDAP Application Program Interface