* mkgroup.c: Use statically linked functions throughout, except for

DsGetDcNameW.  Reformat.  Convert to use WCHAR for names throughout.
	Use defines instead of constants throughout.
	(MAX_SID_LEN): Define.
	(load_netapi): Just load DsGetDcNameW pointer.
	(psx_dir): Remove.
	(uni2ansi): Remove.
	(enum_local_users): Take server name and use in Net... call.
	(DBGSID): Define datastructure.
	(MAX_BUILTIN_SIDS): Define.
	(builtin_sid_list): Define global sid list.
	(builtin_sid_cnt): Define counter for global sid list.
	(enum_local_groups): Take server name and use in Net... and Lookup...
	calls.  Take offset argument.  Use MAX_PREFERRED_LENGTH in call to
	NetLocalGroupEnum.  Check for duplicate builtin groups.
	(enum_users): Take server name and use in Net... call.
	(usage): Change text slightly.
	(print_version): Fix copyright.
	(main): Call enum_local_groups for domains as well.
	* mkpasswd.c: Use statically linked functions throughout, except for
	DsGetDcNameW.  Reformat.  Convert to use WCHAR for names throughout.
	Use defines instead of constants throughout.
	(MAX_SID_LEN): Define.
	(load_netapi): Just load DsGetDcNameW pointer.
	(uni2ansi): Use wcstombs.
	(current_user): Replace "unused_by_nt/2000/xp" by
	just "unused".
	(enum_users): Ditto.
	(print_version): Fix copyright.
This commit is contained in:
Corinna Vinschen 2008-07-09 14:32:29 +00:00
parent 5558de95e5
commit 375a780e06
3 changed files with 272 additions and 337 deletions

View File

@ -1,3 +1,35 @@
2008-07-09 Corinna Vinschen <corinna@vinschen.de>
* mkgroup.c: Use statically linked functions throughout, except for
DsGetDcNameW. Reformat. Convert to use WCHAR for names throughout.
Use defines instead of constants throughout.
(MAX_SID_LEN): Define.
(load_netapi): Just load DsGetDcNameW pointer.
(psx_dir): Remove.
(uni2ansi): Remove.
(enum_local_users): Take server name and use in Net... call.
(DBGSID): Define datastructure.
(MAX_BUILTIN_SIDS): Define.
(builtin_sid_list): Define global sid list.
(builtin_sid_cnt): Define counter for global sid list.
(enum_local_groups): Take server name and use in Net... and Lookup...
calls. Take offset argument. Use MAX_PREFERRED_LENGTH in call to
NetLocalGroupEnum. Check for duplicate builtin groups.
(enum_users): Take server name and use in Net... call.
(usage): Change text slightly.
(print_version): Fix copyright.
(main): Call enum_local_groups for domains as well.
* mkpasswd.c: Use statically linked functions throughout, except for
DsGetDcNameW. Reformat. Convert to use WCHAR for names throughout.
Use defines instead of constants throughout.
(MAX_SID_LEN): Define.
(load_netapi): Just load DsGetDcNameW pointer.
(uni2ansi): Use wcstombs.
(current_user): Replace "unused_by_nt/2000/xp" by
just "unused".
(enum_users): Ditto.
(print_version): Fix copyright.
2008-05-22 Corinna Vinschen <corinna@vinschen.de> 2008-05-22 Corinna Vinschen <corinna@vinschen.de>
* setfacl.c (setfacl): Change from void to int. Return 2 in case of * setfacl.c (setfacl): Change from void to int. Return 2 in case of

View File

