summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/security.cc
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2003-02-03 15:55:20 +0000
committerCorinna Vinschen <corinna@vinschen.de>2003-02-03 15:55:20 +0000
commit153e83c605ece91e9b7e6b15a30591ca218fb9c9 (patch)
tree6e8caf65d4f144c412e9436dbce61ed7fe0fe8c6 /winsup/cygwin/security.cc
parentf0f3ea68f3b3e3a7b9e21eee2572a0d69ea4d563 (diff)
downloadcygnal-153e83c605ece91e9b7e6b15a30591ca218fb9c9.tar.gz
cygnal-153e83c605ece91e9b7e6b15a30591ca218fb9c9.tar.bz2
cygnal-153e83c605ece91e9b7e6b15a30591ca218fb9c9.zip
* security.h: Add third argument to set_process_privilege.
* autoload.cc: Add OpenThreadToken. * sec_helper.cc (set_process_privilege): Add and use use_thread argument. * security.cc (alloc_sd): Modify call to set_process_privilege. Remember the result in each process. If failed and file owner is not the user, fail.
Diffstat (limited to 'winsup/cygwin/security.cc')
-rw-r--r--winsup/cygwin/security.cc17
1 files changed, 14 insertions, 3 deletions
diff --git a/winsup/cygwin/security.cc b/winsup/cygwin/security.cc
index 617ec4612..224eff438 100644
--- a/winsup/cygwin/security.cc
+++ b/winsup/cygwin/security.cc
@@ -1563,9 +1563,20 @@ alloc_sd (__uid32_t uid, __gid32_t gid, int attribute,
}
owner_sid.debug_print ("alloc_sd: owner SID =");
- /* Must have SE_RESTORE_NAME privilege to change owner */
- if (cur_owner_sid && owner_sid != cur_owner_sid
- && set_process_privilege (SE_RESTORE_NAME) < 0 )
+ /* Try turning privilege on, may not have WRITE_OWNER or WRITE_DAC access.
+ Must have privilege to set different owner, else BackupWrite misbehaves */
+ static int NO_COPY saved_res; /* 0: never, 1: failed, 2 & 3: OK */
+ int res;
+ if (!saved_res || cygheap->user.issetuid ())
+ {
+ res = 2 + set_process_privilege (SE_RESTORE_NAME, true,
+ cygheap->user.issetuid ());
+ if (!cygheap->user.issetuid ())
+ saved_res = res;
+ }
+ else
+ res = saved_res;
+ if (res == 1 && owner_sid != cygheap->user.sid ())
return NULL;
/* Get SID of new group. */