delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/2003/03/25/14:41:02

Mailing-List: contact cygwin-developers-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-developers-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin-developers/>
List-Post: <mailto:cygwin-developers AT cygwin DOT com>
List-Help: <mailto:cygwin-developers-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-developers-owner AT cygwin DOT com
Delivered-To: mailing list cygwin-developers AT cygwin DOT com
Message-ID: <3E80B0CB.6000001@hekimian.com>
Date: Tue, 25 Mar 2003 14:40:59 -0500
X-Sybari-Trust: 1d8b5db3 36b09be0 04609a3e 00000109
From: Joe Buehler <jbuehler AT hekimian DOT com>
Reply-To: jbuehler AT hekimian DOT com
Organization: Spirent Communications, Inc.
User-Agent: Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:1.3) Gecko/20030312
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Cygwin Developers <cygwin-developers AT cygwin DOT com>
Subject: [PATCH] performance patch for /proc/registry
X-Enigmail-Version: 0.73.1.0
X-Enigmail-Supports: pgp-inline, pgp-mime

This patch provides a drastic performance improvement for /proc/registry
access (at least on the NT machines I use at work).

On an NT machine running SP5, an "ls -l" on
/proc/registry/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services
returns in 0.25 seconds now.  Without the patch, I killed it after
7 minutes because I got tired of waiting for it to finish.

I do not have a lot of experience at writing Windows software -- please
proofread this carefully.

2003-03-25  Joe Buehler  <jhpb AT draco DOT hekimian DOT com>

	* autoload.cc: added RegGetKeySecurity()
	* security.cc (get_nt_object_attribute): use RegGetKeySecurity() for performance.

Index: autoload.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/autoload.cc,v
retrieving revision 1.65
diff -u -r1.65 autoload.cc
--- autoload.cc	13 Mar 2003 22:53:15 -0000	1.65
+++ autoload.cc	25 Mar 2003 19:28:24 -0000
@@ -375,6 +373,7 @@
  LoadDLLfunc (SetSecurityDescriptorGroup, 12, advapi32)
  LoadDLLfunc (SetSecurityDescriptorOwner, 12, advapi32)
  LoadDLLfunc (SetTokenInformation, 16, advapi32)
+LoadDLLfunc (RegGetKeySecurity, 16, advapi32)

  LoadDLLfunc (NetApiBufferFree, 4, netapi32)
  LoadDLLfuncEx (NetGetDCName, 12, netapi32, 1)
Index: security.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/security.cc,v
retrieving revision 1.141
diff -u -r1.141 security.cc
--- security.cc	19 Mar 2003 21:34:38 -0000	1.141
+++ security.cc	25 Mar 2003 19:29:57 -0000
@@ -1443,20 +1443,81 @@
    PSECURITY_DESCRIPTOR psd = NULL;
    cygpsid owner_sid;
    cygpsid group_sid;
-  PACL acl;
+  PACL acl = NULL;

-  if (ERROR_SUCCESS != GetSecurityInfo (handle, object_type,
-					DACL_SECURITY_INFORMATION |
-					GROUP_SECURITY_INFORMATION |
-					OWNER_SECURITY_INFORMATION,
-					(PSID *) &owner_sid,
-					(PSID *) &group_sid,
-					&acl, NULL, &psd))
-    {
-      __seterrno ();
-      debug_printf ("GetSecurityInfo %E");
-      return -1;
-    }
+  if (object_type == SE_REGISTRY_KEY) {
+	// use different code for registry handles, for performance reasons
+	char sd_buf[4096];
+	PSECURITY_DESCRIPTOR psd2 = (PSECURITY_DESCRIPTOR)&sd_buf[0];
+	DWORD len = sizeof(sd_buf);
+	if (ERROR_SUCCESS != RegGetKeySecurity(
+			(HKEY)handle,
+			DACL_SECURITY_INFORMATION |
+			GROUP_SECURITY_INFORMATION |
+			OWNER_SECURITY_INFORMATION,
+			psd2,
+			&len
+			))
+	{
+		__seterrno ();
+		debug_printf ("RegGetKeySecurity %E");
+		return -1;
+	}
+
+	BOOL bDaclPresent;
+	BOOL bDaclDefaulted;
+	if (!GetSecurityDescriptorDacl(
+			psd2,
+			&bDaclPresent,
+			&acl,
+			&bDaclDefaulted
+			))
+	{
+		__seterrno ();
+		debug_printf ("GetSecurityDescriptorDacl %E");
+		return -1;
+	}
+	if (!bDaclPresent) {
+		acl = NULL;
+	}
+
+	BOOL bGroupDefaulted;
+	if (!GetSecurityDescriptorGroup(
+			psd2,
+			(PSID *)&group_sid,
+			&bGroupDefaulted
+			))
+	{
+		__seterrno ();
+		debug_printf ("GetSecurityDescriptorGroup %E");
+		return -1;
+	}
+
+	BOOL bOwnerDefaulted;
+	if (!GetSecurityDescriptorOwner(
+			psd2,
+			(PSID *)&owner_sid,
+			&bOwnerDefaulted
+			))
+	{
+		__seterrno ();
+		debug_printf ("GetSecurityDescriptorOwner %E");
+		return -1;
+	}
+  } else {
+	if (ERROR_SUCCESS != GetSecurityInfo (handle, object_type,
+					  DACL_SECURITY_INFORMATION |
+					  GROUP_SECURITY_INFORMATION |
+					  OWNER_SECURITY_INFORMATION,
+					  (PSID *) &owner_sid,
+					  (PSID *) &group_sid,
+					  &acl, NULL, &psd))
+	  {
+		__seterrno ();
+		debug_printf ("GetSecurityInfo %E");
+		return -1;
+	  }
+  }

    __uid32_t uid;
    __gid32_t gid;
-- 
Joe Buehler

- Raw text -


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