]> git.cworth.org Git - tar/blob - gnu/unlinkdir.c
upstream: Fix extraction of device nodes.
[tar] / gnu / unlinkdir.c
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* unlinkdir.c - determine whether we can unlink directories
4
5    Copyright (C) 2005-2006, 2009-2010 Free Software Foundation, Inc.
6
7    This program is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 /* Written by Paul Eggert, Jim Meyering, and David Bartley.  */
21
22 #include <config.h>
23
24 #include "unlinkdir.h"
25 #include "priv-set.h"
26 #include <unistd.h>
27
28 #if ! UNLINK_CANNOT_UNLINK_DIR
29
30 /* Return true if we cannot unlink directories, false if we might be
31    able to unlink directories.  */
32
33 bool
34 cannot_unlink_dir (void)
35 {
36   static bool initialized;
37   static bool cannot;
38
39   if (! initialized)
40     {
41 # if defined PRIV_SYS_LINKDIR
42       /* We might be able to unlink directories if we cannot
43          determine our privileges, or if we have the
44          PRIV_SYS_LINKDIR privilege.  */
45       cannot = (priv_set_ismember (PRIV_SYS_LINKDIR) == 0);
46 # else
47       /* In traditional Unix, only root can unlink directories.  */
48       cannot = (geteuid () != 0);
49 # endif
50       initialized = true;
51     }
52
53   return cannot;
54 }
55
56 #endif