@ -1,6 +1,7 @@
/* mkgroup.c: /* mkgroup.c:
Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc. Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
2007, 2008 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -17,6 +18,8 @@
#include <getopt.h> #include <getopt.h>
#include <lmaccess.h> #include <lmaccess.h>
#include <lmapibuf.h> #include <lmapibuf.h>
#include <wininet.h>
#include <iptypes.h>
#include <ntsecapi.h> #include <ntsecapi.h>
#include <ntdef.h> #include <ntdef.h>
@ -24,6 +27,8 @@
static const char version[] = "$Revision$"; static const char version[] = "$Revision$";
#define MAX_SID_LEN 40
typedef struct { typedef struct {
LPWSTR DomainControllerName; LPWSTR DomainControllerName;
LPWSTR DomainControllerAddress; LPWSTR DomainControllerAddress;
@ -39,66 +44,18 @@ typedef struct {
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 (*netapibufferallocate)(DWORD,PVOID*);
NET_API_STATUS WINAPI (*netapibufferfree)(PVOID);
NET_API_STATUS WINAPI (*netgroupenum)(LPWSTR,DWORD,PBYTE*,DWORD,PDWORD,PDWORD,PDWORD);
NET_API_STATUS WINAPI (*netgroupgetinfo)(LPWSTR,LPWSTR,DWORD,PBYTE*);
NET_API_STATUS WINAPI (*netlocalgroupenum)(LPWSTR,DWORD,PBYTE*,DWORD,PDWORD,PDWORD,PDWORD);
NET_API_STATUS WINAPI (*netlocalgroupgetmembers)(LPWSTR,LPWSTR,DWORD,PBYTE*,DWORD,PDWORD,PDWORD,PDWORD);
NET_API_STATUS WINAPI (*netgetdcname)(LPWSTR,LPWSTR,PBYTE*);
NET_API_STATUS WINAPI (*netgroupgetusers)(LPWSTR,LPWSTR,DWORD,PBYTE*,DWORD,PDWORD,PDWORD,PDWORD);
NTSTATUS NTAPI (*lsaclose)(LSA_HANDLE);
NTSTATUS NTAPI (*lsaopenpolicy)(PLSA_UNICODE_STRING,PLSA_OBJECT_ATTRIBUTES,ACCESS_MASK,PLSA_HANDLE);
NTSTATUS NTAPI (*lsaqueryinformationpolicy)(LSA_HANDLE,POLICY_INFORMATION_CLASS,PVOID*);
NTSTATUS NTAPI (*lsafreememory)(PVOID);
NET_API_STATUS WINAPI (*dsgetdcname)(LPWSTR,LPWSTR,GUID*,LPWSTR,ULONG,PDOMAIN_CONTROLLER_INFOW*); NET_API_STATUS WINAPI (*dsgetdcname)(LPWSTR,LPWSTR,GUID*,LPWSTR,ULONG,PDOMAIN_CONTROLLER_INFOW*);
#ifndef min #ifndef min
#define min(a,b) (((a)<(b))?(a):(b)) #define min(a,b) (((a)<(b))?(a):(b))
#endif #endif
BOOL void
load_netapi () load_netapi ()
{ {
HANDLE h = LoadLibrary ("netapi32.dll"); HANDLE h = LoadLibrary ("netapi32.dll");
if (h)
if (!h) dsgetdcname = (void *) GetProcAddress (h, "DsGetDcNameW");
return FALSE;
if (!(netapibufferallocate = (void *) GetProcAddress (h, "NetApiBufferAllocate")))
return FALSE;
if (!(netapibufferfree = (void *) GetProcAddress (h, "NetApiBufferFree")))
return FALSE;
if (!(netgroupenum = (void *) GetProcAddress (h, "NetGroupEnum")))
return FALSE;
if (!(netgroupgetinfo = (void *) GetProcAddress (h, "NetGroupGetInfo")))
return FALSE;
if (!(netgroupgetusers = (void *) GetProcAddress (h, "NetGroupGetUsers")))
return FALSE;
if (!(netlocalgroupenum = (void *) GetProcAddress (h, "NetLocalGroupEnum")))
return FALSE;
if (!(netlocalgroupgetmembers = (void *) GetProcAddress (h, "NetLocalGroupGetMembers")))
return FALSE;
if (!(netgetdcname = (void *) GetProcAddress (h, "NetGetDCName")))
return FALSE;
dsgetdcname = (void *) GetProcAddress (h, "DsGetDcNameW");
if (!(h = LoadLibrary ("advapi32.dll")))
return FALSE;
if (!(lsaclose = (void *) GetProcAddress (h, "LsaClose")))
return FALSE;
if (!(lsaopenpolicy = (void *) GetProcAddress (h, "LsaOpenPolicy")))
return FALSE;
if (!(lsaqueryinformationpolicy = (void *) GetProcAddress (h, "LsaQueryInformationPolicy")))
return FALSE;
if (!(lsafreememory = (void *) GetProcAddress (h, "LsaFreeMemory")))
return FALSE;
return TRUE;
} }
char * char *
@ -119,38 +76,6 @@ put_sid (PSID sid)
return s; return s;
} }
void
psx_dir (char *in, char *out)
{
if (isalpha (in[0]) && in[1] == ':')
{
sprintf (out, "/cygdrive/%c", in[0]);
in += 2;
out += strlen (out);
}
while (*in)
{
if (*in == '\\')
*out = '/';
else
*out = *in;
in++;
out++;
}
*out = '\0';
}
void
uni2ansi (LPWSTR wcs, char *mbs, int size)
{
if (wcs)
WideCharToMultiByte (CP_ACP, 0, wcs, -1, mbs, size, NULL, NULL);
else
*mbs = '\0';
}
void void
_print_win_error(DWORD code, int line) _print_win_error(DWORD code, int line)
{ {
@ -168,15 +93,14 @@ _print_win_error(DWORD code, int line)
} }
void void
enum_local_users (LPWSTR groupname) enum_local_users (LPWSTR servername, LPWSTR groupname)
{ {
LOCALGROUP_MEMBERS_INFO_1 *buf1; LOCALGROUP_MEMBERS_INFO_1 *buf1;
DWORD entries = 0; DWORD entries = 0;
DWORD total = 0; DWORD total = 0;
DWORD reshdl = 0; DWORD reshdl = 0;
if (!netlocalgroupgetmembers (NULL, groupname, if (!NetLocalGroupGetMembers (servername, groupname, 1, (void *) &buf1,
1, (void *) &buf1,
MAX_PREFERRED_LENGTH, MAX_PREFERRED_LENGTH,
&entries, &total, &reshdl)) &entries, &total, &reshdl))
{ {
@ -185,26 +109,35 @@ enum_local_users (LPWSTR groupname)
for (i = 0; i < entries; ++i) for (i = 0; i < entries; ++i)
if (buf1[i].lgrmi1_sidusage == SidTypeUser) if (buf1[i].lgrmi1_sidusage == SidTypeUser)
{ {
char user[256];
if (!first) if (!first)
printf (","); printf (",");
first = 0; first = 0;
uni2ansi (buf1[i].lgrmi1_name, user, sizeof (user)); printf ("%ls", buf1[i].lgrmi1_name);
printf ("%s", user);
} }
netapibufferfree (buf1); NetApiBufferFree (buf1);
} }
} }
typedef struct {
BYTE Revision;
BYTE SubAuthorityCount;
SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
DWORD SubAuthority[8];
} DBGSID, *PDBGSID;
#define MAX_BUILTIN_SIDS 100 /* Should be enough for the forseable future. */
DBGSID builtin_sid_list[MAX_BUILTIN_SIDS];
DWORD builtin_sid_cnt;
int int
enum_local_groups (int print_sids, int print_users, char *disp_groupname) enum_local_groups (LPWSTR servername, int print_sids, int print_users,
int id_offset, char *disp_groupname)
{ {
LOCALGROUP_INFO_0 *buffer; LOCALGROUP_INFO_0 *buffer;
DWORD entriesread = 0; DWORD entriesread = 0;
DWORD totalentries = 0; DWORD totalentries = 0;
DWORD resume_handle = 0; DWORD resume_handle = 0;
WCHAR uni_name[512]; WCHAR uni_name[GNLEN + 1];
DWORD rc; DWORD rc;
do do
@ -213,14 +146,16 @@ enum_local_groups (int print_sids, int print_users, char *disp_groupname)
if (disp_groupname != NULL) if (disp_groupname != NULL)
{ {
MultiByteToWideChar (CP_ACP, 0, disp_groupname, -1, uni_name, 512 ); mbstowcs (uni_name, disp_groupname, GNLEN + 1);
rc = netapibufferallocate(sizeof(LOCALGROUP_INFO_0), (void *) &buffer ); rc = NetApiBufferAllocate (sizeof (LOCALGROUP_INFO_0),
buffer[0].lgrpi0_name = (LPWSTR) & uni_name; (void *) &buffer);
entriesread=1; buffer[0].lgrpi0_name = uni_name;
entriesread = 1;
} }
else else
rc = netlocalgroupenum (NULL, 0, (void *) &buffer, 1024, rc = NetLocalGroupEnum (servername, 0, (void *) &buffer,
&entriesread, &totalentries, &resume_handle); MAX_PREFERRED_LENGTH, &entriesread,
&totalentries, &resume_handle);
switch (rc) switch (rc)
{ {
case ERROR_ACCESS_DENIED: case ERROR_ACCESS_DENIED:
@ -238,55 +173,76 @@ enum_local_groups (int print_sids, int print_users, char *disp_groupname)
for (i = 0; i < entriesread; i++) for (i = 0; i < entriesread; i++)
{ {
char localgroup_name[100]; WCHAR domain_name[MAX_DOMAIN_NAME_LEN + 1];
char domain_name[100]; DWORD domname_len = MAX_DOMAIN_NAME_LEN + 1;
DWORD domname_len = 100; char psid_buffer[MAX_SID_LEN];
char psid_buffer[1024];
PSID psid = (PSID) psid_buffer; PSID psid = (PSID) psid_buffer;
DWORD sid_length = 1024; DWORD sid_length = MAX_SID_LEN;
DWORD gid; DWORD gid;
SID_NAME_USE acc_type; SID_NAME_USE acc_type;
uni2ansi (buffer[i].lgrpi0_name, localgroup_name, sizeof (localgroup_name)); PDBGSID pdsid;
BOOL is_builtin = FALSE;
if (!LookupAccountName (NULL, localgroup_name, psid, if (!LookupAccountNameW (servername, buffer[i].lgrpi0_name, psid,
&sid_length, domain_name, &domname_len, &sid_length, domain_name, &domname_len,
&acc_type)) &acc_type))
{ {
print_win_error(rc); print_win_error(rc);
fprintf(stderr, " (%s)\n", localgroup_name); fprintf (stderr, " (%ls)\n", buffer[i].lgrpi0_name);
continue; continue;
} }
else if (acc_type == SidTypeDomain) else if (acc_type == SidTypeDomain)
{ {
char domname[356]; WCHAR domname[MAX_DOMAIN_NAME_LEN + GNLEN + 2];
strcpy (domname, domain_name); wcscpy (domname, domain_name);
strcat (domname, "\\"); wcscat (domname, L"\\");
strcat (domname, localgroup_name); wcscat (domname, buffer[i].lgrpi0_name);
sid_length = 1024; sid_length = MAX_SID_LEN;
domname_len = 100; domname_len = MAX_DOMAIN_NAME_LEN + 1;
if (!LookupAccountName (NULL, domname, if (!LookupAccountNameW (servername, domname,
psid, &sid_length, psid, &sid_length,
domain_name, &domname_len, domain_name, &domname_len,
&acc_type)) &acc_type))
{ {
print_win_error(rc); print_win_error(rc);
fprintf(stderr, " (%s)\n", domname); fprintf(stderr, " (%ls)\n", domname);
continue; continue;
} }
} }
/* Store all local SIDs with prefix "S-1-5-32-" and check if it
has been printed already. This allows to get all builtin
groups exactly once and not once per domain. */
pdsid = (PDBGSID) psid;
if (pdsid->IdentifierAuthority.Value[5] == sid_nt_auth.Value[5]
&& pdsid->SubAuthority[0] == SECURITY_BUILTIN_DOMAIN_RID)
{
int b;
is_builtin = TRUE;
if (servername && builtin_sid_cnt)
for (b = 0; b < builtin_sid_cnt; b++)
if (EqualSid (&builtin_sid_list[b], psid))
goto skip_group;
if (builtin_sid_cnt < MAX_BUILTIN_SIDS)
CopySid (sizeof (DBGSID), &builtin_sid_list[builtin_sid_cnt++],
psid);
}
gid = *GetSidSubAuthority (psid, *GetSidSubAuthorityCount(psid) - 1); gid = *GetSidSubAuthority (psid, *GetSidSubAuthorityCount(psid) - 1);
printf ("%s:%s:%ld:", localgroup_name, printf ("%ls:%s:%ld:", buffer[i].lgrpi0_name,
print_sids ? put_sid (psid) : "", print_sids ? put_sid (psid) : "",
gid); gid + (is_builtin ? 0 : id_offset));
if (print_users) if (print_users)
enum_local_users (buffer[i].lgrpi0_name); enum_local_users (servername, buffer[i].lgrpi0_name);
printf ("\n"); printf ("\n");
skip_group:
;
} }
netapibufferfree (buffer); NetApiBufferFree (buffer);
} }
while (rc == ERROR_MORE_DATA); while (rc == ERROR_MORE_DATA);
@ -302,24 +258,19 @@ enum_users (LPWSTR servername, LPWSTR groupname)
DWORD total = 0; DWORD total = 0;
DWORD reshdl = 0; DWORD reshdl = 0;
if (!netgroupgetusers (servername, groupname, if (!NetGroupGetUsers (servername, groupname, 0, (void *) &buf1,
0, (void *) &buf1, MAX_PREFERRED_LENGTH, &entries, &total, &reshdl))
MAX_PREFERRED_LENGTH,
&entries, &total, &reshdl))
{ {
unsigned i, first = 1; unsigned i, first = 1;
for (i = 0; i < entries; ++i) for (i = 0; i < entries; ++i)
{ {
char user[256];
if (!first) if (!first)
printf (","); printf (",");
first = 0; first = 0;
uni2ansi (buf1[i].grui0_name, user, sizeof (user)); printf ("%ls", buf1[i].grui0_name);
printf ("%s", user);
} }
netapibufferfree (buf1); NetApiBufferFree (buf1);
} }
} }
@ -331,12 +282,8 @@ enum_groups (LPWSTR servername, int print_sids, int print_users, int id_offset,
DWORD entriesread = 0; DWORD entriesread = 0;
DWORD totalentries = 0; DWORD totalentries = 0;
DWORD resume_handle = 0; DWORD resume_handle = 0;
WCHAR uni_name[512]; WCHAR uni_name[GNLEN + 1];
DWORD rc; DWORD rc;
char ansi_srvname[256];
if (servername)
uni2ansi (servername, ansi_srvname, sizeof (ansi_srvname));
do do
{ {
@ -344,14 +291,15 @@ enum_groups (LPWSTR servername, int print_sids, int print_users, int id_offset,
if (disp_groupname != NULL) if (disp_groupname != NULL)
{ {
MultiByteToWideChar (CP_ACP, 0, disp_groupname, -1, uni_name, 512 ); mbstowcs (uni_name, disp_groupname, GNLEN + 1);
rc = netgroupgetinfo(servername, (LPWSTR) & uni_name, 2, rc = NetGroupGetInfo (servername, (LPWSTR) & uni_name, 2,
(void *) &buffer ); (void *) &buffer);
entriesread=1; entriesread=1;
} }
else else
rc = netgroupenum (servername, 2, (void *) & buffer, MAX_PREFERRED_LENGTH, rc = NetGroupEnum (servername, 2, (void *) & buffer,
&entriesread, &totalentries, &resume_handle); MAX_PREFERRED_LENGTH, &entriesread, &totalentries,
&resume_handle);
switch (rc) switch (rc)
{ {
case ERROR_ACCESS_DENIED: case ERROR_ACCESS_DENIED:
@ -369,50 +317,46 @@ enum_groups (LPWSTR servername, int print_sids, int print_users, int id_offset,
for (i = 0; i < entriesread; i++) for (i = 0; i < entriesread; i++)
{ {
char groupname[100]; WCHAR domain_name[MAX_DOMAIN_NAME_LEN + 1];
char domain_name[100]; DWORD domname_len = MAX_DOMAIN_NAME_LEN + 1;
DWORD domname_len = 100; char psid_buffer[MAX_SID_LEN];
char psid_buffer[1024];
PSID psid = (PSID) psid_buffer; PSID psid = (PSID) psid_buffer;
DWORD sid_length = 1024; DWORD sid_length = MAX_SID_LEN;
SID_NAME_USE acc_type; SID_NAME_USE acc_type;
int gid = buffer[i].grpi2_group_id; int gid = buffer[i].grpi2_group_id;
uni2ansi (buffer[i].grpi2_name, groupname, sizeof (groupname));
if (print_sids) if (print_sids)
{ {
if (!LookupAccountName (servername ? ansi_srvname : NULL, if (!LookupAccountNameW (servername, buffer[i].grpi2_name,
groupname, psid, &sid_length,
psid, &sid_length, domain_name, &domname_len,
domain_name, &domname_len, &acc_type))
&acc_type))
{ {
print_win_error(rc); print_win_error(rc);
fprintf(stderr, " (%s)\n", groupname); fprintf(stderr, " (%ls)\n", buffer[i].grpi2_name);
continue; continue;
} }
else if (acc_type == SidTypeDomain) else if (acc_type == SidTypeDomain)
{ {
char domname[356]; WCHAR domname[MAX_DOMAIN_NAME_LEN + GNLEN + 2];
strcpy (domname, domain_name); wcscpy (domname, domain_name);
strcat (domname, "\\"); wcscat (domname, L"\\");
strcat (domname, groupname); wcscat (domname, buffer[i].grpi2_name);
sid_length = 1024; sid_length = MAX_SID_LEN;
domname_len = 100; domname_len = MAX_DOMAIN_NAME_LEN + 1;
if (!LookupAccountName (servername ? ansi_srvname : NULL, if (!LookupAccountNameW (servername, domname,
domname, psid, &sid_length,
psid, &sid_length, domain_name, &domname_len,
domain_name, &domname_len, &acc_type))
&acc_type))
{ {
print_win_error(rc); print_win_error(rc);
fprintf(stderr, " (%s)\n", domname); fprintf(stderr, " (%ls)\n", domname);
continue; continue;
} }
} }
} }
printf ("%s:%s:%u:", groupname, printf ("%ls:%s:%u:", buffer[i].grpi2_name,
print_sids ? put_sid (psid) : "", print_sids ? put_sid (psid) : "",
gid + id_offset); gid + id_offset);
if (print_users) if (print_users)
@ -420,7 +364,7 @@ enum_groups (LPWSTR servername, int print_sids, int print_users, int id_offset,
printf ("\n"); printf ("\n");
} }
netapibufferfree (buffer); NetApiBufferFree (buffer);
} }
while (rc == ERROR_MORE_DATA); while (rc == ERROR_MORE_DATA);
@ -432,7 +376,7 @@ print_special (int print_sids,
DWORD sub1, DWORD sub2, DWORD sub3, DWORD sub4, DWORD sub1, DWORD sub2, DWORD sub3, DWORD sub4,
DWORD sub5, DWORD sub6, DWORD sub7, DWORD sub8) DWORD sub5, DWORD sub6, DWORD sub7, DWORD sub8)
{ {
char name[256], dom[256]; char name[UNLEN + 1], dom[MAX_DOMAIN_NAME_LEN + 1];
DWORD len, len2, rid; DWORD len, len2, rid;
PSID sid; PSID sid;
SID_NAME_USE use; SID_NAME_USE use;
@ -441,8 +385,8 @@ print_special (int print_sids,
sub5, sub6, sub7, sub8, &sid)) sub5, sub6, sub7, sub8, &sid))
{ {
if (LookupAccountSid (NULL, sid, if (LookupAccountSid (NULL, sid,
name, (len = 256, &len), name, (len = UNLEN + 1, &len),
dom, (len2 = 256, &len), dom, (len2 = MAX_DOMAIN_NAME_LEN + 1, &len),
&use)) &use))
{ {
if (sub8) if (sub8)
@ -478,7 +422,7 @@ current_group (int print_sids, int print_users, int id_offset)
int errpos = 0; int errpos = 0;
struct { struct {
PSID psid; PSID psid;
int buffer[10]; char buffer[MAX_SID_LEN];
} tg; } tg;
@ -520,9 +464,9 @@ usage (FILE * stream, int isNT)
"Print /etc/group file to stdout\n\n" "Print /etc/group file to stdout\n\n"
"Options:\n"); "Options:\n");
if (isNT) if (isNT)
fprintf (stream, " -l,--local print local group information\n" fprintf (stream, " -l,--local print machine local group information\n"
" -c,--current print current group, if a domain account\n" " -c,--current print current group, if a domain account\n"
" -d,--domain print global group information (from current\n" " -d,--domain print domain group information (from current\n"
" domain if no domains specified)\n" " domain if no domains specified)\n"
" -o,--id-offset offset change the default offset (10000) added to gids\n" " -o,--id-offset offset change the default offset (10000) added to gids\n"
" in domain accounts.\n" " in domain accounts.\n"
@ -571,7 +515,7 @@ print_version ()
printf ("\ printf ("\
mkgroup (cygwin) %.*s\n\ mkgroup (cygwin) %.*s\n\
group File Generator\n\ group File Generator\n\
Copyright 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.\n\ Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Red Hat, Inc.\n\
Compiled on %s\n\ Compiled on %s\n\
", len, v, __DATE__); ", len, v, __DATE__);
} }
@ -581,7 +525,7 @@ main (int argc, char **argv)
{ {
LPWSTR servername; LPWSTR servername;
DWORD rc = ERROR_SUCCESS; DWORD rc = ERROR_SUCCESS;
WCHAR domain_name[100]; WCHAR domain_name[MAX_DOMAIN_NAME_LEN + 1];
int print_local = 0; int print_local = 0;
int print_current = 0; int print_current = 0;
int print_domain = 0; int print_domain = 0;
@ -594,9 +538,8 @@ main (int argc, char **argv)
int isNT; int isNT;
int i; int i;
char name[256], dom[256]; char dom[MAX_DOMAIN_NAME_LEN + 1];
DWORD len, len2; DWORD len, len2;
char buf[1024];
PSID psid = NULL; PSID psid = NULL;
SID_NAME_USE use; SID_NAME_USE use;
@ -670,23 +613,22 @@ main (int argc, char **argv)
} }
domain_specified = 1; domain_specified = 1;
} }
if (!load_netapi ()) load_netapi ();
{
print_win_error(GetLastError ());
return 1;
}
if (print_local) if (print_local)
{ {
char machine[INTERNET_MAX_HOST_NAME_LENGTH + 1];
char sid[MAX_SID_LEN];
if (isRoot) if (isRoot)
{ {
/* /*
* Very special feature for the oncoming future: * Very special feature for the oncoming future:
* Create a "root" group account, being actually the local * Create a "root" group account, being actually the local
* Administrators group. Since user name, sid and gid are * Administrators group. Since user name, sid and gid are
* fixed, there's no need to call print_special() for this. * fixed, there's no need to call print_special() for this.
*/ */
printf ("root:S-1-5-32-544:0:\n"); printf ("root:S-1-5-32-544:0:\n");
} }
if (disp_groupname == NULL) if (disp_groupname == NULL)
@ -699,35 +641,35 @@ main (int argc, char **argv)
/* /*
* Get 'None' group * Get 'None' group
*/ */
len = 256; len = INTERNET_MAX_HOST_NAME_LENGTH + 1;
GetComputerName (name, &len); GetComputerName (machine, &len);
len = 1024; len = MAX_SID_LEN;
len2 = 256; len2 = MAX_DOMAIN_NAME_LEN + 1;
if (LookupAccountName (NULL, name, (PSID) buf, &len, dom, &len, &use)) if (LookupAccountName (NULL, machine, (PSID) sid, &len, dom, &len2, &use))
psid = (PSID) buf; psid = (PSID) sid;
else else
{ {
ret = lsaopenpolicy (NULL, &oa, POLICY_VIEW_LOCAL_INFORMATION, &lsa); ret = LsaOpenPolicy (NULL, &oa, POLICY_VIEW_LOCAL_INFORMATION, &lsa);
if (ret == STATUS_SUCCESS && lsa != INVALID_HANDLE_VALUE) if (ret == STATUS_SUCCESS && lsa != INVALID_HANDLE_VALUE)
{ {
ret = lsaqueryinformationpolicy (lsa, ret = LsaQueryInformationPolicy (lsa,
PolicyPrimaryDomainInformation, PolicyPrimaryDomainInformation,
(void *) &pdi); (void *) &pdi);
if (ret == STATUS_SUCCESS) if (ret == STATUS_SUCCESS)
{ {
if (pdi->Sid) if (pdi->Sid)
{ {
CopySid (1024, (PSID) buf, pdi->Sid); CopySid (MAX_SID_LEN, (PSID) sid, pdi->Sid);
psid = (PSID) buf; psid = (PSID) sid;
} }
lsafreememory (pdi); LsaFreeMemory (pdi);
} }
lsaclose (lsa); LsaClose (lsa);
} }
} }
if (!psid) if (!psid)
fprintf (stderr, fprintf (stderr,
"WARNING: Group 513 couldn't get retrieved. Try mkgroup -d\n"); "WARNING: Machine local group 513 couldn't get retrieved. Try mkgroup -d\n");
else else
print_special (print_sids, GetSidIdentifierAuthority (psid), 5, print_special (print_sids, GetSidIdentifierAuthority (psid), 5,
*GetSidSubAuthority (psid, 0), *GetSidSubAuthority (psid, 0),
@ -741,11 +683,8 @@ main (int argc, char **argv)
} }
if (!isRoot) if (!isRoot)
{ enum_local_groups (NULL, print_sids, print_users, 0, disp_groupname);
enum_local_groups (print_sids, print_users, disp_groupname);
}
} }
i = 1; i = 1;
if (print_domain) if (print_domain)
do do
@ -770,13 +709,13 @@ main (int argc, char **argv)
} }
else else
{ {
rc = netgetdcname (NULL, NULL, (void *) &servername); rc = NetGetDCName (NULL, NULL, (void *) &servername);
if (rc == ERROR_SUCCESS && domain_specified) if (rc == ERROR_SUCCESS && domain_specified)
{ {
LPWSTR server = servername; LPWSTR server = servername;
mbstowcs (domain_name, argv[optind], strlen (argv[optind]) + 1); mbstowcs (domain_name, argv[optind], strlen (argv[optind]) + 1);
rc = netgetdcname (NULL, domain_name, (void *) &servername); rc = NetGetDCName (NULL, domain_name, (void *) &servername);
netapibufferfree (server); NetApiBufferFree (server);
} }
if (rc != ERROR_SUCCESS) if (rc != ERROR_SUCCESS)
{ {
@ -784,9 +723,11 @@ main (int argc, char **argv)
return 1; return 1;
} }
} }
enum_groups (servername, print_sids, print_users, id_offset * i++, enum_groups (servername, print_sids, print_users, id_offset * i,
disp_groupname); disp_groupname);
netapibufferfree (pdci ? (PVOID) pdci : (PVOID) servername); enum_local_groups (servername, print_sids, print_users, id_offset * i++,
disp_groupname);
NetApiBufferFree (pdci ? (PVOID) pdci : (PVOID) servername);
} }
while (++optind < argc); while (++optind < argc);

