delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2000/09/19/14:54:45

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Date: Tue, 19 Sep 2000 14:50:00 -0400
From: Jason Tishler <Jason DOT Tishler AT dothill DOT com>
To: DJ Delorie <dj AT delorie DOT com>
Cc: cygwin AT sourceware DOT cygnus DOT com
Subject: [PATCH]: setup.exe defaults install scope (was Re: mount points and inetd)
Message-ID: <20000919145000.B18108@DP>
References: <4 DOT 3 DOT 2 DOT 7 DOT 0 DOT 20000917003310 DOT 00bdce30 AT pop> <4 DOT 3 DOT 2 DOT 7 DOT 0 DOT 20000917015958 DOT 00bda100 AT pop DOT bresnanlink DOT net> <004701c0207f$43c91180$f7c723cb AT lifelesswks> <200009182009 DOT QAA21923 AT envy DOT delorie DOT com> <20000919094214 DOT A18108 AT DP> <200009191417 DOT KAA16418 AT envy DOT delorie DOT com>
Mime-Version: 1.0
User-Agent: Mutt/1.2.4i
In-Reply-To: <200009191417.KAA16418@envy.delorie.com>; from dj@delorie.com on Tue, Sep 19, 2000 at 10:17:10AM -0400
Organization: Dot Hill Systems Corp.

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019