From cb55867514230d86e2383f0a52ee8d2c6fd6dd7c Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 26 Nov 2003 14:29:22 +0000 Subject: [PATCH] * sec_helper.cc (set_process_privilege): Rename restore_priv to priv_luid. * sec_helper.cc (set_process_privilege): Call LookupPrivilegeValue before opening the token. --- winsup/cygwin/ChangeLog | 10 ++++++++++ winsup/cygwin/sec_helper.cc | 16 ++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index a19126aa1..ad11c505a 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,13 @@ +2003-11-26 Corinna Vinschen + + * sec_helper.cc (set_process_privilege): Rename restore_priv to + priv_luid. + +2003-11-26 Pierre Humblet + + * sec_helper.cc (set_process_privilege): Call LookupPrivilegeValue + before opening the token. + 2003-11-26 Corinna Vinschen * dir.cc (mkdir): Use local security_descriptor. Call diff --git a/winsup/cygwin/sec_helper.cc b/winsup/cygwin/sec_helper.cc index f0b851be8..9d8100431 100644 --- a/winsup/cygwin/sec_helper.cc +++ b/winsup/cygwin/sec_helper.cc @@ -329,11 +329,17 @@ int set_process_privilege (const char *privilege, bool enable, bool use_thread) { HANDLE hToken = NULL; - LUID restore_priv; + LUID priv_luid; TOKEN_PRIVILEGES new_priv, orig_priv; int ret = -1; DWORD size; + if (!LookupPrivilegeValue (NULL, privilege, &priv_luid)) + { + __seterrno (); + goto out; + } + if ((use_thread && !OpenThreadToken (GetCurrentThread (), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, 0, &hToken)) @@ -345,14 +351,8 @@ set_process_privilege (const char *privilege, bool enable, bool use_thread) goto out; } - if (!LookupPrivilegeValue (NULL, privilege, &restore_priv)) - { - __seterrno (); - goto out; - } - new_priv.PrivilegeCount = 1; - new_priv.Privileges[0].Luid = restore_priv; + new_priv.Privileges[0].Luid = priv_luid; new_priv.Privileges[0].Attributes = enable ? SE_PRIVILEGE_ENABLED : 0; if (!AdjustTokenPrivileges (hToken, FALSE, &new_priv,