View File

@ -1,6 +1,7 @@
/* mkpasswd.c: /* mkpasswd.c:
Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc. Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006,
2008 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -22,9 +23,12 @@
#include <sys/fcntl.h> #include <sys/fcntl.h>
#include <lmerr.h> #include <lmerr.h>
#include <lmcons.h> #include <lmcons.h>
#include <iptypes.h>
#define print_win_error(x) _print_win_error(x, __LINE__) #define print_win_error(x) _print_win_error(x, __LINE__)
#define MAX_SID_LEN 40
static const char version[] = "$Revision$"; static const char version[] = "$Revision$";
SID_IDENTIFIER_AUTHORITY sid_world_auth = {SECURITY_WORLD_SID_AUTHORITY}; SID_IDENTIFIER_AUTHORITY sid_world_auth = {SECURITY_WORLD_SID_AUTHORITY};
@ -42,39 +46,19 @@ typedef struct {
LPWSTR ClientSiteName; LPWSTR ClientSiteName;
} *PDOMAIN_CONTROLLER_INFOW; } *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*); NET_API_STATUS WINAPI (*dsgetdcname)(LPWSTR,LPWSTR,GUID*,LPWSTR,ULONG,PDOMAIN_CONTROLLER_INFOW*);
#ifndef min #ifndef min
#define min(a,b) (((a)<(b))?(a):(b)) #define min(a,b) (((a)<(b))?(a):(b))
#endif #endif
BOOL void
load_netapi () load_netapi ()
{ {
HANDLE h = LoadLibrary ("netapi32.dll"); HANDLE h = LoadLibrary ("netapi32.dll");
if (!h) if (h)
return FALSE; dsgetdcname = (void *) GetProcAddress (h, "DsGetDcNameW");
if (!(netapibufferfree = (void *) GetProcAddress (h, "NetApiBufferFree")))
return FALSE;
if (!(netuserenum = (void *) GetProcAddress (h, "NetUserEnum")))
return FALSE;
if (!(netlocalgroupenum = (void *) GetProcAddress (h, "NetLocalGroupEnum")))
return FALSE;
if (!(netgetdcname = (void *) GetProcAddress (h, "NetGetDCName")))
return FALSE;
if (!(netusergetinfo = (void *) GetProcAddress (h, "NetUserGetInfo")))
return FALSE;
dsgetdcname = (void *) GetProcAddress (h, "DsGetDcNameW");
return TRUE;
} }
char * char *
@ -122,7 +106,7 @@ void
uni2ansi (LPWSTR wcs, char *mbs, int size) uni2ansi (LPWSTR wcs, char *mbs, int size)
{ {
if (wcs) if (wcs)
WideCharToMultiByte (CP_ACP, 0, wcs, -1, mbs, size, NULL, NULL); wcstombs (mbs, wcs, size);
else else
*mbs = '\0'; *mbs = '\0';
} }
@ -214,7 +198,7 @@ current_user (int print_sids, int print_cygpath,
strlcat (homedir_psx, envname, sizeof (homedir_psx)); strlcat (homedir_psx, envname, sizeof (homedir_psx));
} }
printf ("%s:unused_by_nt/2000/xp:%u:%u:%s%s%s%s%s%s%s%s:%s:/bin/bash\n", printf ("%s:unused:%u:%u:%s%s%s%s%s%s%s%s:%s:/bin/bash\n",
envname, envname,
uid + id_offset, uid + id_offset,
gid + id_offset, gid + id_offset,
@ -238,27 +222,23 @@ enum_users (LPWSTR servername, int print_sids, int print_cygpath,
DWORD totalentries = 0; DWORD totalentries = 0;
DWORD resume_handle = 0; DWORD resume_handle = 0;
DWORD rc; DWORD rc;
char ansi_srvname[256]; WCHAR uni_name[UNLEN + 1];
WCHAR uni_name[512];
if (servername)
uni2ansi (servername, ansi_srvname, sizeof (ansi_srvname));
do do
{ {
DWORD i; DWORD i;
if (disp_username != NULL) if (disp_username != NULL)
{ {
MultiByteToWideChar (CP_ACP, 0, disp_username, -1, uni_name, 512 ); mbstowcs (uni_name, disp_username, UNLEN + 1);
rc = netusergetinfo(servername, (LPWSTR) & uni_name, 3, rc = NetUserGetInfo (servername, (LPWSTR) &uni_name, 3,
(void *) &buffer ); (void *) &buffer);
entriesread=1; entriesread = 1;
} }
else else
rc = netuserenum (servername, 3, FILTER_NORMAL_ACCOUNT, rc = NetUserEnum (servername, 3, FILTER_NORMAL_ACCOUNT,
(void *) &buffer, 1024, (void *) &buffer, MAX_PREFERRED_LENGTH,
&entriesread, &totalentries, &resume_handle); &entriesread, &totalentries, &resume_handle);
switch (rc) switch (rc)
{ {
case ERROR_ACCESS_DENIED: case ERROR_ACCESS_DENIED:
@ -276,21 +256,17 @@ enum_users (LPWSTR servername, int print_sids, int print_cygpath,
for (i = 0; i < entriesread; i++) for (i = 0; i < entriesread; i++)
{ {
char username[100]; char homedir_psx[PATH_MAX];
char fullname[100];
char homedir_psx[MAX_PATH];
char homedir_w32[MAX_PATH]; char homedir_w32[MAX_PATH];
char domain_name[100]; WCHAR domain_name[MAX_DOMAIN_NAME_LEN + 1];
DWORD domname_len = 100; DWORD domname_len = MAX_DOMAIN_NAME_LEN + 1;
char psid_buffer[1024]; char psid_buffer[MAX_SID_LEN];
PSID psid = (PSID) psid_buffer; PSID psid = (PSID) psid_buffer;
DWORD sid_length = 1024; DWORD sid_length = MAX_SID_LEN;
SID_NAME_USE acc_type; SID_NAME_USE acc_type;
int uid = buffer[i].usri3_user_id; int uid = buffer[i].usri3_user_id;
int gid = buffer[i].usri3_primary_group_id; int gid = buffer[i].usri3_primary_group_id;
uni2ansi (buffer[i].usri3_name, username, sizeof (username));
uni2ansi (buffer[i].usri3_full_name, fullname, sizeof (fullname));
homedir_w32[0] = homedir_psx[0] = '\0'; homedir_w32[0] = homedir_psx[0] = '\0';
if (passed_home_path[0] == '\0') if (passed_home_path[0] == '\0')
{ {
@ -300,71 +276,65 @@ enum_users (LPWSTR servername, int print_sids, int print_cygpath,
{ {
if (print_cygpath) if (print_cygpath)
cygwin_conv_path (CCP_WIN_A_TO_POSIX | CCP_ABSOLUTE, cygwin_conv_path (CCP_WIN_A_TO_POSIX | CCP_ABSOLUTE,
homedir_w32, homedir_psx, MAX_PATH); homedir_w32, homedir_psx, PATH_MAX);
else else
psx_dir (homedir_w32, homedir_psx); psx_dir (homedir_w32, homedir_psx);
} }
else else
{ uni2ansi (buffer[i].usri3_name,
strcpy (homedir_psx, "/home/"); stpcpy (homedir_psx, "/home/"), PATH_MAX - 6);
strcat (homedir_psx, username);
}
} }
else else
{ uni2ansi (buffer[i].usri3_name,
strcpy (homedir_psx, passed_home_path); stpcpy (homedir_psx, passed_home_path),
strcat (homedir_psx, username); PATH_MAX - strlen (passed_home_path));
}
if (print_sids) if (print_sids)
{ {
if (!LookupAccountName (servername ? ansi_srvname : NULL, if (!LookupAccountNameW (servername, buffer[i].usri3_name,
username, psid, &sid_length, domain_name,
psid, &sid_length, &domname_len, &acc_type))
domain_name, &domname_len,
&acc_type))
{ {
print_win_error(GetLastError ()); print_win_error(GetLastError ());
fprintf(stderr, " (%s)\n", username); fprintf(stderr, " (%ls)\n", buffer[i].usri3_name);
continue; continue;
} }
else if (acc_type == SidTypeDomain) else if (acc_type == SidTypeDomain)
{ {
char domname[356]; WCHAR domname[MAX_DOMAIN_NAME_LEN + UNLEN + 2];
strcpy (domname, domain_name); wcscpy (domname, domain_name);
strcat (domname, "\\"); wcscat (domname, L"\\");
strcat (domname, username); wcscat (domname, buffer[i].usri3_name);
sid_length = 1024; sid_length = MAX_SID_LEN;
domname_len = 100; domname_len = sizeof (domname);
if (!LookupAccountName (servername ? ansi_srvname : NULL, if (!LookupAccountNameW (servername, domname, psid,
domname, &sid_length, domain_name,
psid, &sid_length, &domname_len, &acc_type))
domain_name, &domname_len,
&acc_type))
{ {
print_win_error(GetLastError ()); print_win_error(GetLastError ());
fprintf(stderr, " (%s)\n", domname); fprintf(stderr, " (%ls)\n", domname);
continue; continue;
} }
} }
} }
printf ("%s:unused_by_nt/2000/xp:%u:%u:%s%s%s%s%s%s%s%s:%s:/bin/bash\n", printf ("%ls:unused:%u:%u:%ls%s%s%ls%s%ls%s%s:%s:/bin/bash\n",
username, buffer[i].usri3_name,
uid + id_offset, uid + id_offset,
gid + id_offset, gid + id_offset,
fullname, buffer[i].usri3_full_name ?: L"",
print_sids && fullname[0] ? "," : "", print_sids && buffer[i].usri3_full_name
&& buffer[i].usri3_full_name[0] ? "," : "",
print_sids ? "U-" : "", print_sids ? "U-" : "",
print_sids ? domain_name : "", print_sids ? domain_name : L"",
print_sids && domain_name[0] ? "\\" : "", print_sids && domain_name[0] ? "\\" : "",
print_sids ? username : "", print_sids ? buffer[i].usri3_full_name : L"",
print_sids ? "," : "", print_sids ? "," : "",
print_sids ? put_sid (psid) : "", print_sids ? put_sid (psid) : "",
homedir_psx); homedir_psx);
} }
netapibufferfree (buffer); NetApiBufferFree (buffer);
} }
while (rc == ERROR_MORE_DATA); while (rc == ERROR_MORE_DATA);
@ -385,7 +355,7 @@ enum_local_groups (int print_sids)
{ {
DWORD i; DWORD i;
rc = netlocalgroupenum (NULL, 0, (void *) &buffer, 1024, rc = NetLocalGroupEnum (NULL, 0, (void *) &buffer, 1024,
&entriesread, &totalentries, &resume_handle); &entriesread, &totalentries, &resume_handle);
switch (rc) switch (rc)
{ {
@ -404,52 +374,48 @@ enum_local_groups (int print_sids)
for (i = 0; i < entriesread; i++) for (i = 0; i < entriesread; i++)
{ {
char localgroup_name[100]; WCHAR domain_name[MAX_DOMAIN_NAME_LEN + 1];
char domain_name[100]; DWORD domname_len = MAX_DOMAIN_NAME_LEN + 1;
DWORD domname_len = 100; char psid_buffer[MAX_SID_LEN];
char psid_buffer[1024];
PSID psid = (PSID) psid_buffer; PSID psid = (PSID) psid_buffer;
DWORD sid_length = 1024; DWORD sid_length = MAX_SID_LEN;
DWORD gid; DWORD gid;
SID_NAME_USE acc_type; SID_NAME_USE acc_type;
uni2ansi (buffer[i].lgrpi0_name, localgroup_name, sizeof (localgroup_name));
if (!LookupAccountName (NULL, localgroup_name, psid, if (!LookupAccountNameW (NULL, buffer[i].lgrpi0_name, psid,
&sid_length, domain_name, &domname_len, &sid_length, domain_name, &domname_len,
&acc_type)) &acc_type))
{ {
print_win_error(GetLastError ()); print_win_error(GetLastError ());
fprintf(stderr, " (%s)\n", localgroup_name); fprintf(stderr, " (%ls)\n", buffer[i].lgrpi0_name);
continue; continue;
} }
else if (acc_type == SidTypeDomain) else if (acc_type == SidTypeDomain)
{ {
char domname[356]; WCHAR domname[MAX_DOMAIN_NAME_LEN + GNLEN + 2];
strcpy (domname, domain_name); wcscpy (domname, domain_name);
strcat (domname, "\\"); wcscat (domname, L"\\");
strcat (domname, localgroup_name); wcscat (domname, buffer[i].lgrpi0_name);
sid_length = 1024; sid_length = MAX_SID_LEN;
domname_len = 100; domname_len = MAX_DOMAIN_NAME_LEN + 1;
if (!LookupAccountName (NULL, domname, if (!LookupAccountNameW (NULL, domname, psid, &sid_length,
psid, &sid_length, domain_name, &domname_len, &acc_type))
domain_name, &domname_len,
&acc_type))
{ {
print_win_error(GetLastError ()); print_win_error(GetLastError ());
fprintf(stderr, " (%s)\n", domname); fprintf(stderr, " (%ls)\n", domname);
continue; continue;
} }
} }
gid = *GetSidSubAuthority (psid, *GetSidSubAuthorityCount(psid) - 1); gid = *GetSidSubAuthority (psid, *GetSidSubAuthorityCount(psid) - 1);
printf ("%s:*:%ld:%ld:%s%s::\n", localgroup_name, gid, gid, printf ("%ls:*:%ld:%ld:%s%s::\n", buffer[i].lgrpi0_name, gid, gid,
print_sids ? "," : "", 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);
@ -463,7 +429,7 @@ print_special (int print_sids,
DWORD sub1, DWORD sub2, DWORD sub3, DWORD sub4, DWORD sub1, DWORD sub2, DWORD sub3, DWORD sub4,
DWORD sub5, DWORD sub6, DWORD sub7, DWORD sub8) DWORD sub5, DWORD sub6, DWORD sub7, DWORD sub8)
{ {
char name[256], dom[256]; char name[UNLEN + 1], dom[MAX_DOMAIN_NAME_LEN + 1];
DWORD len, len2, rid; DWORD len, len2, rid;
PSID sid; PSID sid;
SID_NAME_USE use; SID_NAME_USE use;
@ -472,8 +438,8 @@ print_special (int print_sids,
sub5, sub6, sub7, sub8, &sid)) sub5, sub6, sub7, sub8, &sid))
{ {
if (LookupAccountSid (NULL, sid, if (LookupAccountSid (NULL, sid,
name, (len = 256, &len), name, (len = UNLEN + 1, &len),
dom, (len2 = 256, &len), dom, (len2 = MAX_DOMAIN_NAME_LEN + 1, &len),
&use)) &use))
{ {
if (sub8) if (sub8)
@ -563,7 +529,7 @@ print_version ()
printf ("\ printf ("\
mkpasswd (cygwin) %.*s\n\ mkpasswd (cygwin) %.*s\n\
passwd File Generator\n\ passwd File Generator\n\
Copyright 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.\n\ Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2008 Red Hat, Inc.\n\
Compiled on %s\n\ Compiled on %s\n\
", len, v, __DATE__); ", len, v, __DATE__);
} }
@ -573,7 +539,7 @@ main (int argc, char **argv)
{ {
LPWSTR servername = NULL; LPWSTR servername = NULL;
DWORD rc = ERROR_SUCCESS; DWORD rc = ERROR_SUCCESS;
WCHAR domain_name[200]; WCHAR domain_name[MAX_DOMAIN_NAME_LEN + 1];
int print_local = 0; int print_local = 0;
int print_current = 0; int print_current = 0;
int print_domain = 0; int print_domain = 0;
@ -694,11 +660,7 @@ main (int argc, char **argv)
} }
domain_specified = 1; domain_specified = 1;
} }
if (!load_netapi ()) load_netapi ();
{
print_win_error(GetLastError ());
return 1;
}
if (disp_username == NULL) if (disp_username == NULL)
{ {
@ -745,13 +707,13 @@ main (int argc, char **argv)
} }
else else
{ {
rc = netgetdcname (NULL, NULL, (void *) &servername); rc = NetGetDCName (NULL, NULL, (void *) &servername);
if (rc == ERROR_SUCCESS && domain_specified) if (rc == ERROR_SUCCESS && domain_specified)
{ {
LPWSTR server = servername; LPWSTR server = servername;
mbstowcs (domain_name, argv[optind], strlen (argv[optind]) + 1); mbstowcs (domain_name, argv[optind], strlen (argv[optind]) + 1);
rc = netgetdcname (server, domain_name, (void *) &servername); rc = NetGetDCName (server, domain_name, (void *) &servername);
netapibufferfree (server); NetApiBufferFree (server);
} }
if (rc != ERROR_SUCCESS) if (rc != ERROR_SUCCESS)
{ {
@ -761,7 +723,7 @@ main (int argc, char **argv)
} }
enum_users (servername, print_sids, print_cygpath, passed_home_path, enum_users (servername, print_sids, print_cygpath, passed_home_path,
id_offset * i++, disp_username); id_offset * i++, disp_username);
netapibufferfree (pdci ? (PVOID) pdci : (PVOID) servername); NetApiBufferFree (pdci ? (PVOID) pdci : (PVOID) servername);
} }
while (++optind < argc); while (++optind < argc);