---------------------
PatchSet 6226 
Date: 2004/06/12 19:49:26
Author: serassio
Branch: nt-2_5
Tag: (none) 
Log:
Fixed bugzilla #996: win32_check_group fails when running on PDC

Members: 
	helpers/external_acl/win32_group/readme.txt:1.1.8.8->1.1.8.9 
	helpers/external_acl/win32_group/win32_check_group.c:1.1.8.12->1.1.8.13 

Index: squid/helpers/external_acl/win32_group/readme.txt
===================================================================
RCS file: /cvsroot/squid-sf//squid/helpers/external_acl/win32_group/Attic/readme.txt,v
retrieving revision 1.1.8.8
retrieving revision 1.1.8.9
diff -u -r1.1.8.8 -r1.1.8.9
--- squid/helpers/external_acl/win32_group/readme.txt	4 Apr 2004 08:10:38 -0000	1.1.8.8
+++ squid/helpers/external_acl/win32_group/readme.txt	12 Jun 2004 19:49:26 -0000	1.1.8.9
@@ -80,5 +80,5 @@
 
 --
 Serassio Guido
-guido.serassio@acmeconsulting.it
+squidnt at acmeconsulting dot it
 
Index: squid/helpers/external_acl/win32_group/win32_check_group.c
===================================================================
RCS file: /cvsroot/squid-sf//squid/helpers/external_acl/win32_group/Attic/win32_check_group.c,v
retrieving revision 1.1.8.12
retrieving revision 1.1.8.13
diff -u -r1.1.8.12 -r1.1.8.13
--- squid/helpers/external_acl/win32_group/win32_check_group.c	7 Sep 2003 17:12:50 -0000	1.1.8.12
+++ squid/helpers/external_acl/win32_group/win32_check_group.c	12 Jun 2004 19:49:26 -0000	1.1.8.13
@@ -30,6 +30,9 @@
  *
  * History:
  *
+ * Version 1.20
+ * 13-06-2004 Guido Serassio
+ *              Added support for running on a Domain Controller.
  * Version 1.10
  * 01-05-2003 Guido Serassio
  *              Added option for case insensitive group name comparation.
@@ -341,10 +344,11 @@
     char *domain_qualify;
     char User[256];
 
-    LPCWSTR LclDCptr = NULL;
-    LPCWSTR UsrDCptr = NULL;
-    LPGROUP_USERS_INFO_0 pBuf = NULL;
+    LPWSTR LclDCptr = NULL;
+    LPWSTR UsrDCptr = NULL;
+    LPGROUP_USERS_INFO_0 pUsrBuf = NULL;
     LPGROUP_USERS_INFO_0 pTmpBuf;
+    LPSERVER_INFO_101 pSrvBuf = NULL;
     DWORD dwLevel = 0;
     DWORD dwPrefMaxLen = -1;
     DWORD dwEntriesRead = 0;
@@ -370,10 +374,23 @@
     MultiByteToWideChar(CP_ACP, 0, machinedomain,
 	strlen(machinedomain) + 1, wszLocalDomain, sizeof(wszLocalDomain) / sizeof(wszLocalDomain[0]));
 
-    nStatus = NetGetAnyDCName(
-	NULL,
-	wszLocalDomain,
-	(LPBYTE *) & LclDCptr);
+
+/* Call the NetServerGetInfo function for local computer, specifying level 101. */
+    dwLevel = 101;
+    nStatus = NetServerGetInfo(NULL, dwLevel, (LPBYTE *)&pSrvBuf);
+    
+    if (nStatus == NERR_Success)
+    {
+        /* Check if we are running on a Domain Controller */
+        if ((pSrvBuf->sv101_type & SV_TYPE_DOMAIN_CTRL) ||
+            (pSrvBuf->sv101_type & SV_TYPE_DOMAIN_BAKCTRL))
+        {
+            nStatus = NetApiBufferAllocate(sizeof(pSrvBuf->sv101_name), (LPVOID *) &LclDCptr);
+            wcscpy(LclDCptr, (PCWSTR) pSrvBuf->sv101_name);
+        }
+        else
+            nStatus = NetGetAnyDCName(NULL, wszLocalDomain, (LPBYTE *) & LclDCptr);
+    }
 
     if (nStatus == NERR_Success) {
 	if (strcmp(NTDomain, machinedomain) != 0) {
@@ -385,6 +402,8 @@
 		(LPBYTE *) & UsrDCptr);
 	    if (nStatus != NERR_Success) {
 		fprintf(stderr, "%s Can't find DC for domain %s\n", myname, NTDomain);
+                if (pSrvBuf != NULL)
+                    NetApiBufferFree(pSrvBuf);
 		if (LclDCptr != NULL)
 		    NetApiBufferFree((LPVOID) LclDCptr);
 		if (UsrDCptr != NULL)
@@ -402,10 +421,11 @@
 	     * function should also return the names of the local 
 	     * groups in which the user is indirectly a member.
 	     */
+            dwLevel = 0;
 	    nStatus = NetUserGetGroups(UsrDCptr,
 		wszUserName,
 		dwLevel,
-		(LPBYTE *) & pBuf,
+		(LPBYTE *) & pUsrBuf,
 		dwPrefMaxLen,
 		&dwEntriesRead,
 		&dwTotalEntries);
@@ -413,7 +433,7 @@
 	     * If the call succeeds,
 	     */
 	if (nStatus == NERR_Success) {
-	    if ((pTmpBuf = pBuf) != NULL) {
+	    if ((pTmpBuf = pUsrBuf) != NULL) {
 		for (i = 0; i < dwEntriesRead; i++) {
 		    assert(pTmpBuf != NULL);
 		    if (pTmpBuf == NULL) {
@@ -436,8 +456,10 @@
     /*
      * Free the allocated memory.
      */
-    if (pBuf != NULL)
-        NetApiBufferFree(pBuf);
+    if (pSrvBuf != NULL)
+        NetApiBufferFree(pSrvBuf);
+    if (pUsrBuf != NULL)
+        NetApiBufferFree(pUsrBuf);
     if ((UsrDCptr != NULL) && (UsrDCptr != LclDCptr))
         NetApiBufferFree((LPVOID) UsrDCptr);
     if (LclDCptr != NULL)
