File nspluginwrapper-user-system-path.patch of Package nspluginwrapper

This patch removes incorrect "/root/*" plugin path hack (if /root is not
accessible for anybody, then linked plugin fails for everybody except
root) and introduces discrimination between user plugin and system
plugin).

After applying of this patch, plugins in user home are never wrapped in
system path.

https://bugzilla.novell.com/show_bug.cgi?id=384367
================================================================================
--- src/npw-config.c
+++ src/npw-config.c
@@ -178,6 +178,11 @@
   return dir;
 }
 
+struct mozilla_plugin_dir {
+  bool is_system_dir;
+  char *dir;
+};
+
 static const char *get_user_mozilla_plugin_dir(void)
 {
   const char *home;
@@ -190,7 +195,7 @@
   return plugin_path;
 }
 
-static const char **get_mozilla_plugin_dirs(void)
+static const struct mozilla_plugin_dir *get_mozilla_plugin_dirs(void)
 {
   static const char *default_dirs[] = {
 	"/usr/lib/mozilla/plugins",
@@ -231,15 +236,17 @@
   };
 
   const int n_default_dirs = (sizeof(default_dirs) / sizeof(default_dirs[0]));
-  const char **dirs = malloc((n_default_dirs + 2) * sizeof(dirs[0]));
+  struct mozilla_plugin_dir *dirs = malloc((n_default_dirs + 2) * sizeof(struct mozilla_plugin_dir));
   int i, j;
   for (i = 0, j = 0; i < n_default_dirs; i++) {
 	const char *dir = default_dirs[i];
 	if (dir && access(dir, F_OK) == 0)
-	  dirs[j++] = dir;
+	  dirs[j].is_system_dir = true;
+	  dirs[j++].dir = dir;
   }
-  dirs[j++] = get_user_mozilla_plugin_dir();
-  dirs[j] = NULL;
+  dirs[j].is_system_dir = false;
+  dirs[j++].dir = get_user_mozilla_plugin_dir();
+  dirs[j].dir = NULL;
   return dirs;
 }
 
@@ -642,20 +649,20 @@
 }
 
 typedef bool (*is_plugin_cb)(const char *plugin_path, NPW_PluginInfo *plugin_info);
-typedef int (*process_plugin_cb)(const char *plugin_path, NPW_PluginInfo *plugin_info);
+typedef int (*process_plugin_cb)(const char *plugin_path, bool is_system_dir, NPW_PluginInfo *plugin_info);
 
-static int process_plugin_dir(const char *plugin_dir, is_plugin_cb test, process_plugin_cb process)
+static int process_plugin_dir(const struct mozilla_plugin_dir *plugin_dir, is_plugin_cb test, process_plugin_cb process)
 {
   if (g_verbose)
-	printf("Looking for plugins in %s\n", plugin_dir);
+	printf("Looking for plugins in %s\n", plugin_dir->dir);
 
-  DIR *dir = opendir(plugin_dir);
+  DIR *dir = opendir(plugin_dir->dir);
   if (dir == NULL)
 	return -1;
 
   int plugin_path_length = 256;
   char *plugin_path = (char *)malloc(plugin_path_length);
-  int plugin_dir_length = strlen(plugin_dir);
+  int plugin_dir_length = strlen(plugin_dir->dir);
 
   struct dirent *ent;
   while ((ent = readdir(dir)) != NULL) {
@@ -664,10 +671,10 @@
 	  plugin_path_length = len;
 	  plugin_path = (char *)realloc(plugin_path, plugin_path_length);
 	}
-	sprintf(plugin_path, "%s/%s", plugin_dir, ent->d_name);
+	sprintf(plugin_path, "%s/%s", plugin_dir->dir, ent->d_name);
 	NPW_PluginInfo plugin_info;
 	if (test(plugin_path, &plugin_info))
-	  process(plugin_path, &plugin_info);
+	  process(plugin_path, plugin_dir->is_system_dir, &plugin_info);
   }
 
   free(plugin_path);
