From 5ae2d3ef36c367d4c65a38792247975f580c8e44 Mon Sep 17 00:00:00 2001 From: David Bartley Date: Sat, 7 Mar 2009 13:10:17 -0500 Subject: [PATCH] Add restore_unlink_dir function for restoring PRIV_SYS_LINKDIR on Solaris. --- ChangeLog | 7 ++++++ lib/unlinkdir.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++------ lib/unlinkdir.h | 6 +++- 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4f87a95..acb1dc8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-03-07 David Bartley + + Add restore_unlink_dir function for restoring PRIV_SYS_LINKDIR on + Solaris. + * lib/unlinkdir.c: Add restore_unlink_dir. + * lib/unlinkdir.h: Likewise. + 2009-03-07 Bruno Haible Tests for module 'uninorm/u32-normcoll'. diff --git a/lib/unlinkdir.c b/lib/unlinkdir.c index 9c3ff00..1e8ff69 100644 --- a/lib/unlinkdir.c +++ b/lib/unlinkdir.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -/* Written by Paul Eggert and Jim Meyering. */ +/* Written by Paul Eggert, Jim Meyering, and David Bartley. */ #include @@ -28,6 +28,11 @@ #if ! UNLINK_CANNOT_UNLINK_DIR +static bool initialized; +# if defined PRIV_EFFECTIVE && defined PRIV_SYS_LINKDIR +static bool had_sys_linkdir; +#endif + /* Return true if we cannot unlink directories, false if we might be able to unlink directories. If possible, tell the kernel we don't want to be able to unlink directories, so that we can return true. @@ -39,7 +44,6 @@ bool cannot_unlink_dir (void) { - static bool initialized; static bool cannot; if (! initialized) @@ -51,11 +55,15 @@ cannot_unlink_dir (void) priv_set_t *pset = priv_allocset (); if (pset) { - cannot = - (getppriv (PRIV_EFFECTIVE, pset) == 0 - && (! priv_ismember (pset, PRIV_SYS_LINKDIR) - || (priv_delset (pset, PRIV_SYS_LINKDIR) == 0 - && setppriv (PRIV_SET, PRIV_EFFECTIVE, pset) == 0))); + if (getppriv (PRIV_EFFECTIVE, pset) == 0) + { + if (priv_ismember (pset, PRIV_SYS_LINKDIR)) + cannot = had_sys_linkdir = + (priv_delset (pset, PRIV_SYS_LINKDIR) == 0 + && setppriv (PRIV_SET, PRIV_EFFECTIVE, pset) == 0); + else + cannot = true; + } priv_freeset (pset); } # else @@ -68,4 +76,38 @@ cannot_unlink_dir (void) return cannot; } + +/* Return true if the kernel restored the ability of unlink to remove + directories. */ + +bool +restore_unlink_dir (void) +{ + bool restored = false; + +# if defined PRIV_EFFECTIVE && defined PRIV_SYS_LINKDIR + if (initialized) + { + /* Try to re-add the PRIV_SYS_LINKDIR privilege, but only if we + previously removed it. */ + if (had_sys_linkdir) + { + priv_set_t *pset = priv_allocset (); + if (pset) + { + if (getppriv (PRIV_EFFECTIVE, pset) == 0) + { + initialized = ! (priv_addset (pset, PRIV_SYS_LINKDIR) == 0 + && setppriv (PRIV_SET, PRIV_EFFECTIVE, pset) == 0); + } + } + priv_freeset (pset); + restored = ! initialized; + } + } +# endif + + return restored; +} + #endif diff --git a/lib/unlinkdir.h b/lib/unlinkdir.h index 10c4e5f..86cbd68 100644 --- a/lib/unlinkdir.h +++ b/lib/unlinkdir.h @@ -1,6 +1,6 @@ /* unlinkdir.h - determine (and maybe change) whether we can unlink directories - Copyright (C) 2005 Free Software Foundation, Inc. + Copyright (C) 2005, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,12 +15,14 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -/* Written by Paul Eggert and Jim Meyering. */ +/* Written by Paul Eggert, Jim Meyering, and David Bartley. */ #include #if UNLINK_CANNOT_UNLINK_DIR # define cannot_unlink_dir() true +# define restore_unlink_dir() false #else bool cannot_unlink_dir (void); +bool restore_unlink_dir (void); #endif -- 1.5.6.5