* mkgroup.c (load_netapi): New function to load netapi32.dll functions
dynamically so that mkgroup works on 9x/ME as well.
        Use corresponding function pointers throughout.
        (usage): Change to `int'. Change text to be conformant to mkpasswd.
        (main): Use `getlongopt' to process options.
        Special handling to create a group entry on 9x/ME.
        * mkpasswd.c (load_netapi): New function to load netapi32.dll functions
        dynamically so that mkpasswd works on 9x/ME as well.
        Use corresponding function pointers throughout.
        (usage): Change to `int'. Change text to be conformant to mkgroup.
        (main): Use `getlongopt' to process options.
        Special handling to create a passwd entry on 9x/ME.
        Change conditional to create an entry for the local administrators
        group when appropriate.
			
			
This commit is contained in:
		| @@ -1,3 +1,20 @@ | |||||||
|  | Wed Nov  8 15:52:00 2000  Corinna Vinschen <corinna@vinschen.de> | ||||||
|  |  | ||||||
|  | 	* mkgroup.c (load_netapi): New function to load netapi32.dll functions | ||||||
|  | 	dynamically so that mkgroup works on 9x/ME as well. | ||||||
|  | 	Use corresponding function pointers throughout. | ||||||
|  | 	(usage): Change to `int'. Change text to be conformant to mkpasswd. | ||||||
|  | 	(main): Use `getlongopt' to process options. | ||||||
|  | 	Special handling to create a group entry on 9x/ME. | ||||||
|  | 	* mkpasswd.c (load_netapi): New function to load netapi32.dll functions | ||||||
|  | 	dynamically so that mkpasswd works on 9x/ME as well. | ||||||
|  | 	Use corresponding function pointers throughout. | ||||||
|  | 	(usage): Change to `int'. Change text to be conformant to mkgroup. | ||||||
|  | 	(main): Use `getlongopt' to process options. | ||||||
|  | 	Special handling to create a passwd entry on 9x/ME. | ||||||
|  | 	Change conditional to create an entry for the local administrators | ||||||
|  | 	group when appropriate. | ||||||
|  |  | ||||||
| Thu Nov  2  2:01:00 2000  Corinna Vinschen <corinna@vinschen.de> | Thu Nov  2  2:01:00 2000  Corinna Vinschen <corinna@vinschen.de> | ||||||
|  |  | ||||||
| 	* kill.cc (main): Return 1 in case of errors. | 	* kill.cc (main): Return 1 in case of errors. | ||||||
|   | |||||||
| @@ -14,16 +14,42 @@ | |||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <windows.h> | #include <windows.h> | ||||||
| #include <sys/cygwin.h> | #include <sys/cygwin.h> | ||||||
|  | #include <getopt.h> | ||||||
| #include <lmaccess.h> | #include <lmaccess.h> | ||||||
| #include <lmapibuf.h> | #include <lmapibuf.h> | ||||||
|  |  | ||||||
| SID_IDENTIFIER_AUTHORITY sid_world_auth = {SECURITY_WORLD_SID_AUTHORITY}; | SID_IDENTIFIER_AUTHORITY sid_world_auth = {SECURITY_WORLD_SID_AUTHORITY}; | ||||||
| SID_IDENTIFIER_AUTHORITY sid_nt_auth = {SECURITY_NT_AUTHORITY}; | SID_IDENTIFIER_AUTHORITY sid_nt_auth = {SECURITY_NT_AUTHORITY}; | ||||||
|  |  | ||||||
|  | NET_API_STATUS WINAPI (*netapibufferfree)(PVOID); | ||||||
|  | NET_API_STATUS WINAPI (*netgroupenum)(LPWSTR,DWORD,PBYTE*,DWORD,PDWORD,PDWORD,PDWORD); | ||||||
|  | NET_API_STATUS WINAPI (*netlocalgroupenum)(LPWSTR,DWORD,PBYTE*,DWORD,PDWORD,PDWORD,PDWORD); | ||||||
|  | NET_API_STATUS WINAPI (*netgetdcname)(LPWSTR,LPWSTR,PBYTE*); | ||||||
|  |  | ||||||
| #ifndef min | #ifndef min | ||||||
| #define min(a,b) (((a)<(b))?(a):(b)) | #define min(a,b) (((a)<(b))?(a):(b)) | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | BOOL | ||||||
|  | load_netapi () | ||||||
|  | { | ||||||
|  |   HANDLE h = LoadLibrary ("netapi32.dll"); | ||||||
|  |  | ||||||
|  |   if (!h) | ||||||
|  |     return FALSE; | ||||||
|  |  | ||||||
|  |   if (!(netapibufferfree = GetProcAddress (h, "NetApiBufferFree"))) | ||||||
|  |     return FALSE; | ||||||
|  |   if (!(netgroupenum = GetProcAddress (h, "NetGroupEnum"))) | ||||||
|  |     return FALSE; | ||||||
|  |   if (!(netlocalgroupenum = GetProcAddress (h, "NetLocalGroupEnum"))) | ||||||
|  |     return FALSE; | ||||||
|  |   if (!(netgetdcname = GetProcAddress (h, "NetGetDCName"))) | ||||||
|  |     return FALSE; | ||||||
|  |  | ||||||
|  |   return TRUE; | ||||||
|  | } | ||||||
|  |  | ||||||
| char * | char * | ||||||
| put_sid (PSID sid) | put_sid (PSID sid) | ||||||
| { | { | ||||||
| @@ -88,7 +114,7 @@ enum_local_groups (int print_sids) | |||||||
|     { |     { | ||||||
|       DWORD i; |       DWORD i; | ||||||
|  |  | ||||||
|       rc = NetLocalGroupEnum (NULL, 0, (LPBYTE *) & buffer, 1024, |       rc = netlocalgroupenum (NULL, 0, (LPBYTE *) & buffer, 1024, | ||||||
| 			      &entriesread, &totalentries, &resume_handle); | 			      &entriesread, &totalentries, &resume_handle); | ||||||
|       switch (rc) |       switch (rc) | ||||||
| 	{ | 	{ | ||||||
| @@ -101,7 +127,7 @@ enum_local_groups (int print_sids) | |||||||
| 	  break; | 	  break; | ||||||
|  |  | ||||||
| 	default: | 	default: | ||||||
| 	  fprintf (stderr, "NetUserEnum() failed with %ld\n", rc); | 	  fprintf (stderr, "NetLocalGroupEnum() failed with %ld\n", rc); | ||||||
| 	  exit (1); | 	  exit (1); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -153,7 +179,7 @@ enum_local_groups (int print_sids) | |||||||
|                                   gid); |                                   gid); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|       NetApiBufferFree (buffer); |       netapibufferfree (buffer); | ||||||
|  |  | ||||||
|     } |     } | ||||||
|   while (rc == ERROR_MORE_DATA); |   while (rc == ERROR_MORE_DATA); | ||||||
| @@ -178,7 +204,7 @@ enum_groups (LPWSTR servername, int print_sids) | |||||||
|     { |     { | ||||||
|       DWORD i; |       DWORD i; | ||||||
|  |  | ||||||
|       rc = NetGroupEnum (servername, 2, (LPBYTE *) & buffer, 1024, |       rc = netgroupenum (servername, 2, (LPBYTE *) & buffer, 1024, | ||||||
| 		         &entriesread, &totalentries, &resume_handle); | 		         &entriesread, &totalentries, &resume_handle); | ||||||
|       switch (rc) |       switch (rc) | ||||||
| 	{ | 	{ | ||||||
| @@ -191,7 +217,7 @@ enum_groups (LPWSTR servername, int print_sids) | |||||||
| 	  break; | 	  break; | ||||||
|  |  | ||||||
| 	default: | 	default: | ||||||
| 	  fprintf (stderr, "NetUserEnum() failed with %ld\n", rc); | 	  fprintf (stderr, "NetGroupEnum() failed with %ld\n", rc); | ||||||
| 	  exit (1); | 	  exit (1); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -251,33 +277,42 @@ enum_groups (LPWSTR servername, int print_sids) | |||||||
|                                  gid); |                                  gid); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|       NetApiBufferFree (buffer); |       netapibufferfree (buffer); | ||||||
|  |  | ||||||
|     } |     } | ||||||
|   while (rc == ERROR_MORE_DATA); |   while (rc == ERROR_MORE_DATA); | ||||||
|  |  | ||||||
|   if (servername) |   if (servername) | ||||||
|     NetApiBufferFree (servername); |     netapibufferfree (servername); | ||||||
| } | } | ||||||
|  |  | ||||||
| void | int | ||||||
| usage () | usage () | ||||||
| { | { | ||||||
|   fprintf (stderr, "\n"); |   fprintf (stderr, "Usage: mkgroup [OPTION]... [domain]\n\n"); | ||||||
|   fprintf (stderr, "usage: mkgroup <options> [domain]\n\n"); |   fprintf (stderr, "This program prints a /etc/group file to stdout\n\n"); | ||||||
|   fprintf (stderr, "This program prints group information to stdout\n\n"); |  | ||||||
|   fprintf (stderr, "Options:\n"); |   fprintf (stderr, "Options:\n"); | ||||||
|   fprintf (stderr, "    -l,--local           print pseudo group information if there is\n"); |   fprintf (stderr, "   -l,--local           print local group information\n"); | ||||||
|   fprintf (stderr, "                         no domain\n"); |  | ||||||
|   fprintf (stderr, "   -d,--domain          print global group information from the domain\n"); |   fprintf (stderr, "   -d,--domain          print global group information from the domain\n"); | ||||||
|   fprintf (stderr, "                        specified (or from the current domain if there is\n"); |   fprintf (stderr, "                        specified (or from the current domain if there is\n"); | ||||||
|   fprintf (stderr, "                        no domain specified)\n"); |   fprintf (stderr, "                        no domain specified)\n"); | ||||||
|   fprintf (stderr, "   -s,--no-sids         don't print SIDs in pwd field\n"); |   fprintf (stderr, "   -s,--no-sids         don't print SIDs in pwd field\n"); | ||||||
|   fprintf (stderr, "                         (this affects ntsec)\n"); |   fprintf (stderr, "                         (this affects ntsec)\n"); | ||||||
|   fprintf (stderr, "   -?,--help            print this message\n\n"); |   fprintf (stderr, "   -?,--help            print this message\n\n"); | ||||||
|   exit (1); |   fprintf (stderr, "One of `-l' or `-d' must be given on NT/W2K.\n"); | ||||||
|  |   return 1; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | struct option longopts[] = { | ||||||
|  |   {"local", no_argument, NULL, 'l'}, | ||||||
|  |   {"domain", no_argument, NULL, 'd'}, | ||||||
|  |   {"no-sids", no_argument, NULL, 's'}, | ||||||
|  |   {"help", no_argument, NULL, 'h'}, | ||||||
|  |   {0, no_argument, NULL, 0} | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | char opts[] = "ldsh"; | ||||||
|  |  | ||||||
| int | int | ||||||
| main (int argc, char **argv) | main (int argc, char **argv) | ||||||
| { | { | ||||||
| @@ -295,31 +330,59 @@ main (int argc, char **argv) | |||||||
|   PSID sid, csid; |   PSID sid, csid; | ||||||
|   SID_NAME_USE use; |   SID_NAME_USE use; | ||||||
|  |  | ||||||
|  |   if (GetVersion () < 0x80000000) | ||||||
|     if (argc == 1) |     if (argc == 1) | ||||||
|     usage (); |       return usage (); | ||||||
|  |  | ||||||
|     else |     else | ||||||
|       { |       { | ||||||
|       for (i = 1; i < argc; i++) |         while ((i = getopt_long (argc, argv, opts, longopts, NULL)) != EOF) | ||||||
|  |           switch (i) | ||||||
| 	    { | 	    { | ||||||
| 	  if (!strcmp (argv[i], "-l") || !strcmp (argv[i], "--local")) | 	    case 'l': | ||||||
| 	      print_local = 1; | 	      print_local = 1; | ||||||
|  | 	      break; | ||||||
| 	  else if (!strcmp (argv[i], "-d") || !strcmp (argv[i], "--domain")) | 	    case 'd': | ||||||
| 	      print_domain = 1; | 	      print_domain = 1; | ||||||
|  | 	      break; | ||||||
| 	  else if (!strcmp (argv[i], "-s") || !strcmp (argv[i], "--no-sids")) | 	    case 's': | ||||||
| 	      print_sids = 0; | 	      print_sids = 0; | ||||||
|  | 	      break; | ||||||
| 	  else if (!strcmp (argv[i], "-?") || !strcmp (argv[i], "--help")) | 	    case 'h': | ||||||
| 	    usage (); | 	      return usage (); | ||||||
|  | 	    default: | ||||||
| 	  else | 	      fprintf (stderr, "Try `%s --help' for more information.\n", argv[0]); | ||||||
|  | 	      return 1; | ||||||
|  | 	    } | ||||||
|  |         if (!print_local && !print_domain) | ||||||
|           { |           { | ||||||
| 	      mbstowcs (domain_name, argv[i], strlen (argv[i]) + 1); | 	    fprintf (stderr, "%s: Specify one of `-l' or `-d'\n", argv[0]); | ||||||
|  | 	    return 1; | ||||||
|  | 	  } | ||||||
|  |         if (optind < argc) | ||||||
|  |           { | ||||||
|  | 	    if (!print_domain) | ||||||
|  | 	      { | ||||||
|  | 	        fprintf (stderr, "%s: A domain name is only accepted " | ||||||
|  | 	      		         "when `-d' is given.\n", argv[0]); | ||||||
|  | 	        return 1; | ||||||
|  | 	      } | ||||||
|  | 	    mbstowcs (domain_name, argv[optind], (strlen (argv[optind]) + 1)); | ||||||
| 	    domain_specified = 1; | 	    domain_specified = 1; | ||||||
| 	  } | 	  } | ||||||
|       } |       } | ||||||
|  |  | ||||||
|  |   /* This takes Windows 9x/ME into account. */ | ||||||
|  |   if (GetVersion () >= 0x80000000) | ||||||
|  |     { | ||||||
|  |       printf ("unknown::%ld:\n", DOMAIN_ALIAS_RID_ADMINS); | ||||||
|  |       return 0; | ||||||
|  |     } | ||||||
|  |    | ||||||
|  |   if (!load_netapi ()) | ||||||
|  |     { | ||||||
|  |       fprintf (stderr, "Failed loading symbols from netapi32.dll " | ||||||
|  |       		       "with error %lu\n", GetLastError ()); | ||||||
|  |       return 1; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   /* |   /* | ||||||
| @@ -332,7 +395,7 @@ main (int argc, char **argv) | |||||||
| 			    name, (len = 256, &len), | 			    name, (len = 256, &len), | ||||||
| 			    dom, (len2 = 256, &len), | 			    dom, (len2 = 256, &len), | ||||||
| 			    &use)) | 			    &use)) | ||||||
| 	printf ("%s:%s:%ld:\n", name, | 	printf ("%s:%s:%d:\n", name, | ||||||
|                                print_sids ? put_sid (sid) : "", |                                print_sids ? put_sid (sid) : "", | ||||||
|                                SECURITY_WORLD_RID); |                                SECURITY_WORLD_RID); | ||||||
|       FreeSid (sid); |       FreeSid (sid); | ||||||
| @@ -348,7 +411,7 @@ main (int argc, char **argv) | |||||||
| 			    name, (len = 256, &len), | 			    name, (len = 256, &len), | ||||||
| 			    dom, (len2 = 256, &len), | 			    dom, (len2 = 256, &len), | ||||||
| 			    &use)) | 			    &use)) | ||||||
| 	printf ("%s:%s:%ld:\n", name, | 	printf ("%s:%s:%d:\n", name, | ||||||
|                                print_sids ? put_sid (sid) : "", |                                print_sids ? put_sid (sid) : "", | ||||||
|                                SECURITY_LOCAL_SYSTEM_RID); |                                SECURITY_LOCAL_SYSTEM_RID); | ||||||
|       FreeSid (sid); |       FreeSid (sid); | ||||||
| @@ -391,10 +454,10 @@ main (int argc, char **argv) | |||||||
|   if (print_domain) |   if (print_domain) | ||||||
|     { |     { | ||||||
|       if (domain_specified) |       if (domain_specified) | ||||||
| 	rc = NetGetDCName (NULL, domain_name, (LPBYTE *) & servername); | 	rc = netgetdcname (NULL, domain_name, (LPBYTE *) & servername); | ||||||
|  |  | ||||||
|       else |       else | ||||||
| 	rc = NetGetDCName (NULL, NULL, (LPBYTE *) & servername); | 	rc = netgetdcname (NULL, NULL, (LPBYTE *) & servername); | ||||||
|  |  | ||||||
|       if (rc != ERROR_SUCCESS) |       if (rc != ERROR_SUCCESS) | ||||||
| 	{ | 	{ | ||||||
|   | |||||||
| @@ -14,16 +14,42 @@ | |||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <windows.h> | #include <windows.h> | ||||||
| #include <sys/cygwin.h> | #include <sys/cygwin.h> | ||||||
|  | #include <getopt.h> | ||||||
| #include <lmaccess.h> | #include <lmaccess.h> | ||||||
| #include <lmapibuf.h> | #include <lmapibuf.h> | ||||||
|  |  | ||||||
| SID_IDENTIFIER_AUTHORITY sid_world_auth = {SECURITY_WORLD_SID_AUTHORITY}; | SID_IDENTIFIER_AUTHORITY sid_world_auth = {SECURITY_WORLD_SID_AUTHORITY}; | ||||||
| SID_IDENTIFIER_AUTHORITY sid_nt_auth = {SECURITY_NT_AUTHORITY}; | SID_IDENTIFIER_AUTHORITY sid_nt_auth = {SECURITY_NT_AUTHORITY}; | ||||||
|  |  | ||||||
|  | NET_API_STATUS WINAPI (*netapibufferfree)(PVOID); | ||||||
|  | NET_API_STATUS WINAPI (*netuserenum)(LPWSTR,DWORD,DWORD,PBYTE*,DWORD,PDWORD,PDWORD,PDWORD); | ||||||
|  | NET_API_STATUS WINAPI (*netlocalgroupenum)(LPWSTR,DWORD,PBYTE*,DWORD,PDWORD,PDWORD,PDWORD); | ||||||
|  | NET_API_STATUS WINAPI (*netgetdcname)(LPWSTR,LPWSTR,PBYTE*); | ||||||
|  |  | ||||||
| #ifndef min | #ifndef min | ||||||
| #define min(a,b) (((a)<(b))?(a):(b)) | #define min(a,b) (((a)<(b))?(a):(b)) | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | BOOL | ||||||
|  | load_netapi () | ||||||
|  | { | ||||||
|  |   HANDLE h = LoadLibrary ("netapi32.dll"); | ||||||
|  |  | ||||||
|  |   if (!h) | ||||||
|  |     return FALSE; | ||||||
|  |  | ||||||
|  |   if (!(netapibufferfree = GetProcAddress (h, "NetApiBufferFree"))) | ||||||
|  |     return FALSE; | ||||||
|  |   if (!(netuserenum = GetProcAddress (h, "NetUserEnum"))) | ||||||
|  |     return FALSE; | ||||||
|  |   if (!(netlocalgroupenum = GetProcAddress (h, "NetLocalGroupEnum"))) | ||||||
|  |     return FALSE; | ||||||
|  |   if (!(netgetdcname = GetProcAddress (h, "NetGetDCName"))) | ||||||
|  |     return FALSE; | ||||||
|  |  | ||||||
|  |   return TRUE; | ||||||
|  | } | ||||||
|  |  | ||||||
| char * | char * | ||||||
| put_sid (PSID sid) | put_sid (PSID sid) | ||||||
| { | { | ||||||
| @@ -92,7 +118,7 @@ enum_users (LPWSTR servername, int print_sids, int print_cygpath) | |||||||
|     { |     { | ||||||
|       DWORD i; |       DWORD i; | ||||||
|  |  | ||||||
|       rc = NetUserEnum (servername, 3, FILTER_NORMAL_ACCOUNT, |       rc = netuserenum (servername, 3, FILTER_NORMAL_ACCOUNT, | ||||||
| 			(LPBYTE *) & buffer, 1024, | 			(LPBYTE *) & buffer, 1024, | ||||||
| 			&entriesread, &totalentries, &resume_handle); | 			&entriesread, &totalentries, &resume_handle); | ||||||
|       switch (rc) |       switch (rc) | ||||||
| @@ -180,13 +206,13 @@ enum_users (LPWSTR servername, int print_sids, int print_cygpath) | |||||||
|                   homedir_psx); |                   homedir_psx); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|       NetApiBufferFree (buffer); |       netapibufferfree (buffer); | ||||||
|  |  | ||||||
|     } |     } | ||||||
|   while (rc == ERROR_MORE_DATA); |   while (rc == ERROR_MORE_DATA); | ||||||
|  |  | ||||||
|   if (servername) |   if (servername) | ||||||
|     NetApiBufferFree (servername); |     netapibufferfree (servername); | ||||||
|  |  | ||||||
|   return 0; |   return 0; | ||||||
| } | } | ||||||
| @@ -204,7 +230,7 @@ enum_local_groups (int print_sids) | |||||||
|     { |     { | ||||||
|       DWORD i; |       DWORD i; | ||||||
|  |  | ||||||
|       rc = NetLocalGroupEnum (NULL, 0, (LPBYTE *) & buffer, 1024, |       rc = netlocalgroupenum (NULL, 0, (LPBYTE *) & buffer, 1024, | ||||||
| 			      &entriesread, &totalentries, &resume_handle); | 			      &entriesread, &totalentries, &resume_handle); | ||||||
|       switch (rc) |       switch (rc) | ||||||
| 	{ | 	{ | ||||||
| @@ -217,7 +243,7 @@ enum_local_groups (int print_sids) | |||||||
| 	  break; | 	  break; | ||||||
|  |  | ||||||
| 	default: | 	default: | ||||||
| 	  fprintf (stderr, "NetUserEnum() failed with %ld\n", rc); | 	  fprintf (stderr, "NetLocalGroupEnum() failed with %ld\n", rc); | ||||||
| 	  exit (1); | 	  exit (1); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -269,7 +295,7 @@ enum_local_groups (int print_sids) | |||||||
|                   print_sids ? put_sid (psid) : ""); |                   print_sids ? put_sid (psid) : ""); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|       NetApiBufferFree (buffer); |       netapibufferfree (buffer); | ||||||
|  |  | ||||||
|     } |     } | ||||||
|   while (rc == ERROR_MORE_DATA); |   while (rc == ERROR_MORE_DATA); | ||||||
| @@ -277,25 +303,37 @@ enum_local_groups (int print_sids) | |||||||
|   return 0; |   return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| void | int | ||||||
| usage () | usage () | ||||||
| { | { | ||||||
|   fprintf (stderr, "\n"); |   fprintf (stderr, "Usage: mkpasswd [OPTION]... [domain]\n\n"); | ||||||
|   fprintf (stderr, "usage: mkpasswd [options] [domain]\n\n"); |  | ||||||
|   fprintf (stderr, "This program prints a /etc/passwd file to stdout\n\n"); |   fprintf (stderr, "This program prints a /etc/passwd file to stdout\n\n"); | ||||||
|   fprintf (stderr, "Options are\n"); |   fprintf (stderr, "Options:\n"); | ||||||
|   fprintf (stderr, "   -l,--local              print local accounts\n"); |   fprintf (stderr, "   -l,--local           print local user accounts\n"); | ||||||
|   fprintf (stderr, "   -d,--domain          print domain accounts (from current domain\n"); |   fprintf (stderr, "   -d,--domain          print domain accounts (from current domain\n"); | ||||||
|   fprintf (stderr, "                           if no domain specified\n"); |   fprintf (stderr, "                        if no domain specified)\n"); | ||||||
|   fprintf (stderr, "   -g,--local-groups    print local group information too\n"); |   fprintf (stderr, "   -g,--local-groups    print local group information too\n"); | ||||||
|  |   fprintf (stderr, "                        if no domain specified\n"); | ||||||
|   fprintf (stderr, "   -m,--no-mount        don't use mount points for home dir\n"); |   fprintf (stderr, "   -m,--no-mount        don't use mount points for home dir\n"); | ||||||
|   fprintf (stderr, "   -s,--no-sids         don't print SIDs in GCOS field\n"); |   fprintf (stderr, "   -s,--no-sids         don't print SIDs in GCOS field\n"); | ||||||
|   fprintf (stderr, "                        (this affects ntsec)\n"); |   fprintf (stderr, "                        (this affects ntsec)\n"); | ||||||
|   fprintf (stderr, "   -?,--help            displays this message\n\n"); |   fprintf (stderr, "   -?,--help            displays this message\n\n"); | ||||||
|   fprintf (stderr, "This program does only work on Windows NT\n\n"); |   fprintf (stderr, "One of `-l', `-d' or `-g' must be given on NT/W2K.\n"); | ||||||
|   exit (1); |   return 1; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | struct option longopts[] = { | ||||||
|  |   {"local", no_argument, NULL, 'l'}, | ||||||
|  |   {"domain", no_argument, NULL, 'd'}, | ||||||
|  |   {"loca-groups", no_argument, NULL, 'g'}, | ||||||
|  |   {"no-mount", no_argument, NULL, 'm'}, | ||||||
|  |   {"no-sids", no_argument, NULL, 's'}, | ||||||
|  |   {"help", no_argument, NULL, 'h'}, | ||||||
|  |   {0, no_argument, NULL, 0} | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | char opts[] = "ldgsmh"; | ||||||
|  |  | ||||||
| int | int | ||||||
| main (int argc, char **argv) | main (int argc, char **argv) | ||||||
| { | { | ||||||
| @@ -315,44 +353,73 @@ main (int argc, char **argv) | |||||||
|   PSID sid; |   PSID sid; | ||||||
|   SID_NAME_USE use; |   SID_NAME_USE use; | ||||||
|  |  | ||||||
|  |   if (GetVersion () < 0x80000000) | ||||||
|     if (argc == 1) |     if (argc == 1) | ||||||
|     usage (); |       return usage (); | ||||||
|  |  | ||||||
|     else |     else | ||||||
|       { |       { | ||||||
|       for (i = 1; i < argc; i++) |         while ((i = getopt_long (argc, argv, opts, longopts, NULL)) != EOF) | ||||||
|  |           switch (i) | ||||||
| 	    { | 	    { | ||||||
| 	  if (!strcmp (argv[i], "-l") || !strcmp (argv[i], "--local")) | 	    case 'l': | ||||||
| 	      print_local = 1; | 	      print_local = 1; | ||||||
|  | 	      break; | ||||||
| 	  else if (!strcmp (argv[i], "-d") || !strcmp (argv[i], "--domain")) | 	    case 'd': | ||||||
| 	      print_domain = 1; | 	      print_domain = 1; | ||||||
|  | 	      break; | ||||||
| 	  else if (!strcmp (argv[i], "-g") || !strcmp (argv[i], "--local-groups")) | 	    case 'g': | ||||||
| 	      print_local_groups = 1; | 	      print_local_groups = 1; | ||||||
|  | 	      break; | ||||||
| 	  else if (!strcmp (argv[i], "-s") || !strcmp (argv[i], "--no-sids")) | 	    case 's': | ||||||
| 	      print_sids = 0; | 	      print_sids = 0; | ||||||
|  | 	      break; | ||||||
| 	  else if (!strcmp (argv[i], "-m") || !strcmp (argv[i], "--no-mount")) | 	    case 'm': | ||||||
| 	      print_cygpath = 0; | 	      print_cygpath = 0; | ||||||
|  | 	      break; | ||||||
| 	  else if (!strcmp (argv[i], "-?") || !strcmp (argv[i], "--help")) | 	    case 'h': | ||||||
| 	    usage (); | 	      return usage (); | ||||||
|  | 	    default: | ||||||
| 	  else | 	      fprintf (stderr, "Try `%s --help' for more information.\n", argv[0]); | ||||||
|  | 	      return 1; | ||||||
|  | 	    } | ||||||
|  |         if (!print_local && !print_domain && !print_local_groups) | ||||||
|           { |           { | ||||||
| 	      mbstowcs (domain_name, argv[i], (strlen (argv[i]) + 1)); | 	    fprintf (stderr, "%s: Specify one of `-l', `-d' or `-g'\n", argv[0]); | ||||||
|  | 	    return 1; | ||||||
|  | 	  } | ||||||
|  |         if (optind < argc) | ||||||
|  |           { | ||||||
|  | 	    if (!print_domain) | ||||||
|  | 	      { | ||||||
|  | 	        fprintf (stderr, "%s: A domain name is only accepted " | ||||||
|  | 	      		         "when `-d' is given.\n", argv[0]); | ||||||
|  | 	        return 1; | ||||||
|  | 	      } | ||||||
|  | 	    mbstowcs (domain_name, argv[optind], (strlen (argv[optind]) + 1)); | ||||||
| 	    domain_name_specified = 1; | 	    domain_name_specified = 1; | ||||||
| 	  } | 	  } | ||||||
|       } |       } | ||||||
|     } |  | ||||||
|  |  | ||||||
|   /* FIXME: this needs to take Windows 98 into account. */ |   /* This takes Windows 9x/ME into account. */ | ||||||
|   if (GetVersion () >= 0x80000000) |   if (GetVersion () >= 0x80000000) | ||||||
|     { |     { | ||||||
|       fprintf (stderr, "The required functionality is not supported by Windows 95. Sorry.\n"); |       /* Same behaviour as in cygwin/uinfo.cc (internal_getlogin). */ | ||||||
|       exit (1); |       if (!GetUserName (name, (len = 256, &len))) | ||||||
|  |         strcpy (name, "unknown"); | ||||||
|  |  | ||||||
|  |       printf ("%s::%ld:%ld::/home/%s:/bin/sh\n", name, | ||||||
|  |                                                  DOMAIN_USER_RID_ADMIN, | ||||||
|  |                                                  DOMAIN_ALIAS_RID_ADMINS, | ||||||
|  | 						 name); | ||||||
|  |  | ||||||
|  |       return 0; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |   if (!load_netapi ()) | ||||||
|  |     { | ||||||
|  |       fprintf (stderr, "Failed loading symbols from netapi32.dll " | ||||||
|  |       		       "with error %lu\n", GetLastError ()); | ||||||
|  |       return 1; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   /* |   /* | ||||||
| @@ -365,7 +432,7 @@ main (int argc, char **argv) | |||||||
|                             name, (len = 256, &len), |                             name, (len = 256, &len), | ||||||
|                             dom, (len2 = 256, &len), |                             dom, (len2 = 256, &len), | ||||||
|                             &use)) |                             &use)) | ||||||
|         printf ("%s:*:%ld:%ld:%s%s::\n", name, |         printf ("%s:*:%d:%d:%s%s::\n", name, | ||||||
|                                          SECURITY_WORLD_RID, |                                          SECURITY_WORLD_RID, | ||||||
|                                          SECURITY_WORLD_RID, |                                          SECURITY_WORLD_RID, | ||||||
|                                          print_sids ? "," : "", |                                          print_sids ? "," : "", | ||||||
| @@ -383,7 +450,7 @@ main (int argc, char **argv) | |||||||
|                             name, (len = 256, &len), |                             name, (len = 256, &len), | ||||||
|                             dom, (len2 = 256, &len), |                             dom, (len2 = 256, &len), | ||||||
|                             &use)) |                             &use)) | ||||||
|         printf ("%s:*:%ld:%ld:%s%s::\n", name, |         printf ("%s:*:%d:%d:%s%s::\n", name, | ||||||
|                                          SECURITY_LOCAL_SYSTEM_RID, |                                          SECURITY_LOCAL_SYSTEM_RID, | ||||||
|                                          SECURITY_LOCAL_SYSTEM_RID, |                                          SECURITY_LOCAL_SYSTEM_RID, | ||||||
|                                          print_sids ? "," : "", |                                          print_sids ? "," : "", | ||||||
| @@ -394,7 +461,7 @@ main (int argc, char **argv) | |||||||
|   /* |   /* | ||||||
|    * Get `administrators' group |    * Get `administrators' group | ||||||
|   */ |   */ | ||||||
|   if (!print_local |   if (!print_local_groups | ||||||
|       && AllocateAndInitializeSid (&sid_nt_auth, 2, |       && AllocateAndInitializeSid (&sid_nt_auth, 2, | ||||||
|                                    SECURITY_BUILTIN_DOMAIN_RID, |                                    SECURITY_BUILTIN_DOMAIN_RID, | ||||||
|                                    DOMAIN_ALIAS_RID_ADMINS, |                                    DOMAIN_ALIAS_RID_ADMINS, | ||||||
| @@ -418,10 +485,10 @@ main (int argc, char **argv) | |||||||
|   if (print_domain) |   if (print_domain) | ||||||
|     { |     { | ||||||
|       if (domain_name_specified) |       if (domain_name_specified) | ||||||
| 	rc = NetGetDCName (NULL, domain_name, (LPBYTE *) & servername); | 	rc = netgetdcname (NULL, domain_name, (LPBYTE *) & servername); | ||||||
|  |  | ||||||
|       else |       else | ||||||
| 	rc = NetGetDCName (NULL, NULL, (LPBYTE *) & servername); | 	rc = netgetdcname (NULL, NULL, (LPBYTE *) & servername); | ||||||
|  |  | ||||||
|       if (rc != ERROR_SUCCESS) |       if (rc != ERROR_SUCCESS) | ||||||
| 	{ | 	{ | ||||||
| @@ -436,7 +503,7 @@ main (int argc, char **argv) | |||||||
|     enum_users (NULL, print_sids, print_cygpath); |     enum_users (NULL, print_sids, print_cygpath); | ||||||
|  |  | ||||||
|   if (servername) |   if (servername) | ||||||
|     NetApiBufferFree (servername); |     netapibufferfree (servername); | ||||||
|  |  | ||||||
|   return 0; |   return 0; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user