Ticket #37 (closed defect: fixed)

Opened 1 year ago

Last modified 5 days ago

Cannot install same userscript for multiple users. (Linux)

Reported by: ottodisp-greasemonk..@yahoo.com Assigned to:
Priority: minor Milestone:
Version: Keywords: multiple users
Cc: arantius@gmail.com

Description

My system runs Fedora Core 7 and has 3 users. I can install *any* Greasemonkey userscript for 1 user (any user), but when trying to install the *same* userscript for a second user it fails.

The reason seems to be that a copy of the userscript has been placed in /tmp (for example /tmp/linkify.users.js) that belongs to the first user, and this copy is not removed after installation of the script. When switching to another user and trying to install the same script, it does not manage to create the file in /tmp and the installation fails.

Removal of the file in /tmp resolves the issue and allows a second user to install the script (this must be repeated for each subsequent user one wishes to install the same script for). So this is an easy workaround.

The problem would be resolved if Greasemonkey removed the userscript file from /tmp after installation of the userscript.

ps. I have previously submitted it to https://www.mozdev.org/bugs/show_bug.cgi?id=17361 but that doesn't seem to be used anymore.

Attachments

grease-tmpfile.patch (1.2 kB) - added by agriff..@n01se.net on 04/16/08 06:21:01.
partial fix for tmpefile issues
37-unique.patch (0.6 kB) - added by aranti..@gmail.com on 04/16/08 18:51:02.
Suggested patch to ensure unique files when downloading initial script.

Change History

07/28/07 13:46:47 changed by aranti..@gmail.com

  • cc set to aranti..@gmail.com.

07/28/07 15:56:07 changed by boo..@youngpup.net

Probably obvious, but a better approach would be to write these files in a way that they are overwritable. That way no need to worry about cases where the removal doesn't happen.

07/28/07 16:21:43 changed by ottodisp-greasemonk..@yahoo.com

Even better is to use the PID in the temporary file name. Since no two processes will have the same PID, this prevents two instances of Greasemonkey from even attempting to use the same filename for temporary files. This way there's no need to play with permissions either.

On most systems, files in /tmp will be cleaned up after some time, but I think programs should attempt to clean up after themselves anyway.

08/14/07 18:16:09 changed by anonymous

(in reply to: ↑ description ) 03/15/08 19:47:05 changed by anonymous

Identical problem in Fedora 8.

(in reply to: ↑ description ) 04/15/08 14:49:16 changed by anonymous

This isn't a minor problem. It's a major problem with security implications. GreaseMonkey? should be using nsIFile.createUnique() rather than cooking its own temporary files.

04/16/08 06:21:01 changed by agriff..@n01se.net

  • attachment grease-tmpfile.patch added.

partial fix for tmpefile issues

04/16/08 06:28:02 changed by agriff..@n01se.net

I just attached this patch but unfortunately trac seems to have mangled it (a hunk is missing), so here it is pasted. This patch fixes the installation issues but doesn't fix the alternate path of viewing the source (I wasn't sure how to handle that).

Additionally this patch fixes the stream.init() call to use octal for permissions. The original value 420 was interpreted as decimal. The 0664 will be ANDed to the umask to create the file with appropriate permissions.

--- config.js~	2008-04-16 09:16:03.000000000 -0400
+++ config.js	2008-04-16 09:16:10.000000000 -040..@@ -151,7 +151,7 @@
 
     try {
       this.initFilename(script);
-      script.file.copyTo(newDir, script.filename)
+      script.file.moveTo(newDir, script.filename);
       this.scripts.push(script);
       this.save();
     }

--- scriptdownloader.js~	2008-01-21 11:02:00.000000000 -0500
+++ scriptdownloader.js	2008-04-16 09:17:27.000000000 -040..@@ -52,6 +52,7 @@
 
   var base = this.script.name.replace(/[^A-Z0-9_]/gi, "").toLowerCase();
   file.append(base + ".user.js");
+  file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0664); // honors umask
 
   var converter =  
     Components.classes..@mozilla.org/intl/scriptableunicodeconverter"]  

--- utils.js~	2008-01-21 11:02:00.000000000 -0500
+++ utils.js	2008-04-16 09:07:09.000000000 -040..@@ -199,7 +199,8 @@
   var stream = Components.classes..@mozilla.org/network/file-output-stream;1"]
     .createInstance(Components.interfaces.nsIFileOutputStream);
 
-  stream.init(file, 0x02 | 0x08 | 0x20, 420, -1);
+  // PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE
+  stream.init(file, 0x02 | 0x08 | 0x20, 0664, -1); // honors umask
 
   return stream;
 }

04/16/08 18:27:07 changed by aranti..@gmail.com

The attached patch file is fine. But it appears to be against the 0.7 release, rather than trunk. The copyTo line does not exist, and I fail to see the point of changing the stream.init line.

04/16/08 18:51:02 changed by aranti..@gmail.com

  • attachment 37-unique.patch added.

Suggested patch to ensure unique files when downloading initial script.

04/17/08 16:15:36 changed by aranti..@gmail.com

  • status changed from new to closed.
  • resolution set to fixed.

(In [735]) Fixes #37 Fixes #89

  • When creating temporary files, always use nsILocalFile.createUnique()
  • Track temporary files created during script install
  • Clean up all temporary files when script install completes or is canceled

11/27/08 10:11:56 changed by anonymous


Add/Change #37 (Cannot install same userscript for multiple users. (Linux))




Action