Skip to content
Snippets Groups Projects
Commit dce543df authored by Juhász Bálint's avatar Juhász Bálint
Browse files

privileges work & TODO: header guard doesn't work

parent ccdb796d
Branches
No related tags found
No related merge requests found
......@@ -7,14 +7,17 @@
//
// Compile time OS flags
//
enum OS_TYPE {OS_WINDOWS, OS_LINUX, OS_OSX};
enum OS_TYPE {OS_WINDOWS, OS_LINUX, OS_OSX, OS_UNKNOWN};
#if defined(Q_OS_WIN)
enum OS_TYPE CURRENT_OS = OS_WINDOWS;
constexpr enum OS_TYPE CURRENT_OS = OS_WINDOWS;
#include <windows.h>
#elif defined(Q_OS_LINUX)
enum OS_TYPE CURRENT_OS = OS_LINUX;
constexpr enum OS_TYPE CURRENT_OS = OS_LINUX;
#elif defined(Q_OS_OSX)
enum OS_TYPE CURRENT_OS = OS_OSX;
constexpr enum OS_TYPE CURRENT_OS = OS_OSX;
#else
constexpr enum OS_TYPE CURRENT_OS = OS_UNKNOWN;
#endif
//
......
......@@ -3,7 +3,7 @@
#include <QImage>
#include "NetCheckerWindow.hpp"
//#include "Diagnostic.hpp"
#include "Privileges.hpp"
#include "Translation.hpp"
NetCheckerWindow::NetCheckerWindow(){
......@@ -235,6 +235,11 @@ void NetCheckerWindow::initText(){
}
void NetCheckerWindow::nextPage(){
/* check for root privileges */
if (!Privileges::checkPrivileges(this, TXT_ROOT_MSG_TITLE_WIN[lang], TXT_ROOT_MSG_WIN[lang])){
close();
}
/* turns page */
global_w->setCurrentIndex(1);
......
......@@ -17,5 +17,13 @@ QString TXT_LOG_GROUP[] = { "Log", "Napló" };
QString TXT_CLIPB_BTN[] = { "Copy to clipboard", "Másolás vágólapra" };
QString TXT_SAVE_BTN[] = { "Save to file...", "Mentés fájlba..." };
QString TXT_SAVE_DIALOG[] = { "Save to...", "Mentés helye..." };
QString TXT_ROOT_MSG_TITLE_WIN[] ={
"Diagnostics cannot start",
"A diagnosztika nem indítható"
};
QString TXT_ROOT_MSG_WIN[] ={
"Administrator privileges are needed to gather informations.",
"A program helyes működéséhez rendszergazdai jogosultság szükséges."
};
#endif
#include <QString>
#include <QMessageBox>
#ifndef PRIVILEGES_HPP
#define PRIVILEGES_HPP
struct Privileges {
static bool checkPrivileges(QWidget *parent, const QString title, const QString message){
bool (*isRoot)();
// TODO: isRoot_linux, isRoot_osx
if (!isRoot_win()){
QMessageBox::warning(parent, title, message, QMessageBox::Ok, QMessageBox::NoButton);
return false;
}
return true;
}
static bool isRoot_win(){
BOOL fRet = FALSE;
HANDLE hToken = NULL;
if( OpenProcessToken( GetCurrentProcess( ),TOKEN_QUERY,&hToken ) ) {
TOKEN_ELEVATION Elevation;
DWORD cbSize = sizeof( TOKEN_ELEVATION );
if( GetTokenInformation( hToken, TokenElevation, &Elevation, sizeof( Elevation ), &cbSize ) ) {
fRet = Elevation.TokenIsElevated;
}
}
if( hToken ) {
CloseHandle( hToken );
}
return fRet;
}
};
#endif // PRIVILEGES_HPP
......@@ -8,7 +8,8 @@ HEADERS = \
include/Diagnostic.hpp \
include/Translation.hpp \
include/ProcessHandler.hpp \
include/Globals.hpp
include/Globals.hpp \
include/Privileges.hpp
SOURCES = \
main.cpp \
include/NetCheckerWindow.cpp \
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.4.2, 2015-08-10T22:01:08. -->
<!-- Written by QtCreator 3.4.2, 2015-08-11T13:30:51. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment