1 .\" $NetBSD: tmpnam.3,v 1.17 2010/04/30 04:55:10 jruoho Exp $
3 .\" Copyright (c) 1988, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" This code is derived from software contributed to Berkeley by
7 .\" the American National Standards Committee X3, on Information
8 .\" Processing Systems.
10 .\" Redistribution and use in source and binary forms, with or without
11 .\" modification, are permitted provided that the following conditions
13 .\" 1. Redistributions of source code must retain the above copyright
14 .\" notice, this list of conditions and the following disclaimer.
15 .\" 2. Redistributions in binary form must reproduce the above copyright
16 .\" notice, this list of conditions and the following disclaimer in the
17 .\" documentation and/or other materials provided with the distribution.
18 .\" 3. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)tmpnam.3 8.2 (Berkeley) 11/17/93
43 .Nd temporary file routines
51 .Fn tmpnam "char *str"
53 .Fn tempnam "const char *tmpdir" "const char *prefix"
58 returns a pointer to a stream associated with a file descriptor returned
61 The created file is unlinked before
63 returns, causing the file to be automatically deleted when the last
64 reference to it is closed.
65 The file is opened with the access value
71 returns a pointer to a file name, in the
74 did not reference an existing file at some indeterminate point in the
77 is defined in the include file
83 the file name is copied to the buffer it references.
84 Otherwise, the file name is copied to a static buffer.
87 returns a pointer to the file name.
89 The buffer referenced by
91 is expected to be at least
95 is defined in the include file
103 but provides the ability to specify the directory which will
104 contain the temporary file and the file name prefix.
106 The environment variable
108 (if set), the argument
116 are tried, in the listed order, as directories in which to store the
123 is used to specify a file name prefix, which will be the
124 first part of the created file name.
126 allocates memory in which to store the file name; the returned pointer
127 may be used as a subsequent argument to
133 returns a pointer to an open file stream on success, and a
143 return a pointer to a file name on success, and a
151 may fail and set the global variable
153 for any of the errors specified for the library functions
163 for any of the errors specified for the library function
171 for any of the errors specified for the library functions
186 All described functions also conform to
192 functions have been marked as obsolete in the
196 These interfaces are provided for
203 interface is strongly preferred.
204 .Sh SECURITY CONSIDERATIONS
205 There are four important problems with these interfaces (as well as
209 First, there is an obvious race between file name selection and file
210 creation and deletion: the program is typically written to call
215 Subsequently, the program calls
219 and erroneously opens a file (or symbolic link, or fifo or other
220 device) that the attacker has placed in the expected file location.
223 is recommended, since it atomically creates the file.
225 Second, most historic implementations provide only a limited number
226 of possible temporary file names (usually 26) before file names will
227 start being recycled.
230 implementations of these functions (and of
234 system call to determine whether or not the temporary file may be created.
235 This has obvious ramifications for setuid or setgid programs, complicating
236 the portable use of these interfaces in such programs.
237 Finally, there is no specification of the permissions with which the
238 temporary files are created.
240 This implementation of
242 does not have these flaws,
247 only have the first limitation, but portable software
248 cannot depend on that.
251 interface should not be used in software expected to be used on other systems
252 if there is any possibility that the user does not wish the temporary file to
253 be publicly readable and writable.
255 A link-time warning will be issued if
259 is used, and advises the use of