If Zotero is run as root, clobber the cache directory and show a warning

This commit is contained in:
Simon Kornblith 2013-07-25 00:47:38 -04:00
parent 185c5a3a4d
commit 1055187c8b
2 changed files with 30 additions and 0 deletions

View file

@ -38,6 +38,7 @@ const ZoteroStandalone = new function() {
window.close();
return;
}
_checkRoot();
ZoteroPane.init();
ZoteroPane.makeVisible();
@ -146,6 +147,32 @@ const ZoteroStandalone = new function() {
this.onUnload = function() {
ZoteroPane.destroy();
}
/**
* Warn if Zotero Standalone is running as root and clobber the cache directory
*/
function _checkRoot() {
if(!Zotero.isWin) {
var env = Components.classes["@mozilla.org/process/environment;1"].
getService(Components.interfaces.nsIEnvironment);
var user = env.get("USER") || env.get("USERNAME");
if(user === "root") {
// Zap cache files
try {
Services.dirsvc.get("ProfLD", Components.interfaces.nsIFile).remove(true);
} catch(e) {}
// Warn user never to do this again
if(Services.prompt.confirmEx(null, "", Zotero.getString("standalone.rootWarning"),
Services.prompt.BUTTON_POS_0*Services.prompt.BUTTON_TITLE_IS_STRING |
Services.prompt.BUTTON_POS_1*Services.prompt.BUTTON_TITLE_IS_STRING,
Zotero.getString("standalone.rootWarning.exit"),
Zotero.getString("standalone.rootWarning.continue"),
null, null, {}) == 0) {
goQuitApplication();
}
}
}
}
}
/** Taken from browser.js **/

View file

@ -934,6 +934,9 @@ locate.manageLocateEngines = Manage Lookup Engines…
standalone.corruptInstallation = Your Zotero Standalone installation appears to be corrupted due to a failed auto-update. While Zotero may continue to function, to avoid potential bugs, please download the latest version of Zotero Standalone from http://zotero.org/support/standalone as soon as possible.
standalone.addonInstallationFailed.title = Add-on Installation Failed
standalone.addonInstallationFailed.body = The add-on "%S" could not be installed. It may be incompatible with this version of Zotero Standalone.
standalone.rootWarning = You appear to be running Zotero Standalone as root. This is insecure and may prevent Zotero from functioning when launched from your user account.\n\nIf you wish to install an automatic update, modify the Zotero program directory to be writeable by your user account.
standalone.rootWarning.exit = Exit
standalone.rootWarning.continue = Continue
connector.error.title = Zotero Connector Error
connector.standaloneOpen = Your database cannot be accessed because Zotero Standalone is currently open. Please view your items in Zotero Standalone.