diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2001-04-20 20:36:13 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2001-04-20 20:36:13 +0000 |
commit | 3c8e92d9fc43e7b8c8e5ad4a0235599d7b285274 (patch) | |
tree | 8f851fdf75dc689ad06eab7c8e0c1326811fdb12 /winsup/cygwin/sec_helper.cc | |
parent | b9815dc3dc2e94f94132f098596d0de5f0af1d1c (diff) | |
download | cygnal-3c8e92d9fc43e7b8c8e5ad4a0235599d7b285274.tar.gz cygnal-3c8e92d9fc43e7b8c8e5ad4a0235599d7b285274.tar.bz2 cygnal-3c8e92d9fc43e7b8c8e5ad4a0235599d7b285274.zip |
* security.cc (set_process_privileges): Swap out.
* sec_helper.cc (set_process_privilege): Rename from
`set_process_privileges'. Takes the privilege to enable or disable
as parameter now.
* security.h: Add prototype for `set_process_privileges'.
Diffstat (limited to 'winsup/cygwin/sec_helper.cc')
-rw-r--r-- | winsup/cygwin/sec_helper.cc | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/winsup/cygwin/sec_helper.cc b/winsup/cygwin/sec_helper.cc index 1771d934c..19ab47115 100644 --- a/winsup/cygwin/sec_helper.cc +++ b/winsup/cygwin/sec_helper.cc @@ -397,3 +397,43 @@ got_it: return TRUE; } + +int +set_process_privilege (const char *privilege, BOOL enable) +{ + HANDLE hToken = NULL; + LUID restore_priv; + TOKEN_PRIVILEGES new_priv; + int ret = -1; + + if (!OpenProcessToken (hMainProc, TOKEN_ADJUST_PRIVILEGES, &hToken)) + { + __seterrno (); + 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].Attributes = enable ? SE_PRIVILEGE_ENABLED : 0; + + if (!AdjustTokenPrivileges (hToken, FALSE, &new_priv, 0, NULL, NULL)) + { + __seterrno (); + goto out; + } + + ret = 0; + +out: + if (hToken) + CloseHandle (hToken); + + syscall_printf ("%d = set_process_privilege (%s, %d)",ret, privilege, enable); + return ret; +} |