Koozali.org: home of the SME Server

Samba audit

Offline lerry

  • **
  • 23
  • +0/-0
Samba audit
« on: April 11, 2011, 04:07:33 PM »
Come da richiesta di Stefano sono a riproporre qui un post che ho pubblicato nel forum dedicato a Sme8. (link al post in inglese http://forums.contribs.org/index.php/topic,47393.msg233852.html#msg233852

Stavo cercando di far funzionare l'audit di Samba sotto Sme8beta6.

Situazione:
sto usando diversi contrib, tra i quali l'utile (almeno per me) SharedFolder. Ora ero intenzionato ad abilitare l'audit di Samba, ed ho iniziato a documentarmi. Ho trovato alcuni articoli già pubblicati sul forum, e sono partito da questi per trovare una soluzione al mio problema.
Il primo http://forums.contribs.org/index.php?topic=46444.0 parla appunto di abilitare l'audit sulle i-bay ma, lavorando su un contrib che crea la sue proprie cartelle condivise, purtroppo non funziona.
Andando avanti nella lettura sono imbattuto in http://forums.contribs.org/index.php?topic=35872.0 ed in http://a32.me/2009/10/samba-audit-trail/, così ho iniziato a modificare a mano i fragment del samba di modo da far funzionare il tutto.
Ho modificato il fragment di sharedfolder (/etc/e-smith/templates/etc/smb.conf/90shares
Code: [Select]
{
    # process all information-bay directories

    use esmith::AccountsDB;
    my $adb = esmith::AccountsDB->open_ro();

    foreach my $share ($adb->get_all_by_prop(type => 'share'))
    {
        if ( ($share->prop('smbAccess') || 'browseable') =~ /browseable$/ ){
            $OUT .= esmith::templates::processTemplate (
                {
                    MORE_DATA => {
                        share => $share,
                    },
                    TEMPLATE_PATH => "/etc/smb.conf/shares",
                    OUTPUT_TYPE => 'string',
                });
        }
        else{
            $OUT .= "# ".$share->key." access is disabled\n";
        }
#inizio nuovo codice
     $OUT .="# Audit settings
full_audit:prefix = %u|%I|%S
full_audit:failure = connect
full_audit:success = opendir mkdir rmdir open write rename unlink
full_audit:facility = local5
full_audit:priority = notice
"
#fine
    }
}
Ho eseguito /sbin/e-smith/expand-template /etc/smb.conf e quando vado a controllare in smb.conf la modifica è avvenuta
Code: [Select]
# Please read the developer's guide, which is available
# at http://www.contribs.org/development/
#
# Copyright (C) 1999-2006 Mitel Networks Corporation
#------------------------------------------------------------


[global]



add machine script = /sbin/e-smith/signal-event machine-account-create '%u'

bind interfaces only = yes

case sensitive = no
deadtime = 10080

display charset = ISO8859-1

dns proxy = no

domain logons = yes
domain master = yes
dos charset = 850

encrypt passwords = yes

guest account = public

guest ok = no
hosts allow = 127.0.0.1 192.168.1.0/255.255.255.0 192.168.2.0/255.255.255.0


interfaces = 127.0.0.1 192.168.1.10/255.255.255.0

log file = /var/log/samba/log.%m
logon drive = Z:
logon home = \\%L\%U\._winprofile
logon path = \\%L\Profiles\%U
logon script = netlogon.bat

map to guest = never

max log size = 50

name resolve order = wins lmhosts bcast

netbios name = server-sme
oplocks = true
kernel oplocks = true
level2 oplocks = true

os level = 65

passdb backend = smbpasswd:/etc/samba/smbpasswd


pid directory = /var/run
preferred master = yes

preserve case = yes
private dir = /etc/samba



security = user
server string = SME Server
short preserve case = yes
smb passwd file = /etc/samba/smbpasswd
smb ports = 139

socket options = TCP_NODELAY

strict locking = no
unix charset = UTF8

unix password sync = Yes
pam password change = Yes

passwd program = /usr/bin/passwd %u
passwd chat = *New*UNIX*password* %n\n *ReType*new*UNIX*password* %n\n *passwd:*all*authentication*tokens*updated*successfully*
check password script = /sbin/e-smith/samba_check_password
unix extensions = no


wins support = yes

workgroup = test.local
printcap name = /etc/printcap
load printers = yes
printing = lprng
print command = /usr/bin/lpr -b -h -r -P%p %s

[homes]
comment = Home directory
browseable = no
guest ok = no
read only = no
writable = yes
printable = no
create mode = 0660
force create mode = 0660
directory mode = 0770
force directory mode = 0770
path = /home/e-smith/files/users/%S/home

[printers]
comment = All Printers
path = /var/spool/samba
browseable = no
guest ok = no
writable = no
printable = yes
use client driver = yes
[Profiles]
path = /home/e-smith/files/samba/profiles
writeable = yes
browseable = no
create mask = 0600
directory mask = 0700
csc policy = disable
hide files = /desktop.ini/ntuser.ini/NTUSER.*/

[netlogon]
comment = Network Logon Service
path = /home/e-smith/files/samba/netlogon
guest ok = yes
writable = yes
browseable = no

[print$]
comment = Printer drivers
path = /home/e-smith/files/samba/printers
guest ok = yes
browseable = yes
writable = no


[Primary]
comment = Primary i-bay


path = /home/e-smith/files/ibays/Primary
read only = no
writable = yes
printable = no
inherit permissions = yes
create mode = 0640






[condivisa]
comment = condivisa


path = /home/e-smith/files/shares/condivisa/files
read only = no
writable = yes
printable = no
inherit permissions = yes
create mode = 0660




# Audit settings
full_audit:prefix = %u|%I|%S
full_audit:failure = connect
full_audit:success = opendir mkdir rmdir open write rename unlink
full_audit:facility = local5
full_audit:priority = notice

[dati-privati]
comment = dati privati


path = /home/e-smith/files/shares/dati-privati/files
read only = no
writable = yes
printable = no
inherit permissions = yes
create mode = 0660




# Audit settings
full_audit:prefix = %u|%I|%S
full_audit:failure = connect
full_audit:success = opendir mkdir rmdir open write rename unlink
full_audit:facility = local5
full_audit:priority = notice

[datipubblici]
comment = dati pubbilici


path = /home/e-smith/files/shares/datipubblici/files
read only = no
writable = yes
printable = no
inherit permissions = yes
create mode = 0660




# Audit settings
full_audit:prefix = %u|%I|%S
full_audit:failure = connect
full_audit:success = opendir mkdir rmdir open write rename unlink
full_audit:facility = local5
full_audit:priority = notice

Ma in messages non compare traccia dei log dele operazioni sui file.

Dietro consiglio di Stefano ho eseguito testparm senza che riscontrasse errori nei file di configurazione ed ho modificato il fragment nel seguente modo:
Code: [Select]
{
    # process all information-bay directories

    use esmith::AccountsDB;
    my $adb = esmith::AccountsDB->open_ro();

    foreach my $share ($adb->get_all_by_prop(type => 'share'))
    {
        if ( ($share->prop('smbAccess') || 'browseable') =~ /browseable$/ ){
            $OUT .= esmith::templates::processTemplate (
                {
                    MORE_DATA => {
                        share => $share,
                    },
                    TEMPLATE_PATH => "/etc/smb.conf/shares",
                    OUTPUT_TYPE => 'string',
                });
        }
        else{
            $OUT .= "# ".$share->key." access is disabled\n";
        }
     $OUT .="# Audit settings
#modifica al precendente
vfs objects = full_audit
#fine modifica
full_audit:prefix = %u|%I|%S
full_audit:failure = connect
full_audit:success = opendir mkdir rmdir open write rename unlink
full_audit:facility = local5
full_audit:priority = notice
"
    }
}

Ora finalmente riesco a vedere i log in messages!
Grazie Stefano!

Prossimo step spostare i log in un file separato, inserirò i progressi di modo da agevolare la vita al prossimo che incapperà nel mio solito problema!

Offline Stefano

  • *
  • 10,894
  • +3/-0
Re: Samba audit
« Reply #1 on: April 11, 2011, 04:20:38 PM »
ciao e benvenuto

al link http://bugs.contribs.org/show_bug.cgi?id=6176 trovi le istruzioni per spostare i log su file separato

ho scritto all'autore del contrib sharedfolders per concertare come attaccare questa feature

per cortesia, "segnati" sullo sticky topic "[OT] dove siamo?", grazie

Offline lerry

  • **
  • 23
  • +0/-0
Re: Samba audit
« Reply #2 on: April 11, 2011, 04:55:34 PM »
Siccome non sono molto avvezzo, i passi da eseguire sono i seguenti, giusto?

aggiungere al file /etc/e-smith/templates/etc/syslog.conf/00filenames

Code: [Select]
$audit = "/var/log/samba/samba_audit";

aggiungere al file /etc/e-smith/templates/etc/syslog.conf/local5

Code: [Select]
local5.notice -{ "${audit}" }

creare la cartella /etc/e-smith/templates/etc/logrotate.d/samba_audit e all'interno il file 10default contenente

Code: [Select]
/var/log/samba/samba_audit \{
   weekly
   missingok
   rotate 7
   postrotate
      /etc/init.d/syslog reload > /dev/null 2>&1 || true
   endscript
   compress
   notifempty
\}

eseguire

Code: [Select]
/sbin/e-smith/expand-template /etc/syslog.conf

eseguire

Code: [Select]
/sbin/e-smith/expand-template /etc/logrotate.d/samba_audit

O sto facendo qualche vaccata?

Grazie della disponibilità!

Offline Stefano

  • *
  • 10,894
  • +3/-0
Re: Samba audit
« Reply #3 on: April 11, 2011, 05:07:14 PM »
O sto facendo qualche vaccata?

quasi :-)

nel senso che le modifiche non le devi fare nei file delle dir sotto /etc/e-smith/templates/, ma devi creare una sottostruttura analoga in /etc/e-smith/templates-custom, copiarci dentro il fragment e modificarlo come abbisogni

in questo modo fai un override delle impostazioni "di fabbrica" e le tue modifiche sopravviveranno ad eventuali aggiornamenti del server..

quindi, per ognuno dei faile coinvolti, crei la rispettiva directory (o struttura di directory) sotto templates-custom..

ti consiglio di leggere il manuale dello sviluppatore, è realmente illuminante in merito