diff options
Diffstat (limited to 'winsup/utils')
-rw-r--r-- | winsup/utils/ChangeLog | 60 | ||||
-rw-r--r-- | winsup/utils/Makefile.in | 2 | ||||
-rw-r--r-- | winsup/utils/bloda.cc | 93 | ||||
-rw-r--r-- | winsup/utils/cygcheck.cc | 14 | ||||
-rw-r--r-- | winsup/utils/cygpath.cc | 51 | ||||
-rw-r--r-- | winsup/utils/dump_setup.cc | 18 | ||||
-rw-r--r-- | winsup/utils/dumper.cc | 3 | ||||
-rw-r--r-- | winsup/utils/locale.cc | 4 | ||||
-rw-r--r-- | winsup/utils/mkgroup.c | 36 | ||||
-rw-r--r-- | winsup/utils/mkpasswd.c | 45 | ||||
-rw-r--r-- | winsup/utils/ps.cc | 6 | ||||
-rw-r--r-- | winsup/utils/regtool.cc | 4 | ||||
-rw-r--r-- | winsup/utils/strace.cc | 10 |
13 files changed, 99 insertions, 247 deletions
diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog index 3286cf432..50a957ae4 100644 --- a/winsup/utils/ChangeLog +++ b/winsup/utils/ChangeLog @@ -1,63 +1,3 @@ -2012-07-11 Corinna Vinschen <corinna@vinschen.de> - - * Makefile.in (cygcheck.exe): Link against psapi.dll. - * bloda.cc: Change include section to work with Mingw64 headers. - Include psapi.h. Use SystemProcessInformation instead of - SystemProcessesAndThreadsInformation throughout and add define for - w32api headers. Ditto for PSYSTEM_PROCESS_INFORMATION vs. - PSYSTEM_PROCESSES. - (system_module_list): New type to replace SYSTEM_MODULE_INFORMATION. - Change usage throughout accordingly. - (get_module_list): Fetch module list using PSAPI functions - EnumDeviceDrivers and GetDeviceDriverBaseNameA. - * cygcheck.cc (max): Define as __max if not defined already. - (alloca): Only define if not defined already. - (handle_unique_object_name): Use explicit sharing flags rather than - FILE_SHARE_VALID_FLAGS which officially is only available in DDK - headers. - (PRODUCT_ULTIMATE_E): Only define if not defined already. - * dump_setup.cc: Change include section to work with Mingw64 headers. - (NtQueryAttributesFile): Drop NTOSAPI aka DECLSPEC_IMPORT. - * strace.cc: Change include section to work with Mingw64 headers. - (alloca): Only define if not defined already. - -2012-07-06 Corinna Vinschen <corinna@vinschen.de> - - * cygpath.cc: Change including headers to allow building against - Mingw64 headers. Include ntdef.h and ntdll.h rather than ddk headers. - Define _WIN32_WINNT and WINVER as 0x0602. - (RtlEqualUnicodePathPrefix): Drop definition. Pulled in from ntdll.h - now. - (get_device_name): s/Zw/Nt. - * dumper.cc: Include sys/param.h - (dumper::dump_memory_region): Use MIN rather than min. - * locale.cc: Include stdlib.h. Define _WIN32_WINNT and WINVER as - 0x0602. - * ps.cc: Include ntdef.h and ntdll.h rather than ddk headers. - * regtool.cc (regDeleteKeyEx): Drop WINADVAPI qualifier. - -2012-06-03 Corinna Vinschen <corinna@vinschen.de> - - * cygcheck.cc (dump_sysinfo): Change "Server 8" to official - "Server 2012". - -2012-05-05 Corinna Vinschen <corinna@vinschen.de> - - * mkpasswd.c (current_user): Actually *use* $HOME if it's available. - Add comment to explain what we're doing here. - -2012-04-05 Corinna Vinschen <corinna@vinschen.de> - - * mkgroup.c (print_special_by_sid): Rename from print_special. Change - calls throughout. - (print_special_by_name): New function. - (main): Call print_special_by_name for TrustedInstaller account. - * mkpasswd.c (print_special_by_sid): Rename from print_special. Change - calls throughout. - (print_special_by_name): New function. - (enum_std_accounts): Call print_special_by_name for TrustedInstaller - account. - 2012-02-24 Yaakov Selkowitz <yselkowitz@users.sourceforge.net> * pldd.c: Fix typo in license header. diff --git a/winsup/utils/Makefile.in b/winsup/utils/Makefile.in index f3030a175..25ee5c48a 100644 --- a/winsup/utils/Makefile.in +++ b/winsup/utils/Makefile.in @@ -74,7 +74,7 @@ path-mount.o: path.cc mount.exe: path-mount.o # Provide any necessary per-target variable overrides. -cygcheck.exe: MINGW_LDFLAGS += -lpsapi -lntdll +cygcheck.exe: MINGW_LDFLAGS += -lntdll cygpath.exe: ALL_LDFLAGS += -lcygwin -luserenv -lntdll cygpath.exe: CXXFLAGS += -fno-threadsafe-statics ps.exe: ALL_LDFLAGS += -lcygwin -lpsapi -lntdll diff --git a/winsup/utils/bloda.cc b/winsup/utils/bloda.cc index dcb18f1a4..2cd799aea 100644 --- a/winsup/utils/bloda.cc +++ b/winsup/utils/bloda.cc @@ -11,23 +11,10 @@ #define cygwin_internal cygwin_internal_dontuse #include <stdio.h> #include <assert.h> -#define WIN32_NO_STATUS /* Disable status codes in winnt.h since we include - ntstatus.h for extended status codes below. */ #include <windows.h> -#undef WIN32_NO_STATUS -#include <psapi.h> -#ifndef __MINGW64_VERSION_MAJOR -# include <ntdef.h> -# include <ddk/ntstatus.h> -# include <ddk/ntapi.h> -# define SystemProcessInformation SystemProcessesAndThreadsInformation -# define PSYSTEM_PROCESS_INFORMATION PSYSTEM_PROCESSES -# define ImageName ProcessName -# define NextEntryOffset NextEntryDelta -#else -# include <winternl.h> -# include <ntstatus.h> -#endif +#include <ntdef.h> +#include <ddk/ntstatus.h> +#include <ddk/ntapi.h> #undef cygwin_internal #undef DEBUGGING @@ -121,77 +108,68 @@ static struct bad_app_info big_list_of_dodgy_apps[] = static const size_t num_of_dodgy_apps = sizeof (big_list_of_dodgy_apps) / sizeof (big_list_of_dodgy_apps[0]); -struct system_module_list -{ - LONG count; - PVOID *pid; - PCHAR *name; -}; - -static PSYSTEM_PROCESS_INFORMATION +static PSYSTEM_PROCESSES get_process_list (void) { int n_procs = 0x100; - PSYSTEM_PROCESS_INFORMATION pslist = (PSYSTEM_PROCESS_INFORMATION) malloc (n_procs * sizeof *pslist); + PSYSTEM_PROCESSES pslist = (PSYSTEM_PROCESSES) malloc (n_procs * sizeof *pslist); - while (NtQuerySystemInformation (SystemProcessInformation, + while (NtQuerySystemInformation (SystemProcessesAndThreadsInformation, pslist, n_procs * sizeof *pslist, 0) == STATUS_INFO_LENGTH_MISMATCH) { n_procs *= 2; free (pslist); - pslist = (PSYSTEM_PROCESS_INFORMATION) malloc (n_procs * sizeof *pslist); + pslist = (PSYSTEM_PROCESSES) malloc (n_procs * sizeof *pslist); } return pslist; } -static system_module_list * +static PSYSTEM_MODULE_INFORMATION get_module_list (void) { - DWORD modsize = 0; - system_module_list *modlist = (system_module_list *) - calloc (1, sizeof (system_module_list)); - while (!EnumDeviceDrivers (modlist->pid, modsize, &modsize)) - { - free (modlist->pid); - free (modlist->name); - modlist->count = modsize / sizeof (PVOID); - modlist->pid = (PVOID *) calloc (modlist->count, sizeof (PVOID)); - modlist->name = (PCHAR *) calloc (modlist->count, sizeof (PCHAR)); - } - for (int i = 0; i < modlist->count; ++i) + int modsize = 0x1000; + PSYSTEM_MODULE_INFORMATION modlist = (PSYSTEM_MODULE_INFORMATION) malloc (modsize); + + while (NtQuerySystemInformation (SystemModuleInformation, + modlist, modsize, NULL) == STATUS_INFO_LENGTH_MISMATCH) { - modlist->name[0] = (PCHAR) calloc (256, sizeof (CHAR)); - GetDeviceDriverBaseNameA (modlist->pid[i], modlist->name[i], 256); + modsize *= 2; + free (modlist); + modlist = (PSYSTEM_MODULE_INFORMATION) malloc (modsize); } return modlist; } static bool -find_process_in_list (PSYSTEM_PROCESS_INFORMATION pslist, PUNICODE_STRING psname) +find_process_in_list (PSYSTEM_PROCESSES pslist, PUNICODE_STRING psname) { while (1) { - if (pslist->ImageName.Length && pslist->ImageName.Buffer) + if (pslist->ProcessName.Length && pslist->ProcessName.Buffer) { - dbg_printf (("%S\n", pslist->ImageName.Buffer)); - if (!_wcsicmp (pslist->ImageName.Buffer, psname->Buffer)) + dbg_printf (("%S\n", pslist->ProcessName.Buffer)); + if (!_wcsicmp (pslist->ProcessName.Buffer, psname->Buffer)) return true; } - if (!pslist->NextEntryOffset) + if (!pslist->NextEntryDelta) break; - pslist = (PSYSTEM_PROCESS_INFORMATION)(pslist->NextEntryOffset + (char *)pslist); + pslist = (PSYSTEM_PROCESSES)(pslist->NextEntryDelta + (char *)pslist); }; return false; } static bool -find_module_in_list (system_module_list * modlist, const char * const modname) +find_module_in_list (PSYSTEM_MODULE_INFORMATION modlist, const char * const modname) { - for (int i = 0; i < modlist->count; ++i) + PSYSTEM_MODULE_INFORMATION_ENTRY modptr = &modlist->Module[0]; + DWORD count = modlist->Count; + while (count--) { - dbg_printf (("name '%s' ", modlist->name[i])); - if (!_stricmp (modlist->name[i], modname)) + dbg_printf (("name '%s' offset %d ", &modptr->ImageName[0], modptr->PathLength)); + dbg_printf (("= '%s'\n", &modptr->ImageName[modptr->PathLength])); + if (!_stricmp (&modptr->ImageName[modptr->PathLength], modname)) return true; + modptr++; } return false; } @@ -255,7 +233,7 @@ expand_path (const char *path, char *outbuf) } static bool -detect_dodgy_app (const struct bad_app_det *det, PSYSTEM_PROCESS_INFORMATION pslist, system_module_list * modlist) +detect_dodgy_app (const struct bad_app_det *det, PSYSTEM_PROCESSES pslist, PSYSTEM_MODULE_INFORMATION modlist) { HANDLE fh; HKEY hk; @@ -356,8 +334,8 @@ void dump_dodgy_apps (int verbose) { size_t i, n_det = 0; - PSYSTEM_PROCESS_INFORMATION pslist; - system_module_list * modlist; + PSYSTEM_PROCESSES pslist; + PSYSTEM_MODULE_INFORMATION modlist; /* Read system info for detect testing. */ pslist = get_process_list (); @@ -426,9 +404,6 @@ dump_dodgy_apps (int verbose) } /* Tidy up allocations. */ free (pslist); - for (int i = 0; i < modlist->count; ++i) - free (modlist->name[i]); - free (modlist->name); - free (modlist->pid); + free (modlist); } diff --git a/winsup/utils/cygcheck.cc b/winsup/utils/cygcheck.cc index de45addd2..52411c881 100644 --- a/winsup/utils/cygcheck.cc +++ b/winsup/utils/cygcheck.cc @@ -1,7 +1,7 @@ /* cygcheck.cc Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - 2006, 2007, 2008, 2009, 2010, 2011, 2012 Red Hat, Inc. + 2006, 2007, 2008, 2009, 2010, 2011 Red Hat, Inc. This file is part of Cygwin. @@ -30,13 +30,7 @@ #undef cygwin_internal #include "loadlib.h" -#ifndef max -#define max __max -#endif - -#ifndef alloca #define alloca __builtin_alloca -#endif int verbose = 0; int registry = 0; @@ -1320,7 +1314,7 @@ handle_unique_object_name (int opt, char *path) if (opt == CO_SHOW_UON) { access = GENERIC_READ; - share = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; + share = FILE_SHARE_VALID_FLAGS; protect = PAGE_READONLY; mapping = FILE_MAP_READ; } @@ -1442,7 +1436,7 @@ dump_sysinfo () else if (osversion.dwMinorVersion == 2) { strcpy (osname, osversion.wProductType == VER_NT_WORKSTATION - ? "8" : "Server 2012"); + ? "8" : "Server 8"); strcat (osname, " (not yet supported!)"); } DWORD prod; @@ -1453,9 +1447,7 @@ dump_sysinfo () &prod)) { #define PRODUCT_UNLICENSED 0xabcdabcd -#ifndef PRODUCT_ULTIMATE_E #define PRODUCT_ULTIMATE_E 0x00000047 -#endif const char *products[] = { /* 0x00000000 */ "", diff --git a/winsup/utils/cygpath.cc b/winsup/utils/cygpath.cc index 77ee38426..662112fe5 100644 --- a/winsup/utils/cygpath.cc +++ b/winsup/utils/cygpath.cc @@ -8,6 +8,10 @@ This software is a copyrighted work licensed under the terms of the Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ +#define NOCOMATTRIBUTE + +#define WINVER 0x0600 +#include <shlobj.h> #include <stdio.h> #include <string.h> #include <wchar.h> @@ -15,22 +19,17 @@ details. */ #include <stdlib.h> #include <limits.h> #include <getopt.h> +#include <windows.h> +#include <userenv.h> #include <io.h> #include <sys/fcntl.h> #include <sys/cygwin.h> #include <cygwin/version.h> #include <ctype.h> #include <errno.h> - -#define _WIN32_WINNT 0x0602 -#define WINVER 0x0602 -#define NOCOMATTRIBUTE -#include <windows.h> -#include <userenv.h> -#include <shlobj.h> -#include <ntdef.h> -#include <ntdll.h> - +#include <ddk/ntddk.h> +#include <ddk/winddk.h> +#include <ddk/ntifs.h> #include "wide_path.h" #include "loadlib.h" @@ -149,6 +148,18 @@ RtlAllocateUnicodeString (PUNICODE_STRING uni, ULONG size) return uni->Buffer != NULL; } +static inline BOOLEAN +RtlEqualUnicodePathPrefix (PUNICODE_STRING path, PUNICODE_STRING prefix, + BOOLEAN caseinsensitive) + { + UNICODE_STRING p; + + p.Length = p.MaximumLength = prefix->Length < path->Length + ? prefix->Length : path->Length; + p.Buffer = path->Buffer; + return RtlEqualUnicodeString (&p, prefix, caseinsensitive); + } + static size_t my_wcstombs (char *dest, const wchar_t *src, size_t n) { @@ -192,11 +203,11 @@ get_device_name (char *path) query it and use the new name as actual device name to search for in the DOS device name directory. If not, just use the incoming device name. */ InitializeObjectAttributes (&ntobj, &ntdev, OBJ_CASE_INSENSITIVE, NULL, NULL); - status = NtOpenSymbolicLinkObject (&lnk, SYMBOLIC_LINK_QUERY, &ntobj); + status = ZwOpenSymbolicLinkObject (&lnk, SYMBOLIC_LINK_QUERY, &ntobj); if (NT_SUCCESS (status)) { - status = NtQuerySymbolicLinkObject (lnk, &tgtdev, NULL); - NtClose (lnk); + status = ZwQuerySymbolicLinkObject (lnk, &tgtdev, NULL); + ZwClose (lnk); if (!NT_SUCCESS (status)) goto out; RtlCopyUnicodeString (&ntdev, &tgtdev); @@ -214,28 +225,28 @@ get_device_name (char *path) /* Open the directory... */ InitializeObjectAttributes (&ntobj, &ntdevdir, OBJ_CASE_INSENSITIVE, NULL, NULL); - status = NtOpenDirectoryObject (&dir, DIRECTORY_QUERY, &ntobj); + status = ZwOpenDirectoryObject (&dir, DIRECTORY_QUERY, &ntobj); if (!NT_SUCCESS (status)) break; /* ...and scan it. */ for (restart = TRUE, cont = 0; - NT_SUCCESS (NtQueryDirectoryObject (dir, odi, 4096, TRUE, + NT_SUCCESS (ZwQueryDirectoryObject (dir, odi, 4096, TRUE, restart, &cont, NULL)); restart = FALSE) { /* For each entry check if it's a symbolic link. */ InitializeObjectAttributes (&ntobj, &odi->ObjectName, OBJ_CASE_INSENSITIVE, dir, NULL); - status = NtOpenSymbolicLinkObject (&lnk, SYMBOLIC_LINK_QUERY, &ntobj); + status = ZwOpenSymbolicLinkObject (&lnk, SYMBOLIC_LINK_QUERY, &ntobj); if (!NT_SUCCESS (status)) continue; tgtdev.Length = 0; tgtdev.MaximumLength = 512; /* If so, query it and compare the target of the symlink with the incoming device name. */ - status = NtQuerySymbolicLinkObject (lnk, &tgtdev, NULL); - NtClose (lnk); + status = ZwQuerySymbolicLinkObject (lnk, &tgtdev, NULL); + ZwClose (lnk); if (!NT_SUCCESS (status)) continue; if (tgtdev.Length /* There's actually a symlink pointing to an @@ -282,12 +293,12 @@ get_device_name (char *path) else memmove (ret, ret + 4, strlen (ret + 4) + 1); } - NtClose (dir); + ZwClose (dir); goto out; } } } - NtClose (dir); + ZwClose (dir); } out: diff --git a/winsup/utils/dump_setup.cc b/winsup/utils/dump_setup.cc index f463caf14..70f03eed5 100644 --- a/winsup/utils/dump_setup.cc +++ b/winsup/utils/dump_setup.cc @@ -8,6 +8,7 @@ This software is a copyrighted work licensed under the terms of the Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ +#include <windows.h> #include <stdio.h> #include <stdlib.h> #include <ctype.h> @@ -16,18 +17,9 @@ details. */ #include <io.h> #include <sys/stat.h> #include <errno.h> -#define WIN32_NO_STATUS /* Disable status codes in winnt.h since we include - ntstatus.h for extended status codes below. */ -#include <windows.h> -#undef WIN32_NO_STATUS -#ifndef __MINGW64_VERSION_MAJOR -# include <ddk/ntapi.h> -# include <ddk/winddk.h> -#else -# include <winternl.h> -# include <ntstatus.h> -#endif #include "path.h" +#include <ddk/ntapi.h> +#include <ddk/winddk.h> #if 0 #include "zlib.h" #endif @@ -273,8 +265,8 @@ transform_chars (PWCHAR path, PWCHAR path_end) *path = tfx_chars[*path]; } -extern "C" NTAPI NTSTATUS NtQueryAttributesFile (POBJECT_ATTRIBUTES, - PFILE_BASIC_INFORMATION); +extern "C" NTOSAPI NTAPI NTSTATUS NtQueryAttributesFile( + POBJECT_ATTRIBUTES, PFILE_BASIC_INFORMATION); /* This function checks for file existance and fills the stat structure with only the required mode info. We're using a native NT function diff --git a/winsup/utils/dumper.cc b/winsup/utils/dumper.cc index 28d0add04..3b92bcc18 100644 --- a/winsup/utils/dumper.cc +++ b/winsup/utils/dumper.cc @@ -33,7 +33,6 @@ #include <stdio.h> #include <stdlib.h> #include <unistd.h> -#include <sys/param.h> #include <windows.h> #include "dumper.h" @@ -381,7 +380,7 @@ dumper::dump_memory_region (asection * to, process_mem_region * memory) while (size > 0) { - todo = MIN (size, PAGE_BUFFER_SIZE); + todo = min (size, PAGE_BUFFER_SIZE); if (!ReadProcessMemory (hProcess, pos, mem_buf, todo, &done)) { deb_printf ("Failed to read process memory at %x(%x), error %ld\n", pos, todo, GetLastError ()); diff --git a/winsup/utils/locale.cc b/winsup/utils/locale.cc index be57cf161..e3c39c049 100644 --- a/winsup/utils/locale.cc +++ b/winsup/utils/locale.cc @@ -25,7 +25,6 @@ */ #include <errno.h> #include <stdio.h> -#include <stdlib.h> #include <ctype.h> #include <getopt.h> #include <string.h> @@ -35,8 +34,7 @@ #include <limits.h> #include <sys/cygwin.h> #include <cygwin/version.h> -#define _WIN32_WINNT 0x0602 -#define WINVER 0x0602 +#define WINVER 0x0601 #include <windows.h> #define LOCALE_ALIAS "/usr/share/locale/locale.alias" diff --git a/winsup/utils/mkgroup.c b/winsup/utils/mkgroup.c index f712553c4..393d8f8f7 100644 --- a/winsup/utils/mkgroup.c +++ b/winsup/utils/mkgroup.c @@ -1,7 +1,7 @@ /* mkgroup.c: Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2007, 2008, 2009, 2010, 2011, 2012 Red Hat, Inc. + 2007, 2008, 2009, 2010, 2011 Red Hat, Inc. This file is part of Cygwin. @@ -558,9 +558,9 @@ enum_groups (BOOL domain, domlist_t *dom_or_machine, const char *sep, } static void -print_special_by_sid (PSID_IDENTIFIER_AUTHORITY auth, BYTE cnt, - DWORD sub1, DWORD sub2, DWORD sub3, DWORD sub4, - DWORD sub5, DWORD sub6, DWORD sub7, DWORD sub8) +print_special (PSID_IDENTIFIER_AUTHORITY auth, BYTE cnt, + DWORD sub1, DWORD sub2, DWORD sub3, DWORD sub4, + DWORD sub5, DWORD sub6, DWORD sub7, DWORD sub8) { WCHAR grp[GNLEN + 1], dom[MAX_DOMAIN_NAME_LEN + 1]; DWORD glen, dlen, rid; @@ -597,23 +597,6 @@ print_special_by_sid (PSID_IDENTIFIER_AUTHORITY auth, BYTE cnt, } } -static void -print_special_by_name (PCWSTR name, gid_t gid) -{ - DWORD size = 256, dom_size = 256; - PSID sid = (PSID) alloca (size); - WCHAR dom[dom_size]; - SID_NAME_USE use; - - PWCHAR name_only = wcschr (name, L'\\'); - if (name_only) - ++name_only; - - if (LookupAccountNameW (NULL, name, sid, &size, dom, &dom_size, &use)) - printf ("%ls:%s:%lu:\n", - name_only ?: name, put_sid (sid), (unsigned long) gid); -} - static int usage (FILE * stream) { @@ -747,8 +730,8 @@ main (int argc, char **argv) if (argc == 1) { - print_special_by_sid (&sid_nt_auth, 1, SECURITY_LOCAL_SYSTEM_RID, - 0, 0, 0, 0, 0, 0, 0); + print_special (&sid_nt_auth, 1, SECURITY_LOCAL_SYSTEM_RID, + 0, 0, 0, 0, 0, 0, 0); if (in_domain) { if (!enum_local_groups (TRUE, NULL, sep_char, id_offset, @@ -874,11 +857,8 @@ skip: /* Get 'system' group */ if (!disp_groupname && print_system && print_builtin && print_domlist) - { - print_special_by_sid (&sid_nt_auth, 1, SECURITY_LOCAL_SYSTEM_RID, - 0, 0, 0, 0, 0, 0, 0); - print_special_by_name (L"NT SERVICE\\TrustedInstaller", -2); - } + print_special (&sid_nt_auth, 1, SECURITY_LOCAL_SYSTEM_RID, + 0, 0, 0, 0, 0, 0, 0); off = id_offset; for (i = 0; i < print_domlist; ++i) diff --git a/winsup/utils/mkpasswd.c b/winsup/utils/mkpasswd.c index 5373719c5..c873664f9 100644 --- a/winsup/utils/mkpasswd.c +++ b/winsup/utils/mkpasswd.c @@ -1,7 +1,7 @@ /* mkpasswd.c: Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006, - 2008, 2009, 2010, 2011, 2012 Red Hat, Inc. + 2008, 2009, 2010, 2011 Red Hat, Inc. This file is part of Cygwin. @@ -172,13 +172,9 @@ current_user (const char *sep, const char *passed_home_path, DWORD id_offset, *GetSidSubAuthorityCount(curr_pgrp.psid) - 1); if (passed_home_path[0] == '\0') { - char *envhome = getenv ("HOME"); + char *envhome = getenv ("HOME"); /* POSIX! */ - /* If $HOME exists and is non-empty, just copy it over to homedir_psx. - Otherwise, generate a new path of the form "/home/$USER". */ - if (envhome && envhome[0] != '\0') - strncat (homedir_psx, envhome, sizeof (homedir_psx) - 1); - else + if (!envhome || envhome[0] == '\0') { wcstombs (stpncpy (homedir_psx, "/home/", sizeof (homedir_psx)), user, sizeof (homedir_psx) - 6); @@ -459,9 +455,9 @@ enum_users (BOOL domain, domlist_t *dom_or_machine, const char *sep, } static void -print_special_by_sid (PSID_IDENTIFIER_AUTHORITY auth, BYTE cnt, - DWORD sub1, DWORD sub2, DWORD sub3, DWORD sub4, - DWORD sub5, DWORD sub6, DWORD sub7, DWORD sub8) +print_special (PSID_IDENTIFIER_AUTHORITY auth, BYTE cnt, + DWORD sub1, DWORD sub2, DWORD sub3, DWORD sub4, + DWORD sub5, DWORD sub6, DWORD sub7, DWORD sub8) { WCHAR user[UNLEN + 1], dom[MAX_DOMAIN_NAME_LEN + 1]; DWORD len, len2, rid; @@ -585,29 +581,6 @@ print_version () } static void -print_special_by_name (PCWSTR name, uid_t uid, gid_t gid) -{ - DWORD size = 256, dom_size = 256; - PSID sid = (PSID) alloca (size); - WCHAR dom[dom_size]; - SID_NAME_USE use; - - PWCHAR name_only = wcschr (name, L'\\'); - if (name_only) - ++name_only; - - if (LookupAccountNameW (NULL, name, sid, &size, dom, &dom_size, &use)) - printf ("%ls:*:%lu:%lu:U-%ls%s%ls,%s::\n", - name_only ?: name, - (unsigned long) uid, - (unsigned long) gid, - name_only ? dom : L"", - name_only ? "\\" : "", - name_only ?: name, - put_sid (sid)); -} - -static void enum_std_accounts () { /* Generate service starter account entries. */ @@ -615,10 +588,8 @@ enum_std_accounts () printf ("LocalService:*:19:544:U-NT AUTHORITY\\LocalService,S-1-5-19::\n"); printf ("NetworkService:*:20:544:U-NT AUTHORITY\\NetworkService,S-1-5-20::\n"); /* Get 'administrators' group (has localized name). */ - print_special_by_sid (&sid_nt_auth, 2, SECURITY_BUILTIN_DOMAIN_RID, - DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0); - /* Fetch "TrustedInstaller" account starting with Vista. */ - print_special_by_name (L"NT SERVICE\\TrustedInstaller", -2, -2); + print_special (&sid_nt_auth, 2, SECURITY_BUILTIN_DOMAIN_RID, + DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0); } static PPOLICY_PRIMARY_DOMAIN_INFO p_dom; diff --git a/winsup/utils/ps.cc b/winsup/utils/ps.cc index 7ed69ea9b..e026518c4 100644 --- a/winsup/utils/ps.cc +++ b/winsup/utils/ps.cc @@ -23,8 +23,8 @@ details. */ #include <sys/cygwin.h> #include <cygwin/version.h> #include <psapi.h> -#include <ntdef.h> -#include <ntdll.h> +#include <ddk/ntapi.h> +#include <ddk/winddk.h> #include "loadlib.h" /* Maximum possible path length under NT. There's no official define @@ -347,7 +347,7 @@ main (int argc, char *argv[]) unicode_buf to have enough space for a maximum sized UNICODE_STRING. */ if (uni->Length == 0) /* System process */ - win32path = (wchar_t *) L"System"; + win32path = L"System"; else { uni->Buffer[uni->Length / sizeof (WCHAR)] = L'\0'; diff --git a/winsup/utils/regtool.cc b/winsup/utils/regtool.cc index 5a4244e3e..cc28d485e 100644 --- a/winsup/utils/regtool.cc +++ b/winsup/utils/regtool.cc @@ -574,7 +574,7 @@ cmd_add () } extern "C" { - LONG WINAPI (*regDeleteKeyEx)(HKEY, LPCWSTR, REGSAM, DWORD); +WINADVAPI LONG WINAPI (*regDeleteKeyEx)(HKEY, LPCWSTR, REGSAM, DWORD); } int @@ -587,7 +587,7 @@ cmd_remove () { HMODULE mod = LoadLibrary ("advapi32.dll"); if (mod) - regDeleteKeyEx = (LONG WINAPI (*)(HKEY, LPCWSTR, REGSAM, DWORD)) GetProcAddress (mod, "RegDeleteKeyExW"); + regDeleteKeyEx = (WINADVAPI LONG WINAPI (*)(HKEY, LPCWSTR, REGSAM, DWORD)) GetProcAddress (mod, "RegDeleteKeyExW"); } if (regDeleteKeyEx) rv = (*regDeleteKeyEx) (key, value, wow64, 0); diff --git a/winsup/utils/strace.cc b/winsup/utils/strace.cc index f9d2eb323..f8662582d 100644 --- a/winsup/utils/strace.cc +++ b/winsup/utils/strace.cc @@ -11,12 +11,6 @@ This software is a copyrighted work licensed under the terms of the Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ -#include <windows.h> -#ifndef __MINGW64_VERSION_MAJOR -#include "ddk/ntapi.h" -#else -#include <winternl.h> -#endif #define cygwin_internal cygwin_internal_dontuse #include <stdio.h> #include <fcntl.h> @@ -25,6 +19,7 @@ details. */ #include <string.h> #include <stdlib.h> #include <time.h> +#include <windows.h> #include <signal.h> #include <errno.h> #include "cygwin/include/sys/strace.h" @@ -33,11 +28,10 @@ details. */ #include "path.h" #undef cygwin_internal #include "loadlib.h" +#include "ddk/ntapi.h" /* we *know* we're being built with GCC */ -#ifndef alloca #define alloca __builtin_alloca -#endif static const char *pgm; static int forkdebug = 1; |