summaryrefslogtreecommitdiffstats
path: root/chrome/browser/browser_main_gtk.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/browser_main_gtk.cc')
-rw-r--r--chrome/browser/browser_main_gtk.cc45
1 files changed, 45 insertions, 0 deletions
diff --git a/chrome/browser/browser_main_gtk.cc b/chrome/browser/browser_main_gtk.cc
index 017bbfa..fd73fcb 100644
--- a/chrome/browser/browser_main_gtk.cc
+++ b/chrome/browser/browser_main_gtk.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/browser_main_gtk.h"
+#include <gtk/gtk.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
@@ -18,8 +19,13 @@
#include "chrome/common/result_codes.h"
#include "content/browser/renderer_host/render_sandbox_host_linux.h"
#include "content/browser/zygote_host_linux.h"
+#include "grit/chromium_strings.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
#include "ui/base/x/x11_util.h"
#include "ui/base/x/x11_util_internal.h"
+#include "ui/gfx/gtk_util.h"
#if defined(USE_NSS)
#include "base/nss_util.h"
@@ -54,6 +60,8 @@ int BrowserX11IOErrorHandler(Display* d) {
} // namespace
void BrowserMainPartsGtk::PreEarlyInitialization() {
+ DetectRunningAsRoot();
+
BrowserMainPartsPosix::PreEarlyInitialization();
SetupSandbox();
@@ -64,6 +72,43 @@ void BrowserMainPartsGtk::PreEarlyInitialization() {
#endif
}
+void BrowserMainPartsGtk::DetectRunningAsRoot() {
+ if (geteuid() == 0) {
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+ gfx::GtkInitFromCommandLine(command_line);
+
+ // Get just enough of our resource machinery up so we can extract the
+ // locale appropriate string. Note that the GTK implementation ignores the
+ // passed in parameter and checks the LANG environment variables instead.
+ ResourceBundle::InitSharedInstance("");
+
+ std::string message = l10n_util::GetStringFUTF8(
+ IDS_REFUSE_TO_RUN_AS_ROOT,
+ l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
+ GtkWidget* dialog = gtk_message_dialog_new(
+ NULL,
+ static_cast<GtkDialogFlags>(0),
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "%s",
+ message.c_str());
+
+ message = l10n_util::GetStringFUTF8(
+ IDS_REFUSE_TO_RUN_AS_ROOT_2,
+ l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
+ gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
+ "%s",
+ message.c_str());
+
+ message = l10n_util::GetStringUTF8(IDS_PRODUCT_NAME);
+ gtk_window_set_title(GTK_WINDOW(dialog), message.c_str());
+
+ gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy(dialog);
+ exit(EXIT_FAILURE);
+ }
+}
+
void BrowserMainPartsGtk::SetupSandbox() {
// TODO(evanm): move this into SandboxWrapper; I'm just trying to move this
// code en masse out of chrome_main for now.