Samba + LDAP

Опубликовано nekit - ср, 23/03/2011 - 18:18
Потребовалось на предприятии поставить сервер, который будет раздавать шары. Решил пойти таким путем: поставить самбу и лдап сервер, в котором будут группы и пользователи самбы. На сервере стоит ОС FreeBSD 8.1. Вначале ставим LDAP:
  1. # cd /usr/ports/net/openldap24-server
  2. # make install clean
Все параметры я оставил как есть. После успешной установки идем править конфиг - /usr/local/etc/openldap/slapd.conf. У меня он получился такого содержания
  1. #
  2. # See slapd.conf(5) for details on configuration options.
  3. # This file should NOT be world readable.
  4. #
  5. include     /usr/local/etc/openldap/schema/core.schema
  6. include     /usr/local/etc/openldap/schema/cosine.schema
  7. include     /usr/local/etc/openldap/schema/inetorgperson.schema
  8. include     /usr/local/etc/openldap/schema/misc.schema
  9. include     /usr/local/etc/openldap/schema/nis.schema
  10. include     /usr/local/etc/openldap/schema/openldap.schema
  11.  
  12. # Define global ACLs to disable default read access.
  13.  
  14. # Do not enable referrals until AFTER you have a working directory
  15. # service AND an understanding of referrals.
  16. #referral   ldap://root.openldap.org
  17.  
  18. pidfile     /var/run/openldap/slapd.pid
  19. argsfile    /var/run/openldap/slapd.args
  20.  
  21. # Load dynamic backend modules:
  22. modulepath  /usr/local/libexec/openldap
  23. moduleload  back_bdb
  24. # moduleload    back_hdb
  25. # moduleload    back_ldap
  26.  
  27. # Sample security restrictions
  28. #   Require integrity protection (prevent hijacking)
  29. #   Require 112-bit (3DES or better) encryption for updates
  30. #   Require 63-bit encryption for simple bind
  31. # security ssf=1 update_ssf=112 simple_bind=64
  32.  
  33. # Sample access control policy:
  34. #   Root DSE: allow anyone to read it
  35. #   Subschema (sub)entry DSE: allow anyone to read it
  36. #   Other DSEs:
  37. #       Allow self write access
  38. #       Allow authenticated users read access
  39. #       Allow anonymous users to authenticate
  40. #   Directives needed to implement policy:
  41. # access to dn.base="" by * read
  42. # access to dn.base="cn=Subschema" by * read
  43. # access to *
  44. #   by self write
  45. #   by users read
  46. #   by anonymous auth
  47. #
  48. # if no access controls are present, the default policy
  49. # allows anyone and everyone to read anything but restricts
  50. # updates to rootdn.  (e.g., "access to * by * read")
  51. #
  52. # rootdn can always read and write EVERYTHING!
  53.  
  54. access to attrs=userPassword
  55.     by self write
  56.     by anonymous auth
  57.     by * none
  58.  
  59. access to *
  60.     by self write
  61.     by users read
  62.     by anonymous read
  63.     by * none
  64.  
  65. #######################################################################
  66. # BDB database definitions
  67. #######################################################################
  68.  
  69. database    bdb
  70. suffix      "dc=dush4,dc=ru"
  71. rootdn      "cn=root,dc=dush4,dc=ru"
  72. # Cleartext passwords, especially for the rootdn, should
  73. # be avoid.  See slappasswd(8) and slapd.conf(5) for details.
  74. # Use of strong authentication encouraged.
  75. rootpw      {SSHA}*****
  76. # The database directory MUST exist prior to running slapd AND
  77. # should only be accessible by the slapd and slap tools.
  78. # Mode 700 recommended.
  79. directory   /var/db/openldap-data
  80. # Indices to maintain
  81. index   objectClass eq
  82. index   cn      eq
Пароль для админа в OpenLDAP генерируется командой slappasswd, полученный результат работы команды нужно просто скопировать в конфиг. Добавляем следующие записи в /etc/rc.conf
  1. slapd_enable="YES"
  2. slapd_flags='-h "ldapi://%2fvar%2frun%2fopenldap%2fldapi/ ldap://127.0.0.1/"'
Далее пробуем запустить сервис
  1. # /usr/local/etc/rc.d/slapd start
Проверяем запустился ли сервис:
  1. # sockstat | grep slapd
  2. ldap     slapd      693   3  dgram  -> /var/run/logpriv
  3. ldap     slapd      693   6  stream /var/run/openldap/ldapi
  4. ldap     slapd      693   7  tcp4   127.0.0.1:389         *:*
Если вы видите что-то на подобии этого, то значит - все прошло нормально. Наполняем лдап начальными данными, для этого создаем файл main.ldif следующего содержания:
  1. dn: dc=dush4,dc=ru
  2. objectClass: dcObject
  3. objectClass: organization
  4. objectClass: top
  5. dc: dush4
  6. o: dush4
  7.  
  8. dn: cn=root,dc=srv-home,dc=local
  9. objectClass: organizationalRole
  10. ou: root
  11.  
  12. dn: ou=users,dc=dush4,dc=ru
  13. objectClass: top
  14. objectClass: organizationalUnit
  15. ou: users
  16.  
  17. dn: ou=groups,dc=dush4,dc=ru
  18. objectClass: top
  19. objectClass: organizationalUnit
  20. ou: groups
  21.  
  22. dn: ou=computers,dc=dush4,dc=ru
  23. objectClass: top
  24. objectClass: organizationalUnit
  25. ou: computers
Чтобы добавить записи, выполняем следующую команду:
  1. # ldapadd -x -D "cn=root,dc=dush4,dc=ru" -W -f main.ldif
