Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2008-08-17 20:45:44 +0400
committerChristopher Faylor <me@cgf.cx>2008-08-17 20:45:44 +0400
commit6510edf4bc4b61b49272970d1a311492e5b99285 (patch)
tree309daba5d633c38703374514e85f2a8550e646c6 /winsup
parentf609b6715a96aecbe0eeba55e0bf110eeaf11481 (diff)
* Makefile.in (ALL_LDFLAGS): Add --enable-auto-import option to quiet ld
warnings. * mkgroup.c: Change all global variables and most functions to static. (enum_local_groups): Add a print_current parameter to control whether entries for everything should be printed or just the current user. (enum_groups): Ditto. (main): Move call fetch_current_pgrp_sid earlier to avoid a NULL deference when no command line arguments are specified. Accommodate argument changes to above functions. Avoid printing SYSTEM account when print_current is specified. Issue error when extra stuff is found on the command line. * mkpasswd.c: Change all global variables and most functions to static. (enum_users): Add a print_current parameter to control whether entries for everything should be printed or just the current user. (main): Move call fetch_current_user_sid earlier to avoid a NULL deference when no command line arguments are specified. Accommodate argument change to above function. Avoid printing standard accounts when print_current is specified. Issue error when extra stuff is found on the command line.
Diffstat (limited to 'winsup')
-rw-r--r--winsup/utils/ChangeLog22
-rw-r--r--winsup/utils/Makefile.in2
-rw-r--r--winsup/utils/mkgroup.c137
-rw-r--r--winsup/utils/mkpasswd.c112
4 files changed, 162 insertions, 111 deletions
diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog
index ee94eec8b..583304810 100644
--- a/winsup/utils/ChangeLog
+++ b/winsup/utils/ChangeLog
@@ -1,3 +1,25 @@
+2008-08-17 Christopher Faylor <me+cygwin@cgf.cx>
+
+ * Makefile.in (ALL_LDFLAGS): Add --enable-auto-import option to quiet
+ ld warnings.
+ * mkgroup.c: Change all global variables and most functions to static.
+ (enum_local_groups): Add a print_current parameter to control whether
+ entries for everything should be printed or just the current user.
+ (enum_groups): Ditto.
+ (main): Move call fetch_current_pgrp_sid earlier to avoid a NULL
+ deference when no command line arguments are specified. Accommodate
+ argument changes to above functions. Avoid printing SYSTEM account
+ when print_current is specified. Issue error when extra stuff is found
+ on the command line.
+ * mkpasswd.c: Change all global variables and most functions to static.
+ (enum_users): Add a print_current parameter to control whether entries
+ for everything should be printed or just the current user.
+ (main): Move call fetch_current_user_sid earlier to avoid a NULL
+ deference when no command line arguments are specified. Accommodate
+ argument change to above function. Avoid printing standard accounts
+ when print_current is specified. Issue error when extra stuff is found
+ on the command line.
+
2008-08-15 Corinna Vinschen <corinna@vinschen.de>
* mkgroup.c (fetch_current_pgrp_sid): New function to fetch primary
diff --git a/winsup/utils/Makefile.in b/winsup/utils/Makefile.in
index c8dd4c39d..3715f0aab 100644
--- a/winsup/utils/Makefile.in
+++ b/winsup/utils/Makefile.in
@@ -41,7 +41,7 @@ include $(srcdir)/../Makefile.common
.PHONY: all install clean realclean warn_dumper warn_cygcheck_zlib
ALL_LDLIBS := -lnetapi32 -ladvapi32
-ALL_LDFLAGS := -B$(newlib_build)/libc -B$(w32api_lib) $(LDFLAGS) $(ALL_LDLIBS)
+ALL_LDFLAGS := -Wl,--enable-auto-import -B$(newlib_build)/libc -B$(w32api_lib) $(LDFLAGS) $(ALL_LDLIBS)
ALL_DEP_LDLIBS := $(cygwin_build)/libcygwin.a ${patsubst -l%,\
$(w32api_lib)/lib%.a,$(ALL_LDLIBS) -lkernel32 -luser32}
diff --git a/winsup/utils/mkgroup.c b/winsup/utils/mkgroup.c
index 366e02cca..48d682ee5 100644
--- a/winsup/utils/mkgroup.c
+++ b/winsup/utils/mkgroup.c
@@ -53,7 +53,7 @@ typedef struct
BOOL with_dom;
} domlist_t;
-void
+static void
_print_win_error (DWORD code, int line)
{
char buf[4096];
@@ -69,7 +69,7 @@ _print_win_error (DWORD code, int line)
fprintf (stderr, "mkgroup (%d): error %lu", line, code);
}
-void
+static void
load_dsgetdcname ()
{
HANDLE h = LoadLibrary ("netapi32.dll");
@@ -124,7 +124,7 @@ get_dcname (char *domain)
return server;
}
-char *
+static char *
put_sid (PSID psid)
{
static char s[512];
@@ -158,10 +158,10 @@ typedef struct {
int buffer[10];
} sidbuf;
-sidbuf curr_pgrp;
-BOOL got_curr_pgrp = FALSE;
+static sidbuf curr_pgrp;
+static BOOL got_curr_pgrp = FALSE;
-void
+static void
fetch_current_pgrp_sid ()
{
DWORD len;
@@ -177,7 +177,7 @@ fetch_current_pgrp_sid ()
}
}
-void
+static void
current_group (const char *sep, DWORD id_offset)
{
WCHAR grp[GNLEN + 1];
@@ -204,7 +204,7 @@ current_group (const char *sep, DWORD id_offset)
id_offset + gid);
}
-void
+static void
enum_unix_groups (domlist_t *dom_or_machine, const char *sep, DWORD id_offset,
char *unix_grp_list)
{
@@ -307,9 +307,10 @@ enum_unix_groups (domlist_t *dom_or_machine, const char *sep, DWORD id_offset,
FreeSid (psid);
}
-int
+static int
enum_local_groups (BOOL domain, domlist_t *dom_or_machine, const char *sep,
- DWORD id_offset, char *disp_groupname, int print_builtin)
+ DWORD id_offset, char *disp_groupname, int print_builtin,
+ int print_current)
{
WCHAR machine[INTERNET_MAX_HOST_NAME_LENGTH + 1];
PWCHAR servername = NULL;
@@ -332,7 +333,7 @@ enum_local_groups (BOOL domain, domlist_t *dom_or_machine, const char *sep,
{
int ret = mbstowcs (machine, d_or_m, INTERNET_MAX_HOST_NAME_LENGTH + 1);
if (ret < 1 || ret >= INTERNET_MAX_HOST_NAME_LENGTH + 1)
- {
+ {
fprintf (stderr, "%s: Invalid machine name '%s'. Skipping...\n",
__progname, d_or_m);
return 1;
@@ -352,7 +353,7 @@ enum_local_groups (BOOL domain, domlist_t *dom_or_machine, const char *sep,
buffer[0].lgrpi0_name = gname;
entriesread = 1;
}
- else
+ else
rc = NetLocalGroupEnum (servername, 0, (void *) &buffer,
MAX_PREFERRED_LENGTH, &entriesread,
&totalentries, &resume_handle);
@@ -391,25 +392,25 @@ enum_local_groups (BOOL domain, domlist_t *dom_or_machine, const char *sep,
fprintf (stderr, " (%ls)\n", buffer[i].lgrpi0_name);
continue;
}
- else if (acc_type == SidTypeDomain)
- {
- WCHAR domname[MAX_DOMAIN_NAME_LEN + GNLEN + 2];
-
- wcscpy (domname, domain_name);
- wcscat (domname, L"\\");
- wcscat (domname, buffer[i].lgrpi0_name);
- sid_length = MAX_SID_LEN;
- domname_len = MAX_DOMAIN_NAME_LEN + 1;
- if (!LookupAccountNameW (servername, domname,
- psid, &sid_length,
- domain_name, &domname_len,
- &acc_type))
- {
- print_win_error (rc);
+ else if (acc_type == SidTypeDomain)
+ {
+ WCHAR domname[MAX_DOMAIN_NAME_LEN + GNLEN + 2];
+
+ wcscpy (domname, domain_name);
+ wcscat (domname, L"\\");
+ wcscat (domname, buffer[i].lgrpi0_name);
+ sid_length = MAX_SID_LEN;
+ domname_len = MAX_DOMAIN_NAME_LEN + 1;
+ if (!LookupAccountNameW (servername, domname,
+ psid, &sid_length,
+ domain_name, &domname_len,
+ &acc_type))
+ {
+ print_win_error (rc);
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
@@ -421,7 +422,7 @@ enum_local_groups (BOOL domain, domlist_t *dom_or_machine, const char *sep,
int b;
if (!print_builtin)
- goto skip_group;
+ goto skip_group;
is_builtin = TRUE;
if (builtin_sid_cnt)
for (b = 0; b < builtin_sid_cnt; b++)
@@ -431,8 +432,12 @@ enum_local_groups (BOOL domain, domlist_t *dom_or_machine, const char *sep,
CopySid (sizeof (DBGSID), &builtin_sid_list[builtin_sid_cnt++],
psid);
}
- if (EqualSid (curr_pgrp.psid, psid))
+ if (!print_current)
+ /* fall through */;
+ else if (EqualSid (curr_pgrp.psid, psid))
got_curr_pgrp = TRUE;
+ else
+ continue;
gid = *GetSidSubAuthority (psid, *GetSidSubAuthorityCount(psid) - 1);
printf ("%ls%s%ls:%s:%ld:\n",
with_dom && !is_builtin ? domain_name : L"",
@@ -452,9 +457,9 @@ skip_group:
return 0;
}
-void
+static void
enum_groups (BOOL domain, domlist_t *dom_or_machine, const char *sep,
- DWORD id_offset, char *disp_groupname)
+ DWORD id_offset, char *disp_groupname, int print_current)
{
WCHAR machine[INTERNET_MAX_HOST_NAME_LENGTH + 1];
PWCHAR servername = NULL;
@@ -477,7 +482,7 @@ enum_groups (BOOL domain, domlist_t *dom_or_machine, const char *sep,
{
int ret = mbstowcs (machine, d_or_m, INTERNET_MAX_HOST_NAME_LENGTH + 1);
if (ret < 1 || ret >= INTERNET_MAX_HOST_NAME_LENGTH + 1)
- {
+ {
fprintf (stderr, "%s: Invalid machine name '%s'. Skipping...\n",
__progname, d_or_m);
return;
@@ -496,7 +501,7 @@ enum_groups (BOOL domain, domlist_t *dom_or_machine, const char *sep,
(void *) &buffer);
entriesread=1;
}
- else
+ else
rc = NetGroupEnum (servername, 2, (void *) & buffer,
MAX_PREFERRED_LENGTH, &entriesread, &totalentries,
&resume_handle);
@@ -554,8 +559,12 @@ enum_groups (BOOL domain, domlist_t *dom_or_machine, const char *sep,
continue;
}
}
- if (EqualSid (curr_pgrp.psid, psid))
+ if (!print_current)
+ /* fall through */;
+ else if (EqualSid (curr_pgrp.psid, psid))
got_curr_pgrp = TRUE;
+ else
+ continue;
printf ("%ls%s%ls:%s:%lu:\n",
with_dom ? domain_name : L"",
with_dom ? sep : "",
@@ -570,7 +579,7 @@ enum_groups (BOOL domain, domlist_t *dom_or_machine, const char *sep,
while (rc == ERROR_MORE_DATA);
}
-void
+static void
print_special (PSID_IDENTIFIER_AUTHORITY auth, BYTE cnt,
DWORD sub1, DWORD sub2, DWORD sub3, DWORD sub4,
DWORD sub5, DWORD sub6, DWORD sub7, DWORD sub8)
@@ -581,7 +590,7 @@ print_special (PSID_IDENTIFIER_AUTHORITY auth, BYTE cnt,
SID_NAME_USE acc_type;
if (AllocateAndInitializeSid (auth, cnt, sub1, sub2, sub3, sub4,
- sub5, sub6, sub7, sub8, &psid))
+ sub5, sub6, sub7, sub8, &psid))
{
if (LookupAccountSidW (NULL, psid,
grp, (glen = GNLEN + 1, &glen),
@@ -605,12 +614,12 @@ print_special (PSID_IDENTIFIER_AUTHORITY auth, BYTE cnt,
else
rid = sub1;
printf ("%ls:%s:%lu:\n", grp, put_sid (psid), rid);
- }
+ }
FreeSid (psid);
}
}
-int
+static int
usage (FILE * stream)
{
fprintf (stream,
@@ -672,9 +681,9 @@ struct option longopts[] = {
{0, no_argument, NULL, 0}
};
-char opts[] = "bcCd::D::g:hl::L::o:sS:uU:v";
+static char opts[] = "bcCd::D::g:hl::L::o:sS:uU:v";
-void
+static void
print_version ()
{
const char *v = strchr (version, ':');
@@ -712,7 +721,7 @@ fetch_primary_domain ()
if (!NT_SUCCESS (status))
return FALSE;
status = LsaQueryInformationPolicy (lsa, PolicyPrimaryDomainInformation,
- (PVOID *) &p_dom);
+ (PVOID *) ((void *) &p_dom));
LsaClose (lsa);
if (!NT_SUCCESS (status))
return FALSE;
@@ -741,6 +750,8 @@ main (int argc, char **argv)
load_dsgetdcname ();
in_domain = fetch_primary_domain ();
+ fetch_current_pgrp_sid ();
+
if (argc == 1)
{
print_special (&sid_nt_auth, 1, SECURITY_LOCAL_SYSTEM_RID,
@@ -748,12 +759,12 @@ main (int argc, char **argv)
if (in_domain)
{
if (!enum_local_groups (TRUE, NULL, sep_char, id_offset,
- disp_groupname, print_builtin))
- enum_groups (TRUE, NULL, sep_char, id_offset, disp_groupname);
+ disp_groupname, print_builtin, 0))
+ enum_groups (TRUE, NULL, sep_char, id_offset, disp_groupname, 0);
}
else if (!enum_local_groups (FALSE, NULL, sep_char, 0, disp_groupname,
- print_builtin))
- enum_groups (FALSE, NULL, sep_char, 0, disp_groupname);
+ print_builtin, 0))
+ enum_groups (FALSE, NULL, sep_char, 0, disp_groupname, 0);
return 0;
}
@@ -792,13 +803,13 @@ main (int argc, char **argv)
if (opt && (p = strchr (opt, ',')))
{
if (p == opt
- || !isdigit (p[1])
- || (domlist[print_domlist].id_offset = strtol (p + 1, &ep, 10)
+ || !isdigit (p[1])
+ || (domlist[print_domlist].id_offset = strtol (p + 1, &ep, 10)
, *ep))
{
fprintf (stderr, "%s: Malformed machine,offset string '%s'. "
"Skipping...\n", __progname, opt);
- break;
+ break;
}
*p = '\0';
}
@@ -819,12 +830,12 @@ skip:
"character.\n", __progname);
return 1;
}
- break;
+ break;
case 'U':
- print_unix = optarg;
+ print_unix = optarg;
break;
case 'c':
- sep_char = NULL;
+ sep_char = NULL;
/*FALLTHRU*/
case 'C':
print_current = 1;
@@ -833,7 +844,7 @@ skip:
id_offset = strtol (optarg, NULL, 10);
break;
case 'b':
- print_builtin = 0;
+ print_builtin = 0;
break;
case 's':
break;
@@ -853,13 +864,19 @@ skip:
return 1;
}
+ if (argv[optind])
+ {
+ fprintf (stderr,
+ "mkgroup: non-option command line argument `%s' is not allowed.\n"
+ "Try `mkgroup --help' for more information.\n", argv[optind]);
+ exit (1);
+ }
+
/* Get 'system' group */
- if (!disp_groupname && print_system && print_builtin)
+ if (!disp_groupname && print_system && print_builtin && !print_current)
print_special (&sid_nt_auth, 1, SECURITY_LOCAL_SYSTEM_RID,
0, 0, 0, 0, 0, 0, 0);
- fetch_current_pgrp_sid ();
-
off = id_offset;
for (i = 0; i < print_domlist; ++i)
{
@@ -867,12 +884,12 @@ skip:
? domlist[i].id_offset != ULONG_MAX
? domlist[i].id_offset : off : 0;
if (!enum_local_groups (domlist[i].domain, domlist + i, sep_char,
- my_off, disp_groupname, print_builtin))
+ my_off, disp_groupname, print_builtin, print_current))
{
if (!domlist[i].domain && domlist[i].str && print_unix)
enum_unix_groups (domlist + i, sep_char, my_off, print_unix);
enum_groups (domlist[i].domain, domlist + i, sep_char, my_off,
- disp_groupname);
+ disp_groupname, print_current);
if (my_off)
off += id_offset;
}
diff --git a/winsup/utils/mkpasswd.c b/winsup/utils/mkpasswd.c
index 14c5eb095..66e81a2cf 100644
--- a/winsup/utils/mkpasswd.c
+++ b/winsup/utils/mkpasswd.c
@@ -45,7 +45,7 @@ NET_API_STATUS WINAPI (*dsgetdcname)(LPWSTR,LPWSTR,GUID*,LPWSTR,ULONG,PDOMAIN_CO
#define min(a,b) (((a)<(b))?(a):(b))
#endif
-typedef struct
+typedef struct
{
char *str;
DWORD id_offset;
@@ -53,7 +53,7 @@ typedef struct
BOOL with_dom;
} domlist_t;
-void
+static void
_print_win_error(DWORD code, int line)
{
char buf[4096];
@@ -69,7 +69,7 @@ _print_win_error(DWORD code, int line)
fprintf (stderr, "mkpasswd (%d): error %lu", line, code);
}
-void
+static void
load_dsgetdcname ()
{
HANDLE h = LoadLibrary ("netapi32.dll");
@@ -125,7 +125,7 @@ get_dcname (char *domain)
return server;
}
-char *
+static char *
put_sid (PSID sid)
{
static char s[512];
@@ -143,7 +143,7 @@ put_sid (PSID sid)
return s;
}
-void
+static void
psx_dir (char *in, char *out)
{
if (isalpha (in[0]) && in[1] == ':')
@@ -166,7 +166,7 @@ psx_dir (char *in, char *out)
*out = '\0';
}
-void
+static void
uni2ansi (LPWSTR wcs, char *mbs, int size)
{
if (wcs)
@@ -180,11 +180,11 @@ typedef struct {
int buffer[10];
} sidbuf;
-sidbuf curr_user;
-sidbuf curr_pgrp;
-BOOL got_curr_user = FALSE;
+static sidbuf curr_user;
+static sidbuf curr_pgrp;
+static BOOL got_curr_user = FALSE;
-void
+static void
fetch_current_user_sid ()
{
DWORD len;
@@ -202,7 +202,7 @@ fetch_current_user_sid ()
}
}
-void
+static void
current_user (int print_cygpath, const char *sep, const char *passed_home_path,
DWORD id_offset, const char *disp_username)
{
@@ -233,7 +233,7 @@ current_user (int print_cygpath, const char *sep, const char *passed_home_path,
char *envhomepath = getenv ("HOMEPATH");
if (envhome && envhome[0])
- {
+ {
if (print_cygpath)
cygwin_conv_path (CCP_WIN_A_TO_POSIX | CCP_ABSOLUTE, envhome,
homedir_psx, PATH_MAX);
@@ -241,7 +241,7 @@ current_user (int print_cygpath, const char *sep, const char *passed_home_path,
psx_dir (envhome, homedir_psx);
}
else if (envhomepath && envhomepath[0])
- {
+ {
if (envhomedrive)
strlcpy (homedir_w32, envhomedrive, sizeof (homedir_w32));
if (envhomepath[0] != '\\')
@@ -254,7 +254,7 @@ current_user (int print_cygpath, const char *sep, const char *passed_home_path,
psx_dir (homedir_w32, homedir_psx);
}
else
- {
+ {
wcstombs (stpncpy (homedir_psx, "/home/", sizeof (homedir_psx)),
user, sizeof (homedir_psx) - 6);
homedir_psx[PATH_MAX - 1] = '\0';
@@ -279,7 +279,7 @@ current_user (int print_cygpath, const char *sep, const char *passed_home_path,
homedir_psx);
}
-void
+static void
enum_unix_users (domlist_t *dom_or_machine, const char *sep, DWORD id_offset,
char *unix_user_list)
{
@@ -303,7 +303,7 @@ enum_unix_users (domlist_t *dom_or_machine, const char *sep, DWORD id_offset,
if (ret < 1 || ret >= INTERNET_MAX_HOST_NAME_LENGTH + 1)
{
fprintf (stderr, "%s: Invalid machine name '%s'. Skipping...\n",
- __progname, d_or_m);
+ __progname, d_or_m);
return;
}
servername = machine;
@@ -320,7 +320,7 @@ enum_unix_users (domlist_t *dom_or_machine, const char *sep, DWORD id_offset,
for (ustr = strtok (user_list, ","); ustr; ustr = strtok (NULL, ","))
{
if (!isdigit (ustr[0]) && ustr[0] != '-')
- {
+ {
PWCHAR p = wcpcpy (user, L"Unix User\\");
ret = mbstowcs (p, ustr, UNLEN + 1);
if (ret < 1 || ret >= UNLEN + 1)
@@ -332,14 +332,14 @@ enum_unix_users (domlist_t *dom_or_machine, const char *sep, DWORD id_offset,
dom,
(dlen = MAX_DOMAIN_NAME_LEN + 1, &dlen),
&acc_type))
- printf ("%s%s%ls:unused:%lu:99999:,%s::\n",
- with_dom ? "Unix User" : "",
- with_dom ? sep : "",
- user + 10,
+ printf ("%s%s%ls:unused:%lu:99999:,%s::\n",
+ with_dom ? "Unix User" : "",
+ with_dom ? sep : "",
+ user + 10,
id_offset +
*GetSidSubAuthority (psid,
*GetSidSubAuthorityCount(psid) - 1),
- put_sid (psid));
+ put_sid (psid));
}
else
{
@@ -382,10 +382,10 @@ enum_unix_users (domlist_t *dom_or_machine, const char *sep, DWORD id_offset,
FreeSid (psid);
}
-int
+static int
enum_users (BOOL domain, domlist_t *dom_or_machine, const char *sep,
int print_cygpath, const char *passed_home_path, DWORD id_offset,
- char *disp_username)
+ char *disp_username, int print_current)
{
WCHAR machine[INTERNET_MAX_HOST_NAME_LENGTH + 1];
PWCHAR servername = NULL;
@@ -397,12 +397,11 @@ enum_users (BOOL domain, domlist_t *dom_or_machine, const char *sep,
DWORD resume_handle = 0;
DWORD rc;
WCHAR uni_name[UNLEN + 1];
-
if (domain)
{
servername = get_dcname (d_or_m);
if (servername == (PWCHAR) -1)
- return 1;
+ return 1;
}
else if (d_or_m)
{
@@ -427,7 +426,7 @@ enum_users (BOOL domain, domlist_t *dom_or_machine, const char *sep,
(void *) &buffer);
entriesread = 1;
}
- else
+ else
rc = NetUserEnum (servername, 3, FILTER_NORMAL_ACCOUNT,
(void *) &buffer, MAX_PREFERRED_LENGTH,
&entriesread, &totalentries, &resume_handle);
@@ -508,16 +507,21 @@ enum_users (BOOL domain, domlist_t *dom_or_machine, const char *sep,
continue;
}
}
- if (EqualSid (curr_user.psid, psid))
+ if (!print_current)
+ /* fall through */;
+ else if (EqualSid (curr_user.psid, psid))
got_curr_user = TRUE;
+ else
+ continue;
+
printf ("%ls%s%ls:unused:%lu:%lu:%ls%sU-%ls\\%ls,%s:%s:/bin/bash\n",
with_dom ? domain_name : L"",
with_dom ? sep : "",
- buffer[i].usri3_name,
+ buffer[i].usri3_name,
id_offset + uid,
id_offset + gid,
buffer[i].usri3_full_name ?: L"",
- buffer[i].usri3_full_name
+ buffer[i].usri3_full_name
&& buffer[i].usri3_full_name[0] ? "," : "",
domain_name,
buffer[i].usri3_name,
@@ -533,7 +537,7 @@ enum_users (BOOL domain, domlist_t *dom_or_machine, const char *sep,
return 0;
}
-void
+static void
print_special (PSID_IDENTIFIER_AUTHORITY auth, BYTE cnt,
DWORD sub1, DWORD sub2, DWORD sub3, DWORD sub4,
DWORD sub5, DWORD sub6, DWORD sub7, DWORD sub8)
@@ -544,7 +548,7 @@ print_special (PSID_IDENTIFIER_AUTHORITY auth, BYTE cnt,
SID_NAME_USE acc_type;
if (AllocateAndInitializeSid (auth, cnt, sub1, sub2, sub3, sub4,
- sub5, sub6, sub7, sub8, &sid))
+ sub5, sub6, sub7, sub8, &sid))
{
if (LookupAccountSidW (NULL, sid,
user, (len = UNLEN + 1, &len),
@@ -570,12 +574,12 @@ print_special (PSID_IDENTIFIER_AUTHORITY auth, BYTE cnt,
printf ("%ls:*:%lu:%lu:,%s::\n",
user, rid, rid == 18 ? 544 : rid, /* SYSTEM hack */
put_sid (sid));
- }
+ }
FreeSid (sid);
}
}
-int
+static int
usage (FILE * stream)
{
fprintf (stream,
@@ -605,7 +609,7 @@ usage (FILE * stream)
" -p,--path-to-home path use specified path instead of user account home dir\n"
" or /home prefix\n"
" -m,--no-mount don't use mount points for home dir\n"
-" -U,--unix userlist additionally print UNIX users when using -l or -L\n"
+" -U,--unix userlist additionally print UNIX users when using -l or -L\n"
" on a UNIX Samba server\n"
" userlist is a comma-separated list of usernames\n"
" or uid ranges (root,-25,50-100).\n"
@@ -620,7 +624,7 @@ usage (FILE * stream)
return 1;
}
-struct option longopts[] = {
+static struct option longopts[] = {
{"current", no_argument, NULL, 'c'},
{"Current", no_argument, NULL, 'C'},
{"domain", optional_argument, NULL, 'd'},
@@ -640,7 +644,7 @@ struct option longopts[] = {
{0, no_argument, NULL, 0}
};
-char opts[] = "cCd::D::ghl::L::mo:sS:p:u:U:v";
+static char opts[] = "cCd::D::ghl::L::mo:sS:p:u:U:v";
static void
print_version ()
@@ -692,7 +696,7 @@ fetch_primary_domain ()
if (!NT_SUCCESS (status))
return FALSE;
status = LsaQueryInformationPolicy (lsa, PolicyPrimaryDomainInformation,
- (PVOID *) &p_dom);
+ (PVOID *) ((void *) &p_dom));
LsaClose (lsa);
if (!NT_SUCCESS (status))
return FALSE;
@@ -722,15 +726,17 @@ main (int argc, char **argv)
load_dsgetdcname ();
in_domain = fetch_primary_domain ();
+ fetch_current_user_sid ();
+
if (argc == 1)
{
enum_std_accounts ();
if (in_domain)
enum_users (TRUE, NULL, sep_char, print_cygpath, passed_home_path,
- 10000, disp_username);
+ 10000, disp_username, 0);
else
enum_users (FALSE, NULL, sep_char, print_cygpath, passed_home_path, 0,
- disp_username);
+ disp_username, 0);
return 0;
}
@@ -768,13 +774,13 @@ main (int argc, char **argv)
if (opt && (p = strchr (opt, ',')))
{
if (p == opt
- || !isdigit (p[1])
- || (domlist[print_domlist].id_offset = strtol (p + 1, &ep, 10)
+ || !isdigit (p[1])
+ || (domlist[print_domlist].id_offset = strtol (p + 1, &ep, 10)
, *ep))
{
fprintf (stderr, "%s: Malformed domain,offset string '%s'. "
"Skipping...\n", __progname, opt);
- break;
+ break;
}
*p = '\0';
}
@@ -795,9 +801,9 @@ skip:
"character.\n", __progname);
return 1;
}
- break;
+ break;
case 'U':
- print_unix = optarg;
+ print_unix = optarg;
break;
case 'c':
sep_char = NULL;
@@ -846,7 +852,13 @@ skip:
return 1;
}
- fetch_current_user_sid ();
+ if (argv[optind])
+ {
+ fprintf (stderr,
+ "mkpasswd: non-option command line argument `%s' is not allowed.\n"
+ "Try `mkpasswd --help' for more information.\n", argv[optind]);
+ exit (1);
+ }
off = id_offset;
for (i = 0; i < print_domlist; ++i)
@@ -856,12 +868,12 @@ skip:
? domlist[i].id_offset : off : 0;
if (!domlist[i].domain && domlist[i].str && print_unix)
enum_unix_users (domlist + i, sep_char, my_off, print_unix);
- if (!my_off)
- enum_std_accounts ();
+ if (!my_off && !print_current)
+ enum_std_accounts ();
enum_users (domlist[i].domain, domlist + i, sep_char, print_cygpath,
- passed_home_path, my_off, disp_username);
+ passed_home_path, my_off, disp_username, print_current);
if (my_off)
- off += id_offset;
+ off += id_offset;
}
if (print_current && !got_curr_user)