This is the mail archive of the cygwin-developers@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

mkpasswd and mkgroup patch



Sorry,

I've forgotten the `system' entry for /etc/passwd and
/etc/group. The attached patch replaces the previous patch 
completely. The ChangeLog, too.

Regards,
Corinna

Thu Jun 1 14:17:00 1999  Corinna Vinschen  <corinna@vinschen.de>

        * utils/mkpasswd.c: Changed to output native names of
        well known groups `Everyone' (SID 0) and `system' (SID 18).
        * utils/mkgroup.c: Ditto plus output of native name of
        well known group `None' (SID 513).

-- 
new mail address:
mailto:corinna@vinschen.de
Index: mkpasswd.c
===================================================================
RCS file: /src/cvsroot/winsup-990526/utils/mkpasswd.c,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 mkpasswd.c
--- mkpasswd.c	1999/05/28 19:28:24	1.1.1.1
+++ mkpasswd.c	1999/06/01 13:16:23
@@ -22,6 +22,9 @@
 
 #include <stdio.h>
 
+SID_IDENTIFIER_AUTHORITY sid_world_auth = {SECURITY_WORLD_SID_AUTHORITY};
+SID_IDENTIFIER_AUTHORITY sid_nt_auth = {SECURITY_NT_AUTHORITY};
+
 #ifndef min
 #define min(a,b) (((a)<(b))?(a):(b))
 #endif
@@ -167,9 +170,9 @@ enum_local_groups ()
 	      return 0;
 	    }
 
-	  gid = *GetSidSubAuthority (psid, 1);
+	  gid = *GetSidSubAuthority (psid, *GetSidSubAuthorityCount(psid) - 1);
 
-	  printf ("%s::%ld:0:::\n", localgroup_name, gid);
+	  printf ("%s:*:%ld:%ld:::\n", localgroup_name, gid, gid);
 	}
 
       NetApiBufferFree (buffer);
@@ -208,6 +211,11 @@ main (int argc, char **argv)
   int domain_name_specified = 0;
   int i;
 
+  char name[256], dom[256];
+  DWORD len, len2;
+  PSID sid;
+  SID_NAME_USE use;
+
   if (argc == 1)
     usage ();
 
@@ -243,6 +251,39 @@ main (int argc, char **argv)
       exit (1);
     }
 
+  /*
+   * Get `Everyone' group
+  */
+  if (AllocateAndInitializeSid (&sid_world_auth, 1, SECURITY_WORLD_RID,
+                                0, 0, 0, 0, 0, 0, 0, &sid))
+    {
+      if (LookupAccountSid (NULL, sid,
+                            name, (len = 256, &len),
+                            dom, (len2 = 256, &len),
+                            &use))
+        printf ("%s:*:%d:%d:::\n", name, SECURITY_WORLD_RID, SECURITY_WORLD_RID);
+      FreeSid (sid);
+    }
+
+  /*
+   * Get `system' group
+  */
+  if (AllocateAndInitializeSid (&sid_nt_auth, 1, SECURITY_LOCAL_SYSTEM_RID,
+                                0, 0, 0, 0, 0, 0, 0, &sid))
+    {
+      if (LookupAccountSid (NULL, sid,
+                            name, (len = 256, &len),
+                            dom, (len2 = 256, &len),
+                            &use))
+        printf ("%s:*:%d:%d:::\n", name,
+                                   SECURITY_LOCAL_SYSTEM_RID,
+                                   SECURITY_LOCAL_SYSTEM_RID);
+      FreeSid (sid);
+    }
+
+  if (print_local_groups)
+    enum_local_groups ();
+
   if (print_domain)
     {
       if (domain_name_specified)
@@ -262,9 +303,6 @@ main (int argc, char **argv)
 
   if (print_local)
     enum_users (NULL);
-
-  if (print_local_groups)
-    enum_local_groups ();
 
   return 0;
 }
Index: mkgroup.c
===================================================================
RCS file: /src/cvsroot/winsup-990526/utils/mkgroup.c,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 mkgroup.c
--- mkgroup.c	1999/05/28 19:28:24	1.1.1.1
+++ mkgroup.c	1999/06/01 13:15:16
@@ -16,6 +16,9 @@
 #include <lmaccess.h>
 #include <lmapibuf.h>
 
+SID_IDENTIFIER_AUTHORITY sid_world_auth = {SECURITY_WORLD_SID_AUTHORITY};
+SID_IDENTIFIER_AUTHORITY sid_nt_auth = {SECURITY_NT_AUTHORITY};
+
 #ifndef min
 #define min(a,b) (((a)<(b))?(a):(b))
 #endif
@@ -53,6 +56,70 @@ uni2ansi (LPWSTR wcs, char *mbs)
     *mbs = '\0';
 }
 
