* mkgroup.cc (netapibufferallocate,netgroupgetinfo): New function

pointers.
	(load_netapi): Load NetApiBufferAllocate and NetGroupGetInfo.
	(enum_local_groups,enum_groups): Add disp_groupname parameter.
	Load info for disp_groupname if specified.
	(usage): Add description of "-g/--group" option.
	(longopts,opts): Add "-g/--group" option.
	(main): Process "-g/--group" option.
	* utils.sgml (mkgroup): Add description of "-g/--group" option
This commit is contained in:
Corinna Vinschen 2004-07-12 16:52:16 +00:00
parent 96979a1832
commit e3118d880b
3 changed files with 67 additions and 10 deletions

View File

@ -1,3 +1,15 @@
2004-07-12 Igor Pechtchanski <pechtcha@cs.nyu.edu>
* mkgroup.cc (netapibufferallocate,netgroupgetinfo): New function
pointers.
(load_netapi): Load NetApiBufferAllocate and NetGroupGetInfo.
(enum_local_groups,enum_groups): Add disp_groupname parameter.
Load info for disp_groupname if specified.
(usage): Add description of "-g/--group" option.
(longopts,opts): Add "-g/--group" option.
(main): Process "-g/--group" option.
* utils.sgml (mkgroup): Add description of "-g/--group" option
2004-06-15 Alan Modra <amodra@bigpond.net.au> 2004-06-15 Alan Modra <amodra@bigpond.net.au>
* dumper.cc (dumper::prepare_core_dump): Use bfd_get_section_size * dumper.cc (dumper::prepare_core_dump): Use bfd_get_section_size

View File

