diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2000-10-22 14:13:30 +0400 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2000-10-22 14:13:30 +0400 |
commit | b150b20cfdc34fc2d738b0a935e26738ef630bc3 (patch) | |
tree | 1423ca2acc62d7e60725c208bdbe6c7c869149df /winsup/cygwin/security.cc | |
parent | 5693c8d55b17578934c59013ea440f8a2056d915 (diff) |
* pinfo.cc (pinfo_init): Eliminate call to `set_process_privileges'.
* security.cc (write_sd): Call `set_process_privileges' on the first
call to `write_sd'.
(set_process_privileges): Eliminate adjusting SE_BACKUP_NAME privilege.
Diffstat (limited to 'winsup/cygwin/security.cc')
-rw-r--r-- | winsup/cygwin/security.cc | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/winsup/cygwin/security.cc b/winsup/cygwin/security.cc index 10379b66f..0df0c09c2 100644 --- a/winsup/cygwin/security.cc +++ b/winsup/cygwin/security.cc @@ -540,6 +540,14 @@ write_sd(const char *file, PSECURITY_DESCRIPTOR sd_buf, DWORD sd_size) return -1; } + /* No need to be thread save. */ + static BOOL first_time = TRUE; + if (first_time) + { + set_process_privileges (); + first_time = FALSE; + } + HANDLE fh; fh = CreateFile (file, WRITE_OWNER | WRITE_DAC, @@ -604,14 +612,10 @@ set_process_privileges () { HANDLE hToken = NULL; LUID restore_priv; - LUID backup_priv; - char buf[sizeof (TOKEN_PRIVILEGES) + 2 * sizeof (LUID_AND_ATTRIBUTES)]; - TOKEN_PRIVILEGES *new_priv = (TOKEN_PRIVILEGES *) buf; + TOKEN_PRIVILEGES new_priv; int ret = -1; - if (! OpenProcessToken (hMainProc, - TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, - &hToken)) + if (! OpenProcessToken (hMainProc, TOKEN_ADJUST_PRIVILEGES, &hToken)) { __seterrno (); goto out; @@ -622,19 +626,12 @@ set_process_privileges () __seterrno (); goto out; } - if (! LookupPrivilegeValue (NULL, SE_BACKUP_NAME, &backup_priv)) - { - __seterrno (); - goto out; - } - new_priv->PrivilegeCount = 2; - new_priv->Privileges[0].Luid = restore_priv; - new_priv->Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; - new_priv->Privileges[1].Luid = backup_priv; - new_priv->Privileges[1].Attributes = SE_PRIVILEGE_ENABLED; + new_priv.PrivilegeCount = 1; + new_priv.Privileges[0].Luid = restore_priv; + new_priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; - if (! AdjustTokenPrivileges (hToken, FALSE, new_priv, 0, NULL, NULL)) + if (! AdjustTokenPrivileges (hToken, FALSE, &new_priv, 0, NULL, NULL)) { __seterrno (); goto out; @@ -642,9 +639,6 @@ set_process_privileges () ret = 0; - if (ret == -1) - __seterrno (); - out: if (hToken) CloseHandle (hToken); |