aboutsummaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2000-11-08 15:00:02 +0000
committerCorinna Vinschen <corinna@vinschen.de>2000-11-08 15:00:02 +0000
commit315f8fd37b75a6cfe589afb9eb18cc9bb59874ac (patch)
treeed16c3045c299794a502176a20aefe0f45434dc4 /winsup
parent4c25744f8646215a655604ad1a9413db59d15de5 (diff)
downloadnewlib-315f8fd37b75a6cfe589afb9eb18cc9bb59874ac.zip
newlib-315f8fd37b75a6cfe589afb9eb18cc9bb59874ac.tar.gz
newlib-315f8fd37b75a6cfe589afb9eb18cc9bb59874ac.tar.bz2
* 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.
Diffstat (limited to 'winsup')
-rw-r--r--winsup/utils/ChangeLog17
-rw-r--r--winsup/utils/mkgroup.c155
-rw-r--r--winsup/utils/mkpasswd.c183
3 files changed, 251 insertions, 104 deletions
diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog
index 560c312..ad8620d 100644
--- a/winsup/utils/ChangeLog
+++ b/winsup/utils/ChangeLog
@@ -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>
* kill.cc (main): Return 1 in case of errors.
diff --git a/winsup/utils/mkgroup.c b/winsup/utils/mkgroup.c
index 558a31d..e813375 100644
--- a/winsup/utils/mkgroup.c
+++ b/winsup/utils/mkgroup.c
@@ -14,16 +14,42 @@
#include <stdio.h>
#include <windows.h>
#include <sys/cygwin.h>
+#include <getopt.h>
#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};
+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
#define min(a,b) (((a)<(b))?(a):(b))
#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 *
put_sid (PSID sid)
{
@@ -88,7 +114,7 @@ enum_local_groups (int print_sids)
{
DWORD i;
- rc = NetLocalGroupEnum (NULL, 0, (LPBYTE *) & buffer, 1024,
+ rc = netlocalgroupenum (NULL, 0, (LPBYTE *) & buffer, 1024,
&entriesread, &totalentries, &resume_handle);
switch (rc)
{
@@ -101,7 +127,7 @@ enum_local_groups (int print_sids)
break;
default:
- fprintf (stderr, "NetUserEnum() failed with %ld\n", rc);
+ fprintf (stderr, "NetLocalGroupEnum() failed with %ld\n", rc);
exit (1);
}
@@ -153,7 +179,7 @@ enum_local_groups (int print_sids)
gid);
}
- NetApiBufferFree (buffer);
+ netapibufferfree (buffer);
}
while (rc == ERROR_MORE_DATA);
@@ -178,7 +204,7 @@ enum_groups (LPWSTR servername, int print_sids)
{
DWORD i;
- rc = NetGroupEnum (servername, 2, (LPBYTE *) & buffer, 1024,
+ rc = netgroupenum (servername, 2, (LPBYTE *) & buffer, 1024,
&entriesread, &totalentries, &resume_handle);
switch (rc)
{
@@ -191,7 +217,7 @@ enum_groups (LPWSTR servername, int print_sids)
break;
default:
- fprintf (stderr, "NetUserEnum() failed with %ld\n", rc);
+ fprintf (stderr, "NetGroupEnum() failed with %ld\n", rc);
exit (1);
}
@@ -251,33 +277,42 @@ enum_groups (LPWSTR servername, int print_sids)
gid);
}
- NetApiBufferFree (buffer);
+ netapibufferfree (buffer);
}
while (rc == ERROR_MORE_DATA);
if (servername)
- NetApiBufferFree (servername);
+ netapibufferfree (servername);
}
-void
+int
usage ()
{
- fprintf (stderr, "\n");
- fprintf (stderr, "usage: mkgroup <options> [domain]\n\n");
- fprintf (stderr, "This program prints group information to stdout\n\n");
+ fprintf (stderr, "Usage: mkgroup [OPTION]... [domain]\n\n");
+ fprintf (stderr, "This program prints a /etc/group file to stdout\n\n");
fprintf (stderr, "Options:\n");
- fprintf (stderr, " -l,--local print pseudo group information if there is\n");
- fprintf (stderr, " no 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, " no domain specified)\n");
- fprintf (stderr, " -s,--no-sids don't print SIDs in pwd field\n");
+ fprintf (stderr, " -l,--local print local group information\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, " no domain specified)\n");
+ fprintf (stderr, " -s,--no-sids don't print SIDs in pwd field\n");
fprintf (stderr, " (this affects ntsec)\n");
- fprintf (stderr, " -?,--help print this message\n\n");
- exit (1);
+ fprintf (stderr, " -?,--help print this message\n\n");
+ 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
main (int argc, char **argv)
{
@@ -295,31 +330,59 @@ main (int argc, char **argv)
PSID sid, csid;
SID_NAME_USE use;
- if (argc == 1)
- usage ();
-
- else
- {
- for (i = 1; i < argc; i++)
- {
- if (!strcmp (argv[i], "-l") || !strcmp (argv[i], "--local"))
- print_local = 1;
-
- else if (!strcmp (argv[i], "-d") || !strcmp (argv[i], "--domain"))
- print_domain = 1;
-
- else if (!strcmp (argv[i], "-s") || !strcmp (argv[i], "--no-sids"))
- print_sids = 0;
-
- else if (!strcmp (argv[i], "-?") || !strcmp (argv[i], "--help"))
- usage ();
-
- else
+ if (GetVersion () < 0x80000000)
+ if (argc == 1)
+ return usage ();
+ else
+ {
+ while ((i = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
+ switch (i)
{
- mbstowcs (domain_name, argv[i], strlen (argv[i]) + 1);
- domain_specified = 1;
+ case 'l':
+ print_local = 1;
+ break;
+ case 'd':
+ print_domain = 1;
+ break;
+ case 's':
+ print_sids = 0;
+ break;
+ case 'h':
+ return usage ();
+ default:
+ fprintf (stderr, "Try `%s --help' for more information.\n", argv[0]);
+ return 1;
}
- }
+ if (!print_local && !print_domain)
+ {
+ 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;
+ }
+ }
+
+ /* 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),
dom, (len2 = 256, &len),
&use))
- printf ("%s:%s:%ld:\n", name,
+ printf ("%s:%s:%d:\n", name,
print_sids ? put_sid (sid) : "",
SECURITY_WORLD_RID);
FreeSid (sid);
@@ -348,7 +411,7 @@ main (int argc, char **argv)
name, (len = 256, &len),
dom, (len2 = 256, &len),
&use))
- printf ("%s:%s:%ld:\n", name,
+ printf ("%s:%s:%d:\n", name,
print_sids ? put_sid (sid) : "",
SECURITY_LOCAL_SYSTEM_RID);
FreeSid (sid);
@@ -391,10 +454,10 @@ main (int argc, char **argv)
if (print_domain)
{
if (domain_specified)
- rc = NetGetDCName (NULL, domain_name, (LPBYTE *) & servername);
+ rc = netgetdcname (NULL, domain_name, (LPBYTE *) & servername);
else
- rc = NetGetDCName (NULL, NULL, (LPBYTE *) & servername);
+ rc = netgetdcname (NULL, NULL, (LPBYTE *) & servername);
if (rc != ERROR_SUCCESS)
{
diff --git a/winsup/utils/mkpasswd.c b/winsup/utils/mkpasswd.c
index 2f32206..966a8d1 100644
--- a/winsup/utils/mkpasswd.c
+++ b/winsup/utils/mkpasswd.c
@@ -14,16 +14,42 @@
#include <stdio.h>
#include <windows.h>
#include <sys/cygwin.h>
+#include <getopt.h>
#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};
+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
#define min(a,b) (((a)<(b))?(a):(b))
#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 *
put_sid (PSID sid)
{
@@ -92,7 +118,7 @@ enum_users (LPWSTR servername, int print_sids, int print_cygpath)
{
DWORD i;
- rc = NetUserEnum (servername, 3, FILTER_NORMAL_ACCOUNT,
+ rc = netuserenum (servername, 3, FILTER_NORMAL_ACCOUNT,
(LPBYTE *) & buffer, 1024,
&entriesread, &totalentries, &resume_handle);
switch (rc)
@@ -180,13 +206,13 @@ enum_users (LPWSTR servername, int print_sids, int print_cygpath)
homedir_psx);
}
- NetApiBufferFree (buffer);
+ netapibufferfree (buffer);
}
while (rc == ERROR_MORE_DATA);
if (servername)
- NetApiBufferFree (servername);
+ netapibufferfree (servername);
return 0;
}
@@ -204,7 +230,7 @@ enum_local_groups (int print_sids)
{
DWORD i;
- rc = NetLocalGroupEnum (NULL, 0, (LPBYTE *) & buffer, 1024,
+ rc = netlocalgroupenum (NULL, 0, (LPBYTE *) & buffer, 1024,
&entriesread, &totalentries, &resume_handle);
switch (rc)
{
@@ -217,7 +243,7 @@ enum_local_groups (int print_sids)
break;
default:
- fprintf (stderr, "NetUserEnum() failed with %ld\n", rc);
+ fprintf (stderr, "NetLocalGroupEnum() failed with %ld\n", rc);
exit (1);
}
@@ -269,7 +295,7 @@ enum_local_groups (int print_sids)
print_sids ? put_sid (psid) : "");
}
- NetApiBufferFree (buffer);
+ netapibufferfree (buffer);
}
while (rc == ERROR_MORE_DATA);
@@ -277,25 +303,37 @@ enum_local_groups (int print_sids)
return 0;
}
-void
+int
usage ()
{
- fprintf (stderr, "\n");
- fprintf (stderr, "usage: mkpasswd [options] [domain]\n\n");
+ fprintf (stderr, "Usage: mkpasswd [OPTION]... [domain]\n\n");
fprintf (stderr, "This program prints a /etc/passwd file to stdout\n\n");
- fprintf (stderr, "Options are\n");
- fprintf (stderr, " -l,--local print local accounts\n");
- fprintf (stderr, " -d,--domain print domain accounts (from current domain\n");
- fprintf (stderr, " if no domain specified\n");
- fprintf (stderr, " -g,--local-groups print local group information too\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, " (this affects ntsec)\n");
- fprintf (stderr, " -?,--help displays this message\n\n");
- fprintf (stderr, "This program does only work on Windows NT\n\n");
- exit (1);
+ fprintf (stderr, "Options:\n");
+ fprintf (stderr, " -l,--local print local user accounts\n");
+ fprintf (stderr, " -d,--domain print domain accounts (from current domain\n");
+ fprintf (stderr, " if no domain specified)\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, " -s,--no-sids don't print SIDs in GCOS field\n");
+ fprintf (stderr, " (this affects ntsec)\n");
+ fprintf (stderr, " -?,--help displays this message\n\n");
+ fprintf (stderr, "One of `-l', `-d' or `-g' must be given on NT/W2K.\n");
+ 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
main (int argc, char **argv)
{
@@ -315,44 +353,73 @@ main (int argc, char **argv)
PSID sid;
SID_NAME_USE use;
- if (argc == 1)
- usage ();
-
- else
+ if (GetVersion () < 0x80000000)
+ if (argc == 1)
+ return usage ();
+ else
+ {
+ while ((i = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
+ switch (i)
+ {
+ case 'l':
+ print_local = 1;
+ break;
+ case 'd':
+ print_domain = 1;
+ break;
+ case 'g':
+ print_local_groups = 1;
+ break;
+ case 's':
+ print_sids = 0;
+ break;
+ case 'm':
+ print_cygpath = 0;
+ break;
+ case 'h':
+ return usage ();
+ default:
+ fprintf (stderr, "Try `%s --help' for more information.\n", argv[0]);
+ return 1;
+ }
+ if (!print_local && !print_domain && !print_local_groups)
+ {
+ 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;
+ }
+ }
+
+ /* This takes Windows 9x/ME into account. */
+ if (GetVersion () >= 0x80000000)
{
- for (i = 1; i < argc; i++)
- {
- if (!strcmp (argv[i], "-l") || !strcmp (argv[i], "--local"))
- print_local = 1;
-
- else if (!strcmp (argv[i], "-d") || !strcmp (argv[i], "--domain"))
- print_domain = 1;
-
- else if (!strcmp (argv[i], "-g") || !strcmp (argv[i], "--local-groups"))
- print_local_groups = 1;
-
- else if (!strcmp (argv[i], "-s") || !strcmp (argv[i], "--no-sids"))
- print_sids = 0;
+ /* Same behaviour as in cygwin/uinfo.cc (internal_getlogin). */
+ if (!GetUserName (name, (len = 256, &len)))
+ strcpy (name, "unknown");
- else if (!strcmp (argv[i], "-m") || !strcmp (argv[i], "--no-mount"))
- print_cygpath = 0;
+ printf ("%s::%ld:%ld::/home/%s:/bin/sh\n", name,
+ DOMAIN_USER_RID_ADMIN,
+ DOMAIN_ALIAS_RID_ADMINS,
+ name);
- else if (!strcmp (argv[i], "-?") || !strcmp (argv[i], "--help"))
- usage ();
-
- else
- {
- mbstowcs (domain_name, argv[i], (strlen (argv[i]) + 1));
- domain_name_specified = 1;
- }
- }
+ return 0;
}
- /* FIXME: this needs to take Windows 98 into account. */
- if (GetVersion () >= 0x80000000)
+ if (!load_netapi ())
{
- fprintf (stderr, "The required functionality is not supported by Windows 95. Sorry.\n");
- exit (1);
+ 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),
dom, (len2 = 256, &len),
&use))
- printf ("%s:*:%ld:%ld:%s%s::\n", name,
+ printf ("%s:*:%d:%d:%s%s::\n", name,
SECURITY_WORLD_RID,
SECURITY_WORLD_RID,
print_sids ? "," : "",
@@ -383,7 +450,7 @@ main (int argc, char **argv)
name, (len = 256, &len),
dom, (len2 = 256, &len),
&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,
print_sids ? "," : "",
@@ -394,7 +461,7 @@ main (int argc, char **argv)
/*
* Get `administrators' group
*/
- if (!print_local
+ if (!print_local_groups
&& AllocateAndInitializeSid (&sid_nt_auth, 2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
@@ -418,10 +485,10 @@ main (int argc, char **argv)
if (print_domain)
{
if (domain_name_specified)
- rc = NetGetDCName (NULL, domain_name, (LPBYTE *) & servername);
+ rc = netgetdcname (NULL, domain_name, (LPBYTE *) & servername);
else
- rc = NetGetDCName (NULL, NULL, (LPBYTE *) & servername);
+ rc = netgetdcname (NULL, NULL, (LPBYTE *) & servername);
if (rc != ERROR_SUCCESS)
{
@@ -436,7 +503,7 @@ main (int argc, char **argv)
enum_users (NULL, print_sids, print_cygpath);
if (servername)
- NetApiBufferFree (servername);
+ netapibufferfree (servername);
return 0;
}