2000-02-17 20:38:33 +01:00
|
|
|
/* cygcheck.cc
|
|
|
|
|
2013-01-21 17:28:27 +01:00
|
|
|
Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
|
2015-08-30 21:32:56 +02:00
|
|
|
2009, 2010, 2011, 2012, 2013, 2014, 2015 Red Hat, Inc.
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
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. */
|
|
|
|
|
2013-11-19 12:14:36 +01:00
|
|
|
#define _WIN32_WINNT 0x0602
|
2005-05-09 03:56:34 +02:00
|
|
|
#define cygwin_internal cygwin_internal_dontuse
|
2000-02-17 20:38:33 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2005-11-22 18:19:17 +01:00
|
|
|
#include <stdarg.h>
|
2000-02-17 20:38:33 +01:00
|
|
|
#include <string.h>
|
2002-09-19 05:48:19 +02:00
|
|
|
#include <sys/time.h>
|
2002-09-17 19:13:21 +02:00
|
|
|
#include <ctype.h>
|
2003-03-01 04:38:19 +01:00
|
|
|
#include <io.h>
|
2000-02-17 20:38:33 +01:00
|
|
|
#include <windows.h>
|
2005-11-22 18:19:17 +01:00
|
|
|
#include <wininet.h>
|
2003-03-01 04:38:19 +01:00
|
|
|
#include "path.h"
|
2009-03-14 15:56:20 +01:00
|
|
|
#include "wide_path.h"
|
2003-09-11 04:56:40 +02:00
|
|
|
#include <getopt.h>
|
2012-10-24 12:15:27 +02:00
|
|
|
#include "../cygwin/include/cygwin/version.h"
|
|
|
|
#include "../cygwin/include/sys/cygwin.h"
|
2013-04-23 11:44:36 +02:00
|
|
|
#define _NOMNTENT_MACROS
|
2012-10-24 12:15:27 +02:00
|
|
|
#include "../cygwin/include/mntent.h"
|
|
|
|
#include "../cygwin/cygprops.h"
|
2005-05-09 03:56:34 +02:00
|
|
|
#undef cygwin_internal
|
2010-08-28 13:22:37 +02:00
|
|
|
#include "loadlib.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2012-07-11 18:41:51 +02:00
|
|
|
#ifndef max
|
|
|
|
#define max __max
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef alloca
|
2004-10-14 19:35:46 +02:00
|
|
|
#define alloca __builtin_alloca
|
2012-07-11 18:41:51 +02:00
|
|
|
#endif
|
2004-10-14 19:35:46 +02:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
int verbose = 0;
|
|
|
|
int registry = 0;
|
|
|
|
int sysinfo = 0;
|
|
|
|
int givehelp = 0;
|
2000-09-29 13:20:53 +02:00
|
|
|
int keycheck = 0;
|
2001-11-11 07:07:36 +01:00
|
|
|
int check_setup = 0;
|
2003-09-11 18:24:26 +02:00
|
|
|
int dump_only = 0;
|
2003-08-15 22:26:11 +02:00
|
|
|
int find_package = 0;
|
|
|
|
int list_package = 0;
|
2005-11-22 18:19:17 +01:00
|
|
|
int grep_packages = 0;
|
2009-10-31 14:26:37 +01:00
|
|
|
int del_orphaned_reg = 0;
|
|
|
|
int unique_object_name_opt = 0;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2007-06-04 03:57:16 +02:00
|
|
|
static char emptystr[] = "";
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
#ifdef __GNUC__
|
|
|
|
typedef long long longlong;
|
|
|
|
#else
|
|
|
|
typedef __int64 longlong;
|
|
|
|
#endif
|
|
|
|
|
2007-08-03 21:41:48 +02:00
|
|
|
/* In dump_setup.cc */
|
2001-11-12 01:14:27 +01:00
|
|
|
void dump_setup (int, char **, bool);
|
2003-08-15 22:26:11 +02:00
|
|
|
void package_find (int, char **);
|
|
|
|
void package_list (int, char **);
|
2007-08-03 21:41:48 +02:00
|
|
|
/* In bloda.cc */
|
|
|
|
void dump_dodgy_apps (int verbose);
|
2009-10-31 14:26:37 +01:00
|
|
|
/* Forward declaration */
|
|
|
|
static void usage (FILE *, int);
|
2001-11-11 07:07:36 +01:00
|
|
|
|
2002-02-27 17:10:17 +01:00
|
|
|
static const char *known_env_vars[] = {
|
2000-02-17 20:38:33 +01:00
|
|
|
"c_include_path",
|
|
|
|
"compiler_path",
|
|
|
|
"cxx_include_path",
|
|
|
|
"cygwin",
|
|
|
|
"cygwin32",
|
|
|
|
"dejagnu",
|
|
|
|
"expect",
|
|
|
|
"gcc_default_options",
|
|
|
|
"gcc_exec_prefix",
|
|
|
|
"home",
|
|
|
|
"ld_library_path",
|
|
|
|
"library_path",
|
|
|
|
"login",
|
|
|
|
"lpath",
|
|
|
|
"make_mode",
|
|
|
|
"makeflags",
|
|
|
|
"path",
|
|
|
|
"pwd",
|
|
|
|
"strace",
|
|
|
|
"tcl_library",
|
|
|
|
"user",
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2000-10-28 07:00:00 +02:00
|
|
|
struct
|
|
|
|
{
|
2000-02-17 20:38:33 +01:00
|
|
|
const char *name;
|
|
|
|
int missing_is_good;
|
2000-10-28 07:00:00 +02:00
|
|
|
}
|
2002-03-07 04:13:17 +01:00
|
|
|
static common_apps[] = {
|
2003-02-07 05:51:26 +01:00
|
|
|
{"awk", 0},
|
2000-10-28 07:39:38 +02:00
|
|
|
{"bash", 0},
|
|
|
|
{"cat", 0},
|
2003-02-07 05:51:26 +01:00
|
|
|
{"cp", 0},
|
2000-10-28 07:39:38 +02:00
|
|
|
{"cpp", 1},
|
2005-12-29 20:23:46 +01:00
|
|
|
{"crontab", 0},
|
2000-10-28 07:39:38 +02:00
|
|
|
{"find", 0},
|
|
|
|
{"gcc", 0},
|
|
|
|
{"gdb", 0},
|
2003-02-07 05:51:26 +01:00
|
|
|
{"grep", 0},
|
2005-12-15 04:36:14 +01:00
|
|
|
{"kill", 0},
|
2000-10-28 07:39:38 +02:00
|
|
|
{"ld", 0},
|
|
|
|
{"ls", 0},
|
|
|
|
{"make", 0},
|
2003-02-07 05:51:26 +01:00
|
|
|
{"mv", 0},
|
2006-01-19 22:16:38 +01:00
|
|
|
{"patch", 0},
|
2005-12-15 04:36:14 +01:00
|
|
|
{"perl", 0},
|
2003-02-07 05:51:26 +01:00
|
|
|
{"rm", 0},
|
|
|
|
{"sed", 0},
|
2005-12-15 04:36:14 +01:00
|
|
|
{"ssh", 0},
|
2000-10-28 07:39:38 +02:00
|
|
|
{"sh", 0},
|
2003-02-07 05:51:26 +01:00
|
|
|
{"tar", 0},
|
2005-12-15 04:36:14 +01:00
|
|
|
{"test", 0},
|
2005-12-29 20:23:46 +01:00
|
|
|
{"vi", 0},
|
|
|
|
{"vim", 0},
|
2000-10-28 07:39:38 +02:00
|
|
|
{0, 0}
|
2000-02-17 20:38:33 +01:00
|
|
|
};
|
|
|
|
|
2009-10-31 14:26:37 +01:00
|
|
|
/* Options without ASCII single char representation. */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
CO_DELETE_KEYS = 0x100,
|
|
|
|
CO_ENABLE_UON = 0x101,
|
|
|
|
CO_DISABLE_UON = 0x102,
|
|
|
|
CO_SHOW_UON = 0x103
|
|
|
|
};
|
|
|
|
|
2006-01-19 21:17:11 +01:00
|
|
|
static int num_paths, max_paths;
|
2007-06-04 03:57:16 +02:00
|
|
|
struct pathlike
|
|
|
|
{
|
|
|
|
char *dir;
|
|
|
|
bool issys;
|
2008-09-13 00:43:10 +02:00
|
|
|
void check_existence (const char *fn, int showall, int verbose,
|
|
|
|
char* first, const char *ext1 = "",
|
|
|
|
const char *ext2 = "");
|
2007-06-04 03:57:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
pathlike *paths;
|
2006-01-19 21:17:11 +01:00
|
|
|
int first_nonsys_path;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2004-11-18 06:20:23 +01:00
|
|
|
void
|
|
|
|
eprintf (const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start (ap, format);
|
|
|
|
vfprintf (stderr, format, ap);
|
|
|
|
va_end (ap);
|
|
|
|
}
|
|
|
|
|
2000-12-16 05:53:30 +01:00
|
|
|
/*
|
2004-11-11 02:56:02 +01:00
|
|
|
* display_error() is used to report failure modes
|
2000-12-16 05:53:30 +01:00
|
|
|
*/
|
2002-02-27 17:10:17 +01:00
|
|
|
static int
|
2007-06-04 03:57:16 +02:00
|
|
|
display_error (const char *name, bool show_error, bool print_failed)
|
2000-12-16 05:53:30 +01:00
|
|
|
{
|
2007-06-04 03:57:16 +02:00
|
|
|
fprintf (stderr, "cygcheck: %s", name);
|
2004-11-11 02:17:29 +01:00
|
|
|
if (show_error)
|
2007-06-04 03:57:16 +02:00
|
|
|
fprintf (stderr, "%s: %lu\n",
|
2004-11-11 02:17:29 +01:00
|
|
|
print_failed ? " failed" : "", GetLastError ());
|
|
|
|
else
|
2007-06-04 03:57:16 +02:00
|
|
|
fprintf (stderr, "%s\n",
|
2004-11-11 02:17:29 +01:00
|
|
|
print_failed ? " failed" : "");
|
2000-12-16 05:53:30 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-06-04 03:57:16 +02:00
|
|
|
static int
|
|
|
|
display_error (const char *name)
|
|
|
|
{
|
|
|
|
return display_error (name, true, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
display_error (const char *fmt, const char *x)
|
|
|
|
{
|
|
|
|
char buf[4000];
|
2009-03-14 15:56:20 +01:00
|
|
|
snprintf (buf, sizeof buf, fmt, x);
|
2007-06-04 03:57:16 +02:00
|
|
|
return display_error (buf, false, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
display_error_fmt (const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char buf[4000];
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
va_start (va, fmt);
|
2009-03-14 15:56:20 +01:00
|
|
|
vsnprintf (buf, sizeof buf, fmt, va);
|
2007-06-04 03:57:16 +02:00
|
|
|
return display_error (buf, false, false);
|
|
|
|
}
|
|
|
|
|
2005-11-22 18:19:17 +01:00
|
|
|
/* Display a WinInet error message, and close a variable number of handles.
|
|
|
|
(Passed a list of handles terminated by NULL.) */
|
|
|
|
static int
|
|
|
|
display_internet_error (const char *message, ...)
|
|
|
|
{
|
|
|
|
DWORD err = GetLastError ();
|
|
|
|
TCHAR err_buf[256];
|
|
|
|
va_list hptr;
|
|
|
|
HINTERNET h;
|
|
|
|
|
|
|
|
/* in the case of a successful connection but 404 response, there is no
|
|
|
|
win32 error message, but we still get passed a message to display. */
|
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
if (FormatMessage (FORMAT_MESSAGE_FROM_HMODULE,
|
2007-06-04 03:57:16 +02:00
|
|
|
GetModuleHandle ("wininet.dll"), err, 0, err_buf,
|
|
|
|
sizeof (err_buf), NULL) == 0)
|
|
|
|
strcpy (err_buf, "(Unknown error)");
|
2005-11-22 18:19:17 +01:00
|
|
|
|
2008-09-13 00:43:10 +02:00
|
|
|
fprintf (stderr, "cygcheck: %s: %s (win32 error %lu)\n", message,
|
2007-06-04 03:57:16 +02:00
|
|
|
err_buf, err);
|
2005-11-22 18:19:17 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
fprintf (stderr, "cygcheck: %s\n", message);
|
|
|
|
|
|
|
|
va_start (hptr, message);
|
|
|
|
while ((h = va_arg (hptr, HINTERNET)) != 0)
|
2013-11-19 12:14:36 +01:00
|
|
|
InternetCloseHandle (h);
|
2005-11-22 18:19:17 +01:00
|
|
|
va_end (hptr);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-02-27 17:10:17 +01:00
|
|
|
static void
|
2007-06-04 03:57:16 +02:00
|
|
|
add_path (char *s, int maxlen, bool issys)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
if (num_paths >= max_paths)
|
|
|
|
{
|
|
|
|
max_paths += 10;
|
2007-06-04 03:57:16 +02:00
|
|
|
/* Extend path array */
|
|
|
|
paths = (pathlike *) realloc (paths, (1 + max_paths) * sizeof (paths[0]));
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2007-06-04 03:57:16 +02:00
|
|
|
|
|
|
|
pathlike *pth = paths + num_paths;
|
|
|
|
|
|
|
|
/* Allocate space for directory in path list */
|
|
|
|
char *dir = (char *) calloc (maxlen + 2, sizeof (char));
|
|
|
|
if (dir == NULL)
|
2000-12-16 05:53:30 +01:00
|
|
|
{
|
2007-06-04 03:57:16 +02:00
|
|
|
display_error ("add_path: calloc() failed");
|
2000-12-16 05:53:30 +01:00
|
|
|
return;
|
|
|
|
}
|
2007-06-04 03:57:16 +02:00
|
|
|
|
|
|
|
/* Copy input directory to path list */
|
|
|
|
memcpy (dir, s, maxlen);
|
|
|
|
|
|
|
|
/* Add a trailing slash by default */
|
|
|
|
char *e = strchr (dir, '\0');
|
|
|
|
if (e != dir && e[-1] != '\\')
|
|
|
|
strcpy (e, "\\");
|
|
|
|
|
|
|
|
/* Fill out this element */
|
|
|
|
pth->dir = dir;
|
|
|
|
pth->issys = issys;
|
|
|
|
pth[1].dir = NULL;
|
2000-02-17 20:38:33 +01:00
|
|
|
num_paths++;
|
|
|
|
}
|
|
|
|
|
2002-02-27 17:10:17 +01:00
|
|
|
static void
|
2000-02-17 20:38:33 +01:00
|
|
|
init_paths ()
|
|
|
|
{
|
|
|
|
char tmp[4000], *sl;
|
2007-06-04 03:57:16 +02:00
|
|
|
add_path ((char *) ".", 1, true); /* to be replaced later */
|
2005-05-27 17:45:53 +02:00
|
|
|
|
2005-03-24 15:48:15 +01:00
|
|
|
if (GetCurrentDirectory (4000, tmp))
|
2007-06-04 03:57:16 +02:00
|
|
|
add_path (tmp, strlen (tmp), true);
|
2005-03-24 15:48:15 +01:00
|
|
|
else
|
2005-05-27 17:45:53 +02:00
|
|
|
display_error ("init_paths: GetCurrentDirectory()");
|
|
|
|
|
2000-12-16 05:53:30 +01:00
|
|
|
if (GetSystemDirectory (tmp, 4000))
|
2007-06-04 03:57:16 +02:00
|
|
|
add_path (tmp, strlen (tmp), true);
|
2000-12-16 05:53:30 +01:00
|
|
|
else
|
2004-11-11 02:56:02 +01:00
|
|
|
display_error ("init_paths: GetSystemDirectory()");
|
2000-02-17 20:38:33 +01:00
|
|
|
sl = strrchr (tmp, '\\');
|
|
|
|
if (sl)
|
|
|
|
{
|
|
|
|
strcpy (sl, "\\SYSTEM");
|
2007-06-04 03:57:16 +02:00
|
|
|
add_path (tmp, strlen (tmp), true);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
GetWindowsDirectory (tmp, 4000);
|
2007-06-04 03:57:16 +02:00
|
|
|
add_path (tmp, strlen (tmp), true);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2001-11-11 04:06:59 +01:00
|
|
|
char *wpath = getenv ("PATH");
|
2006-01-19 21:17:11 +01:00
|
|
|
if (!wpath)
|
2007-06-04 03:57:16 +02:00
|
|
|
display_error ("WARNING: PATH is not set\n", "");
|
2006-01-19 21:17:11 +01:00
|
|
|
else
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2001-11-11 04:06:59 +01:00
|
|
|
char *b, *e;
|
2000-02-17 20:38:33 +01:00
|
|
|
b = wpath;
|
|
|
|
while (1)
|
|
|
|
{
|
2007-06-04 03:57:16 +02:00
|
|
|
for (e = b; *e && *e != ';'; e++)
|
|
|
|
continue; /* loop terminates at first ';' or EOS */
|
|
|
|
if (strncmp(b, ".\\", 2) != 0)
|
|
|
|
add_path (b, e - b, false);
|
2000-02-17 20:38:33 +01:00
|
|
|
if (!*e)
|
|
|
|
break;
|
|
|
|
b = e + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
#define LINK_EXTENSION ".lnk"
|
|
|
|
|
2007-06-04 03:57:16 +02:00
|
|
|
void
|
|
|
|
pathlike::check_existence (const char *fn, int showall, int verbose,
|
|
|
|
char* first, const char *ext1, const char *ext2)
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
{
|
2007-06-04 03:57:16 +02:00
|
|
|
char file[4000];
|
|
|
|
strcpy (file, dir);
|
|
|
|
strcat (file, fn);
|
|
|
|
strcat (file, ext1);
|
|
|
|
strcat (file, ext2);
|
|
|
|
|
2009-03-14 15:56:20 +01:00
|
|
|
wide_path wpath (file);
|
|
|
|
if (GetFileAttributesW (wpath) != (DWORD) - 1)
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
{
|
|
|
|
char *lastdot = strrchr (file, '.');
|
|
|
|
bool is_link = lastdot && !strcmp (lastdot, LINK_EXTENSION);
|
|
|
|
// If file is a link, fix up the extension before printing
|
|
|
|
if (is_link)
|
|
|
|
*lastdot = '\0';
|
|
|
|
if (showall)
|
|
|
|
printf ("Found: %s\n", file);
|
2007-06-04 03:57:16 +02:00
|
|
|
if (verbose && *first != '\0' && strcasecmp (first, file) != 0)
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
{
|
|
|
|
char *flastdot = strrchr (first, '.');
|
|
|
|
bool f_is_link = flastdot && !strcmp (flastdot, LINK_EXTENSION);
|
|
|
|
// if first is a link, fix up the extension before printing
|
|
|
|
if (f_is_link)
|
|
|
|
*flastdot = '\0';
|
|
|
|
printf ("Warning: %s hides %s\n", first, file);
|
|
|
|
if (f_is_link)
|
|
|
|
*flastdot = '.';
|
|
|
|
}
|
|
|
|
if (is_link)
|
|
|
|
*lastdot = '.';
|
2007-06-04 03:57:16 +02:00
|
|
|
if (!*first)
|
|
|
|
strcpy (first, file);
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-04 03:57:16 +02:00
|
|
|
static const char *
|
|
|
|
find_on_path (const char *in_file, const char *ext, bool showall = false,
|
|
|
|
bool search_sys = false, bool checklinks = false)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
static char rv[4000];
|
|
|
|
|
2007-06-04 03:57:16 +02:00
|
|
|
/* Sort of a kludge but we've already tested this once, so don't try it again */
|
|
|
|
if (in_file == rv)
|
|
|
|
return in_file;
|
|
|
|
|
|
|
|
static pathlike abspath[2] =
|
|
|
|
{
|
|
|
|
{emptystr, 0},
|
|
|
|
{NULL, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
*rv = '\0';
|
|
|
|
if (!in_file)
|
2000-12-16 05:53:30 +01:00
|
|
|
{
|
2007-06-04 03:57:16 +02:00
|
|
|
display_error ("internal error find_on_path: NULL pointer for file", false, false);
|
2000-12-16 05:53:30 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-06-04 03:57:16 +02:00
|
|
|
if (!ext)
|
2000-12-16 05:53:30 +01:00
|
|
|
{
|
2007-06-04 03:57:16 +02:00
|
|
|
display_error ("internal error find_on_path: NULL pointer for default_extension", false, false);
|
2000-12-16 05:53:30 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-06-04 03:57:16 +02:00
|
|
|
const char *file;
|
|
|
|
pathlike *search_paths;
|
|
|
|
if (!strpbrk (in_file, ":/\\"))
|
2005-07-19 23:00:34 +02:00
|
|
|
{
|
2007-06-04 03:57:16 +02:00
|
|
|
file = in_file;
|
|
|
|
search_paths = paths;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
file = cygpath (in_file, NULL);
|
|
|
|
search_paths = abspath;
|
|
|
|
showall = false;
|
2005-07-19 23:00:34 +02:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2007-06-04 03:57:16 +02:00
|
|
|
if (!file)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2007-06-04 03:57:16 +02:00
|
|
|
display_error ("internal error find_on_path: cygpath conversion failed for %s\n", in_file);
|
|
|
|
return 0;
|
|
|
|
}
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
|
2007-06-04 03:57:16 +02:00
|
|
|
char *hasext = strrchr (file, '.');
|
|
|
|
if (hasext && !strpbrk (hasext, "/\\"))
|
|
|
|
ext = "";
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
|
2007-06-04 03:57:16 +02:00
|
|
|
for (pathlike *pth = search_paths; pth->dir; pth++)
|
|
|
|
if (!pth->issys || search_sys)
|
|
|
|
{
|
|
|
|
pth->check_existence (file, showall, verbose, rv, ext);
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
|
2007-06-04 03:57:16 +02:00
|
|
|
if (checklinks)
|
|
|
|
pth->check_existence (file, showall, verbose, rv, ext, LINK_EXTENSION);
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
|
2007-06-04 03:57:16 +02:00
|
|
|
if (!*ext)
|
|
|
|
continue;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2007-06-04 03:57:16 +02:00
|
|
|
pth->check_existence (file, showall, verbose, rv);
|
|
|
|
if (checklinks)
|
|
|
|
pth->check_existence (file, showall, verbose, rv, LINK_EXTENSION);
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2007-06-04 03:57:16 +02:00
|
|
|
return *rv ? rv : NULL;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define DID_NEW 1
|
|
|
|
#define DID_ACTIVE 2
|
|
|
|
#define DID_INACTIVE 3
|
|
|
|
|
|
|
|
struct Did
|
|
|
|
{
|
|
|
|
Did *next;
|
|
|
|
char *file;
|
|
|
|
int state;
|
|
|
|
};
|
2002-02-27 17:10:17 +01:00
|
|
|
static Did *did = 0;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2002-02-27 17:10:17 +01:00
|
|
|
static Did *
|
2007-06-04 03:57:16 +02:00
|
|
|
already_did (const char *file)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
Did *d;
|
|
|
|
for (d = did; d; d = d->next)
|
|
|
|
if (strcasecmp (d->file, file) == 0)
|
|
|
|
return d;
|
2002-01-18 03:57:10 +01:00
|
|
|
d = (Did *) malloc (sizeof (Did));
|
2000-02-17 20:38:33 +01:00
|
|
|
d->file = strdup (file);
|
|
|
|
d->next = did;
|
|
|
|
d->state = DID_NEW;
|
|
|
|
did = d;
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Section
|
|
|
|
{
|
|
|
|
char name[8];
|
|
|
|
int virtual_size;
|
|
|
|
int virtual_address;
|
|
|
|
int size_of_raw_data;
|
|
|
|
int pointer_to_raw_data;
|
|
|
|
};
|
|
|
|
|
2002-02-27 17:10:17 +01:00
|
|
|
static int
|
2000-02-17 20:38:33 +01:00
|
|
|
rva_to_offset (int rva, char *sections, int nsections, int *sz)
|
|
|
|
{
|
|
|
|
int i;
|
2000-12-16 05:53:30 +01:00
|
|
|
|
|
|
|
if (sections == NULL)
|
|
|
|
{
|
2004-11-16 06:16:59 +01:00
|
|
|
display_error ("rva_to_offset: NULL passed for sections", true, false);
|
2000-12-16 05:53:30 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
for (i = 0; i < nsections; i++)
|
|
|
|
{
|
|
|
|
Section *s = (Section *) (sections + i * 40);
|
|
|
|
#if 0
|
|
|
|
printf ("%08x < %08x < %08x ? %08x\n",
|
|
|
|
s->virtual_address, rva,
|
|
|
|
s->virtual_address + s->virtual_size, s->pointer_to_raw_data);
|
|
|
|
#endif
|
|
|
|
if (rva >= s->virtual_address
|
|
|
|
&& rva < s->virtual_address + s->virtual_size)
|
|
|
|
{
|
|
|
|
if (sz)
|
|
|
|
*sz = s->virtual_address + s->virtual_size - rva;
|
|
|
|
return rva - s->virtual_address + s->pointer_to_raw_data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0; /* punt */
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ExpDirectory
|
|
|
|
{
|
|
|
|
int flags;
|
|
|
|
int timestamp;
|
|
|
|
short major_ver;
|
|
|
|
short minor_ver;
|
|
|
|
int name_rva;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ImpDirectory
|
2000-10-28 07:00:00 +02:00
|
|
|
{
|
|
|
|
unsigned characteristics;
|
|
|
|
unsigned timestamp;
|
|
|
|
unsigned forwarder_chain;
|
|
|
|
unsigned name_rva;
|
|
|
|
unsigned iat_rva;
|
|
|
|
};
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2007-06-04 03:57:16 +02:00
|
|
|
static bool track_down (const char *file, const char *suffix, int lvl);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-06-25 05:18:54 +02:00
|
|
|
#define CYGPREFIX (sizeof ("%%% Cygwin ") - 1)
|
|
|
|
static void
|
|
|
|
cygwin_info (HANDLE h)
|
|
|
|
{
|
2000-12-16 05:53:30 +01:00
|
|
|
char *buf, *bufend, *buf_start = NULL;
|
2000-06-25 05:18:54 +02:00
|
|
|
const char *hello = " Cygwin DLL version info:\n";
|
|
|
|
DWORD size = GetFileSize (h, NULL);
|
|
|
|
DWORD n;
|
|
|
|
|
|
|
|
if (size == 0xffffffff)
|
|
|
|
return;
|
|
|
|
|
2000-12-16 05:53:30 +01:00
|
|
|
buf_start = buf = (char *) calloc (1, size + 1);
|
|
|
|
if (buf == NULL)
|
|
|
|
{
|
2004-11-11 02:56:02 +01:00
|
|
|
display_error ("cygwin_info: calloc()");
|
2000-12-16 05:53:30 +01:00
|
|
|
return;
|
|
|
|
}
|
2000-06-25 05:18:54 +02:00
|
|
|
|
|
|
|
(void) SetFilePointer (h, 0, NULL, FILE_BEGIN);
|
|
|
|
if (!ReadFile (h, buf, size, &n, NULL))
|
2000-12-16 05:53:30 +01:00
|
|
|
{
|
|
|
|
free (buf_start);
|
|
|
|
return;
|
|
|
|
}
|
2000-06-25 05:18:54 +02:00
|
|
|
|
2002-01-22 04:17:59 +01:00
|
|
|
static char dummy[] = "\0\0\0\0\0\0\0";
|
|
|
|
char *dll_major = dummy;
|
2000-06-25 05:18:54 +02:00
|
|
|
bufend = buf + size;
|
|
|
|
while (buf < bufend)
|
|
|
|
if ((buf = (char *) memchr (buf, '%', bufend - buf)) == NULL)
|
2000-10-28 07:00:00 +02:00
|
|
|
break;
|
2000-06-25 05:18:54 +02:00
|
|
|
else if (strncmp ("%%% Cygwin ", buf, CYGPREFIX) != 0)
|
2000-10-28 07:00:00 +02:00
|
|
|
buf++;
|
2000-06-25 05:18:54 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
char *p = strchr (buf += CYGPREFIX, '\n');
|
2000-12-16 05:53:30 +01:00
|
|
|
if (!p)
|
|
|
|
break;
|
2001-11-11 04:06:59 +01:00
|
|
|
if (strncasecmp (buf, "dll major:", 10) == 0)
|
|
|
|
{
|
|
|
|
dll_major = buf + 11;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
char *s, pbuf[80];
|
|
|
|
int len;
|
|
|
|
len = 1 + p - buf;
|
|
|
|
if (strncasecmp (buf, "dll minor:", 10) != 0)
|
|
|
|
s = buf;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char c = dll_major[1];
|
|
|
|
dll_major[1] = '\0';
|
|
|
|
int maj = atoi (dll_major);
|
|
|
|
dll_major[1] = c;
|
|
|
|
int min = atoi (dll_major + 1);
|
2002-03-07 04:13:17 +01:00
|
|
|
sprintf (pbuf, "DLL version: %d.%d.%.*s", maj, min, len - 11,
|
|
|
|
buf + 11);
|
2001-11-11 04:06:59 +01:00
|
|
|
len = strlen (s = pbuf);
|
|
|
|
}
|
|
|
|
if (strncmp (s, "dll", 3) == 0)
|
|
|
|
memcpy (s, "DLL", 3);
|
|
|
|
else if (strncmp (s, "api", 3) == 0)
|
|
|
|
memcpy (s, "API", 3);
|
|
|
|
else if (islower (*s))
|
|
|
|
*s = toupper (*s);
|
|
|
|
fprintf (stdout, "%s %.*s", hello, len, s);
|
2000-06-25 05:18:54 +02:00
|
|
|
hello = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*hello)
|
|
|
|
puts ("");
|
2000-12-16 05:53:30 +01:00
|
|
|
|
|
|
|
free (buf_start);
|
2000-06-25 05:18:54 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-02-27 17:10:17 +01:00
|
|
|
static void
|
2000-06-25 05:18:54 +02:00
|
|
|
dll_info (const char *path, HANDLE fh, int lvl, int recurse)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
DWORD junk;
|
|
|
|
int i;
|
2013-07-07 18:57:11 +02:00
|
|
|
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;
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
int pe_header_offset = get_dword (fh, 0x3c);
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
if (GetLastError () != NO_ERROR)
|
|
|
|
display_error ("get_dword");
|
2013-04-23 11:44:36 +02:00
|
|
|
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)
|
|
|
|
{
|
2013-07-07 18:57:11 +02:00
|
|
|
puts (verbose ? " (not x86_64 dll)" : "\n");
|
2013-04-23 11:44:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
int base_off = 108;
|
|
|
|
#else
|
|
|
|
if (arch != IMAGE_FILE_MACHINE_I386)
|
|
|
|
{
|
2013-07-07 18:57:11 +02:00
|
|
|
puts (verbose ? " (not x86 dll)" : "\n");
|
2013-04-23 11:44:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
int base_off = 92;
|
|
|
|
#endif
|
2000-02-17 20:38:33 +01:00
|
|
|
int opthdr_ofs = pe_header_offset + 4 + 20;
|
|
|
|
unsigned short v[6];
|
2000-12-16 05:53:30 +01:00
|
|
|
|
|
|
|
if (path == NULL)
|
|
|
|
{
|
2004-11-16 06:16:59 +01:00
|
|
|
display_error ("dll_info: NULL passed for path", true, false);
|
2000-12-16 05:53:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-03-07 04:13:17 +01:00
|
|
|
if (SetFilePointer (fh, opthdr_ofs + 40, 0, FILE_BEGIN) ==
|
|
|
|
INVALID_SET_FILE_POINTER && GetLastError () != NO_ERROR)
|
2004-11-11 02:56:02 +01:00
|
|
|
display_error ("dll_info: SetFilePointer()");
|
2000-12-16 05:53:30 +01:00
|
|
|
|
|
|
|
if (!ReadFile (fh, &v, sizeof (v), &junk, 0))
|
2004-11-11 02:56:02 +01:00
|
|
|
display_error ("dll_info: Readfile()");
|
2000-12-16 05:53:30 +01:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
if (verbose)
|
|
|
|
printf (" - os=%d.%d img=%d.%d sys=%d.%d\n",
|
|
|
|
v[0], v[1], v[2], v[3], v[4], v[5]);
|
|
|
|
else
|
|
|
|
printf ("\n");
|
2000-12-16 05:53:30 +01:00
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
int num_entries = get_dword (fh, opthdr_ofs + base_off + 0);
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
if (GetLastError () != NO_ERROR)
|
|
|
|
display_error ("get_dword");
|
2013-04-23 11:44:36 +02:00
|
|
|
int export_rva = get_dword (fh, opthdr_ofs + base_off + 4);
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
if (GetLastError () != NO_ERROR)
|
|
|
|
display_error ("get_dword");
|
2013-04-23 11:44:36 +02:00
|
|
|
int export_size = get_dword (fh, opthdr_ofs + base_off + 8);
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
if (GetLastError () != NO_ERROR)
|
|
|
|
display_error ("get_dword");
|
2013-04-23 11:44:36 +02:00
|
|
|
int import_rva = get_dword (fh, opthdr_ofs + base_off + 12);
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
if (GetLastError () != NO_ERROR)
|
|
|
|
display_error ("get_dword");
|
2013-04-23 11:44:36 +02:00
|
|
|
int import_size = get_dword (fh, opthdr_ofs + base_off + 16);
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
if (GetLastError () != NO_ERROR)
|
|
|
|
display_error ("get_dword");
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
int nsections = get_word (fh, pe_header_offset + 4 + 2);
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
if (nsections == -1)
|
|
|
|
display_error ("get_word");
|
2000-02-17 20:38:33 +01:00
|
|
|
char *sections = (char *) malloc (nsections * 40);
|
2000-12-16 05:53:30 +01:00
|
|
|
|
|
|
|
if (SetFilePointer (fh, pe_header_offset + 4 + 20 +
|
|
|
|
get_word (fh, pe_header_offset + 4 + 16), 0,
|
|
|
|
FILE_BEGIN) == INVALID_SET_FILE_POINTER
|
|
|
|
&& GetLastError () != NO_ERROR)
|
2004-11-11 02:56:02 +01:00
|
|
|
display_error ("dll_info: SetFilePointer()");
|
2000-12-16 05:53:30 +01:00
|
|
|
|
|
|
|
if (!ReadFile (fh, sections, nsections * 40, &junk, 0))
|
2004-11-11 02:56:02 +01:00
|
|
|
display_error ("dll_info: Readfile()");
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
if (verbose && num_entries >= 1 && export_size > 0)
|
|
|
|
{
|
|
|
|
int expsz;
|
|
|
|
int expbase = rva_to_offset (export_rva, sections, nsections, &expsz);
|
2000-12-16 05:53:30 +01:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
if (expbase)
|
|
|
|
{
|
2002-03-07 04:13:17 +01:00
|
|
|
if (SetFilePointer (fh, expbase, 0, FILE_BEGIN) ==
|
|
|
|
INVALID_SET_FILE_POINTER && GetLastError () != NO_ERROR)
|
2004-11-11 02:56:02 +01:00
|
|
|
display_error ("dll_info: SetFilePointer()");
|
2000-12-16 05:53:30 +01:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
unsigned char *exp = (unsigned char *) malloc (expsz);
|
2000-12-16 05:53:30 +01:00
|
|
|
|
|
|
|
if (!ReadFile (fh, exp, expsz, &junk, 0))
|
2004-11-11 02:56:02 +01:00
|
|
|
display_error ("dll_info: Readfile()");
|
2000-12-16 05:53:30 +01:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
ExpDirectory *ed = (ExpDirectory *) exp;
|
|
|
|
int ofs = ed->name_rva - export_rva;
|
2013-04-23 11:44:36 +02:00
|
|
|
time_t ts = ed->timestamp; /* timestamp is only 4 bytes! */
|
|
|
|
struct tm *tm = localtime (&ts);
|
|
|
|
if (tm && tm->tm_year < 60)
|
2000-02-17 20:38:33 +01:00
|
|
|
tm->tm_year += 2000;
|
2013-04-23 11:44:36 +02:00
|
|
|
if (tm && tm->tm_year < 200)
|
2000-02-17 20:38:33 +01:00
|
|
|
tm->tm_year += 1900;
|
|
|
|
printf ("%*c", lvl + 2, ' ');
|
2013-04-23 11:44:36 +02:00
|
|
|
printf ("\"%s\" v%d.%d", exp + ofs,
|
2000-02-17 20:38:33 +01:00
|
|
|
ed->major_ver, ed->minor_ver);
|
2013-04-23 11:44:36 +02:00
|
|
|
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');
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_entries >= 2 && import_size > 0 && recurse)
|
|
|
|
{
|
|
|
|
int impsz;
|
|
|
|
int impbase = rva_to_offset (import_rva, sections, nsections, &impsz);
|
|
|
|
if (impbase)
|
|
|
|
{
|
2002-03-07 04:13:17 +01:00
|
|
|
if (SetFilePointer (fh, impbase, 0, FILE_BEGIN) ==
|
|
|
|
INVALID_SET_FILE_POINTER && GetLastError () != NO_ERROR)
|
2004-11-11 02:56:02 +01:00
|
|
|
display_error ("dll_info: SetFilePointer()");
|
2000-12-16 05:53:30 +01:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
unsigned char *imp = (unsigned char *) malloc (impsz);
|
2000-12-16 05:53:30 +01:00
|
|
|
if (imp == NULL)
|
|
|
|
{
|
2004-11-11 02:56:02 +01:00
|
|
|
display_error ("dll_info: malloc()");
|
2000-12-16 05:53:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ReadFile (fh, imp, impsz, &junk, 0))
|
2004-11-11 02:56:02 +01:00
|
|
|
display_error ("dll_info: Readfile()");
|
2000-12-16 05:53:30 +01:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
ImpDirectory *id = (ImpDirectory *) imp;
|
|
|
|
for (i = 0; id[i].name_rva; i++)
|
|
|
|
{
|
|
|
|
/* int ofs = id[i].name_rva - import_rva; */
|
|
|
|
track_down ((char *) imp + id[i].name_rva - import_rva,
|
|
|
|
(char *) ".dll", lvl + 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-06-25 05:18:54 +02:00
|
|
|
if (strstr (path, "\\cygwin1.dll"))
|
|
|
|
cygwin_info (fh);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2005-07-05 23:41:37 +02:00
|
|
|
// Return true on success, false if error printed
|
|
|
|
static bool
|
2007-06-04 03:57:16 +02:00
|
|
|
track_down (const char *file, const char *suffix, int lvl)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-12-16 05:53:30 +01:00
|
|
|
if (file == NULL)
|
|
|
|
{
|
2004-11-16 06:16:59 +01:00
|
|
|
display_error ("track_down: NULL passed for file", true, false);
|
2005-07-05 23:41:37 +02:00
|
|
|
return false;
|
2000-12-16 05:53:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (suffix == NULL)
|
|
|
|
{
|
2004-11-16 06:16:59 +01:00
|
|
|
display_error ("track_down: NULL passed for suffix", false, false);
|
2005-07-05 23:41:37 +02:00
|
|
|
return false;
|
2000-12-16 05:53:30 +01:00
|
|
|
}
|
|
|
|
|
2007-06-04 03:57:16 +02:00
|
|
|
const char *path = find_on_path (file, suffix, false, true);
|
2000-02-17 20:38:33 +01:00
|
|
|
if (!path)
|
|
|
|
{
|
2015-08-30 21:32:56 +02:00
|
|
|
/* 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);
|
2005-07-05 23:41:37 +02:00
|
|
|
return false;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Did *d = already_did (file);
|
|
|
|
switch (d->state)
|
|
|
|
{
|
|
|
|
case DID_NEW:
|
|
|
|
break;
|
|
|
|
case DID_ACTIVE:
|
|
|
|
if (verbose)
|
|
|
|
{
|
|
|
|
if (lvl)
|
|
|
|
printf ("%*c", lvl, ' ');
|
|
|
|
printf ("%s", path);
|
|
|
|
printf (" (recursive)\n");
|
|
|
|
}
|
2005-07-05 23:41:37 +02:00
|
|
|
return true;
|
2000-02-17 20:38:33 +01:00
|
|
|
case DID_INACTIVE:
|
|
|
|
if (verbose)
|
|
|
|
{
|
|
|
|
if (lvl)
|
|
|
|
printf ("%*c", lvl, ' ');
|
|
|
|
printf ("%s", path);
|
|
|
|
printf (" (already done)\n");
|
|
|
|
}
|
2005-07-05 23:41:37 +02:00
|
|
|
return true;
|
2000-12-16 05:53:30 +01:00
|
|
|
default:
|
|
|
|
break;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lvl)
|
|
|
|
printf ("%*c", lvl, ' ');
|
|
|
|
|
|
|
|
if (!path)
|
|
|
|
{
|
2007-06-04 03:57:16 +02:00
|
|
|
display_error ("file not found - '%s'\n", file);
|
2005-07-05 23:41:37 +02:00
|
|
|
return false;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
printf ("%s", path);
|
|
|
|
|
2009-03-14 15:56:20 +01:00
|
|
|
wide_path wpath (path);
|
2000-10-28 07:00:00 +02:00
|
|
|
HANDLE fh =
|
2009-03-14 15:56:20 +01:00
|
|
|
CreateFileW (wpath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
2000-02-17 20:38:33 +01:00
|
|
|
if (fh == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2007-06-04 03:57:16 +02:00
|
|
|
display_error ("cannot open - '%s'\n", path);
|
2005-07-05 23:41:37 +02:00
|
|
|
return false;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
d->state = DID_ACTIVE;
|
|
|
|
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
if (is_exe (fh))
|
|
|
|
dll_info (path, fh, lvl, 1);
|
|
|
|
else if (is_symlink (fh))
|
2007-06-04 03:57:16 +02:00
|
|
|
display_error ("%s is a symlink instead of a DLL\n", path);
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
int magic = get_word (fh, 0x0);
|
|
|
|
if (magic == -1)
|
2007-06-04 03:57:16 +02:00
|
|
|
display_error ("get_word");
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
magic &= 0x00FFFFFF;
|
2007-06-04 03:57:16 +02:00
|
|
|
display_error_fmt ("%s is not a DLL: magic number %x (%d) '%s'\n",
|
|
|
|
path, magic, magic, (char *)&magic);
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
d->state = DID_INACTIVE;
|
2000-12-16 05:53:30 +01:00
|
|
|
if (!CloseHandle (fh))
|
2004-11-11 02:56:02 +01:00
|
|
|
display_error ("track_down: CloseHandle()");
|
2005-07-05 23:41:37 +02:00
|
|
|
return true;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2002-02-27 17:10:17 +01:00
|
|
|
static void
|
2000-02-17 20:38:33 +01:00
|
|
|
ls (char *f)
|
|
|
|
{
|
2009-03-14 15:56:20 +01:00
|
|
|
wide_path wpath (f);
|
|
|
|
HANDLE h = CreateFileW (wpath, GENERIC_READ,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
2000-02-17 20:38:33 +01:00
|
|
|
BY_HANDLE_FILE_INFORMATION info;
|
2000-12-16 05:53:30 +01:00
|
|
|
|
|
|
|
if (!GetFileInformationByHandle (h, &info))
|
2004-11-11 02:56:02 +01:00
|
|
|
display_error ("ls: GetFileInformationByHandle()");
|
2000-12-16 05:53:30 +01:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
SYSTEMTIME systime;
|
2000-12-16 05:53:30 +01:00
|
|
|
|
|
|
|
if (!FileTimeToSystemTime (&info.ftLastWriteTime, &systime))
|
2004-11-11 02:56:02 +01:00
|
|
|
display_error ("ls: FileTimeToSystemTime()");
|
2000-02-17 20:38:33 +01:00
|
|
|
printf ("%5dk %04d/%02d/%02d %s",
|
|
|
|
(((int) info.nFileSizeLow) + 512) / 1024,
|
2000-10-28 07:00:00 +02:00
|
|
|
systime.wYear, systime.wMonth, systime.wDay, f);
|
2000-06-25 05:18:54 +02:00
|
|
|
dll_info (f, h, 16, 0);
|
2000-12-16 05:53:30 +01:00
|
|
|
if (!CloseHandle (h))
|
2004-11-11 02:56:02 +01:00
|
|
|
display_error ("ls: CloseHandle()");
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2008-03-11 18:20:02 +01:00
|
|
|
/* Remove filename from 's' and return directory name without trailing
|
|
|
|
backslash, or NULL if 's' doesn't seem to have a dirname. */
|
|
|
|
static char *
|
|
|
|
dirname (const char *s)
|
|
|
|
{
|
2009-03-14 15:56:20 +01:00
|
|
|
static char buf[PATH_MAX];
|
2008-03-11 18:20:02 +01:00
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return NULL;
|
|
|
|
|
2009-03-14 15:56:20 +01:00
|
|
|
strncpy (buf, s, PATH_MAX);
|
|
|
|
buf[PATH_MAX - 1] = '\0'; // in case strlen(s) > PATH_MAX
|
2008-03-11 18:20:02 +01:00
|
|
|
char *lastsep = strrchr (buf, '\\');
|
|
|
|
if (!lastsep)
|
|
|
|
return NULL; // no backslash -> no dirname
|
|
|
|
else if (lastsep - buf <= 2 && buf[1] == ':')
|
|
|
|
lastsep[1] = '\0'; // can't remove backslash of "x:\"
|
|
|
|
else
|
|
|
|
*lastsep = '\0';
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
// Find a real application on the path (possibly following symlinks)
|
2007-06-04 03:57:16 +02:00
|
|
|
static const char *
|
|
|
|
find_app_on_path (const char *app, bool showall = false)
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
{
|
2007-06-04 03:57:16 +02:00
|
|
|
const char *papp = find_on_path (app, ".exe", showall, false, true);
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
|
2009-05-04 20:51:08 +02:00
|
|
|
if (!papp)
|
|
|
|
return NULL;
|
|
|
|
|
2009-03-14 15:56:20 +01:00
|
|
|
wide_path wpath (papp);
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
HANDLE fh =
|
2009-03-14 15:56:20 +01:00
|
|
|
CreateFileW (wpath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
if (fh == INVALID_HANDLE_VALUE)
|
2007-06-04 03:57:16 +02:00
|
|
|
return NULL;
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
|
|
|
|
if (is_symlink (fh))
|
|
|
|
{
|
2008-03-11 19:43:11 +01:00
|
|
|
static char tmp[SYMLINK_MAX + 1];
|
2008-03-11 18:20:02 +01:00
|
|
|
if (!readlink (fh, tmp, SYMLINK_MAX))
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
display_error("readlink failed");
|
2011-12-18 00:39:47 +01:00
|
|
|
|
2008-03-11 18:20:02 +01:00
|
|
|
/* Resolve the linkname relative to the directory of the link. */
|
|
|
|
char *ptr = cygpath_rel (dirname (papp), tmp, NULL);
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
printf (" -> %s\n", ptr);
|
|
|
|
if (!strchr (ptr, '\\'))
|
|
|
|
{
|
|
|
|
char *lastsep;
|
2008-03-11 19:43:11 +01:00
|
|
|
strncpy (tmp, cygpath (papp, NULL), SYMLINK_MAX);
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
lastsep = strrchr (tmp, '\\');
|
2008-03-11 19:43:11 +01:00
|
|
|
strncpy (lastsep+1, ptr, SYMLINK_MAX - (lastsep-tmp));
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
ptr = tmp;
|
|
|
|
}
|
|
|
|
if (!CloseHandle (fh))
|
|
|
|
display_error ("find_app_on_path: CloseHandle()");
|
2008-03-11 18:20:02 +01:00
|
|
|
/* FIXME: We leak the ptr returned by cygpath() here which is a
|
2011-12-18 00:39:47 +01:00
|
|
|
malloc()d string. */
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
return find_app_on_path (ptr, showall);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CloseHandle (fh))
|
|
|
|
display_error ("find_app_on_path: CloseHandle()");
|
|
|
|
return papp;
|
|
|
|
}
|
|
|
|
|
2005-07-05 23:41:37 +02:00
|
|
|
// Return true on success, false if error printed
|
|
|
|
static bool
|
2007-06-04 03:57:16 +02:00
|
|
|
cygcheck (const char *app)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2007-06-04 03:57:16 +02:00
|
|
|
const char *papp = find_app_on_path (app, 1);
|
2000-02-17 20:38:33 +01:00
|
|
|
if (!papp)
|
|
|
|
{
|
2007-06-04 03:57:16 +02:00
|
|
|
display_error ("could not find '%s'\n", app);
|
2005-07-05 23:41:37 +02:00
|
|
|
return false;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2007-06-04 03:57:16 +02:00
|
|
|
|
|
|
|
char *s;
|
|
|
|
char *sep = strpbrk (papp, ":/\\");
|
|
|
|
if (!sep)
|
|
|
|
{
|
|
|
|
static char dot[] = ".";
|
|
|
|
s = dot;
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
else
|
|
|
|
{
|
2007-06-04 03:57:16 +02:00
|
|
|
int n = sep - papp;
|
|
|
|
s = (char *) malloc (n + 2);
|
|
|
|
memcpy ((char *) s, papp, n);
|
|
|
|
strcpy (s + n, "\\");
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2007-06-04 03:57:16 +02:00
|
|
|
|
|
|
|
paths[0].dir = s;
|
|
|
|
did = NULL;
|
|
|
|
return track_down (papp, ".exe", 0);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct RegInfo
|
2000-10-28 07:00:00 +02:00
|
|
|
{
|
|
|
|
RegInfo *prev;
|
|
|
|
char *name;
|
|
|
|
HKEY key;
|
|
|
|
};
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2002-02-27 17:10:17 +01:00
|
|
|
static void
|
2000-02-17 20:38:33 +01:00
|
|
|
show_reg (RegInfo * ri, int nest)
|
|
|
|
{
|
|
|
|
if (!ri)
|
|
|
|
return;
|
|
|
|
show_reg (ri->prev, 1);
|
|
|
|
if (nest)
|
|
|
|
printf ("%s\\", ri->name);
|
|
|
|
else
|
|
|
|
printf ("%s\n", ri->name);
|
|
|
|
}
|
|
|
|
|
2002-02-27 17:10:17 +01:00
|
|
|
static void
|
2009-01-17 12:59:16 +01:00
|
|
|
scan_registry (RegInfo * prev, HKEY hKey, char *name, int cygwin, bool wow64)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
RegInfo ri;
|
|
|
|
ri.prev = prev;
|
|
|
|
ri.name = name;
|
|
|
|
ri.key = hKey;
|
|
|
|
|
|
|
|
char *cp;
|
|
|
|
for (cp = name; *cp; cp++)
|
2009-01-17 12:59:16 +01:00
|
|
|
if (strncasecmp (cp, "Cygwin", 6) == 0)
|
|
|
|
cygwin = 1;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
DWORD num_subkeys, max_subkey_len, num_values;
|
|
|
|
DWORD max_value_len, max_valdata_len, i;
|
|
|
|
if (RegQueryInfoKey (hKey, 0, 0, 0, &num_subkeys, &max_subkey_len, 0,
|
|
|
|
&num_values, &max_value_len, &max_valdata_len, 0, 0)
|
|
|
|
!= ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
char tmp[400];
|
|
|
|
FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError (),
|
2000-10-28 07:00:00 +02:00
|
|
|
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), tmp, 400, 0);
|
2000-02-17 20:38:33 +01:00
|
|
|
printf ("RegQueryInfoKey: %s\n", tmp);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-17 12:59:16 +01:00
|
|
|
if (cygwin)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
show_reg (&ri, 0);
|
2000-12-16 05:53:30 +01:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
char *value_name = (char *) malloc (max_value_len + 1);
|
2000-12-16 05:53:30 +01:00
|
|
|
if (value_name == NULL)
|
|
|
|
{
|
2004-11-11 02:56:02 +01:00
|
|
|
display_error ("scan_registry: malloc()");
|
2000-12-16 05:53:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
char *value_data = (char *) malloc (max_valdata_len + 1);
|
2000-12-16 05:53:30 +01:00
|
|
|
if (value_data == NULL)
|
|
|
|
{
|
2004-11-11 02:56:02 +01:00
|
|
|
display_error ("scan_registry: malloc()");
|
2000-12-16 05:53:30 +01:00
|
|
|
return;
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
for (i = 0; i < num_values; i++)
|
|
|
|
{
|
|
|
|
DWORD dlen = max_valdata_len + 1;
|
|
|
|
DWORD nlen = max_value_len + 1;
|
|
|
|
DWORD type;
|
|
|
|
RegEnumValue (hKey, i, value_name, &nlen, 0,
|
|
|
|
&type, (BYTE *) value_data, &dlen);
|
|
|
|
{
|
|
|
|
printf (" %s = ", i ? value_name : "(default)");
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case REG_DWORD:
|
|
|
|
printf ("0x%08x\n", *(unsigned *) value_data);
|
|
|
|
break;
|
|
|
|
case REG_EXPAND_SZ:
|
|
|
|
case REG_SZ:
|
2006-01-12 18:43:53 +01:00
|
|
|
printf ("'%s'\n", value_data);
|
2000-02-17 20:38:33 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf ("(unsupported type)\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free (value_name);
|
|
|
|
free (value_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *subkey_name = (char *) malloc (max_subkey_len + 1);
|
|
|
|
for (i = 0; i < num_subkeys; i++)
|
|
|
|
{
|
2000-10-28 07:00:00 +02:00
|
|
|
if (RegEnumKey (hKey, i, subkey_name, max_subkey_len + 1) ==
|
|
|
|
ERROR_SUCCESS)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
HKEY sKey;
|
2009-01-17 12:59:16 +01:00
|
|
|
/* Don't recurse more than one level into the WOW64 subkey since
|
|
|
|
that would lead to an endless recursion. */
|
|
|
|
if (!strcasecmp (subkey_name, "Wow6432Node"))
|
|
|
|
{
|
|
|
|
if (wow64)
|
|
|
|
continue;
|
|
|
|
wow64 = true;
|
|
|
|
}
|
2001-11-12 01:14:27 +01:00
|
|
|
if (RegOpenKeyEx (hKey, subkey_name, 0, KEY_READ, &sKey)
|
2000-02-17 20:38:33 +01:00
|
|
|
== ERROR_SUCCESS)
|
|
|
|
{
|
2009-01-17 12:59:16 +01:00
|
|
|
scan_registry (&ri, sKey, subkey_name, cygwin, wow64);
|
2000-12-16 05:53:30 +01:00
|
|
|
if (RegCloseKey (sKey) != ERROR_SUCCESS)
|
2004-11-11 02:56:02 +01:00
|
|
|
display_error ("scan_registry: RegCloseKey()");
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free (subkey_name);
|
|
|
|
}
|
|
|
|
|
2003-03-01 04:38:19 +01:00
|
|
|
void
|
2009-10-28 12:41:27 +01:00
|
|
|
pretty_id ()
|
2003-03-01 04:38:19 +01:00
|
|
|
{
|
|
|
|
char *groups[16384];
|
|
|
|
|
|
|
|
char *id = cygpath ("/bin/id.exe", NULL);
|
2003-09-11 04:56:40 +02:00
|
|
|
for (char *p = id; (p = strchr (p, '/')); p++)
|
2003-03-01 04:38:19 +01:00
|
|
|
*p = '\\';
|
|
|
|
|
|
|
|
if (access (id, X_OK))
|
2004-01-24 00:04:27 +01:00
|
|
|
{
|
2006-01-12 18:43:53 +01:00
|
|
|
fprintf (stderr, "'id' program not found\n");
|
2004-01-24 00:04:27 +01:00
|
|
|
return;
|
|
|
|
}
|
2003-03-01 04:38:19 +01:00
|
|
|
|
|
|
|
char buf[16384];
|
2008-12-31 02:44:36 +01:00
|
|
|
snprintf (buf, sizeof (buf), "\"%s\"", id);
|
|
|
|
FILE *f = popen (buf, "rt");
|
|
|
|
|
2004-01-24 00:04:27 +01:00
|
|
|
buf[0] = '\0';
|
2003-03-01 04:38:19 +01:00
|
|
|
fgets (buf, sizeof (buf), f);
|
2004-10-04 11:42:08 +02:00
|
|
|
pclose (f);
|
2004-01-24 00:04:27 +01:00
|
|
|
char *uid = strtok (buf, ")");
|
|
|
|
if (uid)
|
|
|
|
uid += strlen ("uid=");
|
|
|
|
else
|
2004-10-14 19:35:46 +02:00
|
|
|
{
|
2006-01-12 18:43:53 +01:00
|
|
|
fprintf (stderr, "garbled output from 'id' command - no uid= found\n");
|
2004-10-15 15:57:56 +02:00
|
|
|
return;
|
2004-10-14 19:35:46 +02:00
|
|
|
}
|
2004-01-24 00:04:27 +01:00
|
|
|
char *gid = strtok (NULL, ")");
|
|
|
|
if (gid)
|
|
|
|
gid += strlen ("gid=") + 1;
|
|
|
|
else
|
2004-10-14 19:35:46 +02:00
|
|
|
{
|
2006-01-12 18:43:53 +01:00
|
|
|
fprintf (stderr, "garbled output from 'id' command - no gid= found\n");
|
2004-10-15 15:57:56 +02:00
|
|
|
return;
|
2004-10-14 19:35:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
char **ng = groups - 1;
|
2004-10-18 03:44:55 +02:00
|
|
|
size_t len_uid = strlen ("UID: )") + strlen (uid);
|
|
|
|
size_t len_gid = strlen ("GID: )") + strlen (gid);
|
2004-10-18 01:31:23 +02:00
|
|
|
*++ng = groups[0] = (char *) alloca (len_uid + 1);
|
|
|
|
*++ng = groups[1] = (char *) alloca (len_gid + 1);
|
2004-10-14 19:35:46 +02:00
|
|
|
sprintf (groups[0], "UID: %s)", uid);
|
|
|
|
sprintf (groups[1], "GID: %s)", gid);
|
|
|
|
size_t sz = max (len_uid, len_gid);
|
|
|
|
while ((*++ng = strtok (NULL, ",")))
|
2003-03-01 04:38:19 +01:00
|
|
|
{
|
|
|
|
char *p = strchr (*ng, '\n');
|
|
|
|
if (p)
|
|
|
|
*p = '\0';
|
2004-10-14 19:35:46 +02:00
|
|
|
if (ng == groups + 2)
|
2003-06-13 04:36:12 +02:00
|
|
|
*ng += strlen (" groups=");
|
2003-03-01 04:38:19 +01:00
|
|
|
size_t len = strlen (*ng);
|
|
|
|
if (sz < len)
|
|
|
|
sz = len;
|
|
|
|
}
|
2004-10-15 15:57:56 +02:00
|
|
|
ng--;
|
2003-03-01 04:38:19 +01:00
|
|
|
|
2009-10-28 12:41:27 +01:00
|
|
|
printf ("\nOutput from %s\n", id);
|
2004-10-15 15:57:56 +02:00
|
|
|
int n = 80 / (int) ++sz;
|
2004-10-18 12:25:38 +02:00
|
|
|
int i = n > 2 ? n - 2 : 0;
|
2004-10-15 15:57:56 +02:00
|
|
|
sz = -sz;
|
|
|
|
for (char **g = groups; g <= ng; g++)
|
|
|
|
if ((g != ng) && (++i < n))
|
2013-04-23 11:44:36 +02:00
|
|
|
printf ("%*s", (int) sz, *g);
|
2004-10-14 19:35:46 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
puts (*g);
|
|
|
|
i = 0;
|
|
|
|
}
|
2003-03-01 04:38:19 +01:00
|
|
|
}
|
|
|
|
|
2005-05-23 11:54:44 +02:00
|
|
|
/* This dumps information about each installed cygwin service, if cygrunsrv
|
|
|
|
is available. */
|
|
|
|
void
|
|
|
|
dump_sysinfo_services ()
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
char buf2[1024];
|
|
|
|
FILE *f;
|
2005-08-17 02:52:43 +02:00
|
|
|
bool no_services = false;
|
2005-05-27 17:45:53 +02:00
|
|
|
|
2005-05-23 11:54:44 +02:00
|
|
|
if (givehelp)
|
2005-05-27 17:45:53 +02:00
|
|
|
printf ("\nChecking for any Cygwin services... %s\n\n",
|
|
|
|
verbose ? "" : "(use -v for more detail)");
|
2005-05-23 11:54:44 +02:00
|
|
|
else
|
|
|
|
fputc ('\n', stdout);
|
2005-05-27 17:45:53 +02:00
|
|
|
|
2005-05-23 11:54:44 +02:00
|
|
|
/* find the location of cygrunsrv.exe */
|
2005-05-27 17:45:53 +02:00
|
|
|
char *cygrunsrv = cygpath ("/bin/cygrunsrv.exe", NULL);
|
2005-05-23 11:54:44 +02:00
|
|
|
for (char *p = cygrunsrv; (p = strchr (p, '/')); p++)
|
|
|
|
*p = '\\';
|
|
|
|
|
|
|
|
if (access (cygrunsrv, X_OK))
|
|
|
|
{
|
|
|
|
puts ("Can't find the cygrunsrv utility, skipping services check.\n");
|
|
|
|
return;
|
|
|
|
}
|
2005-05-27 17:45:53 +02:00
|
|
|
|
2005-05-23 11:54:44 +02:00
|
|
|
/* check for a recent cygrunsrv */
|
2008-12-31 02:44:36 +01:00
|
|
|
snprintf (buf, sizeof (buf), "\"%s\" --version", cygrunsrv);
|
2005-05-27 17:45:53 +02:00
|
|
|
if ((f = popen (buf, "rt")) == NULL)
|
2005-05-23 11:54:44 +02:00
|
|
|
{
|
|
|
|
printf ("Failed to execute '%s', skipping services check.\n", buf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int maj, min;
|
|
|
|
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");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fclose (f);
|
2005-05-27 17:45:53 +02:00
|
|
|
|
2005-08-17 02:52:43 +02:00
|
|
|
/* For verbose mode, just run cygrunsrv --list --verbose and copy output
|
|
|
|
verbatim; otherwise run cygrunsrv --list and then cygrunsrv --query for
|
|
|
|
each service. */
|
2009-01-06 05:11:23 +01:00
|
|
|
snprintf (buf, sizeof (buf), (verbose ? "\"%s\" --list --verbose" : "\"%s\" --list"),
|
2005-08-17 02:52:43 +02:00
|
|
|
cygrunsrv);
|
2005-05-23 11:54:44 +02:00
|
|
|
if ((f = popen (buf, "rt")) == NULL)
|
|
|
|
{
|
|
|
|
printf ("Failed to execute '%s', skipping services check.\n", buf);
|
|
|
|
return;
|
|
|
|
}
|
2005-05-27 17:45:53 +02:00
|
|
|
|
2005-08-17 02:52:43 +02:00
|
|
|
if (verbose)
|
2005-05-23 11:54:44 +02:00
|
|
|
{
|
2005-08-17 02:52:43 +02:00
|
|
|
/* copy output to stdout */
|
|
|
|
size_t nchars = 0;
|
|
|
|
while (!feof (f) && !ferror (f))
|
|
|
|
nchars += fwrite ((void *) buf, 1,
|
|
|
|
fread ((void *) buf, 1, sizeof (buf), f), stdout);
|
|
|
|
|
|
|
|
/* cygrunsrv outputs nothing if there are no cygwin services found */
|
|
|
|
if (nchars < 1)
|
|
|
|
no_services = true;
|
|
|
|
pclose (f);
|
2005-05-23 11:54:44 +02:00
|
|
|
}
|
2005-08-17 02:52:43 +02:00
|
|
|
else
|
2005-05-23 11:54:44 +02:00
|
|
|
{
|
2005-08-17 02:52:43 +02:00
|
|
|
/* read the output of --list, and then run --query for each service */
|
|
|
|
size_t nchars = fread ((void *) buf, 1, sizeof (buf) - 1, f);
|
|
|
|
buf[nchars] = 0;
|
2005-05-23 11:54:44 +02:00
|
|
|
pclose (f);
|
2005-05-27 17:45:53 +02:00
|
|
|
|
2005-08-17 02:52:43 +02:00
|
|
|
if (nchars > 0)
|
|
|
|
for (char *srv = strtok (buf, "\n"); srv; srv = strtok (NULL, "\n"))
|
|
|
|
{
|
2008-12-31 02:44:36 +01:00
|
|
|
snprintf (buf2, sizeof (buf2), "\"%s\" --query %s", cygrunsrv, srv);
|
2005-08-17 02:52:43 +02:00
|
|
|
if ((f = popen (buf2, "rt")) == NULL)
|
|
|
|
{
|
|
|
|
printf ("Failed to execute '%s', skipping services check.\n", buf2);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy output to stdout */
|
|
|
|
while (!feof (f) && !ferror (f))
|
|
|
|
fwrite ((void *) buf2, 1,
|
|
|
|
fread ((void *) buf2, 1, sizeof (buf2), f), stdout);
|
|
|
|
pclose (f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
no_services = true;
|
2005-05-23 11:54:44 +02:00
|
|
|
}
|
2005-08-17 02:52:43 +02:00
|
|
|
|
|
|
|
/* inform the user if nothing found */
|
|
|
|
if (no_services)
|
|
|
|
puts ("No Cygwin services found.\n");
|
2005-05-23 11:54:44 +02:00
|
|
|
}
|
|
|
|
|
2009-10-31 14:26:37 +01:00
|
|
|
enum handle_reg_t
|
|
|
|
{
|
|
|
|
PRINT_KEY,
|
|
|
|
DELETE_KEY
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
handle_reg_installation (handle_reg_t what)
|
|
|
|
{
|
|
|
|
HKEY key;
|
|
|
|
|
|
|
|
if (what == PRINT_KEY)
|
|
|
|
printf ("Cygwin installations found in the registry:\n");
|
|
|
|
for (int i = 0; i < 2; ++i)
|
|
|
|
if (RegOpenKeyEx (i ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE,
|
|
|
|
"SOFTWARE\\Cygwin\\Installations", 0,
|
|
|
|
what == DELETE_KEY ? KEY_READ | KEY_WRITE : KEY_READ,
|
|
|
|
&key)
|
|
|
|
== ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
char name[32], data[PATH_MAX];
|
|
|
|
DWORD nsize, dsize, type;
|
|
|
|
LONG ret;
|
|
|
|
|
|
|
|
for (DWORD index = 0;
|
|
|
|
(ret = RegEnumValue (key, index, name, (nsize = 32, &nsize), 0,
|
|
|
|
&type, (PBYTE) data,
|
|
|
|
(dsize = PATH_MAX, &dsize)))
|
|
|
|
!= ERROR_NO_MORE_ITEMS; ++index)
|
|
|
|
if (ret == ERROR_SUCCESS && dsize > 5)
|
|
|
|
{
|
|
|
|
char *path = data + 4;
|
|
|
|
if (path[1] != ':')
|
2011-12-18 00:39:47 +01:00
|
|
|
*(path += 2) = '\\';
|
2009-10-31 14:26:37 +01:00
|
|
|
if (what == PRINT_KEY)
|
|
|
|
printf (" %s Key: %s Path: %s", i ? "User: " : "System:",
|
|
|
|
name, path);
|
|
|
|
strcat (path, "\\bin\\cygwin1.dll");
|
|
|
|
if (what == PRINT_KEY)
|
|
|
|
printf ("%s\n", access (path, F_OK) ? " (ORPHANED)" : "");
|
|
|
|
else if (access (path, F_OK))
|
|
|
|
{
|
|
|
|
RegDeleteValue (key, name);
|
|
|
|
/* Start over since index is not reliable anymore. */
|
|
|
|
--i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey (key);
|
|
|
|
}
|
|
|
|
if (what == PRINT_KEY)
|
|
|
|
printf ("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_reg_installations ()
|
|
|
|
{
|
|
|
|
handle_reg_installation (PRINT_KEY);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
del_orphaned_reg_installations ()
|
|
|
|
{
|
|
|
|
handle_reg_installation (DELETE_KEY);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unfortunately neither mingw nor Windows know this function. */
|
|
|
|
char *
|
|
|
|
memmem (char *haystack, size_t haystacklen,
|
2011-12-18 00:39:47 +01:00
|
|
|
const char *needle, size_t needlelen)
|
2009-10-31 14:26:37 +01:00
|
|
|
{
|
|
|
|
if (needlelen == 0)
|
|
|
|
return haystack;
|
|
|
|
while (needlelen <= haystacklen)
|
|
|
|
{
|
|
|
|
if (!memcmp (haystack, needle, needlelen))
|
2011-12-18 00:39:47 +01:00
|
|
|
return haystack;
|
2009-10-31 14:26:37 +01:00
|
|
|
haystack++;
|
|
|
|
haystacklen--;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-12-18 00:39:47 +01:00
|
|
|
|
2009-10-31 14:26:37 +01:00
|
|
|
int
|
|
|
|
handle_unique_object_name (int opt, char *path)
|
|
|
|
{
|
|
|
|
HANDLE fh, fm;
|
2011-03-29 13:02:58 +02:00
|
|
|
void *haystack = NULL;
|
2009-10-31 14:26:37 +01:00
|
|
|
|
|
|
|
if (!path || !*path)
|
|
|
|
usage (stderr, 1);
|
|
|
|
|
|
|
|
DWORD access, share, protect, mapping;
|
|
|
|
|
|
|
|
if (opt == CO_SHOW_UON)
|
|
|
|
{
|
|
|
|
access = GENERIC_READ;
|
2012-07-11 18:41:51 +02:00
|
|
|
share = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
|
2009-10-31 14:26:37 +01:00
|
|
|
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);
|
2011-12-18 00:39:47 +01:00
|
|
|
cygwin_props_t *cygwin_props = (cygwin_props_t *)
|
2009-10-31 14:26:37 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-11-19 23:26:37 +01:00
|
|
|
extern "C" NTSTATUS NTAPI RtlGetVersion (PRTL_OSVERSIONINFOEXW);
|
|
|
|
|
2002-02-27 17:10:17 +01:00
|
|
|
static void
|
2000-02-17 20:38:33 +01:00
|
|
|
dump_sysinfo ()
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
char tmp[4000];
|
|
|
|
time_t now;
|
2000-06-25 05:18:54 +02:00
|
|
|
char *found_cygwin_dll;
|
2005-05-23 11:54:44 +02:00
|
|
|
bool is_nt = false;
|
2009-01-16 13:10:02 +01:00
|
|
|
char osname[128];
|
2009-01-29 20:31:04 +01:00
|
|
|
DWORD obcaseinsensitive = 1;
|
|
|
|
HKEY key;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2014-10-21 12:59:40 +02:00
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
2004-03-21 18:58:14 +01:00
|
|
|
printf ("\nCygwin Configuration Diagnostics\n");
|
2000-02-17 20:38:33 +01:00
|
|
|
time (&now);
|
|
|
|
printf ("Current System Time: %s\n", ctime (&now));
|
|
|
|
|
2013-11-19 23:26:37 +01:00
|
|
|
RTL_OSVERSIONINFOEXW osversion;
|
|
|
|
osversion.dwOSVersionInfoSize = sizeof (RTL_OSVERSIONINFOEXW);
|
|
|
|
RtlGetVersion (&osversion);
|
2008-01-13 14:41:45 +01:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
switch (osversion.dwPlatformId)
|
|
|
|
{
|
|
|
|
case VER_PLATFORM_WIN32_NT:
|
2005-05-23 11:54:44 +02:00
|
|
|
is_nt = true;
|
2015-08-30 21:34:24 +02:00
|
|
|
if (osversion.dwMajorVersion >= 6)
|
2008-01-13 14:41:45 +01:00
|
|
|
{
|
2013-11-19 23:26:37 +01:00
|
|
|
HMODULE k32 = GetModuleHandleW (L"kernel32.dll");
|
2008-01-13 14:41:45 +01:00
|
|
|
BOOL (WINAPI *GetProductInfo) (DWORD, DWORD, DWORD, DWORD, PDWORD) =
|
|
|
|
(BOOL (WINAPI *)(DWORD, DWORD, DWORD, DWORD, PDWORD))
|
|
|
|
GetProcAddress (k32, "GetProductInfo");
|
2015-08-30 21:34:24 +02:00
|
|
|
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)
|
2012-10-09 14:47:40 +02:00
|
|
|
{
|
2014-11-10 17:21:52 +01:00
|
|
|
strcpy (osname, osversion.wProductType == VER_NT_WORKSTATION
|
2015-08-30 21:34:24 +02:00
|
|
|
? "10" : "2016");
|
2012-10-09 14:47:40 +02:00
|
|
|
}
|
2008-01-13 14:41:45 +01:00
|
|
|
DWORD prod;
|
|
|
|
if (GetProductInfo (osversion.dwMajorVersion,
|
|
|
|
osversion.dwMinorVersion,
|
|
|
|
osversion.wServicePackMajor,
|
|
|
|
osversion.wServicePackMinor,
|
|
|
|
&prod))
|
|
|
|
{
|
|
|
|
const char *products[] =
|
2011-12-18 00:39:47 +01:00
|
|
|
{
|
2009-10-20 17:26:33 +02:00
|
|
|
/* 0x00000000 */ "",
|
|
|
|
/* 0x00000001 */ " Ultimate",
|
|
|
|
/* 0x00000002 */ " Home Basic",
|
|
|
|
/* 0x00000003 */ " Home Premium",
|
|
|
|
/* 0x00000004 */ " Enterprise",
|
|
|
|
/* 0x00000005 */ " Home Basic N",
|
|
|
|
/* 0x00000006 */ " Business",
|
|
|
|
/* 0x00000007 */ " Server Standard",
|
|
|
|
/* 0x00000008 */ " Server Datacenter",
|
|
|
|
/* 0x00000009 */ " Small Business Server",
|
|
|
|
/* 0x0000000a */ " Server Enterprise",
|
|
|
|
/* 0x0000000b */ " Starter",
|
|
|
|
/* 0x0000000c */ " Server Datacenter Core",
|
|
|
|
/* 0x0000000d */ " Server Standard Core",
|
|
|
|
/* 0x0000000e */ " Server Enterprise Core",
|
|
|
|
/* 0x0000000f */ " Server Enterprise for Itanium-based Systems",
|
2011-10-13 19:50:48 +02:00
|
|
|
/* 0x00000010 */ " Business N",
|
2009-10-20 17:26:33 +02:00
|
|
|
/* 0x00000011 */ " Web Server",
|
|
|
|
/* 0x00000012 */ " HPC Edition",
|
|
|
|
/* 0x00000013 */ " Home Server",
|
|
|
|
/* 0x00000014 */ " Storage Server Express",
|
|
|
|
/* 0x00000015 */ " Storage Server Standard",
|
|
|
|
/* 0x00000016 */ " Storage Server Workgroup",
|
|
|
|
/* 0x00000017 */ " Storage Server Enterprise",
|
|
|
|
/* 0x00000018 */ " for Windows Essential Server Solutions",
|
2012-09-02 12:06:12 +02:00
|
|
|
/* 0x00000019 */ " Small Business Server Premium",
|
2009-10-20 17:26:33 +02:00
|
|
|
/* 0x0000001a */ " Home Premium N",
|
|
|
|
/* 0x0000001b */ " Enterprise N",
|
|
|
|
/* 0x0000001c */ " Ultimate N",
|
|
|
|
/* 0x0000001d */ " Web Server Core",
|
|
|
|
/* 0x0000001e */ " Essential Business Server Management Server",
|
2013-11-19 11:43:10 +01:00
|
|
|
/* 0x0000001f */ " Essential Business Server Security Server",
|
2009-10-20 17:26:33 +02:00
|
|
|
/* 0x00000020 */ " Essential Business Server Messaging Server",
|
|
|
|
/* 0x00000021 */ " Server Foundation",
|
2011-10-13 19:50:48 +02:00
|
|
|
/* 0x00000022 */ " Home Server 2011",
|
2009-10-20 17:26:33 +02:00
|
|
|
/* 0x00000023 */ " without Hyper-V for Windows Essential Server Solutions",
|
|
|
|
/* 0x00000024 */ " Server Standard without Hyper-V",
|
|
|
|
/* 0x00000025 */ " Server Datacenter without Hyper-V",
|
|
|
|
/* 0x00000026 */ " Server Enterprise without Hyper-V",
|
|
|
|
/* 0x00000027 */ " Server Datacenter Core without Hyper-V",
|
|
|
|
/* 0x00000028 */ " Server Standard Core without Hyper-V",
|
|
|
|
/* 0x00000029 */ " Server Enterprise Core without Hyper-V",
|
|
|
|
/* 0x0000002a */ " Hyper-V Server",
|
2012-09-02 12:06:12 +02:00
|
|
|
/* 0x0000002b */ " Storage Server Express Core",
|
|
|
|
/* 0x0000002c */ " Storage Server Standard Core",
|
|
|
|
/* 0x0000002d */ " Storage Server Workgroup Core",
|
|
|
|
/* 0x0000002e */ " Storage Server Enterprise Core",
|
2009-10-20 17:26:33 +02:00
|
|
|
/* 0x0000002f */ " Starter N",
|
|
|
|
/* 0x00000030 */ " Professional",
|
2009-11-27 11:01:50 +01:00
|
|
|
/* 0x00000031 */ " Professional N",
|
2013-11-19 11:43:10 +01:00
|
|
|
/* 0x00000032 */ " Small Business Server 2011 Essentials",
|
2012-09-02 12:06:12 +02:00
|
|
|
/* 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 */
|
2011-10-13 19:50:48 +02:00
|
|
|
/* 0x00000038 */ " Multipoint Server",
|
2009-10-20 17:26:33 +02:00
|
|
|
/* 0x00000039 */ "",
|
|
|
|
/* 0x0000003a */ "",
|
2012-09-02 12:06:12 +02:00
|
|
|
/* 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",
|
2009-10-20 17:26:33 +02:00
|
|
|
/* 0x00000041 */ "",
|
|
|
|
/* 0x00000042 */ " Starter E",
|
|
|
|
/* 0x00000043 */ " Home Basic E",
|
|
|
|
/* 0x00000044 */ " Home Premium E",
|
|
|
|
/* 0x00000045 */ " Professional E",
|
|
|
|
/* 0x00000046 */ " Enterprise E",
|
2013-11-19 11:43:10 +01:00
|
|
|
/* 0x00000047 */ " Ultimate E",
|
2012-09-02 12:06:12 +02:00
|
|
|
/* 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 */ "",
|
2015-08-30 21:34:24 +02:00
|
|
|
/* 0x00000062 */ " N",
|
|
|
|
/* 0x00000063 */ " China",
|
|
|
|
/* 0x00000064 */ " Single Language",
|
|
|
|
/* 0x00000065 */ " Home",
|
2012-09-02 12:06:12 +02:00
|
|
|
/* 0x00000066 */ "",
|
2015-08-30 21:46:58 +02:00
|
|
|
/* 0x00000067 */ " Professional with Media Center",
|
|
|
|
/* 0x00000068 */ " Mobile",
|
2015-08-30 21:34:24 +02:00
|
|
|
/* 0x00000069 */ "",
|
|
|
|
/* 0x0000006a */ "",
|
|
|
|
/* 0x0000006b */ "",
|
|
|
|
/* 0x0000006c */ "",
|
|
|
|
/* 0x0000006d */ "",
|
|
|
|
/* 0x0000006e */ "",
|
|
|
|
/* 0x0000006f */ "",
|
|
|
|
/* 0x00000070 */ "",
|
|
|
|
/* 0x00000071 */ "",
|
|
|
|
/* 0x00000072 */ "",
|
|
|
|
/* 0x00000073 */ "",
|
|
|
|
/* 0x00000074 */ "",
|
|
|
|
/* 0x00000075 */ "",
|
|
|
|
/* 0x00000076 */ "",
|
|
|
|
/* 0x00000077 */ "",
|
|
|
|
/* 0x00000078 */ "",
|
2015-08-30 21:46:58 +02:00
|
|
|
/* 0x00000079 */ " Education",
|
|
|
|
/* 0x0000007a */ " Education N",
|
2015-08-30 21:34:24 +02:00
|
|
|
/* 0x0000007b */ "",
|
|
|
|
/* 0x0000007c */ "",
|
|
|
|
/* 0x0000007d */ "",
|
|
|
|
/* 0x0000007e */ "",
|
|
|
|
/* 0x0000007f */ "",
|
|
|
|
/* 0x00000080 */ "",
|
|
|
|
/* 0x00000081 */ "",
|
|
|
|
/* 0x00000082 */ "",
|
|
|
|
/* 0x00000083 */ "",
|
|
|
|
/* 0x00000084 */ "",
|
2015-08-30 21:46:58 +02:00
|
|
|
/* 0x00000085 */ " Mobile Enterprise",
|
2008-01-13 14:41:45 +01:00
|
|
|
};
|
|
|
|
if (prod == PRODUCT_UNLICENSED)
|
2011-12-18 00:39:47 +01:00
|
|
|
strcat (osname, "Unlicensed");
|
2015-08-30 21:34:24 +02:00
|
|
|
else if (prod > 0x00000085)
|
2011-12-18 00:39:47 +01:00
|
|
|
strcat (osname, "");
|
2008-01-13 14:41:45 +01:00
|
|
|
else
|
2011-12-18 00:39:47 +01:00
|
|
|
strcat (osname, products[prod]);
|
2008-01-13 14:41:45 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2006-01-13 14:39:05 +01:00
|
|
|
else if (osversion.dwMajorVersion == 5)
|
2001-11-09 18:18:36 +01:00
|
|
|
{
|
2013-11-19 11:43:10 +01:00
|
|
|
/* cygcheck won't run on Windows 200 or earlier. */
|
|
|
|
if (osversion.dwMinorVersion == 1)
|
2001-11-12 18:55:52 +01:00
|
|
|
{
|
2008-01-13 14:41:45 +01:00
|
|
|
strcpy (osname, "XP");
|
2005-05-30 17:49:31 +02:00
|
|
|
if (GetSystemMetrics (SM_MEDIACENTER))
|
2008-01-13 14:41:45 +01:00
|
|
|
strcat (osname, " Media Center Edition");
|
2005-05-30 17:49:31 +02:00
|
|
|
else if (GetSystemMetrics (SM_TABLETPC))
|
2008-01-13 14:41:45 +01:00
|
|
|
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");
|
2001-11-12 18:55:52 +01:00
|
|
|
else
|
2008-01-13 14:41:45 +01:00
|
|
|
strcat (osname, " Professional");
|
2005-05-30 17:49:31 +02:00
|
|
|
}
|
|
|
|
else if (osversion.dwMinorVersion == 2)
|
|
|
|
{
|
2008-01-13 14:41:45 +01:00
|
|
|
strcpy (osname, "2003 Server");
|
|
|
|
if (GetSystemMetrics (SM_SERVERR2))
|
2011-12-18 00:39:47 +01:00
|
|
|
strcat (osname, " R2");
|
2008-01-13 14:41:45 +01:00
|
|
|
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)
|
2011-12-18 00:39:47 +01:00
|
|
|
strcat (osname, " Compute Cluster Edition");
|
2008-01-13 14:41:45 +01:00
|
|
|
}
|
|
|
|
}
|
2001-11-09 18:18:36 +01:00
|
|
|
else
|
2008-01-13 14:41:45 +01:00
|
|
|
strcpy (osname, "NT");
|
2000-02-17 20:38:33 +01:00
|
|
|
break;
|
|
|
|
default:
|
2008-01-13 14:41:45 +01:00
|
|
|
strcpy (osname, "??");
|
2000-02-17 20:38:33 +01:00
|
|
|
break;
|
|
|
|
}
|
2013-11-19 23:26:37 +01:00
|
|
|
printf ("Windows %s Ver %lu.%lu Build %lu %ls\n", osname,
|
2001-11-12 22:55:39 +01:00
|
|
|
osversion.dwMajorVersion, osversion.dwMinorVersion,
|
|
|
|
osversion.dwPlatformId == VER_PLATFORM_WIN32_NT ?
|
2002-03-07 04:13:17 +01:00
|
|
|
osversion.dwBuildNumber : (osversion.dwBuildNumber & 0xffff),
|
2001-11-12 22:55:39 +01:00
|
|
|
osversion.dwPlatformId == VER_PLATFORM_WIN32_NT ?
|
2013-11-19 23:26:37 +01:00
|
|
|
osversion.szCSDVersion : L"");
|
2006-01-13 14:39:05 +01:00
|
|
|
|
2008-01-13 14:41:45 +01:00
|
|
|
if (osversion.dwPlatformId == VER_PLATFORM_WIN32s
|
|
|
|
|| osversion.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
|
|
|
|
exit (EXIT_FAILURE);
|
2006-01-13 14:39:05 +01:00
|
|
|
|
|
|
|
BOOL is_wow64 = FALSE;
|
2013-11-19 11:43:10 +01:00
|
|
|
if (IsWow64Process (GetCurrentProcess (), &is_wow64) && is_wow64)
|
2006-01-13 14:39:05 +01:00
|
|
|
{
|
|
|
|
SYSTEM_INFO natinfo;
|
2013-11-19 11:43:10 +01:00
|
|
|
GetNativeSystemInfo (&natinfo);
|
2006-01-13 14:39:05 +01:00
|
|
|
fputs ("\nRunning under WOW64 on ", stdout);
|
|
|
|
switch (natinfo.wProcessorArchitecture)
|
2007-06-04 03:57:16 +02:00
|
|
|
{
|
2006-01-13 14:39:05 +01:00
|
|
|
case PROCESSOR_ARCHITECTURE_IA64:
|
|
|
|
puts ("IA64");
|
|
|
|
break;
|
|
|
|
case PROCESSOR_ARCHITECTURE_AMD64:
|
|
|
|
puts ("AMD64");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
puts("??");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-30 17:49:31 +02:00
|
|
|
if (GetSystemMetrics (SM_REMOTESESSION))
|
2006-01-13 14:39:05 +01:00
|
|
|
printf ("\nRunning in Terminal Service session\n");
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2006-01-13 14:39:05 +01:00
|
|
|
printf ("\nPath:");
|
2000-02-17 20:38:33 +01:00
|
|
|
char *s = getenv ("PATH"), *e;
|
2005-05-20 18:38:42 +02:00
|
|
|
if (!s)
|
|
|
|
puts ("");
|
|
|
|
else
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2005-05-20 18:38:42 +02:00
|
|
|
char sep = strchr (s, ';') ? ';' : ':';
|
|
|
|
int count_path_items = 0;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
for (e = s; *e && *e != sep; e++);
|
|
|
|
if (e-s)
|
2013-04-23 11:44:36 +02:00
|
|
|
printf ("\t%.*s\n", (int) (e - s), s);
|
2005-05-20 18:38:42 +02:00
|
|
|
else
|
|
|
|
puts ("\t.");
|
|
|
|
count_path_items++;
|
|
|
|
if (!*e)
|
|
|
|
break;
|
|
|
|
s = e + 1;
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2003-03-01 04:38:19 +01:00
|
|
|
fflush (stdout);
|
|
|
|
|
2009-10-28 12:41:27 +01:00
|
|
|
pretty_id ();
|
2003-03-01 04:38:19 +01:00
|
|
|
|
2000-12-16 05:53:30 +01:00
|
|
|
if (!GetSystemDirectory (tmp, 4000))
|
2004-11-11 02:56:02 +01:00
|
|
|
display_error ("dump_sysinfo: GetSystemDirectory()");
|
2000-02-17 20:38:33 +01:00
|
|
|
printf ("\nSysDir: %s\n", tmp);
|
2000-12-16 05:53:30 +01:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
GetWindowsDirectory (tmp, 4000);
|
|
|
|
printf ("WinDir: %s\n\n", tmp);
|
|
|
|
|
|
|
|
|
|
|
|
if (givehelp)
|
|
|
|
printf ("Here's some environment variables that may affect cygwin:\n");
|
|
|
|
for (i = 0; environ[i]; i++)
|
|
|
|
{
|
|
|
|
char *eq = strchr (environ[i], '=');
|
|
|
|
if (!eq)
|
|
|
|
continue;
|
|
|
|
/* int len = eq - environ[i]; */
|
|
|
|
for (j = 0; known_env_vars[j]; j++)
|
|
|
|
{
|
|
|
|
*eq = 0;
|
|
|
|
if (strcmp (environ[i], "PATH") == 0)
|
|
|
|
continue; /* we handle this one specially */
|
|
|
|
if (strcasecmp (environ[i], known_env_vars[j]) == 0)
|
2006-01-12 18:43:53 +01:00
|
|
|
printf ("%s = '%s'\n", environ[i], eq + 1);
|
2000-02-17 20:38:33 +01:00
|
|
|
*eq = '=';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf ("\n");
|
|
|
|
|
|
|
|
if (verbose)
|
|
|
|
{
|
|
|
|
if (givehelp)
|
|
|
|
printf ("Here's the rest of your environment variables:\n");
|
|
|
|
for (i = 0; environ[i]; i++)
|
|
|
|
{
|
|
|
|
int found = 0;
|
|
|
|
char *eq = strchr (environ[i], '=');
|
|
|
|
if (!eq)
|
|
|
|
continue;
|
|
|
|
/* int len = eq - environ[i]; */
|
|
|
|
for (j = 0; known_env_vars[j]; j++)
|
|
|
|
{
|
|
|
|
*eq = 0;
|
|
|
|
if (strcasecmp (environ[i], known_env_vars[j]) == 0)
|
|
|
|
found = 1;
|
|
|
|
*eq = '=';
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
*eq = 0;
|
2006-01-12 18:43:53 +01:00
|
|
|
printf ("%s = '%s'\n", environ[i], eq + 1);
|
2000-02-17 20:38:33 +01:00
|
|
|
*eq = '=';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf ("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (registry)
|
|
|
|
{
|
|
|
|
if (givehelp)
|
2009-01-17 12:59:16 +01:00
|
|
|
printf ("Scanning registry for keys with 'Cygwin' in them...\n");
|
|
|
|
scan_registry (0, HKEY_CURRENT_USER,
|
|
|
|
(char *) "HKEY_CURRENT_USER", 0, false);
|
|
|
|
scan_registry (0, HKEY_LOCAL_MACHINE,
|
|
|
|
(char *) "HKEY_LOCAL_MACHINE", 0, false);
|
2000-02-17 20:38:33 +01:00
|
|
|
printf ("\n");
|
|
|
|
}
|
|
|
|
else
|
2006-01-12 18:43:53 +01:00
|
|
|
printf ("Use '-r' to scan registry\n\n");
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2009-01-29 20:31:04 +01:00
|
|
|
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE,
|
2011-12-18 00:39:47 +01:00
|
|
|
"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\kernel",
|
|
|
|
0, KEY_READ, &key) == ERROR_SUCCESS)
|
2009-01-29 20:31:04 +01:00
|
|
|
{
|
|
|
|
DWORD size;
|
|
|
|
RegQueryValueEx (key, "obcaseinsensitive", NULL, NULL,
|
2011-12-18 00:39:47 +01:00
|
|
|
(LPBYTE) &obcaseinsensitive, &size);
|
2009-01-29 20:31:04 +01:00
|
|
|
RegCloseKey (key);
|
|
|
|
}
|
2009-03-24 14:35:08 +01:00
|
|
|
printf ("obcaseinsensitive set to %lu\n\n", obcaseinsensitive);
|
2009-01-29 20:31:04 +01:00
|
|
|
|
2009-10-31 14:26:37 +01:00
|
|
|
print_reg_installations ();
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
if (givehelp)
|
|
|
|
{
|
|
|
|
printf ("Listing available drives...\n");
|
2004-10-21 02:06:37 +02:00
|
|
|
printf ("Drv Type Size Used Flags Name\n");
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2000-10-28 07:00:00 +02:00
|
|
|
int prev_mode =
|
|
|
|
SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
|
2000-02-17 20:38:33 +01:00
|
|
|
int drivemask = GetLogicalDrives ();
|
|
|
|
|
|
|
|
for (i = 0; i < 26; i++)
|
|
|
|
{
|
|
|
|
if (!(drivemask & (1 << i)))
|
|
|
|
continue;
|
|
|
|
char drive[4], name[200], fsname[200];
|
|
|
|
DWORD serno = 0, maxnamelen = 0, flags = 0;
|
2011-03-29 13:02:58 +02:00
|
|
|
name[0] = fsname[0] = 0;
|
2000-02-17 20:38:33 +01:00
|
|
|
sprintf (drive, "%c:\\", i + 'a');
|
2004-10-25 17:49:36 +02:00
|
|
|
/* Report all errors, except if the Volume is ERROR_NOT_READY.
|
|
|
|
ERROR_NOT_READY is returned when removeable media drives are empty
|
|
|
|
(CD, floppy, etc.) */
|
2006-01-05 19:31:26 +01:00
|
|
|
if (!GetVolumeInformation (drive, name, sizeof (name), &serno,
|
|
|
|
&maxnamelen, &flags, fsname,
|
|
|
|
sizeof (fsname))
|
|
|
|
&& GetLastError () != ERROR_NOT_READY)
|
|
|
|
{
|
|
|
|
# define FMT "dump_sysinfo: GetVolumeInformation() for drive %c:"
|
|
|
|
char buf[sizeof (FMT)];
|
|
|
|
sprintf (buf, FMT, 'A' + i);
|
|
|
|
display_error (buf);
|
|
|
|
# undef FMT
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
int dtype = GetDriveType (drive);
|
|
|
|
char drive_type[4] = "unk";
|
|
|
|
switch (dtype)
|
|
|
|
{
|
|
|
|
case DRIVE_REMOVABLE:
|
|
|
|
strcpy (drive_type, "fd ");
|
|
|
|
break;
|
|
|
|
case DRIVE_FIXED:
|
|
|
|
strcpy (drive_type, "hd ");
|
|
|
|
break;
|
|
|
|
case DRIVE_REMOTE:
|
|
|
|
strcpy (drive_type, "net");
|
|
|
|
break;
|
|
|
|
case DRIVE_CDROM:
|
|
|
|
strcpy (drive_type, "cd ");
|
|
|
|
break;
|
|
|
|
case DRIVE_RAMDISK:
|
|
|
|
strcpy (drive_type, "ram");
|
|
|
|
break;
|
2000-12-16 05:53:30 +01:00
|
|
|
default:
|
|
|
|
strcpy (drive_type, "unk");
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
long capacity_mb = -1;
|
|
|
|
int percent_full = -1;
|
|
|
|
|
2013-11-19 11:43:10 +01:00
|
|
|
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))
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2013-11-19 11:43:10 +01:00
|
|
|
capacity_mb = total_bytes.QuadPart / (1024L * 1024L);
|
|
|
|
percent_full = 100 - (int) ((100.0 * free_me.QuadPart)
|
|
|
|
/ total_bytes.QuadPart);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD spc = 0, bps = 0, fc = 0, tc = 1;
|
|
|
|
if (GetDiskFreeSpace (drive, &spc, &bps, &fc, &tc))
|
|
|
|
{
|
|
|
|
capacity_mb = (spc * bps * tc) / (1024 * 1024);
|
|
|
|
percent_full = 100 - (int) ((100.0 * fc) / tc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf ("%.2s %s %-6s ", drive, drive_type, fsname);
|
|
|
|
if (capacity_mb >= 0)
|
2004-10-21 02:06:37 +02:00
|
|
|
printf ("%7dMb %3d%% ", (int) capacity_mb, (int) percent_full);
|
2000-02-17 20:38:33 +01:00
|
|
|
else
|
2004-10-21 02:06:37 +02:00
|
|
|
printf (" N/A N/A ");
|
2000-02-17 20:38:33 +01:00
|
|
|
printf ("%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);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetErrorMode (prev_mode);
|
|
|
|
if (givehelp)
|
|
|
|
{
|
2004-10-25 18:11:41 +02:00
|
|
|
puts ("\n"
|
2004-10-22 03:29:10 +02:00
|
|
|
"fd = floppy, hd = hard drive, cd = CD-ROM\n"
|
|
|
|
"net= Network Share, ram= RAM drive, unk= Unknown\n"
|
|
|
|
"CP = Case Preserving, CS = Case Sensitive, UN = Unicode\n"
|
|
|
|
"PA = Persistent ACLS, FC = File Compression, VC = Volume Compression");
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
printf ("\n");
|
|
|
|
|
2002-01-22 04:17:59 +01:00
|
|
|
unsigned ml_fsname = 4, ml_dir = 7, ml_type = 6;
|
2004-10-10 01:19:38 +02:00
|
|
|
bool ml_trailing = false;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2001-11-11 04:06:59 +01:00
|
|
|
struct mntent *mnt;
|
|
|
|
setmntent (0, 0);
|
|
|
|
while ((mnt = getmntent (0)))
|
|
|
|
{
|
2002-01-22 04:17:59 +01:00
|
|
|
unsigned n = (int) strlen (mnt->mnt_fsname);
|
2004-10-10 01:19:38 +02:00
|
|
|
ml_trailing |= (n > 1 && strchr ("\\/", mnt->mnt_fsname[n - 1]));
|
2001-11-11 04:06:59 +01:00
|
|
|
if (ml_fsname < n)
|
|
|
|
ml_fsname = n;
|
|
|
|
n = (int) strlen (mnt->mnt_dir);
|
2004-10-10 01:19:38 +02:00
|
|
|
ml_trailing |= (n > 1 && strchr ("\\/", mnt->mnt_dir[n - 1]));
|
2001-11-11 04:06:59 +01:00
|
|
|
if (ml_dir < n)
|
|
|
|
ml_dir = n;
|
|
|
|
}
|
|
|
|
|
2004-10-10 01:19:38 +02:00
|
|
|
if (ml_trailing)
|
|
|
|
puts ("Warning: Mount entries should not have a trailing (back)slash\n");
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
if (givehelp)
|
|
|
|
{
|
2000-10-28 07:00:00 +02:00
|
|
|
printf
|
|
|
|
("Mount entries: these map POSIX directories to your NT drives.\n");
|
|
|
|
printf ("%-*s %-*s %-*s %s\n", ml_fsname, "-NT-", ml_dir, "-POSIX-",
|
2000-02-17 20:38:33 +01:00
|
|
|
ml_type, "-Type-", "-Flags-");
|
|
|
|
}
|
|
|
|
|
|
|
|
setmntent (0, 0);
|
|
|
|
while ((mnt = getmntent (0)))
|
|
|
|
{
|
|
|
|
printf ("%-*s %-*s %-*s %s\n",
|
|
|
|
ml_fsname, mnt->mnt_fsname,
|
2000-10-28 07:00:00 +02:00
|
|
|
ml_dir, mnt->mnt_dir, ml_type, mnt->mnt_type, mnt->mnt_opts);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
printf ("\n");
|
|
|
|
|
|
|
|
if (givehelp)
|
2000-10-28 07:00:00 +02:00
|
|
|
printf
|
|
|
|
("Looking to see where common programs can be found, if at all...\n");
|
2000-02-17 20:38:33 +01:00
|
|
|
for (i = 0; common_apps[i].name; i++)
|
* cygcheck.cc (get_word, get_dword): Move to path.cc.
(LINK_EXTENSION): New macro.
(check_existence): New static function.
(find_on_path): Check for symbolic links if asked.
(dll_info): New error handling.
(track_down): Only call dll_info() for executables, display
an error for symlinks, and print magic number for others.
(find_app_on_path): New static function.
(cygcheck, dump_sysinfo): Call find_app_on_path() instead of
find_on_path().
* path.cc (cmp_shortcut_header): New static function.
(get_word, get_dword): Moved from cygcheck.cc.
(EXE_MAGIC, SHORTCUT_MAGIC, SYMLINK_COOKIE, SYMLINK_MAGIC): New
macros.
(is_exe, is_symlink, readlink): New functions.
* path.h (is_exe, is_symlink, readlink): Declare.
(get_word, get_dword): Ditto.
2006-10-05 19:24:13 +02:00
|
|
|
if (!find_app_on_path ((char *) common_apps[i].name, 1))
|
2000-10-28 07:00:00 +02:00
|
|
|
{
|
|
|
|
if (common_apps[i].missing_is_good)
|
|
|
|
printf ("Not Found: %s (good!)\n", common_apps[i].name);
|
|
|
|
else
|
|
|
|
printf ("Not Found: %s\n", common_apps[i].name);
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
printf ("\n");
|
|
|
|
|
|
|
|
if (givehelp)
|
2005-05-23 11:54:44 +02:00
|
|
|
printf ("Looking for various Cygwin DLLs... (-v gives version info)\n");
|
2004-10-27 03:28:07 +02:00
|
|
|
int cygwin_dll_count = 0;
|
2008-04-22 16:42:05 +02:00
|
|
|
char cygdll_path[32768];
|
2007-06-04 03:57:16 +02:00
|
|
|
for (pathlike *pth = paths; pth->dir; pth++)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2009-03-14 15:56:20 +01:00
|
|
|
WIN32_FIND_DATAW ffinfo;
|
2007-06-04 03:57:16 +02:00
|
|
|
sprintf (tmp, "%s*.*", pth->dir);
|
2009-03-14 15:56:20 +01:00
|
|
|
wide_path wpath (tmp);
|
|
|
|
HANDLE ff = FindFirstFileW (wpath, &ffinfo);
|
2000-02-17 20:38:33 +01:00
|
|
|
int found = (ff != INVALID_HANDLE_VALUE);
|
2000-06-25 05:18:54 +02:00
|
|
|
found_cygwin_dll = NULL;
|
2000-02-17 20:38:33 +01:00
|
|
|
while (found)
|
|
|
|
{
|
2009-03-14 15:56:20 +01:00
|
|
|
char f[FILENAME_MAX + 1];
|
|
|
|
wcstombs (f, ffinfo.cFileName, sizeof f);
|
2000-02-17 20:38:33 +01:00
|
|
|
if (strcasecmp (f + strlen (f) - 4, ".dll") == 0)
|
|
|
|
{
|
|
|
|
if (strncasecmp (f, "cyg", 3) == 0)
|
|
|
|
{
|
2007-06-04 03:57:16 +02:00
|
|
|
sprintf (tmp, "%s%s", pth->dir, f);
|
2000-06-25 05:18:54 +02:00
|
|
|
if (strcasecmp (f, "cygwin1.dll") == 0)
|
2004-10-27 03:28:07 +02:00
|
|
|
{
|
2008-04-22 16:42:05 +02:00
|
|
|
if (!cygwin_dll_count)
|
2011-12-18 00:39:47 +01:00
|
|
|
strcpy (cygdll_path, pth->dir);
|
2008-04-22 16:42:05 +02:00
|
|
|
if (!cygwin_dll_count
|
|
|
|
|| strcasecmp (cygdll_path, pth->dir) != 0)
|
|
|
|
cygwin_dll_count++;
|
2004-10-27 03:28:07 +02:00
|
|
|
found_cygwin_dll = strdup (tmp);
|
|
|
|
}
|
2000-06-25 05:18:54 +02:00
|
|
|
else
|
|
|
|
ls (tmp);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
}
|
2009-03-14 15:56:20 +01:00
|
|
|
found = FindNextFileW (ff, &ffinfo);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2000-06-25 05:18:54 +02:00
|
|
|
if (found_cygwin_dll)
|
|
|
|
{
|
|
|
|
ls (found_cygwin_dll);
|
|
|
|
free (found_cygwin_dll);
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
FindClose (ff);
|
|
|
|
}
|
2004-10-27 03:28:07 +02:00
|
|
|
if (cygwin_dll_count > 1)
|
|
|
|
puts ("Warning: There are multiple cygwin1.dlls on your path");
|
|
|
|
if (!cygwin_dll_count)
|
|
|
|
puts ("Warning: cygwin1.dll not found on your path");
|
2005-05-23 11:54:44 +02:00
|
|
|
|
2007-08-03 21:41:48 +02:00
|
|
|
dump_dodgy_apps (verbose);
|
|
|
|
|
2005-05-23 11:54:44 +02:00
|
|
|
if (is_nt)
|
|
|
|
dump_sysinfo_services ();
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2002-02-27 17:10:17 +01:00
|
|
|
static int
|
2000-09-29 13:20:53 +02:00
|
|
|
check_keys ()
|
|
|
|
{
|
2011-10-10 11:42:00 +02:00
|
|
|
HANDLE h = CreateFileW (L"CONIN$", GENERIC_READ | GENERIC_WRITE,
|
2000-10-28 07:00:00 +02:00
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
2000-09-29 13:20:53 +02:00
|
|
|
|
|
|
|
if (h == INVALID_HANDLE_VALUE || h == NULL)
|
2004-11-11 02:56:02 +01:00
|
|
|
return (display_error ("check_keys: Opening CONIN$"));
|
2000-09-29 13:20:53 +02:00
|
|
|
|
|
|
|
DWORD mode;
|
|
|
|
|
|
|
|
if (!GetConsoleMode (h, &mode))
|
2004-11-11 02:56:02 +01:00
|
|
|
display_error ("check_keys: GetConsoleMode()");
|
2000-09-29 13:20:53 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
mode &= ~ENABLE_PROCESSED_INPUT;
|
|
|
|
if (!SetConsoleMode (h, mode))
|
2004-11-11 02:56:02 +01:00
|
|
|
display_error ("check_keys: SetConsoleMode()");
|
2000-09-29 13:20:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fputs ("\nThis key check works only in a console window,", stderr);
|
|
|
|
fputs (" _NOT_ in a terminal session!\n", stderr);
|
|
|
|
fputs ("Abort with Ctrl+C if in a terminal session.\n\n", stderr);
|
2006-01-12 18:43:53 +01:00
|
|
|
fputs ("Press 'q' to exit.\n", stderr);
|
2000-09-29 13:20:53 +02:00
|
|
|
|
|
|
|
INPUT_RECORD in, prev_in;
|
|
|
|
|
|
|
|
// Drop first <RETURN> key
|
2011-10-10 11:42:00 +02:00
|
|
|
ReadConsoleInputW (h, &in, 1, &mode);
|
2000-09-29 13:20:53 +02:00
|
|
|
|
|
|
|
memset (&in, 0, sizeof in);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
prev_in = in;
|
2011-10-10 11:42:00 +02:00
|
|
|
if (!ReadConsoleInputW (h, &in, 1, &mode))
|
2004-11-11 02:56:02 +01:00
|
|
|
display_error ("check_keys: ReadConsoleInput()");
|
2000-09-29 13:20:53 +02:00
|
|
|
|
|
|
|
if (!memcmp (&in, &prev_in, sizeof in))
|
2000-10-28 07:00:00 +02:00
|
|
|
continue;
|
2000-09-29 13:20:53 +02:00
|
|
|
|
|
|
|
switch (in.EventType)
|
2000-10-28 07:00:00 +02:00
|
|
|
{
|
|
|
|
case KEY_EVENT:
|
2011-10-10 11:42:00 +02:00
|
|
|
printf ("%s %ux VK: 0x%04x VS: 0x%04x C: 0x%04x CTRL: ",
|
2000-10-28 07:00:00 +02:00
|
|
|
in.Event.KeyEvent.bKeyDown ? "Pressed " : "Released",
|
|
|
|
in.Event.KeyEvent.wRepeatCount,
|
|
|
|
in.Event.KeyEvent.wVirtualKeyCode,
|
|
|
|
in.Event.KeyEvent.wVirtualScanCode,
|
2011-10-10 11:42:00 +02:00
|
|
|
(unsigned char) in.Event.KeyEvent.uChar.UnicodeChar);
|
2000-10-28 07:00:00 +02:00
|
|
|
fputs (in.Event.KeyEvent.dwControlKeyState & CAPSLOCK_ON ?
|
|
|
|
"CL " : "-- ", stdout);
|
|
|
|
fputs (in.Event.KeyEvent.dwControlKeyState & ENHANCED_KEY ?
|
|
|
|
"EK " : "-- ", stdout);
|
|
|
|
fputs (in.Event.KeyEvent.dwControlKeyState & LEFT_ALT_PRESSED ?
|
|
|
|
"LA " : "-- ", stdout);
|
|
|
|
fputs (in.Event.KeyEvent.dwControlKeyState & LEFT_CTRL_PRESSED ?
|
|
|
|
"LC " : "-- ", stdout);
|
|
|
|
fputs (in.Event.KeyEvent.dwControlKeyState & NUMLOCK_ON ?
|
|
|
|
"NL " : "-- ", stdout);
|
|
|
|
fputs (in.Event.KeyEvent.dwControlKeyState & RIGHT_ALT_PRESSED ?
|
|
|
|
"RA " : "-- ", stdout);
|
|
|
|
fputs (in.Event.KeyEvent.dwControlKeyState & RIGHT_CTRL_PRESSED ?
|
|
|
|
"RC " : "-- ", stdout);
|
|
|
|
fputs (in.Event.KeyEvent.dwControlKeyState & SCROLLLOCK_ON ?
|
|
|
|
"SL " : "-- ", stdout);
|
|
|
|
fputs (in.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED ?
|
|
|
|
"SH " : "-- ", stdout);
|
|
|
|
fputc ('\n', stdout);
|
|
|
|
break;
|
|
|
|
|
2000-12-16 05:53:30 +01:00
|
|
|
default:
|
|
|
|
break;
|
2000-10-28 07:00:00 +02:00
|
|
|
}
|
2000-09-29 13:20:53 +02:00
|
|
|
}
|
|
|
|
while (in.EventType != KEY_EVENT ||
|
2000-10-28 07:00:00 +02:00
|
|
|
in.Event.KeyEvent.bKeyDown != FALSE ||
|
2011-10-10 11:42:00 +02:00
|
|
|
in.Event.KeyEvent.uChar.UnicodeChar != L'q');
|
2000-09-29 13:20:53 +02:00
|
|
|
|
|
|
|
CloseHandle (h);
|
|
|
|
return 0;
|
|
|
|
}
|
2000-10-28 07:00:00 +02:00
|
|
|
|
2005-11-22 18:19:17 +01:00
|
|
|
/* RFC1738 says that these do not need to be escaped. */
|
|
|
|
static const char safe_chars[] = "$-_.+!*'(),";
|
|
|
|
|
|
|
|
/* the URL to query. */
|
|
|
|
static const char base_url[] =
|
2007-06-04 03:57:16 +02:00
|
|
|
"http://cygwin.com/cgi-bin2/package-grep.cgi?text=1&grep=";
|
2005-11-22 18:19:17 +01:00
|
|
|
|
|
|
|
/* Queries Cygwin web site for packages containing files matching a regexp.
|
|
|
|
Return value is 1 if there was a problem, otherwise 0. */
|
|
|
|
static int
|
|
|
|
package_grep (char *search)
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
/* construct the actual URL by escaping */
|
2013-08-23 21:56:26 +02:00
|
|
|
char *url = (char *) alloca (sizeof (base_url) + strlen ("&arch=x86_64") + strlen (search) * 3);
|
2005-11-22 18:19:17 +01:00
|
|
|
strcpy (url, base_url);
|
|
|
|
|
|
|
|
char *dest;
|
|
|
|
for (dest = &url[sizeof (base_url) - 1]; *search; search++)
|
|
|
|
{
|
|
|
|
if (isalnum (*search)
|
2007-06-04 03:57:16 +02:00
|
|
|
|| memchr (safe_chars, *search, sizeof (safe_chars) - 1))
|
|
|
|
{
|
|
|
|
*dest++ = *search;
|
|
|
|
}
|
2005-11-22 18:19:17 +01:00
|
|
|
else
|
2007-06-04 03:57:16 +02:00
|
|
|
{
|
|
|
|
*dest++ = '%';
|
|
|
|
sprintf (dest, "%02x", (unsigned char) *search);
|
|
|
|
dest += 2;
|
|
|
|
}
|
2005-11-22 18:19:17 +01:00
|
|
|
}
|
2013-08-23 21:56:26 +02:00
|
|
|
#ifdef __x86_64__
|
|
|
|
strcpy (dest, "&arch=x86_64");
|
|
|
|
#else
|
|
|
|
strcpy (dest, "&arch=x86");
|
|
|
|
#endif
|
2005-11-22 18:19:17 +01:00
|
|
|
|
|
|
|
/* Connect to the net and open the URL. */
|
2013-11-19 12:14:36 +01:00
|
|
|
if (InternetAttemptConnect (0) != ERROR_SUCCESS)
|
2005-11-22 18:19:17 +01:00
|
|
|
{
|
|
|
|
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;
|
2013-11-19 12:14:36 +01:00
|
|
|
if (!(hi = InternetOpenA ("cygcheck", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0)))
|
2005-11-22 18:19:17 +01:00
|
|
|
return display_internet_error ("InternetOpen() failed", NULL);
|
|
|
|
|
2013-11-19 12:14:36 +01:00
|
|
|
if (!(hurl = InternetOpenUrlA (hi, url, NULL, 0, 0, 0)))
|
2005-11-22 18:19:17 +01:00
|
|
|
return display_internet_error ("unable to contact cygwin.com site, "
|
2007-06-04 03:57:16 +02:00
|
|
|
"InternetOpenUrl() failed", hi, NULL);
|
2005-11-22 18:19:17 +01:00
|
|
|
|
|
|
|
/* Check the HTTP response code. */
|
|
|
|
DWORD rc = 0, rc_s = sizeof (DWORD);
|
2013-11-19 12:14:36 +01:00
|
|
|
if (!HttpQueryInfoA (hurl, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,
|
2007-06-04 03:57:16 +02:00
|
|
|
(void *) &rc, &rc_s, NULL))
|
2005-11-22 18:19:17 +01:00
|
|
|
return display_internet_error ("HttpQueryInfo() failed", hurl, hi, NULL);
|
|
|
|
|
|
|
|
if (rc != HTTP_STATUS_OK)
|
|
|
|
{
|
|
|
|
sprintf (buf, "error retrieving results from cygwin.com site, "
|
2007-06-04 03:57:16 +02:00
|
|
|
"HTTP status code %lu", rc);
|
2005-11-22 18:19:17 +01:00
|
|
|
return display_internet_error (buf, hurl, hi, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fetch result and print to stdout. */
|
|
|
|
DWORD numread;
|
|
|
|
do
|
|
|
|
{
|
2013-11-19 12:14:36 +01:00
|
|
|
if (!InternetReadFile (hurl, (void *) buf, sizeof (buf), &numread))
|
2007-06-04 03:57:16 +02:00
|
|
|
return display_internet_error ("InternetReadFile failed", hurl, hi, NULL);
|
2005-11-22 18:19:17 +01:00
|
|
|
if (numread)
|
2007-06-04 03:57:16 +02:00
|
|
|
fwrite ((void *) buf, (size_t) numread, 1, stdout);
|
2005-11-22 18:19:17 +01:00
|
|
|
}
|
|
|
|
while (numread);
|
|
|
|
|
2013-11-19 12:14:36 +01:00
|
|
|
InternetCloseHandle (hurl);
|
|
|
|
InternetCloseHandle (hi);
|
2005-11-22 18:19:17 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-02-27 17:10:17 +01:00
|
|
|
static void
|
2002-03-07 04:13:17 +01:00
|
|
|
usage (FILE * stream, int status)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-02-27 17:10:17 +01:00
|
|
|
fprintf (stream, "\
|
2009-05-04 12:15:48 +02:00
|
|
|
Usage: cygcheck [-v] [-h] PROGRAM\n\
|
|
|
|
cygcheck -c [-d] [PACKAGE]\n\
|
|
|
|
cygcheck -s [-r] [-v] [-h]\n\
|
2005-11-22 18:19:17 +01:00
|
|
|
cygcheck -k\n\
|
2009-05-04 12:15:48 +02:00
|
|
|
cygcheck -f FILE [FILE]...\n\
|
|
|
|
cygcheck -l [PACKAGE]...\n\
|
2005-11-22 18:19:17 +01:00
|
|
|
cygcheck -p REGEXP\n\
|
2009-10-31 14:26:37 +01:00
|
|
|
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\
|
2009-05-04 12:15:48 +02:00
|
|
|
cygcheck -h\n\n\
|
2005-11-22 18:19:17 +01:00
|
|
|
List system information, check installed packages, or query package database.\n\
|
|
|
|
\n\
|
|
|
|
At least one command option or a PROGRAM is required, as shown above.\n\
|
|
|
|
\n\
|
|
|
|
PROGRAM list library (DLL) dependencies of PROGRAM\n\
|
|
|
|
-c, --check-setup show installed version of PACKAGE and verify integrity\n\
|
2011-12-18 00:39:47 +01:00
|
|
|
(or for all installed packages if none specified)\n\
|
2005-11-22 18:19:17 +01:00
|
|
|
-d, --dump-only just list packages, do not verify (with -c)\n\
|
2011-01-10 13:51:02 +01:00
|
|
|
-s, --sysinfo produce diagnostic system information (implies -c)\n\
|
2005-11-22 18:19:17 +01:00
|
|
|
-r, --registry also scan registry for Cygwin settings (with -s)\n\
|
|
|
|
-k, --keycheck perform a keyboard check session (must be run from a\n\
|
2011-12-18 00:39:47 +01:00
|
|
|
plain console only, not from a pty/rxvt/xterm)\n\
|
2009-04-03 13:50:26 +02:00
|
|
|
-f, --find-package find the package to which FILE belongs\n\
|
2005-11-22 18:19:17 +01:00
|
|
|
-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\
|
2011-12-18 00:39:47 +01:00
|
|
|
repository (requires internet connectivity)\n\
|
2009-10-31 14:26:37 +01:00
|
|
|
--delete-orphaned-installation-keys\n\
|
2011-12-18 00:39:47 +01:00
|
|
|
Delete installation keys of old, now unused\n\
|
|
|
|
installations from the registry. Requires the right\n\
|
|
|
|
to change the registry.\n\
|
2009-10-31 14:26:37 +01:00
|
|
|
--enable-unique-object-names Cygwin-DLL\n\
|
|
|
|
--disable-unique-object-names Cygwin-DLL\n\
|
|
|
|
--show-unique-object-names Cygwin-DLL\n\
|
2011-12-18 00:39:47 +01:00
|
|
|
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\
|
2005-11-22 18:19:17 +01:00
|
|
|
-v, --verbose produce more verbose output\n\
|
|
|
|
-h, --help annotate output with explanatory comments when given\n\
|
2011-12-18 00:39:47 +01:00
|
|
|
with another command, otherwise print this help\n\
|
2005-11-22 18:19:17 +01:00
|
|
|
-V, --version print the version of cygcheck and exit\n\
|
2003-04-26 23:52:03 +02:00
|
|
|
\n\
|
2005-11-22 18:19:17 +01:00
|
|
|
Note: -c, -f, and -l only report on packages that are currently installed. To\n\
|
|
|
|
search all official Cygwin packages use -p instead. The -p REGEXP matches\n\
|
|
|
|
package names, descriptions, and names of files/paths within all packages.\n\
|
|
|
|
\n");
|
2002-02-27 17:10:17 +01:00
|
|
|
exit (status);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2000-09-29 13:20:53 +02:00
|
|
|
struct option longopts[] = {
|
2001-11-11 07:07:36 +01:00
|
|
|
{"check-setup", no_argument, NULL, 'c'},
|
2003-09-11 18:24:26 +02:00
|
|
|
{"dump-only", no_argument, NULL, 'd'},
|
2000-10-28 07:00:00 +02:00
|
|
|
{"sysinfo", no_argument, NULL, 's'},
|
|
|
|
{"registry", no_argument, NULL, 'r'},
|
|
|
|
{"verbose", no_argument, NULL, 'v'},
|
|
|
|
{"keycheck", no_argument, NULL, 'k'},
|
2003-08-15 22:26:11 +02:00
|
|
|
{"find-package", no_argument, NULL, 'f'},
|
|
|
|
{"list-package", no_argument, NULL, 'l'},
|
2005-11-22 18:19:17 +01:00
|
|
|
{"package-query", no_argument, NULL, 'p'},
|
2009-10-31 14:26:37 +01:00
|
|
|
{"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},
|
2000-10-28 07:00:00 +02:00
|
|
|
{"help", no_argument, NULL, 'h'},
|
2002-03-07 04:06:28 +01:00
|
|
|
{"version", no_argument, 0, 'V'},
|
2000-10-28 07:00:00 +02:00
|
|
|
{0, no_argument, NULL, 0}
|
2000-09-29 13:20:53 +02:00
|
|
|
};
|
2000-10-28 07:39:38 +02:00
|
|
|
|
2005-11-22 18:19:17 +01:00
|
|
|
static char opts[] = "cdsrvkflphV";
|
2002-02-27 17:10:17 +01:00
|
|
|
|
|
|
|
static void
|
|
|
|
print_version ()
|
|
|
|
{
|
2011-10-10 16:57:48 +02:00
|
|
|
printf ("cygcheck (cygwin) %d.%d.%d\n"
|
|
|
|
"System Checker for Cygwin\n"
|
|
|
|
"Copyright (C) 1998 - %s Red Hat, Inc.\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);
|
2002-02-27 17:10:17 +01:00
|
|
|
}
|
2000-09-29 13:20:53 +02:00
|
|
|
|
2005-05-09 03:56:34 +02:00
|
|
|
void
|
|
|
|
nuke (char *ev)
|
|
|
|
{
|
2005-05-20 18:38:42 +02:00
|
|
|
int n = 1 + strchr (ev, '=') - ev;
|
2008-08-27 22:11:11 +02:00
|
|
|
char *s = (char *) malloc (n + 1);
|
2005-05-09 03:56:34 +02:00
|
|
|
memcpy (s, ev, n);
|
|
|
|
s[n] = '\0';
|
|
|
|
putenv (s);
|
|
|
|
}
|
|
|
|
|
2005-05-17 03:26:16 +02:00
|
|
|
extern "C" {
|
2013-04-23 11:44:36 +02:00
|
|
|
uintptr_t (*cygwin_internal) (int, ...);
|
2009-11-04 18:00:45 +01:00
|
|
|
WCHAR cygwin_dll_path[32768];
|
2005-05-17 03:26:16 +02:00
|
|
|
};
|
2005-05-09 03:56:34 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
load_cygwin (int& argc, char **&argv)
|
|
|
|
{
|
|
|
|
HMODULE h;
|
|
|
|
|
|
|
|
if (!(h = LoadLibrary ("cygwin1.dll")))
|
|
|
|
return;
|
2009-11-04 18:00:45 +01:00
|
|
|
GetModuleFileNameW (h, cygwin_dll_path, 32768);
|
2013-04-23 11:44:36 +02:00
|
|
|
if ((cygwin_internal = (uintptr_t (*) (int, ...))
|
|
|
|
GetProcAddress (h, "cygwin_internal")))
|
2008-07-27 16:53:42 +02:00
|
|
|
{
|
|
|
|
char **av = (char **) cygwin_internal (CW_ARGV);
|
2013-04-23 11:44:36 +02:00
|
|
|
if (av && ((uintptr_t) av != (uintptr_t) -1))
|
2008-08-04 17:30:06 +02:00
|
|
|
{
|
2015-08-30 21:35:23 +02:00
|
|
|
/* Copy cygwin's idea of the argument list into this Window
|
|
|
|
application. */
|
2008-08-04 17:30:06 +02:00
|
|
|
for (argc = 0; av[argc]; argc++)
|
|
|
|
continue;
|
|
|
|
argv = (char **) calloc (argc + 1, sizeof (char *));
|
|
|
|
for (char **argvp = argv; *av; av++)
|
|
|
|
*argvp++ = strdup (*av);
|
|
|
|
}
|
|
|
|
|
2005-05-09 03:56:34 +02:00
|
|
|
|
2008-07-27 16:53:42 +02:00
|
|
|
char **envp = (char **) cygwin_internal (CW_ENVP);
|
2013-04-23 11:44:36 +02:00
|
|
|
if (envp && ((uintptr_t) envp != (uintptr_t) -1))
|
2005-05-15 14:29:47 +02:00
|
|
|
{
|
2015-08-30 21:35:23 +02:00
|
|
|
/* Store path and revert to this value, otherwise path gets
|
|
|
|
overwritten by the POSIXy Cygwin variation, which breaks cygcheck.
|
2008-07-27 16:53:42 +02:00
|
|
|
Another approach would be to use the Cygwin PATH and convert it to
|
|
|
|
Win32 again. */
|
|
|
|
char *path = NULL;
|
|
|
|
char **env;
|
|
|
|
while (*(env = _environ))
|
|
|
|
{
|
|
|
|
if (strncmp (*env, "PATH=", 5) == 0)
|
|
|
|
path = strdup (*env);
|
|
|
|
nuke (*env);
|
|
|
|
}
|
|
|
|
for (char **ev = envp; *ev; ev++)
|
|
|
|
if (strncmp (*ev, "PATH=", 5) != 0)
|
2008-08-27 22:11:11 +02:00
|
|
|
putenv (strdup (*ev));
|
2008-07-27 16:53:42 +02:00
|
|
|
if (path)
|
|
|
|
putenv (path);
|
2005-05-27 17:45:53 +02:00
|
|
|
}
|
2005-05-09 03:56:34 +02:00
|
|
|
}
|
2015-08-30 21:35:23 +02:00
|
|
|
/* GDB chokes when the DLL got unloaded and, for some reason, fails to set
|
|
|
|
any breakpoint after the fact. */
|
|
|
|
if (!IsDebuggerPresent ())
|
|
|
|
FreeLibrary (h);
|
2005-05-09 03:56:34 +02:00
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
int i;
|
2005-07-05 23:41:37 +02:00
|
|
|
bool ok = true;
|
2005-05-09 03:56:34 +02:00
|
|
|
load_cygwin (argc, argv);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2006-09-13 17:32:04 +02:00
|
|
|
/* Need POSIX sorting while parsing args, but don't forget the
|
|
|
|
user's original environment. */
|
|
|
|
char *posixly = getenv ("POSIXLY_CORRECT");
|
|
|
|
if (posixly == NULL)
|
2009-10-31 14:26:37 +01:00
|
|
|
(void) putenv ("POSIXLY_CORRECT=1");
|
2000-09-29 13:20:53 +02:00
|
|
|
while ((i = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case 's':
|
2000-10-28 07:00:00 +02:00
|
|
|
sysinfo = 1;
|
|
|
|
break;
|
2001-11-11 07:07:36 +01:00
|
|
|
case 'c':
|
|
|
|
check_setup = 1;
|
|
|
|
break;
|
2003-09-11 18:24:26 +02:00
|
|
|
case 'd':
|
|
|
|
dump_only = 1;
|
|
|
|
break;
|
2000-09-29 13:20:53 +02:00
|
|
|
case 'r':
|
2000-10-28 07:00:00 +02:00
|
|
|
registry = 1;
|
|
|
|
break;
|
2000-09-29 13:20:53 +02:00
|
|
|
case 'v':
|
2000-10-28 07:00:00 +02:00
|
|
|
verbose = 1;
|
|
|
|
break;
|
2000-09-29 13:20:53 +02:00
|
|
|
case 'k':
|
2000-10-28 07:00:00 +02:00
|
|
|
keycheck = 1;
|
|
|
|
break;
|
2003-08-15 22:26:11 +02:00
|
|
|
case 'f':
|
|
|
|
find_package = 1;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
list_package = 1;
|
|
|
|
break;
|
2005-11-22 18:19:17 +01:00
|
|
|
case 'p':
|
2007-06-04 03:57:16 +02:00
|
|
|
grep_packages = 1;
|
|
|
|
break;
|
2000-09-29 13:20:53 +02:00
|
|
|
case 'h':
|
2000-10-28 07:00:00 +02:00
|
|
|
givehelp = 1;
|
|
|
|
break;
|
2009-10-31 14:26:37 +01:00
|
|
|
case CO_DELETE_KEYS:
|
2011-12-18 00:39:47 +01:00
|
|
|
del_orphaned_reg = 1;
|
2009-10-31 14:26:37 +01:00
|
|
|
break;
|
|
|
|
case CO_ENABLE_UON:
|
|
|
|
case CO_DISABLE_UON:
|
|
|
|
case CO_SHOW_UON:
|
2011-12-18 00:39:47 +01:00
|
|
|
unique_object_name_opt = i;
|
2009-10-31 14:26:37 +01:00
|
|
|
break;
|
2002-02-27 17:10:17 +01:00
|
|
|
case 'V':
|
|
|
|
print_version ();
|
2002-03-07 04:13:17 +01:00
|
|
|
exit (0);
|
2000-09-29 13:20:53 +02:00
|
|
|
default:
|
2011-10-10 16:57:48 +02:00
|
|
|
fprintf (stderr, "Try `cygcheck --help' for more information.\n");
|
|
|
|
exit (1);
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
2000-09-29 13:20:53 +02:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
2006-09-13 17:32:04 +02:00
|
|
|
if (posixly == NULL)
|
|
|
|
putenv ("POSIXLY_CORRECT=");
|
2000-09-29 13:20:53 +02:00
|
|
|
|
2009-10-31 14:26:37 +01:00
|
|
|
if ((argc == 0) && !sysinfo && !keycheck && !check_setup && !list_package
|
|
|
|
&& !del_orphaned_reg)
|
2008-09-13 00:43:10 +02:00
|
|
|
{
|
|
|
|
if (givehelp)
|
|
|
|
usage (stdout, 0);
|
|
|
|
else
|
|
|
|
usage (stderr, 1);
|
|
|
|
}
|
2000-09-29 13:20:53 +02:00
|
|
|
|
2009-10-31 14:26:37 +01:00
|
|
|
if ((check_setup || sysinfo || find_package || list_package || grep_packages
|
|
|
|
|| del_orphaned_reg || unique_object_name_opt)
|
2005-11-22 18:19:17 +01:00
|
|
|
&& keycheck)
|
2003-08-15 22:26:11 +02:00
|
|
|
usage (stderr, 1);
|
|
|
|
|
2009-10-31 14:26:37 +01:00
|
|
|
if ((find_package || list_package || grep_packages)
|
|
|
|
&& (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)
|
2003-08-15 22:26:11 +02:00
|
|
|
usage (stderr, 1);
|
|
|
|
|
2011-01-10 13:51:02 +01:00
|
|
|
if (dump_only && !check_setup && !sysinfo)
|
2003-09-11 18:24:26 +02:00
|
|
|
usage (stderr, 1);
|
|
|
|
|
2005-11-22 18:19:17 +01:00
|
|
|
if (find_package + list_package + grep_packages > 1)
|
2002-02-27 17:10:17 +01:00
|
|
|
usage (stderr, 1);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-09-29 13:20:53 +02:00
|
|
|
if (keycheck)
|
2000-10-28 07:00:00 +02:00
|
|
|
return check_keys ();
|
2009-10-31 14:26:37 +01:00
|
|
|
if (unique_object_name_opt)
|
|
|
|
return handle_unique_object_name (unique_object_name_opt, *argv);
|
|
|
|
if (del_orphaned_reg)
|
|
|
|
del_orphaned_reg_installations ();
|
2005-11-22 18:19:17 +01:00
|
|
|
if (grep_packages)
|
|
|
|
return package_grep (*argv);
|
2000-09-29 13:20:53 +02:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
init_paths ();
|
|
|
|
|
2003-08-15 22:26:11 +02:00
|
|
|
/* FIXME: Add help for check_setup and {list,find}_package */
|
|
|
|
if (argc >= 1 && givehelp && !check_setup && !find_package && !list_package)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2003-08-15 22:26:11 +02:00
|
|
|
printf("Here is where the OS will find your program%s, and which dlls\n",
|
|
|
|
argc > 1 ? "s" : "");
|
|
|
|
printf ("will be used for it. Use -v to see DLL version info\n");
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
if (!sysinfo)
|
|
|
|
printf ("\n");
|
|
|
|
}
|
|
|
|
|
2001-11-11 07:07:36 +01:00
|
|
|
if (check_setup)
|
2004-11-11 02:52:33 +01:00
|
|
|
dump_setup (verbose, argv, !dump_only);
|
2003-08-15 22:26:11 +02:00
|
|
|
else if (find_package)
|
2004-11-11 02:52:33 +01:00
|
|
|
package_find (verbose, argv);
|
2003-08-15 22:26:11 +02:00
|
|
|
else if (list_package)
|
2004-11-11 02:52:33 +01:00
|
|
|
package_list (verbose, argv);
|
2001-11-11 07:07:36 +01:00
|
|
|
else
|
|
|
|
for (i = 0; i < argc; i++)
|
|
|
|
{
|
2003-08-15 22:26:11 +02:00
|
|
|
if (i)
|
|
|
|
puts ("");
|
2005-07-05 23:41:37 +02:00
|
|
|
ok &= cygcheck (argv[i]);
|
2001-11-11 07:07:36 +01:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
if (sysinfo)
|
2001-11-11 07:16:18 +01:00
|
|
|
{
|
|
|
|
dump_sysinfo ();
|
|
|
|
if (!check_setup)
|
|
|
|
{
|
2001-11-12 22:28:32 +01:00
|
|
|
puts ("");
|
2011-01-10 13:51:02 +01:00
|
|
|
dump_setup (verbose, NULL, !dump_only);
|
2001-11-11 07:16:18 +01:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2003-08-15 22:26:11 +02:00
|
|
|
if (!givehelp)
|
|
|
|
puts ("Use -h to see help about each section");
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2005-07-05 23:41:37 +02:00
|
|
|
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|