Use unlink () and close () to create a secure temporary file

Source: Internet
Author: User

You can use POSIX (Portable Operating System Interface) standard file operation functions to create secure temporary files:

  1. Use open () to create a temporary file.
  2. Call unlink () to delete the file immediately. The temporary file will be removed from the current directory. However, inode will wait until all opened file descriptors are closed (reference count = 0) is deleted. Previously, it became an orphan (orphan inode) and the file cannot be viewed using ls or du. However, you can still know the existence of the file by running DF on the file system.
  3. Call close () to close the file after use, so that the file will completely disappear in the file system.

Temporary files created in this way have the following security:

  1. If the program crashes, the operating system will close all files opened by the program. The temporary file will disappear when it is closed, and will not remain in the file system.
  2. Users cannot access this file, so they cannot monitor and filter the content.

Of course, there are other methods: encryption, multiple overwriting of the file storage area to prevent data recovery, and so on. Alternatively, you can combine multiple methods to meet high security requirements.

Sample Code unlink_before_close.c

Compile and execute:

$ Gcc-O unlink_before_close unlink_before_close.c $./unlink_before_close

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.