[PATCH] mkpasswd.c - allows selection of specific user
Mark Bradshaw
bradshaw@staff.crosswalk.com
Fri Jan 11 17:59:00 GMT 2002
Corinna,
You probably don't remember this, but I had volunteered back in December
to make the error messages in mkpasswd a bit more user friendly. Well, I
finally took a few free moments to take a stab at it. I sprinkled a liberal
dose of FormatMessage wherever error reporting was going on. So before,
where there'd be a message that basically said, "You got error number
12345", now it'll print out the corresponding text.
When I pulled my network cable and tried to get a user from the domain I
got...
$ ./mkpasswd -d -u bradshaw
mkpasswd: error 2453.
Could not find domain controller for this domain.
Asking for a bogus user...
$ ./mkpasswd -d -u bradshaj
mkpasswd: error 2221.
The user name could not be found.
------------------------------------------
2002-01-11 Mark Bradshaw <bradshaw@staff.crosswalk.com>
* mkpasswd.c: (enum_users): Use FormatMessage to print text error
messages.
(enum_local_groups): Use FormatMessage to print text
error messages.
(main): Use FormatMessage to print text error messages.
------------------------------------------
--- mkpasswd.c Fri Jan 11 19:40:57 2002
+++ mkpasswd.new.c Fri Jan 11 20:34:18 2002
@@ -114,9 +114,10 @@ enum_users (LPWSTR servername, int print
DWORD entriesread = 0;
DWORD totalentries = 0;
DWORD resume_handle = 0;
- DWORD rc;
+ DWORD rc, er;
char ansi_srvname[256];
WCHAR uni_name[512];
+ char buf[4096];
if (servername)
uni2ansi (servername, ansi_srvname, sizeof (ansi_srvname));
@@ -147,9 +148,14 @@ enum_users (LPWSTR servername, int print
break;
default:
- fprintf (stderr, "NetUserEnum() failed with error %ld.\n", rc);
- if (rc == NERR_UserNotFound)
- fprintf (stderr, "That user doesn't exist.\n");
+ fprintf (stderr, "mkpasswd: error %ld.\n", rc);
+ if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
+ | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ rc,
+ MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) buf, sizeof (buf), NULL))
+ fprintf (stderr, "%s", buf);
exit (1);
}
@@ -206,7 +212,14 @@ enum_users (LPWSTR servername, int print
"LookupAccountName(%s,%s) failed with error
%ld\n",
servername ? ansi_srvname : "NULL",
username,
- GetLastError ());
+ er = GetLastError ());
+ if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
+ | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ er,
+ MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) buf, sizeof (buf), NULL))
+ fprintf (stderr, "%s", buf);
continue;
}
else if (acc_type == SidTypeDomain)
@@ -228,7 +241,14 @@ enum_users (LPWSTR servername, int print
"LookupAccountName(%s,%s) failed with error
%ld\n",
servername ? ansi_srvname : "NULL",
domname,
- GetLastError ());
+ er = GetLastError ());
+ if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
+ | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ er,
+ MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) buf, sizeof (buf), NULL))
+ fprintf (stderr, "%s", buf);
continue;
}
}
@@ -266,7 +286,8 @@ enum_local_groups (int print_sids)
DWORD entriesread = 0;
DWORD totalentries = 0;
DWORD resume_handle = 0;
- DWORD rc ;
+ DWORD rc, er;
+ char buf[4096];
do
{
@@ -285,7 +306,14 @@ enum_local_groups (int print_sids)
break;
default:
- fprintf (stderr, "NetLocalGroupEnum() failed with %ld\n", rc);
+ fprintf (stderr, "mkpasswd: error %ld.\n", rc);
+ if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
+ | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ rc,
+ MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) buf, sizeof (buf), NULL))
+ fprintf (stderr, "%s", buf);
exit (1);
}
@@ -306,7 +334,14 @@ enum_local_groups (int print_sids)
&acc_type))
{
fprintf (stderr, "LookupAccountName(%s) failed with %ld\n",
- localgroup_name, GetLastError ());
+ localgroup_name, er = GetLastError ());
+ if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
+ | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ er,
+ MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) buf, sizeof (buf), NULL))
+ fprintf (stderr, "%s", buf);
continue;
}
else if (acc_type == SidTypeDomain)
@@ -325,7 +360,14 @@ enum_local_groups (int print_sids)
{
fprintf (stderr,
"LookupAccountName(%s) failed with error %ld\n",
- localgroup_name, GetLastError ());
+ localgroup_name, er = GetLastError ());
+ if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
+ | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ er,
+ MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) buf, sizeof (buf), NULL))
+ fprintf (stderr, "%s", buf);
continue;
}
}
@@ -432,6 +474,7 @@ main (int argc, char **argv)
{
LPWSTR servername = NULL;
DWORD rc = ERROR_SUCCESS;
+ DWORD er;
WCHAR domain_name[200];
int print_local = 0;
int print_domain = 0;
@@ -442,6 +485,7 @@ main (int argc, char **argv)
int id_offset = 10000;
int i;
char *disp_username = NULL;
+ char buf[4096];
char name[256], passed_home_path[MAX_PATH];
DWORD len;
@@ -534,7 +578,14 @@ main (int argc, char **argv)
if (!load_netapi ())
{
fprintf (stderr, "Failed loading symbols from netapi32.dll "
- "with error %lu\n", GetLastError ());
+ "with error %lu\n", er = GetLastError ());
+ if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
+ | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ er,
+ MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) buf, sizeof (buf), NULL))
+ fprintf (stderr, "%s", buf);
return 1;
}
@@ -571,7 +622,14 @@ main (int argc, char **argv)
if (rc != ERROR_SUCCESS)
{
- fprintf (stderr, "Cannot get DC, code = %ld\n", rc);
+ fprintf (stderr, "mkpasswd: error %ld.\n", rc);
+ if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
+ | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ rc,
+ MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) buf, sizeof (buf), NULL))
+ fprintf (stderr, "%s", buf);
exit (1);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mkpasswd.c.diff
Type: application/octet-stream
Size: 5277 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20020111/85b116ec/attachment.obj>
More information about the Cygwin-patches
mailing list