@ -25,8 +25,10 @@ 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};
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 (*netapibufferfree)(PVOID);
NET_API_STATUS WINAPI (*netgroupenum)(LPWSTR,DWORD,PBYTE*,DWORD,PDWORD,PDWORD,PDWORD); 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 (*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 (*netlocalgroupgetmembers)(LPWSTR,LPWSTR,DWORD,PBYTE*,DWORD,PDWORD,PDWORD,PDWORD);
NET_API_STATUS WINAPI (*netgetdcname)(LPWSTR,LPWSTR,PBYTE*); NET_API_STATUS WINAPI (*netgetdcname)(LPWSTR,LPWSTR,PBYTE*);
@ -49,10 +51,14 @@ load_netapi ()
if (!h) if (!h)
return FALSE; return FALSE;
if (!(netapibufferallocate = (void *) GetProcAddress (h, "NetApiBufferAllocate")))
return FALSE;
if (!(netapibufferfree = (void *) GetProcAddress (h, "NetApiBufferFree"))) if (!(netapibufferfree = (void *) GetProcAddress (h, "NetApiBufferFree")))
return FALSE; return FALSE;
if (!(netgroupenum = (void *) GetProcAddress (h, "NetGroupEnum"))) if (!(netgroupenum = (void *) GetProcAddress (h, "NetGroupEnum")))
return FALSE; return FALSE;
if (!(netgroupgetinfo = (void *) GetProcAddress (h, "NetGroupGetInfo")))
return FALSE;
if (!(netgroupgetusers = (void *) GetProcAddress (h, "NetGroupGetUsers"))) if (!(netgroupgetusers = (void *) GetProcAddress (h, "NetGroupGetUsers")))
return FALSE; return FALSE;
if (!(netlocalgroupenum = (void *) GetProcAddress (h, "NetLocalGroupEnum"))) if (!(netlocalgroupenum = (void *) GetProcAddress (h, "NetLocalGroupEnum")))
@ -158,18 +164,27 @@ enum_local_users (LPWSTR groupname)
} }
int int
enum_local_groups (int print_sids, int print_users) enum_local_groups (int print_sids, int print_users, 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];
DWORD rc; DWORD rc;
do do
{ {
DWORD i; DWORD i;
if (disp_groupname != NULL)
{
MultiByteToWideChar (CP_ACP, 0, disp_groupname, -1, uni_name, 512 );
rc = netapibufferallocate(sizeof(LOCALGROUP_INFO_0), (void *) &buffer );
buffer[0].lgrpi0_name = (LPWSTR) & uni_name;
entriesread=1;
}
else
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)
@ -276,12 +291,14 @@ enum_users (LPWSTR servername, LPWSTR groupname)
} }
void void
enum_groups (LPWSTR servername, int print_sids, int print_users, int id_offset) enum_groups (LPWSTR servername, int print_sids, int print_users, int id_offset,
char *disp_groupname)
{ {
GROUP_INFO_2 *buffer; GROUP_INFO_2 *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];
DWORD rc; DWORD rc;
char ansi_srvname[256]; char ansi_srvname[256];
@ -292,6 +309,14 @@ enum_groups (LPWSTR servername, int print_sids, int print_users, int id_offset)
{ {
DWORD i; DWORD i;
if (disp_groupname != NULL)
{
MultiByteToWideChar (CP_ACP, 0, disp_groupname, -1, uni_name, 512 );
rc = netgroupgetinfo(servername, (LPWSTR) & uni_name, 2,
(void *) &buffer );
entriesread=1;
}
else
rc = netgroupenum (servername, 2, (void *) & buffer, 1024, rc = netgroupenum (servername, 2, (void *) & buffer, 1024,
&entriesread, &totalentries, &resume_handle); &entriesread, &totalentries, &resume_handle);
switch (rc) switch (rc)
@ -493,7 +518,8 @@ usage (FILE * stream, int isNT)
" in domain accounts.\n" " in domain accounts.\n"
" -s,--no-sids don't print SIDs in pwd field\n" " -s,--no-sids don't print SIDs in pwd field\n"
" (this affects ntsec)\n" " (this affects ntsec)\n"
" -u,--users print user list in gr_mem field\n"); " -u,--users print user list in gr_mem field\n"
" -g,--group groupname only return information for the specified group\n");
fprintf (stream, " -h,--help print this message\n" fprintf (stream, " -h,--help print this message\n"
" -v,--version print version information and exit\n\n"); " -v,--version print version information and exit\n\n");
if (isNT) if (isNT)
@ -509,12 +535,13 @@ struct option longopts[] = {
{"id-offset", required_argument, NULL, 'o'}, {"id-offset", required_argument, NULL, 'o'},
{"no-sids", no_argument, NULL, 's'}, {"no-sids", no_argument, NULL, 's'},
{"users", no_argument, NULL, 'u'}, {"users", no_argument, NULL, 'u'},
{"group", required_argument, NULL, 'g'},
{"help", no_argument, NULL, 'h'}, {"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'v'}, {"version", no_argument, NULL, 'v'},
{0, no_argument, NULL, 0} {0, no_argument, NULL, 0}
}; };
char opts[] = "lcdo:suhv"; char opts[] = "lcdo:sug:hv";
void void
print_version () print_version ()
@ -552,6 +579,8 @@ main (int argc, char **argv)
int print_users = 0; int print_users = 0;
int domain_specified = 0; int domain_specified = 0;
int id_offset = 10000; int id_offset = 10000;
char *disp_groupname = NULL;
int isRoot = 0;
int isNT; int isNT;
int i; int i;
@ -593,6 +622,10 @@ main (int argc, char **argv)
case 'u': case 'u':
print_users = 1; print_users = 1;
break; break;
case 'g':
disp_groupname = optarg;
isRoot = !strcmp(disp_groupname, "root");
break;
case 'h': case 'h':
usage (stdout, isNT); usage (stdout, isNT);
return 0; return 0;
@ -635,6 +668,8 @@ main (int argc, char **argv)
} }
if (print_local) if (print_local)
{
if (isRoot)
{ {
/* /*
* Very special feature for the oncoming future: * Very special feature for the oncoming future:
@ -643,7 +678,10 @@ main (int argc, char **argv)
* 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)
{
/* /*
* Get `system' group * Get `system' group
*/ */
@ -691,8 +729,12 @@ main (int argc, char **argv)
0, 0,
0, 0,
0); 0);
}
enum_local_groups (print_sids, print_users); if (!isRoot)
{
enum_local_groups (print_sids, print_users, disp_groupname);
}
} }
i = 1; i = 1;
@ -713,7 +755,7 @@ 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);
netapibufferfree (servername); netapibufferfree (servername);
} }
while (++optind < argc); while (++optind < argc);

View File

@ -424,6 +424,7 @@ Options:
-s,--no-sids don't print SIDs in pwd field -s,--no-sids don't print SIDs in pwd field
(this affects ntsec) (this affects ntsec)
-u,--users print user list in gr_mem field -u,--users print user list in gr_mem field
-g,--group groupname only return information for the specified group\n");
-h,--help print this message -h,--help print this message
-v,--version print version information and exit -v,--version print version information and exit
@ -471,6 +472,8 @@ gr_mem (last) field. Note that this can greatly increase
the time for <command>mkgroup</command> to run in a large domain. the time for <command>mkgroup</command> to run in a large domain.
Having gr_mem fields is helpful when a domain user logs in remotely Having gr_mem fields is helpful when a domain user logs in remotely
while the local machine is disconnected from the Domain Controller. while the local machine is disconnected from the Domain Controller.
The <literal>-g</literal> option only prints the information for
one group.
</para> </para>
</sect2> </sect2>