21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

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.

if (!(fd = opendir("."))) break;<br />

if (fstat(dirfd(fd), &f) = = -1) {<br />

closedir(fd);<br />

break;<br />

}<br />

closedir(fd);<br />

if (l.st_mode != f.st_mode || l.st_ino != f.st_ino || l.st_dev != f.st_dev)<br />

break;<br />

if ((f.st_mode & (S_IWOTH | S_IWGRP)) || (f.st_uid && f.st_uid != uid)) {<br />

rc = 0;<br />

break;<br />

}<br />

dir = "..";<br />

if (lstat(dir, &l) = = -1) break;<br />

if (!getcwd(new_dir, PATH_MAX + 1)) break;<br />

} while (new_dir[1]); /* new_dir[0] will always be a slash */<br />

if (!new_dir[1]) rc = 1;<br />

fchdir(dirfd(start));<br />

closedir(start);<br />

return rc;<br />

}<br />

2.5 Erasing Files Securely<br />

<strong>Problem</strong><br />

You want to erase a file securely, preventing recovery of any data via “undelete” tools<br />

or any inspection of the disk for data that has been left behind.<br />

Solution<br />

Write over the data in the file multiple times, varying the data written each time. You<br />

should write both random and patterned data for maximum effectiveness.<br />

Discussion<br />

It is extremely difficult, if not outright impossible, to guarantee that<br />

the contents of a file are completely unrecoverable on modern operating<br />

systems that offer logging filesystems, virtual memory, and other<br />

such features.<br />

Securely deleting files from disk is not as simple as issuing a system call to delete the<br />

file from the filesystem. The first problem is that most delete operations do not do<br />

anything to the data; they merely delete any underlying metadata that the filesystem<br />

uses to associate the file contents with the filename. The storage space where the<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.<br />

Erasing Files Securely | 47

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

Saved successfully!

Ooh no, something went wrong!