2000-09-28 03:16:29 +00:00
|
|
|
/* filesystem.c
|
|
|
|
* Filesystem utility routines
|
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2000-09-28 03:16:29 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
2018-02-07 11:26:45 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2000-09-28 03:16:29 +00:00
|
|
|
*/
|
|
|
|
|
2016-03-14 19:03:11 +00:00
|
|
|
#include <config.h>
|
2000-09-28 03:16:29 +00:00
|
|
|
|
2001-10-23 03:40:39 +00:00
|
|
|
#include <stdio.h>
|
2000-09-28 03:16:29 +00:00
|
|
|
#include <stdlib.h>
|
2000-10-11 07:35:02 +00:00
|
|
|
#include <string.h>
|
On Windows, use the directory in which the binary resides as the
directory in which global data files are stored. If an installed binary
is being run, that's the correct directory for them; if a build-tree
binary is being run, the "manuf" file will be there, and you can put
other data files there as well, if necessary.
Do the same with plugins, except that, if there's no
"plugins\\{version}" subdirectory of that directory, fall back on the
default installation directory, so you at least have a place where you
can put plugins for use by build-tree binaries. (Should we, instead,
have the Windows build procedure create a subdirectory of the "plugins"
source directory, with the plugin version number as its name, and copy
the plugins there, so you'd use the build-tree plugin binaries?)
Move "test_for_directory()" out of "util.c" and into
"epan/filesystem.c", with the other file system access portability
wrappers and convenience routines. Fix "util.h" not to declare it - or
other routines moved to "epan/filesystem.c" a while ago.
svn path=/trunk/; revision=3858
2001-08-21 06:39:18 +00:00
|
|
|
#include <errno.h>
|
|
|
|
|
2000-09-28 03:16:29 +00:00
|
|
|
#include <glib.h>
|
|
|
|
|
2006-03-08 22:13:21 +00:00
|
|
|
#ifdef _WIN32
|
2001-08-21 08:16:54 +00:00
|
|
|
#include <windows.h>
|
2006-03-08 20:55:32 +00:00
|
|
|
#include <tchar.h>
|
2007-01-14 22:25:22 +00:00
|
|
|
#include <shlobj.h>
|
2008-06-30 17:16:29 +00:00
|
|
|
#include <wsutil/unicode-utils.h>
|
2009-03-22 00:42:33 +00:00
|
|
|
#else /* _WIN32 */
|
2013-08-12 08:28:34 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <mach-o/dyld.h>
|
|
|
|
#endif
|
|
|
|
#ifdef __linux__
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
#endif
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#endif
|
2018-05-05 06:39:46 +00:00
|
|
|
#ifdef HAVE_DLGET
|
2009-03-22 00:42:33 +00:00
|
|
|
#include <dlfcn.h>
|
2013-08-12 00:59:34 +00:00
|
|
|
#endif
|
2006-03-08 22:13:21 +00:00
|
|
|
#include <pwd.h>
|
2009-03-22 00:42:33 +00:00
|
|
|
#endif /* _WIN32 */
|
2000-09-28 03:16:29 +00:00
|
|
|
|
|
|
|
#include "filesystem.h"
|
2017-04-08 19:45:19 +00:00
|
|
|
#include <wsutil/report_message.h>
|
2008-06-30 17:16:29 +00:00
|
|
|
#include <wsutil/privileges.h>
|
2008-05-22 15:46:27 +00:00
|
|
|
#include <wsutil/file_util.h>
|
2016-06-20 16:41:10 +00:00
|
|
|
#include <wsutil/utf8_entities.h>
|
2000-09-28 03:16:29 +00:00
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
#include <wiretap/wtap.h> /* for WTAP_ERR_SHORT_WRITE */
|
2009-02-15 21:47:57 +00:00
|
|
|
|
2008-01-14 16:40:23 +00:00
|
|
|
#define PROFILES_DIR "profiles"
|
2009-10-23 17:52:18 +00:00
|
|
|
#define PLUGINS_DIR_NAME "plugins"
|
2017-06-21 14:43:21 +00:00
|
|
|
#define PROFILES_INFO_NAME "profile_files.txt"
|
2009-10-23 17:52:18 +00:00
|
|
|
|
2018-06-01 14:18:22 +00:00
|
|
|
#define ENV_CONFIG_PATH_VAR "WIRESHARK_CONFIG_DIR"
|
|
|
|
|
2007-03-14 02:55:54 +00:00
|
|
|
char *persconffile_dir = NULL;
|
2018-12-04 01:34:25 +00:00
|
|
|
char *datafile_dir = NULL;
|
2007-03-14 02:55:54 +00:00
|
|
|
char *persdatafile_dir = NULL;
|
2008-01-14 16:40:23 +00:00
|
|
|
char *persconfprofile = NULL;
|
2007-03-14 02:55:54 +00:00
|
|
|
|
2009-12-21 12:32:31 +00:00
|
|
|
static gboolean do_store_persconffiles = FALSE;
|
|
|
|
static GHashTable *profile_files = NULL;
|
|
|
|
|
2001-04-02 09:53:46 +00:00
|
|
|
/*
|
|
|
|
* Given a pathname, return a pointer to the last pathname separator
|
|
|
|
* character in the pathname, or NULL if the pathname contains no
|
|
|
|
* separators.
|
|
|
|
*/
|
2010-08-10 11:36:18 +00:00
|
|
|
char *
|
"gtk_entry_get_text()" returns a "const char *" - assign the result to
one.
"get_basename()" doesn't modify its argument, and its callers don't
modify the substring pointed to by the result, so make it take a "const
char *" as an argument and return a "const char *".
"find_last_pathname_separator()" doesn't modify its argument, so make it
a "const char *" - but some of its callers pass a non-"const" "char *"
and modify the result, so don't make its return value a "const char *".
And, as none of its callers are outside "filesystem.c", make it static.
In "about_folders_page_new()", have separate variables for pathnames
returned as "const char *" (which are cached by the routine that returns
them, so you can't modify them - and can't free them, so get rid of the
commented-out "g_free()" calls for them) and pathnames returned as "char
*" (which are allocated anew for each call, and can be modified, but
have to be freed).
Clean up white space.
svn path=/trunk/; revision=12881
2004-12-31 00:26:36 +00:00
|
|
|
find_last_pathname_separator(const char *path)
|
2001-04-02 09:53:46 +00:00
|
|
|
{
|
2011-09-21 17:14:14 +00:00
|
|
|
char *separator;
|
2001-04-02 09:53:46 +00:00
|
|
|
|
2004-09-11 23:03:36 +00:00
|
|
|
#ifdef _WIN32
|
2011-09-21 17:14:14 +00:00
|
|
|
char c;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have to scan for '\' or '/'.
|
|
|
|
* Get to the end of the string.
|
|
|
|
*/
|
|
|
|
separator = strchr(path, '\0'); /* points to ending '\0' */
|
|
|
|
while (separator > path) {
|
|
|
|
c = *--separator;
|
|
|
|
if (c == '\\' || c == '/')
|
|
|
|
return separator; /* found it */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* OK, we didn't find any, so no directories - but there might
|
|
|
|
* be a drive letter....
|
|
|
|
*/
|
|
|
|
return strchr(path, ':');
|
2001-04-02 09:53:46 +00:00
|
|
|
#else
|
2011-09-21 17:14:14 +00:00
|
|
|
separator = strrchr(path, '/');
|
|
|
|
return separator;
|
2011-01-30 23:27:57 +00:00
|
|
|
#endif
|
2001-04-02 09:53:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a pathname, return the last component.
|
|
|
|
*/
|
"gtk_entry_get_text()" returns a "const char *" - assign the result to
one.
"get_basename()" doesn't modify its argument, and its callers don't
modify the substring pointed to by the result, so make it take a "const
char *" as an argument and return a "const char *".
"find_last_pathname_separator()" doesn't modify its argument, so make it
a "const char *" - but some of its callers pass a non-"const" "char *"
and modify the result, so don't make its return value a "const char *".
And, as none of its callers are outside "filesystem.c", make it static.
In "about_folders_page_new()", have separate variables for pathnames
returned as "const char *" (which are cached by the routine that returns
them, so you can't modify them - and can't free them, so get rid of the
commented-out "g_free()" calls for them) and pathnames returned as "char
*" (which are allocated anew for each call, and can be modified, but
have to be freed).
Clean up white space.
svn path=/trunk/; revision=12881
2004-12-31 00:26:36 +00:00
|
|
|
const char *
|
|
|
|
get_basename(const char *path)
|
2001-04-02 09:53:46 +00:00
|
|
|
{
|
2011-09-21 17:14:14 +00:00
|
|
|
const char *filename;
|
|
|
|
|
|
|
|
g_assert(path != NULL);
|
|
|
|
filename = find_last_pathname_separator(path);
|
|
|
|
if (filename == NULL) {
|
|
|
|
/*
|
|
|
|
* There're no directories, drive letters, etc. in the
|
|
|
|
* name; the pathname *is* the file name.
|
|
|
|
*/
|
|
|
|
filename = path;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Skip past the pathname or drive letter separator.
|
|
|
|
*/
|
|
|
|
filename++;
|
|
|
|
}
|
|
|
|
return filename;
|
2001-04-02 09:53:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a pathname, return a string containing everything but the
|
|
|
|
* last component. NOTE: this overwrites the pathname handed into
|
|
|
|
* it....
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
get_dirname(char *path)
|
|
|
|
{
|
2011-09-21 17:14:14 +00:00
|
|
|
char *separator;
|
|
|
|
|
|
|
|
g_assert(path != NULL);
|
|
|
|
separator = find_last_pathname_separator(path);
|
|
|
|
if (separator == NULL) {
|
|
|
|
/*
|
|
|
|
* There're no directories, drive letters, etc. in the
|
|
|
|
* name; there is no directory path to return.
|
|
|
|
*/
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get rid of the last pathname separator and the final file
|
|
|
|
* name following it.
|
|
|
|
*/
|
|
|
|
*separator = '\0';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "path" now contains the pathname of the directory containing
|
|
|
|
* the file/directory to which it referred.
|
|
|
|
*/
|
|
|
|
return path;
|
2001-04-02 09:53:46 +00:00
|
|
|
}
|
|
|
|
|
On Windows, use the directory in which the binary resides as the
directory in which global data files are stored. If an installed binary
is being run, that's the correct directory for them; if a build-tree
binary is being run, the "manuf" file will be there, and you can put
other data files there as well, if necessary.
Do the same with plugins, except that, if there's no
"plugins\\{version}" subdirectory of that directory, fall back on the
default installation directory, so you at least have a place where you
can put plugins for use by build-tree binaries. (Should we, instead,
have the Windows build procedure create a subdirectory of the "plugins"
source directory, with the plugin version number as its name, and copy
the plugins there, so you'd use the build-tree plugin binaries?)
Move "test_for_directory()" out of "util.c" and into
"epan/filesystem.c", with the other file system access portability
wrappers and convenience routines. Fix "util.h" not to declare it - or
other routines moved to "epan/filesystem.c" a while ago.
svn path=/trunk/; revision=3858
2001-08-21 06:39:18 +00:00
|
|
|
/*
|
|
|
|
* Given a pathname, return:
|
|
|
|
*
|
2011-09-21 17:14:14 +00:00
|
|
|
* the errno, if an attempt to "stat()" the file fails;
|
On Windows, use the directory in which the binary resides as the
directory in which global data files are stored. If an installed binary
is being run, that's the correct directory for them; if a build-tree
binary is being run, the "manuf" file will be there, and you can put
other data files there as well, if necessary.
Do the same with plugins, except that, if there's no
"plugins\\{version}" subdirectory of that directory, fall back on the
default installation directory, so you at least have a place where you
can put plugins for use by build-tree binaries. (Should we, instead,
have the Windows build procedure create a subdirectory of the "plugins"
source directory, with the plugin version number as its name, and copy
the plugins there, so you'd use the build-tree plugin binaries?)
Move "test_for_directory()" out of "util.c" and into
"epan/filesystem.c", with the other file system access portability
wrappers and convenience routines. Fix "util.h" not to declare it - or
other routines moved to "epan/filesystem.c" a while ago.
svn path=/trunk/; revision=3858
2001-08-21 06:39:18 +00:00
|
|
|
*
|
2011-09-21 17:14:14 +00:00
|
|
|
* EISDIR, if the attempt succeeded and the file turned out
|
|
|
|
* to be a directory;
|
On Windows, use the directory in which the binary resides as the
directory in which global data files are stored. If an installed binary
is being run, that's the correct directory for them; if a build-tree
binary is being run, the "manuf" file will be there, and you can put
other data files there as well, if necessary.
Do the same with plugins, except that, if there's no
"plugins\\{version}" subdirectory of that directory, fall back on the
default installation directory, so you at least have a place where you
can put plugins for use by build-tree binaries. (Should we, instead,
have the Windows build procedure create a subdirectory of the "plugins"
source directory, with the plugin version number as its name, and copy
the plugins there, so you'd use the build-tree plugin binaries?)
Move "test_for_directory()" out of "util.c" and into
"epan/filesystem.c", with the other file system access portability
wrappers and convenience routines. Fix "util.h" not to declare it - or
other routines moved to "epan/filesystem.c" a while ago.
svn path=/trunk/; revision=3858
2001-08-21 06:39:18 +00:00
|
|
|
*
|
2011-09-21 17:14:14 +00:00
|
|
|
* 0, if the attempt succeeded and the file turned out not
|
|
|
|
* to be a directory.
|
On Windows, use the directory in which the binary resides as the
directory in which global data files are stored. If an installed binary
is being run, that's the correct directory for them; if a build-tree
binary is being run, the "manuf" file will be there, and you can put
other data files there as well, if necessary.
Do the same with plugins, except that, if there's no
"plugins\\{version}" subdirectory of that directory, fall back on the
default installation directory, so you at least have a place where you
can put plugins for use by build-tree binaries. (Should we, instead,
have the Windows build procedure create a subdirectory of the "plugins"
source directory, with the plugin version number as its name, and copy
the plugins there, so you'd use the build-tree plugin binaries?)
Move "test_for_directory()" out of "util.c" and into
"epan/filesystem.c", with the other file system access portability
wrappers and convenience routines. Fix "util.h" not to declare it - or
other routines moved to "epan/filesystem.c" a while ago.
svn path=/trunk/; revision=3858
2001-08-21 06:39:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
test_for_directory(const char *path)
|
|
|
|
{
|
2011-09-21 17:14:14 +00:00
|
|
|
ws_statb64 statb;
|
On Windows, use the directory in which the binary resides as the
directory in which global data files are stored. If an installed binary
is being run, that's the correct directory for them; if a build-tree
binary is being run, the "manuf" file will be there, and you can put
other data files there as well, if necessary.
Do the same with plugins, except that, if there's no
"plugins\\{version}" subdirectory of that directory, fall back on the
default installation directory, so you at least have a place where you
can put plugins for use by build-tree binaries. (Should we, instead,
have the Windows build procedure create a subdirectory of the "plugins"
source directory, with the plugin version number as its name, and copy
the plugins there, so you'd use the build-tree plugin binaries?)
Move "test_for_directory()" out of "util.c" and into
"epan/filesystem.c", with the other file system access portability
wrappers and convenience routines. Fix "util.h" not to declare it - or
other routines moved to "epan/filesystem.c" a while ago.
svn path=/trunk/; revision=3858
2001-08-21 06:39:18 +00:00
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
if (ws_stat64(path, &statb) < 0)
|
|
|
|
return errno;
|
On Windows, use the directory in which the binary resides as the
directory in which global data files are stored. If an installed binary
is being run, that's the correct directory for them; if a build-tree
binary is being run, the "manuf" file will be there, and you can put
other data files there as well, if necessary.
Do the same with plugins, except that, if there's no
"plugins\\{version}" subdirectory of that directory, fall back on the
default installation directory, so you at least have a place where you
can put plugins for use by build-tree binaries. (Should we, instead,
have the Windows build procedure create a subdirectory of the "plugins"
source directory, with the plugin version number as its name, and copy
the plugins there, so you'd use the build-tree plugin binaries?)
Move "test_for_directory()" out of "util.c" and into
"epan/filesystem.c", with the other file system access portability
wrappers and convenience routines. Fix "util.h" not to declare it - or
other routines moved to "epan/filesystem.c" a while ago.
svn path=/trunk/; revision=3858
2001-08-21 06:39:18 +00:00
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
if (S_ISDIR(statb.st_mode))
|
|
|
|
return EISDIR;
|
|
|
|
else
|
|
|
|
return 0;
|
On Windows, use the directory in which the binary resides as the
directory in which global data files are stored. If an installed binary
is being run, that's the correct directory for them; if a build-tree
binary is being run, the "manuf" file will be there, and you can put
other data files there as well, if necessary.
Do the same with plugins, except that, if there's no
"plugins\\{version}" subdirectory of that directory, fall back on the
default installation directory, so you at least have a place where you
can put plugins for use by build-tree binaries. (Should we, instead,
have the Windows build procedure create a subdirectory of the "plugins"
source directory, with the plugin version number as its name, and copy
the plugins there, so you'd use the build-tree plugin binaries?)
Move "test_for_directory()" out of "util.c" and into
"epan/filesystem.c", with the other file system access portability
wrappers and convenience routines. Fix "util.h" not to declare it - or
other routines moved to "epan/filesystem.c" a while ago.
svn path=/trunk/; revision=3858
2001-08-21 06:39:18 +00:00
|
|
|
}
|
|
|
|
|
2002-06-23 21:33:09 +00:00
|
|
|
int
|
|
|
|
test_for_fifo(const char *path)
|
|
|
|
{
|
2011-09-21 17:14:14 +00:00
|
|
|
ws_statb64 statb;
|
2002-06-23 21:33:09 +00:00
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
if (ws_stat64(path, &statb) < 0)
|
|
|
|
return errno;
|
2002-06-23 21:33:09 +00:00
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
if (S_ISFIFO(statb.st_mode))
|
|
|
|
return ESPIPE;
|
|
|
|
else
|
|
|
|
return 0;
|
2002-06-23 21:33:09 +00:00
|
|
|
}
|
|
|
|
|
2007-05-21 20:31:45 +00:00
|
|
|
/*
|
|
|
|
* Directory from which the executable came.
|
|
|
|
*/
|
Add a routine to attempt to get the absolute pathname of the executable
file, strip off the last component to get the pathname of the directory
containing the executable file, and save it for future use. On Windows,
you can get that from the OS, but, on UN*X, you have to look at argv[0]
and derive the absolute path from that (argv[0] is not guaranteed to be
an absolute path, or even a path at all). (In addition, if you're
running from the build directory, you might have to strip off a ".libs/"
added to argv[0] as an artifact of the libtoolizing script.)
Use that in the About dialog, and use it to construct the path of
dumpcap.
Don't put quotes into the path of dumpcap; you don't have to quote
strings with spaces in them when handing them to execvp and, in fact,
you *mustn't* quote them, as the quotes will be treated as part of the
pathname.
svn path=/trunk/; revision=17267
2006-02-12 03:15:29 +00:00
|
|
|
static char *progfile_dir;
|
|
|
|
|
2013-08-12 00:59:34 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
/*
|
|
|
|
* Directory of the application bundle in which we're contained,
|
|
|
|
* if we're contained in an application bundle. Otherwise, NULL.
|
2013-08-12 01:20:20 +00:00
|
|
|
*
|
|
|
|
* Note: Table 2-5 "Subdirectories of the Contents directory" of
|
|
|
|
*
|
|
|
|
* https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html#//apple_ref/doc/uid/10000123i-CH101-SW1
|
|
|
|
*
|
|
|
|
* says that the "Frameworks" directory
|
|
|
|
*
|
|
|
|
* Contains any private shared libraries and frameworks used by the
|
|
|
|
* executable. The frameworks in this directory are revision-locked
|
|
|
|
* to the application and cannot be superseded by any other, even
|
|
|
|
* newer, versions that may be available to the operating system. In
|
|
|
|
* other words, the frameworks included in this directory take precedence
|
|
|
|
* over any other similarly named frameworks found in other parts of
|
|
|
|
* the operating system. For information on how to add private
|
|
|
|
* frameworks to your application bundle, see Framework Programming Guide.
|
|
|
|
*
|
|
|
|
* so if we were to ship with any frameworks (e.g. Qt) we should
|
|
|
|
* perhaps put them in a Frameworks directory rather than under
|
|
|
|
* Resources.
|
|
|
|
*
|
|
|
|
* It also says that the "PlugIns" directory
|
|
|
|
*
|
|
|
|
* Contains loadable bundles that extend the basic features of your
|
|
|
|
* application. You use this directory to include code modules that
|
|
|
|
* must be loaded into your applicationbs process space in order to
|
|
|
|
* be used. You would not use this directory to store standalone
|
|
|
|
* executables.
|
|
|
|
*
|
|
|
|
* Our plugins are just raw .so/.dylib files; I don't know whether by
|
|
|
|
* "bundles" they mean application bundles (i.e., directory hierarchies)
|
|
|
|
* or just "bundles" in the Mach-O sense (which are an image type that
|
|
|
|
* can be loaded with dlopen() but not linked as libraries; our plugins
|
|
|
|
* are, I think, built as dylibs and can be loaded either way).
|
|
|
|
*
|
|
|
|
* And it says that the "SharedSupport" directory
|
|
|
|
*
|
|
|
|
* Contains additional non-critical resources that do not impact the
|
|
|
|
* ability of the application to run. You might use this directory to
|
|
|
|
* include things like document templates, clip art, and tutorials
|
|
|
|
* that your application expects to be present but that do not affect
|
|
|
|
* the ability of your application to run.
|
|
|
|
*
|
|
|
|
* I don't think I'd put the files that currently go under Resources/share
|
|
|
|
* into that category; they're not, for example, sample Lua scripts that
|
|
|
|
* don't actually get run by Wireshark, they're configuration/data files
|
|
|
|
* for Wireshark whose absence might not prevent Wireshark from running
|
|
|
|
* but that would affect how it behaves when run.
|
2013-08-12 00:59:34 +00:00
|
|
|
*/
|
|
|
|
static char *appbundle_dir;
|
|
|
|
#endif
|
2013-09-13 20:15:46 +00:00
|
|
|
|
2007-05-21 20:31:45 +00:00
|
|
|
/*
|
2008-03-15 18:31:52 +00:00
|
|
|
* TRUE if we're running from the build directory and we aren't running
|
|
|
|
* with special privileges.
|
2007-05-21 20:31:45 +00:00
|
|
|
*/
|
|
|
|
static gboolean running_in_build_directory_flag = FALSE;
|
|
|
|
|
2013-08-12 08:28:34 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
/*
|
|
|
|
* Get the pathname of the executable using various platform-
|
|
|
|
* dependent mechanisms for various UN*Xes.
|
|
|
|
*
|
|
|
|
* These calls all should return something independent of the argv[0]
|
|
|
|
* passed to the program, so it shouldn't be fooled by an argv[0]
|
|
|
|
* that doesn't match the executable path.
|
|
|
|
*
|
2018-05-05 07:19:09 +00:00
|
|
|
* We don't use dladdr() because:
|
|
|
|
*
|
|
|
|
* not all UN*Xes necessarily have dladdr();
|
|
|
|
*
|
|
|
|
* those that do have it don't necessarily have dladdr(main)
|
|
|
|
* return information about the executable image;
|
|
|
|
*
|
|
|
|
* those that do have a dladdr() where dladdr(main) returns
|
|
|
|
* information about the executable image don't necessarily
|
|
|
|
* have a mechanism by which the executable image can get
|
|
|
|
* its own path from the kernel (either by a call or by it
|
|
|
|
* being handed to it along with argv[] and the environment),
|
|
|
|
* so they just fall back on getting it from argv[0], which we
|
|
|
|
* already have code to do;
|
|
|
|
*
|
|
|
|
* those that do have such a mechanism don't necessarily use
|
|
|
|
* it in dladdr(), and, instead, just fall back on getting it
|
|
|
|
* from argv[0];
|
|
|
|
*
|
|
|
|
* so the only places where it's worth bothering to use dladdr()
|
|
|
|
* are platforms where dladdr(main) return information about the
|
|
|
|
* executable image by getting it from the kernel rather than
|
|
|
|
* by looking at argv[0], and where we can't get at that information
|
|
|
|
* ourselves, and we haven't seen any indication that there are any
|
|
|
|
* such platforms.
|
2013-08-12 08:28:34 +00:00
|
|
|
*
|
2013-08-13 23:37:32 +00:00
|
|
|
* In particular, some dynamic linkers supply a dladdr() such that
|
|
|
|
* dladdr(main) just returns something derived from argv[0], so
|
|
|
|
* just using dladdr(main) is the wrong thing to do if there's
|
|
|
|
* another mechanism that can get you a more reliable version of
|
|
|
|
* the executable path.
|
2013-08-12 18:51:06 +00:00
|
|
|
*
|
2018-05-05 07:19:09 +00:00
|
|
|
* So, on platforms where we know of a mechanism to get that path
|
|
|
|
* (where getting that path doesn't involve argv[0], which is not
|
|
|
|
* guaranteed to reflect the path to the binary), this routine
|
|
|
|
* attempsts to use that platform's mechanism. On other platforms,
|
|
|
|
* it just returns NULL.
|
2013-08-12 08:28:34 +00:00
|
|
|
*
|
|
|
|
* This is not guaranteed to return an absolute path; if it doesn't,
|
2013-08-13 23:37:32 +00:00
|
|
|
* our caller must prepend the current directory if it's a path.
|
2013-08-12 08:28:34 +00:00
|
|
|
*
|
|
|
|
* This is not guaranteed to return the "real path"; it might return
|
|
|
|
* something with symbolic links in the path. Our caller must
|
|
|
|
* use realpath() if they want the real thing, but that's also true of
|
|
|
|
* something obtained by looking at argv[0].
|
|
|
|
*/
|
2019-05-10 18:22:11 +00:00
|
|
|
#define xx_free free /* hack so checkAPIs doesn't complain */
|
2014-01-10 07:01:15 +00:00
|
|
|
static const char *
|
2013-08-12 08:28:34 +00:00
|
|
|
get_executable_path(void)
|
|
|
|
{
|
|
|
|
#if defined(__APPLE__)
|
2019-05-10 18:22:11 +00:00
|
|
|
static char *executable_path;
|
2013-08-12 08:28:34 +00:00
|
|
|
uint32_t path_buf_size;
|
|
|
|
|
2019-05-10 18:22:11 +00:00
|
|
|
if (executable_path) {
|
|
|
|
return executable_path;
|
|
|
|
}
|
|
|
|
|
2013-08-12 08:28:34 +00:00
|
|
|
path_buf_size = PATH_MAX;
|
|
|
|
executable_path = (char *)g_malloc(path_buf_size);
|
|
|
|
if (_NSGetExecutablePath(executable_path, &path_buf_size) == -1) {
|
|
|
|
executable_path = (char *)g_realloc(executable_path, path_buf_size);
|
|
|
|
if (_NSGetExecutablePath(executable_path, &path_buf_size) == -1)
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-05-10 18:22:11 +00:00
|
|
|
/*
|
|
|
|
* Resolve our path so that it's possible to symlink the executables
|
|
|
|
* in our application bundle.
|
|
|
|
*/
|
|
|
|
char *rp_execpath = realpath(executable_path, NULL);
|
|
|
|
if (rp_execpath) {
|
|
|
|
g_free(executable_path);
|
|
|
|
executable_path = g_strdup(rp_execpath);
|
|
|
|
xx_free(rp_execpath);
|
|
|
|
}
|
2013-08-12 08:28:34 +00:00
|
|
|
return executable_path;
|
|
|
|
#elif defined(__linux__)
|
2013-08-13 23:37:32 +00:00
|
|
|
/*
|
|
|
|
* In older versions of GNU libc's dynamic linker, as used on Linux,
|
|
|
|
* dladdr(main) supplies a path based on argv[0], so we use
|
|
|
|
* /proc/self/exe instead; there are Linux distributions with
|
|
|
|
* kernels that support /proc/self/exe and those older versions
|
|
|
|
* of the dynamic linker, and this will get a better answer on
|
|
|
|
* those versions.
|
|
|
|
*
|
|
|
|
* It only works on Linux 2.2 or later, so we just give up on
|
|
|
|
* earlier versions.
|
|
|
|
*
|
|
|
|
* XXX - are there OS versions that support "exe" but not "self"?
|
|
|
|
*/
|
2013-08-12 08:28:34 +00:00
|
|
|
struct utsname name;
|
2015-07-11 16:06:22 +00:00
|
|
|
static char executable_path[PATH_MAX + 1];
|
|
|
|
ssize_t r;
|
2013-08-12 08:28:34 +00:00
|
|
|
|
|
|
|
if (uname(&name) == -1)
|
|
|
|
return NULL;
|
|
|
|
if (strncmp(name.release, "1.", 2) == 0)
|
|
|
|
return NULL; /* Linux 1.x */
|
2013-08-12 09:18:54 +00:00
|
|
|
if (strcmp(name.release, "2.0") == 0 ||
|
|
|
|
strncmp(name.release, "2.0.", 4) == 0 ||
|
|
|
|
strcmp(name.release, "2.1") == 0 ||
|
|
|
|
strncmp(name.release, "2.1.", 4) == 0)
|
2013-08-12 08:28:34 +00:00
|
|
|
return NULL; /* Linux 2.0.x or 2.1.x */
|
2015-07-11 16:06:22 +00:00
|
|
|
if ((r = readlink("/proc/self/exe", executable_path, PATH_MAX)) == -1)
|
2013-08-12 08:28:34 +00:00
|
|
|
return NULL;
|
2015-07-11 16:06:22 +00:00
|
|
|
executable_path[r] = '\0';
|
2013-08-12 08:28:34 +00:00
|
|
|
return executable_path;
|
|
|
|
#elif defined(__FreeBSD__) && defined(KERN_PROC_PATHNAME)
|
2013-08-13 23:37:32 +00:00
|
|
|
/*
|
|
|
|
* In older versions of FreeBSD's dynamic linker, dladdr(main)
|
|
|
|
* supplies a path based on argv[0], so we use the KERN_PROC_PATHNAME
|
|
|
|
* sysctl instead; there are, I think, versions of FreeBSD
|
|
|
|
* that support the sysctl that have and those older versions
|
|
|
|
* of the dynamic linker, and this will get a better answer on
|
|
|
|
* those versions.
|
|
|
|
*/
|
2013-08-12 08:28:34 +00:00
|
|
|
int mib[4];
|
2013-09-03 17:54:23 +00:00
|
|
|
char *executable_path;
|
2013-08-12 08:28:34 +00:00
|
|
|
size_t path_buf_size;
|
|
|
|
|
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_PROC;
|
|
|
|
mib[2] = KERN_PROC_PATHNAME;
|
|
|
|
mib[3] = -1;
|
|
|
|
path_buf_size = PATH_MAX;
|
|
|
|
executable_path = (char *)g_malloc(path_buf_size);
|
|
|
|
if (sysctl(mib, 4, executable_path, &path_buf_size, NULL, 0) == -1) {
|
|
|
|
if (errno != ENOMEM)
|
|
|
|
return NULL;
|
|
|
|
executable_path = (char *)g_realloc(executable_path, path_buf_size);
|
|
|
|
if (sysctl(mib, 4, executable_path, &path_buf_size, NULL, 0) == -1)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return executable_path;
|
2013-08-13 23:37:32 +00:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
/*
|
|
|
|
* In all versions of NetBSD's dynamic linker as of 2013-08-12,
|
|
|
|
* dladdr(main) supplies a path based on argv[0], so we use
|
|
|
|
* /proc/curproc/exe instead.
|
|
|
|
*
|
|
|
|
* XXX - are there OS versions that support "exe" but not "curproc"
|
|
|
|
* or "self"? Are there any that support "self" but not "curproc"?
|
|
|
|
*/
|
2015-07-11 16:06:22 +00:00
|
|
|
static char executable_path[PATH_MAX + 1];
|
|
|
|
ssize_t r;
|
2013-08-13 23:37:32 +00:00
|
|
|
|
2015-07-11 16:06:22 +00:00
|
|
|
if ((r = readlink("/proc/curproc/exe", executable_path, PATH_MAX)) == -1)
|
2013-08-13 23:37:32 +00:00
|
|
|
return NULL;
|
2015-07-11 16:06:22 +00:00
|
|
|
executable_path[r] = '\0';
|
2013-08-13 23:37:32 +00:00
|
|
|
return executable_path;
|
|
|
|
#elif defined(__DragonFly__)
|
|
|
|
/*
|
|
|
|
* In older versions of DragonFly BSD's dynamic linker, dladdr(main)
|
|
|
|
* supplies a path based on argv[0], so we use /proc/curproc/file
|
|
|
|
* instead; it appears to be supported by all versions of DragonFly
|
|
|
|
* BSD.
|
|
|
|
*/
|
2015-07-11 16:06:22 +00:00
|
|
|
static char executable_path[PATH_MAX + 1];
|
|
|
|
ssize_t r;
|
2013-08-13 23:37:32 +00:00
|
|
|
|
2015-07-11 16:06:22 +00:00
|
|
|
if ((r = readlink("/proc/curproc/file", executable_path, PATH_MAX)) == -1)
|
2013-08-13 23:37:32 +00:00
|
|
|
return NULL;
|
2015-07-11 16:06:22 +00:00
|
|
|
executable_path[r] = '\0';
|
2013-08-13 23:37:32 +00:00
|
|
|
return executable_path;
|
2018-05-05 06:39:46 +00:00
|
|
|
#elif defined(HAVE_GETEXECNAME)
|
2013-08-13 23:37:32 +00:00
|
|
|
/*
|
2018-05-05 06:39:46 +00:00
|
|
|
* Solaris, with getexecname().
|
2013-08-13 23:37:32 +00:00
|
|
|
* It appears that getexecname() dates back to at least Solaris 8,
|
2013-08-14 00:37:14 +00:00
|
|
|
* but /proc/{pid}/path is first documented in the Solaris 10 documentation,
|
2013-08-13 23:37:32 +00:00
|
|
|
* so we use getexecname() if available, rather than /proc/self/path/a.out
|
|
|
|
* (which isn't documented, but appears to be a symlink to the
|
|
|
|
* executable image file).
|
|
|
|
*/
|
2013-08-12 08:28:34 +00:00
|
|
|
return getexecname();
|
2018-05-05 06:39:46 +00:00
|
|
|
#elif defined(HAVE_DLGET)
|
|
|
|
/*
|
|
|
|
* HP-UX 11, with dlget(); use dlget() and dlgetname().
|
|
|
|
* See
|
|
|
|
*
|
|
|
|
* https://web.archive.org/web/20081025174755/http://h21007.www2.hp.com/portal/site/dspp/menuitem.863c3e4cbcdc3f3515b49c108973a801?ciid=88086d6e1de021106d6e1de02110275d6e10RCRD#two
|
|
|
|
*/
|
|
|
|
struct load_module_desc desc;
|
|
|
|
|
|
|
|
if (dlget(-2, &desc, sizeof(desc)) != NULL)
|
|
|
|
return dlgetname(&desc, sizeof(desc), NULL, NULL, NULL);
|
|
|
|
else
|
|
|
|
return NULL;
|
2013-08-12 08:28:34 +00:00
|
|
|
#else
|
|
|
|
/* Fill in your favorite UN*X's code here, if there is something */
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
On Windows, use the directory in which the binary resides as the
directory in which global data files are stored. If an installed binary
is being run, that's the correct directory for them; if a build-tree
binary is being run, the "manuf" file will be there, and you can put
other data files there as well, if necessary.
Do the same with plugins, except that, if there's no
"plugins\\{version}" subdirectory of that directory, fall back on the
default installation directory, so you at least have a place where you
can put plugins for use by build-tree binaries. (Should we, instead,
have the Windows build procedure create a subdirectory of the "plugins"
source directory, with the plugin version number as its name, and copy
the plugins there, so you'd use the build-tree plugin binaries?)
Move "test_for_directory()" out of "util.c" and into
"epan/filesystem.c", with the other file system access portability
wrappers and convenience routines. Fix "util.h" not to declare it - or
other routines moved to "epan/filesystem.c" a while ago.
svn path=/trunk/; revision=3858
2001-08-21 06:39:18 +00:00
|
|
|
/*
|
Add a routine to attempt to get the absolute pathname of the executable
file, strip off the last component to get the pathname of the directory
containing the executable file, and save it for future use. On Windows,
you can get that from the OS, but, on UN*X, you have to look at argv[0]
and derive the absolute path from that (argv[0] is not guaranteed to be
an absolute path, or even a path at all). (In addition, if you're
running from the build directory, you might have to strip off a ".libs/"
added to argv[0] as an artifact of the libtoolizing script.)
Use that in the About dialog, and use it to construct the path of
dumpcap.
Don't put quotes into the path of dumpcap; you don't have to quote
strings with spaces in them when handing them to execvp and, in fact,
you *mustn't* quote them, as the quotes will be treated as part of the
pathname.
svn path=/trunk/; revision=17267
2006-02-12 03:15:29 +00:00
|
|
|
* Get the pathname of the directory from which the executable came,
|
2006-05-01 06:51:14 +00:00
|
|
|
* and save it for future use. Returns NULL on success, and a
|
|
|
|
* g_mallocated string containing an error on failure.
|
Add a routine to attempt to get the absolute pathname of the executable
file, strip off the last component to get the pathname of the directory
containing the executable file, and save it for future use. On Windows,
you can get that from the OS, but, on UN*X, you have to look at argv[0]
and derive the absolute path from that (argv[0] is not guaranteed to be
an absolute path, or even a path at all). (In addition, if you're
running from the build directory, you might have to strip off a ".libs/"
added to argv[0] as an artifact of the libtoolizing script.)
Use that in the About dialog, and use it to construct the path of
dumpcap.
Don't put quotes into the path of dumpcap; you don't have to quote
strings with spaces in them when handing them to execvp and, in fact,
you *mustn't* quote them, as the quotes will be treated as part of the
pathname.
svn path=/trunk/; revision=17267
2006-02-12 03:15:29 +00:00
|
|
|
*/
|
2006-05-01 06:51:14 +00:00
|
|
|
char *
|
2019-09-15 09:25:18 +00:00
|
|
|
init_progfile_dir(
|
Add a routine to attempt to get the absolute pathname of the executable
file, strip off the last component to get the pathname of the directory
containing the executable file, and save it for future use. On Windows,
you can get that from the OS, but, on UN*X, you have to look at argv[0]
and derive the absolute path from that (argv[0] is not guaranteed to be
an absolute path, or even a path at all). (In addition, if you're
running from the build directory, you might have to strip off a ".libs/"
added to argv[0] as an artifact of the libtoolizing script.)
Use that in the About dialog, and use it to construct the path of
dumpcap.
Don't put quotes into the path of dumpcap; you don't have to quote
strings with spaces in them when handing them to execvp and, in fact,
you *mustn't* quote them, as the quotes will be treated as part of the
pathname.
svn path=/trunk/; revision=17267
2006-02-12 03:15:29 +00:00
|
|
|
#ifdef _WIN32
|
2019-09-15 09:25:18 +00:00
|
|
|
const char* arg0 _U_
|
|
|
|
#else
|
|
|
|
const char* arg0
|
Add a routine to attempt to get the absolute pathname of the executable
file, strip off the last component to get the pathname of the directory
containing the executable file, and save it for future use. On Windows,
you can get that from the OS, but, on UN*X, you have to look at argv[0]
and derive the absolute path from that (argv[0] is not guaranteed to be
an absolute path, or even a path at all). (In addition, if you're
running from the build directory, you might have to strip off a ".libs/"
added to argv[0] as an artifact of the libtoolizing script.)
Use that in the About dialog, and use it to construct the path of
dumpcap.
Don't put quotes into the path of dumpcap; you don't have to quote
strings with spaces in them when handing them to execvp and, in fact,
you *mustn't* quote them, as the quotes will be treated as part of the
pathname.
svn path=/trunk/; revision=17267
2006-02-12 03:15:29 +00:00
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
2011-09-21 17:14:14 +00:00
|
|
|
TCHAR prog_pathname_w[_MAX_PATH+2];
|
|
|
|
char *prog_pathname;
|
|
|
|
DWORD error;
|
|
|
|
TCHAR *msg_w;
|
|
|
|
guchar *msg;
|
|
|
|
size_t msglen;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attempt to get the full pathname of the currently running
|
|
|
|
* program.
|
|
|
|
*/
|
|
|
|
if (GetModuleFileName(NULL, prog_pathname_w, G_N_ELEMENTS(prog_pathname_w)) != 0 && GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
|
|
|
|
/*
|
2016-03-31 03:38:51 +00:00
|
|
|
* XXX - Should we use g_utf16_to_utf8()?
|
2011-09-21 17:14:14 +00:00
|
|
|
*/
|
|
|
|
prog_pathname = utf_16to8(prog_pathname_w);
|
|
|
|
/*
|
|
|
|
* We got it; strip off the last component, which would be
|
|
|
|
* the file name of the executable, giving us the pathname
|
|
|
|
* of the directory where the executable resides.
|
|
|
|
*/
|
|
|
|
progfile_dir = g_path_get_dirname(prog_pathname);
|
|
|
|
if (progfile_dir != NULL) {
|
|
|
|
return NULL; /* we succeeded */
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* OK, no. What do we do now?
|
|
|
|
*/
|
|
|
|
return g_strdup_printf("No \\ in executable pathname \"%s\"",
|
|
|
|
prog_pathname);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Oh, well. Return an indication of the error.
|
|
|
|
*/
|
|
|
|
error = GetLastError();
|
2012-06-09 03:41:23 +00:00
|
|
|
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
|
2011-09-21 17:14:14 +00:00
|
|
|
NULL, error, 0, (LPTSTR) &msg_w, 0, NULL) == 0) {
|
|
|
|
/*
|
|
|
|
* Gak. We can't format the message.
|
|
|
|
*/
|
|
|
|
return g_strdup_printf("GetModuleFileName failed: %u (FormatMessage failed: %u)",
|
|
|
|
error, GetLastError());
|
|
|
|
}
|
|
|
|
msg = utf_16to8(msg_w);
|
|
|
|
LocalFree(msg_w);
|
|
|
|
/*
|
|
|
|
* "FormatMessage()" "helpfully" sticks CR/LF at the
|
|
|
|
* end of the message. Get rid of it.
|
|
|
|
*/
|
|
|
|
msglen = strlen(msg);
|
|
|
|
if (msglen >= 2) {
|
|
|
|
msg[msglen - 1] = '\0';
|
|
|
|
msg[msglen - 2] = '\0';
|
|
|
|
}
|
|
|
|
return g_strdup_printf("GetModuleFileName failed: %s (%u)",
|
|
|
|
msg, error);
|
|
|
|
}
|
Add a routine to attempt to get the absolute pathname of the executable
file, strip off the last component to get the pathname of the directory
containing the executable file, and save it for future use. On Windows,
you can get that from the OS, but, on UN*X, you have to look at argv[0]
and derive the absolute path from that (argv[0] is not guaranteed to be
an absolute path, or even a path at all). (In addition, if you're
running from the build directory, you might have to strip off a ".libs/"
added to argv[0] as an artifact of the libtoolizing script.)
Use that in the About dialog, and use it to construct the path of
dumpcap.
Don't put quotes into the path of dumpcap; you don't have to quote
strings with spaces in them when handing them to execvp and, in fact,
you *mustn't* quote them, as the quotes will be treated as part of the
pathname.
svn path=/trunk/; revision=17267
2006-02-12 03:15:29 +00:00
|
|
|
#else
|
2013-08-12 08:28:34 +00:00
|
|
|
const char *execname;
|
2011-09-21 17:14:14 +00:00
|
|
|
char *prog_pathname;
|
|
|
|
char *curdir;
|
|
|
|
long path_max;
|
2016-03-31 03:38:51 +00:00
|
|
|
const char *pathstr;
|
|
|
|
const char *path_start, *path_end;
|
2013-11-17 08:49:51 +00:00
|
|
|
size_t path_component_len, path_len;
|
2011-09-21 17:14:14 +00:00
|
|
|
char *retstr;
|
|
|
|
char *path;
|
|
|
|
char *dir_end;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set in the
|
|
|
|
* environment; if so, set running_in_build_directory_flag if we
|
|
|
|
* weren't started with special privileges. (If we were started
|
|
|
|
* with special privileges, it's not safe to allow the user to point
|
|
|
|
* us to some other directory; running_in_build_directory_flag, when
|
|
|
|
* set, causes us to look for plugins and the like in the build
|
|
|
|
* directory.)
|
|
|
|
*/
|
2016-03-31 03:38:51 +00:00
|
|
|
if (g_getenv("WIRESHARK_RUN_FROM_BUILD_DIRECTORY") != NULL
|
2011-09-21 17:14:14 +00:00
|
|
|
&& !started_with_special_privs())
|
|
|
|
running_in_build_directory_flag = TRUE;
|
2007-05-21 20:31:45 +00:00
|
|
|
|
2013-08-12 08:28:34 +00:00
|
|
|
execname = get_executable_path();
|
|
|
|
if (execname == NULL) {
|
|
|
|
/*
|
|
|
|
* OK, guess based on argv[0].
|
|
|
|
*/
|
|
|
|
execname = arg0;
|
|
|
|
}
|
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
/*
|
|
|
|
* Try to figure out the directory in which the currently running
|
|
|
|
* program resides, given something purporting to be the executable
|
2018-05-05 07:19:09 +00:00
|
|
|
* name (from an OS mechanism or from the argv[0] it was started with).
|
2011-09-21 17:14:14 +00:00
|
|
|
* That might be the absolute path of the program, or a path relative
|
|
|
|
* to the current directory of the process that started it, or
|
|
|
|
* just a name for the program if it was started from the command
|
|
|
|
* line and was searched for in $PATH. It's not guaranteed to be
|
|
|
|
* any of those, however, so there are no guarantees....
|
|
|
|
*/
|
2013-08-12 08:28:34 +00:00
|
|
|
if (execname[0] == '/') {
|
2011-09-21 17:14:14 +00:00
|
|
|
/*
|
|
|
|
* It's an absolute path.
|
|
|
|
*/
|
2013-08-12 08:28:34 +00:00
|
|
|
prog_pathname = g_strdup(execname);
|
|
|
|
} else if (strchr(execname, '/') != NULL) {
|
2011-09-21 17:14:14 +00:00
|
|
|
/*
|
|
|
|
* It's a relative path, with a directory in it.
|
|
|
|
* Get the current directory, and combine it
|
|
|
|
* with that directory.
|
|
|
|
*/
|
|
|
|
path_max = pathconf(".", _PC_PATH_MAX);
|
|
|
|
if (path_max == -1) {
|
|
|
|
/*
|
|
|
|
* We have no idea how big a buffer to
|
|
|
|
* allocate for the current directory.
|
|
|
|
*/
|
|
|
|
return g_strdup_printf("pathconf failed: %s\n",
|
|
|
|
g_strerror(errno));
|
|
|
|
}
|
|
|
|
curdir = (char *)g_malloc(path_max);
|
|
|
|
if (getcwd(curdir, path_max) == NULL) {
|
|
|
|
/*
|
|
|
|
* It failed - give up, and just stick
|
2018-12-04 01:46:01 +00:00
|
|
|
* with DATA_DIR.
|
2011-09-21 17:14:14 +00:00
|
|
|
*/
|
|
|
|
g_free(curdir);
|
|
|
|
return g_strdup_printf("getcwd failed: %s\n",
|
|
|
|
g_strerror(errno));
|
|
|
|
}
|
2013-08-12 08:28:34 +00:00
|
|
|
path = g_strdup_printf("%s/%s", curdir, execname);
|
2011-09-21 17:14:14 +00:00
|
|
|
g_free(curdir);
|
|
|
|
prog_pathname = path;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* It's just a file name.
|
|
|
|
* Search the path for a file with that name
|
|
|
|
* that's executable.
|
|
|
|
*/
|
|
|
|
prog_pathname = NULL; /* haven't found it yet */
|
2016-03-31 03:38:51 +00:00
|
|
|
pathstr = g_getenv("PATH");
|
2011-09-21 17:14:14 +00:00
|
|
|
path_start = pathstr;
|
|
|
|
if (path_start != NULL) {
|
|
|
|
while (*path_start != '\0') {
|
|
|
|
path_end = strchr(path_start, ':');
|
|
|
|
if (path_end == NULL)
|
|
|
|
path_end = path_start + strlen(path_start);
|
|
|
|
path_component_len = path_end - path_start;
|
2013-11-17 08:49:51 +00:00
|
|
|
path_len = path_component_len + 1
|
|
|
|
+ strlen(execname) + 1;
|
|
|
|
path = (char *)g_malloc(path_len);
|
2011-09-21 17:14:14 +00:00
|
|
|
memcpy(path, path_start, path_component_len);
|
|
|
|
path[path_component_len] = '\0';
|
2013-11-17 08:49:51 +00:00
|
|
|
g_strlcat(path, "/", path_len);
|
|
|
|
g_strlcat(path, execname, path_len);
|
2011-09-21 17:14:14 +00:00
|
|
|
if (access(path, X_OK) == 0) {
|
|
|
|
/*
|
|
|
|
* Found it!
|
|
|
|
*/
|
|
|
|
prog_pathname = path;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* That's not it. If there are more
|
|
|
|
* path components to test, try them.
|
|
|
|
*/
|
|
|
|
if (*path_end == ':')
|
|
|
|
path_end++;
|
|
|
|
path_start = path_end;
|
|
|
|
g_free(path);
|
|
|
|
}
|
|
|
|
if (prog_pathname == NULL) {
|
|
|
|
/*
|
|
|
|
* Program not found in path.
|
|
|
|
*/
|
|
|
|
return g_strdup_printf("\"%s\" not found in \"%s\"",
|
2013-08-12 08:28:34 +00:00
|
|
|
execname, pathstr);
|
2011-09-21 17:14:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* PATH isn't set.
|
|
|
|
* XXX - should we pick a default?
|
|
|
|
*/
|
|
|
|
return g_strdup("PATH isn't set");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* OK, we have what we think is the pathname
|
|
|
|
* of the program.
|
|
|
|
*
|
|
|
|
* First, find the last "/" in the directory,
|
|
|
|
* as that marks the end of the directory pathname.
|
|
|
|
*/
|
|
|
|
dir_end = strrchr(prog_pathname, '/');
|
|
|
|
if (dir_end != NULL) {
|
|
|
|
/*
|
|
|
|
* Found it. Strip off the last component,
|
|
|
|
* as that's the path of the program.
|
|
|
|
*/
|
|
|
|
*dir_end = '\0';
|
|
|
|
|
|
|
|
/*
|
2018-04-25 03:46:25 +00:00
|
|
|
* Is there a "/run" at the end?
|
2011-09-21 17:14:14 +00:00
|
|
|
*/
|
|
|
|
dir_end = strrchr(prog_pathname, '/');
|
|
|
|
if (dir_end != NULL) {
|
2018-04-25 03:46:25 +00:00
|
|
|
if (!started_with_special_privs()) {
|
2015-02-28 16:44:27 +00:00
|
|
|
/*
|
|
|
|
* Check for the CMake output directory. As people may name
|
|
|
|
* their directories "run" (really?), also check for the
|
|
|
|
* CMakeCache.txt file before assuming a CMake output dir.
|
|
|
|
*/
|
|
|
|
if (strcmp(dir_end, "/run") == 0) {
|
|
|
|
gchar *cmake_file;
|
|
|
|
cmake_file = g_strdup_printf("%.*s/CMakeCache.txt",
|
|
|
|
(int)(dir_end - prog_pathname),
|
|
|
|
prog_pathname);
|
|
|
|
if (file_exists(cmake_file))
|
|
|
|
running_in_build_directory_flag = TRUE;
|
|
|
|
g_free(cmake_file);
|
|
|
|
}
|
2013-08-12 00:59:34 +00:00
|
|
|
#ifdef __APPLE__
|
2018-10-02 17:00:01 +00:00
|
|
|
{
|
2013-08-12 00:59:34 +00:00
|
|
|
/*
|
|
|
|
* Scan up the path looking for a component
|
|
|
|
* named "Contents". If we find it, we assume
|
|
|
|
* we're in a bundle, and that the top-level
|
|
|
|
* directory of the bundle is the one containing
|
|
|
|
* "Contents".
|
2013-08-12 08:28:34 +00:00
|
|
|
*
|
|
|
|
* Not all executables are in the Contents/MacOS
|
|
|
|
* directory, so we can't just check for those
|
|
|
|
* in the path and strip them off.
|
|
|
|
*
|
|
|
|
* XXX - should we assume that it's either
|
|
|
|
* Contents/MacOS or Resources/bin?
|
2013-08-12 00:59:34 +00:00
|
|
|
*/
|
|
|
|
char *component_end, *p;
|
|
|
|
|
|
|
|
component_end = strchr(prog_pathname, '\0');
|
|
|
|
p = component_end;
|
|
|
|
for (;;) {
|
|
|
|
while (p >= prog_pathname && *p != '/')
|
|
|
|
p--;
|
|
|
|
if (p == prog_pathname) {
|
|
|
|
/*
|
|
|
|
* We're looking at the first component of
|
|
|
|
* the pathname now, so we're definitely
|
|
|
|
* not in a bundle, even if we're in
|
|
|
|
* "/Contents".
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (strncmp(p, "/Contents", component_end - p) == 0) {
|
|
|
|
/* Found it. */
|
|
|
|
appbundle_dir = (char *)g_malloc(p - prog_pathname + 1);
|
|
|
|
memcpy(appbundle_dir, prog_pathname, p - prog_pathname);
|
|
|
|
appbundle_dir[p - prog_pathname] = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
component_end = p;
|
|
|
|
p--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2015-02-28 16:44:27 +00:00
|
|
|
}
|
2011-09-21 17:14:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* OK, we have the path we want.
|
|
|
|
*/
|
|
|
|
progfile_dir = prog_pathname;
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* This "shouldn't happen"; we apparently
|
|
|
|
* have no "/" in the pathname.
|
|
|
|
* Just free up prog_pathname.
|
|
|
|
*/
|
|
|
|
retstr = g_strdup_printf("No / found in \"%s\"", prog_pathname);
|
|
|
|
g_free(prog_pathname);
|
|
|
|
return retstr;
|
|
|
|
}
|
Add a routine to attempt to get the absolute pathname of the executable
file, strip off the last component to get the pathname of the directory
containing the executable file, and save it for future use. On Windows,
you can get that from the OS, but, on UN*X, you have to look at argv[0]
and derive the absolute path from that (argv[0] is not guaranteed to be
an absolute path, or even a path at all). (In addition, if you're
running from the build directory, you might have to strip off a ".libs/"
added to argv[0] as an artifact of the libtoolizing script.)
Use that in the About dialog, and use it to construct the path of
dumpcap.
Don't put quotes into the path of dumpcap; you don't have to quote
strings with spaces in them when handing them to execvp and, in fact,
you *mustn't* quote them, as the quotes will be treated as part of the
pathname.
svn path=/trunk/; revision=17267
2006-02-12 03:15:29 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the directory in which the program resides.
|
|
|
|
*/
|
|
|
|
const char *
|
|
|
|
get_progfile_dir(void)
|
|
|
|
{
|
2011-09-21 17:14:14 +00:00
|
|
|
return progfile_dir;
|
Add a routine to attempt to get the absolute pathname of the executable
file, strip off the last component to get the pathname of the directory
containing the executable file, and save it for future use. On Windows,
you can get that from the OS, but, on UN*X, you have to look at argv[0]
and derive the absolute path from that (argv[0] is not guaranteed to be
an absolute path, or even a path at all). (In addition, if you're
running from the build directory, you might have to strip off a ".libs/"
added to argv[0] as an artifact of the libtoolizing script.)
Use that in the About dialog, and use it to construct the path of
dumpcap.
Don't put quotes into the path of dumpcap; you don't have to quote
strings with spaces in them when handing them to execvp and, in fact,
you *mustn't* quote them, as the quotes will be treated as part of the
pathname.
svn path=/trunk/; revision=17267
2006-02-12 03:15:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2019-07-30 08:12:30 +00:00
|
|
|
* Get the directory in which the global configuration and data files are
|
Add a routine to attempt to get the absolute pathname of the executable
file, strip off the last component to get the pathname of the directory
containing the executable file, and save it for future use. On Windows,
you can get that from the OS, but, on UN*X, you have to look at argv[0]
and derive the absolute path from that (argv[0] is not guaranteed to be
an absolute path, or even a path at all). (In addition, if you're
running from the build directory, you might have to strip off a ".libs/"
added to argv[0] as an artifact of the libtoolizing script.)
Use that in the About dialog, and use it to construct the path of
dumpcap.
Don't put quotes into the path of dumpcap; you don't have to quote
strings with spaces in them when handing them to execvp and, in fact,
you *mustn't* quote them, as the quotes will be treated as part of the
pathname.
svn path=/trunk/; revision=17267
2006-02-12 03:15:29 +00:00
|
|
|
* stored.
|
2003-03-26 00:34:27 +00:00
|
|
|
*
|
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
|
|
|
* On Windows, we use the directory in which the executable for this
|
|
|
|
* process resides.
|
|
|
|
*
|
2018-10-02 17:00:01 +00:00
|
|
|
* On macOS (when executed from an app bundle), use a directory within
|
|
|
|
* that app bundle.
|
|
|
|
*
|
|
|
|
* Otherwise, if the program was executed from the build directory, use the
|
|
|
|
* directory in which the executable for this process resides. In all other
|
2018-12-04 01:46:01 +00:00
|
|
|
* cases, use the DATA_DIR value that was set at compile time.
|
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
|
|
|
*
|
2006-05-31 00:23:01 +00:00
|
|
|
* XXX - if we ever make libwireshark a real library, used by multiple
|
2006-05-31 17:38:42 +00:00
|
|
|
* applications (more than just TShark and versions of Wireshark with
|
2003-03-26 00:34:27 +00:00
|
|
|
* various UIs), should the configuration files belong to the library
|
|
|
|
* (and be shared by all those applications) or to the applications?
|
|
|
|
*
|
|
|
|
* If they belong to the library, that could be done on UNIX by the
|
|
|
|
* configure script, but it's trickier on Windows, as you can't just
|
|
|
|
* use the pathname of the executable.
|
|
|
|
*
|
|
|
|
* If they belong to the application, that could be done on Windows
|
|
|
|
* by using the pathname of the executable, but we'd have to have it
|
|
|
|
* passed in as an argument, in some call, on UNIX.
|
|
|
|
*
|
|
|
|
* Note that some of those configuration files might be used by code in
|
2006-05-31 00:23:01 +00:00
|
|
|
* libwireshark, some of them might be used by dissectors (would they
|
|
|
|
* belong to libwireshark, the application, or a separate library?),
|
2006-05-22 08:21:22 +00:00
|
|
|
* and some of them might be used by other code (the Wireshark preferences
|
2003-03-26 00:34:27 +00:00
|
|
|
* file includes resolver preferences that control the behavior of code
|
2006-05-31 00:23:01 +00:00
|
|
|
* in libwireshark, dissector preferences, and UI preferences, for
|
2003-03-26 00:34:27 +00:00
|
|
|
* example).
|
On Windows, use the directory in which the binary resides as the
directory in which global data files are stored. If an installed binary
is being run, that's the correct directory for them; if a build-tree
binary is being run, the "manuf" file will be there, and you can put
other data files there as well, if necessary.
Do the same with plugins, except that, if there's no
"plugins\\{version}" subdirectory of that directory, fall back on the
default installation directory, so you at least have a place where you
can put plugins for use by build-tree binaries. (Should we, instead,
have the Windows build procedure create a subdirectory of the "plugins"
source directory, with the plugin version number as its name, and copy
the plugins there, so you'd use the build-tree plugin binaries?)
Move "test_for_directory()" out of "util.c" and into
"epan/filesystem.c", with the other file system access portability
wrappers and convenience routines. Fix "util.h" not to declare it - or
other routines moved to "epan/filesystem.c" a while ago.
svn path=/trunk/; revision=3858
2001-08-21 06:39:18 +00:00
|
|
|
*/
|
|
|
|
const char *
|
|
|
|
get_datafile_dir(void)
|
|
|
|
{
|
2011-09-21 17:14:14 +00:00
|
|
|
if (datafile_dir != NULL)
|
|
|
|
return datafile_dir;
|
2006-08-26 17:55:21 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2011-09-21 17:14:14 +00:00
|
|
|
/*
|
2016-03-11 17:15:12 +00:00
|
|
|
* Do we have the pathname of the program? If so, assume we're
|
|
|
|
* running an installed version of the program. If we fail,
|
|
|
|
* we don't change "datafile_dir", and thus end up using the
|
|
|
|
* default.
|
|
|
|
*
|
|
|
|
* XXX - does NSIS put the installation directory into
|
|
|
|
* "\HKEY_LOCAL_MACHINE\SOFTWARE\Wireshark\InstallDir"?
|
|
|
|
* If so, perhaps we should read that from the registry,
|
|
|
|
* instead.
|
2011-09-21 17:14:14 +00:00
|
|
|
*/
|
2016-03-11 17:15:12 +00:00
|
|
|
if (progfile_dir != NULL) {
|
2011-09-21 17:14:14 +00:00
|
|
|
/*
|
2016-03-11 17:15:12 +00:00
|
|
|
* Yes, we do; use that.
|
2011-09-21 17:14:14 +00:00
|
|
|
*/
|
2018-12-04 01:34:25 +00:00
|
|
|
datafile_dir = g_strdup(progfile_dir);
|
2011-09-21 17:14:14 +00:00
|
|
|
} else {
|
|
|
|
/*
|
2016-03-11 17:15:12 +00:00
|
|
|
* No, we don't.
|
|
|
|
* Fall back on the default installation directory.
|
2011-09-21 17:14:14 +00:00
|
|
|
*/
|
2018-12-04 01:34:25 +00:00
|
|
|
datafile_dir = g_strdup("C:\\Program Files\\Wireshark\\");
|
2011-09-21 17:14:14 +00:00
|
|
|
}
|
On Windows, use the directory in which the binary resides as the
directory in which global data files are stored. If an installed binary
is being run, that's the correct directory for them; if a build-tree
binary is being run, the "manuf" file will be there, and you can put
other data files there as well, if necessary.
Do the same with plugins, except that, if there's no
"plugins\\{version}" subdirectory of that directory, fall back on the
default installation directory, so you at least have a place where you
can put plugins for use by build-tree binaries. (Should we, instead,
have the Windows build procedure create a subdirectory of the "plugins"
source directory, with the plugin version number as its name, and copy
the plugins there, so you'd use the build-tree plugin binaries?)
Move "test_for_directory()" out of "util.c" and into
"epan/filesystem.c", with the other file system access portability
wrappers and convenience routines. Fix "util.h" not to declare it - or
other routines moved to "epan/filesystem.c" a while ago.
svn path=/trunk/; revision=3858
2001-08-21 06:39:18 +00:00
|
|
|
#else
|
2013-10-29 02:28:16 +00:00
|
|
|
|
2018-10-02 17:00:01 +00:00
|
|
|
if (g_getenv("WIRESHARK_DATA_DIR") && !started_with_special_privs()) {
|
|
|
|
/*
|
|
|
|
* The user specified a different directory for data files
|
|
|
|
* and we aren't running with special privileges.
|
|
|
|
* XXX - We might be able to dispense with the priv check
|
|
|
|
*/
|
|
|
|
datafile_dir = g_strdup(g_getenv("WIRESHARK_DATA_DIR"));
|
|
|
|
}
|
|
|
|
#ifdef __APPLE__
|
|
|
|
/*
|
|
|
|
* If we're running from an app bundle and weren't started
|
|
|
|
* with special privileges, use the Contents/Resources/share/wireshark
|
|
|
|
* subdirectory of the app bundle.
|
|
|
|
*
|
|
|
|
* (appbundle_dir is not set to a non-null value if we're
|
|
|
|
* started with special privileges, so we need only check
|
|
|
|
* it; we don't need to call started_with_special_privs().)
|
|
|
|
*/
|
|
|
|
else if (appbundle_dir != NULL) {
|
|
|
|
datafile_dir = g_strdup_printf("%s/Contents/Resources/share/wireshark",
|
|
|
|
appbundle_dir);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else if (running_in_build_directory_flag && progfile_dir != NULL) {
|
2011-09-21 17:14:14 +00:00
|
|
|
/*
|
|
|
|
* We're (probably) being run from the build directory and
|
|
|
|
* weren't started with special privileges.
|
|
|
|
*
|
2013-10-29 02:28:16 +00:00
|
|
|
* (running_in_build_directory_flag is never set to TRUE
|
|
|
|
* if we're started with special privileges, so we need
|
|
|
|
* only check it; we don't need to call started_with_special_privs().)
|
|
|
|
*
|
2018-05-04 18:45:10 +00:00
|
|
|
* Data files (console.lua, radius/, etc.) are copied to the build
|
2018-10-02 17:00:01 +00:00
|
|
|
* directory during the build which also contains executables. A special
|
|
|
|
* exception is macOS (when built with an app bundle).
|
cmake,wslua,wsutil: load files from run/ instead of source tree
Fixes Lua on macOS, tested with an out-of-tree build:
WS_BIN_PATH=$PWD/run ../wireshark/test/test.sh -s wslua
Previously programs that were ran from the build directory would load
data files (radius/, diameter/, init.lua) from the source directory.
Then in the case of Lua, files were loaded from the program directory
($BUILDDIR/run/init.lua on Linux) or source directory
(sSOURCEDIR/epan/wslua/console.lua).
On macOS, this does not work for Lua since files are installed into
$BUILDDIR/run/Wireshark.app/Contents/Resources/share/wireshark/init.lua
instead. Since CMake always copies data files (radius, console.lua,
etc.) into the build directory, make get_datafile_dir() return this
"run" directory instead.
Change-Id: If97d2f5686271caf9ad4d4e4fc58e902dc592a98
Reviewed-on: https://code.wireshark.org/review/19330
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Graham Bloice <graham.bloice@trihedral.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2016-12-18 15:49:24 +00:00
|
|
|
*/
|
2018-12-04 01:34:25 +00:00
|
|
|
datafile_dir = g_strdup(progfile_dir);
|
2011-09-21 17:14:14 +00:00
|
|
|
} else {
|
2018-12-04 01:46:01 +00:00
|
|
|
datafile_dir = g_strdup(DATA_DIR);
|
2011-09-21 17:14:14 +00:00
|
|
|
}
|
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
|
|
|
|
|
|
|
#endif
|
2011-09-21 17:14:14 +00:00
|
|
|
return datafile_dir;
|
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the directory where the plugins are stored.
|
|
|
|
*
|
2017-08-08 21:04:53 +00:00
|
|
|
* On Windows, we use the plugin\{VERSION} subdirectory of the datafile
|
2016-12-05 03:21:19 +00:00
|
|
|
* directory, where {VERSION} is the version number of this version of
|
|
|
|
* Wireshark.
|
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
|
|
|
*
|
2016-12-05 03:21:19 +00:00
|
|
|
* On UN*X:
|
|
|
|
*
|
|
|
|
* if we appear to be run from the build directory, we use the
|
|
|
|
* "plugin" subdirectory of the datafile directory;
|
|
|
|
*
|
|
|
|
* otherwise, if the WIRESHARK_PLUGIN_DIR environment variable is
|
|
|
|
* set and we aren't running with special privileges, we use the
|
|
|
|
* value of that environment variable;
|
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
|
|
|
*
|
2016-12-05 03:21:19 +00:00
|
|
|
* otherwise, if we're running from an app bundle in macOS, we
|
|
|
|
* use the Contents/PlugIns/wireshark subdirectory of the app bundle;
|
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
|
|
|
*
|
2017-09-12 09:51:46 +00:00
|
|
|
* otherwise, we use the PLUGIN_DIR value supplied by the
|
2016-12-05 03:21:19 +00:00
|
|
|
* configure script.
|
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
|
|
|
*/
|
2016-07-23 02:52:10 +00:00
|
|
|
static char *plugin_dir = NULL;
|
2017-09-18 15:25:20 +00:00
|
|
|
static char *plugin_dir_with_version = NULL;
|
2017-09-10 22:38:36 +00:00
|
|
|
static char *plugin_pers_dir = NULL;
|
2017-09-18 15:25:20 +00:00
|
|
|
static char *plugin_pers_dir_with_version = NULL;
|
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
|
|
|
|
2007-05-25 20:03:26 +00:00
|
|
|
static void
|
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
|
|
|
init_plugin_dir(void)
|
|
|
|
{
|
2017-09-18 15:25:20 +00:00
|
|
|
#if defined(HAVE_PLUGINS) || defined(HAVE_LUA)
|
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
|
|
|
#ifdef _WIN32
|
2011-09-21 17:14:14 +00:00
|
|
|
/*
|
|
|
|
* On Windows, the data file directory is the installation
|
|
|
|
* directory; the plugins are stored under it.
|
|
|
|
*
|
|
|
|
* Assume we're running the installed version of Wireshark;
|
|
|
|
* on Windows, the data file directory is the directory
|
|
|
|
* in which the Wireshark binary resides.
|
|
|
|
*/
|
2017-09-22 18:13:33 +00:00
|
|
|
plugin_dir = g_build_filename(get_datafile_dir(), "plugins", (gchar *)NULL);
|
2015-04-07 18:56:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure that pathname refers to a directory.
|
|
|
|
*/
|
|
|
|
if (test_for_directory(plugin_dir) != EISDIR) {
|
|
|
|
/*
|
|
|
|
* Either it doesn't refer to a directory or it
|
|
|
|
* refers to something that doesn't exist.
|
|
|
|
*
|
|
|
|
* Assume that means we're running a version of
|
|
|
|
* Wireshark we've built in a build directory,
|
|
|
|
* in which case {datafile dir}\plugins is the
|
|
|
|
* top-level plugins source directory, and use
|
|
|
|
* that directory and set the "we're running in
|
|
|
|
* a build directory" flag, so the plugin
|
|
|
|
* scanner will check all subdirectories of that
|
|
|
|
* directory for plugins.
|
|
|
|
*/
|
2016-07-23 02:52:10 +00:00
|
|
|
g_free(plugin_dir);
|
|
|
|
plugin_dir = g_build_filename(get_datafile_dir(), "plugins", (gchar *)NULL);
|
2015-04-07 18:56:36 +00:00
|
|
|
running_in_build_directory_flag = TRUE;
|
|
|
|
}
|
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
|
|
|
#else
|
2011-09-21 17:14:14 +00:00
|
|
|
if (running_in_build_directory_flag) {
|
|
|
|
/*
|
|
|
|
* We're (probably) being run from the build directory and
|
|
|
|
* weren't started with special privileges, so we'll use
|
2013-10-29 02:28:16 +00:00
|
|
|
* the "plugins" subdirectory of the directory where the program
|
|
|
|
* we're running is (that's the build directory).
|
2011-09-21 17:14:14 +00:00
|
|
|
*/
|
2016-07-23 02:52:10 +00:00
|
|
|
plugin_dir = g_build_filename(get_progfile_dir(), "plugins", (gchar *)NULL);
|
2011-09-21 17:14:14 +00:00
|
|
|
} else {
|
2016-03-31 03:38:51 +00:00
|
|
|
if (g_getenv("WIRESHARK_PLUGIN_DIR") && !started_with_special_privs()) {
|
2011-09-21 17:14:14 +00:00
|
|
|
/*
|
|
|
|
* The user specified a different directory for plugins
|
|
|
|
* and we aren't running with special privileges.
|
|
|
|
*/
|
2016-03-31 03:38:51 +00:00
|
|
|
plugin_dir = g_strdup(g_getenv("WIRESHARK_PLUGIN_DIR"));
|
2013-08-12 00:59:34 +00:00
|
|
|
}
|
|
|
|
#ifdef __APPLE__
|
|
|
|
/*
|
|
|
|
* If we're running from an app bundle and weren't started
|
2014-03-19 18:40:53 +00:00
|
|
|
* with special privileges, use the Contents/PlugIns/wireshark
|
2013-08-12 00:59:34 +00:00
|
|
|
* subdirectory of the app bundle.
|
|
|
|
*
|
|
|
|
* (appbundle_dir is not set to a non-null value if we're
|
|
|
|
* started with special privileges, so we need only check
|
|
|
|
* it; we don't need to call started_with_special_privs().)
|
|
|
|
*/
|
|
|
|
else if (appbundle_dir != NULL) {
|
2016-07-23 02:52:10 +00:00
|
|
|
plugin_dir = g_build_filename(appbundle_dir, "Contents/PlugIns/wireshark", (gchar *)NULL);
|
2013-08-12 00:59:34 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else {
|
2017-09-12 09:51:46 +00:00
|
|
|
plugin_dir = g_strdup(PLUGIN_DIR);
|
2011-09-21 17:14:14 +00:00
|
|
|
}
|
|
|
|
}
|
On Windows, use the directory in which the binary resides as the
directory in which global data files are stored. If an installed binary
is being run, that's the correct directory for them; if a build-tree
binary is being run, the "manuf" file will be there, and you can put
other data files there as well, if necessary.
Do the same with plugins, except that, if there's no
"plugins\\{version}" subdirectory of that directory, fall back on the
default installation directory, so you at least have a place where you
can put plugins for use by build-tree binaries. (Should we, instead,
have the Windows build procedure create a subdirectory of the "plugins"
source directory, with the plugin version number as its name, and copy
the plugins there, so you'd use the build-tree plugin binaries?)
Move "test_for_directory()" out of "util.c" and into
"epan/filesystem.c", with the other file system access portability
wrappers and convenience routines. Fix "util.h" not to declare it - or
other routines moved to "epan/filesystem.c" a while ago.
svn path=/trunk/; revision=3858
2001-08-21 06:39:18 +00:00
|
|
|
#endif
|
2017-09-18 15:25:20 +00:00
|
|
|
#endif /* defined(HAVE_PLUGINS) || defined(HAVE_LUA) */
|
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
|
|
|
}
|
|
|
|
|
2017-09-10 22:38:36 +00:00
|
|
|
static void
|
|
|
|
init_plugin_pers_dir(void)
|
|
|
|
{
|
2017-09-18 15:25:20 +00:00
|
|
|
#if defined(HAVE_PLUGINS) || defined(HAVE_LUA)
|
2017-09-11 01:20:03 +00:00
|
|
|
#ifdef _WIN32
|
2017-09-10 22:38:36 +00:00
|
|
|
plugin_pers_dir = get_persconffile_path(PLUGINS_DIR_NAME, FALSE);
|
2017-09-11 01:20:03 +00:00
|
|
|
#else
|
|
|
|
plugin_pers_dir = g_build_filename(g_get_home_dir(), ".local/lib/wireshark/" PLUGINS_DIR_NAME, (gchar *)NULL);
|
|
|
|
#endif
|
2017-09-18 15:25:20 +00:00
|
|
|
#endif /* defined(HAVE_PLUGINS) || defined(HAVE_LUA) */
|
2017-09-10 22:38:36 +00:00
|
|
|
}
|
|
|
|
|
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
|
|
|
/*
|
|
|
|
* Get the directory in which the plugins are stored.
|
|
|
|
*/
|
|
|
|
const char *
|
2017-09-18 14:45:17 +00:00
|
|
|
get_plugins_dir(void)
|
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
|
|
|
{
|
2017-09-18 15:25:20 +00:00
|
|
|
if (!plugin_dir)
|
|
|
|
init_plugin_dir();
|
2011-09-21 17:14:14 +00:00
|
|
|
return plugin_dir;
|
2017-09-18 15:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
get_plugins_dir_with_version(void)
|
|
|
|
{
|
|
|
|
if (!plugin_dir)
|
|
|
|
init_plugin_dir();
|
|
|
|
if (plugin_dir && !plugin_dir_with_version)
|
2019-02-13 19:08:19 +00:00
|
|
|
plugin_dir_with_version = g_build_filename(plugin_dir, PLUGIN_PATH_ID, (gchar *)NULL);
|
2017-09-18 15:25:20 +00:00
|
|
|
return plugin_dir_with_version;
|
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
|
|
|
}
|
|
|
|
|
2017-09-10 22:38:36 +00:00
|
|
|
/* Get the personal plugin dir */
|
|
|
|
const char *
|
|
|
|
get_plugins_pers_dir(void)
|
|
|
|
{
|
|
|
|
if (!plugin_pers_dir)
|
|
|
|
init_plugin_pers_dir();
|
|
|
|
return plugin_pers_dir;
|
2017-09-18 15:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
get_plugins_pers_dir_with_version(void)
|
|
|
|
{
|
|
|
|
if (!plugin_pers_dir)
|
|
|
|
init_plugin_pers_dir();
|
|
|
|
if (plugin_pers_dir && !plugin_pers_dir_with_version)
|
2019-02-13 19:08:19 +00:00
|
|
|
plugin_pers_dir_with_version = g_build_filename(plugin_pers_dir, PLUGIN_PATH_ID, (gchar *)NULL);
|
2017-09-18 15:25:20 +00:00
|
|
|
return plugin_pers_dir_with_version;
|
2017-09-10 22:38:36 +00:00
|
|
|
}
|
|
|
|
|
2014-02-25 13:05:11 +00:00
|
|
|
/*
|
|
|
|
* Find the directory where the extcap hooks are stored.
|
|
|
|
*
|
2019-04-19 00:51:03 +00:00
|
|
|
* If the WIRESHARK_EXTCAP_DIR environment variable is set and we are not
|
|
|
|
* running with special privileges, use that. Otherwise:
|
|
|
|
*
|
2014-02-25 13:05:11 +00:00
|
|
|
* On Windows, we use the "extcap" subdirectory of the datafile directory.
|
|
|
|
*
|
2019-04-19 00:51:03 +00:00
|
|
|
* On UN*X:
|
|
|
|
*
|
|
|
|
* if we appear to be run from the build directory, we use the
|
|
|
|
* "extcap" subdirectory of the build directory.
|
2014-02-25 13:05:11 +00:00
|
|
|
*
|
2019-04-19 00:51:03 +00:00
|
|
|
* otherwise, if we're running from an app bundle in macOS, we
|
|
|
|
* use the Contents/MacOS/extcap subdirectory of the app bundle;
|
2014-02-25 13:05:11 +00:00
|
|
|
*
|
2019-04-19 00:51:03 +00:00
|
|
|
* otherwise, we use the EXTCAP_DIR value supplied by CMake.
|
2014-02-25 13:05:11 +00:00
|
|
|
*/
|
2016-07-23 02:52:10 +00:00
|
|
|
static char *extcap_dir = NULL;
|
2014-02-25 13:05:11 +00:00
|
|
|
|
|
|
|
static void init_extcap_dir(void) {
|
2019-04-19 00:51:03 +00:00
|
|
|
if (g_getenv("WIRESHARK_EXTCAP_DIR") && !started_with_special_privs()) {
|
|
|
|
/*
|
|
|
|
* The user specified a different directory for extcap hooks
|
|
|
|
* and we aren't running with special privileges.
|
|
|
|
*/
|
|
|
|
extcap_dir = g_strdup(g_getenv("WIRESHARK_EXTCAP_DIR"));
|
|
|
|
}
|
2014-02-25 13:05:11 +00:00
|
|
|
#ifdef _WIN32
|
2019-04-19 00:51:03 +00:00
|
|
|
else {
|
2015-03-24 22:04:57 +00:00
|
|
|
/*
|
2019-04-19 00:51:03 +00:00
|
|
|
* On Windows, the data file directory is the installation
|
|
|
|
* directory; the extcap hooks are stored under it.
|
|
|
|
*
|
|
|
|
* Assume we're running the installed version of Wireshark;
|
|
|
|
* on Windows, the data file directory is the directory
|
|
|
|
* in which the Wireshark binary resides.
|
2015-03-24 22:04:57 +00:00
|
|
|
*/
|
2016-07-23 02:52:10 +00:00
|
|
|
extcap_dir = g_build_filename(get_datafile_dir(), "extcap", (gchar *)NULL);
|
2015-03-24 22:04:57 +00:00
|
|
|
}
|
2014-02-25 13:05:11 +00:00
|
|
|
#else
|
2019-04-19 00:51:03 +00:00
|
|
|
else if (running_in_build_directory_flag) {
|
2014-10-06 02:14:57 +00:00
|
|
|
/*
|
|
|
|
* We're (probably) being run from the build directory and
|
|
|
|
* weren't started with special privileges, so we'll use
|
|
|
|
* the "extcap hooks" subdirectory of the directory where the program
|
|
|
|
* we're running is (that's the build directory).
|
|
|
|
*/
|
2016-07-23 02:52:10 +00:00
|
|
|
extcap_dir = g_build_filename(get_progfile_dir(), "extcap", (gchar *)NULL);
|
2019-04-19 00:51:03 +00:00
|
|
|
}
|
2014-02-25 13:05:11 +00:00
|
|
|
#ifdef __APPLE__
|
2019-04-19 00:51:03 +00:00
|
|
|
else if (appbundle_dir != NULL) {
|
2014-10-06 02:14:57 +00:00
|
|
|
/*
|
|
|
|
* If we're running from an app bundle and weren't started
|
2015-04-16 18:38:04 +00:00
|
|
|
* with special privileges, use the Contents/MacOS/extcap
|
2014-10-06 02:14:57 +00:00
|
|
|
* subdirectory of the app bundle.
|
|
|
|
*
|
|
|
|
* (appbundle_dir is not set to a non-null value if we're
|
|
|
|
* started with special privileges, so we need only check
|
|
|
|
* it; we don't need to call started_with_special_privs().)
|
|
|
|
*/
|
2019-04-19 00:51:03 +00:00
|
|
|
extcap_dir = g_build_filename(appbundle_dir, "Contents/MacOS/extcap", (gchar *)NULL);
|
|
|
|
}
|
2014-02-25 13:05:11 +00:00
|
|
|
#endif
|
2019-04-19 00:51:03 +00:00
|
|
|
else {
|
|
|
|
extcap_dir = g_strdup(EXTCAP_DIR);
|
2014-10-06 02:14:57 +00:00
|
|
|
}
|
2014-02-25 13:05:11 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the directory in which the extcap hooks are stored.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
const char *
|
2018-01-06 20:39:26 +00:00
|
|
|
get_extcap_dir(void)
|
|
|
|
{
|
2014-10-06 02:14:57 +00:00
|
|
|
if (!extcap_dir)
|
|
|
|
init_extcap_dir();
|
|
|
|
return extcap_dir;
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
|
|
|
/*
|
|
|
|
* Get the flag indicating whether we're running from a build
|
|
|
|
* directory.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
running_in_build_directory(void)
|
|
|
|
{
|
2011-09-21 17:14:14 +00:00
|
|
|
return running_in_build_directory_flag;
|
On Windows, use the directory in which the binary resides as the
directory in which global data files are stored. If an installed binary
is being run, that's the correct directory for them; if a build-tree
binary is being run, the "manuf" file will be there, and you can put
other data files there as well, if necessary.
Do the same with plugins, except that, if there's no
"plugins\\{version}" subdirectory of that directory, fall back on the
default installation directory, so you at least have a place where you
can put plugins for use by build-tree binaries. (Should we, instead,
have the Windows build procedure create a subdirectory of the "plugins"
source directory, with the plugin version number as its name, and copy
the plugins there, so you'd use the build-tree plugin binaries?)
Move "test_for_directory()" out of "util.c" and into
"epan/filesystem.c", with the other file system access portability
wrappers and convenience routines. Fix "util.h" not to declare it - or
other routines moved to "epan/filesystem.c" a while ago.
svn path=/trunk/; revision=3858
2001-08-21 06:39:18 +00:00
|
|
|
}
|
|
|
|
|
2001-10-21 21:48:00 +00:00
|
|
|
/*
|
|
|
|
* Get the directory in which files that, at least on UNIX, are
|
|
|
|
* system files (such as "/etc/ethers") are stored; on Windows,
|
2019-07-30 08:12:30 +00:00
|
|
|
* there's no "/etc" directory, so we get them from the global
|
Add a routine to attempt to get the absolute pathname of the executable
file, strip off the last component to get the pathname of the directory
containing the executable file, and save it for future use. On Windows,
you can get that from the OS, but, on UN*X, you have to look at argv[0]
and derive the absolute path from that (argv[0] is not guaranteed to be
an absolute path, or even a path at all). (In addition, if you're
running from the build directory, you might have to strip off a ".libs/"
added to argv[0] as an artifact of the libtoolizing script.)
Use that in the About dialog, and use it to construct the path of
dumpcap.
Don't put quotes into the path of dumpcap; you don't have to quote
strings with spaces in them when handing them to execvp and, in fact,
you *mustn't* quote them, as the quotes will be treated as part of the
pathname.
svn path=/trunk/; revision=17267
2006-02-12 03:15:29 +00:00
|
|
|
* configuration and data file directory.
|
2001-10-21 21:48:00 +00:00
|
|
|
*/
|
|
|
|
const char *
|
|
|
|
get_systemfile_dir(void)
|
|
|
|
{
|
2004-09-11 23:03:36 +00:00
|
|
|
#ifdef _WIN32
|
2011-09-21 17:14:14 +00:00
|
|
|
return get_datafile_dir();
|
2001-10-21 21:48:00 +00:00
|
|
|
#else
|
2011-09-21 17:14:14 +00:00
|
|
|
return "/etc";
|
2001-10-21 21:48:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-01-15 19:39:31 +00:00
|
|
|
void
|
2008-01-14 16:40:23 +00:00
|
|
|
set_profile_name(const gchar *profilename)
|
|
|
|
{
|
2011-09-21 17:14:14 +00:00
|
|
|
g_free (persconfprofile);
|
|
|
|
|
|
|
|
if (profilename && strlen(profilename) > 0 &&
|
|
|
|
strcmp(profilename, DEFAULT_PROFILE) != 0) {
|
|
|
|
persconfprofile = g_strdup (profilename);
|
|
|
|
} else {
|
|
|
|
/* Default Profile */
|
|
|
|
persconfprofile = NULL;
|
|
|
|
}
|
2008-01-14 16:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
get_profile_name(void)
|
|
|
|
{
|
2011-09-21 17:14:14 +00:00
|
|
|
if (persconfprofile) {
|
|
|
|
return persconfprofile;
|
|
|
|
} else {
|
|
|
|
return DEFAULT_PROFILE;
|
|
|
|
}
|
2008-01-14 16:40:23 +00:00
|
|
|
}
|
|
|
|
|
2010-10-01 16:29:37 +00:00
|
|
|
gboolean
|
|
|
|
is_default_profile(void)
|
|
|
|
{
|
2011-09-21 17:14:14 +00:00
|
|
|
return (!persconfprofile || strcmp(persconfprofile, DEFAULT_PROFILE) == 0) ? TRUE : FALSE;
|
2010-10-01 16:29:37 +00:00
|
|
|
}
|
|
|
|
|
2011-02-26 17:23:24 +00:00
|
|
|
gboolean
|
2019-07-30 08:12:30 +00:00
|
|
|
has_global_profiles(void)
|
2011-02-26 17:23:24 +00:00
|
|
|
{
|
2011-09-21 17:14:14 +00:00
|
|
|
WS_DIR *dir;
|
|
|
|
WS_DIRENT *file;
|
2019-07-30 08:12:30 +00:00
|
|
|
gchar *global_dir = get_global_profiles_dir();
|
2011-09-21 17:14:14 +00:00
|
|
|
gchar *filename;
|
2019-07-30 08:12:30 +00:00
|
|
|
gboolean has_global = FALSE;
|
2011-09-21 17:14:14 +00:00
|
|
|
|
2019-07-30 08:12:30 +00:00
|
|
|
if ((test_for_directory(global_dir) == EISDIR) &&
|
|
|
|
((dir = ws_dir_open(global_dir, 0, NULL)) != NULL))
|
2011-02-26 17:23:24 +00:00
|
|
|
{
|
2011-09-21 17:14:14 +00:00
|
|
|
while ((file = ws_dir_read_name(dir)) != NULL) {
|
2019-07-30 08:12:30 +00:00
|
|
|
filename = g_strdup_printf ("%s%s%s", global_dir, G_DIR_SEPARATOR_S,
|
2011-09-21 17:14:14 +00:00
|
|
|
ws_dir_get_name(file));
|
|
|
|
if (test_for_directory(filename) == EISDIR) {
|
2019-07-30 08:12:30 +00:00
|
|
|
has_global = TRUE;
|
2011-09-21 17:14:14 +00:00
|
|
|
g_free (filename);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
ws_dir_close(dir);
|
|
|
|
}
|
2019-07-30 08:12:30 +00:00
|
|
|
g_free(global_dir);
|
|
|
|
return has_global;
|
2011-02-26 17:23:24 +00:00
|
|
|
}
|
|
|
|
|
2009-12-21 12:32:31 +00:00
|
|
|
void
|
|
|
|
profile_store_persconffiles(gboolean store)
|
|
|
|
{
|
2011-09-21 17:14:14 +00:00
|
|
|
if (store) {
|
|
|
|
profile_files = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
}
|
|
|
|
do_store_persconffiles = store;
|
2009-12-21 12:32:31 +00:00
|
|
|
}
|
|
|
|
|
2001-10-22 23:16:01 +00:00
|
|
|
/*
|
2015-10-18 22:02:52 +00:00
|
|
|
* Get the directory in which personal configuration files reside.
|
|
|
|
*
|
|
|
|
* On Windows, it's "Wireshark", under %APPDATA% or, if %APPDATA% isn't set,
|
|
|
|
* it's "%USERPROFILE%\Application Data" (which is what %APPDATA% normally
|
|
|
|
* is on Windows 2000).
|
|
|
|
*
|
|
|
|
* On UNIX-compatible systems, we first look in XDG_CONFIG_HOME/wireshark
|
|
|
|
* and, if that doesn't exist, ~/.wireshark, for backwards compatibility.
|
|
|
|
* If neither exists, we use XDG_CONFIG_HOME/wireshark, so that the directory
|
|
|
|
* is initially created as XDG_CONFIG_HOME/wireshark. We use that regardless
|
|
|
|
* of whether the user is running under an XDG desktop or not, so that
|
|
|
|
* if the user's home directory is on a server and shared between
|
|
|
|
* different desktop environments on different machines, they can all
|
|
|
|
* share the same configuration file directory.
|
|
|
|
*
|
|
|
|
* XXX - what about stuff that shouldn't be shared between machines,
|
|
|
|
* such as plugins in the form of shared loadable images?
|
2001-10-22 23:16:01 +00:00
|
|
|
*/
|
2001-10-24 07:18:39 +00:00
|
|
|
static const char *
|
2008-01-14 16:40:23 +00:00
|
|
|
get_persconffile_dir_no_profile(void)
|
2000-09-28 03:16:29 +00:00
|
|
|
{
|
2015-10-18 22:02:52 +00:00
|
|
|
const char *env;
|
2000-09-28 03:16:29 +00:00
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
/* Return the cached value, if available */
|
|
|
|
if (persconffile_dir != NULL)
|
|
|
|
return persconffile_dir;
|
2001-10-22 23:16:01 +00:00
|
|
|
|
2013-09-13 20:15:46 +00:00
|
|
|
/*
|
|
|
|
* See if the user has selected an alternate environment.
|
|
|
|
*/
|
2018-06-01 14:18:22 +00:00
|
|
|
env = g_getenv(ENV_CONFIG_PATH_VAR);
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (env == NULL) {
|
|
|
|
/* for backward compatibility */
|
|
|
|
env = g_getenv("WIRESHARK_APPDATA");
|
|
|
|
}
|
|
|
|
#endif
|
2015-10-18 22:02:52 +00:00
|
|
|
if (env != NULL) {
|
|
|
|
persconffile_dir = g_strdup(env);
|
2013-09-13 20:15:46 +00:00
|
|
|
return persconffile_dir;
|
|
|
|
}
|
|
|
|
|
2018-06-01 14:18:22 +00:00
|
|
|
#ifdef _WIN32
|
2015-10-18 22:02:52 +00:00
|
|
|
/*
|
|
|
|
* Use %APPDATA% or %USERPROFILE%, so that configuration
|
|
|
|
* files are stored in the user profile, rather than in
|
|
|
|
* the home directory. The Windows convention is to store
|
|
|
|
* configuration information in the user profile, and doing
|
|
|
|
* so means you can use Wireshark even if the home directory
|
|
|
|
* is an inaccessible network drive.
|
|
|
|
*/
|
2016-03-31 03:38:51 +00:00
|
|
|
env = g_getenv("APPDATA");
|
2015-10-18 22:02:52 +00:00
|
|
|
if (env != NULL) {
|
2011-09-21 17:14:14 +00:00
|
|
|
/*
|
2015-10-18 22:02:52 +00:00
|
|
|
* Concatenate %APPDATA% with "\Wireshark".
|
2011-09-21 17:14:14 +00:00
|
|
|
*/
|
2015-10-18 22:02:52 +00:00
|
|
|
persconffile_dir = g_build_filename(env, "Wireshark", NULL);
|
|
|
|
return persconffile_dir;
|
2011-09-21 17:14:14 +00:00
|
|
|
}
|
2015-10-18 22:02:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* OK, %APPDATA% wasn't set, so use %USERPROFILE%\Application Data.
|
|
|
|
*/
|
2016-03-31 03:38:51 +00:00
|
|
|
env = g_getenv("USERPROFILE");
|
2015-10-18 22:02:52 +00:00
|
|
|
if (env != NULL) {
|
|
|
|
persconffile_dir = g_build_filename(env, "Application Data", "Wireshark", NULL);
|
|
|
|
return persconffile_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Give up and use "C:".
|
|
|
|
*/
|
|
|
|
persconffile_dir = g_build_filename("C:", "Wireshark", NULL);
|
|
|
|
return persconffile_dir;
|
2000-09-28 03:16:29 +00:00
|
|
|
#else
|
2018-06-01 14:18:22 +00:00
|
|
|
char *xdg_path, *path;
|
|
|
|
struct passwd *pwd;
|
|
|
|
const char *homedir;
|
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
/*
|
2015-10-18 22:02:52 +00:00
|
|
|
* Check if XDG_CONFIG_HOME/wireshark exists and is a directory.
|
|
|
|
*/
|
|
|
|
xdg_path = g_build_filename(g_get_user_config_dir(), "wireshark", NULL);
|
|
|
|
if (g_file_test(xdg_path, G_FILE_TEST_IS_DIR)) {
|
|
|
|
persconffile_dir = xdg_path;
|
|
|
|
return persconffile_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It doesn't exist, or it does but isn't a directory, so try
|
|
|
|
* ~/.wireshark.
|
|
|
|
*
|
|
|
|
* If $HOME is set, use that for ~.
|
|
|
|
*
|
|
|
|
* (Note: before GLib 2.36, g_get_home_dir() didn't look at $HOME,
|
|
|
|
* but we always want to do so, so we don't use g_get_home_dir().)
|
2011-09-21 17:14:14 +00:00
|
|
|
*/
|
2016-03-31 03:38:51 +00:00
|
|
|
homedir = g_getenv("HOME");
|
2011-09-21 17:14:14 +00:00
|
|
|
if (homedir == NULL) {
|
|
|
|
/*
|
2015-10-18 22:02:52 +00:00
|
|
|
* It's not set.
|
|
|
|
*
|
2011-09-21 17:14:14 +00:00
|
|
|
* Get their home directory from the password file.
|
|
|
|
* If we can't even find a password file entry for them,
|
|
|
|
* use "/tmp".
|
|
|
|
*/
|
|
|
|
pwd = getpwuid(getuid());
|
|
|
|
if (pwd != NULL) {
|
2012-07-09 01:56:27 +00:00
|
|
|
homedir = pwd->pw_dir;
|
|
|
|
} else {
|
2011-09-21 17:14:14 +00:00
|
|
|
homedir = "/tmp";
|
2012-07-09 01:56:27 +00:00
|
|
|
}
|
2011-09-21 17:14:14 +00:00
|
|
|
}
|
2015-10-18 22:02:52 +00:00
|
|
|
path = g_build_filename(homedir, ".wireshark", NULL);
|
|
|
|
if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
|
|
|
|
g_free(xdg_path);
|
|
|
|
persconffile_dir = path;
|
|
|
|
return persconffile_dir;
|
|
|
|
}
|
2001-10-24 06:13:07 +00:00
|
|
|
|
2015-10-18 22:02:52 +00:00
|
|
|
/*
|
|
|
|
* Neither are directories that exist; use the XDG path, so we'll
|
|
|
|
* create that as necessary.
|
|
|
|
*/
|
|
|
|
g_free(path);
|
|
|
|
persconffile_dir = xdg_path;
|
2011-09-21 17:14:14 +00:00
|
|
|
return persconffile_dir;
|
2015-10-18 22:02:52 +00:00
|
|
|
#endif
|
2001-10-22 22:59:26 +00:00
|
|
|
}
|
2001-10-23 05:01:02 +00:00
|
|
|
|
2013-11-19 19:45:38 +00:00
|
|
|
void
|
|
|
|
set_persconffile_dir(const char *p)
|
|
|
|
{
|
|
|
|
g_free(persconffile_dir);
|
|
|
|
persconffile_dir = g_strdup(p);
|
|
|
|
}
|
|
|
|
|
2017-02-18 15:46:24 +00:00
|
|
|
char *
|
2008-01-14 16:40:23 +00:00
|
|
|
get_profiles_dir(void)
|
|
|
|
{
|
2017-02-18 15:46:24 +00:00
|
|
|
return g_strdup_printf ("%s%s%s", get_persconffile_dir_no_profile (),
|
2011-09-21 17:14:14 +00:00
|
|
|
G_DIR_SEPARATOR_S, PROFILES_DIR);
|
2008-01-14 16:40:23 +00:00
|
|
|
}
|
|
|
|
|
2017-06-20 19:12:48 +00:00
|
|
|
int
|
|
|
|
create_profiles_dir(char **pf_dir_path_return)
|
|
|
|
{
|
|
|
|
char *pf_dir_path;
|
|
|
|
ws_statb64 s_buf;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the "Default" personal configuration files directory, if necessary.
|
|
|
|
*/
|
|
|
|
if (create_persconffile_profile (NULL, pf_dir_path_return) == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if profiles directory exists.
|
|
|
|
* If not then create it.
|
|
|
|
*/
|
|
|
|
pf_dir_path = get_profiles_dir ();
|
|
|
|
if (ws_stat64(pf_dir_path, &s_buf) != 0) {
|
|
|
|
if (errno != ENOENT) {
|
|
|
|
/* Some other problem; give up now. */
|
|
|
|
*pf_dir_path_return = pf_dir_path;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It doesn't exist; try to create it.
|
|
|
|
*/
|
|
|
|
int ret = ws_mkdir(pf_dir_path, 0755);
|
|
|
|
if (ret == -1) {
|
|
|
|
*pf_dir_path_return = pf_dir_path;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free(pf_dir_path);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-18 15:46:24 +00:00
|
|
|
char *
|
2019-07-30 08:12:30 +00:00
|
|
|
get_global_profiles_dir(void)
|
2011-02-26 17:23:24 +00:00
|
|
|
{
|
2017-02-18 15:46:24 +00:00
|
|
|
return g_strdup_printf ("%s%s%s", get_datafile_dir(),
|
2011-09-21 17:14:14 +00:00
|
|
|
G_DIR_SEPARATOR_S, PROFILES_DIR);
|
2011-02-26 17:23:24 +00:00
|
|
|
}
|
|
|
|
|
2017-02-10 17:04:20 +00:00
|
|
|
static char *
|
2008-01-14 16:40:23 +00:00
|
|
|
get_persconffile_dir(const gchar *profilename)
|
|
|
|
{
|
2017-02-18 15:46:24 +00:00
|
|
|
char *persconffile_profile_dir = NULL, *profile_dir;
|
2008-01-14 16:40:23 +00:00
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
if (profilename && strlen(profilename) > 0 &&
|
|
|
|
strcmp(profilename, DEFAULT_PROFILE) != 0) {
|
2017-02-18 15:46:24 +00:00
|
|
|
profile_dir = get_profiles_dir();
|
|
|
|
persconffile_profile_dir = g_strdup_printf ("%s%s%s", profile_dir,
|
2011-09-21 17:14:14 +00:00
|
|
|
G_DIR_SEPARATOR_S, profilename);
|
2017-02-18 15:46:24 +00:00
|
|
|
g_free(profile_dir);
|
2011-09-21 17:14:14 +00:00
|
|
|
} else {
|
|
|
|
persconffile_profile_dir = g_strdup (get_persconffile_dir_no_profile ());
|
|
|
|
}
|
2008-01-14 16:40:23 +00:00
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
return persconffile_profile_dir;
|
2008-01-14 16:40:23 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 06:26:35 +00:00
|
|
|
char *
|
2019-07-30 08:12:30 +00:00
|
|
|
get_profile_dir(const char *profilename, gboolean is_global)
|
2008-01-14 16:40:23 +00:00
|
|
|
{
|
2018-10-05 06:26:35 +00:00
|
|
|
gchar *profile_dir;
|
|
|
|
|
2019-07-30 08:12:30 +00:00
|
|
|
if (is_global) {
|
2018-10-05 06:26:35 +00:00
|
|
|
if (profilename && strlen(profilename) > 0 &&
|
|
|
|
strcmp(profilename, DEFAULT_PROFILE) != 0)
|
|
|
|
{
|
2019-07-30 08:12:30 +00:00
|
|
|
gchar *global_path = get_global_profiles_dir();
|
|
|
|
profile_dir = g_build_filename(global_path, profilename, NULL);
|
|
|
|
g_free(global_path);
|
2018-10-05 06:26:35 +00:00
|
|
|
} else {
|
|
|
|
profile_dir = g_strdup(get_datafile_dir());
|
2011-09-21 17:14:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-02-07 22:20:12 +00:00
|
|
|
/*
|
|
|
|
* If we didn't supply a profile name, i.e. if profilename is
|
|
|
|
* null, get_persconffile_dir() returns the default profile.
|
|
|
|
*/
|
2018-10-05 06:26:35 +00:00
|
|
|
profile_dir = get_persconffile_dir(profilename);
|
2011-09-21 17:14:14 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 06:26:35 +00:00
|
|
|
return profile_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2019-07-30 08:12:30 +00:00
|
|
|
profile_exists(const gchar *profilename, gboolean global)
|
2018-10-05 06:26:35 +00:00
|
|
|
{
|
|
|
|
gchar *path = NULL;
|
|
|
|
gboolean exists;
|
|
|
|
|
|
|
|
/*
|
2019-07-30 08:12:30 +00:00
|
|
|
* If we're looking up a global profile, we must have a
|
2018-10-05 06:26:35 +00:00
|
|
|
* profile name.
|
|
|
|
*/
|
2019-07-30 08:12:30 +00:00
|
|
|
if (global && !profilename)
|
2018-10-05 06:26:35 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2019-07-30 08:12:30 +00:00
|
|
|
path = get_profile_dir(profilename, global);
|
2018-10-05 06:26:35 +00:00
|
|
|
exists = (test_for_directory(path) == EISDIR) ? TRUE : FALSE;
|
|
|
|
|
|
|
|
g_free(path);
|
|
|
|
return exists;
|
2008-01-14 16:40:23 +00:00
|
|
|
}
|
|
|
|
|
2008-01-15 19:39:31 +00:00
|
|
|
static int
|
2008-01-14 16:40:23 +00:00
|
|
|
delete_directory (const char *directory, char **pf_dir_path_return)
|
|
|
|
{
|
2011-09-21 17:14:14 +00:00
|
|
|
WS_DIR *dir;
|
|
|
|
WS_DIRENT *file;
|
|
|
|
gchar *filename;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if ((dir = ws_dir_open(directory, 0, NULL)) != NULL) {
|
|
|
|
while ((file = ws_dir_read_name(dir)) != NULL) {
|
|
|
|
filename = g_strdup_printf ("%s%s%s", directory, G_DIR_SEPARATOR_S,
|
|
|
|
ws_dir_get_name(file));
|
|
|
|
if (test_for_directory(filename) != EISDIR) {
|
|
|
|
ret = ws_remove(filename);
|
2008-01-14 16:40:23 +00:00
|
|
|
#if 0
|
2011-09-21 17:14:14 +00:00
|
|
|
} else {
|
|
|
|
/* The user has manually created a directory in the profile directory */
|
|
|
|
/* I do not want to delete the directory recursively yet */
|
|
|
|
ret = delete_directory (filename, pf_dir_path_return);
|
2008-01-14 16:40:23 +00:00
|
|
|
#endif
|
2011-09-21 17:14:14 +00:00
|
|
|
}
|
|
|
|
if (ret != 0) {
|
|
|
|
*pf_dir_path_return = filename;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
ws_dir_close(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == 0 && (ret = ws_remove(directory)) != 0) {
|
|
|
|
*pf_dir_path_return = g_strdup (directory);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2008-01-14 16:40:23 +00:00
|
|
|
}
|
|
|
|
|
2017-02-13 22:00:00 +00:00
|
|
|
static int
|
|
|
|
reset_default_profile(char **pf_dir_path_return)
|
|
|
|
{
|
2017-02-18 15:46:24 +00:00
|
|
|
char *profile_dir = get_persconffile_dir(NULL);
|
2017-02-13 22:00:00 +00:00
|
|
|
gchar *filename, *del_file;
|
|
|
|
GList *files, *file;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
files = g_hash_table_get_keys(profile_files);
|
|
|
|
file = g_list_first(files);
|
|
|
|
while (file) {
|
|
|
|
filename = (gchar *)file->data;
|
|
|
|
del_file = g_strdup_printf("%s%s%s", profile_dir, G_DIR_SEPARATOR_S, filename);
|
|
|
|
|
|
|
|
if (file_exists(del_file)) {
|
|
|
|
ret = ws_remove(del_file);
|
|
|
|
if (ret != 0) {
|
2017-02-18 15:46:24 +00:00
|
|
|
*pf_dir_path_return = profile_dir;
|
2017-02-13 22:00:00 +00:00
|
|
|
g_free(del_file);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(del_file);
|
|
|
|
file = g_list_next(file);
|
|
|
|
}
|
2017-06-21 14:48:22 +00:00
|
|
|
g_list_free(files);
|
2017-02-13 22:00:00 +00:00
|
|
|
|
2017-02-18 15:46:24 +00:00
|
|
|
g_free(profile_dir);
|
2017-02-13 22:00:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-14 16:40:23 +00:00
|
|
|
int
|
|
|
|
delete_persconffile_profile(const char *profilename, char **pf_dir_path_return)
|
|
|
|
{
|
2017-02-13 22:00:00 +00:00
|
|
|
if (strcmp(profilename, DEFAULT_PROFILE) == 0) {
|
|
|
|
return reset_default_profile(pf_dir_path_return);
|
|
|
|
}
|
|
|
|
|
2017-02-18 15:46:24 +00:00
|
|
|
char *profile_dir = get_persconffile_dir(profilename);
|
2011-09-21 17:14:14 +00:00
|
|
|
int ret = 0;
|
2008-01-14 16:40:23 +00:00
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
if (test_for_directory (profile_dir) == EISDIR) {
|
|
|
|
ret = delete_directory (profile_dir, pf_dir_path_return);
|
|
|
|
}
|
2008-01-14 16:40:23 +00:00
|
|
|
|
2017-02-18 15:46:24 +00:00
|
|
|
g_free(profile_dir);
|
2011-09-21 17:14:14 +00:00
|
|
|
return ret;
|
2008-01-14 16:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rename_persconffile_profile(const char *fromname, const char *toname,
|
2011-09-21 17:14:14 +00:00
|
|
|
char **pf_from_dir_path_return, char **pf_to_dir_path_return)
|
2008-01-14 16:40:23 +00:00
|
|
|
{
|
2017-02-18 15:46:24 +00:00
|
|
|
char *from_dir = get_persconffile_dir(fromname);
|
|
|
|
char *to_dir = get_persconffile_dir(toname);
|
2011-09-21 17:14:14 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
ret = ws_rename (from_dir, to_dir);
|
|
|
|
if (ret != 0) {
|
2017-02-18 15:46:24 +00:00
|
|
|
*pf_from_dir_path_return = from_dir;
|
|
|
|
*pf_to_dir_path_return = to_dir;
|
|
|
|
return ret;
|
2011-09-21 17:14:14 +00:00
|
|
|
}
|
2008-01-14 16:40:23 +00:00
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
g_free (from_dir);
|
|
|
|
g_free (to_dir);
|
2008-01-14 16:40:23 +00:00
|
|
|
|
2017-02-18 15:46:24 +00:00
|
|
|
return 0;
|
2008-01-14 16:40:23 +00:00
|
|
|
}
|
|
|
|
|
2001-10-23 05:01:02 +00:00
|
|
|
/*
|
|
|
|
* Create the directory that holds personal configuration files, if
|
|
|
|
* necessary. If we attempted to create it, and failed, return -1 and
|
2001-10-24 06:13:07 +00:00
|
|
|
* set "*pf_dir_path_return" to the pathname of the directory we failed
|
|
|
|
* to create (it's g_mallocated, so our caller should free it); otherwise,
|
2001-10-23 05:01:02 +00:00
|
|
|
* return 0.
|
|
|
|
*/
|
|
|
|
int
|
2008-01-14 16:40:23 +00:00
|
|
|
create_persconffile_profile(const char *profilename, char **pf_dir_path_return)
|
2001-10-23 05:01:02 +00:00
|
|
|
{
|
2017-02-18 15:46:24 +00:00
|
|
|
char *pf_dir_path;
|
2015-10-28 23:06:18 +00:00
|
|
|
#ifdef _WIN32
|
2011-09-21 17:14:14 +00:00
|
|
|
char *pf_dir_path_copy, *pf_dir_parent_path;
|
|
|
|
size_t pf_dir_parent_path_len;
|
2017-02-22 01:41:55 +00:00
|
|
|
int save_errno;
|
2015-10-28 23:06:18 +00:00
|
|
|
#endif
|
2011-09-21 17:14:14 +00:00
|
|
|
ws_statb64 s_buf;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (profilename) {
|
|
|
|
/*
|
2017-06-20 19:12:48 +00:00
|
|
|
* Create the personal profiles directory, if necessary.
|
2011-09-21 17:14:14 +00:00
|
|
|
*/
|
2017-06-20 19:12:48 +00:00
|
|
|
if (create_profiles_dir(pf_dir_path_return) == -1) {
|
2011-09-21 17:14:14 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pf_dir_path = get_persconffile_dir(profilename);
|
2016-01-07 03:01:39 +00:00
|
|
|
if (ws_stat64(pf_dir_path, &s_buf) != 0) {
|
|
|
|
if (errno != ENOENT) {
|
|
|
|
/* Some other problem; give up now. */
|
2017-02-18 15:46:24 +00:00
|
|
|
*pf_dir_path_return = pf_dir_path;
|
2016-01-07 03:01:39 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2015-10-28 23:06:18 +00:00
|
|
|
#ifdef _WIN32
|
2011-09-21 17:14:14 +00:00
|
|
|
/*
|
|
|
|
* Does the parent directory of that directory
|
|
|
|
* exist? %APPDATA% may not exist even though
|
2015-10-28 23:06:18 +00:00
|
|
|
* %USERPROFILE% does.
|
2011-09-21 17:14:14 +00:00
|
|
|
*
|
|
|
|
* We check for the existence of the directory
|
2015-10-28 23:06:18 +00:00
|
|
|
* by first checking whether the parent directory
|
|
|
|
* is just a drive letter and, if it's not, by
|
|
|
|
* doing a "stat()" on it. If it's a drive letter,
|
|
|
|
* or if the "stat()" succeeds, we assume it exists.
|
2011-09-21 17:14:14 +00:00
|
|
|
*/
|
2017-02-21 17:57:16 +00:00
|
|
|
pf_dir_path_copy = g_strdup(pf_dir_path);
|
2011-09-21 17:14:14 +00:00
|
|
|
pf_dir_parent_path = get_dirname(pf_dir_path_copy);
|
|
|
|
pf_dir_parent_path_len = strlen(pf_dir_parent_path);
|
|
|
|
if (pf_dir_parent_path_len > 0
|
|
|
|
&& pf_dir_parent_path[pf_dir_parent_path_len - 1] != ':'
|
|
|
|
&& ws_stat64(pf_dir_parent_path, &s_buf) != 0) {
|
2016-01-07 03:01:39 +00:00
|
|
|
/*
|
|
|
|
* Not a drive letter and the stat() failed.
|
|
|
|
*/
|
|
|
|
if (errno != ENOENT) {
|
|
|
|
/* Some other problem; give up now. */
|
2017-02-18 15:46:24 +00:00
|
|
|
*pf_dir_path_return = pf_dir_path;
|
2017-02-22 01:41:55 +00:00
|
|
|
save_errno = errno;
|
2017-02-21 17:57:16 +00:00
|
|
|
g_free(pf_dir_path_copy);
|
2017-02-22 01:41:55 +00:00
|
|
|
errno = save_errno;
|
2016-01-07 03:01:39 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2011-09-21 17:14:14 +00:00
|
|
|
/*
|
|
|
|
* No, it doesn't exist - make it first.
|
|
|
|
*/
|
|
|
|
ret = ws_mkdir(pf_dir_parent_path, 0755);
|
|
|
|
if (ret == -1) {
|
|
|
|
*pf_dir_path_return = pf_dir_parent_path;
|
2017-02-22 01:41:55 +00:00
|
|
|
save_errno = errno;
|
2017-02-21 17:57:16 +00:00
|
|
|
g_free(pf_dir_path);
|
2017-02-22 01:41:55 +00:00
|
|
|
errno = save_errno;
|
2011-09-21 17:14:14 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free(pf_dir_path_copy);
|
|
|
|
ret = ws_mkdir(pf_dir_path, 0755);
|
2015-10-28 23:06:18 +00:00
|
|
|
#else
|
|
|
|
ret = g_mkdir_with_parents(pf_dir_path, 0755);
|
|
|
|
#endif
|
2011-09-21 17:14:14 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Something with that pathname exists; if it's not
|
|
|
|
* a directory, we'll get an error if we try to put
|
|
|
|
* something in it, so we don't fail here, we wait
|
|
|
|
* for that attempt fo fail.
|
|
|
|
*/
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
if (ret == -1)
|
2017-02-18 15:46:24 +00:00
|
|
|
*pf_dir_path_return = pf_dir_path;
|
2017-04-19 21:16:28 +00:00
|
|
|
else
|
|
|
|
g_free(pf_dir_path);
|
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
return ret;
|
2001-10-23 05:01:02 +00:00
|
|
|
}
|
2001-10-24 07:18:39 +00:00
|
|
|
|
2019-08-05 08:04:22 +00:00
|
|
|
const GHashTable *
|
|
|
|
allowed_profile_filenames(void)
|
|
|
|
{
|
|
|
|
return profile_files;
|
|
|
|
}
|
|
|
|
|
2008-01-14 16:40:23 +00:00
|
|
|
int
|
|
|
|
create_persconffile_dir(char **pf_dir_path_return)
|
|
|
|
{
|
2016-01-07 09:40:44 +00:00
|
|
|
return create_persconffile_profile(persconfprofile, pf_dir_path_return);
|
2008-01-14 16:40:23 +00:00
|
|
|
}
|
|
|
|
|
2009-12-21 12:32:31 +00:00
|
|
|
int
|
2019-07-30 08:12:30 +00:00
|
|
|
copy_persconffile_profile(const char *toname, const char *fromname, gboolean from_global,
|
2011-09-21 17:14:14 +00:00
|
|
|
char **pf_filename_return, char **pf_to_dir_path_return, char **pf_from_dir_path_return)
|
2009-12-21 12:32:31 +00:00
|
|
|
{
|
2011-09-21 17:14:14 +00:00
|
|
|
gchar *from_dir;
|
2017-02-18 15:46:24 +00:00
|
|
|
gchar *to_dir = get_persconffile_dir(toname);
|
2018-10-05 06:26:35 +00:00
|
|
|
gchar *filename, *from_file, *to_file;
|
2011-09-21 17:14:14 +00:00
|
|
|
GList *files, *file;
|
|
|
|
|
2019-07-30 08:12:30 +00:00
|
|
|
from_dir = get_profile_dir(fromname, from_global);
|
2011-09-21 17:14:14 +00:00
|
|
|
|
|
|
|
files = g_hash_table_get_keys(profile_files);
|
|
|
|
file = g_list_first(files);
|
|
|
|
while (file) {
|
|
|
|
filename = (gchar *)file->data;
|
|
|
|
from_file = g_strdup_printf ("%s%s%s", from_dir, G_DIR_SEPARATOR_S, filename);
|
|
|
|
to_file = g_strdup_printf ("%s%s%s", to_dir, G_DIR_SEPARATOR_S, filename);
|
|
|
|
|
|
|
|
if (file_exists(from_file) && !copy_file_binary_mode(from_file, to_file)) {
|
|
|
|
*pf_filename_return = g_strdup(filename);
|
|
|
|
*pf_to_dir_path_return = to_dir;
|
|
|
|
*pf_from_dir_path_return = from_dir;
|
|
|
|
g_free (from_file);
|
|
|
|
g_free (to_file);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (from_file);
|
|
|
|
g_free (to_file);
|
|
|
|
|
|
|
|
file = g_list_next(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (files);
|
|
|
|
g_free (from_dir);
|
|
|
|
g_free (to_dir);
|
|
|
|
|
|
|
|
return 0;
|
2009-12-21 12:32:31 +00:00
|
|
|
}
|
|
|
|
|
2007-01-14 22:25:22 +00:00
|
|
|
/*
|
|
|
|
* Get the (default) directory in which personal data is stored.
|
|
|
|
*
|
2016-03-11 17:15:12 +00:00
|
|
|
* On Win32, this is the "My Documents" folder in the personal profile.
|
2007-01-14 22:25:22 +00:00
|
|
|
* On UNIX this is simply the current directory.
|
|
|
|
*/
|
|
|
|
/* XXX - should this and the get_home_dir() be merged? */
|
2010-03-02 00:06:20 +00:00
|
|
|
extern const char *
|
2007-01-14 22:25:22 +00:00
|
|
|
get_persdatafile_dir(void)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
2011-09-21 17:14:14 +00:00
|
|
|
TCHAR tszPath[MAX_PATH];
|
|
|
|
|
|
|
|
/* Return the cached value, if available */
|
|
|
|
if (persdatafile_dir != NULL)
|
|
|
|
return persdatafile_dir;
|
|
|
|
|
|
|
|
/*
|
2016-03-11 17:15:12 +00:00
|
|
|
* Hint: SHGetFolderPath is not available on MSVC 6 - without
|
|
|
|
* Platform SDK
|
2011-09-21 17:14:14 +00:00
|
|
|
*/
|
2016-03-11 17:15:12 +00:00
|
|
|
if (SHGetSpecialFolderPath(NULL, tszPath, CSIDL_PERSONAL, FALSE)) {
|
|
|
|
persdatafile_dir = g_utf16_to_utf8(tszPath, -1, NULL, NULL, NULL);
|
2013-11-19 20:06:47 +00:00
|
|
|
return persdatafile_dir;
|
2011-09-21 17:14:14 +00:00
|
|
|
} else {
|
2016-03-11 17:15:12 +00:00
|
|
|
return "";
|
2011-09-21 17:14:14 +00:00
|
|
|
}
|
2007-01-14 22:25:22 +00:00
|
|
|
#else
|
2011-09-21 17:14:14 +00:00
|
|
|
return "";
|
2007-01-14 22:25:22 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-11-19 19:45:38 +00:00
|
|
|
void
|
|
|
|
set_persdatafile_dir(const char *p)
|
|
|
|
{
|
|
|
|
g_free(persdatafile_dir);
|
|
|
|
persdatafile_dir = g_strdup(p);
|
|
|
|
}
|
|
|
|
|
2004-09-11 23:03:36 +00:00
|
|
|
#ifdef _WIN32
|
2001-10-24 07:18:39 +00:00
|
|
|
/*
|
|
|
|
* Returns the user's home directory on Win32.
|
|
|
|
*/
|
|
|
|
static const char *
|
|
|
|
get_home_dir(void)
|
|
|
|
{
|
2011-09-21 17:14:14 +00:00
|
|
|
static const char *home = NULL;
|
2016-03-31 03:38:51 +00:00
|
|
|
const char *homedrive, *homepath;
|
2011-09-21 17:14:14 +00:00
|
|
|
char *homestring;
|
|
|
|
char *lastsep;
|
|
|
|
|
|
|
|
/* Return the cached value, if available */
|
|
|
|
if (home)
|
|
|
|
return home;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX - should we use USERPROFILE anywhere in this process?
|
|
|
|
* Is there a chance that it might be set but one or more of
|
|
|
|
* HOMEDRIVE or HOMEPATH isn't set?
|
|
|
|
*/
|
2016-03-31 03:38:51 +00:00
|
|
|
homedrive = g_getenv("HOMEDRIVE");
|
2011-09-21 17:14:14 +00:00
|
|
|
if (homedrive != NULL) {
|
2016-03-31 03:38:51 +00:00
|
|
|
homepath = g_getenv("HOMEPATH");
|
2011-09-21 17:14:14 +00:00
|
|
|
if (homepath != NULL) {
|
|
|
|
/*
|
|
|
|
* This is cached, so we don't need to worry about
|
|
|
|
* allocating multiple ones of them.
|
|
|
|
*/
|
|
|
|
homestring = g_strdup_printf("%s%s", homedrive, homepath);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Trim off any trailing slash or backslash.
|
|
|
|
*/
|
|
|
|
lastsep = find_last_pathname_separator(homestring);
|
|
|
|
if (lastsep != NULL && *(lastsep + 1) == '\0') {
|
|
|
|
/*
|
|
|
|
* Last separator is the last character
|
|
|
|
* in the string. Nuke it.
|
|
|
|
*/
|
|
|
|
*lastsep = '\0';
|
|
|
|
}
|
|
|
|
home = homestring;
|
|
|
|
} else
|
|
|
|
home = homedrive;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Give up and use C:.
|
|
|
|
*/
|
|
|
|
home = "C:";
|
|
|
|
}
|
|
|
|
|
|
|
|
return home;
|
2001-10-24 07:18:39 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct the path name of a personal configuration file, given the
|
|
|
|
* file name.
|
|
|
|
*
|
|
|
|
* On Win32, if "for_writing" is FALSE, we check whether the file exists
|
2006-05-28 19:49:07 +00:00
|
|
|
* and, if not, construct a path name relative to the ".wireshark"
|
2001-10-24 07:18:39 +00:00
|
|
|
* subdirectory of the user's home directory, and check whether that
|
|
|
|
* exists; if it does, we return that, so that configuration files
|
|
|
|
* from earlier versions can be read.
|
2008-02-26 18:58:12 +00:00
|
|
|
*
|
|
|
|
* The returned file name was g_malloc()'d so it must be g_free()d when the
|
|
|
|
* caller is done with it.
|
2001-10-24 07:18:39 +00:00
|
|
|
*/
|
|
|
|
char *
|
2013-04-09 02:48:03 +00:00
|
|
|
get_persconffile_path(const char *filename, gboolean from_profile)
|
2001-10-24 07:18:39 +00:00
|
|
|
{
|
2017-02-18 15:46:24 +00:00
|
|
|
char *path, *dir = NULL;
|
2017-02-10 17:04:20 +00:00
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
if (do_store_persconffiles && from_profile && !g_hash_table_lookup (profile_files, filename)) {
|
|
|
|
/* Store filenames so we know which filenames belongs to a configuration profile */
|
|
|
|
g_hash_table_insert (profile_files, g_strdup(filename), g_strdup(filename));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (from_profile) {
|
2017-07-17 23:22:25 +00:00
|
|
|
dir = get_persconffile_dir(persconfprofile);
|
2011-09-21 17:14:14 +00:00
|
|
|
} else {
|
2017-07-17 23:22:25 +00:00
|
|
|
dir = get_persconffile_dir(NULL);
|
2011-09-21 17:14:14 +00:00
|
|
|
}
|
2017-07-17 23:22:25 +00:00
|
|
|
path = g_build_filename(dir, filename, NULL);
|
2001-10-24 07:18:39 +00:00
|
|
|
|
2017-02-18 15:46:24 +00:00
|
|
|
g_free(dir);
|
2011-09-21 17:14:14 +00:00
|
|
|
return path;
|
2001-10-24 09:22:23 +00:00
|
|
|
}
|
2003-05-15 07:44:54 +00:00
|
|
|
|
|
|
|
/*
|
2019-07-30 08:12:30 +00:00
|
|
|
* Construct the path name of a global configuration file, given the
|
2003-05-15 07:44:54 +00:00
|
|
|
* file name.
|
2008-02-26 18:58:12 +00:00
|
|
|
*
|
|
|
|
* The returned file name was g_malloc()'d so it must be g_free()d when the
|
|
|
|
* caller is done with it.
|
2003-05-15 07:44:54 +00:00
|
|
|
*/
|
|
|
|
char *
|
|
|
|
get_datafile_path(const char *filename)
|
|
|
|
{
|
2014-08-01 19:26:18 +00:00
|
|
|
if (running_in_build_directory_flag &&
|
|
|
|
(!strcmp(filename, "AUTHORS-SHORT") ||
|
2014-10-06 02:14:57 +00:00
|
|
|
!strcmp(filename, "hosts"))) {
|
2013-10-29 02:28:16 +00:00
|
|
|
/* We're running in the build directory and the requested file is a
|
2014-08-01 19:26:18 +00:00
|
|
|
* generated (or a test) file. Return the file name in the build
|
2014-10-06 02:14:57 +00:00
|
|
|
* directory (not in the source/data directory).
|
|
|
|
* (Oh the things we do to keep the source directory pristine...)
|
2013-10-29 02:28:16 +00:00
|
|
|
*/
|
2018-04-26 15:36:58 +00:00
|
|
|
return g_build_filename(get_progfile_dir(), filename, (char *)NULL);
|
2013-10-29 02:28:16 +00:00
|
|
|
} else {
|
2018-04-26 15:36:58 +00:00
|
|
|
return g_build_filename(get_datafile_dir(), filename, (char *)NULL);
|
2013-10-29 02:28:16 +00:00
|
|
|
}
|
2003-05-15 07:44:54 +00:00
|
|
|
}
|
|
|
|
|
2004-01-24 01:44:29 +00:00
|
|
|
/*
|
2004-01-24 02:01:44 +00:00
|
|
|
* Return an error message for UNIX-style errno indications on open or
|
|
|
|
* create operations.
|
2004-01-24 01:44:29 +00:00
|
|
|
*/
|
2005-07-23 11:41:25 +00:00
|
|
|
const char *
|
2004-01-24 01:44:29 +00:00
|
|
|
file_open_error_message(int err, gboolean for_writing)
|
|
|
|
{
|
2011-09-21 17:14:14 +00:00
|
|
|
const char *errmsg;
|
|
|
|
static char errmsg_errno[1024+1];
|
2004-01-24 01:44:29 +00:00
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
switch (err) {
|
2004-01-24 01:44:29 +00:00
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
case ENOENT:
|
|
|
|
if (for_writing)
|
|
|
|
errmsg = "The path to the file \"%s\" doesn't exist.";
|
|
|
|
else
|
|
|
|
errmsg = "The file \"%s\" doesn't exist.";
|
|
|
|
break;
|
2004-01-24 01:44:29 +00:00
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
case EACCES:
|
|
|
|
if (for_writing)
|
|
|
|
errmsg = "You don't have permission to create or write to the file \"%s\".";
|
|
|
|
else
|
|
|
|
errmsg = "You don't have permission to read the file \"%s\".";
|
|
|
|
break;
|
2004-01-24 01:44:29 +00:00
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
case EISDIR:
|
|
|
|
errmsg = "\"%s\" is a directory (folder), not a file.";
|
|
|
|
break;
|
2004-01-24 01:44:29 +00:00
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
case ENOSPC:
|
|
|
|
errmsg = "The file \"%s\" could not be created because there is no space left on the file system.";
|
|
|
|
break;
|
2004-01-24 02:01:44 +00:00
|
|
|
|
|
|
|
#ifdef EDQUOT
|
2011-09-21 17:14:14 +00:00
|
|
|
case EDQUOT:
|
|
|
|
errmsg = "The file \"%s\" could not be created because you are too close to, or over, your disk quota.";
|
|
|
|
break;
|
2004-01-24 02:01:44 +00:00
|
|
|
#endif
|
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
case EINVAL:
|
|
|
|
errmsg = "The file \"%s\" could not be created because an invalid filename was specified.";
|
|
|
|
break;
|
|
|
|
|
2016-06-20 16:41:10 +00:00
|
|
|
#ifdef ENAMETOOLONG
|
|
|
|
case ENAMETOOLONG:
|
|
|
|
/* XXX Make sure we truncate on a character boundary. */
|
|
|
|
errmsg = "The file name \"%.80s" UTF8_HORIZONTAL_ELLIPSIS "\" is too long.";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2013-06-01 06:48:37 +00:00
|
|
|
case ENOMEM:
|
|
|
|
/*
|
|
|
|
* The problem probably has nothing to do with how much RAM the
|
|
|
|
* user has on their machine, so don't confuse them by saying
|
|
|
|
* "memory". The problem is probably either virtual address
|
|
|
|
* space or swap space.
|
|
|
|
*/
|
|
|
|
#if GLIB_SIZEOF_VOID_P == 4
|
|
|
|
/*
|
|
|
|
* ILP32; we probably ran out of virtual address space.
|
|
|
|
*/
|
|
|
|
#define ENOMEM_REASON "it can't be handled by a 32-bit application"
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* LP64 or LLP64; we probably ran out of swap space.
|
|
|
|
*/
|
|
|
|
#if defined(_WIN32)
|
|
|
|
/*
|
|
|
|
* You need to make the pagefile bigger.
|
|
|
|
*/
|
|
|
|
#define ENOMEM_REASON "the pagefile is too small"
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
/*
|
|
|
|
* dynamic_pager couldn't, or wouldn't, create more swap files.
|
|
|
|
*/
|
|
|
|
#define ENOMEM_REASON "your system ran out of swap file space"
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* Either you have a fixed swap partition or a fixed swap file,
|
|
|
|
* and it needs to be made bigger.
|
|
|
|
*
|
2017-04-05 19:15:27 +00:00
|
|
|
* This is UN*X, but it's not macOS, so we assume the user is
|
2013-06-01 06:48:37 +00:00
|
|
|
* *somewhat* nerdy.
|
|
|
|
*/
|
|
|
|
#define ENOMEM_REASON "your system is out of swap space"
|
|
|
|
#endif
|
|
|
|
#endif /* GLIB_SIZEOF_VOID_P == 4 */
|
|
|
|
if (for_writing)
|
2013-06-03 02:08:13 +00:00
|
|
|
errmsg = "The file \"%s\" could not be created because " ENOMEM_REASON ".";
|
2013-06-01 06:48:37 +00:00
|
|
|
else
|
2013-06-03 02:08:13 +00:00
|
|
|
errmsg = "The file \"%s\" could not be opened because " ENOMEM_REASON ".";
|
2013-06-01 06:48:37 +00:00
|
|
|
break;
|
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
default:
|
|
|
|
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
|
|
|
|
"The file \"%%s\" could not be %s: %s.",
|
|
|
|
for_writing ? "created" : "opened",
|
|
|
|
g_strerror(err));
|
|
|
|
errmsg = errmsg_errno;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return errmsg;
|
2004-01-24 01:44:29 +00:00
|
|
|
}
|
2004-01-24 02:01:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return an error message for UNIX-style errno indications on write
|
|
|
|
* operations.
|
|
|
|
*/
|
2005-07-23 11:41:25 +00:00
|
|
|
const char *
|
2004-01-24 02:01:44 +00:00
|
|
|
file_write_error_message(int err)
|
|
|
|
{
|
2011-09-21 17:14:14 +00:00
|
|
|
const char *errmsg;
|
|
|
|
static char errmsg_errno[1024+1];
|
2004-01-24 02:01:44 +00:00
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
switch (err) {
|
2004-01-24 02:01:44 +00:00
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
case ENOSPC:
|
|
|
|
errmsg = "The file \"%s\" could not be saved because there is no space left on the file system.";
|
|
|
|
break;
|
2004-01-24 02:01:44 +00:00
|
|
|
|
|
|
|
#ifdef EDQUOT
|
2011-09-21 17:14:14 +00:00
|
|
|
case EDQUOT:
|
|
|
|
errmsg = "The file \"%s\" could not be saved because you are too close to, or over, your disk quota.";
|
|
|
|
break;
|
2004-01-24 02:01:44 +00:00
|
|
|
#endif
|
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
default:
|
|
|
|
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
|
|
|
|
"An error occurred while writing to the file \"%%s\": %s.",
|
|
|
|
g_strerror(err));
|
|
|
|
errmsg = errmsg_errno;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return errmsg;
|
2004-01-24 02:01:44 +00:00
|
|
|
}
|
|
|
|
|
2005-04-12 21:12:19 +00:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
file_exists(const char *fname)
|
|
|
|
{
|
2011-09-21 17:14:14 +00:00
|
|
|
ws_statb64 file_stat;
|
2005-04-12 21:12:19 +00:00
|
|
|
|
2011-10-09 09:54:48 +00:00
|
|
|
if (!fname) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-09-21 17:14:14 +00:00
|
|
|
if (ws_stat64(fname, &file_stat) != 0 && errno == ENOENT) {
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
return TRUE;
|
|
|
|
}
|
2005-04-12 21:12:19 +00:00
|
|
|
}
|
|
|
|
|
2018-10-10 12:33:40 +00:00
|
|
|
gboolean config_file_exists_with_entries(const char *fname, char comment_char)
|
|
|
|
{
|
|
|
|
gboolean start_of_line = TRUE;
|
|
|
|
gboolean has_entries = FALSE;
|
|
|
|
FILE *file;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
if (!fname) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((file = ws_fopen(fname, "r")) == NULL) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
c = ws_getc_unlocked(file);
|
|
|
|
if (start_of_line && c != comment_char && !g_ascii_isspace(c) && g_ascii_isprint(c)) {
|
|
|
|
has_entries = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (c == '\n' || !g_ascii_isspace(c)) {
|
|
|
|
start_of_line = (c == '\n');
|
|
|
|
}
|
|
|
|
} while (c != EOF);
|
|
|
|
|
|
|
|
fclose(file);
|
|
|
|
return has_entries;
|
|
|
|
}
|
|
|
|
|
2006-02-08 02:06:09 +00:00
|
|
|
/*
|
|
|
|
* Check that the from file is not the same as to file
|
|
|
|
* We do it here so we catch all cases ...
|
|
|
|
* Unfortunately, the file requester gives us an absolute file
|
|
|
|
* name and the read file name may be relative (if supplied on
|
|
|
|
* the command line), so we can't just compare paths. From Joerg Mayer.
|
|
|
|
*/
|
2005-04-12 21:12:19 +00:00
|
|
|
gboolean
|
|
|
|
files_identical(const char *fname1, const char *fname2)
|
|
|
|
{
|
2011-09-21 17:14:14 +00:00
|
|
|
/* Two different implementations, because:
|
|
|
|
*
|
|
|
|
* - _fullpath is not available on UN*X, so we can't get full
|
|
|
|
* paths and compare them (which wouldn't work with hard links
|
|
|
|
* in any case);
|
|
|
|
*
|
|
|
|
* - st_ino isn't filled in with a meaningful value on Windows.
|
|
|
|
*/
|
2005-04-12 21:12:19 +00:00
|
|
|
#ifdef _WIN32
|
2011-09-21 17:14:14 +00:00
|
|
|
char full1[MAX_PATH], full2[MAX_PATH];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the absolute full paths of the file and compare them.
|
|
|
|
* That won't work if you have hard links, but those aren't
|
|
|
|
* much used on Windows, even though NTFS supports them.
|
|
|
|
*
|
|
|
|
* XXX - will _fullpath work with UNC?
|
|
|
|
*/
|
|
|
|
if( _fullpath( full1, fname1, MAX_PATH ) == NULL ) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( _fullpath( full2, fname2, MAX_PATH ) == NULL ) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(strcmp(full1, full2) == 0) {
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-04-12 21:12:19 +00:00
|
|
|
#else
|
2011-09-21 17:14:14 +00:00
|
|
|
ws_statb64 filestat1, filestat2;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compare st_dev and st_ino.
|
|
|
|
*/
|
|
|
|
if (ws_stat64(fname1, &filestat1) == -1)
|
|
|
|
return FALSE; /* can't get info about the first file */
|
|
|
|
if (ws_stat64(fname2, &filestat2) == -1)
|
|
|
|
return FALSE; /* can't get info about the second file */
|
|
|
|
return (filestat1.st_dev == filestat2.st_dev &&
|
|
|
|
filestat1.st_ino == filestat2.st_ino);
|
2005-04-12 21:12:19 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-02-15 21:47:57 +00:00
|
|
|
/*
|
|
|
|
* Copy a file in binary mode, for those operating systems that care about
|
|
|
|
* such things. This should be OK for all files, even text files, as
|
|
|
|
* we'll copy the raw bytes, and we don't look at the bytes as we copy
|
|
|
|
* them.
|
|
|
|
*
|
|
|
|
* Returns TRUE on success, FALSE on failure. If a failure, it also
|
|
|
|
* displays a simple dialog window with the error message.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
copy_file_binary_mode(const char *from_filename, const char *to_filename)
|
|
|
|
{
|
2012-12-26 05:57:06 +00:00
|
|
|
int from_fd, to_fd, err;
|
|
|
|
ssize_t nread, nwritten;
|
2011-09-21 17:14:14 +00:00
|
|
|
guint8 *pd = NULL;
|
|
|
|
|
|
|
|
/* Copy the raw bytes of the file. */
|
|
|
|
from_fd = ws_open(from_filename, O_RDONLY | O_BINARY, 0000 /* no creation so don't matter */);
|
|
|
|
if (from_fd < 0) {
|
|
|
|
report_open_failure(from_filename, errno, FALSE);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use open() instead of creat() so that we can pass the O_BINARY
|
|
|
|
flag, which is relevant on Win32; it appears that "creat()"
|
|
|
|
may open the file in text mode, not binary mode, but we want
|
|
|
|
to copy the raw bytes of the file, so we need the output file
|
|
|
|
to be open in binary mode. */
|
|
|
|
to_fd = ws_open(to_filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
|
|
|
|
if (to_fd < 0) {
|
|
|
|
report_open_failure(to_filename, errno, TRUE);
|
|
|
|
ws_close(from_fd);
|
|
|
|
goto done;
|
|
|
|
}
|
2009-02-15 21:47:57 +00:00
|
|
|
|
2011-03-29 21:39:15 +00:00
|
|
|
#define FS_READ_SIZE 65536
|
2013-03-05 22:15:20 +00:00
|
|
|
pd = (guint8 *)g_malloc(FS_READ_SIZE);
|
2011-09-21 17:14:14 +00:00
|
|
|
while ((nread = ws_read(from_fd, pd, FS_READ_SIZE)) > 0) {
|
|
|
|
nwritten = ws_write(to_fd, pd, nread);
|
|
|
|
if (nwritten < nread) {
|
|
|
|
if (nwritten < 0)
|
|
|
|
err = errno;
|
|
|
|
else
|
|
|
|
err = WTAP_ERR_SHORT_WRITE;
|
|
|
|
report_write_failure(to_filename, err);
|
|
|
|
ws_close(from_fd);
|
|
|
|
ws_close(to_fd);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nread < 0) {
|
|
|
|
err = errno;
|
|
|
|
report_read_failure(from_filename, err);
|
|
|
|
ws_close(from_fd);
|
|
|
|
ws_close(to_fd);
|
|
|
|
goto done;
|
2009-02-15 21:47:57 +00:00
|
|
|
}
|
|
|
|
ws_close(from_fd);
|
2011-09-21 17:14:14 +00:00
|
|
|
if (ws_close(to_fd) < 0) {
|
|
|
|
report_write_failure(to_filename, errno);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(pd);
|
|
|
|
pd = NULL;
|
|
|
|
return TRUE;
|
2009-02-15 21:47:57 +00:00
|
|
|
|
|
|
|
done:
|
2011-09-21 17:14:14 +00:00
|
|
|
g_free(pd);
|
|
|
|
return FALSE;
|
2009-02-15 21:47:57 +00:00
|
|
|
}
|
|
|
|
|
2016-12-09 10:46:20 +00:00
|
|
|
gchar *
|
|
|
|
data_file_url(const gchar *filename)
|
|
|
|
{
|
|
|
|
gchar *file_path;
|
|
|
|
gchar *uri;
|
|
|
|
|
|
|
|
/* Absolute path? */
|
|
|
|
if(g_path_is_absolute(filename)) {
|
|
|
|
file_path = g_strdup(filename);
|
|
|
|
} else if(running_in_build_directory()) {
|
|
|
|
file_path = g_strdup_printf("%s/doc/%s", get_datafile_dir(), filename);
|
|
|
|
} else {
|
|
|
|
file_path = g_strdup_printf("%s/%s", get_datafile_dir(), filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX - check, if the file is really existing, otherwise display a simple_dialog about the problem */
|
|
|
|
|
|
|
|
/* convert filename to uri */
|
|
|
|
uri = g_filename_to_uri(file_path, NULL, NULL);
|
|
|
|
g_free(file_path);
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
|
2017-02-08 13:25:57 +00:00
|
|
|
void
|
|
|
|
free_progdirs(void)
|
|
|
|
{
|
2017-02-10 17:04:20 +00:00
|
|
|
g_free(persconffile_dir);
|
|
|
|
persconffile_dir = NULL;
|
2018-12-04 01:34:25 +00:00
|
|
|
g_free(datafile_dir);
|
|
|
|
datafile_dir = NULL;
|
2017-02-10 17:04:20 +00:00
|
|
|
g_free(persdatafile_dir);
|
|
|
|
persdatafile_dir = NULL;
|
|
|
|
g_free(persconfprofile);
|
|
|
|
persconfprofile = NULL;
|
2017-02-08 13:25:57 +00:00
|
|
|
g_free(progfile_dir);
|
2017-02-10 17:04:20 +00:00
|
|
|
progfile_dir = NULL;
|
2017-02-25 11:00:26 +00:00
|
|
|
#if defined(HAVE_PLUGINS) || defined(HAVE_LUA)
|
2017-02-08 13:25:57 +00:00
|
|
|
g_free(plugin_dir);
|
2017-02-10 17:04:20 +00:00
|
|
|
plugin_dir = NULL;
|
2017-09-18 15:25:20 +00:00
|
|
|
g_free(plugin_dir_with_version);
|
|
|
|
plugin_dir_with_version = NULL;
|
2017-09-10 22:38:36 +00:00
|
|
|
g_free(plugin_pers_dir);
|
|
|
|
plugin_pers_dir = NULL;
|
2017-09-18 15:25:20 +00:00
|
|
|
g_free(plugin_pers_dir_with_version);
|
|
|
|
plugin_pers_dir_with_version = NULL;
|
2017-02-25 11:00:26 +00:00
|
|
|
#endif
|
2017-02-08 13:25:57 +00:00
|
|
|
g_free(extcap_dir);
|
2017-02-10 17:04:20 +00:00
|
|
|
extcap_dir = NULL;
|
2017-02-08 13:25:57 +00:00
|
|
|
}
|
|
|
|
|
2008-03-15 18:31:52 +00:00
|
|
|
/*
|
|
|
|
* Editor modelines
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 4
|
2011-09-21 17:14:14 +00:00
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
2008-03-15 18:31:52 +00:00
|
|
|
* End:
|
|
|
|
*
|
2011-09-21 17:14:14 +00:00
|
|
|
* ex: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
2008-03-15 18:31:52 +00:00
|
|
|
*/
|