SAMBA+LDAP bajo Centos-5

Moderador: frank

Responder
Avatar de Usuario
DiosdelSueno1
Mensajes: 11
Registrado: Jue, 15 Ago 2013, 09:08
Ubicación: Regla

SAMBA+LDAP bajo Centos-5

Mensaje por DiosdelSueno1 » Vie, 16 Ago 2013, 08:39

Bueno e aquí como logre configurar el samba+ldap en le centos 5.8

Lo primero que haremos es configurar el openldap para la autentificación ahí agregaremos todo lo necesario para vincularlo con el samba téngase en cuenta que no entrare en detalles de cada parámetro de lo que es ldap de sus bases de datos y tampoco explicar cada apartado solamente me enfocare en lo necesario para que pueda trabajar el samba+ldap, cualquier duda si lo desean escríbanme...

Equipamiento lógico requerido.
• openldap-2.3.27
• openldap-clients-2.3.27
• openldap-servers-2.3.
• authconfig-5.3.12
• samba-common
• samba-client
• samba-3.0.
• smbldap-tools-0.9.1-1
yum -y install openldap openldap-clients openldap-servers authconfig authconfig-gtk samba samba-client samba-common
en caso claro esta que no lo tengan instalado previamente en el servidor.
Luego hacemos nuevamente el mismo procedimiento para instalar el smbldap-tools
yum –y install smbldap-tools-0.9.1-1 (en este caso eso este puede que ustedes tengan una versión mas actualizada.)
1. OPENLDAP Y AUTENTICACIÓN
Vamos a copiar el archivo de esquema de samba al directorio de esquemas de openLDAP:
cp /usr/share/doc/samba-*/LDAP/samba.schema /etc/openldap/schema/

Luego de esto editaremos el archivo /etc/openldap/slapd.conf y agregar una línea más para que openLDAP soporte el esquema de samba. El archivo quedar¬a como lo siguiente:
# # See slapd.conf(5) for details on configuration options.
# This file should NOT be world readable.
#
include /etc/openldap/schema/core.schema
include /etc/openldap/schema/cosine.schema
include /etc/openldap/schema/inetorgperson.schema
include /etc/openldap/schema/nis.schema
include /etc/openldap/schema/samba.schema (tener en cuenta este orden pues es necesario)



Añadimos al final del archivo /etc/openldap/slapd.conf :
database bdb
suffix "dc=prueba " (Como también puede ser solamente "dc=prueba,dc=edu,dc=cu ")
rootdn "cn=root,dc=prueba " (Como también puede ser solamente "dc=prueba,dc=edu,dc=cu ")

# Este password obtenido previamente al digitar slappasswd
rootpw XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX (previamente trae secret que es utilizable, )
# The database directory MUST exist prior to running slapd AND
# should only be accessible by the slapd and slap tools.
# Mode 700 recommended.

directory /var/lib/ldap

# Indices to maintain for this database
#index objectClass eq,pres
#index ou,cn,mail,surname,givenname eq,pres,sub
#index uidNumber,gidNumber,loginShell eq,pres
#index uid,memberUid eq,pres,sub
#index nisMapName,nisMapEntry eq,pres,sub
index objectClass eq
index cn pres,sub,eq
index sn pres,sub,eq
index uid pres,sub,eq
index displayName pres,sub,eq
index uidNumber eq
index gidNumber eq
index memberUID eq
index sambaSID eq
index sambaPrimaryGroupSID eq
index sambaDomainName eq
index default sub

# Replicas of this database
#replogfile /var/lib/ldap/openldap-master-replog
#replica host=ldap-1.example.com:389 starttls=critical
# bindmethod=sasl saslmech=GSSAPI
# authcId=host/ldap-master.example.com@EXAMPLE.COM


Aquí termina la configuración del fichero slapd.conf

Tenemos que configurar los parámetros globales como cliente(NSS), el mismo servidor localhost en /etc/ldap.conf :
host 127.0.0.1
base dc=prueba
También tenemos que configurar el cliente LDAP en /etc/openldap/ldap.conf :

HOST 127.0.0.1
BASE dc=prueba
Iniciamos el servicio LDAP y configuramos que arranque por defecto:

service ldap start (iniciamos el servicio ldap)
chkconfig ldap on (lo agregamos para que arranque por defecto)

Configuramos la autenticación de Linux con authconfig-tui
Y donde dice información del usuario marcamos Utilizar LDAP, en Autentificacion marcamos utilizar MD5, Utilizar contraseñas ocultas (SHADOW) y Utilizar Autentificacoin LDAP
En la pestaña configuración ldap por lo menos tengo desmarcado utilizar TSL de momento no lo estoy utilizando pero bien en servidor: 127.0.0.1ldap:127.0.0.1 Puede que esto les salga automático sin necesidad que ustedes agregen nada aquí pero les pongo lo que debería salir, en DN base: dc=prueba y aceptan la configuración.

2. SAMBA e INTEGRACION LDAP

Ahora configuremos Samba en /etc/samba/smb.conf

# Samba PDC openLDAP para CentOS 5
# x Richard Soriano Sánchez

# Global parameters
[global]
workgroup = prueba
; netbios name = poseidon
security = user
; enable privileges = yes
#interfaces = 192.168.5.11
#username map = /etc/samba/smbusers
server string = No me gusta dar mucha información de mi serv
#security = ads
; encrypt passwords = yes
#min passwd length = 3
#pam password change = no
#obey pam restrictions = No

# method 2:
unix password sync = yes
; ldap passwd sync = no
passwd program = /usr/sbin/smbldap-passwd -u "%u"
passwd chat = "Changing *\nNew password*" %n\n "*Retype new password*" %n\n"

; log level = 0
syslog = 0
log file = /var/log/samba/log.%U
max log size = 100000
time server = Yes
socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192
; mangling method = hash2


logon script = logon.bat
logon drive = Z:
logon home = \\POSEIDON\%U
logon path =

domain logons = Yes
domain master = Yes
os level = 65
preferred master = Yes
wins support = yes
passdb backend = ldapsam:ldap://127.0.0.1/
ldap admin dn = cn=root,dc=prueba
ldap suffix = dc=prueba
ldap group suffix = ou=Group
ldap user suffix = ou=People
ldap machine suffix = ou=Computers
ldap idmap suffix = ou=Idmap
add user script = /usr/sbin/smbldap-useradd -m "%u"
ldap delete dn = Yes
delete user script = /usr/sbin/smbldap-userdel "%u"
add machine script = /usr/sbin/smbldap-useradd -t 0 -w "%u"
add group script = /usr/sbin/smbldap-groupadd -p "%g"
delete group script = /usr/sbin/smbldap-groupdel "%g"
add user to group script = /usr/sbin/smbldap-groupmod -m "%u" "%g"
delete user from group script = /usr/sbin/smbldap-groupmod -x "%u" "%g"
set primary group script = /usr/sbin/smbldap-usermod -g '%g' '%u'

# printers configuration
#printer admin = @"Print Operators"
; load printers = yes
create mask = 0640
directory mask = 0750
#force create mode = 0640
#force directory mode = 0750
nt acl support = No
; printing = cups
printcap name = cups
deadtime = 10
; guest account = nobody
map to guest = Bad User
dont descend = /proc,/dev,/etc,/lib,/lost+found,/initrd
; show add printer wizard = yes
; to maintain capital letters in shortcuts in any of the profile folders:
; preserve case = yes
; short preserve case = yes
case sensitive = no
username map = /etc/samba/smbusers


