File: geteuid.cpp

package info (click to toggle)
vdr-plugin-markad 4.2.15-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,084 kB
  • sloc: cpp: 22,441; python: 613; makefile: 270; sh: 95
file content (31 lines) | stat: -rw-r--r-- 775 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "geteuid.h"
#include <iostream>
#include "include_first.h"
#include <windows.h>

bool process_is_elevated(void) {
  HANDLE h = nullptr;

  if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &h)) {
     std::cerr << "OpenProcessToken failed with " << GetLastError() << std::endl;
     if (h) CloseHandle(h);
     return false;
     }

  TOKEN_ELEVATION elevation;
  DWORD dwSize;
  if (!GetTokenInformation(h, TokenElevation, &elevation, sizeof(elevation), &dwSize)) {
     std::cerr << "GetTokenInformation failed with " << GetLastError() << std::endl;
     if (h) CloseHandle(h);
     return false;
     }

  return elevation.TokenIsElevated != 0;
}

int geteuid(void) {
  if (process_is_elevated())
     return 0;

  return 1000; // anything, but non-zero.
}