summaryrefslogtreecommitdiff
path: root/zen/privilege.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:15:16 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:15:16 +0200
commitbd6336c629841c6db3a6ca53a936d629d34db53b (patch)
tree3721ef997864108df175ce677a8a7d4342a6f1d2 /zen/privilege.h
parent4.0 (diff)
downloadFreeFileSync-bd6336c629841c6db3a6ca53a936d629d34db53b.tar.gz
FreeFileSync-bd6336c629841c6db3a6ca53a936d629d34db53b.tar.bz2
FreeFileSync-bd6336c629841c6db3a6ca53a936d629d34db53b.zip
4.1
Diffstat (limited to 'zen/privilege.h')
-rw-r--r--zen/privilege.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/zen/privilege.h b/zen/privilege.h
new file mode 100644
index 00000000..4545aac7
--- /dev/null
+++ b/zen/privilege.h
@@ -0,0 +1,64 @@
+// **************************************************************************
+// * This file is part of the FreeFileSync project. It is distributed under *
+// * GNU General Public License: http://www.gnu.org/licenses/gpl.html *
+// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) *
+// **************************************************************************
+
+#ifndef PRIVILEGE_H_INCLUDED
+#define PRIVILEGE_H_INCLUDED
+
+#include <map>
+#include "zstring.h"
+#include "file_error.h"
+#include "win.h" //includes "windows.h"
+
+namespace zen
+{
+#ifdef FFS_WIN
+class Privileges
+{
+public:
+ static Privileges& getInstance();
+
+ void ensureActive(LPCTSTR privilege) //throw FileError
+ {
+ if (activePrivileges.find(privilege) != activePrivileges.end())
+ return; //privilege already active
+
+ if (privilegeIsActive(privilege)) //privilege was already active before starting this tool
+ activePrivileges.insert(std::make_pair(privilege, false));
+ else
+ {
+ setPrivilege(privilege, true);
+ activePrivileges.insert(std::make_pair(privilege, true));
+ }
+ }
+
+private:
+ Privileges() {}
+ Privileges(Privileges&);
+ void operator=(Privileges&);
+
+ ~Privileges() //clean up: deactivate all privileges that have been activated by this application
+ {
+ for (PrivBuffType::const_iterator i = activePrivileges.begin(); i != activePrivileges.end(); ++i)
+ try
+ {
+ if (i->second)
+ Privileges::setPrivilege(i->first.c_str(), false);
+ }
+ catch (...) {}
+ }
+
+ static bool privilegeIsActive(LPCTSTR privilege); //throw FileError
+ static void setPrivilege(LPCTSTR privilege, bool enable); //throw FileError
+
+ typedef std::map<Zstring, bool> PrivBuffType; //bool: enabled by this application
+
+ PrivBuffType activePrivileges;
+};
+#endif
+}
+
+
+#endif // PRIVILEGE_H_INCLUDED
bgstack15