[homes]
#valid users = %U
read only = No
create mask = 0664
directory mask = 0775
browseable = No
veto files = /*.mp3/*.mp4/*.avi/*.mpg/*.dat/*.vob/*.exe/*.mkv/ (*Nota* en este caso que miran aquí es que a mi no me interesan que los usuarios me llenen el servidor de diferentes tipos de fichero que no sean de trabajo razón de este veto.)

[netlogon]
path = /home/netlogon/
browseable = No
; read only = yes

[profiles]
path = /home/profiles
read only = no
create mask = 0600
directory mask = 0700
browseable = No
guest ok = Yes
profile acls = yes
csc policy = disable
# next line is a great way to secure the profiles
#force user = %U
# next line allows administrator to access all profiles
#valid users = %U "Domain Admins"

[printers]
comment = Network Printers
#printer admin = @"Print Operators"
guest ok = yes
printable = yes
path = /home/spool/
browseable = No
; read only = yes
print command = /usr/bin/lpr -P%p -r %s
lpq command = /usr/bin/lpq -P%p
lprm command = /usr/bin/lprm -P%p %j
# print command = /usr/bin/lpr -U%U@%M -P%p -r %s
# lpq command = /usr/bin/lpq -U%U@%M -P%p
# lprm command = /usr/bin/lprm -U%U@%M -P%p %j
# lppause command = /usr/sbin/lpc -U%U@%M hold %p %j
# lpresume command = /usr/sbin/lpc -U%U@%M release %p %j
# queuepause command = /usr/sbin/lpc -U%U@%M stop %p
# queueresume command = /usr/sbin/lpc -U%U@%M start %p

[print$]
path = /home/printers
; guest ok = no
; browseable = yes
; read only = yes
valid users = @"Print Operators"
write list = @"Print Operators"
create mask = 0664
directory mask = 0775

#[public]
# path = /tmp
# guest ok = yes
# browseable = Yes
# writable = yes

Ahora necesitamos hacer saber a samba cual es el password del usuario Administrador o del root en caso que sea este quien este como administreador en la config del slapd.conf de openLDAP para que pueda conectarse al directorio (Esto ahí quien cree que no es necesario aunque yo lo implemento aquí.) :
smbpasswd -w password

Nos aparecerá el siguiente mensaje y confirmara que samba ya pueda autenticarse en openLDAP:
Setting stored password for "cn=root,dc=prueba" in secrets.tdb

Testeamos y reiniciamos samba:
testparm
service smb restart









3. Smbldap-tools

Ahora averiguamos el SID de nuestro servidor Samba:
net getlocalsid

Nos mostrará un mensaje similar al siguiente y debemos de anotarlo o copiarlo:
SID for domain POSEIDON is: S-1-5-21-XXXXXXXXXX-XXXXXXXXXX


Procedemos a configurar el acceso smbldap-tools a la BD de openLDAP en /etc/smbldap-tools/smbldap_bind.conf :
# password es el password sin cifrar del Administrador openLDAP
slaveDN="cn=root,dc=prueba"
slavePw="password"
masterDN="cn=root,dc=prueba"
masterPw="password"

Y la configuración principal en /etc/smbldap-tools/smbldap.conf :
# Aquí¬ el SID que copiamos
SID="S-1-5-21-XXXXXXXXXXX-XXXXXXXXXX-XXXXXXX"

sambaDomain="PRUEBA"

##############################################################################
#
# LDAP Configuration
#
##############################################################################

# Notes: to use to dual ldap servers backend for Samba, you must patch
# Samba with the dual-head patch from IDEALX. If not using this patch
# just use the same server for slaveLDAP and masterLDAP.
# Those two servers declarations can also be used when you have
# . one master LDAP server where all writing operations must be done
# . one slave LDAP server where all reading operations must be done
# (typically a replication directory)

# Slave LDAP server
# Ex: slaveLDAP=127.0.0.1
# If not defined, parameter is set to "127.0.0.1"
slaveLDAP="127.0.0.1"

# Slave LDAP port
# If not defined, parameter is set to "389"
slavePort="389"

# Master LDAP server: needed for write operations
# Ex: masterLDAP=127.0.0.1
# If not defined, parameter is set to "127.0.0.1"
masterLDAP="127.0.0.1"

# Master LDAP port
# If not defined, parameter is set to "389"
masterPort="389"

# Use TLS for LDAP
# If set to 1, this option will use start_tls for connection
# (you should also used the port 389)
# If not defined, parameter is set to "1"
ldapTLS="0"

# How to verify the server's certificate (none, optional or require)
# see "man Net::LDAP" in start_tls section for more details
verify=""

# CA certificate
# see "man Net::LDAP" in start_tls section for more details
cafile=""

# certificate to use to connect to the ldap server
# see "man Net::LDAP" in start_tls section for more details
clientcert=""

# key certificate to use to connect to the ldap server
# see "man Net::LDAP" in start_tls section for more details
clientkey=""

# LDAP Suffix
# Ex: suffix=dc=IDEALX,dc=ORG
suffix="dc=PRUEBA"

# Where are stored Users
# Ex: usersdn="ou=Users,dc=IDEALX,dc=ORG"
# Warning: if 'suffix' is not set here, you must set the full dn for usersdn
usersdn="ou=People,${suffix}"

# Where are stored Computers
# Ex: computersdn="ou=Computers,dc=IDEALX,dc=ORG"
# Warning: if 'suffix' is not set here, you must set the full dn for computersdn
computersdn="ou=Computers,${suffix}"

# Where are stored Groups
# Ex: groupsdn="ou=Groups,dc=IDEALX,dc=ORG"
# Warning: if 'suffix' is not set here, you must set the full dn for groupsdn
groupsdn="ou=Group,${suffix}"

# Where are stored Idmap entries (used if samba is a domain member server)
# Ex: groupsdn="ou=Idmap,dc=IDEALX,dc=ORG"
# Warning: if 'suffix' is not set here, you must set the full dn for idmapdn
idmapdn="ou=Idmap,${suffix}"

# Where to store next uidNumber and gidNumber available for new users and groups
# If not defined, entries are stored in sambaDomainName object.
# Ex: sambaUnixIdPooldn="sambaDomainName=${sambaDomain},${suffix}"
# Ex: sambaUnixIdPooldn="cn=NextFreeUnixId,${suffix}"
sambaUnixIdPooldn="sambaDomainName=PRUEBA,${suffix}"

# Default scope Used
scope="sub"

# Unix password encryption (CRYPT, MD5, SMD5, SSHA, SHA, CLEARTEXT)
hash_encrypt="MD5"

# if hash_encrypt is set to CRYPT, you may set a salt format.
# default is "%s", but many systems will generate MD5 hashed
# passwords if you use "$1$%.8s". This parameter is optional!
crypt_salt_format=""

##############################################################################
#
# Unix Accounts Configuration
#
##############################################################################

# Login defs
# Default Login Shell
# Ex: userLoginShell="/bin/bash"
userLoginShell="/bin/false"

# Home directory
# Ex: userHome="/home/%U"
userHome="/home/%U"

# Default mode used for user homeDirectory
userHomeDirectoryMode="700"

# Gecos
userGecos="System User"

# Default User (POSIX and Samba) GID
defaultUserGid="513"

# Default Computer (Samba) GID
defaultComputerGid="515"

# Skel dir
skeletonDir="/etc/skel"

# Default password validation time (time in days) Comment the next line if
# you don't want password to be enable for defaultMaxPasswordAge days (be
# careful to the sambaPwdMustChange attribute's value)
defaultMaxPasswordAge="45"

##############################################################################
#
# SAMBA Configuration
#
##############################################################################

# The UNC path to home drives location (%U username substitution)
# Just set it to a null string if you want to use the smb.conf 'logon home'
# directive and/or disable roaming profiles
# Ex: userSmbHome="\\PDC-SMB3\%U"
userSmbHome="\\POSEIDON\%U"

# The UNC path to profiles locations (%U username substitution)
# Just set it to a null string if you want to use the smb.conf 'logon path'
# directive and/or disable roaming profiles
# Ex: userProfile="\\PDC-SMB3\profiles\%U"
userProfile="\\POSEIDON\profiles\%U"

# The default Home Drive Letter mapping
# (will be automatically mapped at logon time if home directory exist)
# Ex: userHomeDrive="H:"
userHomeDrive="Z"

# The default user netlogon script name (%U username substitution)
# if not used, will be automatically username.cmd
# make sure script file is edited under dos
# Ex: userScript="startup.cmd" # make sure script file is edited under dos
userScript="%u.bat"

# Domain appended to the users "mail"-attribute
# when smbldap-useradd -M is used
# Ex: mailDomain="idealx.com"
mailDomain="prueba.edu.cu"

##############################################################################
#
# SMBLDAP-TOOLS Configuration (default are ok for a RedHat)
#
##############################################################################

# Allows not to use smbpasswd (if with_smbpasswd="0" in smbldap.conf) but
# prefer Crypt::SmbHash library
with_smbpasswd="0"
smbpasswd="/usr/bin/smbpasswd"

# Allows not to use slappasswd (if with_slappasswd="0" in smbldap.conf)
# but prefer Crypt:: libraries
with_slappasswd="0"
slappasswd="/usr/sbin/slappasswd"

# comment out the following line to get rid of the default banner
# no_banner="1"


Ahora debemos crear la estructura de dominio en openldap con el comando y digitar el password de Administrator que es el administrador del dominio:
smbldap-populate -a Administrator

Con un resultado similar al siguiente:

Populating LDAP directory for domain DOMAIN (S-1-5-21-XXXXXXXXXXX-XXXXXXXXXXx-XXXXXXXXXx)
(using builtin directory structure)
adding new entry: dc=prueba
adding new entry: ou=People,dc=prueba
adding new entry: ou=Group,dc=prueba
adding new entry: ou=Computers,dc=prueba
adding new entry: ou=Idmap,dc=prueba
adding new entry: uid=Administrator,ou=People,dc=prueba
adding new entry: uid=nobody,ou=People,dc=prueba
adding new entry: cn=Domain Admins,ou=Group,dc=prueba
adding new entry: cn=Domain Users,ou=Group,dc=prueba
adding new entry: cn=Domain Guests,ou=Group,dc=prueba
adding new entry: cn=Domain Computers,ou=Group,dc=prueba
adding new entry: cn=Administrators,ou=Group,dc=prueba
adding new entry: cn=Account Operators,ou=Group,dc=prueba
adding new entry: cn=Print Operators,ou=Group,dc=prueba
adding new entry: cn=Backup Operators,ou=Group,dc=prueba
adding new entry: cn=Replicators,ou=Group,dc=prueba
adding new entry: sambaDomainName=DOMAIN,dc=prueba
Please provide a password for the domain Administrator:
Changing password for root
New password :
Retype new password :

En este caso no quiero que se llame root por defecto, por ello lo cambie con el parámetro -a Administrator. (*nota* de momento lo pueden configurar con el usuario root por defecto luego cambiarlo cuando todo este trabajando bien asi les ahorra posibles problemas en caso de confusión de permisos.)
Ahora veremos la asociación de los builtin groups del dominio SAMBA con los grupos openLDAP creados:
net groupmap list

Con un resultado similar al siguiente:

Domain Admins (S-1-5-21-XXXXXXXXXX-XXXXXXXX-512) -> Domain Admins
Domain Users (S-1-5-21-XXXXXXXXXX-XXXXXXXX-513) -> Domain Users
Domain Guests (S-1-5-21-XXXXXXXXXX-XXXXXXXX-514) -> Domain Guests
Domain Computers (S-1-5-21-XXXXXXXXXX-XXXXXXXX-515) -> Domain Computers
Administrators (S-1-5-32-544) -> Administrators
Account Operators (S-1-5-32-548) -> Account Operators
Print Operators (S-1-5-32-550) -> Print Operators
Backup Operators (S-1-5-32-551) -> Backup Operators
Replicators (S-1-5-32-552) -> Replicators

Ahora podemos crear una cuenta de usuario Windows ( -a), se le crear su carpeta personal ( -m), especificando que no tenga una ruta Profile (opción -F) y le asignamos un password:

smbldap-useradd -a -m -F "" usuariowin
smbldap-passwd usuariowin

Para dudas del comando smbldap-useradd les recomiendo este comando man smbldap-useradd y leen lo que necesiten en cuanto a esto.

Reiniciamos samba y openLdap:
service ldap restart
service smb restart
Amiga mia, recuerda que la bellesa del cuerpo es un viajero que pasa, pero la del alma es un amigo que queda. Quisiera ser lo ultimo que vez cuando te acuestas pero lo primero que miras cuando te lebantas.

Avatar de Usuario
fixoconn
Mensajes: 32
Registrado: Mié, 05 Ene 2011, 10:13
Contactar:

Re: SAMBA+LDAP bajo Centos-5

Mensaje por fixoconn » Mié, 02 Oct 2013, 12:05

Si esto está probado debías llevarlo a la wiki.
FXCNN

Avatar de Usuario
DiosdelSueno1
Mensajes: 11
Registrado: Jue, 15 Ago 2013, 09:08
Ubicación: Regla

Re: SAMBA+LDAP bajo Centos-5

Mensaje por DiosdelSueno1 » Jue, 24 Oct 2013, 11:41

Si colega actualmente esta probado aunque con algunas modificaciones que con el tiempo le e echo para mejorar pero si pincha.
Amiga mia, recuerda que la bellesa del cuerpo es un viajero que pasa, pero la del alma es un amigo que queda. Quisiera ser lo ultimo que vez cuando te acuestas pero lo primero que miras cuando te lebantas.

Avatar de Usuario
DiosdelSueno1
Mensajes: 11
Registrado: Jue, 15 Ago 2013, 09:08
Ubicación: Regla

Re: SAMBA+LDAP bajo Centos-5

Mensaje por DiosdelSueno1 » Vie, 25 Oct 2013, 16:15

Colega si buscas en la Wiki esta publicado ya como explicaba con las configuraciones que actualmente e realizado en mi serv.
Saludos.
Amiga mia, recuerda que la bellesa del cuerpo es un viajero que pasa, pero la del alma es un amigo que queda. Quisiera ser lo ultimo que vez cuando te acuestas pero lo primero que miras cuando te lebantas.

Responder