592f01e073c572f81e2d60ebc1afd2cf33f82390
[debian/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-2013 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 "root-uid.h"
27 #include <unistd.h>
28
29 #if ! UNLINK_CANNOT_UNLINK_DIR
30
31 /* Return true if we cannot unlink directories, false if we might be
32    able to unlink directories.  */
33
34 bool
35 cannot_unlink_dir (void)
36 {
37   static bool initialized;
38   static bool cannot;
39
40   if (! initialized)
41     {
42 # if defined PRIV_SYS_LINKDIR
43       /* We might be able to unlink directories if we cannot
44          determine our privileges, or if we have the
45          PRIV_SYS_LINKDIR privilege.  */
46       cannot = (priv_set_ismember (PRIV_SYS_LINKDIR) == 0);
47 # else
48       /* In traditional Unix, only root can unlink directories.  */
49       cannot = (geteuid () != ROOT_UID);
50 # endif
51       initialized = true;
52     }
53
54   return cannot;
55 }
56
57 #endif