Have init_progfile_dir() also check whether

WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set and, if so and we weren't run
with special privileges, set the running_in_build_directory_flag.  Have
it do the same if it finds ".libs" in the pathname of the program and we
weren't run with special privileges, as that means it was probably run
from the libtool wrapper script and presumably thus isn't an installed
binary.

This means that get_credential_info() has to be called before
init_progfile_dir().

Clean up some indentation.

svn path=/trunk/; revision=21866
This commit is contained in:
Guy Harris 2007-05-21 20:31:45 +00:00
parent 4a22b30c36
commit a3d3282e64
4 changed files with 69 additions and 49 deletions

View File

@ -66,16 +66,16 @@ main(int argc, char **argv)
e_prefs *prefs; e_prefs *prefs;
dfilter_t *df; dfilter_t *df;
/*
* Attempt to get the pathname of the executable file.
*/
init_progfile_dir(argv[0]);
/* /*
* Get credential information for later use. * Get credential information for later use.
*/ */
get_credential_info(); get_credential_info();
/*
* Attempt to get the pathname of the executable file.
*/
init_progfile_dir(argv[0]);
/* /*
* Now attempt to get the pathname of the plugins. * Now attempt to get the pathname of the plugins.
*/ */

View File

@ -212,8 +212,16 @@ test_for_fifo(const char *path)
return 0; return 0;
} }
/*
* Directory from which the executable came.
*/
static char *progfile_dir; static char *progfile_dir;
/*
* TRUE if we're running from the build directory.
*/
static gboolean running_in_build_directory_flag = FALSE;
/* /*
* Get the pathname of the directory from which the executable came, * Get the pathname of the directory from which the executable came,
* and save it for future use. Returns NULL on success, and a * and save it for future use. Returns NULL on success, and a
@ -320,6 +328,19 @@ init_progfile_dir(const char *arg0
size_t path_component_len; size_t path_component_len;
char *retstr; char *retstr;
/*
* 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;
/* /*
* Try to figure out the directory in which the currently running * Try to figure out the directory in which the currently running
* program resides, given the argv[0] it was started with. That * program resides, given the argv[0] it was started with. That
@ -452,6 +473,20 @@ init_progfile_dir(const char *arg0
* artifact of libtool. * artifact of libtool.
*/ */
*dir_end = '\0'; *dir_end = '\0';
/*
* 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;
} }
} }
@ -490,9 +525,9 @@ get_progfile_dir(void)
* process resides. * process resides.
* *
* On UN*X, we use the DATAFILE_DIR value supplied by the configure * On UN*X, we use the DATAFILE_DIR value supplied by the configure
* script, unless the WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment * script, unless we think we're being run from the build directory,
* variable is set, in which case we use the directory in which the * in which case we use the directory in which the executable for this
* executable for this process resides. * process resides.
* *
* XXX - if we ever make libwireshark a real library, used by multiple * XXX - if we ever make libwireshark a real library, used by multiple
* applications (more than just TShark and versions of Wireshark with * applications (more than just TShark and versions of Wireshark with
@ -563,13 +598,12 @@ get_datafile_dir(void)
} }
} }
#else #else
if (getenv("WIRESHARK_RUN_FROM_BUILD_DIRECTORY") != NULL if (running_in_build_directory_flag && progfile_dir != NULL) {
&& !started_with_special_privs() && progfile_dir != NULL) {
/* /*
* WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, and * We're (probably) being run from the build directory and
* we weren't started with special privileges, and * weren't started with special privileges, and we were
* we were able to determine the directory in which * able to determine the directory in which the program
* the program was found, so use that. * was found, so use that.
*/ */
datafile_dir = progfile_dir; datafile_dir = progfile_dir;
} else { } else {
@ -590,14 +624,13 @@ get_datafile_dir(void)
* On Windows, we use the "plugin" subdirectory of the datafile directory. * On Windows, we use the "plugin" subdirectory of the datafile directory.
* *
* On UN*X, we use the PLUGIN_DIR value supplied by the configure * On UN*X, we use the PLUGIN_DIR value supplied by the configure
* script, unless the WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment * script, unless we think we're being run from the build directory,
* variable is set, in which case we use the "plugin" subdirectory of * in which case we use the "plugin" subdirectory of the datafile directory.
* the datafile directory.
* *
* In both cases, we then use the subdirectory of that directory whose * In both cases, we then use the subdirectory of that directory whose
* name is the version number. * name is the version number.
* *
* XXX - if WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, perhaps we * 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 * 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, but look in all of the subdirectories
* of the plugin directory, so it can just fetch the plugins built * of the plugin directory, so it can just fetch the plugins built
@ -605,11 +638,6 @@ get_datafile_dir(void)
*/ */
static const char *plugin_dir; static const char *plugin_dir;
/*
* TRUE if we're running from the build directory.
*/
static gboolean running_in_build_directory_flag = FALSE;
void void
init_plugin_dir(void) init_plugin_dir(void)
{ {
@ -647,22 +675,14 @@ init_plugin_dir(void)
running_in_build_directory_flag = TRUE; running_in_build_directory_flag = TRUE;
} }
#else #else
if (getenv("WIRESHARK_RUN_FROM_BUILD_DIRECTORY") != NULL if (running_in_build_directory_flag) {
&& !started_with_special_privs()) {
/* /*
* WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, and * We're (probably) being run from the build directory and
* we weren't started with special privileges, so * weren't started with special privileges, so we'll use
* we'll use the "plugins" subdirectory of the * the "plugins" subdirectory of the datafile directory
* datafile directory (the datafile directory is * (the datafile directory is the build directory).
* the build 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. (If we were started with special
* privileges, it's not safe to allow the user to
* point us to some other directory.)
*/ */
plugin_dir = g_strdup_printf("%s/plugins", get_datafile_dir()); plugin_dir = g_strdup_printf("%s/plugins", get_datafile_dir());
running_in_build_directory_flag = TRUE;
} else } else
plugin_dir = PLUGIN_DIR; plugin_dir = PLUGIN_DIR;
#endif #endif

View File

@ -2144,21 +2144,21 @@ main(int argc, char *argv[])
OPTSTRING_INIT OPTSTRING_WIN32; OPTSTRING_INIT OPTSTRING_WIN32;
#ifdef HAVE_AIRPDCAP #ifdef HAVE_AIRPDCAP
/* Davide Schiera (2006-11-18): init AirPDcap context */ /* Davide Schiera (2006-11-18): init AirPDcap context */
AirPDcapInitContext(&airpdcap_ctx); AirPDcapInitContext(&airpdcap_ctx);
/* Davide Schiera (2006-11-18) ------------------------------------------- */ /* Davide Schiera (2006-11-18) ------------------------------------------- */
#endif #endif
/*
* Attempt to get the pathname of the executable file.
*/
init_progfile_dir_error = init_progfile_dir(argv[0]);
/* /*
* Get credential information for later use. * Get credential information for later use.
*/ */
get_credential_info(); get_credential_info();
/*
* Attempt to get the pathname of the executable file.
*/
init_progfile_dir_error = init_progfile_dir(argv[0]);
/* /*
* Now attempt to get the pathname of the plugins. * Now attempt to get the pathname of the plugins.
*/ */

View File

@ -720,6 +720,11 @@ main(int argc, char *argv[])
static const char optstring[] = OPTSTRING_INIT OPTSTRING_WIN32; static const char optstring[] = OPTSTRING_INIT OPTSTRING_WIN32;
/*
* Get credential information for later use.
*/
get_credential_info();
/* /*
* Attempt to get the pathname of the executable file. * Attempt to get the pathname of the executable file.
*/ */
@ -729,11 +734,6 @@ main(int argc, char *argv[])
init_progfile_dir_error); init_progfile_dir_error);
} }
/*
* Get credential information for later use.
*/
get_credential_info();
/* /*
* Now attempt to get the pathname of the plugins. * Now attempt to get the pathname of the plugins.
*/ */