/* cygcheck.cc
- Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
- 2006, 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.
-
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
+#define _WIN32_WINNT 0x0a00
#define cygwin_internal cygwin_internal_dontuse
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <ctype.h>
+#include <fcntl.h>
#include <io.h>
#include <windows.h>
#include <wininet.h>
#include "path.h"
#include "wide_path.h"
#include <getopt.h>
-#include "cygwin/include/sys/cygwin.h"
-#include "cygwin/include/mntent.h"
-#include "cygwin/cygprops.h"
+#include "../cygwin/include/cygwin/version.h"
+#include "../cygwin/include/sys/cygwin.h"
+#define _NOMNTENT_MACROS
+#include "../cygwin/include/mntent.h"
#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;
int list_package = 0;
int grep_packages = 0;
int del_orphaned_reg = 0;
-int unique_object_name_opt = 0;
static char emptystr[] = "";
-/* This is global because it's used in both internet_display_error as well
- as package_grep. */
-BOOL (WINAPI *pInternetCloseHandle) (HINTERNET);
-
#ifdef __GNUC__
typedef long long longlong;
#else
void package_list (int, char **);
/* In bloda.cc */
void dump_dodgy_apps (int verbose);
-/* Forward declaration */
-static void usage (FILE *, int);
-
-static const char version[] = "$Revision$";
static const char *known_env_vars[] = {
"c_include_path",
{"awk", 0},
{"bash", 0},
{"cat", 0},
+ {"certutil", 0},
+ {"clinfo", 0},
+ {"comp", 0},
+ {"convert", 0},
{"cp", 0},
{"cpp", 1},
{"crontab", 0},
+ {"curl", 0},
+ {"expand", 0},
{"find", 0},
+ {"ftp", 0},
{"gcc", 0},
{"gdb", 0},
{"grep", 0},
+ {"hostname", 0},
{"kill", 0},
+ {"klist", 0},
{"ld", 0},
{"ls", 0},
{"make", 0},
{"mv", 0},
+ {"nslookup", 0},
{"patch", 0},
{"perl", 0},
+ {"replace", 0},
{"rm", 0},
{"sed", 0},
- {"ssh", 0},
{"sh", 0},
+ {"shutdown", 0},
+ {"sort", 0},
+ {"ssh", 0},
{"tar", 0},
{"test", 0},
+ {"timeout", 0},
{"vi", 0},
{"vim", 0},
+ {"whoami", 0},
{0, 0}
};
enum
{
CO_DELETE_KEYS = 0x100,
- CO_ENABLE_UON = 0x101,
- CO_DISABLE_UON = 0x102,
- CO_SHOW_UON = 0x103
};
static int num_paths, max_paths;
va_start (hptr, message);
while ((h = va_arg (hptr, HINTERNET)) != 0)
- pInternetCloseHandle (h);
+ InternetCloseHandle (h);
va_end (hptr);
return 1;
char* first, const char *ext1, const char *ext2)
{
char file[4000];
- strcpy (file, dir);
- strcat (file, fn);
- strcat (file, ext1);
- strcat (file, ext2);
+ snprintf (file, sizeof file, "%s%s%s%s", dir, fn, ext1, ext2);
wide_path wpath (file);
if (GetFileAttributesW (wpath) != (DWORD) - 1)
{
static char rv[4000];
- /* Sort of a kludge but we've already tested this once, so don't try it again */
+ /* Sort of a kludge but we've already tested this once, so don't try it
+ again */
if (in_file == rv)
return in_file;
*rv = '\0';
if (!in_file)
{
- display_error ("internal error find_on_path: NULL pointer for file", false, false);
+ display_error ("internal error find_on_path: NULL pointer for file",
+ false, false);
return 0;
}
if (!ext)
{
- display_error ("internal error find_on_path: NULL pointer for default_extension", false, false);
+ display_error ("internal error find_on_path: "
+ "NULL pointer for default_extension", false, false);
return 0;
}
if (!file)
{
- display_error ("internal error find_on_path: cygpath conversion failed for %s\n", in_file);
+ display_error ("internal error find_on_path: "
+ "cygpath conversion failed for %s\n", in_file);
return 0;
}
pth->check_existence (file, showall, verbose, rv, ext);
if (checklinks)
- pth->check_existence (file, showall, verbose, rv, ext, LINK_EXTENSION);
+ pth->check_existence (file, showall, verbose, rv, ext,
+ LINK_EXTENSION);
if (!*ext)
continue;
{
DWORD junk;
int i;
+ if (is_symlink (fh))
+ {
+ if (!verbose)
+ puts ("");
+ else
+ {
+ char buf[PATH_MAX + 1] = "";
+ readlink (fh, buf, sizeof(buf) - 1);
+ printf (" (symlink to %s)\n", buf);
+ }
+ return;
+ }
int pe_header_offset = get_dword (fh, 0x3c);
if (GetLastError () != NO_ERROR)
display_error ("get_dword");
+ WORD arch = get_word (fh, pe_header_offset + 4);
+ if (GetLastError () != NO_ERROR)
+ display_error ("get_word");
+#ifdef __x86_64__
+ if (arch != IMAGE_FILE_MACHINE_AMD64)
+ {
+ puts (verbose ? " (not x86_64 dll)" : "\n");
+ return;
+ }
+ int base_off = 108;
+#else
+ if (arch != IMAGE_FILE_MACHINE_I386)
+ {
+ puts (verbose ? " (not x86 dll)" : "\n");
+ return;
+ }
+ int base_off = 92;
+#endif
int opthdr_ofs = pe_header_offset + 4 + 20;
unsigned short v[6];
else
printf ("\n");
- int num_entries = get_dword (fh, opthdr_ofs + 92);
+ int num_entries = get_dword (fh, opthdr_ofs + base_off + 0);
if (GetLastError () != NO_ERROR)
display_error ("get_dword");
- int export_rva = get_dword (fh, opthdr_ofs + 96);
+ int export_rva = get_dword (fh, opthdr_ofs + base_off + 4);
if (GetLastError () != NO_ERROR)
display_error ("get_dword");
- int export_size = get_dword (fh, opthdr_ofs + 100);
+ int export_size = get_dword (fh, opthdr_ofs + base_off + 8);
if (GetLastError () != NO_ERROR)
display_error ("get_dword");
- int import_rva = get_dword (fh, opthdr_ofs + 104);
+ int import_rva = get_dword (fh, opthdr_ofs + base_off + 12);
if (GetLastError () != NO_ERROR)
display_error ("get_dword");
- int import_size = get_dword (fh, opthdr_ofs + 108);
+ int import_size = get_dword (fh, opthdr_ofs + base_off + 16);
if (GetLastError () != NO_ERROR)
display_error ("get_dword");
ExpDirectory *ed = (ExpDirectory *) exp;
int ofs = ed->name_rva - export_rva;
- struct tm *tm = localtime ((const time_t *) &(ed->timestamp));
- if (tm->tm_year < 60)
+ time_t ts = ed->timestamp; /* timestamp is only 4 bytes! */
+ struct tm *tm = localtime (&ts);
+ if (tm && tm->tm_year < 60)
tm->tm_year += 2000;
- if (tm->tm_year < 200)
+ if (tm && tm->tm_year < 200)
tm->tm_year += 1900;
printf ("%*c", lvl + 2, ' ');
- printf ("\"%s\" v%d.%d ts=", exp + ofs,
+ printf ("\"%s\" v%d.%d", exp + ofs,
ed->major_ver, ed->minor_ver);
- printf ("%d/%d/%d %d:%02d\n",
- tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
- tm->tm_hour, tm->tm_min);
+ if (tm)
+ printf (" ts=%04d-%02d-%02d %02d:%02d",
+ tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
+ tm->tm_hour, tm->tm_min);
+ putchar ('\n');
}
}
const char *path = find_on_path (file, suffix, false, true);
if (!path)
{
- display_error ("track_down: could not find %s\n", file);
+ /* The api-ms-win-*.dll files are in system32/downlevel and not in the
+ DLL search path, so find_on_path doesn't find them. Since they are
+ never actually linked against by the executables, they are of no
+ interest to us. Skip any error message in not finding them. */
+ if (strncasecmp (file, "api-ms-win-", 11) || strcasecmp (suffix, ".dll"))
+ display_error ("track_down: could not find %s\n", file);
return false;
}
if (lvl)
printf ("%*c", lvl, ' ');
- if (!path)
- {
- display_error ("file not found - '%s'\n", file);
- return false;
- }
-
printf ("%s", path);
wide_path wpath (path);
static char tmp[SYMLINK_MAX + 1];
if (!readlink (fh, tmp, SYMLINK_MAX))
display_error("readlink failed");
-
+
/* Resolve the linkname relative to the directory of the link. */
char *ptr = cygpath_rel (dirname (papp), tmp, NULL);
printf (" -> %s\n", ptr);
if (!CloseHandle (fh))
display_error ("find_app_on_path: CloseHandle()");
/* FIXME: We leak the ptr returned by cygpath() here which is a
- malloc()d string. */
+ malloc()d string. */
return find_app_on_path (ptr, showall);
}
sz = -sz;
for (char **g = groups; g <= ng; g++)
if ((g != ng) && (++i < n))
- printf ("%*s", sz, *g);
+ printf ("%*s", (int) sz, *g);
else
{
puts (*g);
int ret = fscanf (f, "cygrunsrv V%u.%u", &maj, &min);
if (ferror (f) || feof (f) || ret == EOF || maj < 1 || min < 10)
{
- puts ("The version of cygrunsrv installed is too old to dump service info.\n");
+ puts ("The version of cygrunsrv installed is too old to dump "
+ "service info.\n");
return;
}
- fclose (f);
+ pclose (f);
/* For verbose mode, just run cygrunsrv --list --verbose and copy output
verbatim; otherwise run cygrunsrv --list and then cygrunsrv --query for
each service. */
- snprintf (buf, sizeof (buf), (verbose ? "\"%s\" --list --verbose" : "\"%s\" --list"),
+ snprintf (buf, sizeof (buf),
+ (verbose ? "\"%s\" --list --verbose" : "\"%s\" --list"),
cygrunsrv);
if ((f = popen (buf, "rt")) == NULL)
{
snprintf (buf2, sizeof (buf2), "\"%s\" --query %s", cygrunsrv, srv);
if ((f = popen (buf2, "rt")) == NULL)
{
- printf ("Failed to execute '%s', skipping services check.\n", buf2);
+ printf ("Failed to execute '%s', skipping services check.\n",
+ buf2);
return;
}
{
char *path = data + 4;
if (path[1] != ':')
- *(path += 2) = '\\';
+ *(path += 2) = '\\';
if (what == PRINT_KEY)
printf (" %s Key: %s Path: %s", i ? "User: " : "System:",
name, path);
/* Unfortunately neither mingw nor Windows know this function. */
char *
memmem (char *haystack, size_t haystacklen,
- const char *needle, size_t needlelen)
+ const char *needle, size_t needlelen)
{
if (needlelen == 0)
return haystack;
while (needlelen <= haystacklen)
{
if (!memcmp (haystack, needle, needlelen))
- return haystack;
+ return haystack;
haystack++;
haystacklen--;
}
return NULL;
}
-
-int
-handle_unique_object_name (int opt, char *path)
-{
- HANDLE fh, fm;
- void *haystack = NULL;
-
- if (!path || !*path)
- usage (stderr, 1);
-
- DWORD access, share, protect, mapping;
-
- if (opt == CO_SHOW_UON)
- {
- access = GENERIC_READ;
- share = FILE_SHARE_VALID_FLAGS;
- protect = PAGE_READONLY;
- mapping = FILE_MAP_READ;
- }
- else
- {
- access = GENERIC_READ | GENERIC_WRITE;
- share = 0;
- protect = PAGE_READWRITE;
- mapping = FILE_MAP_WRITE;
- }
- fh = CreateFile (path, access, share, NULL, OPEN_EXISTING,
- FILE_FLAG_BACKUP_SEMANTICS, NULL);
- if (fh == INVALID_HANDLE_VALUE)
- {
- DWORD err = GetLastError ();
- switch (err)
- {
- case ERROR_SHARING_VIOLATION:
- display_error ("%s still used by other Cygwin processes.\n"
- "Please stop all of them and retry.", path);
- break;
- case ERROR_ACCESS_DENIED:
- display_error (
- "Your permissions are not sufficient to change the file \"%s\"",
- path);
- break;
- case ERROR_FILE_NOT_FOUND:
- display_error ("%s: No such file.", path);
- break;
- default:
- display_error (path, true, false);
- break;
- }
- return 1;
- }
- if (!(fm = CreateFileMapping (fh, NULL, protect, 0, 0, NULL)))
- display_error ("CreateFileMapping");
- else if (!(haystack = MapViewOfFile (fm, mapping, 0, 0, 0)))
- display_error ("MapViewOfFile");
- else
- {
- size_t haystacklen = GetFileSize (fh, NULL);
- cygwin_props_t *cygwin_props = (cygwin_props_t *)
- memmem ((char *) haystack, haystacklen,
- CYGWIN_PROPS_MAGIC, sizeof (CYGWIN_PROPS_MAGIC));
- if (!cygwin_props)
- display_error ("Can't find Cygwin properties in %s", path);
- else
- {
- if (opt != CO_SHOW_UON)
- cygwin_props->disable_key = opt - CO_ENABLE_UON;
- printf ("Unique object names are %s\n",
- cygwin_props->disable_key ? "disabled" : "enabled");
- UnmapViewOfFile (haystack);
- CloseHandle (fm);
- CloseHandle (fh);
- return 0;
- }
- }
- if (haystack)
- UnmapViewOfFile (haystack);
- if (fm)
- CloseHandle (fm);
- CloseHandle (fh);
- return 1;
-}
+extern "C" NTSTATUS NTAPI RtlGetVersion (PRTL_OSVERSIONINFOEXW);
static void
dump_sysinfo ()
time_t now;
char *found_cygwin_dll;
bool is_nt = false;
- bool more_info = true;
char osname[128];
DWORD obcaseinsensitive = 1;
HKEY key;
+ /* MSVCRT popen (called by pretty_id and dump_sysinfo_services) SEGVs if
+ COMSPEC isn't set correctly. Simply enforce it here. Using
+ Get/SetEnvironmentVariable to set the dir does *not* help, btw.
+ Apparently MSVCRT keeps its own copy of the environment and changing
+ that requires to use _wputenv. */
+ if (!_wgetenv (L"COMSPEC"))
+ {
+ WCHAR comspec[MAX_PATH + 17];
+ wcscpy (comspec, L"COMSPEC=");
+ GetSystemDirectoryW (comspec + 8, MAX_PATH);
+ wcsncat (comspec, L"\\cmd.exe", sizeof comspec);
+ _wputenv (comspec);
+ }
+
printf ("\nCygwin Configuration Diagnostics\n");
time (&now);
printf ("Current System Time: %s\n", ctime (&now));
- OSVERSIONINFOEX osversion;
- osversion.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
- if (!GetVersionEx (reinterpret_cast<LPOSVERSIONINFO>(&osversion)))
- {
- more_info = false;
- osversion.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
- if (!GetVersionEx (reinterpret_cast<LPOSVERSIONINFO>(&osversion)))
- display_error ("dump_sysinfo: GetVersionEx()");
- }
-
- HMODULE k32 = GetModuleHandleW (L"kernel32.dll");
+ RTL_OSVERSIONINFOEXW osversion;
+ osversion.dwOSVersionInfoSize = sizeof (RTL_OSVERSIONINFOEXW);
+ RtlGetVersion (&osversion);
switch (osversion.dwPlatformId)
{
- case VER_PLATFORM_WIN32s:
- strcpy (osname, "32s (not supported)");
- break;
- case VER_PLATFORM_WIN32_WINDOWS:
- strcpy (osname, "95/98/Me (not supported)");
- break;
case VER_PLATFORM_WIN32_NT:
is_nt = true;
- if (osversion.dwMajorVersion == 6)
+ if (osversion.dwMajorVersion >= 6)
{
+ HMODULE k32 = GetModuleHandleW (L"kernel32.dll");
BOOL (WINAPI *GetProductInfo) (DWORD, DWORD, DWORD, DWORD, PDWORD) =
(BOOL (WINAPI *)(DWORD, DWORD, DWORD, DWORD, PDWORD))
GetProcAddress (k32, "GetProductInfo");
- if (osversion.dwMinorVersion == 0)
- strcpy (osname, osversion.wProductType == VER_NT_WORKSTATION
- ? "Vista" : "2008");
- else if (osversion.dwMinorVersion == 1)
- strcpy (osname, osversion.wProductType == VER_NT_WORKSTATION
- ? "7" : "2008 R2");
+ if (osversion.dwMajorVersion == 6)
+ switch (osversion.dwMinorVersion)
+ {
+ case 0:
+ strcpy (osname, osversion.wProductType == VER_NT_WORKSTATION
+ ? "Vista" : "2008");
+ break;
+ case 1:
+ strcpy (osname, osversion.wProductType == VER_NT_WORKSTATION
+ ? "7" : "2008 R2");
+ break;
+ case 2:
+ strcpy (osname, osversion.wProductType == VER_NT_WORKSTATION
+ ? "8" : "2012");
+ break;
+ case 3:
+ strcpy (osname, osversion.wProductType == VER_NT_WORKSTATION
+ ? "8.1" : "2012 R2");
+ break;
+ case 4:
+ default:
+ strcpy (osname, osversion.wProductType == VER_NT_WORKSTATION
+ ? "10 Preview" : "2016 Preview");
+ break;
+ }
+ else if (osversion.dwMajorVersion == 10)
+ {
+ strcpy (osname, osversion.wProductType == VER_NT_WORKSTATION
+ ? "10" : "2016");
+ }
DWORD prod;
if (GetProductInfo (osversion.dwMajorVersion,
osversion.dwMinorVersion,
osversion.wServicePackMinor,
&prod))
{
-#define PRODUCT_UNLICENSED 0xabcdabcd
-#define PRODUCT_ULTIMATE_E 0x00000047
const char *products[] =
- {
+ {
/* 0x00000000 */ "",
/* 0x00000001 */ " Ultimate",
/* 0x00000002 */ " Home Basic",
/* 0x0000000d */ " Server Standard Core",
/* 0x0000000e */ " Server Enterprise Core",
/* 0x0000000f */ " Server Enterprise for Itanium-based Systems",
- /* 0x00000000 */ " Business N",
+ /* 0x00000010 */ " Business N",
/* 0x00000011 */ " Web Server",
/* 0x00000012 */ " HPC Edition",
/* 0x00000013 */ " Home Server",
/* 0x00000016 */ " Storage Server Workgroup",
/* 0x00000017 */ " Storage Server Enterprise",
/* 0x00000018 */ " for Windows Essential Server Solutions",
- /* 0x00000019 */ "",
+ /* 0x00000019 */ " Small Business Server Premium",
/* 0x0000001a */ " Home Premium N",
/* 0x0000001b */ " Enterprise N",
/* 0x0000001c */ " Ultimate N",
/* 0x0000001d */ " Web Server Core",
/* 0x0000001e */ " Essential Business Server Management Server",
- /* 0x0000001f */ " Essential Business Server Security Server"
+ /* 0x0000001f */ " Essential Business Server Security Server",
/* 0x00000020 */ " Essential Business Server Messaging Server",
/* 0x00000021 */ " Server Foundation",
- /* 0x00000022 */ "",
+ /* 0x00000022 */ " Home Server 2011",
/* 0x00000023 */ " without Hyper-V for Windows Essential Server Solutions",
/* 0x00000024 */ " Server Standard without Hyper-V",
/* 0x00000025 */ " Server Datacenter without Hyper-V",
/* 0x00000028 */ " Server Standard Core without Hyper-V",
/* 0x00000029 */ " Server Enterprise Core without Hyper-V",
/* 0x0000002a */ " Hyper-V Server",
- /* 0x0000002b */ "",
- /* 0x0000002c */ "",
- /* 0x0000002d */ "",
- /* 0x0000002e */ "",
+ /* 0x0000002b */ " Storage Server Express Core",
+ /* 0x0000002c */ " Storage Server Standard Core",
+ /* 0x0000002d */ " Storage Server Workgroup Core",
+ /* 0x0000002e */ " Storage Server Enterprise Core",
/* 0x0000002f */ " Starter N",
/* 0x00000030 */ " Professional",
/* 0x00000031 */ " Professional N",
- /* 0x00000032 */ "",
- /* 0x00000033 */ "",
- /* 0x00000034 */ "",
- /* 0x00000035 */ "",
- /* 0x00000036 */ "",
- /* 0x00000037 */ "",
- /* 0x00000038 */ "",
+ /* 0x00000032 */ " Small Business Server 2011 Essentials",
+ /* 0x00000033 */ " Server For SB Solutions",
+ /* 0x00000034 */ " Server Solutions Premium",
+ /* 0x00000035 */ " Server Solutions Premium Core",
+ /* 0x00000036 */ " Server For SB Solutions EM", /* per MSDN, 2012-09-01 */
+ /* 0x00000037 */ " Server For SB Solutions EM", /* per MSDN, 2012-09-01 */
+ /* 0x00000038 */ " Multipoint Server",
/* 0x00000039 */ "",
/* 0x0000003a */ "",
- /* 0x0000003b */ "",
- /* 0x0000003c */ "",
- /* 0x0000003d */ "",
- /* 0x0000003e */ "",
- /* 0x0000003f */ "",
- /* 0x00000040 */ "",
+ /* 0x0000003b */ " Essential Server Solution Management",
+ /* 0x0000003c */ " Essential Server Solution Additional",
+ /* 0x0000003d */ " Essential Server Solution Management SVC",
+ /* 0x0000003e */ " Essential Server Solution Additional SVC",
+ /* 0x0000003f */ " Small Business Server Premium Core",
+ /* 0x00000040 */ " Server Hyper Core V",
/* 0x00000041 */ "",
/* 0x00000042 */ " Starter E",
/* 0x00000043 */ " Home Basic E",
/* 0x00000044 */ " Home Premium E",
/* 0x00000045 */ " Professional E",
/* 0x00000046 */ " Enterprise E",
- /* 0x00000047 */ " Ultimate E"
+ /* 0x00000047 */ " Ultimate E",
+ /* 0x00000048 */ " Server Enterprise (Evaluation inst.)",
+ /* 0x00000049 */ "",
+ /* 0x0000004a */ "",
+ /* 0x0000004b */ "",
+ /* 0x0000004c */ " MultiPoint Server Standard",
+ /* 0x0000004d */ " MultiPoint Server Premium",
+ /* 0x0000004e */ "",
+ /* 0x0000004f */ " Server Standard (Evaluation inst.)",
+ /* 0x00000050 */ " Server Datacenter (Evaluation inst.)",
+ /* 0x00000051 */ "",
+ /* 0x00000052 */ "",
+ /* 0x00000053 */ "",
+ /* 0x00000054 */ " Enterprise N (Evaluation inst.)",
+ /* 0x00000055 */ "",
+ /* 0x00000056 */ "",
+ /* 0x00000057 */ "",
+ /* 0x00000058 */ "",
+ /* 0x00000059 */ "",
+ /* 0x0000005a */ "",
+ /* 0x0000005b */ "",
+ /* 0x0000005c */ "",
+ /* 0x0000005d */ "",
+ /* 0x0000005e */ "",
+ /* 0x0000005f */ " Storage Server Workgroup (Evaluation inst.)",
+ /* 0x00000060 */ " Storage Server Standard (Evaluation inst.)",
+ /* 0x00000061 */ "",
+ /* 0x00000062 */ " N",
+ /* 0x00000063 */ " China",
+ /* 0x00000064 */ " Single Language",
+ /* 0x00000065 */ " Home",
+ /* 0x00000066 */ "",
+ /* 0x00000067 */ " Professional with Media Center",
+ /* 0x00000068 */ " Mobile",
+ /* 0x00000069 */ "",
+ /* 0x0000006a */ "",
+ /* 0x0000006b */ "",
+ /* 0x0000006c */ "",
+ /* 0x0000006d */ "",
+ /* 0x0000006e */ "",
+ /* 0x0000006f */ "",
+ /* 0x00000070 */ "",
+ /* 0x00000071 */ "",
+ /* 0x00000072 */ "",
+ /* 0x00000073 */ "",
+ /* 0x00000074 */ "",
+ /* 0x00000075 */ "",
+ /* 0x00000076 */ "",
+ /* 0x00000077 */ "",
+ /* 0x00000078 */ "",
+ /* 0x00000079 */ " Education",
+ /* 0x0000007a */ " Education N",
+ /* 0x0000007b */ "",
+ /* 0x0000007c */ "",
+ /* 0x0000007d */ "",
+ /* 0x0000007e */ "",
+ /* 0x0000007f */ "",
+ /* 0x00000080 */ "",
+ /* 0x00000081 */ "",
+ /* 0x00000082 */ "",
+ /* 0x00000083 */ "",
+ /* 0x00000084 */ "",
+ /* 0x00000085 */ " Mobile Enterprise",
};
if (prod == PRODUCT_UNLICENSED)
- strcat (osname, "Unlicensed");
- else if (prod > PRODUCT_ULTIMATE_E)
- strcat (osname, "");
+ strcat (osname, "Unlicensed");
+ else if (prod > 0x00000085)
+ strcat (osname, "");
else
- strcat (osname, products[prod]);
+ strcat (osname, products[prod]);
}
else
{
}
}
- else if (osversion.dwMajorVersion == 5)
- {
- if (osversion.dwMinorVersion == 0)
- {
- strcpy (osname, "2000");
- if (osversion.wProductType == VER_NT_WORKSTATION)
- strcat (osname, " Professional");
- else if (osversion.wSuiteMask & VER_SUITE_DATACENTER)
- strcat (osname, " Datacenter Server");
- else if (osversion.wSuiteMask & VER_SUITE_ENTERPRISE)
- strcat (osname, " Advanced Server");
- else
- strcat (osname, " Server");
- }
- else if (osversion.dwMinorVersion == 1)
- {
- strcpy (osname, "XP");
- if (GetSystemMetrics (SM_MEDIACENTER))
- strcat (osname, " Media Center Edition");
- else if (GetSystemMetrics (SM_TABLETPC))
- strcat (osname, " Tablet PC Edition");
- else if (GetSystemMetrics (SM_STARTER))
- strcat (osname, " Starter Edition");
- else if (osversion.wSuiteMask & VER_SUITE_PERSONAL)
- strcat (osname, " Home Edition");
- else
- strcat (osname, " Professional");
- }
- else if (osversion.dwMinorVersion == 2)
- {
- strcpy (osname, "2003 Server");
- if (GetSystemMetrics (SM_SERVERR2))
- strcat (osname, " R2");
- if (osversion.wSuiteMask & VER_SUITE_BLADE)
- strcat (osname, " Web Edition");
- else if (osversion.wSuiteMask & VER_SUITE_DATACENTER)
- strcat (osname, " Datacenter Edition");
- else if (osversion.wSuiteMask & VER_SUITE_ENTERPRISE)
- strcat (osname, " Enterprise Edition");
- else if (osversion.wSuiteMask & VER_SUITE_COMPUTE_SERVER)
- strcat (osname, " Compute Cluster Edition");
- }
- }
- else if (osversion.dwMajorVersion == 4)
- {
- strcpy (osname, "NT 4");
- if (more_info)
- {
- if (osversion.wProductType == VER_NT_WORKSTATION)
- strcat (osname, " Workstation");
- else
- {
- strcat (osname, " Server");
- if (osversion.wSuiteMask & VER_SUITE_ENTERPRISE)
- strcat (osname, " Enterprise Edition");
- }
- }
- }
else
strcpy (osname, "NT");
break;
strcpy (osname, "??");
break;
}
- printf ("Windows %s Ver %lu.%lu Build %lu %s\n", osname,
+ printf ("Windows %s Ver %lu.%lu Build %lu %ls\n", osname,
osversion.dwMajorVersion, osversion.dwMinorVersion,
osversion.dwPlatformId == VER_PLATFORM_WIN32_NT ?
osversion.dwBuildNumber : (osversion.dwBuildNumber & 0xffff),
osversion.dwPlatformId == VER_PLATFORM_WIN32_NT ?
- osversion.szCSDVersion : "");
+ osversion.szCSDVersion : L"");
if (osversion.dwPlatformId == VER_PLATFORM_WIN32s
|| osversion.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
exit (EXIT_FAILURE);
- BOOL (WINAPI *wow64_func) (HANDLE, PBOOL) = (BOOL (WINAPI *) (HANDLE, PBOOL))
- GetProcAddress (k32, "IsWow64Process");
BOOL is_wow64 = FALSE;
- if (wow64_func && wow64_func (GetCurrentProcess (), &is_wow64) && is_wow64)
+ if (IsWow64Process (GetCurrentProcess (), &is_wow64) && is_wow64)
{
- void (WINAPI *nativinfo) (LPSYSTEM_INFO) = (void (WINAPI *)
- (LPSYSTEM_INFO)) GetProcAddress (k32, "GetNativeSystemInfo");
SYSTEM_INFO natinfo;
- nativinfo (&natinfo);
+ GetNativeSystemInfo (&natinfo);
fputs ("\nRunning under WOW64 on ", stdout);
switch (natinfo.wProcessorArchitecture)
{
{
for (e = s; *e && *e != sep; e++);
if (e-s)
- printf ("\t%.*s\n", e - s, s);
+ printf ("\t%.*s\n", (int) (e - s), s);
else
puts ("\t.");
count_path_items++;
printf ("Use '-r' to scan registry\n\n");
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE,
- "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\kernel",
- 0, KEY_READ, &key) == ERROR_SUCCESS)
+ "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\kernel",
+ 0, KEY_READ, &key) == ERROR_SUCCESS)
{
DWORD size;
RegQueryValueEx (key, "obcaseinsensitive", NULL, NULL,
- (LPBYTE) &obcaseinsensitive, &size);
+ (LPBYTE) &obcaseinsensitive, &size);
RegCloseKey (key);
}
printf ("obcaseinsensitive set to %lu\n\n", obcaseinsensitive);
SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
int drivemask = GetLogicalDrives ();
- BOOL (WINAPI * gdfse) (LPCSTR, long long *, long long *, long long *) =
- (BOOL (WINAPI *) (LPCSTR, long long *, long long *, long long *))
- GetProcAddress (k32, "GetDiskFreeSpaceExA");
-
for (i = 0; i < 26; i++)
{
if (!(drivemask & (1 << i)))
long capacity_mb = -1;
int percent_full = -1;
- long long free_me = 0ULL, free_bytes = 0ULL, total_bytes = 1ULL;
- if (gdfse != NULL && gdfse (drive, &free_me, &total_bytes, &free_bytes))
+ ULARGE_INTEGER free_me, free_bytes, total_bytes;
+ free_me.QuadPart = free_bytes.QuadPart = 0ULL;
+ total_bytes.QuadPart = 1ULL;
+ if (GetDiskFreeSpaceEx (drive, &free_me, &total_bytes, &free_bytes))
{
- capacity_mb = total_bytes / (1024L * 1024L);
- percent_full = 100 - (int) ((100.0 * free_me) / total_bytes);
+ capacity_mb = total_bytes.QuadPart / (1024L * 1024L);
+ percent_full = 100 - (int) ((100.0 * free_me.QuadPart)
+ / total_bytes.QuadPart);
}
else
{
printf ("%7dMb %3d%% ", (int) capacity_mb, (int) percent_full);
else
printf (" N/A N/A ");
- printf ("%s %s %s %s %s %s %s\n",
+ printf ("%s %s %s %s %s %s %s %s\n",
flags & FS_CASE_IS_PRESERVED ? "CP" : " ",
flags & FS_CASE_SENSITIVE ? "CS" : " ",
flags & FS_UNICODE_STORED_ON_DISK ? "UN" : " ",
flags & FS_PERSISTENT_ACLS ? "PA" : " ",
flags & FS_FILE_COMPRESSION ? "FC" : " ",
flags & FS_VOL_IS_COMPRESSED ? "VC" : " ",
-#if 0
- flags & FILE_SUPPORTS_ENCRYPTION ? "EN" : " ",
- flags & FILE_SUPPORTS_OBJECT_IDS ? "OI" : " ",
- flags & FILE_SUPPORTS_REPARSE_POINTS ? "RP" : " ",
- flags & FILE_SUPPORTS_SPARSE_FILES ? "SP" : " ",
flags & FILE_VOLUME_QUOTAS ? "QU" : " ",
-#endif
name);
}
if (strcasecmp (f, "cygwin1.dll") == 0)
{
if (!cygwin_dll_count)
- strcpy (cygdll_path, pth->dir);
+ strcpy (cygdll_path, pth->dir);
if (!cygwin_dll_count
|| strcasecmp (cygdll_path, pth->dir) != 0)
cygwin_dll_count++;
return 0;
}
-/* RFC1738 says that these do not need to be escaped. */
-static const char safe_chars[] = "$-_.+!*'(),";
+/* These do not need to be escaped in application/x-www-form-urlencoded */
+static const char safe_chars[] = "$-_.!*'(),";
/* the URL to query. */
static const char base_url[] =
"http://cygwin.com/cgi-bin2/package-grep.cgi?text=1&grep=";
+#ifdef __x86_64__
+#define ARCH_STR "&arch=x86_64"
+#else
+#define ARCH_STR "&arch=x86"
+#endif
+static const char *ARCH_str = ARCH_STR;
+
/* Queries Cygwin web site for packages containing files matching a regexp.
Return value is 1 if there was a problem, otherwise 0. */
static int
{
char buf[1024];
- /* Attempt to dynamically load the necessary WinInet API functions so that
- cygcheck can still function on older systems without IE. */
- HMODULE hWinInet;
- if (!(hWinInet = LoadLibrary ("wininet.dll")))
- {
- fputs ("Unable to locate WININET.DLL. This feature requires Microsoft "
- "Internet Explorer v3 or later to function.\n", stderr);
- return 1;
- }
-
- /* InternetCloseHandle is used outside this function so it is declared
- global. The rest of these functions are only used here, so declare them
- and call GetProcAddress for each of them with the following macro. */
-
- pInternetCloseHandle = (BOOL (WINAPI *) (HINTERNET))
- GetProcAddress (hWinInet, "InternetCloseHandle");
-#define make_func_pointer(name, ret, args) ret (WINAPI * p##name) args = \
- (ret (WINAPI *) args) GetProcAddress (hWinInet, #name);
- make_func_pointer (InternetAttemptConnect, DWORD, (DWORD));
- make_func_pointer (InternetOpenA, HINTERNET, (LPCSTR, DWORD, LPCSTR, LPCSTR,
- DWORD));
- make_func_pointer (InternetOpenUrlA, HINTERNET, (HINTERNET, LPCSTR, LPCSTR,
- DWORD, DWORD, DWORD));
- make_func_pointer (InternetReadFile, BOOL, (HINTERNET, PVOID, DWORD, PDWORD));
- make_func_pointer (HttpQueryInfoA, BOOL, (HINTERNET, DWORD, PVOID, PDWORD,
- PDWORD));
-#undef make_func_pointer
-
- if(!pInternetCloseHandle || !pInternetAttemptConnect || !pInternetOpenA
- || !pInternetOpenUrlA || !pInternetReadFile || !pHttpQueryInfoA)
- {
- fputs ("Unable to load one or more functions from WININET.DLL. This "
- "feature requires Microsoft Internet Explorer v3 or later to "
- "function.\n", stderr);
- return 1;
- }
-
/* construct the actual URL by escaping */
- char *url = (char *) alloca (sizeof (base_url) + strlen (search) * 3);
+ char *url = (char *) alloca (sizeof (base_url) + strlen (ARCH_str)
+ + strlen (search) * 3);
strcpy (url, base_url);
char *dest;
dest += 2;
}
}
- *dest = 0;
+ strcpy (dest, ARCH_str);
/* Connect to the net and open the URL. */
- if (pInternetAttemptConnect (0) != ERROR_SUCCESS)
+ if (InternetAttemptConnect (0) != ERROR_SUCCESS)
{
fputs ("An internet connection is required for this function.\n", stderr);
return 1;
/* Initialize WinInet and attempt to fetch our URL. */
HINTERNET hi = NULL, hurl = NULL;
- if (!(hi = pInternetOpenA ("cygcheck", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0)))
+ if (!(hi = InternetOpenA ("cygcheck", INTERNET_OPEN_TYPE_PRECONFIG,
+ NULL, NULL, 0)))
return display_internet_error ("InternetOpen() failed", NULL);
- if (!(hurl = pInternetOpenUrlA (hi, url, NULL, 0, 0, 0)))
+ if (!(hurl = InternetOpenUrlA (hi, url, NULL, 0, 0, 0)))
return display_internet_error ("unable to contact cygwin.com site, "
"InternetOpenUrl() failed", hi, NULL);
/* Check the HTTP response code. */
DWORD rc = 0, rc_s = sizeof (DWORD);
- if (!pHttpQueryInfoA (hurl, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,
+ if (!HttpQueryInfoA (hurl, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,
(void *) &rc, &rc_s, NULL))
return display_internet_error ("HttpQueryInfo() failed", hurl, hi, NULL);
DWORD numread;
do
{
- if (!pInternetReadFile (hurl, (void *) buf, sizeof (buf), &numread))
+ if (!InternetReadFile (hurl, (void *) buf, sizeof (buf), &numread))
return display_internet_error ("InternetReadFile failed", hurl, hi, NULL);
if (numread)
fwrite ((void *) buf, (size_t) numread, 1, stdout);
}
while (numread);
- pInternetCloseHandle (hurl);
- pInternetCloseHandle (hi);
+ InternetCloseHandle (hurl);
+ InternetCloseHandle (hi);
return 0;
}
-static void
+static void __attribute__ ((__noreturn__))
usage (FILE * stream, int status)
{
fprintf (stream, "\
cygcheck -l [PACKAGE]...\n\
cygcheck -p REGEXP\n\
cygcheck --delete-orphaned-installation-keys\n\
- cygcheck --enable-unique-object-names Cygwin-DLL\n\
- cygcheck --disable-unique-object-names Cygwin-DLL\n\
- cygcheck --show-unique-object-names Cygwin-DLL\n\
cygcheck -h\n\n\
List system information, check installed packages, or query package database.\n\
\n\
\n\
PROGRAM list library (DLL) dependencies of PROGRAM\n\
-c, --check-setup show installed version of PACKAGE and verify integrity\n\
- (or for all installed packages if none specified)\n\
+ (or for all installed packages if none specified)\n\
-d, --dump-only just list packages, do not verify (with -c)\n\
-s, --sysinfo produce diagnostic system information (implies -c)\n\
-r, --registry also scan registry for Cygwin settings (with -s)\n\
-k, --keycheck perform a keyboard check session (must be run from a\n\
- plain console only, not from a pty/rxvt/xterm)\n\
+ plain console only, not from a pty/rxvt/xterm)\n\
-f, --find-package find the package to which FILE belongs\n\
-l, --list-package list contents of PACKAGE (or all packages if none given)\n\
-p, --package-query search for REGEXP in the entire cygwin.com package\n\
- repository (requires internet connectivity)\n\
+ repository (requires internet connectivity)\n\
--delete-orphaned-installation-keys\n\
- Delete installation keys of old, now unused\n\
- installations from the registry. Requires the right\n\
- to change the registry.\n\
- --enable-unique-object-names Cygwin-DLL\n\
- --disable-unique-object-names Cygwin-DLL\n\
- --show-unique-object-names Cygwin-DLL\n\
- Enable, disable, or show the setting of the\n\
- \"unique object names\" setting in the Cygwin DLL\n\
- given as argument to this option. The DLL path must\n\
- be given as valid Windows(!) path.\n\
- See the users guide for more information.\n\
- If you don't know what this means, don't change it.\n\
+ Delete installation keys of old, now unused\n\
+ installations from the registry. Requires the right\n\
+ to change the registry.\n\
-v, --verbose produce more verbose output\n\
-h, --help annotate output with explanatory comments when given\n\
- with another command, otherwise print this help\n\
+ with another command, otherwise print this help\n\
-V, --version print the version of cygcheck and exit\n\
\n\
Note: -c, -f, and -l only report on packages that are currently installed. To\n\
{"list-package", no_argument, NULL, 'l'},
{"package-query", no_argument, NULL, 'p'},
{"delete-orphaned-installation-keys", no_argument, NULL, CO_DELETE_KEYS},
- {"enable-unique-object-names", no_argument, NULL, CO_ENABLE_UON},
- {"disable-unique-object-names", no_argument, NULL, CO_DISABLE_UON},
- {"show-unique-object-names", no_argument, NULL, CO_SHOW_UON},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, 0, 'V'},
{0, no_argument, NULL, 0}
static void
print_version ()
{
- const char *v = strchr (version, ':');
- int len;
- if (!v)
- {
- v = "?";
- len = 1;
- }
- else
- {
- v += 2;
- len = strchr (v, ' ') - v;
- }
- printf ("\
-cygcheck version %.*s\n\
-System Checker for Cygwin\n\
-Copyright (C) 1998 - 2008 Red Hat, Inc.\n\
-Compiled on %s\n\
-", len, v, __DATE__);
+ printf ("cygcheck (cygwin) %d.%d.%d\n"
+ "System Checker for Cygwin\n"
+ "Copyright (C) 1998 - %s Cygwin Authors\n"
+ "This is free software; see the source for copying conditions. "
+ "There is NO\n"
+ "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR "
+ "PURPOSE.\n",
+ CYGWIN_VERSION_DLL_MAJOR / 1000,
+ CYGWIN_VERSION_DLL_MAJOR % 1000,
+ CYGWIN_VERSION_DLL_MINOR,
+ strrchr (__DATE__, ' ') + 1);
}
void
}
extern "C" {
-unsigned long (*cygwin_internal) (int, ...);
+uintptr_t (*cygwin_internal) (int, ...);
WCHAR cygwin_dll_path[32768];
};
if (!(h = LoadLibrary ("cygwin1.dll")))
return;
GetModuleFileNameW (h, cygwin_dll_path, 32768);
- if ((cygwin_internal = (DWORD (*) (int, ...)) GetProcAddress (h, "cygwin_internal")))
+ if ((cygwin_internal = (uintptr_t (*) (int, ...))
+ GetProcAddress (h, "cygwin_internal")))
{
char **av = (char **) cygwin_internal (CW_ARGV);
- if (av && ((DWORD) av != (DWORD) -1))
+ if (av && ((uintptr_t) av != (uintptr_t) -1))
{
- /* Copy cygwin's idea of the argument list into this Window application. */
+ /* Copy cygwin's idea of the argument list into this Window
+ application. */
for (argc = 0; av[argc]; argc++)
continue;
argv = (char **) calloc (argc + 1, sizeof (char *));
char **envp = (char **) cygwin_internal (CW_ENVP);
- if (envp && ((DWORD) envp != (DWORD) -1))
+ if (envp && ((uintptr_t) envp != (uintptr_t) -1))
{
- /* Store path and revert to this value, otherwise path gets overwritten
- by the POSIXy Cygwin variation, which breaks cygcheck.
+ /* Store path and revert to this value, otherwise path gets
+ overwritten by the POSIXy Cygwin variation, which breaks cygcheck.
Another approach would be to use the Cygwin PATH and convert it to
Win32 again. */
char *path = NULL;
putenv (path);
}
}
- FreeLibrary (h);
+ /* GDB chokes when the DLL got unloaded and, for some reason, fails to set
+ any breakpoint after the fact. */
+ if (!IsDebuggerPresent ())
+ FreeLibrary (h);
}
int
bool ok = true;
load_cygwin (argc, argv);
+ _setmode (1, _O_BINARY);
+ _setmode (2, _O_BINARY);
+
/* Need POSIX sorting while parsing args, but don't forget the
user's original environment. */
char *posixly = getenv ("POSIXLY_CORRECT");
givehelp = 1;
break;
case CO_DELETE_KEYS:
- del_orphaned_reg = 1;
- break;
- case CO_ENABLE_UON:
- case CO_DISABLE_UON:
- case CO_SHOW_UON:
- unique_object_name_opt = i;
+ del_orphaned_reg = 1;
break;
case 'V':
print_version ();
exit (0);
default:
- usage (stderr, 1);
- /*NOTREACHED*/}
+ fprintf (stderr, "Try `cygcheck --help' for more information.\n");
+ exit (1);
+ /*NOTREACHED*/
+ }
argc -= optind;
argv += optind;
if (posixly == NULL)
}
if ((check_setup || sysinfo || find_package || list_package || grep_packages
- || del_orphaned_reg || unique_object_name_opt)
+ || del_orphaned_reg)
&& keycheck)
usage (stderr, 1);
&& (check_setup || del_orphaned_reg))
usage (stderr, 1);
- if ((check_setup || sysinfo || find_package || list_package || grep_packages
- || del_orphaned_reg)
- && unique_object_name_opt)
- usage (stderr, 1);
-
if (dump_only && !check_setup && !sysinfo)
usage (stderr, 1);
if (keycheck)
return check_keys ();
- if (unique_object_name_opt)
- return handle_unique_object_name (unique_object_name_opt, *argv);
if (del_orphaned_reg)
del_orphaned_reg_installations ();
if (grep_packages)