* mkpasswd.cc (current_user): Create.
(usage): Reorganize to support Win95/98/ME. (main): Add option for -c. Reorganize to parse options for Win95/98/ME and to call current_user. Add username in gecos field on Win95/98/ME. * mkgroup.cc (enum_groups): Print gid with %u. (print_win_error): Create from passwd.cc. (current_group): Create. (usage): Reorganize to support Win95/98/ME. (main): Add option for -c. Reorganize to parse options for Win95/98/ME and to call current_group.
This commit is contained in:
parent
afa53b05b0
commit
f1c9046a57
|
@ -1,3 +1,17 @@
|
||||||
|
2003-01-07 Pierre Humblet <pierre.humblet@ieee.org>
|
||||||
|
|
||||||
|
* mkpasswd.cc (current_user): Create.
|
||||||
|
(usage): Reorganize to support Win95/98/ME.
|
||||||
|
(main): Add option for -c. Reorganize to parse options for
|
||||||
|
Win95/98/ME and to call current_user. Add username in gecos field
|
||||||
|
on Win95/98/ME.
|
||||||
|
* mkgroup.cc (enum_groups): Print gid with %u.
|
||||||
|
(print_win_error): Create from passwd.cc.
|
||||||
|
(current_group): Create.
|
||||||
|
(usage): Reorganize to support Win95/98/ME.
|
||||||
|
(main): Add option for -c. Reorganize to parse options for
|
||||||
|
Win95/98/ME and to call current_group.
|
||||||
|
|
||||||
2002-12-14 Pierre Humblet <pierre.humblet@ieee.org>
|
2002-12-14 Pierre Humblet <pierre.humblet@ieee.org>
|
||||||
|
|
||||||
* setfacl.c (main): Place a single : after other and mask.
|
* setfacl.c (main): Place a single : after other and mask.
|
||||||
|
|
|
@ -360,7 +360,7 @@ enum_groups (LPWSTR servername, int print_sids, int print_users, int id_offset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf ("%s:%s:%d:", groupname,
|
printf ("%s:%s:%u:", groupname,
|
||||||
print_sids ? put_sid (psid) : "",
|
print_sids ? put_sid (psid) : "",
|
||||||
gid + id_offset);
|
gid + id_offset);
|
||||||
if (print_users)
|
if (print_users)
|
||||||
|
@ -420,29 +420,95 @@ print_special (int print_sids,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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, "mkgroup: [%lu] %s", code, buf);
|
||||||
|
else
|
||||||
|
fprintf (stderr, "mkgroup: error %lu", code);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
current_group (int print_sids, int print_users, int id_offset)
|
||||||
|
{
|
||||||
|
char name[UNLEN + 1], *envname, *envdomain;
|
||||||
|
DWORD len;
|
||||||
|
HANDLE ptok;
|
||||||
|
int errpos = 0;
|
||||||
|
struct {
|
||||||
|
PSID psid;
|
||||||
|
int buffer[10];
|
||||||
|
} tg;
|
||||||
|
|
||||||
|
|
||||||
|
if ((!GetUserName (name, (len = sizeof (name), &len)) && (errpos = __LINE__))
|
||||||
|
|| !name[0]
|
||||||
|
|| !(envname = getenv("USERNAME"))
|
||||||
|
|| strcasecmp (envname, name)
|
||||||
|
|| (!GetComputerName (name, (len = sizeof (name), &len))
|
||||||
|
&& (errpos = __LINE__))
|
||||||
|
|| !(envdomain = getenv("USERDOMAIN"))
|
||||||
|
|| !envdomain[0]
|
||||||
|
|| !strcasecmp (envdomain, name)
|
||||||
|
|| (!OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &ptok)
|
||||||
|
&& (errpos = __LINE__))
|
||||||
|
|| (!GetTokenInformation (ptok, TokenPrimaryGroup, &tg, sizeof tg, &len)
|
||||||
|
&& (errpos = __LINE__))
|
||||||
|
|| (!CloseHandle (ptok) && (errpos = __LINE__)))
|
||||||
|
{
|
||||||
|
if (errpos)
|
||||||
|
{
|
||||||
|
print_win_error (GetLastError ());
|
||||||
|
fprintf(stderr, " on line %d\n", errpos);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int gid = *GetSidSubAuthority (tg.psid, *GetSidSubAuthorityCount(tg.psid) - 1);
|
||||||
|
|
||||||
|
printf ("mkgroup_l_d:%s:%u:", print_sids ? put_sid (tg.psid) : "",
|
||||||
|
gid + id_offset);
|
||||||
|
if (print_users)
|
||||||
|
printf("%s", envname);
|
||||||
|
printf ("\n");
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
usage (FILE * stream, int status)
|
usage (FILE * stream, int isNT)
|
||||||
{
|
{
|
||||||
fprintf (stream, "Usage: mkgroup [OPTION]... [domain]\n\n"
|
fprintf (stream, "Usage: mkgroup [OPTION]... [domain]\n\n"
|
||||||
"This program prints a /etc/group file to stdout\n\n"
|
"This program prints a /etc/group file to stdout\n\n"
|
||||||
"Options:\n"
|
"Options:\n");
|
||||||
" -l,--local print local group information\n"
|
if (isNT)
|
||||||
" -d,--domain print global group information from the domain\n"
|
fprintf (stream, " -l,--local print local group information\n"
|
||||||
" specified (or from the current domain if there is\n"
|
" -c,--current print current group, if a domain account\n"
|
||||||
" no domain specified)\n"
|
" -d,--domain print global group information from the domain\n"
|
||||||
" -o,--id-offset offset change the default offset (10000) added to uids\n"
|
" specified (or from the current domain if there is\n"
|
||||||
" in domain accounts.\n"
|
" no domain specified)\n"
|
||||||
" -s,--no-sids don't print SIDs in pwd field\n"
|
" -o,--id-offset offset change the default offset (10000) added to uids\n"
|
||||||
" (this affects ntsec)\n"
|
" in domain accounts.\n"
|
||||||
" -u,--users print user list in gr_mem field\n"
|
" -s,--no-sids don't print SIDs in pwd field\n"
|
||||||
" -h,--help print this message\n\n"
|
" (this affects ntsec)\n"
|
||||||
" -v,--version print version information and exit\n\n"
|
" -u,--users print user list in gr_mem field\n");
|
||||||
"One of `-l' or `-d' must be given on NT/W2K.\n");
|
fprintf (stream, " -h,--help print this message\n"
|
||||||
return status;
|
" -v,--version print version information and exit\n\n");
|
||||||
|
if (isNT)
|
||||||
|
fprintf (stream, "One of `-l' or `-d' must be given.\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct option longopts[] = {
|
struct option longopts[] = {
|
||||||
{"local", no_argument, NULL, 'l'},
|
{"local", no_argument, NULL, 'l'},
|
||||||
|
{"current", no_argument, NULL, 'c'},
|
||||||
{"domain", no_argument, NULL, 'd'},
|
{"domain", no_argument, NULL, 'd'},
|
||||||
{"id-offset", required_argument, NULL, 'o'},
|
{"id-offset", required_argument, NULL, 'o'},
|
||||||
{"no-sids", no_argument, NULL, 's'},
|
{"no-sids", no_argument, NULL, 's'},
|
||||||
|
@ -452,7 +518,7 @@ struct option longopts[] = {
|
||||||
{0, no_argument, NULL, 0}
|
{0, no_argument, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
char opts[] = "ldo:suhv";
|
char opts[] = "lcdo:suhv";
|
||||||
|
|
||||||
void
|
void
|
||||||
print_version ()
|
print_version ()
|
||||||
|
@ -484,11 +550,13 @@ main (int argc, char **argv)
|
||||||
DWORD rc = ERROR_SUCCESS;
|
DWORD rc = ERROR_SUCCESS;
|
||||||
WCHAR domain_name[100];
|
WCHAR domain_name[100];
|
||||||
int print_local = 0;
|
int print_local = 0;
|
||||||
|
int print_current = 0;
|
||||||
int print_domain = 0;
|
int print_domain = 0;
|
||||||
int print_sids = 1;
|
int print_sids = 1;
|
||||||
int print_users = 0;
|
int print_users = 0;
|
||||||
int domain_specified = 0;
|
int domain_specified = 0;
|
||||||
int id_offset = 10000;
|
int id_offset = 10000;
|
||||||
|
int isNT;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
char name[256], dom[256];
|
char name[256], dom[256];
|
||||||
|
@ -502,65 +570,68 @@ main (int argc, char **argv)
|
||||||
NTSTATUS ret;
|
NTSTATUS ret;
|
||||||
PPOLICY_PRIMARY_DOMAIN_INFO pdi;
|
PPOLICY_PRIMARY_DOMAIN_INFO pdi;
|
||||||
|
|
||||||
if (GetVersion () < 0x80000000)
|
isNT = (GetVersion () < 0x80000000);
|
||||||
|
|
||||||
|
if (isNT && argc == 1)
|
||||||
|
return usage(stderr, isNT);
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (argc == 1)
|
while ((i = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
|
||||||
return usage(stderr, 1);
|
switch (i)
|
||||||
else
|
|
||||||
{
|
{
|
||||||
while ((i = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
|
case 'l':
|
||||||
switch (i)
|
print_local = 1;
|
||||||
{
|
break;
|
||||||
case 'l':
|
case 'c':
|
||||||
print_local = 1;
|
print_current = 1;
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
print_domain = 1;
|
print_domain = 1;
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
id_offset = strtol (optarg, NULL, 10);
|
id_offset = strtol (optarg, NULL, 10);
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
print_sids = 0;
|
print_sids = 0;
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
print_users = 1;
|
print_users = 1;
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
return usage (stdout, 0);
|
usage (stdout, isNT);
|
||||||
case 'v':
|
return 0;
|
||||||
print_version ();
|
case 'v':
|
||||||
return 0;
|
print_version ();
|
||||||
default:
|
return 0;
|
||||||
fprintf (stderr, "Try `%s --help' for more information.\n", argv[0]);
|
default:
|
||||||
return 1;
|
fprintf (stderr, "Try `%s --help' for more information.\n", argv[0]);
|
||||||
}
|
return 1;
|
||||||
if (!print_local && !print_domain)
|
|
||||||
{
|
|
||||||
fprintf (stderr, "%s: Specify one of `-l' or `-d'\n", argv[0]);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (optind < argc)
|
|
||||||
{
|
|
||||||
if (!print_domain)
|
|
||||||
{
|
|
||||||
fprintf (stderr, "%s: A domain name is only accepted "
|
|
||||||
"when `-d' is given.\n", argv[0]);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
mbstowcs (domain_name, argv[optind], (strlen (argv[optind]) + 1));
|
|
||||||
domain_specified = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This takes Windows 9x/ME into account. */
|
/* This takes Windows 9x/ME into account. */
|
||||||
if (GetVersion () >= 0x80000000)
|
if (!isNT)
|
||||||
{
|
{
|
||||||
printf ("unknown::%ld:\n", DOMAIN_ALIAS_RID_ADMINS);
|
printf ("unknown::%ld:\n", DOMAIN_ALIAS_RID_ADMINS);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!print_local && !print_domain)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: Specify one of `-l' or `-d'\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (optind < argc)
|
||||||
|
{
|
||||||
|
if (!print_domain)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: A domain name is only accepted "
|
||||||
|
"when `-d' is given.\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
mbstowcs (domain_name, argv[optind], (strlen (argv[optind]) + 1));
|
||||||
|
domain_specified = 1;
|
||||||
|
}
|
||||||
if (!load_netapi ())
|
if (!load_netapi ())
|
||||||
{
|
{
|
||||||
fprintf (stderr, "Failed loading symbols from netapi32.dll "
|
fprintf (stderr, "Failed loading symbols from netapi32.dll "
|
||||||
|
@ -647,5 +718,8 @@ main (int argc, char **argv)
|
||||||
if (print_local)
|
if (print_local)
|
||||||
enum_local_groups (print_sids, print_users);
|
enum_local_groups (print_sids, print_users);
|
||||||
|
|
||||||
|
if (print_current && !print_domain)
|
||||||
|
current_group (print_sids, print_users, id_offset);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <lmapibuf.h>
|
#include <lmapibuf.h>
|
||||||
#include <sys/fcntl.h>
|
#include <sys/fcntl.h>
|
||||||
#include <lmerr.h>
|
#include <lmerr.h>
|
||||||
|
#include <lmcons.h>
|
||||||
|
|
||||||
static const char version[] = "$Revision$";
|
static const char version[] = "$Revision$";
|
||||||
|
|
||||||
|
@ -125,6 +126,94 @@ print_win_error(DWORD code)
|
||||||
fprintf (stderr, "mkpasswd: error %lu", code);
|
fprintf (stderr, "mkpasswd: error %lu", code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
current_user (int print_sids, int print_cygpath,
|
||||||
|
const char * passed_home_path, int id_offset, const char * disp_username)
|
||||||
|
{
|
||||||
|
char name[UNLEN + 1], *envname, *envdomain;
|
||||||
|
DWORD len;
|
||||||
|
HANDLE ptok;
|
||||||
|
int errpos = 0;
|
||||||
|
struct {
|
||||||
|
PSID psid;
|
||||||
|
int buffer[10];
|
||||||
|
} tu, tg;
|
||||||
|
|
||||||
|
|
||||||
|
if ((!GetUserName (name, (len = sizeof (name), &len)) && (errpos = __LINE__))
|
||||||
|
|| !name[0]
|
||||||
|
|| !(envname = getenv("USERNAME"))
|
||||||
|
|| strcasecmp (envname, name)
|
||||||
|
|| (disp_username && strcasecmp(envname, disp_username))
|
||||||
|
|| (!GetComputerName (name, (len = sizeof (name), &len))
|
||||||
|
&& (errpos = __LINE__))
|
||||||
|
|| !(envdomain = getenv("USERDOMAIN"))
|
||||||
|
|| !envdomain[0]
|
||||||
|
|| !strcasecmp (envdomain, name)
|
||||||
|
|| (!OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &ptok)
|
||||||
|
&& (errpos = __LINE__))
|
||||||
|
|| (!GetTokenInformation (ptok, TokenUser, &tu, sizeof tu, &len)
|
||||||
|
&& (errpos = __LINE__))
|
||||||
|
|| (!GetTokenInformation (ptok, TokenPrimaryGroup, &tg, sizeof tg, &len)
|
||||||
|
&& (errpos = __LINE__))
|
||||||
|
|| (!CloseHandle (ptok) && (errpos = __LINE__)))
|
||||||
|
{
|
||||||
|
if (errpos)
|
||||||
|
{
|
||||||
|
print_win_error (GetLastError ());
|
||||||
|
fprintf(stderr, " on line %d\n", errpos);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int uid = *GetSidSubAuthority (tu.psid, *GetSidSubAuthorityCount(tu.psid) - 1);
|
||||||
|
int gid = *GetSidSubAuthority (tg.psid, *GetSidSubAuthorityCount(tg.psid) - 1);
|
||||||
|
char homedir_psx[MAX_PATH] = {0}, homedir_w32[MAX_PATH] = {0};
|
||||||
|
|
||||||
|
char *envhomedrive = getenv ("HOMEDRIVE");
|
||||||
|
char *envhomepath = getenv ("HOMEPATH");
|
||||||
|
|
||||||
|
if (passed_home_path[0] == '\0')
|
||||||
|
{
|
||||||
|
if (envhomepath && envhomepath[0])
|
||||||
|
{
|
||||||
|
if (envhomedrive)
|
||||||
|
strlcpy (homedir_w32, envhomedrive, sizeof (homedir_w32));
|
||||||
|
if (envhomepath[0] != '\\')
|
||||||
|
strlcat (homedir_w32, "\\", sizeof (homedir_w32));
|
||||||
|
strlcat (homedir_w32, envhomepath, sizeof (homedir_w32));
|
||||||
|
if (print_cygpath)
|
||||||
|
cygwin_conv_to_posix_path (homedir_w32, homedir_psx);
|
||||||
|
else
|
||||||
|
psx_dir (homedir_w32, homedir_psx);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strlcpy (homedir_psx, "/home/", sizeof (homedir_psx));
|
||||||
|
strlcat (homedir_psx, envname, sizeof (homedir_psx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strlcpy (homedir_psx, passed_home_path, sizeof (homedir_psx));
|
||||||
|
strlcat (homedir_psx, envname, sizeof (homedir_psx));
|
||||||
|
}
|
||||||
|
|
||||||
|
printf ("%s:unused_by_nt/2000/xp:%d:%d:%s%s%s%s%s%s%s%s:%s:/bin/bash\n",
|
||||||
|
envname,
|
||||||
|
uid + id_offset,
|
||||||
|
gid + id_offset,
|
||||||
|
envname,
|
||||||
|
print_sids ? "," : "",
|
||||||
|
print_sids ? "U-" : "",
|
||||||
|
print_sids ? envdomain : "",
|
||||||
|
print_sids ? "\\" : "",
|
||||||
|
print_sids ? envname : "",
|
||||||
|
print_sids ? "," : "",
|
||||||
|
print_sids ? put_sid (tu.psid) : "",
|
||||||
|
homedir_psx);
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
@ -396,31 +485,35 @@ print_special (int print_sids,
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
usage (FILE * stream, int status)
|
usage (FILE * stream, int isNT)
|
||||||
{
|
{
|
||||||
fprintf (stream, "Usage: mkpasswd [OPTION]... [domain]\n\n"
|
fprintf (stream, "Usage: mkpasswd [OPTION]... [domain]\n\n"
|
||||||
"This program prints a /etc/passwd file to stdout\n\n"
|
"This program prints a /etc/passwd file to stdout\n\n"
|
||||||
"Options:\n"
|
"Options:\n");
|
||||||
" -l,--local print local user accounts\n"
|
if (isNT)
|
||||||
" -d,--domain print domain accounts (from current domain\n"
|
fprintf (stream, " -l,--local print local user accounts\n"
|
||||||
" if no domain specified)\n"
|
" -c,--current print current account, if a domain account\n"
|
||||||
" -o,--id-offset offset change the default offset (10000) added to uids\n"
|
" -d,--domain print domain accounts (from current domain\n"
|
||||||
" in domain accounts.\n"
|
" if no domain specified)\n"
|
||||||
" -g,--local-groups print local group information too\n"
|
" -o,--id-offset offset change the default offset (10000) added to uids\n"
|
||||||
" if no domain specified\n"
|
" in domain accounts.\n"
|
||||||
" -m,--no-mount don't use mount points for home dir\n"
|
" -g,--local-groups print local group information too\n"
|
||||||
" -s,--no-sids don't print SIDs in GCOS field\n"
|
" if no domain specified\n"
|
||||||
" (this affects ntsec)\n"
|
" -m,--no-mount don't use mount points for home dir\n"
|
||||||
" -p,--path-to-home path use specified path instead of user account home dir\n"
|
" -s,--no-sids don't print SIDs in GCOS field\n"
|
||||||
|
" (this affects ntsec)\n");
|
||||||
|
fprintf (stream, " -p,--path-to-home path use specified path instead of user account home dir\n"
|
||||||
" -u,--username username only return information for the specified user\n"
|
" -u,--username username only return information for the specified user\n"
|
||||||
" -h,--help displays this message\n"
|
" -h,--help displays this message\n"
|
||||||
" -v,--version version information and exit\n\n"
|
" -v,--version version information and exit\n\n");
|
||||||
"One of `-l', `-d' or `-g' must be given on NT/W2K.\n");
|
if (isNT)
|
||||||
return status;
|
fprintf (stream, "One of `-l', `-d' or `-g' must be given.\n");
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct option longopts[] = {
|
struct option longopts[] = {
|
||||||
{"local", no_argument, NULL, 'l'},
|
{"local", no_argument, NULL, 'l'},
|
||||||
|
{"current", no_argument, NULL, 'c'},
|
||||||
{"domain", no_argument, NULL, 'd'},
|
{"domain", no_argument, NULL, 'd'},
|
||||||
{"id-offset", required_argument, NULL, 'o'},
|
{"id-offset", required_argument, NULL, 'o'},
|
||||||
{"local-groups", no_argument, NULL, 'g'},
|
{"local-groups", no_argument, NULL, 'g'},
|
||||||
|
@ -433,7 +526,7 @@ struct option longopts[] = {
|
||||||
{0, no_argument, NULL, 0}
|
{0, no_argument, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
char opts[] = "ldo:gsmhp:u:v";
|
char opts[] = "lcdo:gsmhp:u:v";
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_version ()
|
print_version ()
|
||||||
|
@ -465,6 +558,7 @@ main (int argc, char **argv)
|
||||||
DWORD rc = ERROR_SUCCESS;
|
DWORD rc = ERROR_SUCCESS;
|
||||||
WCHAR domain_name[200];
|
WCHAR domain_name[200];
|
||||||
int print_local = 0;
|
int print_local = 0;
|
||||||
|
int print_current = 0;
|
||||||
int print_domain = 0;
|
int print_domain = 0;
|
||||||
int print_local_groups = 0;
|
int print_local_groups = 0;
|
||||||
int domain_name_specified = 0;
|
int domain_name_specified = 0;
|
||||||
|
@ -472,103 +566,108 @@ main (int argc, char **argv)
|
||||||
int print_cygpath = 1;
|
int print_cygpath = 1;
|
||||||
int id_offset = 10000;
|
int id_offset = 10000;
|
||||||
int i;
|
int i;
|
||||||
|
int isNT;
|
||||||
char *disp_username = NULL;
|
char *disp_username = NULL;
|
||||||
|
|
||||||
char name[256], passed_home_path[MAX_PATH];
|
char name[256], passed_home_path[MAX_PATH];
|
||||||
DWORD len;
|
DWORD len;
|
||||||
|
|
||||||
|
isNT = (GetVersion () < 0x80000000);
|
||||||
passed_home_path[0] = '\0';
|
passed_home_path[0] = '\0';
|
||||||
if (!isatty (1))
|
if (!isatty (1))
|
||||||
setmode (1, O_BINARY);
|
setmode (1, O_BINARY);
|
||||||
|
|
||||||
if (GetVersion () < 0x80000000)
|
if (isNT && argc == 1)
|
||||||
|
return usage (stderr, isNT);
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (argc == 1)
|
while ((i = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
|
||||||
return usage (stderr, 1);
|
switch (i)
|
||||||
else
|
{
|
||||||
{
|
case 'l':
|
||||||
while ((i = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
|
print_local = 1;
|
||||||
switch (i)
|
break;
|
||||||
{
|
case 'c':
|
||||||
case 'l':
|
print_current = 1;
|
||||||
print_local = 1;
|
break;
|
||||||
break;
|
case 'd':
|
||||||
case 'd':
|
print_domain = 1;
|
||||||
print_domain = 1;
|
break;
|
||||||
break;
|
case 'o':
|
||||||
case 'o':
|
id_offset = strtol (optarg, NULL, 10);
|
||||||
id_offset = strtol (optarg, NULL, 10);
|
break;
|
||||||
break;
|
case 'g':
|
||||||
case 'g':
|
print_local_groups = 1;
|
||||||
print_local_groups = 1;
|
break;
|
||||||
break;
|
case 's':
|
||||||
case 's':
|
print_sids = 0;
|
||||||
print_sids = 0;
|
break;
|
||||||
break;
|
case 'm':
|
||||||
case 'm':
|
print_cygpath = 0;
|
||||||
print_cygpath = 0;
|
break;
|
||||||
break;
|
case 'p':
|
||||||
case 'p':
|
if (optarg[0] != '/')
|
||||||
if (optarg[0] != '/')
|
|
||||||
{
|
|
||||||
fprintf (stderr, "%s: `%s' is not a fully qualified path.\n",
|
|
||||||
argv[0], optarg);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
strcpy (passed_home_path, optarg);
|
|
||||||
if (optarg[strlen (optarg)-1] != '/')
|
|
||||||
strcat (passed_home_path, "/");
|
|
||||||
break;
|
|
||||||
case 'u':
|
|
||||||
disp_username = optarg;
|
|
||||||
break;
|
|
||||||
case 'h':
|
|
||||||
return usage (stdout, 0);
|
|
||||||
case 'v':
|
|
||||||
print_version ();
|
|
||||||
return 0;
|
|
||||||
default:
|
|
||||||
fprintf (stderr, "Try `%s --help' for more information.\n", argv[0]);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (!print_local && !print_domain && !print_local_groups)
|
|
||||||
{
|
{
|
||||||
fprintf (stderr, "%s: Specify one of `-l', `-d' or `-g'\n", argv[0]);
|
fprintf (stderr, "%s: `%s' is not a fully qualified path.\n",
|
||||||
|
argv[0], optarg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (optind < argc)
|
strcpy (passed_home_path, optarg);
|
||||||
{
|
if (optarg[strlen (optarg)-1] != '/')
|
||||||
if (!print_domain)
|
strcat (passed_home_path, "/");
|
||||||
{
|
break;
|
||||||
fprintf (stderr, "%s: A domain name is only accepted "
|
case 'u':
|
||||||
"when `-d' is given.\n", argv[0]);
|
disp_username = optarg;
|
||||||
return 1;
|
break;
|
||||||
}
|
case 'h':
|
||||||
mbstowcs (domain_name, argv[optind], (strlen (argv[optind]) + 1));
|
usage (stdout, isNT);
|
||||||
domain_name_specified = 1;
|
return 0;
|
||||||
}
|
case 'v':
|
||||||
}
|
print_version ();
|
||||||
|
return 0;
|
||||||
|
default:
|
||||||
|
fprintf (stderr, "Try `%s --help' for more information.\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (!isNT)
|
||||||
/* This takes Windows 9x/ME into account. */
|
|
||||||
if (GetVersion () >= 0x80000000)
|
|
||||||
{
|
{
|
||||||
/* Same behaviour as in cygwin/uinfo.cc (internal_getlogin). */
|
/* This takes Windows 9x/ME into account. */
|
||||||
if (!GetUserName (name, (len = 256, &len)))
|
if (!disp_username)
|
||||||
strcpy (name, "unknown");
|
{
|
||||||
|
if (GetUserName (name, (len = 256, &len)))
|
||||||
|
disp_username = name;
|
||||||
|
else
|
||||||
|
/* Same behaviour as in cygwin/shared.cc (memory_init). */
|
||||||
|
disp_username = (char *) "unknown";
|
||||||
|
}
|
||||||
|
|
||||||
if (passed_home_path[0] == '\0')
|
if (passed_home_path[0] == '\0')
|
||||||
strcpy (passed_home_path, "/home/");
|
strcpy (passed_home_path, "/home/");
|
||||||
|
|
||||||
printf ("%s:*:%ld:%ld::%s%s:/bin/bash\n", name,
|
printf ("%s:*:%ld:%ld:%s:%s%s:/bin/bash\n", disp_username,
|
||||||
DOMAIN_USER_RID_ADMIN,
|
DOMAIN_USER_RID_ADMIN,
|
||||||
DOMAIN_ALIAS_RID_ADMINS,
|
DOMAIN_ALIAS_RID_ADMINS,
|
||||||
|
disp_username,
|
||||||
passed_home_path,
|
passed_home_path,
|
||||||
name);
|
disp_username);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if (!print_local && !print_domain && !print_local_groups)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: Specify one of `-l', `-d' or `-g'\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (optind < argc)
|
||||||
|
{
|
||||||
|
if (!print_domain)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: A domain name is only accepted "
|
||||||
|
"when `-d' is given.\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
mbstowcs (domain_name, argv[optind], (strlen (argv[optind]) + 1));
|
||||||
|
domain_name_specified = 1;
|
||||||
|
}
|
||||||
if (!load_netapi ())
|
if (!load_netapi ())
|
||||||
{
|
{
|
||||||
print_win_error(GetLastError ());
|
print_win_error(GetLastError ());
|
||||||
|
@ -622,6 +721,10 @@ main (int argc, char **argv)
|
||||||
enum_users (NULL, print_sids, print_cygpath, passed_home_path, 0,
|
enum_users (NULL, print_sids, print_cygpath, passed_home_path, 0,
|
||||||
disp_username);
|
disp_username);
|
||||||
|
|
||||||
|
if (print_current && !print_domain)
|
||||||
|
current_user(print_sids, print_cygpath, passed_home_path,
|
||||||
|
id_offset, disp_username);
|
||||||
|
|
||||||
if (servername)
|
if (servername)
|
||||||
netapibufferfree (servername);
|
netapibufferfree (servername);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue