11.04.2013 Views

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

sum<br />

cksum<br />

md5sum<br />

sha1sum<br />

Capitolo 12. Filtri, programmi e coman<strong>di</strong> esterni<br />

Sono utility per creare le checksum. Una checksum è un numero ricavato con un calcolo matematico<br />

eseguito sul contenuto <strong>di</strong> un file, con lo scopo <strong>di</strong> verificarne l’integrità. Uno script potrebbe<br />

verificare un elenco <strong>di</strong> checksum a fini <strong>di</strong> sicurezza, per esempio per assicurarsi che il contenuto <strong>di</strong><br />

in<strong>di</strong>spensabili file <strong>di</strong> sistema non sia stato mo<strong>di</strong>ficato o corrotto. Per applicazioni <strong>di</strong> sicurezza, si<br />

dovrebbe utilizzare il comando md5sum a 128-bit (message <strong>di</strong>gest 5 checksum) o, ancor meglio, il<br />

nuovissimo sha1sum (Secure Hash Algorithm).<br />

bash$ cksum /boot/vmlinuz<br />

1670054224 804083 /boot/vmlinuz<br />

bash$ echo -n "Top Secret" | cksum<br />

3391003827 10<br />

bash$ md5sum /boot/vmlinuz<br />

0f43eccea8f09e0a0b2b5cf1dcf333ba /boot/vmlinuz<br />

bash$ echo -n "Top Secret" | md5sum<br />

8babc97a6f62a4649716f4df8d61728f -<br />

Nota: Il comando cksum visualizza anche la <strong>di</strong>mensione, in byte, del suo riferimento. sia esso<br />

un file o lo stdout.<br />

I coman<strong>di</strong> md5sum e sha1sum visualizzano un trattino quando l’input proviene dallo stdout.<br />

Esempio 12-34. Verificare l’integrità dei file<br />

#!/bin/bash<br />

# file-integrity.sh: Verifica se i file <strong>di</strong> una data <strong>di</strong>rectory<br />

# sono stati mo<strong>di</strong>ficati senza autorizzazione.<br />

E_DIR_ERRATA=70<br />

E_ERR_DBFILE=71<br />

dbfile=File_record.md5<br />

# Nome del file che contiene le registrazioni (file database).<br />

crea_database ()<br />

{<br />

echo ""$<strong>di</strong>rectory"" > "$dbfile"<br />

289

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!