Este documento fornece instruções para configurar um diretório LDAP avançado utilizando o OpenLDAP, incluindo instalação, configuração, importação de entradas, alteração de senhas em tempo real, consultas na base de dados e replicação.
1. CIRCUITO AVANÇADO DE OPENLDAP
MarcioGarciaMarcenari
marciogarcia@gmail.com
mgarcia@thesource.com.br
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
1 de 25
3. OpenLDAP
• Pré-requisitos:
OpenSSL – Última versão estável: openssl-0.9.7l.tar.gz
http://www.openssl.org
BerkeleyDB – Última versão estável: db-4.5.20.tar.gz
http://www.sleepycat.com
Cyrus-SASL – Última versão estável: cyrus-sasl-2.1.22.tar.gz
http://asg.web.cmu.edu/cyrus/
• Pacotes:
OpenLDAP – Última versão estável: openldap-stable-20070110.tar.gz
http://www.openldap.org
NSS_LDAP
http://www.padl.com/OSS/nss_ldap.html
Instalação
• OpenSSL
root@mgarcia:~# wget -c http://www.openssl.org/source/openssl-0.9.7l.tar.gz
root@mgarcia:~# tar xzvf openssl-0.9.7l.tar.gz
root@mgarcia:~# cd openssl-0.9.7l
root@mgarcia:~# ./config shared --openssldir=/usr/local
root@mgarcia:~# make
root@mgarcia:~# make install
• BerkeleyDB
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
3 de 25
4. root@mgarcia:~# wget -c http://downloads.sleepycat.com/db-4.5.20.tar.gz
root@mgarcia:~# tar xzvf db-4.5.20.tar.gz
root@mgarcia:~# cd db-4.5.20/build_unix
root@mgarcia:~# ../dist/configure --prefix=/usr/local
root@mgarcia:~# make
root@mgarcia:~# make install
root@mgarcia:~# ldconfig
Obs.: No Slackware o diretório “/usr/local/lib” já existe no arquivo “/etc/ld.so.conf”.
• Cyrus-SASL
root@mgarcia:~# wget -c ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-sasl-
2.1.22.tar.gz
root@mgarcia:~# tar xzvf cyrus-sasl-2.1.22.tar.gz
root@mgarcia:~# cd cyrus-sasl-2.1.22
root@mgarcia:~# ./configure
root@mgarcia:~# make
root@mgarcia:~# make install
root@mgarcia:~# cd /usr/lib
root@mgarcia:~# mv sasl2 sasl2.original
root@mgarcia:~# ln -s /usr/local/lib/sasl2
• OpenLDAP
root@mgarcia:~# wget -c ftp://ftp.openldap.org/pub/OpenLDAP/openldap-
stable/openldap-stable-20070110.tgz
root@mgarcia:~# tar xzvf openldap-stable-20070110.tgz
root@mgarcia:~# cd openldap-2.3.32
root@mgarcia:~# ./configure --with-tls --enable-syncprov --enable-crypt
--enable-syslog --enable-wrappers --enable-unique --disable-ipv6
root@mgarcia:~# make depend
root@mgarcia:~# make
root@mgarcia:~# make install
Configuração
• OpenLDAP
root@mgarcia:~# cd /usr/local/etc/openldap
root@mgarcia:~# vi slapd.conf
# Opcoes Globais
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
4 de 25
5. include /usr/local/etc/openldap/schema/core.schema
include /usr/local/etc/openldap/schema/cosine.schema
include /usr/local/etc/openldap/schema/nis.schema
include /usr/local/etc/openldap/schema/inetorgperson.schema
pidfile /usr/local/var/run/slapd.pid
argsfile /usr/local/var/run/slapd.args
allow bind_v2
loglevel 256
# TLS / SSL
# Opcoes do banco de dados
database bdb
suffix "c=BR"
rootdn "cn=Master,c=BR"
rootpw {SSHA}+7vJt6RStpyegSCslgAaym6P8AhacpF3
directory /usr/local/var/openldap-data
# ACL's
# Indices de pesquisa
index objectClass eq
• loglevel – Níveis de log
1 (0x1 trace) trace function calls
2 (0x2 packet) debug packet handling
4 (0x4 args) heavy trace debugging (function args)
8 (0x8 conns) connection management
6 (0x10 BER) print out packets sent and received
32 (0x20 filter) search filter processing
64 (0x40 config) configuration file processing
128 (0x80 ACL) access control list processing
256 (0x100 stats) stats log connections/operations/results
512 (0x200 stats2) stats log entries sent
1024 (0x400 shell) print communication with shell backends
2048 (0x800 parse) entry parsing
4096 (0x1000 cache) caching (unused)
8192 (0x2000 index) data indexing (unused)
16384 (0x4000 sync) LDAPSync replication
32768 (0x8000 none) only messages that get logged whatever log level is set
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
5 de 25
6. Inicialização
• Iniciando o OpenLDAP no modo normal
root@mgarcia:~# /usr/local/libexec/slapd
root@mgarcia:~# ps wax | grep slapd
5140 ? Ssl 0:00 /usr/local/libexec/slapd
root@mgarcia:~# netstat -at | grep LISTEN
tcp 0 0 *:ldap *:* LISTEN
root@mgarcia:~# netstat -nat | grep LISTEN
tcp 0 0 0.0.0.0:389 0.0.0.0:* LISTEN
• Iniciando o OpenLDAP no modo debug
root@mgarcia:~# /usr/local/libexec/slapd -d2
• Parando o OpenLDAP
root@mgarcia:~# killall -INT slapd
Criação das entradas para importação na base LDAP
• Country BR: “c=BR”
root@mgarcia:~# vi br.ldif
dn: c=BR
objectClass: country
c: BR
• Organização TheSource: “o=TheSource”
root@mgarcia:~# vi thesource.ldif
dn: o=TheSource, c=BR
objectClass: organization
o: TheSource
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
6 de 25
7. • Departamento TI: “ou=TI”
root@mgarcia:~# vi ti.ldif
dn: ou=TI, o=TheSource, c=BR
objectClass: organizationalUnit
ou: TI
• Departamento RH: “ou=RH”
root@mgarcia:~# vi rh.ldif
dn: ou=RH, o=TheSource, c=BR
objectClass: organizationalUnit
ou: RH
• Usuário mgarcia: “uid=mgarcia”
root@mgarcia:~# vi mgarcia.ldif
dn: uid=mgarcia, ou=TI, o=TheSource, c=BR
objectClass: inetOrgPerson
uid: mgarcia
cn: Marcio Garcia
mail: mgarcia@thesource.com.br
sn: Garcia
userPassword: {SSHA}sOEFhMFdlam1lMm5rdmp3WVBMTVVSY0hzTWs=
• Usuário ralf: “uid=ralf”
root@mgarcia:~# vi ralf.ldif
dn: uid=ralf, ou=TI, o=TheSource, c=BR
objectClass: inetOrgPerson
uid: ralf
cn: Ralf Braga
mail: ralf@thesource.com.br
sn: Braga
userPassword: {SSHA}sOEFhMFdlam1lMm5rdmp3WVBMTVVSY0hzTWs=
• Usuário recursoshumanos: “uid=recursoshumanos”
root@mgarcia:~# vi recursoshumanos.ldif
dn: uid=recursoshumanos, ou=RH, o=TheSource, c=BR
objectClass: inetOrgPerson
uid: recursoshumanos
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
7 de 25
8. cn: Recursos Humanos The Source
mail: rh@thesource.com.br
sn: Recursos Humanos
userPassword: {SSHA}sOEFhMFdlam1lMm5rdmp3WVBMTVVSY0hzTWs=
Importação das entradas na base LDAP
• Entrada: br.ldif
root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f br.ldif
ldap_initialize( <DEFAULT> )
Enter LDAP Password: ******
add objectClass:
country
add c:
BR
adding new entry "c=BR"
modify complete
• Entrada: thesource.ldif
root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f thesource.ldif
ldap_initialize( <DEFAULT> )
Enter LDAP Password: ******
add objectClass:
organization
add o:
TheSource
adding new entry "o=TheSource, c=BR"
modify complete
• Entrada: ti.ldif
root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f ti.ldif
ldap_initialize( <DEFAULT> )
Enter LDAP Password: ******
add objectClass:
organizationalUnit
add ou:
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
8 de 25
9. TI
adding new entry "ou=TI, o=TheSource, c=BR"
modify complete
• Entrada: rh.ldif
root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f rh.ldif
ldap_initialize( <DEFAULT> )
Enter LDAP Password: ******
add objectClass:
organizationalUnit
add ou:
RH
adding new entry "ou=RH, o=TheSource, c=BR"
modify complete
• Entrada: mgarcia.ldif
root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f mgarcia.ldif
ldap_initialize( <DEFAULT> )
Enter LDAP Password: ******
add objectClass:
inetOrgPerson
add uid:
mgarcia
add cn:
Marcio Garcia
add mail:
mgarcia@thesource.com.br
add sn:
Garcia
add userPassword:
{SSHA}sOEFhMFdlam1lMm5rdmp3WVBMTVVSY0hzTWs=
adding new entry "uid=mgarcia, ou=TI, o=TheSource, c=BR"
modify complete
• Entrada: ralf.ldif
root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f ralf.ldif
ldap_initialize( <DEFAULT> )
Enter LDAP Password: ******
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
9 de 25
10. add objectClass:
inetOrgPerson
add uid:
ralf
add cn:
Ralf Braga
add mail:
ralf@thesource.com.br
add sn:
Braga
add userPassword:
{SSHA}sOEFhMFdlam1lMm5rdmp3WVBMTVVSY0hzTWs=
adding new entry "uid=ralf, ou=TI, o=TheSource, c=BR"
modify complete
• Entrada: recursoshumanos.ldif
root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f recursoshumanos.ldif
ldap_initialize( <DEFAULT> )
Enter LDAP Password: ******
add objectClass:
inetOrgPerson
add uid:
recursoshumanos
add cn:
Recursos Humanos The Source
add mail:
rh@thesource.com.br
add sn:
Recursos Humanos
add userPassword:
{SSHA}sOEFhMFdlam1lMm5rdmp3WVBMTVVSY0hzTWs=
adding new entry "uid=recursoshumanos, ou=RH, o=TheSource, c=BR"
modify complete
• Opções do “ldapadd”
-x Utiliza autenticação simples ao invés de SASL
-W Autenticação através de prompt
-w Autenticação através de linha de comando
-v Verbose, utilizado para printar o status do ldapadd
-D Especifica o usuário que ira fazer um bind na base
-f Especifica o arquivo que será importado
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
10 de 25
11. Alteração de senhas de usuários em tempo real
• Algoritmos disponíveis
root@mgarcia:~# ldappasswd -x -W -v -D 'uid=mgarcia,ou=TI,o=TheSource,c=BR'
-A -S
Old password:
Re-enter old password:
New password:
Re-enter new password:
Enter LDAP Password:
ldap_initialize( <DEFAULT> )
Result: Success (0)
root@mgarcia:~#
Obs.: O usuário só poderá alterar sua senha se existir uma ACL permitindo.
• Opções do “ldappasswd”
-x Utiliza autenticação simples ao invés de SASL
-W Autenticação através de prompt
-w Autenticação através de linha de comando
-v Verbose, utilizado para printar o status do ldapadd
-D Especifica o usuário que ira fazer um bind na base
-A Prompt para a senha antiga
-S Prompt para a senha nova
Consultas na base LDAP – RFC 2254
• Consultando a base LDAP
root@mgarcia:~# ldapsearch -x -b c=BR
• Consultando a base LDAP, sem comentários e descrições
root@mgarcia:~# ldapsearch -x -b c=BR -LLL
• Consultando a base LDAP, filtrando pelo usuário “mgarcia”
root@mgarcia:~# ldapsearch -x -b c=BR '(uid=mgarcia)'
root@mgarcia:~# ldapsearch -x -b c=BR -u uid=mgarcia
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
11 de 25
12. • Consultando a base LDAP, filtrando pelo nome “Ralf Braga”
root@mgarcia:~# ldapsearch -x -b c=BR '(cn=Ralf Braga)'
root@mgarcia:~# ldapsearch -x -b c=BR -u 'cn=Ralf Braga'
• Consultando a base LDAP, filtrando pelo nome “Marcio Garcia” e/ou “Ralf
Braga”
root@mgarcia:~# ldapsearch -x -b c=BR -LLL '(&(|(cn=Marcio Garcia)(cn=Ralf
Braga)) (objectClass=inetOrgPerson))'
root@mgarcia:~# ldapsearch -x -b c=BR -LLL '(&(|(cn=Marcio Garcia)(cn=Ralf
Braga)))'
• Consultando a base LDAP, com exceção do nome “Marcio Garcia”
root@mgarcia:~# ldapsearch -x -b c=BR -LLL '(!(cn=Marcio Garcia))
(objectClass=inetOrgPerson)'
root@mgarcia:~# ldapsearch -x -b c=BR -LLL '(!(cn=Marcio Garcia))'
• Consultando a base LDAP, com exceção do nome “Marcio Garcia”, filtrando
o resultado pelo atributo “mail”
root@mgarcia:~# ldapsearch -x -b c=BR -LLL '(!(cn=Marcio Garcia))' mail
• Operadores boleanos que podem ser utilizados na pesquisa
& and
| or
! not
• Filtros de pesquisa
= igual
=~ direfente
>= maior ou igual
<= menor ou igual
• Exibe os atributos com todos os detalhes, inclusive os invisíveis
root@mgarcia:~# ldapsearch -x -b c=BR +
• Exibe todos os objectClass por “OID”
root@mgarcia:~# ldapsearch -x -b "" -s base "(objectClass=*)" +
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
12 de 25
13. • Consulta todos os esquemas disponíveis no servidor LDAP
root@mgarcia:~# ldapsearch -x -W -D cn=Master,c=BR -s base -b "cn=SubSchema"
"(objectClass=*)" +
Obs.: É a mesma coisa que dar um cat nos esquemas do diretório:
/usr/local/etc/openldap/schema
O comando acima exibe alguns parâmetros adicionais.
ACL's Avançadas
• Master e mgarcia lêem toda a base somente com autenticação
• Demais usuários não lêem a base
access to *
by dn="cn=Master,c=BR" read
by dn="uid=mgarcia,ou=TI,o=TheSource,c=BR" read
by * auth
• Master e mgarcia lêem toda a base somente com autenticação
• Os usuários lêem somente o seu conf
• Demais usuários não lê a base
access to *
by dn="cn=Master,c=BR" read
by dn="uid=mgarcia,ou=TI,o=TheSource,c=BR" read
by self read
by * auth
• Master e usuários lêem toda a base somente com autenticação
access to *
by dn="cn=Master,c=BR" read
by dn.regex="(.*,)?c=BR" read
by * auth
• Master e usuários que começam com a letra “m” lêem toda a base somente
com autenticação
access to *
by dn="cn=Master,c=BR" read
by dn.regex="^uid=m.+,?c=BR" read
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
13 de 25
14. by * auth
• Master faz tudo
• Usuários que começam com a letra “m” podem ler a base, somente com
permissão de leitura e pesquisa
• Demais usuários lêem somente o seu conf
access to *
by dn="cn=Master,c=BR" +r
by dn.regex="^uid=m.+?c=BR" +rsx
by self +rsx
by * +x
• Master faz tudo
• Usuários que começam com a letra “m” podem ler a base, somente com
permissão de escrita, leitura e pesquisa e também podem ler o atributo
userPassword
• Demais usuários lêem somente o seu conf
access to attrs=userPassword
by dn="cn=Master,c=BR" +wrs
by dn.regex="^uid=m.+?c=BR" +wrsx
by self +wx
by * +x
access to *
by dn="cn=Master,c=BR" +r
by dn.regex="^uid=m.+?c=BR" +rsx
by self +rsx
by * +x
Schemas – RFC 2242
• Opções
1.3.6.1 Reservado ao IANA – OID's de Internet
{iso(1) org(3) dod(6) iana(1)}
4.1.x Private Enterprise arc.
{private(4) enterprise(1) SEU_OID(x)}
1.3.6.1.4.1.x SEU_OID
• Syntaxes mais utilizadas / comuns
NOME OID Description
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
14 de 25
15. boolean 1.3.6.1.4.1.1466.115.121.1.7 boolean value
directoryString 1.3.6.1.4.1.1466.115.121.1.15 Unicode (UTF-8)
String
distinguishedName 1.3.6.1.4.1.1466.115.121.1.12 LDAP DN
integer 1.3.6.1.4.1.1466.115.121.1.27 Integer
numericString 1.3.6.1.4.1.1466.115.121.1.36 Numeric String
OID 1.3.6.1.4.1.1466.115.121.1.38 Object Identifier
octetString 1.3.6.1.4.1.1466.115.121.1.40 Arbitary octets
jpeg 1.3.6.1.4.1.1466.115.121.1.28 Photo JPEG
• Matching Rules mais utilizadas / comuns
NOME TIPO DESCRIÇÃO
booleanMatch equality boolen
caseIgnoreMatch equality case insensitive, space insensitive
caseIgnoreOrderingMatch ordering case insensitive, space insensitive
caseIgnoreSubstringsMatch substrings case insensitive, space insensitive
caseExactMatch equality case sensitive, space insensitive
caseExactOrderingMatch ordering case sensitive, space insensitive
caseExactSubstringsMatch substrings case sensitive, space insensitive
integerMatch equality integer
integerOrderingMatch ordering integer
numericStringMatc equality numerical
numericStringOrderingMatch ordering numerical
numericStringSubstringsMatch substrings numerical
octetStringMatch equality octet string
octetStringOrderingStringMatch ordering octet string
octetStringSubstringsStringMatch ordering octet string
objectIdentiferMatch equality object identifier
• Objetos / atributos
1.3.6.1.4.1.1466.1.x Define atributos (attributetypes)
1.3.6.1.4.1.1466.2.x Define Objetos (ObjectClass)
• Tipos de objectClass
AUXILIARY São schemas como: qmail, samba, bind, etc...
São objetos que não dependem de outros objetos
Não herdam atributos de outros objectClass
STRUCTURAL São objetos que dependem de outros objetos
• Criando nosso próprio schema
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
15 de 25
16. root@mgarcia:~# vi local.schema
attributetype (1.3.6.1.4.1.28002.1.1 NAME 'ramal'
DESC 'Lista de Ramais'
EQUALITY integerMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27{6}
)
attributetype (1.3.6.1.4.1.28002.1.2 NAME 'CPF'
DESC 'CPF'
EQUALITY caseIgnoreMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{14}
)
attributetype (1.3.6.1.4.1.28002.1.3 NAME 'RG'
DESC 'Registro Geral'
EQUALITY caseIgnoreMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{14}
)
objectClass (1.3.6.1.4.1.28002.2.1 NAME 'brasileiro'
DESC 'brasileiro'
SUP inetOrgPerson STRUCTURAL
MUST (UID $ CPF $ RG)
MAY (ramal)
)
root@mgarcia:~#
Serviço de diretório distribuído
• Criando estrutura de diretórios
root@mgarcia:~# vi referencia.ldif
dn: ou=RJ,o=TheSource,c=BR
objectClass: referral
objectClass: extensibleObject
ou: RJ
ref: ldap://192.x.x.x/ou=RJ,o=TheSource,c=BR
dn: ou=PR,o=TheSource,c=BR
objectClass: referral
objectClass: extensibleObject
ou: PR
ref: ldap://192.x.x.x/ou=PR,o=TheSource,c=BR
root@mgarcia:~#
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
16 de 25
17. • Importando na base os diretórios distribuídos
root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f referencia.ldif
• Consultando a estrutura de diretórios
root@mgarcia:~# ldapsearch -x -b c=BR -C
Habilitando a opção “unique”
• Configuração do servidor
root@mgarcia:~# vi /usr/local/etc/openldap/slapd.conf
## Opcoes globais
# Includes / Schemas
include /usr/local/etc/openldap/schema/core.schema
include /usr/local/etc/openldap/schema/cosine.schema
include /usr/local/etc/openldap/schema/inetorgperson.schema
include /usr/local/etc/openldap/schema/java.schema
include /usr/local/etc/openldap/schema/nis.schema
# PID / ARGS File
pidfile /usr/local/var/run/slapd.pid
argsfile /usr/local/var/run/slapd.args
# Misc options
loglevel 256
allow bind_v2
sizelimit unlimited
threads 8
## BDB Definitions
database bdb
suffix "c=BR"
rootdn "cn=Master,c=BR"
rootpw {MD5}4QrcOUm6Wau+VuBX8g+IPg==
directory /usr/local/var/openldap-data
# Opção “unique”
overlay unique
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
17 de 25
18. unique_ignore o cn sn ou objectClass
unique_attributes uid mail displayName
# ACL's
access to dn.subtree="c=BR"
by dn="cn=Master,c=BR" write
by dn="cn=Replica,c=BR" write
by * read
# Indices
index default eq,pres
index objectClass eq
index cn,sn,givenname,mail eq,pres,sub
index uid,uidNumber,gidNumber eq
index entryUUID,entryCSN eq
Replicação com LDAP SYNC REPLICATION
• Configuração do servidor Master
root@mgarcia:~# vi /usr/local/etc/openldap/slapd.conf
## Opcoes globais
# Includes / Schemas
include /usr/local/etc/openldap/schema/core.schema
include /usr/local/etc/openldap/schema/cosine.schema
include /usr/local/etc/openldap/schema/inetorgperson.schema
include /usr/local/etc/openldap/schema/java.schema
include /usr/local/etc/openldap/schema/nis.schema
# PID / ARGS File
pidfile /usr/local/var/run/slapd.pid
argsfile /usr/local/var/run/slapd.args
# Misc options
loglevel 256
allow bind_v2
sizelimit unlimited
threads 8
## BDB Definitions
database bdb
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
18 de 25
19. suffix "c=BR"
rootdn "cn=Master,c=BR"
rootpw {MD5}4QrcOUm6Wau+VuBX8g+IPg==
directory /usr/local/var/openldap-data
# Opção “unique”
overlay unique
unique_ignore o cn sn ou objectClass
unique_attributes uid mail displayName
# LDAP Sync Replication
overlay syncprov
# ACL's
access to dn.subtree="c=BR"
by dn="cn=Master,c=BR" write
by dn="cn=Replica,c=BR" write
by * read
# Indices
index default eq,pres
index objectClass eq
index cn,sn,givenname,mail eq,pres,sub
index uid,uidNumber,gidNumber eq
index entryUUID,entryCSN eq
• Configuração do servidor Slave
root@mgarcia:~# vi /usr/local/etc/openldap/slapd.conf
## Opcoes globais
# Includes / Schemas
include /usr/local/etc/openldap/schema/core.schema
include /usr/local/etc/openldap/schema/cosine.schema
include /usr/local/etc/openldap/schema/inetorgperson.schema
include /usr/local/etc/openldap/schema/java.schema
include /usr/local/etc/openldap/schema/nis.schema
# PID / ARGS File
pidfile /usr/local/var/run/slapd.pid
argsfile /usr/local/var/run/slapd.args
# Misc options
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
19 de 25
20. loglevel 256
allow bind_v2
sizelimit 20
threads 8
## BDB Definitions
database bdb
suffix "c=BR"
rootdn "cn=Replica,c=BR"
rootpw {MD5}4QrcOUm6Wau+VuBX8g+IPg==
directory /usr/local/var/openldap-data
# Opção “unique”
overlay unique
unique_ignore o cn sn ou objectClass
unique_attributes uid mail displayName
# ACL's
access to dn.subtree="c=BR"
by dn="cn=Master,c=BR" write
by dn="cn=Replica,c=BR" write
by * read
# LDAP Sync Replication
syncrepl rid=1
provider=ldap://192.x.x.x:389
binddn="cn=Master,c=BR"
bindmethod=simple
credentials=123456
searchbase="c=BR"
filter="(objectClass=*)"
attrs="*"
schemachecking=off
scope=sub
type=refreshOnly
interval=00:00:00:10
# Indices
index default eq,pres
index objectClass eq
index cn,sn,givenname,mail eq,pres,sub
index uid,uidNumber,gidNumber eq
index entryUUID,entryCSN eq
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
20 de 25
21. Disaster Recover
• Recuperando a base LDAP
root@mgarcia:~# killall -9 slapd
root@mgarcia:~# db_recover -h /usr/local/var/openldap-data
root@mgarcia:~# /usr/local/libexec/slapd -d2
Alguns recursos do OpenLDAP / BerkeleyDB
• Último checkpoint
root@mgarcia:~# db_stat -t -h /usr/local/var/openldap-data
1/403179 File/offset for last checkpoint LSN
Sun Jan 21 06:41:49 2007 Checkpoint timestamp
0x800000df Last transaction ID allocated
48 Maximum number of active transactions configured
0 Active transactions
3 Maximum active transactions
223 Number of transactions begun
2 Number of transactions aborted
221 Number of transactions committed
0 Snapshot transactions
0 Maximum snapshot transactions
0 Number of transactions restored
24KB Transaction region size
0 The number of region locks that required waiting (0%)
Active transactions:
root@mgarcia:~#
• Efetuar um checkpoint
root@mgarcia:~# /usr/local/var/openldap-data# db_checkpoint -1
• Listar logs do BerkeleyDB, tudo o que foi feito e por quem
root@mgarcia:~# db_printlog -h /usr/local/var/openldap-data
[1][423569]__bam_repl: rec: 58 txnp 800000da prevlsn [1][423501]
fileid: 8
pgno: 1
lsn: [1][400966]
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
21 de 25
24. root@mgarcia:~# groupadd ldap
root@mgarcia:~# useradd ldap -g ldap -s /bin/false
root@mgarcia:~# cd /usr/local/etc/
root@mgarcia:~# chown -R ldap: openldap/
root@mgarcia:~# chmod 750 openldap
root@mgarcia:~# cd /usr/local/var/
root@mgarcia:~# chown -R ldap: openldap-data/ openldap-slurp/
root@mgarcia:~# chmod 750 openldap-data/ openldap-slurp
root@mgarcia:~# cd /usr/local/var/run/
root@mgarcia:~# mkdir ldap
root@mgarcia:~# chown -R ldap: ldap
root@mgarcia:~# chmod 750 ldap
root@mgarcia:~# vi /usr/local/etc/openldap/slapd.conf
## Opcoes globais
# Includes / Schemas
include /usr/local/etc/openldap/schema/core.schema
include /usr/local/etc/openldap/schema/cosine.schema
include /usr/local/etc/openldap/schema/inetorgperson.schema
include /usr/local/etc/openldap/schema/java.schema
include /usr/local/etc/openldap/schema/nis.schema
# PID / ARGS File
pidfile /usr/local/var/run/ldap/slapd.pid
argsfile /usr/local/var/run/ldap/slapd.args
# Misc options
loglevel 256
allow bind_v2
sizelimit unlimited
threads 8
## BDB Definitions
database bdb
suffix "c=BR"
rootdn "cn=Master,c=BR"
rootpw {MD5}4QrcOUm6Wau+VuBX8g+IPg==
directory /usr/local/var/openldap-data
# Opção “unique”
overlay unique
unique_ignore o cn sn ou objectClass
unique_attributes uid mail displayName
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
24 de 25
25. # LDAP Sync Replication
overlay syncprov
# ACL's
access to dn.subtree="c=BR"
by dn="cn=Master,c=BR" write
by dn="cn=Replica,c=BR" write
by * read
# Indices
index default eq,pres
index objectClass eq
index cn,sn,givenname,mail eq,pres,sub
index uid,uidNumber,gidNumber eq
index entryUUID,entryCSN eq
root@mgarcia:~# /usr/local/libexec/slapd -u ldap -g ldap
Obrigado!
MarcioGarciaMarcenari
marciogarcia@gmail.com
mgarcia@thesource.com.br
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
25 de 25