terça-feira, 28 de maio de 2013

Mac OS X: Samba 3, versão open source (II)

1.- Confirmar que a opção "File Sharing" está desactivada (System Preferences, Sharing).

2.- Desactivar o serviço com.apple.netbiosd (Apple's SMB server)
~$ sudo mv /System/Library/LaunchDaemons/com.apple.netbiosd.plist com.apple.netbiosd.bak

ou...

... editamos o ficheiro /etc/services e modificamos as entradas correspondentes às portas 137, 138, 139 e 445 para 19137, 19138, 19139 e 19445 de forma a que os serviços não entrem em conflito caso activemos acidentalmente a opção "File Sharing":

Criar backup do ficheiro original
~$ sudo cp /etc/services /etc/services.bak

~$ sudo nano /etc/services

netbios-ns      19137/udp     # NETBIOS Name Service   
netbios-ns      19137/tcp     # NETBIOS Name Service   
netbios-dgm     19138/udp     # NETBIOS Datagram Service
netbios-dgm     19138/tcp     # NETBIOS Datagram Service
netbios-ssn     19139/udp     # NETBIOS Session Service
netbios-ssn     19139/tcp     # NETBIOS Session Service
microsoft-ds    19445/udp     # Microsoft-DS
microsoft-ds    19445/tcp     # Microsoft-DS


3.- Instalar o Samba (3.6.20) via Homebrew
~$ brew install samba

4.- Criar ficheiro org.samba.smbd.plist:
~$ sudo nano /Library/LaunchDaemons/org.samba.smbd.plist
 <?xml version="1.0" encoding="UTF-8"?>  
 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">  
 <plist version="1.0">  
   <dict>  
     <key>Label</key>  
     <string>org.samba.smbd</string>  
     <key>OnDemand</key>  
     <false/>  
     <key>ProgramArguments</key>  
     <array>  
       <string>/usr/local/Cellar/samba/3.6.20/sbin/smbd</string>  
       <string>-F</string>  
     </array>  
     <key>RunAtLoad</key>  
     <true/>  
     <key>ServiceDescription</key>  
     <string>samba</string>  
   </dict>  
 </plist>  

5.- Criar ficheiro org.samba.nmbd.plist:
~$ sudo nano /Library/LaunchDaemons/org.samba.nmbd.plist
 <?xml version="1.0" encoding="UTF-8"?>  
 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">  
 <plist version="1.0">  
   <dict>  
     <key>Label</key>  
     <string>org.samba.nmbd</string>  
     <key>OnDemand</key>  
     <false/>  
     <key>ProgramArguments</key>  
     <array>  
       <string>/usr/local/Cellar/samba/3.6.20/sbin/nmbd</string>  
       <string>-F</string>  
     </array>  
     <key>RunAtLoad</key>  
     <true/>  
     <key>ServiceDescription</key>  
     <string>netbios</string>  
   </dict>  
 </plist>  

6.- Criar a directoria "private" (O Homebrew não cria automaticamente...):
~$ mkdir /usr/local/Cellar/samba/3.6.20/private

7.- Configurar smb.conf (com acesso "guest"):
~$ sudo nano /usr/local/Cellar/samba/3.6.20/etc/smb.conf

[global]
  workgroup = WORKGROUP
  server string = Samba 3.6.20
  netbios name = gandalf
  security = user
  Map to guest = Bad User
  smb passwd file = /usr/local/Cellar/samba/3.6.20/private/smbpasswd
  private dir = /usr/local/Cellar/samba/3.6.20/private
  passdb backend = tdbsam
  client NTLMv2 auth = Yes
  log level = 2
  debug timestamp = No
  debug hires timestamp = Yes
  max open files = 16384
  ldap ssl = start tls
  lock directory = /usr/local/Cellar/samba/3.6.20/var/locks
  pid directory = /usr/local/Cellar/samba/3.6.20/var/locks
  usershare path = /usr/local/Cellar/samba/3.6.20/var/locks/usershares
  idmap cache time = 604800
  wide links = No

[share]
  comment = MacBook
  path = /Users/Shared/share
  guest ok = yes
  wide links = no
  writeable = Yes
  force create mode = 0755
  force directory mode = 0755


8.- Verificar se há erros:
~$ testparm /usr/local/Cellar/samba/3.6.20/etc/smb.conf

se houver, é quase de certeza por causa da inexistência das directorias mencionadas acima. Por isso, criamos manualmente:
~$ mkdir /usr/local/Cellar/samba/3.6.20/var
~$ mkdir /usr/local/Cellar/samba/3.6.20/var/locks
~$ mkdir /usr/local/Cellar/samba/3.6.20/var/locks/usershares

9.- Iniciar serviço
~$ sudo launchctl load /Library/LaunchDaemons/org.samba.smbd.plist
~$ sudo launchctl load /Library/LaunchDaemons/org.samba.nmbd.plist

Et voilà.

Mais informações:
- http://www.x2416.com/2012/06/samba-on-osx-lion-server.html
- http://blog.rubbingalcoholic.com/post/39412902216/fix-smb-windows-sharing-permissions-issue-in-os-x-10-7
...
- http://penadigital.blogspot.pt/2012/09/mac-os-x-samba-3-versao-open-source.html

#edit 16.11.2013