4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-18 12:29:32 +08:00

* mkpasswd.c (print_win_error): Add a new function.

(enum_users): Use print_win_error.
	(enum_local_groups): Ditto.
	(main): Ditto.
This commit is contained in:
Corinna Vinschen 2002-01-15 13:10:45 +00:00
parent 7837ec4bda
commit 7041c7aba0
2 changed files with 33 additions and 24 deletions

View File

@ -1,3 +1,10 @@
2002-01-15 Mark Bradshaw <bradshaw@crosswalk.com>
* mkpasswd.c (print_win_error): Add a new function.
(enum_users): Use print_win_error.
(enum_local_groups): Ditto.
(main): Ditto.
2001-12-26 Jonathan Kamens <jik@curl.com> 2001-12-26 Jonathan Kamens <jik@curl.com>
* cygpath.cc (doit): Detect and warn about an empty path. Detect and * cygpath.cc (doit): Detect and warn about an empty path. Detect and

View File

@ -106,6 +106,22 @@ uni2ansi (LPWSTR wcs, char *mbs, int size)
*mbs = '\0'; *mbs = '\0';
} }
void
print_win_error(DWORD code)
{
char buf[4096];
if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
code,
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) buf, sizeof (buf), NULL))
fprintf (stderr, "mkpasswd: [%lu] %s", code, buf);
else
fprintf (stderr, "mkpasswd: error %lu", code);
}
int int
enum_users (LPWSTR servername, int print_sids, int print_cygpath, enum_users (LPWSTR servername, int print_sids, int print_cygpath,
const char * passed_home_path, int id_offset, char *disp_username) const char * passed_home_path, int id_offset, char *disp_username)
@ -139,7 +155,7 @@ enum_users (LPWSTR servername, int print_sids, int print_cygpath,
switch (rc) switch (rc)
{ {
case ERROR_ACCESS_DENIED: case ERROR_ACCESS_DENIED:
fprintf (stderr, "Access denied\n"); print_win_error(rc);
exit (1); exit (1);
case ERROR_MORE_DATA: case ERROR_MORE_DATA:
@ -147,9 +163,7 @@ enum_users (LPWSTR servername, int print_sids, int print_cygpath,
break; break;
default: default:
fprintf (stderr, "NetUserEnum() failed with error %ld.\n", rc); print_win_error(rc);
if (rc == NERR_UserNotFound)
fprintf (stderr, "That user doesn't exist.\n");
exit (1); exit (1);
} }
@ -202,11 +216,7 @@ enum_users (LPWSTR servername, int print_sids, int print_cygpath,
domain_name, &domname_len, domain_name, &domname_len,
&acc_type)) &acc_type))
{ {
fprintf (stderr, print_win_error(GetLastError ());
"LookupAccountName(%s,%s) failed with error %ld\n",
servername ? ansi_srvname : "NULL",
username,
GetLastError ());
continue; continue;
} }
else if (acc_type == SidTypeDomain) else if (acc_type == SidTypeDomain)
@ -224,11 +234,7 @@ enum_users (LPWSTR servername, int print_sids, int print_cygpath,
domain_name, &domname_len, domain_name, &domname_len,
&acc_type)) &acc_type))
{ {
fprintf (stderr, print_win_error(GetLastError ());
"LookupAccountName(%s,%s) failed with error %ld\n",
servername ? ansi_srvname : "NULL",
domname,
GetLastError ());
continue; continue;
} }
} }
@ -277,7 +283,7 @@ enum_local_groups (int print_sids)
switch (rc) switch (rc)
{ {
case ERROR_ACCESS_DENIED: case ERROR_ACCESS_DENIED:
fprintf (stderr, "Access denied\n"); print_win_error(rc);
exit (1); exit (1);
case ERROR_MORE_DATA: case ERROR_MORE_DATA:
@ -285,7 +291,7 @@ enum_local_groups (int print_sids)
break; break;
default: default:
fprintf (stderr, "NetLocalGroupEnum() failed with %ld\n", rc); print_win_error(rc);
exit (1); exit (1);
} }
@ -305,8 +311,7 @@ enum_local_groups (int print_sids)
&sid_length, domain_name, &domname_len, &sid_length, domain_name, &domname_len,
&acc_type)) &acc_type))
{ {
fprintf (stderr, "LookupAccountName(%s) failed with %ld\n", print_win_error(GetLastError ());
localgroup_name, GetLastError ());
continue; continue;
} }
else if (acc_type == SidTypeDomain) else if (acc_type == SidTypeDomain)
@ -323,9 +328,7 @@ enum_local_groups (int print_sids)
domain_name, &domname_len, domain_name, &domname_len,
&acc_type)) &acc_type))
{ {
fprintf (stderr, print_win_error(GetLastError ());
"LookupAccountName(%s) failed with error %ld\n",
localgroup_name, GetLastError ());
continue; continue;
} }
} }
@ -533,8 +536,7 @@ main (int argc, char **argv)
if (!load_netapi ()) if (!load_netapi ())
{ {
fprintf (stderr, "Failed loading symbols from netapi32.dll " print_win_error(GetLastError ());
"with error %lu\n", GetLastError ());
return 1; return 1;
} }
@ -571,7 +573,7 @@ main (int argc, char **argv)
if (rc != ERROR_SUCCESS) if (rc != ERROR_SUCCESS)
{ {
fprintf (stderr, "Cannot get DC, code = %ld\n", rc); print_win_error(rc);
exit (1); exit (1);
} }