21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Solution<br />

Two basic types of locks exist: advisory and mandatory. Unix supports both advisory<br />

and, to an extremely limited extent, mandatory locks, while Windows supports<br />

only mandatory locks.<br />

Discussion<br />

In the following sections, we will look at the different issues for Unix and Windows.<br />

Locking files on Unix<br />

All modern Unix variants support advisory locks. An advisory lock is a lock in which<br />

the operating system does not enforce the lock. Instead, programs sharing the same<br />

file must cooperate with each other to ensure that locks are properly observed. From<br />

a security perspective, advisory locks are of little use because any program is free to<br />

perform any action on a file regardless of the state of any advisory locks that other<br />

programs may hold on the file.<br />

Support for mandatory locks varies greatly from one Unix variant to another. Both<br />

Linux and Solaris support mandatory locks, but Darwin, FreeBSD, NetBSD, and<br />

OpenBSD do not, even though they export the interface used by Linux and Solaris to<br />

support them. On such systems, this interface creates advisory locks.<br />

Support for mandatory locking does not extend to NFS. In other words, both Linux<br />

and Solaris are capable only of using mandatory locks on local filesystems. Further,<br />

Linux requires that filesystems be mounted with support for mandatory locking,<br />

which is disabled by default. In the end, Solaris is really the only Unix variant on<br />

which you can reasonably expect mandatory locking to work, and even then, relying<br />

on mandatory locks is like playing with fire.<br />

As if the story for mandatory locking on Unix were not bad enough already, it gets<br />

worse. To be able to use mandatory locks on a file, the file must have the setgid bit<br />

enabled and the group execute bit disabled in its permissions. Even if a process holds<br />

a mandatory lock on a file, another process may remove the setgid bit from the file’s<br />

permissions, which effectively turns the mandatory lock into an advisory lock!<br />

Essentially, there is no such thing as a mandatory lock on Unix.<br />

Just to add more fuel to the fire, neither Solaris nor Linux fully or properly implement<br />

the System V defined semantics for mandatory locks, and both systems differ in<br />

where they stray from the System V definitions. The details of the differences are not<br />

important here. We strongly recommend that you avoid the Unix mandatory lock<br />

debacle altogether. If you want to use advisory locking on Unix, then we recommend<br />

using a standalone lock file, as described in Recipe 2.9.<br />

58 | Chapter 2: Access Control<br />

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

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

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

Saved successfully!

Ooh no, something went wrong!