Mail Archives: cygwin/2000/09/19/14:54:45
DJ,
On Tue, Sep 19, 2000 at 10:17:10AM -0400, DJ Delorie wrote:
>
> > I can provide you with a "patch" (i.e., code snippets) that tests whether
> > or not the current user is a member of the Administrators group. Is this
> > the kind of test for which you are looking?
>
> Yes, but a patch against setup's cvs sources would be best.
OK, you shamed me into it. If I remember correctly, you preferred inline...
ChangeLog:
Tue Sep 19 14:25:23 2000 Jason Tishler <jt AT dothill DOT com>
* root.cc (is_admin): New function.
* root.cc (read_mount_table): Check for administrative priviledges and
set installation scope as appropriate.
Patch:
Index: root.cc
===================================================================
RCS file: /cvs/src/src/winsup/cinstall/root.cc,v
retrieving revision 2.2
diff -u -p -r2.2 root.cc
--- root.cc 2000/09/07 03:09:30 2.2
+++ root.cc 2000/09/19 18:24:12
@@ -59,6 +59,60 @@ save_dialog (HWND h)
root_dir = eget (h, IDC_ROOT_DIR, root_dir);
}
+/*
+ * is_admin () determines whether or not the current user is a member of the
+ * Administrators group. On Windows 9X, the current user is considered an
+ * Administrator by definition.
+ */
+
+static int
+is_admin ()
+{
+ // Windows 9X users are considered Administrators by definition
+ OSVERSIONINFO verinfo;
+ verinfo.dwOSVersionInfoSize = sizeof (verinfo);
+ GetVersionEx (&verinfo);
+ if (verinfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
+ return 1;
+
+ // Get the process token for the current process
+ HANDLE token;
+ BOOL status = OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &token);
+ if (!status)
+ return 0;
+
+ // Get the group token information
+ UCHAR token_info[1024];
+ PTOKEN_GROUPS groups = (PTOKEN_GROUPS) token_info;
+ DWORD token_info_len = sizeof (token_info);
+ status = GetTokenInformation (token, TokenGroups, token_info, token_info_len, &token_info_len);
+ CloseHandle(token);
+ if (!status)
+ return 0;
+
+ // Create the Administrators group SID
+ PSID admin_sid;
+ SID_IDENTIFIER_AUTHORITY authority = SECURITY_NT_AUTHORITY;
+ status = AllocateAndInitializeSid (&authority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &admin_sid);
+ if (!status)
+ return 0;
+
+ // Check to see if the user is a member of the Administrators group
+ status = 0;
+ for (UINT i=0; i<groups->GroupCount; i++) {
+ if (EqualSid(groups->Groups[i].Sid, admin_sid)) {
+ status = 1;
+ break;
+ }
+ }
+
+ // Destroy the Administrators group SID
+ FreeSid (admin_sid);
+
+ // Return whether or not the user is a member of the Administrators group
+ return status;
+}
+
static void
read_mount_table ()
{
@@ -83,7 +137,7 @@ read_mount_table ()
windir[2] = 0;
root_dir = concat (windir, "\\cygwin", 0);
root_text = IDC_ROOT_BINARY;
- root_scope = IDC_ROOT_USER;
+ root_scope = (is_admin()) ? IDC_ROOT_SYSTEM : IDC_ROOT_USER;
}
}
Jason
--
Jason Tishler
Director, Software Engineering Phone: +1 (732) 264-8770 x235
Dot Hill Systems Corporation Fax: +1 (732) 264-8798
82 Bethany Road, Suite 7 Email: Jason DOT Tishler AT dothill DOT com
Hazlet, NJ 07730 USA WWW: http://www.dothill.com
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com
- Raw text -