il nostro /etc/samba/smb.conf deve risultare simile al seguente:
[global]
workgroup = ESEMPIO
realm = ESEMPIO.LAN
netbios name = pdc
server string = PDC/KDC
use kerberos keytab = yes
use spnego = yes
client NTLMv2 auth = yes
username map = /etc/samba/usermap
debug level = 1
log file = /var/log/samba/%m.log
max log size = 5000
syslog = 0
log level = 1
utmp = Yes
guest account = nobody
map to guest = Never
admin users = root addmachine @"Domain Admins"
enable privileges = yes
security = user
encrypt passwords = yes
os level = 255
local master = yes
domain master = yes
preferred master = yes
domain logons = yes
keepalive = 20
time server = yes
preserve case = yes
short preserve case = yes
case sensitive = no
null passwords = no
logon script = %U.bat
logon path =
logon drive = H:
logon home =
bind interfaces only = yes
interfaces = eth0, lo
hosts allow = 192.168.0.0/24 127.
wins support = yes
dns proxy = yes
passdb backend = ldapsam:ldaps://pdc.esempio.lan/
ldap admin dn = krb5PrincipalName=ldapmaster/[email protected],ou=KerberosPrincipals,ou=Users,dc=esempio,dc=lan
ldap suffix = dc=esempio,dc=lan
ldap group suffix = ou=Groups
ldap user suffix = ou=Users
ldap machine suffix = ou=Computers
ldap idmap suffix = ou=Idmap
ldap ssl = On
ldap delete dn = Yes
ldapsam:trusted = yes
idmap backend = ldap:ldaps://pdc.esempio.lan/
idmap uid = 10000-15000
idmap gid = 10000-15000
#
# Meccanismi interni a samba per tenere sincronizzate le password samba e ldap/kerberos
#
pam password change = no
ldap passwd sync = yes
unix password sync = no
socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=8192 SO_SNDBUF=8192
add machine script = /usr/sbin/smbldap-useradd -w "%u"
add user script = /usr/sbin/smbldap-useradd -m -a "%u"
delete user script = /usr/sbin/smbldap-userdel "%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"
dos charset = cp850
unix charset = iso8859-1
display charset = LOCALE
restrict anonymous = 0
# Comando per loggare login e logoff
root preexec = /etc/samba/log_access_login.bash "%L" "%U" "%G" "%H" "%u" "%S" "%I" "%m" ON
root postexec = /etc/samba/log_access_login.bash "%L" "%U" "%G" "%H" "%u" "%S" "%I" "%m" OFF
[homes]
comment = Home Directories
valid users = %S
browseable = no
writable = yes
admin users = %u
write list = %u
read list = %u
create mask = 0700
directory mask = 0700
[netlogon]
path = /samba/netlogon
writable = yes
browseable = no
share modes = no
admin users = @"Domain Admins"
modifichiamo anche il file /etc/samba/usermap:
addmachine = ESEMPIO.LAN\addmachine/admin root = ESEMPIO.LAN\root/admin
e scarichiamo lo script log_access_login.bash che ci servirà per loggare gli accessi al dominio:
# wget http://stefano.dscnet.org/howto/samba-pdc-ldap-kerberos/files/log_access_login.bash -P /etc/samba # chmod 700 /etc/samba/log_access_login.bashmodifichiamo inoltre /etc/request-key.conf aggiungendo
create cifs.spnego * * /usr/sbin/cifs.upcall %k %d
sistemiamo ora le cartelle necessarie:
# mkdir -p /samba/netlogon # mkdir -p /var/log/samba/login-logoff # rm -rf /etc/samba/*tdb # rm -rf /var/lib/samba/*tdb # rm -rf /var/lib/samba/*dat # rm -f /var/log/samba/*facciamo memorizzare a samba la password dell'utente ldap da usare per la connessione:
# smbpasswd -w secret1che restituirà questo output:
Setting stored password for "krb5PrincipalName=ldapmaster/[email protected],ou=KerberosPrincipals,ou=Users,dc=esempio,dc=lan" in secrets.tdbriavviamo ora samba:
# /etc/init.d/samba restart
# net getlocalsid ESEMPIO
e andiamo a creare il file /etc/smbldap-tools/smbldap.conf, inserendo al suo interno il SID appena recuperato.
SID="S-1-5-21-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX"
sambaDomain="ESEMPIO"
realm="ESEMPIO.LAN"
slaveLDAP="ldap://pdc.esempio.lan"
slavePort="389"
masterLDAP="ldap://pdc.esempio.lan"
masterPort="389"
ldapTLS="1"
verify="require"
cafile="/etc/ldap/ssl/cacert.pem"
clientcert="/etc/ldap/ssl/servercrt.pem"
clientkey="/etc/ldap/ssl/serverkey.pem"
suffix="dc=esempio,dc=lan"
usersdn="ou=Users,${suffix}"
computersdn="ou=Computers,${suffix}"
groupsdn="ou=Groups,${suffix}"
idmapdn="ou=Idmap,${suffix}"
sambaUnixIdPooldn="sambaDomainName=ESEMPIO,${suffix}"
scope="sub"
hash_encrypt="MD5"
crypt_salt_format="%s"
userLoginShell="/bin/bash"
userHome="/srv/home/%U"
userHomeDirectoryMode="700"
userGecos="LDAP-Kerberos User"
defaultUserGid="513"
defaultComputerGid="515"
skeletonDir="/etc/skel"
defaultMaxPasswordAge="45"
userSmbHome="\\pdc\%U"
#userProfile="\\pdc\profiles\%U"
userHomeDrive="H:"
userScript="%U.bat"
mailDomain="esempio.lan"
with_smbpasswd="0"
smbpasswd="/usr/bin/smbpasswd"
with_slappasswd="0"
slappasswd="/usr/sbin/slappasswd"
# no_banner="1"
creiamo anche il file /etc/smbldap-tools/smbldap_bind.conf
slaveDN="krb5PrincipalName=ldapmaster/[email protected],ou=KerberosPrincipals,ou=Users,dc=esempio,dc=lan" slavePw="secret1" masterDN="krb5PrincipalName=ldapmaster/[email protected],ou=KerberosPrincipals,ou=Users,dc=esempio,dc=lan" masterPw="secret1"
recuperiamo ora le versioni modificate di alcuni script smbldap:
# wget http://stefano.dscnet.org/howto/samba-pdc-ldap-kerberos/files/smbldap-useradd -P /tmp/ # wget http://stefano.dscnet.org/howto/samba-pdc-ldap-kerberos/files/smbldap-passwd -P /tmp/ # mv /tmp/smbldap-useradd /usr/sbin/ # mv /tmp/smbldap-passwd /usr/sbin/ # chmod +x /usr/sbin/smbldap-useradd # chmod +x /usr/sbin/smbldap-passwd
sistemiamo cartelle e permessi
# chmod 600 /etc/smbldap-tools/ -R # chmod 700 /usr/sbin/smbldap-* # mkdir -p /srv/home
# smbldap-populate -a root -k 0 -m 0il comando dovrebbe restituire
Populating LDAP directory for domain ESEMPIO (S-1-5-21-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX) (using builtin directory structure) entry dc=esempio,dc=lan already exist. entry ou=Users,dc=esempio,dc=lan already exist. entry ou=Groups,dc=esempio,dc=lan already exist. entry ou=Computers,dc=esempio,dc=lan already exist. adding new entry: ou=Idmap,dc=esempio,dc=lan adding new entry: uid=root,ou=Users,dc=esempio,dc=lan adding new entry: uid=nobody,ou=Users,dc=esempio,dc=lan adding new entry: cn=Domain Admins,ou=Groups,dc=esempio,dc=lan adding new entry: cn=Domain Users,ou=Groups,dc=esempio,dc=lan adding new entry: cn=Domain Guests,ou=Groups,dc=esempio,dc=lan adding new entry: cn=Domain Computers,ou=Groups,dc=esempio,dc=lan adding new entry: cn=Administrators,ou=Groups,dc=esempio,dc=lan adding new entry: cn=Account Operators,ou=Groups,dc=esempio,dc=lan adding new entry: cn=Print Operators,ou=Groups,dc=esempio,dc=lan adding new entry: cn=Backup Operators,ou=Groups,dc=esempio,dc=lan adding new entry: cn=Replicators,ou=Groups,dc=esempio,dc=lan entry sambaDomainName=ESEMPIO,dc=esempio,dc=lan already exist. Updating it... Please provide a password for the domain root: Changing UNIX and samba passwords for root New password: Retype new password:
È necessario ora effettuare alcune modifiche nella struttura creata:
iniziamo modificando il primo User ID libero: creiamo il file /root/ldap_nextuid.ldif:
dn: sambaDomainName=ESEMPIO,dc=esempio,dc=lan replace: uidNumber uidNumber: 2000 - replace: gidNumber gidNumber: 2000lanciamo poi
# ldapmodify -x -D "krb5PrincipalName=ldapmaster/[email protected],ou=KerberosPrincipals,ou=Users,dc=esempio,dc=lan" -w secret1 -f /root/ldap_nextuid.ldif
modifiche per l'utente root inserito in LDAP: /root/ldap_rootuser.ldif
dn: uid=root,ou=Users,dc=esempio,dc=lan changetype: modify add: objectClass objectClass: krb5Principal objectClass: krb5KDCEntry - add: krb5KeyVersionNumber krb5KeyVersionNumber: 1 - add: krb5PrincipalName krb5PrincipalName: root/[email protected] - add: krb5KDCFlags krb5KDCFlags: 126 - add: krb5MaxRenew krb5MaxRenew: 604800 - add: krb5MaxLife krb5MaxLife: 86400 - replace: homeDirectory homeDirectory: /root - replace: gidNumber gidNumber: 512lanciamo quindi:
# ldapmodify -x -D "krb5PrincipalName=ldapmaster/[email protected],ou=KerberosPrincipals,ou=Users,dc=esempio,dc=lan" -w secret1 -f /root/ldap_rootuser.ldif
modifiche per l'utente nobody inserito in LDAP: /root/ldap_nobodyuser.ldif
dn: uid=nobody,ou=Users,dc=esempio,dc=lan changetype: modify replace: gidNumber gidNumber: 514lanciamo poi:
# ldapmodify -x -D "krb5PrincipalName=ldapmaster/[email protected],ou=KerberosPrincipals,ou=Users,dc=esempio,dc=lan" -w secret1 -f /root/ldap_nobodyuser.ldif
Creiamo ora un utente per l'aggiunta di macchine al dominio samba/kerberos:
# smbldap-useradd -a -m addmachine # smbldap-passwd addmachinemodifichiamo anche per questo utente alcuni dati: creiamo quindi il file /root/ldap_addmachineuser.ldif
dn: uid=addmachine,ou=Users,dc=esempio,dc=lan replace: krb5PrincipalName krb5PrincipalName: addmachine/[email protected]e lanciamo poi:
# ldapmodify -x -D "krb5PrincipalName=ldapmaster/[email protected],ou=KerberosPrincipals,ou=Users,dc=esempio,dc=lan" -w secret1 -f /root/ldap_addmachineuser.ldif
# smbldap-useradd -m -a stefano # smbldap-passwd stefano # smbldap-userinfo stefanoSe vogliamo che un utente possa loggarsi correttamente anche in un desktop GNU/Linux dobbiamo "clonare" in LDAP anche le informazioni sui vari gruppi a cui l'utente dovrà appartenere per poter operare correttamente nel suo ambiente di lavoro (gruppi video, plugdev, disk, fuse, ...) e inserire l'utente in tali gruppi, sempre usando i tools smbldap.
# /etc/init.d/bind9 restart # /etc/init.d/slapd restart # /etc/init.d/samba restart # /etc/init.d/heimdal-kdc restart # /etc/init.d/heimdal-kcm restart # /etc/init.d/ntp restart # /etc/init.d/saslauthd restart # /etc/init.d/openbsd-inetd restart
Stefano Sasso 2009-04-16