[nanny/win32: 53/75] New checker for admin group
- From: Roberto Majadas <telemaco src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nanny/win32: 53/75] New checker for admin group
- Date: Tue, 2 Nov 2010 18:55:24 +0000 (UTC)
commit 780e47fbecc284d62d606fe6e16022189edc3fd4
Author: Roberto Majadas <roberto majadas openshine com>
Date: Fri Oct 22 15:43:30 2010 +0200
New checker for admin group
client/common/src/Utils.py | 32 ++++++++++++++++++++++++++------
1 files changed, 26 insertions(+), 6 deletions(-)
---
diff --git a/client/common/src/Utils.py b/client/common/src/Utils.py
index bb7aa65..35ef0c4 100644
--- a/client/common/src/Utils.py
+++ b/client/common/src/Utils.py
@@ -60,13 +60,33 @@ def ui_magic(object, ui_file, prefix):
except:
print "Something fails at ui_magic"
+def is_win32user_an_admin():
+ WHO_AM_I = "C:\\WINDOWS\\System32\\whoami.exe"
+ if not os.path.exists(WHO_AM_I) :
+ import win32security
+ import ntsecuritycon
+ subAuths = ntsecuritycon.SECURITY_BUILTIN_DOMAIN_RID, \
+ ntsecuritycon.DOMAIN_ALIAS_RID_ADMINS
+ sidAdmins = win32security.SID(ntsecuritycon.SECURITY_NT_AUTHORITY, subAuths)
+ return win32security.CheckTokenMembership(None, sidAdmins)
+ else:
+ import subprocess
+
+ p = subprocess.Popen([WHO_AM_I, "/GROUPS", "/SID"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ if p.wait () != 0 :
+ p = subprocess.Popen([WHO_AM_I, "/GROUPS"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ if p.wait () != 0 :
+ return False
+
+ for line in p.stdout.readlines() :
+ if "S-1-5-32-544 " in line or "S-1-5-32-544\r\n" in line :
+ return True
+
+ return False
+
+
def check_win32_admin():
- import win32security
- import ntsecuritycon
- subAuths = ntsecuritycon.SECURITY_BUILTIN_DOMAIN_RID, \
- ntsecuritycon.DOMAIN_ALIAS_RID_ADMINS
- sidAdmins = win32security.SID(ntsecuritycon.SECURITY_NT_AUTHORITY, subAuths)
- if win32security.CheckTokenMembership(None, sidAdmins) == False:
+ if is_win32user_an_admin() == False:
msg = gtk.MessageDialog(parent=None, flags=0,
type=gtk.MESSAGE_INFO,
buttons=gtk.BUTTONS_CLOSE, message_format=None)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]