@@ -690,10 +697,6 @@
   if (n < 0 || n >= sizeof(d_plugin_path))
 	return 3;
 
-  int mode = 0700;
-  if (geteuid() == 0 && strcmp(plugin_dir, "/root") != 0)
-	mode = 0755;
-
   NPW_PluginInfo w_plugin_info;
   if (!is_wrapper_plugin(NPW_DEFAULT_PLUGIN_PATH, &w_plugin_info))
 	return 5;
@@ -750,7 +753,7 @@
   strcpy(pi->target_arch, plugin_info->target_arch);
   strcpy(pi->target_os, plugin_info->target_os);
 
-  int d_fd = open(d_plugin_path, O_CREAT | O_WRONLY, mode);
+  int d_fd = open(d_plugin_path, O_CREAT | O_WRONLY, 0755);
   if (d_fd < 0)
 	return 4;
 
@@ -765,16 +768,18 @@
   return 0;
 }
 
-static int install_plugin(const char *plugin_path, NPW_PluginInfo *plugin_info)
+static int install_plugin(const char *plugin_path, bool is_system_dir, NPW_PluginInfo *plugin_info)
 {
   int ret;
 
   if (g_verbose)
 	printf("Install plugin %s\n", plugin_path);
 
-  ret = do_install_plugin(plugin_path, get_system_mozilla_plugin_dir(), plugin_info);
-  if (ret == 0)
-	return 0;
+  if (is_system_dir) {
+	ret = do_install_plugin(plugin_path, get_system_mozilla_plugin_dir(), plugin_info);
+	if (ret == 0)
+	  return 0;
+  }
 
   // don't install plugin in user home dir if already available system-wide
   if (is_system_wide_wrapper_plugin(plugin_path)) {
@@ -796,13 +801,13 @@
 
 static int auto_install_plugins(void)
 {
-  const char **plugin_dirs = get_mozilla_plugin_dirs();
+  const struct mozilla_plugin_dir *plugin_dirs = get_mozilla_plugin_dirs();
   if (plugin_dirs) {
 	int i;
-	for (i = 0; plugin_dirs[i] != NULL; i++) {
-	  const char *plugin_dir = plugin_dirs[i];
+	for (i = 0; plugin_dirs[i].dir != NULL; i++) {
+	  const struct mozilla_plugin_dir *plugin_dir = &(plugin_dirs[i]);
 	  if (g_verbose)
-		printf("Auto-install plugins from %s\n", plugin_dir);
+		printf("Auto-install plugins from %s\n", plugin_dir->dir);
 	  process_plugin_dir(plugin_dir, is_compatible_plugin, (process_plugin_cb)install_plugin);
 	}
   }
@@ -823,13 +828,13 @@
 
 static int auto_remove_plugins(void)
 {
-  const char **plugin_dirs = get_mozilla_plugin_dirs();
+  const struct mozilla_plugin_dir *plugin_dirs = get_mozilla_plugin_dirs();
   if (plugin_dirs) {
 	int i;
-	for (i = 0; plugin_dirs[i] != NULL; i++) {
-	  const char *plugin_dir = plugin_dirs[i];
+	for (i = 0; plugin_dirs[i].dir != NULL; i++) {
+	  const struct mozilla_plugin_dir *plugin_dir = &(plugin_dirs[i]);
 	  if (g_verbose)
-		printf("Auto-remove plugins from %s\n", plugin_dir);
+		printf("Auto-remove plugins from %s\n", plugin_dir->dir);
 	  process_plugin_dir(plugin_dir, (is_plugin_cb)is_wrapper_plugin_0, (process_plugin_cb)remove_plugin);
 	}
   }
@@ -837,7 +842,7 @@
   return 0;
 }
 
-static int update_plugin(const char *plugin_path, ...)
+static int update_plugin(const char *plugin_path, bool is_system_dir, ...)
 {
   if (g_verbose)
 	printf("Update plugin %s\n", plugin_path);
@@ -862,12 +867,12 @@
   else if (stat(plugin_info.path, &st) == 0 && st.st_mtime > plugin_info.mtime) {
 	if (g_verbose)
 	  printf("  NS4 plugin %s was modified, reinstalling plugin\n", plugin_info.path);
-	ret = install_plugin(plugin_info.path, &plugin_info);
+	ret = install_plugin(plugin_info.path, is_system_dir, &plugin_info);
   }
   else if (strcmp(plugin_info.ident, NPW_PLUGIN_IDENT) != 0) {
 	if (g_verbose)
 	  printf("  nspluginwrapper ident mismatch, reinstalling plugin\n");
-	ret = install_plugin(plugin_info.path, &plugin_info);
+	ret = install_plugin(plugin_info.path, is_system_dir, &plugin_info);
   }
 
   return ret;
@@ -875,13 +880,13 @@
 
 static int auto_update_plugins(void)
 {
-  const char **plugin_dirs = get_mozilla_plugin_dirs();
+  const struct mozilla_plugin_dir *plugin_dirs = get_mozilla_plugin_dirs();
   if (plugin_dirs) {
 	int i;
-	for (i = 0; plugin_dirs[i] != NULL; i++) {
-	  const char *plugin_dir = plugin_dirs[i];
+	for (i = 0; plugin_dirs[i].dir != NULL; i++) {
+	  const struct mozilla_plugin_dir *plugin_dir = &(plugin_dirs[i]);
 	  if (g_verbose)
-		printf("Auto-update plugins from %s\n", plugin_dir);
+		printf("Auto-update plugins from %s\n", plugin_dir->dir);
 	  process_plugin_dir(plugin_dir, (is_plugin_cb)is_wrapper_plugin_0, (process_plugin_cb)update_plugin);
 	}
   }
@@ -947,13 +952,13 @@
 
 static int process_list(int argvc, char *argv[])
 {
-  const char **plugin_dirs = get_mozilla_plugin_dirs();
+  const struct mozilla_plugin_dir *plugin_dirs = get_mozilla_plugin_dirs();
   if (plugin_dirs) {
 	int i;
-	for (i = 0; plugin_dirs[i] != NULL; i++) {
-	  const char *plugin_dir = plugin_dirs[i];
+	for (i = 0; plugin_dirs[i].dir != NULL; i++) {
+	  const struct mozilla_plugin_dir *plugin_dir = &(plugin_dirs[i]);
 	  if (g_verbose)
-		printf("List plugins in %s\n", plugin_dir);
+		printf("List plugins in %s\n", plugin_dir->dir);
 	  process_plugin_dir(plugin_dir, (is_plugin_cb)is_wrapper_plugin_0, (process_plugin_cb)list_plugin);
 	}
   }
@@ -961,6 +966,13 @@
   return 0;
 }
 
+static bool is_system_path(const char *plugin_path)
+{
+  const char *user_mozilla_plugin_dir = get_user_mozilla_plugin_dir();
+
+  return strncmp(plugin_path, user_mozilla_plugin_dir, strlen(user_mozilla_plugin_dir) - 1);
+}
+
 static int process_update(int argc, char *argv[])
 {
   int i;
@@ -975,7 +987,7 @@
 	const char *plugin_path = argv[i];
 	if (!is_wrapper_plugin_0(plugin_path))
 	  error("%s is not a valid nspluginwrapper plugin", plugin_path);
-	int ret = update_plugin(plugin_path);
+	int ret = update_plugin(plugin_path, is_system_path(plugin_path));
 	if (ret != 0)
 	  return ret;
   }
@@ -1004,7 +1016,7 @@
 		return 0; /* silently ignore exit status */
 	  error("no appropriate viewer found for %s", plugin_path);
 	}
-	ret = install_plugin(plugin_path, &plugin_info);
+	ret = install_plugin(plugin_path, is_system_path(plugin_path), &plugin_info);
 	if (ret != 0)
 	  return ret;
   }
openSUSE Build Service is sponsored by