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.

eset the umask between your adjustment of the umask and any of your file creation<br />

calls, you could potentially create sensitive files with wide-open permissions.<br />

Modifying the umask programmatically is a simple matter of calling the function<br />

umask( ) with the new mask. The return value will be the old umask value. The standard<br />

header file sys/stat.h prototypes the umask( ) function, and it also contains definitions<br />

for a sizable set of macros that map to the various permission bits. Table 2-2<br />

lists the macros, their values in octal, and the permission bit or bits to which each<br />

one corresponds.<br />

Table 2-2. Macros for permission bits and their octal values<br />

Macro Octal value Permission bit(s)<br />

S_IRWXU 0700 Owner read, write, execute<br />

S_IRUSR 0400 Owner read<br />

S_IWUSR 0200 Owner write<br />

S_IXUSR 0100 Owner execute<br />

S_IRWXG 0070 Group read, write, execute<br />

S_IRGRP 0040 Group read<br />

S_IWGRP 0020 Group write<br />

S_IXGRP 0010 Group execute<br />

S_IRWXO 0007 Other/world read, write, execute<br />

S_IROTH 0004 Other/world read<br />

S_IWOTH 0002 Other/world write<br />

S_IXOTH 0001 Other/world execute<br />

umasks are a useful tool for users, allowing them to limit the amount of access others<br />

get to their files. Your program should make every attempt to honor the users’<br />

wishes in this regard, but if extra security is required for files that your application<br />

generates, you should always explicitly set this permission yourself.<br />

See Also<br />

Recipe 2.4<br />

2.8 Locking Files<br />

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

You want to lock files (or portions of them) to prevent two or more processes from<br />

accessing them simultaneously.<br />

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

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

Locking Files | 57

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

Saved successfully!

Ooh no, something went wrong!