From d829da1423d10f4c6fa72d6cdad23da4eb03e455 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 21 Sep 2005 22:26:08 +0000 Subject: Align error message handling to mkpasswd's error messages throughout. * mkgroup.c (print_win_error): Create macro calling ... (_print_win_error): ... this function created from former print_win_error. Move up in source. (PDOMAIN_CONTROLLER_INFOW): Define return type of DcGetDcNameW. (dsgetdcname): New function pointer for DcGetDcNameW. (load_netapi): Get DcGetDcNameW address. (main): If DcGetDcNameW is available, use it. * mkpasswd.c (PDOMAIN_CONTROLLER_INFOW): Define return type of DcGetDcNameW. (dsgetdcname): New function pointer for DcGetDcNameW. (load_netapi): Get DcGetDcNameW address. (main): If DcGetDcNameW is available, use it. Rename local variable domain_name_specified to domain_specified as in mkgroup.c. --- winsup/utils/mkpasswd.c | 61 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 13 deletions(-) (limited to 'winsup/utils/mkpasswd.c') diff --git a/winsup/utils/mkpasswd.c b/winsup/utils/mkpasswd.c index 30e53cf33..96fec7ad1 100644 --- a/winsup/utils/mkpasswd.c +++ b/winsup/utils/mkpasswd.c @@ -30,11 +30,24 @@ static const char version[] = "$Revision$"; SID_IDENTIFIER_AUTHORITY sid_world_auth = {SECURITY_WORLD_SID_AUTHORITY}; SID_IDENTIFIER_AUTHORITY sid_nt_auth = {SECURITY_NT_AUTHORITY}; +typedef struct { + LPWSTR DomainControllerName; + LPWSTR DomainControllerAddress; + ULONG DomainControllerAddressType; + GUID DomainGuid; + LPWSTR DomainName; + LPWSTR DnsForestName; + ULONG Flags; + LPWSTR DcSiteName; + LPWSTR ClientSiteName; +} *PDOMAIN_CONTROLLER_INFOW; + 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*); NET_API_STATUS WINAPI (*netusergetinfo)(LPWSTR,LPWSTR,DWORD,PBYTE*); +NET_API_STATUS WINAPI (*dsgetdcname)(LPWSTR,LPWSTR,GUID*,LPWSTR,ULONG,PDOMAIN_CONTROLLER_INFOW*); #ifndef min #define min(a,b) (((a)<(b))?(a):(b)) @@ -59,6 +72,8 @@ load_netapi () if (!(netusergetinfo = (void *) GetProcAddress (h, "NetUserGetInfo"))) return FALSE; + dsgetdcname = (void *) GetProcAddress (h, "DsGetDcNameW"); + return TRUE; } @@ -561,7 +576,7 @@ main (int argc, char **argv) int print_current = 0; int print_domain = 0; int print_local_groups = 0; - int domain_name_specified = 0; + int domain_specified = 0; int print_sids = 1; int print_cygpath = 1; int id_offset = 10000; @@ -675,7 +690,7 @@ main (int argc, char **argv) "when `-d' is given.\n", argv[0]); return 1; } - domain_name_specified = 1; + domain_specified = 1; } if (!load_netapi ()) { @@ -718,23 +733,43 @@ main (int argc, char **argv) if (print_domain) do { - if (domain_name_specified) + PDOMAIN_CONTROLLER_INFOW pdci = NULL; + + if (dsgetdcname) { - mbstowcs (domain_name, argv[optind], (strlen (argv[optind]) + 1)); - rc = netgetdcname (NULL, domain_name, (void *) &servername); + if (domain_specified) + { + mbstowcs (domain_name, argv[optind], strlen (argv[optind]) + 1); + rc = dsgetdcname (NULL, domain_name, NULL, NULL, 0, &pdci); + } + else + rc = dsgetdcname (NULL, NULL, NULL, NULL, 0, &pdci); + if (rc != ERROR_SUCCESS) + { + print_win_error(rc); + return 1; + } + servername = pdci->DomainControllerName; } else - rc = netgetdcname (NULL, NULL, (void *) &servername); - - if (rc != ERROR_SUCCESS) { - print_win_error(rc); - return 1; - } - + rc = netgetdcname (NULL, NULL, (void *) &servername); + if (rc == ERROR_SUCCESS && domain_specified) + { + LPWSTR server = servername; + mbstowcs (domain_name, argv[optind], strlen (argv[optind]) + 1); + rc = netgetdcname (server, domain_name, (void *) &servername); + netapibufferfree (server); + } + if (rc != ERROR_SUCCESS) + { + print_win_error(rc); + return 1; + } + } enum_users (servername, print_sids, print_cygpath, passed_home_path, id_offset * i++, disp_username); - netapibufferfree (servername); + netapibufferfree (pdci ? (PVOID) pdci : (PVOID) servername); } while (++optind < argc); -- cgit v1.2.3