...
- Temporary files must be created with unique and unpredictable file names.
- Temporary files must be opened with exclusive access.
- Temporary files must be removed before the program exits.
- The file must be opened with appropriate permissions.
...
- shared locks, provided by
LockFile()
, prohibit all write access to the locked file region while allowing concurrent read access to all processes. - exclusive locks, provided by
LockFileEx()
, grant unrestricted file access to the locking process while denying access to all other processes.
In both cases, the lock is removed by calling UnlockFile()
.
...
It is important to remember to cleanup to allow file names and other resources such as secondary storage to be recycled. In the case of abnormal termination, there is no sure method that can guarantee the removal of orphaned files. For this reason temp , temporary file cleaner utilities, which are invoked manually by a system administrator or periodically run by a daemon to sweep temporary directories and remove old files, are widely used. However, these utilities are themselves vulnerable to file-based exploits, and often require the use of shared directories (see FIO15-A. Do not create temporary files in shared directories). However, during During normal operation, it is the responsibility of the program to ensure that temporary files are removed either explicitly, or through the use of library routines such as tmpfile_s
which guarantee temporary file deletion upon program termination.
...
Wiki Markup |
---|
The Open Group Base Specification Issue 6 \[[Open Group 04|AA. C References#Open Group 04]\] does not specify the permissions the file is created with, so these are [implementation-defined|BB. Definitions#implementation-defined behavior]. However, Issue 7 (that is, POSIX.1-2008) specifies them as {{S_IRUSR\|S_IWUSR}} (0600) \[[Austin Group 08|AA. C References#Austin Group 08]\]. |
...