2000-09-28 03:16:29 +00:00
|
|
|
/* filesystem.c
|
|
|
|
* Filesystem utility routines
|
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2000-09-28 03:16:29 +00:00
|
|
|
*
|
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
|
|
|
*
|
2000-09-28 03:16:29 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
2000-09-28 03:16:29 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
2000-09-28 03:16:29 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2009-03-22 18:06:06 +00:00
|
|
|
/*
|
|
|
|
* Required with GNU libc to get dladdr().
|
|
|
|
* We define it here because <dlfcn.h> apparently gets included by
|
|
|
|
* one of the headers we include below.
|
|
|
|
*/
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
|
2008-01-15 19:39:31 +00:00
|
|
|
#ifdef HAVE_DIRENT_H
|
|
|
|
#include <dirent.h>
|
|
|
|
#endif
|
|
|
|
|
2001-10-23 03:40:39 +00:00
|
|
|
#include <stdio.h>
|
2007-03-14 18:22:28 +00:00
|
|
|
#include <ctype.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>
|
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2009-02-15 21:47:57 +00:00
|
|
|
#ifdef HAVE_FCNTL_H
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
2005-11-07 02:47:09 +00:00
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
|
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 */
|
|
|
|
#ifdef DLADDR_FINDS_EXECUTABLE_PATH
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#endif /* DLADDR_FINDS_EXECUTABLE_PATH */
|
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"
|
2009-02-15 21:47:57 +00:00
|
|
|
#include "report_err.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>
|
2000-09-28 03:16:29 +00:00
|
|
|
|
2009-02-15 21:47:57 +00:00
|
|
|
#include <wiretap/wtap.h> /* for WTAP_ERR_SHORT_WRITE */
|
|
|
|
|
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"
|
|
|
|
|
2007-01-15 19:11:29 +00:00
|
|
|
#define U3_MY_CAPTURES "\\My Captures"
|
|
|
|
|
2007-03-14 02:55:54 +00:00
|
|
|
char *persconffile_dir = NULL;
|
|
|
|
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
|
|
|
{
|
|
|
|
char *separator;
|
|
|
|
|
2004-09-11 23:03:36 +00:00
|
|
|
#ifdef _WIN32
|
2001-04-02 09:53:46 +00:00
|
|
|
char c;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have to scan for '\' or '/'.
|
|
|
|
* Get to the end of the string.
|
|
|
|
*/
|
"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
|
|
|
separator = strchr(path, '\0'); /* points to ending '\0' */
|
2001-04-02 09:53:46 +00:00
|
|
|
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, ':');
|
|
|
|
#else
|
|
|
|
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
|
|
|
{
|
"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 *filename;
|
2001-04-02 09:53:46 +00:00
|
|
|
|
2003-09-15 19:05:01 +00:00
|
|
|
g_assert(path != NULL);
|
2001-04-02 09:53:46 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
char *separator;
|
|
|
|
|
2003-09-15 19:05:01 +00:00
|
|
|
g_assert(path != NULL);
|
2001-04-02 09:53:46 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
*
|
|
|
|
* the errno, if an attempt to "stat()" the file fails;
|
|
|
|
*
|
|
|
|
* EISDIR, if the attempt succeeded and the file turned out
|
|
|
|
* to be a directory;
|
|
|
|
*
|
|
|
|
* 0, if the attempt succeeded and the file turned out not
|
|
|
|
* to be a directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Visual C++ on Win32 systems doesn't define these. (Old UNIX systems don't
|
|
|
|
* define them either.)
|
|
|
|
*
|
|
|
|
* Visual C++ on Win32 systems doesn't define S_IFIFO, it defines _S_IFIFO.
|
|
|
|
*/
|
|
|
|
#ifndef S_ISREG
|
|
|
|
#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
|
|
|
|
#endif
|
|
|
|
#ifndef S_IFIFO
|
|
|
|
#define S_IFIFO _S_IFIFO
|
|
|
|
#endif
|
|
|
|
#ifndef S_ISFIFO
|
|
|
|
#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
|
|
|
|
#endif
|
|
|
|
#ifndef S_ISDIR
|
|
|
|
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int
|
|
|
|
test_for_directory(const char *path)
|
|
|
|
{
|
2011-04-10 20:59:10 +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-04-10 20:59:10 +00:00
|
|
|
if (ws_stat64(path, &statb) < 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
|
|
|
return errno;
|
|
|
|
|
|
|
|
if (S_ISDIR(statb.st_mode))
|
|
|
|
return EISDIR;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-06-23 21:33:09 +00:00
|
|
|
int
|
|
|
|
test_for_fifo(const char *path)
|
|
|
|
{
|
2011-04-10 20:59:10 +00:00
|
|
|
ws_statb64 statb;
|
2002-06-23 21:33:09 +00:00
|
|
|
|
2011-04-10 20:59:10 +00:00
|
|
|
if (ws_stat64(path, &statb) < 0)
|
2002-06-23 21:33:09 +00:00
|
|
|
return errno;
|
|
|
|
|
|
|
|
if (S_ISFIFO(statb.st_mode))
|
|
|
|
return ESPIPE;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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 *
|
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
|
|
|
init_progfile_dir(const char *arg0
|
|
|
|
#ifdef _WIN32
|
|
|
|
_U_
|
|
|
|
#endif
|
2009-03-22 06:53:17 +00:00
|
|
|
, int (*main_addr)(int, char **)
|
2009-03-22 00:42:33 +00:00
|
|
|
#if defined(_WIN32) || !defined(DLADDR_FINDS_EXECUTABLE_PATH)
|
|
|
|
_U_
|
|
|
|
#endif
|
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
|
2006-03-08 20:55:32 +00:00
|
|
|
TCHAR prog_pathname_w[_MAX_PATH+2];
|
2009-01-20 21:43:49 +00:00
|
|
|
char *prog_pathname;
|
|
|
|
DWORD error;
|
|
|
|
TCHAR *msg_w;
|
|
|
|
guchar *msg;
|
|
|
|
size_t msglen;
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* Attempt to get the full pathname of the currently running
|
|
|
|
* program.
|
|
|
|
*/
|
2010-08-25 20:30:59 +00:00
|
|
|
if (GetModuleFileName(NULL, prog_pathname_w, G_N_ELEMENTS(prog_pathname_w)) != 0 && GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
|
2009-01-20 21:43:49 +00:00
|
|
|
/*
|
|
|
|
* XXX - Should we use g_utf16_to_utf8(), as in
|
|
|
|
* getenv_utf8()?
|
|
|
|
*/
|
|
|
|
prog_pathname = utf_16to8(prog_pathname_w);
|
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
|
|
|
/*
|
|
|
|
* We got it; strip off the last component, which would be
|
|
|
|
* the file name of the executable, giving us the pathname
|
2010-11-22 21:05:55 +00:00
|
|
|
* of the directory where the executable resides.
|
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
|
|
|
*/
|
2010-11-22 21:05:55 +00:00
|
|
|
progfile_dir = g_path_get_dirname(prog_pathname);
|
|
|
|
if (progfile_dir != NULL) {
|
2006-05-01 06:51:14 +00:00
|
|
|
return NULL; /* we succeeded */
|
|
|
|
} else {
|
|
|
|
/*
|
2010-11-22 21:05:55 +00:00
|
|
|
* OK, no. What do we do now?
|
2006-05-01 06:51:14 +00:00
|
|
|
*/
|
2006-05-01 08:09:39 +00:00
|
|
|
return g_strdup_printf("No \\ in executable pathname \"%s\"",
|
2006-05-01 06:51:14 +00:00
|
|
|
prog_pathname);
|
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
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Oh, well. Return an indication of the error.
|
|
|
|
*/
|
|
|
|
error = GetLastError();
|
|
|
|
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
|
|
|
|
NULL, error, 0, (LPTSTR) &msg_w, 0, NULL) == 0) {
|
|
|
|
/*
|
|
|
|
* Gak. We can't format the message.
|
|
|
|
*/
|
2006-05-01 08:09:39 +00:00
|
|
|
return g_strdup_printf("GetModuleFileName failed: %u (FormatMessage failed: %u)",
|
2006-05-01 06:51:14 +00:00
|
|
|
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';
|
|
|
|
}
|
2006-05-01 08:09:39 +00:00
|
|
|
return g_strdup_printf("GetModuleFileName failed: %s (%u)",
|
2006-05-01 06:51:14 +00:00
|
|
|
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
|
2009-03-22 00:42:33 +00:00
|
|
|
#ifdef DLADDR_FINDS_EXECUTABLE_PATH
|
|
|
|
Dl_info info;
|
|
|
|
#endif
|
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
|
|
|
char *prog_pathname;
|
|
|
|
char *curdir;
|
|
|
|
long path_max;
|
2006-05-01 06:51:14 +00:00
|
|
|
char *pathstr;
|
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
|
|
|
char *path_start, *path_end;
|
|
|
|
size_t path_component_len;
|
2006-05-01 06:51:14 +00:00
|
|
|
char *retstr;
|
2010-11-22 21:05:55 +00:00
|
|
|
char *path;
|
|
|
|
char *dir_end;
|
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
|
|
|
|
2007-05-21 20:31:45 +00:00
|
|
|
/*
|
|
|
|
* 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.)
|
|
|
|
*/
|
|
|
|
if (getenv("WIRESHARK_RUN_FROM_BUILD_DIRECTORY") != NULL
|
|
|
|
&& !started_with_special_privs())
|
|
|
|
running_in_build_directory_flag = TRUE;
|
|
|
|
|
2009-03-22 00:42:33 +00:00
|
|
|
#ifdef DLADDR_FINDS_EXECUTABLE_PATH
|
|
|
|
/*
|
|
|
|
* Try to use dladdr() to find the pathname of the executable.
|
2009-03-22 18:06:06 +00:00
|
|
|
* dladdr() is not guaranteed to give you anything better than
|
|
|
|
* argv[0] (i.e., it might not contain a / at all, much less
|
|
|
|
* being an absolute path), and doesn't appear to do so on
|
|
|
|
* Linux, but on other platforms it could give you an absolute
|
|
|
|
* path and obviate the need for us to determine the absolute
|
|
|
|
* path.
|
2009-03-22 00:42:33 +00:00
|
|
|
*/
|
2009-03-22 18:06:06 +00:00
|
|
|
if (dladdr((void *)main_addr, &info))
|
|
|
|
arg0 = info.dli_fname;
|
2009-03-22 00:42:33 +00:00
|
|
|
#endif
|
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
|
|
|
/*
|
|
|
|
* Try to figure out the directory in which the currently running
|
2009-03-22 18:06:06 +00:00
|
|
|
* program resides, given something purporting to be the executable
|
|
|
|
* name (from dladdr() or from the argv[0] it was started with.
|
|
|
|
* That might be the absolute path of the program, or a path relative
|
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
|
|
|
* 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....
|
|
|
|
*/
|
|
|
|
if (arg0[0] == '/') {
|
|
|
|
/*
|
|
|
|
* It's an absolute path.
|
|
|
|
*/
|
|
|
|
prog_pathname = g_strdup(arg0);
|
|
|
|
} else if (strchr(arg0, '/') != NULL) {
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2006-05-01 06:51:14 +00:00
|
|
|
return g_strdup_printf("pathconf failed: %s\n",
|
2011-06-28 09:00:11 +00:00
|
|
|
g_strerror(errno));
|
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
|
|
|
}
|
2010-03-02 00:06:20 +00:00
|
|
|
curdir = (char *)g_malloc(path_max);
|
2006-05-18 12:01:33 +00:00
|
|
|
if (getcwd(curdir, path_max) == NULL) {
|
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
|
|
|
/*
|
|
|
|
* It failed - give up, and just stick
|
|
|
|
* with DATAFILE_DIR.
|
|
|
|
*/
|
|
|
|
g_free(curdir);
|
2006-05-01 06:51:14 +00:00
|
|
|
return g_strdup_printf("getcwd failed: %s\n",
|
2011-06-28 09:00:11 +00:00
|
|
|
g_strerror(errno));
|
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
|
|
|
}
|
2008-02-03 15:38:20 +00:00
|
|
|
path = g_strdup_printf("%s/%s", curdir, 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
|
|
|
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 */
|
2006-05-01 06:51:14 +00:00
|
|
|
pathstr = getenv("PATH");
|
|
|
|
path_start = pathstr;
|
2006-02-14 09:08:12 +00:00
|
|
|
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;
|
2010-03-02 00:06:20 +00:00
|
|
|
path = (char *)g_malloc(path_component_len + 1
|
2006-02-14 09:08:12 +00:00
|
|
|
+ strlen(arg0) + 1);
|
|
|
|
memcpy(path, path_start, path_component_len);
|
|
|
|
path[path_component_len] = '\0';
|
2008-02-03 15:38:20 +00:00
|
|
|
strncat(path, "/", 2);
|
|
|
|
strncat(path, arg0, strlen(arg0) + 1);
|
2006-02-14 09:08:12 +00:00
|
|
|
if (access(path, X_OK) == 0) {
|
|
|
|
/*
|
|
|
|
* Found it!
|
|
|
|
*/
|
|
|
|
prog_pathname = path;
|
|
|
|
break;
|
|
|
|
}
|
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-02-14 09:08:12 +00:00
|
|
|
* That's not it. If there are more
|
|
|
|
* path components to test, try them.
|
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-02-14 09:08:12 +00:00
|
|
|
if (*path_end == '\0') {
|
|
|
|
/*
|
|
|
|
* There's nothing more to try.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*path_end == ':')
|
|
|
|
path_end++;
|
|
|
|
path_start = path_end;
|
|
|
|
g_free(path);
|
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
|
|
|
if (prog_pathname == NULL) {
|
|
|
|
/*
|
|
|
|
* Program not found in path.
|
|
|
|
*/
|
|
|
|
return g_strdup_printf("\"%s\" not found in \"%s\"",
|
|
|
|
arg0, pathstr);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* PATH isn't set.
|
|
|
|
* XXX - should we pick a default?
|
|
|
|
*/
|
|
|
|
return g_strdup("PATH isn't set");
|
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
|
|
|
/*
|
|
|
|
* 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) {
|
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
|
|
|
* Found it. Strip off the last component,
|
|
|
|
* as that's the path of the program.
|
|
|
|
*/
|
|
|
|
*dir_end = '\0';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is there a "/.libs" at the end?
|
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
|
|
|
*/
|
|
|
|
dir_end = strrchr(prog_pathname, '/');
|
|
|
|
if (dir_end != NULL) {
|
2006-05-01 06:51:14 +00:00
|
|
|
if (strcmp(dir_end, "/.libs") == 0) {
|
|
|
|
/*
|
|
|
|
* Yup, it's ".libs".
|
|
|
|
* Strip that off; it's an
|
|
|
|
* artifact of libtool.
|
|
|
|
*/
|
|
|
|
*dir_end = '\0';
|
2007-05-21 20:31:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This presumably means we're run from
|
|
|
|
* the libtool wrapper, which probably
|
|
|
|
* means we're being run from the build
|
|
|
|
* directory. If we weren't started
|
|
|
|
* with special privileges, set
|
|
|
|
* running_in_build_directory_flag.
|
|
|
|
*
|
|
|
|
* XXX - should we check whether what
|
|
|
|
* follows ".libs/" begins with "lt-"?
|
|
|
|
*/
|
|
|
|
if (!started_with_special_privs())
|
|
|
|
running_in_build_directory_flag = TRUE;
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
return progfile_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the directory in which the global configuration and data files are
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* On UN*X, we use the DATAFILE_DIR value supplied by the configure
|
2007-05-21 20:31:45 +00:00
|
|
|
* script, unless we think we're being run from the build directory,
|
|
|
|
* in which case we use the directory in which the executable for this
|
|
|
|
* process resides.
|
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)
|
|
|
|
{
|
2004-09-11 23:03:36 +00:00
|
|
|
#ifdef _WIN32
|
2006-08-26 17:55:21 +00:00
|
|
|
char *u3deviceexecpath;
|
|
|
|
#endif
|
2010-03-02 00:06:20 +00:00
|
|
|
static const char *datafile_dir = NULL;
|
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
|
|
|
|
2006-09-02 06:39:09 +00:00
|
|
|
if (datafile_dir != NULL)
|
2006-08-26 17:55:21 +00:00
|
|
|
return datafile_dir;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
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
|
|
|
/*
|
|
|
|
* See if we are running in a U3 environment.
|
|
|
|
*/
|
2006-08-26 17:55:21 +00:00
|
|
|
u3deviceexecpath = getenv_utf8("U3_DEVICE_EXEC_PATH");
|
|
|
|
|
2006-09-02 06:39:09 +00:00
|
|
|
if (u3deviceexecpath != 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
|
|
|
/*
|
|
|
|
* We are; use the U3 device executable path.
|
|
|
|
*/
|
2006-08-26 17:55:21 +00:00
|
|
|
datafile_dir = u3deviceexecpath;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2006-09-02 06:39:09 +00:00
|
|
|
if (progfile_dir != NULL) {
|
|
|
|
/*
|
|
|
|
* Yes, we do; use that.
|
|
|
|
*/
|
2006-08-26 17:55:21 +00:00
|
|
|
datafile_dir = progfile_dir;
|
2006-09-02 06:39:09 +00:00
|
|
|
} else {
|
2006-08-26 17:55:21 +00:00
|
|
|
/*
|
2006-09-02 06:39:09 +00:00
|
|
|
* No, we don't.
|
|
|
|
* Fall back on the default installation directory.
|
|
|
|
*/
|
2006-08-26 17:55:21 +00:00
|
|
|
datafile_dir = "C:\\Program Files\\Wireshark\\";
|
2006-09-02 06:39:09 +00:00
|
|
|
}
|
2006-08-26 17:55:21 +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
|
2007-05-21 20:31:45 +00:00
|
|
|
if (running_in_build_directory_flag && progfile_dir != 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-21 20:31:45 +00:00
|
|
|
* We're (probably) being run from the build directory and
|
|
|
|
* weren't started with special privileges, and we were
|
|
|
|
* able to determine the directory in which the program
|
|
|
|
* was found, so use that.
|
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
|
|
|
*/
|
|
|
|
datafile_dir = progfile_dir;
|
|
|
|
} else {
|
|
|
|
/*
|
2008-03-15 18:31:52 +00:00
|
|
|
* Return the directory specified when the build was
|
|
|
|
* configured, prepending the run path prefix if it exists.
|
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
|
|
|
*/
|
2008-03-15 18:31:52 +00:00
|
|
|
if (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(getenv("WIRESHARK_DATA_DIR"));
|
|
|
|
} else {
|
|
|
|
datafile_dir = 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
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
return datafile_dir;
|
|
|
|
}
|
|
|
|
|
2009-05-29 21:10:40 +00:00
|
|
|
#ifdef HAVE_PYTHON
|
|
|
|
/*
|
|
|
|
* Find the directory where the python dissectors are stored.
|
|
|
|
*
|
|
|
|
* On Windows, we use the "py_dissector" subdirectory of the datafile directory.
|
|
|
|
*
|
2009-06-01 17:28:20 +00:00
|
|
|
* On UN*X, we use the PYTHON_DIR value supplied by the configure
|
2009-05-29 21:10:40 +00:00
|
|
|
* script, unless we think we're being run from the build directory,
|
|
|
|
* in which case we use the "py_dissector" subdirectory of the datafile directory.
|
|
|
|
*
|
|
|
|
* In both cases, we then use the subdirectory of that directory whose
|
|
|
|
* name is the version number.
|
|
|
|
*
|
|
|
|
* XXX - if we think we're being run from the build directory, perhaps we
|
|
|
|
* should have the plugin code not look in the version subdirectory
|
|
|
|
* of the plugin directory, but look in all of the subdirectories
|
|
|
|
* of the plugin directory, so it can just fetch the plugins built
|
|
|
|
* as part of the build process.
|
|
|
|
*/
|
|
|
|
static const char *wspython_dir = NULL;
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_wspython_dir(void)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
/*
|
|
|
|
* On Windows, the data file directory is the installation
|
|
|
|
* directory; the python dissectors 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.
|
|
|
|
*/
|
|
|
|
wspython_dir = g_strdup_printf("%s\\python\\%s", get_datafile_dir(),
|
|
|
|
VERSION);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure that pathname refers to a directory.
|
|
|
|
*/
|
|
|
|
if (test_for_directory(wspython_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}\python 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 python dissectors.
|
|
|
|
*/
|
|
|
|
g_free( (gpointer) wspython_dir);
|
|
|
|
wspython_dir = g_strdup_printf("%s\\python", get_datafile_dir());
|
|
|
|
running_in_build_directory_flag = TRUE;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
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
|
|
|
|
* the "python" subdirectory of the datafile directory
|
|
|
|
* (the datafile directory is the build directory).
|
|
|
|
*/
|
|
|
|
wspython_dir = g_strdup_printf("%s/epan/wspython/", get_datafile_dir());
|
|
|
|
} else {
|
|
|
|
if (getenv("WIRESHARK_PYTHON_DIR") && !started_with_special_privs()) {
|
|
|
|
/*
|
|
|
|
* The user specified a different directory for plugins
|
|
|
|
* and we aren't running with special privileges.
|
|
|
|
*/
|
|
|
|
wspython_dir = g_strdup(getenv("WIRESHARK_PYTHON_DIR"));
|
|
|
|
} else {
|
|
|
|
wspython_dir = PYTHON_DIR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif /* HAVE_PYTHON */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the directory in which the python dissectors are stored.
|
|
|
|
*/
|
|
|
|
const char *
|
|
|
|
get_wspython_dir(void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_PYTHON
|
|
|
|
if (!wspython_dir) init_wspython_dir();
|
|
|
|
return wspython_dir;
|
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-23 17:52:18 +00:00
|
|
|
#if defined(HAVE_PLUGINS) || defined(HAVE_LUA_5_1)
|
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.
|
|
|
|
*
|
|
|
|
* On Windows, we use the "plugin" subdirectory of the datafile directory.
|
|
|
|
*
|
|
|
|
* On UN*X, we use the PLUGIN_DIR value supplied by the configure
|
2007-05-21 20:31:45 +00:00
|
|
|
* script, unless we think we're being run from the build directory,
|
|
|
|
* in which case we use the "plugin" subdirectory of the datafile directory.
|
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
|
|
|
*
|
|
|
|
* In both cases, we then use the subdirectory of that directory whose
|
|
|
|
* name is the version number.
|
|
|
|
*
|
2007-05-21 20:31:45 +00:00
|
|
|
* XXX - if we think we're being run from the build directory, perhaps we
|
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
|
|
|
* should have the plugin code not look in the version subdirectory
|
|
|
|
* of the plugin directory, but look in all of the subdirectories
|
|
|
|
* of the plugin directory, so it can just fetch the plugins built
|
|
|
|
* as part of the build process.
|
|
|
|
*/
|
2007-05-25 17:22:32 +00:00
|
|
|
static const char *plugin_dir = 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)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
plugin_dir = g_strdup_printf("%s\\plugins\\%s", get_datafile_dir(),
|
2011-03-29 21:39:15 +00:00
|
|
|
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
|
|
|
|
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 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
|
|
|
* Make sure that pathname refers to 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
|
|
|
*/
|
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
|
|
|
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.
|
|
|
|
*/
|
2007-01-15 04:22:10 +00:00
|
|
|
g_free( (gpointer) plugin_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
|
|
|
plugin_dir = g_strdup_printf("%s\\plugins", get_datafile_dir());
|
|
|
|
running_in_build_directory_flag = TRUE;
|
|
|
|
}
|
|
|
|
#else
|
2007-05-21 20:31:45 +00:00
|
|
|
if (running_in_build_directory_flag) {
|
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-21 20:31:45 +00:00
|
|
|
* We're (probably) being run from the build directory and
|
|
|
|
* weren't started with special privileges, so we'll use
|
|
|
|
* the "plugins" subdirectory of the datafile directory
|
|
|
|
* (the datafile directory is the build directory).
|
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
|
|
|
*/
|
|
|
|
plugin_dir = g_strdup_printf("%s/plugins", get_datafile_dir());
|
2008-03-15 18:31:52 +00:00
|
|
|
} else {
|
|
|
|
if (getenv("WIRESHARK_PLUGIN_DIR") && !started_with_special_privs()) {
|
|
|
|
/*
|
|
|
|
* The user specified a different directory for plugins
|
|
|
|
* and we aren't running with special privileges.
|
|
|
|
*/
|
|
|
|
plugin_dir = g_strdup(getenv("WIRESHARK_PLUGIN_DIR"));
|
|
|
|
} else {
|
|
|
|
plugin_dir = PLUGIN_DIR;
|
|
|
|
}
|
|
|
|
}
|
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
|
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
|
|
|
}
|
2009-10-23 17:52:18 +00:00
|
|
|
#endif /* HAVE_PLUGINS || HAVE_LUA_5_1 */
|
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 *
|
|
|
|
get_plugin_dir(void)
|
|
|
|
{
|
2009-10-23 17:52:18 +00:00
|
|
|
#if defined(HAVE_PLUGINS) || defined(HAVE_LUA_5_1)
|
2007-05-25 17:22:32 +00:00
|
|
|
if (!plugin_dir) init_plugin_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
|
|
|
return plugin_dir;
|
2007-08-24 00:03:02 +00:00
|
|
|
#else
|
2008-03-15 18:31:52 +00:00
|
|
|
return NULL;
|
2007-08-24 00:03:02 +00:00
|
|
|
#endif
|
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)
|
|
|
|
{
|
|
|
|
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,
|
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
|
|
|
* there's no "/etc" directory, so we get them from the global
|
|
|
|
* 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
|
2001-10-21 21:48:00 +00:00
|
|
|
return get_datafile_dir();
|
|
|
|
#else
|
|
|
|
return "/etc";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-10-22 23:16:01 +00:00
|
|
|
/*
|
|
|
|
* Name of directory, under the user's home directory, in which
|
|
|
|
* personal configuration files are stored.
|
2001-10-24 06:13:07 +00:00
|
|
|
*/
|
2004-09-11 23:03:36 +00:00
|
|
|
#ifdef _WIN32
|
2006-05-28 19:49:07 +00:00
|
|
|
#define PF_DIR "Wireshark"
|
2001-10-24 06:13:07 +00:00
|
|
|
#else
|
|
|
|
/*
|
2001-10-22 23:16:01 +00:00
|
|
|
* XXX - should this be ".libepan"? For backwards-compatibility, I'll keep
|
2006-05-28 19:49:07 +00:00
|
|
|
* it ".wireshark" for now.
|
2001-10-22 23:16:01 +00:00
|
|
|
*/
|
2006-05-28 19:49:07 +00:00
|
|
|
#define PF_DIR ".wireshark"
|
2001-10-24 06:13:07 +00:00
|
|
|
#endif
|
2001-10-22 23:16:01 +00:00
|
|
|
|
2008-01-15 19:39:31 +00:00
|
|
|
void
|
2008-01-14 16:40:23 +00:00
|
|
|
set_profile_name(const gchar *profilename)
|
|
|
|
{
|
2009-03-13 22:06:48 +00:00
|
|
|
g_free (persconfprofile);
|
2008-01-15 19:39:31 +00:00
|
|
|
|
2008-02-26 18:58:12 +00:00
|
|
|
if (profilename && strlen(profilename) > 0 &&
|
2008-01-27 14:45:31 +00:00
|
|
|
strcmp(profilename, DEFAULT_PROFILE) != 0) {
|
2008-01-14 16:40:23 +00:00
|
|
|
persconfprofile = g_strdup (profilename);
|
|
|
|
} else {
|
|
|
|
/* Default Profile */
|
|
|
|
persconfprofile = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
get_profile_name(void)
|
|
|
|
{
|
2008-01-24 17:06:22 +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)
|
|
|
|
{
|
|
|
|
return (!persconfprofile || strcmp(persconfprofile, DEFAULT_PROFILE) == 0) ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
2011-02-26 17:23:24 +00:00
|
|
|
gboolean
|
|
|
|
has_global_profiles(void)
|
|
|
|
{
|
|
|
|
WS_DIR *dir;
|
|
|
|
WS_DIRENT *file;
|
|
|
|
const gchar *global_dir = get_global_profiles_dir();
|
|
|
|
gchar *filename;
|
|
|
|
gboolean has_global = FALSE;
|
|
|
|
|
|
|
|
if ((test_for_directory(global_dir) == EISDIR) &&
|
|
|
|
((dir = ws_dir_open(global_dir, 0, NULL)) != NULL))
|
|
|
|
{
|
|
|
|
while ((file = ws_dir_read_name(dir)) != NULL) {
|
|
|
|
filename = g_strdup_printf ("%s%s%s", global_dir, G_DIR_SEPARATOR_S,
|
2011-03-29 21:39:15 +00:00
|
|
|
ws_dir_get_name(file));
|
2011-02-26 17:23:24 +00:00
|
|
|
if (test_for_directory(filename) == EISDIR) {
|
|
|
|
has_global = TRUE;
|
|
|
|
g_free (filename);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
ws_dir_close(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
return has_global;
|
|
|
|
}
|
|
|
|
|
2009-12-21 12:32:31 +00:00
|
|
|
void
|
|
|
|
profile_store_persconffiles(gboolean store)
|
|
|
|
{
|
|
|
|
if (store) {
|
|
|
|
profile_files = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
}
|
|
|
|
do_store_persconffiles = store;
|
|
|
|
}
|
|
|
|
|
2001-10-22 23:16:01 +00:00
|
|
|
/*
|
|
|
|
* Get the directory in which personal configuration files reside;
|
2006-05-28 19:49:07 +00:00
|
|
|
* in UNIX-compatible systems, it's ".wireshark", under the user's home
|
|
|
|
* directory, and on Windows systems, it's "Wireshark", under %APPDATA%
|
2001-10-24 06:13:07 +00:00
|
|
|
* or, if %APPDATA% isn't set, it's "%USERPROFILE%\Application Data"
|
|
|
|
* (which is what %APPDATA% normally is on Windows 2000).
|
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
|
|
|
{
|
2004-09-11 23:03:36 +00:00
|
|
|
#ifdef _WIN32
|
2001-10-24 06:13:07 +00:00
|
|
|
char *appdatadir;
|
|
|
|
char *userprofiledir;
|
2006-08-26 17:55:21 +00:00
|
|
|
char *u3appdatapath;
|
2001-10-24 06:13:07 +00:00
|
|
|
#else
|
2005-07-23 11:41:25 +00:00
|
|
|
const char *homedir;
|
2000-09-28 03:16:29 +00:00
|
|
|
struct passwd *pwd;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Return the cached value, if available */
|
2007-03-14 02:55:54 +00:00
|
|
|
if (persconffile_dir != NULL)
|
|
|
|
return persconffile_dir;
|
2001-10-22 23:16:01 +00:00
|
|
|
|
2004-09-11 23:03:36 +00:00
|
|
|
#ifdef _WIN32
|
2000-09-28 03:16:29 +00:00
|
|
|
/*
|
2006-09-02 06:39:09 +00:00
|
|
|
* See if we are running in a U3 environment.
|
2000-09-28 03:16:29 +00:00
|
|
|
*/
|
2006-09-22 22:34:54 +00:00
|
|
|
u3appdatapath = getenv_utf8("U3_APP_DATA_PATH");
|
2006-09-02 06:39:09 +00:00
|
|
|
if (u3appdatapath != NULL) {
|
|
|
|
/*
|
|
|
|
* We are; use the U3 application data path.
|
|
|
|
*/
|
2007-03-14 02:55:54 +00:00
|
|
|
persconffile_dir = u3appdatapath;
|
2001-10-24 06:13:07 +00:00
|
|
|
} else {
|
|
|
|
/*
|
2006-09-02 06:39:09 +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.
|
2001-10-24 06:13:07 +00:00
|
|
|
*/
|
2006-08-26 17:55:21 +00:00
|
|
|
appdatadir = getenv_utf8("APPDATA");
|
|
|
|
if (appdatadir != NULL) {
|
|
|
|
/*
|
|
|
|
* Concatenate %APPDATA% with "\Wireshark".
|
|
|
|
*/
|
2007-03-14 02:55:54 +00:00
|
|
|
persconffile_dir = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
|
2008-01-14 16:40:23 +00:00
|
|
|
appdatadir, PF_DIR);
|
2001-10-24 06:13:07 +00:00
|
|
|
} else {
|
|
|
|
/*
|
2006-08-26 17:55:21 +00:00
|
|
|
* OK, %APPDATA% wasn't set, so use
|
|
|
|
* %USERPROFILE%\Application Data.
|
2001-10-24 06:13:07 +00:00
|
|
|
*/
|
2006-08-26 17:55:21 +00:00
|
|
|
userprofiledir = getenv_utf8("USERPROFILE");
|
|
|
|
if (userprofiledir != NULL) {
|
2007-03-14 02:55:54 +00:00
|
|
|
persconffile_dir = g_strdup_printf(
|
2006-09-02 06:39:09 +00:00
|
|
|
"%s" G_DIR_SEPARATOR_S "Application Data" G_DIR_SEPARATOR_S "%s",
|
|
|
|
userprofiledir, PF_DIR);
|
2006-08-26 17:55:21 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Give up and use "C:".
|
|
|
|
*/
|
2007-03-14 02:55:54 +00:00
|
|
|
persconffile_dir = g_strdup_printf("C:" G_DIR_SEPARATOR_S "%s", PF_DIR);
|
2006-08-26 17:55:21 +00:00
|
|
|
}
|
2001-10-24 06:13:07 +00:00
|
|
|
}
|
2000-09-28 03:16:29 +00:00
|
|
|
}
|
|
|
|
#else
|
2001-10-22 23:16:01 +00:00
|
|
|
/*
|
|
|
|
* If $HOME is set, use that.
|
|
|
|
*/
|
|
|
|
homedir = getenv("HOME");
|
|
|
|
if (homedir == NULL) {
|
2000-09-28 03:16:29 +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) {
|
|
|
|
/*
|
|
|
|
* This is cached, so we don't need to worry
|
|
|
|
* about allocating multiple ones of them.
|
|
|
|
*/
|
2001-10-22 23:16:01 +00:00
|
|
|
homedir = g_strdup(pwd->pw_dir);
|
2000-09-28 03:16:29 +00:00
|
|
|
} else
|
2001-10-22 23:16:01 +00:00
|
|
|
homedir = "/tmp";
|
2000-09-28 03:16:29 +00:00
|
|
|
}
|
2007-03-14 02:55:54 +00:00
|
|
|
persconffile_dir = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", homedir, PF_DIR);
|
2001-10-24 06:13:07 +00:00
|
|
|
#endif
|
|
|
|
|
2007-03-14 02:55:54 +00:00
|
|
|
return persconffile_dir;
|
2001-10-22 22:59:26 +00:00
|
|
|
}
|
2001-10-23 05:01:02 +00:00
|
|
|
|
2008-01-14 16:40:23 +00:00
|
|
|
const char *
|
|
|
|
get_profiles_dir(void)
|
|
|
|
{
|
|
|
|
static char *profiles_dir = NULL;
|
|
|
|
|
2009-03-13 22:06:48 +00:00
|
|
|
g_free (profiles_dir);
|
2008-01-14 16:40:23 +00:00
|
|
|
profiles_dir = g_strdup_printf ("%s%s%s", get_persconffile_dir_no_profile (),
|
|
|
|
G_DIR_SEPARATOR_S, PROFILES_DIR);
|
|
|
|
|
|
|
|
return profiles_dir;
|
|
|
|
}
|
|
|
|
|
2011-02-26 17:23:24 +00:00
|
|
|
const char *
|
|
|
|
get_global_profiles_dir(void)
|
|
|
|
{
|
|
|
|
static char *global_profiles_dir = NULL;
|
|
|
|
|
|
|
|
if (!global_profiles_dir) {
|
2011-03-29 21:39:15 +00:00
|
|
|
global_profiles_dir = g_strdup_printf ("%s%s%s", get_datafile_dir(),
|
|
|
|
G_DIR_SEPARATOR_S, PROFILES_DIR);
|
2011-02-26 17:23:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return global_profiles_dir;
|
|
|
|
}
|
|
|
|
|
2008-01-14 16:40:23 +00:00
|
|
|
static const char *
|
|
|
|
get_persconffile_dir(const gchar *profilename)
|
|
|
|
{
|
|
|
|
static char *persconffile_profile_dir = NULL;
|
|
|
|
|
2009-03-13 22:06:48 +00:00
|
|
|
g_free (persconffile_profile_dir);
|
2008-01-14 16:40:23 +00:00
|
|
|
|
2008-01-27 14:45:31 +00:00
|
|
|
if (profilename && strlen(profilename) > 0 &&
|
|
|
|
strcmp(profilename, DEFAULT_PROFILE) != 0) {
|
2008-02-26 18:58:12 +00:00
|
|
|
persconffile_profile_dir = g_strdup_printf ("%s%s%s", get_profiles_dir (),
|
2008-01-27 14:45:31 +00:00
|
|
|
G_DIR_SEPARATOR_S, profilename);
|
2008-01-14 16:40:23 +00:00
|
|
|
} else {
|
2008-12-20 00:12:54 +00:00
|
|
|
persconffile_profile_dir = g_strdup (get_persconffile_dir_no_profile ());
|
2008-01-14 16:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return persconffile_profile_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2011-02-26 17:23:24 +00:00
|
|
|
profile_exists(const gchar *profilename, gboolean global)
|
2008-01-14 16:40:23 +00:00
|
|
|
{
|
2011-02-26 17:23:24 +00:00
|
|
|
if (global) {
|
|
|
|
gchar *path = g_strdup_printf ("%s%s%s", get_global_profiles_dir(),
|
2011-03-29 21:39:15 +00:00
|
|
|
G_DIR_SEPARATOR_S, profilename);
|
2011-02-26 17:23:24 +00:00
|
|
|
if (test_for_directory (path) == EISDIR) {
|
|
|
|
g_free (path);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
g_free (path);
|
|
|
|
} else {
|
|
|
|
if (test_for_directory (get_persconffile_dir (profilename)) == EISDIR) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-01-14 16:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2008-10-27 04:47:57 +00:00
|
|
|
WS_DIR *dir;
|
|
|
|
WS_DIRENT *file;
|
2008-01-14 16:40:23 +00:00
|
|
|
gchar *filename;
|
|
|
|
int ret = 0;
|
|
|
|
|
2008-05-22 15:46:27 +00:00
|
|
|
if ((dir = ws_dir_open(directory, 0, NULL)) != NULL) {
|
|
|
|
while ((file = ws_dir_read_name(dir)) != NULL) {
|
2008-02-26 18:58:12 +00:00
|
|
|
filename = g_strdup_printf ("%s%s%s", directory, G_DIR_SEPARATOR_S,
|
2008-05-22 15:46:27 +00:00
|
|
|
ws_dir_get_name(file));
|
2008-01-14 16:40:23 +00:00
|
|
|
if (test_for_directory(filename) != EISDIR) {
|
2008-05-22 15:46:27 +00:00
|
|
|
ret = ws_remove(filename);
|
2008-01-14 16:40:23 +00:00
|
|
|
#if 0
|
|
|
|
} 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);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (ret != 0) {
|
|
|
|
*pf_dir_path_return = filename;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_free (filename);
|
|
|
|
}
|
2008-05-22 15:46:27 +00:00
|
|
|
ws_dir_close(dir);
|
2008-01-14 16:40:23 +00:00
|
|
|
}
|
2008-01-15 19:39:31 +00:00
|
|
|
|
2008-05-22 15:46:27 +00:00
|
|
|
if (ret == 0 && (ret = ws_remove(directory)) != 0) {
|
2008-01-14 16:40:23 +00:00
|
|
|
*pf_dir_path_return = g_strdup (directory);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
delete_persconffile_profile(const char *profilename, char **pf_dir_path_return)
|
|
|
|
{
|
|
|
|
const char *profile_dir = get_persconffile_dir(profilename);
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (test_for_directory (profile_dir) == EISDIR) {
|
|
|
|
ret = delete_directory (profile_dir, pf_dir_path_return);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rename_persconffile_profile(const char *fromname, const char *toname,
|
|
|
|
char **pf_from_dir_path_return, char **pf_to_dir_path_return)
|
|
|
|
{
|
2008-03-15 18:31:52 +00:00
|
|
|
char *from_dir = g_strdup (get_persconffile_dir(fromname));
|
|
|
|
char *to_dir = g_strdup (get_persconffile_dir(toname));
|
|
|
|
int ret = 0;
|
2008-01-14 16:40:23 +00:00
|
|
|
|
2008-05-22 15:46:27 +00:00
|
|
|
ret = ws_rename (from_dir, to_dir);
|
2008-03-15 18:31:52 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
*pf_from_dir_path_return = g_strdup (from_dir);
|
|
|
|
*pf_to_dir_path_return = g_strdup (to_dir);
|
|
|
|
}
|
2008-01-14 16:40:23 +00:00
|
|
|
|
2008-03-15 18:31:52 +00:00
|
|
|
g_free (from_dir);
|
|
|
|
g_free (to_dir);
|
2008-01-14 16:40:23 +00:00
|
|
|
|
2008-03-15 18:31:52 +00:00
|
|
|
return ret;
|
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
|
|
|
{
|
|
|
|
const char *pf_dir_path;
|
2004-09-11 23:03:36 +00:00
|
|
|
#ifdef _WIN32
|
2001-10-24 09:22:23 +00:00
|
|
|
char *pf_dir_path_copy, *pf_dir_parent_path;
|
2002-01-04 21:50:26 +00:00
|
|
|
size_t pf_dir_parent_path_len;
|
2001-10-24 09:22:23 +00:00
|
|
|
#endif
|
2011-04-10 20:59:10 +00:00
|
|
|
ws_statb64 s_buf;
|
2001-10-23 05:01:02 +00:00
|
|
|
int ret;
|
2008-01-15 19:39:31 +00:00
|
|
|
|
2008-01-14 16:40:23 +00:00
|
|
|
if (profilename) {
|
2011-03-23 14:52:39 +00:00
|
|
|
/*
|
|
|
|
* Create the "Default" personal configuration files directory, if necessary.
|
|
|
|
*/
|
2011-03-23 14:58:34 +00:00
|
|
|
if (create_persconffile_profile (NULL, pf_dir_path_return) == -1) {
|
2011-03-23 14:52:39 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-01-14 16:40:23 +00:00
|
|
|
/*
|
|
|
|
* Check if profiles directory exists.
|
|
|
|
* If not then create it.
|
|
|
|
*/
|
|
|
|
pf_dir_path = get_profiles_dir ();
|
2011-04-10 20:59:10 +00:00
|
|
|
if (ws_stat64(pf_dir_path, &s_buf) != 0 && errno == ENOENT) {
|
2008-05-22 15:46:27 +00:00
|
|
|
ret = ws_mkdir(pf_dir_path, 0755);
|
2008-01-14 16:40:23 +00:00
|
|
|
if (ret == -1) {
|
|
|
|
*pf_dir_path_return = g_strdup(pf_dir_path);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-10-23 05:01:02 +00:00
|
|
|
|
2008-01-14 16:40:23 +00:00
|
|
|
pf_dir_path = get_persconffile_dir(profilename);
|
2011-04-10 20:59:10 +00:00
|
|
|
if (ws_stat64(pf_dir_path, &s_buf) != 0 && errno == ENOENT) {
|
2004-09-11 23:03:36 +00:00
|
|
|
#ifdef _WIN32
|
2001-10-24 06:13:07 +00:00
|
|
|
/*
|
|
|
|
* Does the parent directory of that directory
|
|
|
|
* exist? %APPDATA% may not exist even though
|
|
|
|
* %USERPROFILE% does.
|
2002-01-04 21:50:26 +00:00
|
|
|
*
|
|
|
|
* We check for the existence of the directory
|
|
|
|
* 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.
|
2001-10-24 06:13:07 +00:00
|
|
|
*/
|
|
|
|
pf_dir_path_copy = g_strdup(pf_dir_path);
|
|
|
|
pf_dir_parent_path = get_dirname(pf_dir_path_copy);
|
2002-01-04 21:50:26 +00:00
|
|
|
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] != ':'
|
2011-04-10 20:59:10 +00:00
|
|
|
&& ws_stat64(pf_dir_parent_path, &s_buf) != 0) {
|
2001-10-24 06:13:07 +00:00
|
|
|
/*
|
2002-01-04 21:50:26 +00:00
|
|
|
* No, it doesn't exist - make it first.
|
2001-10-24 06:13:07 +00:00
|
|
|
*/
|
2008-05-22 15:46:27 +00:00
|
|
|
ret = ws_mkdir(pf_dir_parent_path, 0755);
|
2001-10-24 06:13:07 +00:00
|
|
|
if (ret == -1) {
|
|
|
|
*pf_dir_path_return = pf_dir_parent_path;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free(pf_dir_path_copy);
|
2008-05-22 15:46:27 +00:00
|
|
|
ret = ws_mkdir(pf_dir_path, 0755);
|
2001-10-23 05:01:02 +00:00
|
|
|
#else
|
2008-05-22 15:46:27 +00:00
|
|
|
ret = ws_mkdir(pf_dir_path, 0755);
|
2001-10-23 05:01:02 +00:00
|
|
|
#endif
|
|
|
|
} 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)
|
2001-10-24 06:13:07 +00:00
|
|
|
*pf_dir_path_return = g_strdup(pf_dir_path);
|
2001-10-23 05:01:02 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2001-10-24 07:18:39 +00:00
|
|
|
|
2008-01-14 16:40:23 +00:00
|
|
|
int
|
|
|
|
create_persconffile_dir(char **pf_dir_path_return)
|
|
|
|
{
|
2008-01-24 17:06:22 +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
|
2011-02-26 17:23:24 +00:00
|
|
|
copy_persconffile_profile(const char *toname, const char *fromname, gboolean from_global,
|
2011-03-29 21:39:15 +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-02-26 17:23:24 +00:00
|
|
|
gchar *from_dir;
|
2009-12-21 12:32:31 +00:00
|
|
|
gchar *to_dir = g_strdup (get_persconffile_dir(toname));
|
|
|
|
gchar *filename, *from_file, *to_file;
|
2009-12-21 17:39:37 +00:00
|
|
|
GList *files, *file;
|
2009-12-21 17:28:47 +00:00
|
|
|
|
2011-02-26 17:23:24 +00:00
|
|
|
if (from_global) {
|
|
|
|
if (strcmp(fromname, DEFAULT_PROFILE) == 0) {
|
|
|
|
from_dir = g_strdup (get_global_profiles_dir());
|
|
|
|
} else {
|
|
|
|
from_dir = g_strdup_printf ("%s%s%s", get_global_profiles_dir(), G_DIR_SEPARATOR_S, fromname);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
from_dir = g_strdup (get_persconffile_dir(fromname));
|
|
|
|
}
|
|
|
|
|
2009-12-21 17:39:37 +00:00
|
|
|
files = g_hash_table_get_keys(profile_files);
|
2009-12-21 17:28:47 +00:00
|
|
|
file = g_list_first(files);
|
2009-12-21 12:32:31 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-12-21 17:28:47 +00:00
|
|
|
g_list_free (files);
|
2009-12-21 12:32:31 +00:00
|
|
|
g_free (from_dir);
|
|
|
|
g_free (to_dir);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-01-14 22:25:22 +00:00
|
|
|
/*
|
|
|
|
* Get the (default) directory in which personal data is stored.
|
|
|
|
*
|
2010-03-02 00:06:20 +00:00
|
|
|
* On Win32, this is the "My Documents" folder in the personal profile,
|
|
|
|
* except that, if we're running from a U3 device, this is the
|
|
|
|
* "$U3_DEVICE_DOCUMENT_PATH\My Captures" folder.
|
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
|
2008-03-15 18:31:52 +00:00
|
|
|
char *u3devicedocumentpath;
|
|
|
|
TCHAR tszPath[MAX_PATH];
|
2007-01-14 22:25:22 +00:00
|
|
|
char *szPath;
|
2007-03-14 02:55:54 +00:00
|
|
|
BOOL bRet;
|
|
|
|
|
|
|
|
/* Return the cached value, if available */
|
|
|
|
if (persdatafile_dir != NULL)
|
|
|
|
return persdatafile_dir;
|
|
|
|
|
2007-01-15 19:11:29 +00:00
|
|
|
/*
|
|
|
|
* See if we are running in a U3 environment.
|
|
|
|
*/
|
|
|
|
u3devicedocumentpath = getenv_utf8("U3_DEVICE_DOCUMENT_PATH");
|
2007-01-14 22:25:22 +00:00
|
|
|
|
2007-01-15 19:11:29 +00:00
|
|
|
if (u3devicedocumentpath != NULL) {
|
2010-03-02 00:06:20 +00:00
|
|
|
/* the "My Captures" sub-directory is created (if it doesn't
|
|
|
|
exist) by u3util.exe when the U3 Wireshark is first run */
|
2008-01-15 19:39:31 +00:00
|
|
|
|
2010-03-02 00:06:20 +00:00
|
|
|
szPath = g_strdup_printf("%s%s", u3devicedocumentpath, U3_MY_CAPTURES);
|
2007-01-15 19:11:29 +00:00
|
|
|
|
2007-03-14 02:55:54 +00:00
|
|
|
persdatafile_dir = szPath;
|
2007-01-14 22:25:22 +00:00
|
|
|
return szPath;
|
|
|
|
} else {
|
2010-03-02 00:06:20 +00:00
|
|
|
/*
|
|
|
|
* Hint: SHGetFolderPath is not available on MSVC 6 - without
|
|
|
|
* Platform SDK
|
|
|
|
*/
|
|
|
|
bRet = SHGetSpecialFolderPath(NULL, tszPath, CSIDL_PERSONAL,
|
|
|
|
FALSE);
|
|
|
|
if(bRet == TRUE) {
|
|
|
|
szPath = utf_16to8(tszPath);
|
|
|
|
persdatafile_dir = szPath;
|
|
|
|
return szPath;
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
2007-01-14 22:25:22 +00:00
|
|
|
}
|
|
|
|
#else
|
2010-03-02 00:06:20 +00:00
|
|
|
return "";
|
2007-01-14 22:25:22 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
static const char *home = NULL;
|
|
|
|
char *homedrive, *homepath;
|
|
|
|
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?
|
|
|
|
*/
|
2006-01-12 22:32:29 +00:00
|
|
|
homedrive = getenv_utf8("HOMEDRIVE");
|
2001-10-24 07:18:39 +00:00
|
|
|
if (homedrive != NULL) {
|
2006-01-12 22:32:29 +00:00
|
|
|
homepath = getenv_utf8("HOMEPATH");
|
2001-10-24 07:18:39 +00:00
|
|
|
if (homepath != NULL) {
|
|
|
|
/*
|
|
|
|
* This is cached, so we don't need to worry about
|
|
|
|
* allocating multiple ones of them.
|
|
|
|
*/
|
2008-02-03 15:38:20 +00:00
|
|
|
homestring = g_strdup_printf("%s%s", homedrive, homepath);
|
2001-10-24 07:18:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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:";
|
|
|
|
}
|
2001-10-24 09:22:23 +00:00
|
|
|
|
|
|
|
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 *
|
2008-01-14 16:40:23 +00:00
|
|
|
get_persconffile_path(const char *filename, gboolean from_profile, gboolean for_writing
|
2004-09-11 23:03:36 +00:00
|
|
|
#ifndef _WIN32
|
2002-03-02 20:51:46 +00:00
|
|
|
_U_
|
|
|
|
#endif
|
|
|
|
)
|
2001-10-24 07:18:39 +00:00
|
|
|
{
|
|
|
|
char *path;
|
2004-09-11 23:03:36 +00:00
|
|
|
#ifdef _WIN32
|
2011-04-10 20:59:10 +00:00
|
|
|
ws_statb64 s_buf;
|
2001-10-24 07:18:39 +00:00
|
|
|
char *old_path;
|
|
|
|
#endif
|
2009-12-21 12:32:31 +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));
|
|
|
|
}
|
2001-10-24 07:18:39 +00:00
|
|
|
|
2008-01-14 16:40:23 +00:00
|
|
|
if (from_profile) {
|
2008-01-15 19:39:31 +00:00
|
|
|
path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
|
2008-01-24 17:06:22 +00:00
|
|
|
get_persconffile_dir(persconfprofile), filename);
|
2008-01-14 16:40:23 +00:00
|
|
|
} else {
|
2008-01-15 19:39:31 +00:00
|
|
|
path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
|
2008-01-14 16:40:23 +00:00
|
|
|
get_persconffile_dir(NULL), filename);
|
|
|
|
}
|
2004-09-11 23:03:36 +00:00
|
|
|
#ifdef _WIN32
|
2001-10-24 07:18:39 +00:00
|
|
|
if (!for_writing) {
|
2011-04-10 20:59:10 +00:00
|
|
|
if (ws_stat64(path, &s_buf) != 0 && errno == ENOENT) {
|
2001-10-24 07:18:39 +00:00
|
|
|
/*
|
|
|
|
* OK, it's not in the personal configuration file
|
2006-05-28 19:49:07 +00:00
|
|
|
* directory; is it in the ".wireshark" subdirectory
|
2001-10-24 07:18:39 +00:00
|
|
|
* of their home directory?
|
|
|
|
*/
|
2005-08-08 18:50:39 +00:00
|
|
|
old_path = g_strdup_printf(
|
2006-05-28 19:49:07 +00:00
|
|
|
"%s" G_DIR_SEPARATOR_S ".wireshark" G_DIR_SEPARATOR_S "%s",
|
2001-10-24 07:18:39 +00:00
|
|
|
get_home_dir(), filename);
|
2011-04-10 20:59:10 +00:00
|
|
|
if (ws_stat64(old_path, &s_buf) == 0) {
|
2001-10-24 07:18:39 +00:00
|
|
|
/*
|
|
|
|
* OK, it exists; return it instead.
|
|
|
|
*/
|
|
|
|
g_free(path);
|
|
|
|
path = old_path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return path;
|
2001-10-24 09:22:23 +00:00
|
|
|
}
|
2003-05-15 07:44:54 +00:00
|
|
|
|
2008-01-15 19:39:31 +00:00
|
|
|
/*
|
2007-03-14 02:55:54 +00:00
|
|
|
* process command line option belonging to the filesystem settings
|
|
|
|
* (move this e.g. to main.c and have set_persconffile_dir() instead in this file?)
|
|
|
|
*/
|
|
|
|
int
|
2008-06-23 20:31:21 +00:00
|
|
|
filesystem_opt(int opt _U_, const char *optstr)
|
2007-03-14 02:55:54 +00:00
|
|
|
{
|
2008-03-15 18:31:52 +00:00
|
|
|
gchar *p, *colonp;
|
|
|
|
|
2008-06-23 20:31:21 +00:00
|
|
|
colonp = strchr(optstr, ':');
|
2008-03-15 18:31:52 +00:00
|
|
|
if (colonp == NULL) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = colonp;
|
|
|
|
*p++ = '\0';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip over any white space (there probably won't be any, but
|
|
|
|
* as we allow it in the preferences file, we might as well
|
|
|
|
* allow it here).
|
|
|
|
*/
|
|
|
|
while (isspace((guchar)*p))
|
2008-06-23 20:31:21 +00:00
|
|
|
p++;
|
2008-03-15 18:31:52 +00:00
|
|
|
if (*p == '\0') {
|
|
|
|
/*
|
|
|
|
* Put the colon back, so if our caller uses, in an
|
|
|
|
* error message, the string they passed us, the message
|
|
|
|
* looks correct.
|
|
|
|
*/
|
|
|
|
*colonp = ':';
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* directory should be existing */
|
|
|
|
/* XXX - is this a requirement? */
|
|
|
|
if(test_for_directory(p) != EISDIR) {
|
|
|
|
/*
|
|
|
|
* Put the colon back, so if our caller uses, in an
|
|
|
|
* error message, the string they passed us, the message
|
|
|
|
* looks correct.
|
|
|
|
*/
|
|
|
|
*colonp = ':';
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-06-23 20:31:21 +00:00
|
|
|
if (strcmp(optstr,"persconf") == 0) {
|
2008-03-15 18:31:52 +00:00
|
|
|
persconffile_dir = p;
|
2008-06-23 20:31:21 +00:00
|
|
|
} else if (strcmp(optstr,"persdata") == 0) {
|
2008-03-15 18:31:52 +00:00
|
|
|
persdatafile_dir = p;
|
|
|
|
/* XXX - might need to add the temp file path */
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
*colonp = ':'; /* put the colon back */
|
|
|
|
return 0;
|
2007-03-14 02:55:54 +00:00
|
|
|
}
|
|
|
|
|
2003-05-15 07:44:54 +00:00
|
|
|
/*
|
|
|
|
* Construct the path name of a global configuration file, given the
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
|
2011-03-29 21:39:15 +00:00
|
|
|
return g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", get_datafile_dir(), filename);
|
2003-05-15 07:44:54 +00:00
|
|
|
}
|
|
|
|
|
2009-10-23 17:52:18 +00:00
|
|
|
/* Get the personal plugin dir */
|
|
|
|
/* Return value is malloced so the caller should g_free() it. */
|
|
|
|
char *
|
|
|
|
get_plugins_pers_dir(void)
|
|
|
|
{
|
|
|
|
return get_persconffile_path(PLUGINS_DIR_NAME, FALSE, FALSE);
|
|
|
|
}
|
|
|
|
|
2003-05-15 07:44:54 +00:00
|
|
|
/* Delete a file */
|
|
|
|
gboolean
|
|
|
|
deletefile(const char *path)
|
|
|
|
{
|
2008-05-22 15:46:27 +00:00
|
|
|
return ws_unlink(path) == 0;
|
2003-05-15 07:44:54 +00:00
|
|
|
}
|
2003-11-02 23:12:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct and return the path name of a file in the
|
2003-11-03 22:32:36 +00:00
|
|
|
* appropriate temporary file directory.
|
2003-11-02 23:12:35 +00:00
|
|
|
*/
|
2003-11-03 02:41:07 +00:00
|
|
|
char *get_tempfile_path(const char *filename)
|
2003-11-02 23:12:35 +00:00
|
|
|
{
|
2005-08-08 18:50:39 +00:00
|
|
|
return g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", g_get_tmp_dir(), filename);
|
2003-11-02 23:12:35 +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)
|
|
|
|
{
|
2005-07-23 11:41:25 +00:00
|
|
|
const char *errmsg;
|
2004-01-24 01:44:29 +00:00
|
|
|
static char errmsg_errno[1024+1];
|
|
|
|
|
|
|
|
switch (err) {
|
|
|
|
|
|
|
|
case ENOENT:
|
|
|
|
if (for_writing)
|
2004-12-29 01:08:20 +00:00
|
|
|
errmsg = "The path to the file \"%s\" doesn't exist.";
|
2004-01-24 01:44:29 +00:00
|
|
|
else
|
2004-12-29 01:08:20 +00:00
|
|
|
errmsg = "The file \"%s\" doesn't exist.";
|
2004-01-24 01:44:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EACCES:
|
|
|
|
if (for_writing)
|
2004-12-29 01:08:20 +00:00
|
|
|
errmsg = "You don't have permission to create or write to the file \"%s\".";
|
2004-01-24 01:44:29 +00:00
|
|
|
else
|
2004-12-29 01:08:20 +00:00
|
|
|
errmsg = "You don't have permission to read the file \"%s\".";
|
2004-01-24 01:44:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EISDIR:
|
|
|
|
errmsg = "\"%s\" is a directory (folder), not a file.";
|
|
|
|
break;
|
|
|
|
|
2004-01-24 02:01:44 +00:00
|
|
|
case ENOSPC:
|
|
|
|
errmsg = "The file \"%s\" could not be created because there is no space left on the file system.";
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef EDQUOT
|
|
|
|
case EDQUOT:
|
|
|
|
errmsg = "The file \"%s\" could not be created because you are too close to, or over, your disk quota.";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2007-03-02 21:17:44 +00:00
|
|
|
case EINVAL:
|
|
|
|
errmsg = "The file \"%s\" could not be created because an invalid filename was specified.";
|
|
|
|
break;
|
|
|
|
|
2004-01-24 01:44:29 +00:00
|
|
|
default:
|
2005-08-08 18:50:39 +00:00
|
|
|
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
|
2011-03-29 21:39:15 +00:00
|
|
|
"The file \"%%s\" could not be %s: %s.",
|
|
|
|
for_writing ? "created" : "opened",
|
2011-06-28 09:00:11 +00:00
|
|
|
g_strerror(err));
|
2004-01-24 01:44:29 +00:00
|
|
|
errmsg = errmsg_errno;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return errmsg;
|
|
|
|
}
|
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)
|
|
|
|
{
|
2005-07-23 11:41:25 +00:00
|
|
|
const char *errmsg;
|
2004-01-24 02:01:44 +00:00
|
|
|
static char errmsg_errno[1024+1];
|
|
|
|
|
|
|
|
switch (err) {
|
|
|
|
|
|
|
|
case ENOSPC:
|
|
|
|
errmsg = "The file \"%s\" could not be saved because there is no space left on the file system.";
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef EDQUOT
|
|
|
|
case EDQUOT:
|
|
|
|
errmsg = "The file \"%s\" could not be saved because you are too close to, or over, your disk quota.";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2010-06-16 01:30:29 +00:00
|
|
|
case WTAP_ERR_SHORT_WRITE:
|
|
|
|
errmsg = "A full write couldn't be done to the file \"%s\".";
|
|
|
|
break;
|
|
|
|
|
2004-01-24 02:01:44 +00:00
|
|
|
default:
|
2005-08-08 18:50:39 +00:00
|
|
|
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
|
2011-03-29 21:39:15 +00:00
|
|
|
"An error occurred while writing to the file \"%%s\": %s.",
|
2011-06-28 09:00:11 +00:00
|
|
|
g_strerror(err));
|
2004-01-24 02:01:44 +00:00
|
|
|
errmsg = errmsg_errno;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return errmsg;
|
|
|
|
}
|
|
|
|
|
2005-04-12 21:12:19 +00:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
file_exists(const char *fname)
|
|
|
|
{
|
2011-04-10 20:59:10 +00:00
|
|
|
ws_statb64 file_stat;
|
2005-04-12 21:12:19 +00:00
|
|
|
|
2006-02-08 00:06:38 +00:00
|
|
|
#ifdef _WIN32
|
2008-03-15 18:31:52 +00:00
|
|
|
/*
|
|
|
|
* This is a bit tricky on win32. The st_ino field is documented as:
|
|
|
|
* "The inode, and therefore st_ino, has no meaning in the FAT, ..."
|
|
|
|
* but it *is* set to zero if stat() returns without an error,
|
|
|
|
* so this is working, but maybe not quite the way expected. ULFL
|
|
|
|
*/
|
|
|
|
file_stat.st_ino = 1; /* this will make things work if an error occured */
|
2011-04-10 20:59:10 +00:00
|
|
|
ws_stat64(fname, &file_stat);
|
2008-03-15 18:31:52 +00:00
|
|
|
if (file_stat.st_ino == 0) {
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2006-02-08 00:06:38 +00:00
|
|
|
#else
|
2011-04-10 20:59:10 +00:00
|
|
|
if (ws_stat64(fname, &file_stat) != 0 && errno == ENOENT) {
|
2008-03-15 18:31:52 +00:00
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
return TRUE;
|
|
|
|
}
|
2006-02-08 00:06:38 +00:00
|
|
|
#endif
|
2005-04-12 21:12:19 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2008-03-15 18:31:52 +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
|
2008-03-15 18:31:52 +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-04-10 20:59:10 +00:00
|
|
|
ws_statb64 filestat1, filestat2;
|
2008-03-15 18:31:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Compare st_dev and st_ino.
|
|
|
|
*/
|
2011-04-10 20:59:10 +00:00
|
|
|
if (ws_stat64(fname1, &filestat1) == -1)
|
2008-03-15 18:31:52 +00:00
|
|
|
return FALSE; /* can't get info about the first file */
|
2011-04-10 20:59:10 +00:00
|
|
|
if (ws_stat64(fname2, &filestat2) == -1)
|
2008-03-15 18:31:52 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
int from_fd, to_fd, nread, nwritten, err;
|
2011-03-29 21:39:15 +00:00
|
|
|
guint8 *pd = NULL;
|
2009-02-15 21:47:57 +00:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2011-03-29 21:39:15 +00:00
|
|
|
#define FS_READ_SIZE 65536
|
|
|
|
pd = g_malloc(FS_READ_SIZE);
|
|
|
|
while ((nread = ws_read(from_fd, pd, FS_READ_SIZE)) > 0) {
|
2009-02-15 21:47:57 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
ws_close(from_fd);
|
|
|
|
if (ws_close(to_fd) < 0) {
|
|
|
|
report_write_failure(to_filename, errno);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2011-03-29 21:39:15 +00:00
|
|
|
g_free(pd);
|
|
|
|
pd = NULL;
|
2009-02-15 21:47:57 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
done:
|
2011-03-29 21:39:15 +00:00
|
|
|
g_free(pd);
|
2009-02-15 21:47:57 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-03-15 18:31:52 +00:00
|
|
|
/*
|
|
|
|
* Editor modelines
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 4
|
2008-09-02 11:17:03 +00:00
|
|
|
* indent-tabs-mode: t
|
2008-03-15 18:31:52 +00:00
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* ex: set shiftwidth=4 tabstop=4 noexpandtab
|
|
|
|
* :indentSize=4:tabSize=4:noTabs=false:
|
|
|
|
*/
|