С настройкой OpenLDAP пока закончили, переходим к установке Samba.
  1. # cd /usr/ports/net/samba
  2. # make install clean
Из всех опций я оставил следующие:
  • LDAP
  • ACL_SUPPORT
  • QUOTAS
  • POPT
После установки самбы нужно добавить новую схему в OpenLDAP, для этого делаем следующее
  1. # cp /usr/local/share/examples/samba/LDAP/samba.schema /usr/local/etc/openldap/schema
Далее правим конфиг, добавляем следующую строчку
  1. include     /usr/local/etc/openldap/schema/samba.schema
И перезапускаем сервер
  1. # /usr/local/etc/rc.d/slapd restart
После этих не сложных действий правим конфиг самбы - /usr/local/etc/smb.conf. У меня он получился таким:
  1. #======================= Global Settings =====================================
  2. [global]
  3.    workgroup = DUSH-4
  4.    server string = DUSH-4 File Server
  5.    netbios name = srv-data.local
  6.  
  7.    security = user
  8.    hosts allow = 192.168.4. 127.
  9.    load printers = no
  10. ;   printcap name = /etc/printcap
  11. ;   printcap name = lpstat
  12. ;   printing = cups
  13. ;  guest account = pcguest
  14.  
  15.    log file = /var/log/samba/log.%m
  16.    max log size = 50
  17.  
  18.    encrypt passwords = yes
  19.    passdb backend = ldapsam:ldap://localhost/
  20.    ldap suffix = dc=dush4,dc=ru
  21.    ldap user suffix = ou=users
  22.    ldap group suffix = ou=groups
  23.    ldap machine suffix = ou=computers
  24.    ldap admin dn = "cn=root,dc=dush4,dc=ru"
  25.    ldap delete dn = no
  26.    ldap ssl = no
  27.  
  28.    socket options = SO_RCVBUF=32768 SO_SNDBUF=32768
  29.  
  30.    interfaces = 192.168.4.251/24 127.0.0.1/8
  31.    bind interfaces only = yes
  32.    local master = yes
  33.    os level = 65
  34.    domain master = yes
  35.    preferred master = yes
  36.    domain logons = no
  37.    wins support = yes
  38.    dns proxy = no
  39.    hide dot files = yes
  40.    hide files = /.*
  41.    dfree cache time = 60
  42.    dfree command = /usr/local/bin/dfree
  43.  
  44.    display charset = koi8-r
  45.    unix charset = koi8-r
  46.    dos charset = cp866
  47.  
  48. # Use inherited ACLs for directories
  49. ;    nt acl support = yes
  50. ;    inherit acls = yes
  51. ;    map acl inherit = yes
  52.  
  53. # These scripts are used on a domain controller or stand-alone
  54. # machine to add or delete corresponding unix accounts
  55. ;  add user script = /usr/sbin/useradd %u
  56. ;  add group script = /usr/sbin/groupadd %g
  57. ;  add machine script = /usr/sbin/adduser -n -g machines -c Machine -d /dev/null -s /bin/false %u
  58. ;  delete user script = /usr/sbin/userdel %u
  59. ;  delete user from group script = /usr/sbin/deluser %u %g
  60. ;  delete group script = /usr/sbin/groupdel %g
  61.  
  62.  
  63. #============================ Share Definitions ==============================
  64. [homes]
  65.    comment = Home Directories
  66.    browseable = no
  67.    writable = yes
  68.  
  69. # Un-comment the following and create the netlogon directory for Domain Logons
  70. ; [netlogon]
  71. ;   comment = Network Logon Service
  72. ;   path = /usr/local/samba/lib/netlogon
  73. ;   guest ok = yes
  74. ;   writable = no
  75. ;   share modes = no
  76.  
  77.  
  78. # Un-comment the following to provide a specific roving profile share
  79. # the default is to use the user's home directory
  80. ;[Profiles]
  81. ;    path = /usr/local/samba/profiles
  82. ;    browseable = no
  83. ;    guest ok = yes
  84.  
  85.  
  86. # NOTE: If you have a BSD-style print system there is no need to
  87. # specifically define each individual printer
  88. [printers]
  89.    comment = All Printers
  90.    path = /var/spool/samba
  91.    browseable = no
  92. # Set public = yes to allow user 'guest account' to print
  93.    guest ok = no
  94.    writable = no
  95.    printable = yes
  96.  
  97. [distrib]
  98.    comment = Distrib
  99.    path = /mnt/media/samba/distrib
  100.    public = no
  101.    writable = yes
  102.    force create mode = 0640
  103.    force directory mode = 0750
  104.    force user = smb_user
  105.    force group = smb_write
  106.    valid users = @smb_read
  107.    read list = @smb_read
  108.    write list = @smb_write
  109.  
  110. [temp]
  111.    comment = Temporary files
  112.    path = /mnt/media/samba/temp
  113.    public = no
  114.    writable = yes
  115.    force create mode = 0640
  116.    force directory mode = 0750
  117.    force user = smb_user
  118.    force group = smb_write
  119.    valid users = @smb_read
  120.    read list = @smb_read
  121.    write list = @smb_read
После чего нужно сказать пароль самбе от указанной учетной записи лдап, для этого делаем следующее:
  1. # smbpasswd
  2. New password: ***
  3. Retry new password: ***
Вводим пароль за запускаем самбу:
  1. # /usr/local/etc/rc.d/samba start
  2. Starting nmbd.
  3. Starting smbd.
На этом установка и настройка пакетов закончена. Для простоты администрирования учетных записей в LDAP можно дополнительно установить пакет ldapscripts.

Добавить комментарий

Этот вопрос задается для того, чтобы выяснить, являетесь ли Вы человеком или представляете из себя автоматическую спам-рассылку.