+int 
+enum_local_groups ()
+{
+  LOCALGROUP_INFO_0 *buffer;
+  DWORD entriesread = 0;
+  DWORD totalentries = 0;
+  DWORD resume_handle = 0;
+
+  do
+    {
+      DWORD i;
+      DWORD rc = NetLocalGroupEnum (NULL, 0, (LPBYTE *) & buffer, 1024,
+			       &entriesread, &totalentries, &resume_handle);
+
+      switch (rc)
+	{
+	case ERROR_ACCESS_DENIED:
+	  fprintf (stderr, "Access denied\n");
+	  exit (1);
+
+	case ERROR_MORE_DATA:
+	case ERROR_SUCCESS:
+	  break;
+
+	default:
+	  fprintf (stderr, "NetUserEnum() failed with %ld\n", rc);
+	  exit (1);
+	}
+
+      for (i = 0; i < entriesread; i++)
+	{
+	  char localgroup_name[100];
+	  char domain_name[100];
+	  DWORD domname_len = 100;
+	  char psid_buffer[1024];
+	  PSID psid = (PSID) psid_buffer;
+	  DWORD sid_length = 1024;
+	  DWORD gid;
+	  SID_NAME_USE acc_type;
+	  uni2ansi (buffer[i].lgrpi0_name, localgroup_name);
+
+	  if (!LookupAccountName (NULL, localgroup_name, psid,
+				  &sid_length, domain_name, &domname_len,
+				  &acc_type))
+	    {
+	      int code = GetLastError ();
+	      fprintf (stderr, "LookupAccountName(%s) failed with %d\n",
+		       localgroup_name, code);
+	      return 0;
+	    }
+
+	  gid = *GetSidSubAuthority (psid, *GetSidSubAuthorityCount(psid) - 1);
+
+	  printf ("%s::%ld:\n", localgroup_name, gid);
+	}
+
+      NetApiBufferFree (buffer);
+
+    }
+  while (entriesread < totalentries);
+
+  return 0;
+}
+
 void 
 enum_groups (LPWSTR servername)
 {
@@ -126,6 +193,11 @@ main (int argc, char **argv)
   int domain_specified = 0;
   int i;
 
+  char name[256], dom[256];
+  DWORD len, len2;
+  PSID sid, csid;
+  SID_NAME_USE use;
+
   if (argc == 1)
     usage ();
 
@@ -150,6 +222,65 @@ main (int argc, char **argv)
 	    }
 	}
     }
+
+  /*
+   * Get `Everyone' group
+  */
+  if (AllocateAndInitializeSid (&sid_world_auth, 1, SECURITY_WORLD_RID,
+                                0, 0, 0, 0, 0, 0, 0, &sid))
+    {
+      if (LookupAccountSid (NULL, sid,
+                            name, (len = 256, &len),
+                            dom, (len2 = 256, &len),
+                            &use))
+        printf ("%s::%d:\n", name, SECURITY_WORLD_RID);
+      FreeSid (sid);
+    }
+
+  /*
+   * Get `system' group
+  */
+  if (AllocateAndInitializeSid (&sid_nt_auth, 1, SECURITY_LOCAL_SYSTEM_RID,
+                                0, 0, 0, 0, 0, 0, 0, &sid))
+    {
+      if (LookupAccountSid (NULL, sid,
+                            name, (len = 256, &len),
+                            dom, (len2 = 256, &len),
+                            &use))
+        printf ("%s::%d:\n", name, SECURITY_LOCAL_SYSTEM_RID);
+      FreeSid (sid);
+    }
+
+  /*
+   * Get `None' group
+  */
+  GetComputerName (name, (len = 256, &len));
+  csid = (PSID) malloc (1024);
+  LookupAccountName (NULL, name,
+                     csid, (len = 1024, &len),
+                     dom, (len2 = 256, &len),
+                     &use);
+  if (AllocateAndInitializeSid (GetSidIdentifierAuthority (csid),
+                                *GetSidSubAuthorityCount (csid),
+                                *GetSidSubAuthority (csid, 0),
+                                *GetSidSubAuthority (csid, 1),
+                                *GetSidSubAuthority (csid, 2),
+                                *GetSidSubAuthority (csid, 3),
+                                513,
+                                0,
+                                0,
+                                0,
+                                &sid))
+    {
+      if (LookupAccountSid (NULL, sid,
+                            name, (len = 256, &len),
+                            dom, (len2 = 256, &len),
+                            &use))
+        printf ("%s::513:\n", name);
+      FreeSid (sid);
+    }
+  free (csid);
+
   if (print_domain)
     {
       if (domain_specified)
@@ -168,9 +299,7 @@ main (int argc, char **argv)
     }
 
   if (print_local)
-    enum_groups (NULL);
-
-  printf ("Everyone::0:\n");
+    enum_local_groups ();
 
   return 0;
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]