Problems on accessing Windows network resources

Pierre A. Humblet Pierre.Humblet@ieee.org
Tue Jul 15 03:25:00 GMT 2003


Corinna,

As announced, this patch is only about style conformance and 
efficiency. You have already applied the bug fix part.

Pierre

2003-07-15  Pierre Humblet  <pierre.humblet@ieee.org>

	* security.cc (verify_token): Fix white space and style.
	Use type bool instead of BOOL and char. Use alloca
	instead of malloc and free for my_grps. 

-------------- next part --------------
Index: security.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/security.cc,v
retrieving revision 1.148
diff -u -p -r1.148 security.cc
--- security.cc	14 Jul 2003 17:04:21 -0000	1.148
+++ security.cc	15 Jul 2003 01:22:50 -0000
@@ -744,30 +744,26 @@ verify_token (HANDLE token, cygsid &user
 	return gsid == groups.pgsid;
     }

-  PTOKEN_GROUPS my_grps = NULL;
-  BOOL ret = FALSE;
-  char saw_buf[NGROUPS_MAX] = {};
-  char *saw = saw_buf, sawpg = FALSE;
+  PTOKEN_GROUPS my_grps;
+  bool saw_buf[NGROUPS_MAX] = {};
+  bool *saw = saw_buf, sawpg = false, ret = false;

   if (!GetTokenInformation (token, TokenGroups, NULL, 0, &size) &&
       GetLastError () != ERROR_INSUFFICIENT_BUFFER)
     debug_printf ("GetTokenInformation(token, TokenGroups): %E");
-  else if (!(my_grps = (PTOKEN_GROUPS) malloc (size)))
-    debug_printf ("malloc (my_grps) failed.");
+  else if (!(my_grps = (PTOKEN_GROUPS) alloca (size)))
+    debug_printf ("alloca (my_grps) failed.");
   else if (!GetTokenInformation (token, TokenGroups, my_grps, size, &size))
     debug_printf ("GetTokenInformation(my_token, TokenGroups): %E");
   else if (!groups.issetgroups ()) /* setgroups was never called */
-    {
-      ret = sid_in_token_groups (my_grps, groups.pgsid);
-      if (ret == FALSE)
-	ret = (groups.pgsid == tok_usersid);
-    }
+    ret = sid_in_token_groups (my_grps, groups.pgsid)
+          || groups.pgsid == usersid;
   else /* setgroups was called */
     {
       struct __group32 *gr;
       cygsid gsid;
-      if (groups.sgsids.count > (int) sizeof (saw_buf) &&
-	  !(saw = (char *) calloc (groups.sgsids.count, sizeof (char))))
+      if (groups.sgsids.count > (int) (sizeof (saw_buf) / sizeof (*saw_buf))
+	  && !(saw = (bool *) calloc (groups.sgsids.count, sizeof (bool))))
 	goto done;

       /* token groups found in /etc/group match the user.gsids ? */
@@ -776,24 +772,21 @@ verify_token (HANDLE token, cygsid &user
 	  {
 	    int pos = groups.sgsids.position (gsid);
 	    if (pos >= 0)
-	      saw[pos] = TRUE;
+	      saw[pos] = true;
 	    else if (groups.pgsid == gsid)
-	      sawpg = TRUE;
-	   else if (gsid != well_known_world_sid &&
-		    gsid != usersid)
+	      sawpg = true;
+	    else if (gsid != well_known_world_sid
+		     && gsid != usersid)
 	      goto done;
 	  }
       for (int gidx = 0; gidx < groups.sgsids.count; gidx++)
 	if (!saw[gidx])
 	  goto done;
-      if (sawpg ||
-	  groups.sgsids.contains (groups.pgsid) ||
-	  groups.pgsid == usersid)
-	ret = TRUE;
+      ret = sawpg
+	    || groups.sgsids.contains (groups.pgsid)
+	    || groups.pgsid == usersid;
     }
 done:
-  if (my_grps)
-    free (my_grps);
   if (saw != saw_buf)
     free (saw);
   return ret;


More information about the Cygwin-patches mailing list