Bugtraq mailing list archives

Re: mktemp() and friends


From: scoile () patriot net (Steve \)
Date: Tue, 24 Dec 1996 10:42:43 -0500


Here's what I'd like to see in a routine that creates and opens temporary
files:

+ Atomic operation, like mkstemp, where one routine names, creates,
  and opens the file.

+ Something that accepts the new file's modes, unlike mkstemp, so that
  we don't have to go through the following three step process to ensure
  that the file is empty before we use a file created with 0666:

      mkstemp
      chmod
      ftruncate

+ Something that relocates relative file specifications to another
  location.  For instance, why not have the function use the TMP or
  TEMP environment variables to determine what directory to place the
  temporary file in if the file is given as a relative path (default to
  /tmp if TMP and TEMP are undefined)?  Or, why not have the function
  use a system-provided directory template.  This would give system
  management the ability to relocate temporary files without having to
  inform the users or update programs.

  For instance, if a system manager prefers that all temporary files
  be located in directories under /tmp named after the user (or euid)
  creating them, such a guideline would be built into this routine.
  What would be really cool is if it could be a modifiable parameter,
  perhaps specified at boot-time.

So, suppose we call the new routine nmkstmp:

  int *nmkstmp(char *template,int modes);

if (template[0] == '/')
        tmpname = template;
else
{

        /* We might have things in here that do the following:
        /*
        /* + If TMP or TEMP environment variables are defined, use one
        /*   of them as the directory.
        /*
        /* + If the effective user ID is less than 100 (i.e. a system
        /*   account), we look to see whether the user has a directory
        /*   named "tmp" (or, if TMP or TEMP was relative in the above,
        /*   we might use that as the name of the directory to look for)
        /*   in their home directory and use it if it exists.  We might
        /*   also do this for all users.
        /*
        /* + If there exists a directory in the system temporary directory
        /*   (e.g.  /tmp) named after and owned by the user specified
        /*   by the effective user ID, use that directory.
        /*
        /* + If all else fails, simply use /tmp as the directory.
        */

        /* Combine the directory and name template giving a new template. */
}
/* Continue as normal. */

--
    Steve Coile           P a t r i o t  N e t      Systems Engineering
 scoile () patriot net      Patriot Computer Group        (703) 277-7737



Current thread: