void relinquish_special_privs_perm(void) { /* * If we were started with special privileges, set the * real and effective group and user IDs to the original * values of the real and effective group and user IDs. * If we're not, don't bother - doing so seems to mung * our group set, at least in OS X 10.5. * * (Set the effective UID last - that takes away our * rights to set anything else.) */ if (started_with_special_privs()) { #ifdef HAVE_SETRESGID setresgid(rgid, rgid, rgid); #else setgid(rgid); setegid(rgid); #endif #ifdef HAVE_SETRESUID setresuid(ruid, ruid, ruid); #else setuid(ruid); seteuid(ruid); #endif } }
/* * Scan for plugins. */ void scan_plugins(void) { const char *plugin_dir; const char *name; char *plugin_dir_path; char *plugins_pers_dir; WS_DIR *dir; /* scanned directory */ WS_DIRENT *file; /* current file */ if (plugin_list == NULL) /* ensure scan_plugins is only run once */ { /* * Scan the global plugin directory. * If we're running from a build directory, scan the subdirectories * of that directory, as the global plugin directory is the * "plugins" directory of the source tree, and the subdirectories * are the source directories for the plugins, with the plugins * built in those subdirectories. */ plugin_dir = get_plugin_dir(); if (running_in_build_directory()) { if ((dir = ws_dir_open(plugin_dir, 0, NULL)) != NULL) { while ((file = ws_dir_read_name(dir)) != NULL) { name = ws_dir_get_name(file); if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) continue; /* skip "." and ".." */ /* * Get the full path of a ".libs" subdirectory of that * directory. */ plugin_dir_path = g_strdup_printf( "%s" G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR_S ".libs", plugin_dir, name); if (test_for_directory(plugin_dir_path) != EISDIR) { /* * Either it doesn't refer to a directory or it * refers to something that doesn't exist. * * Assume that means that the plugins are in * the subdirectory of the plugin directory, not * a ".libs" subdirectory of that subdirectory. */ g_free(plugin_dir_path); plugin_dir_path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", plugin_dir, name); } plugins_scan_dir(plugin_dir_path); g_free(plugin_dir_path); } ws_dir_close(dir); } } else plugins_scan_dir(plugin_dir); /* * If the program wasn't started with special privileges, * scan the users plugin directory. (Even if we relinquish * them, plugins aren't safe unless we've *permanently* * relinquished them, and we can't do that in Wireshark as, * if we need privileges to start capturing, we'd need to * reclaim them before each time we start capturing.) */ if (!started_with_special_privs()) { plugins_pers_dir = get_plugins_pers_dir(); plugins_scan_dir(plugins_pers_dir); g_free(plugins_pers_dir); } } }