author | zecke <zecke> | 2004-02-29 18:39:07 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-02-29 18:39:07 (UTC) |
commit | 1a59dd467d210703b69d2d694f95988f2e97c27f (patch) (side-by-side diff) | |
tree | 009e2d2c137c4d0d89b4901a8d3a53ff76bd64de | |
parent | f8e1f2c5201f7e86abaa7365040d919e2afcd2ae (diff) | |
download | opie-1a59dd467d210703b69d2d694f95988f2e97c27f.zip opie-1a59dd467d210703b69d2d694f95988f2e97c27f.tar.gz opie-1a59dd467d210703b69d2d694f95988f2e97c27f.tar.bz2 |
from the branch to find the best shell or fallback to /bin/sh
-rw-r--r-- | core/apps/embeddedkonsole/konsole.cpp | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/core/apps/embeddedkonsole/konsole.cpp b/core/apps/embeddedkonsole/konsole.cpp index eafc12e..084c39d 100644 --- a/core/apps/embeddedkonsole/konsole.cpp +++ b/core/apps/embeddedkonsole/konsole.cpp @@ -1,73 +1,76 @@ /* ---------------------------------------------------------------------- */ /* */ /* [main.C] Konsole */ /* */ /* ---------------------------------------------------------------------- */ /* */ /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ /* */ /* This file is part of Konsole, an X terminal. */ /* */ /* The material contained in here more or less directly orginates from */ /* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */ /* */ /* ---------------------------------------------------------------------- */ /* */ /* Ported Konsole to Qt/Embedded */ /* */ /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ /* */ /* -------------------------------------------------------------------------- */ // enhancements added by L.J. Potter <ljp@llornkcor.com> // enhancements added by Phillip Kuhn #include <stdlib.h> +#include <sys/types.h> +#include <pwd.h> +#include <unistd.h> #ifdef QT_QWS_OPIE #include <opie2/ocolorpopupmenu.h> #endif #include <qpe/resource.h> #include <qdir.h> #include <qevent.h> #include <qdragobject.h> #include <qobjectlist.h> #include <qtoolbutton.h> #include <qtoolbar.h> #include <qpushbutton.h> #include <qfontdialog.h> #include <qglobal.h> #include <qpainter.h> #include <qmenubar.h> #include <qmessagebox.h> #include <qaction.h> #include <qapplication.h> #include <qfontmetrics.h> #include <qcombobox.h> #include <qevent.h> #include <qtabwidget.h> #include <qtabbar.h> #include <qpe/config.h> #include <qstringlist.h> #include <qpalette.h> #include <qfontdatabase.h> #include <qfile.h> #include <qspinbox.h> #include <qlayout.h> #include <qvbox.h> #include <sys/wait.h> #include <stdio.h> #include <stdlib.h> #include <assert.h> #include "konsole.h" #include "keytrans.h" #include "commandeditdialog.h" class EKNumTabBar : public QTabBar { public: EKNumTabBar(QWidget *parent = 0, const char *name = 0) : @@ -175,101 +178,139 @@ static const char *commonCmds[] = "ipkg ", "mkdir ", "mv ", "nc localhost 7776", "nc localhost 7777", "netstat ", "nslookup ", "ping ", "ps aux", "pwd ", "qcop QPE/System 'linkChanged(QString)' ''", "qcop QPE/System 'restart()'", "qcop QPE/System 'quit()'", "rm ", "rmdir ", "route ", "set ", "traceroute", /* "gzip", "gunzip", "chgrp", "chown", "date", "dd", "df", "dmesg", "fuser", "hostname", "kill", "killall", "ln", "ping", "mount", "more", "sort", "touch", "umount", "mknod", "netstat", */ "exit", NULL }; +static void konsoleInit(const char** shell) { + if(setuid(getuid()) !=0) qDebug("setuid failed"); + if(setgid(getgid()) != 0) qDebug("setgid failed"); // drop privileges + + +// QPEApplication::grabKeyboard(); // for CTRL and ALT + + qDebug("keyboard grabbed"); +#ifdef FAKE_CTRL_AND_ALT + qDebug("Fake Ctrl and Alt defined"); + QPEApplication::grabKeyboard(); // for CTRL and ALT +#endif + + *shell = getenv("SHELL"); + qWarning("SHell initially is %s", *shell ); + + if (shell == NULL || *shell == '\0') { + struct passwd *ent = 0; + uid_t me = getuid(); + *shell = "/bin/sh"; + + while ( (ent = getpwent()) != 0 ) { + if (ent->pw_uid == me) { + if (ent->pw_shell != "") + *shell = ent->pw_shell; + break; + } + } + endpwent(); + } + + if( putenv((char*)"COLORTERM=") !=0) + qDebug("putenv failed"); // to trigger mc's color detection +} + + Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) : QMainWindow(parent, name, fl) { - QStrList args; - init("/bin/bash",args); + QStrList tmp; const char* shell; + + konsoleInit( &shell); + init(shell,tmp); } Konsole::Konsole(const char* name, const char* _pgm, QStrList & _args, int) : QMainWindow(0, name) { init(_pgm,_args); } struct HistoryItem { HistoryItem(int c, const QString &l) { count = c; line = l; } int count; QString line; }; class HistoryList : public QList<HistoryItem> { virtual int compareItems( QCollection::Item item1, QCollection::Item item2) { int c1 = ((HistoryItem*)item1)->count; int c2 = ((HistoryItem*)item2)->count; if (c1 > c2) return(1); if (c1 < c2) return(-1); return(0); } }; void Konsole::initCommandList() { // qDebug("Konsole::initCommandList"); Config cfg( "Konsole" ); cfg.setGroup("Commands"); // commonCombo->setInsertionPolicy(QComboBox::AtCurrent); commonCombo->clear(); if (cfg.readEntry("ShellHistory","TRUE") == "TRUE") { QString histfilename = QString(getenv("HOME")) + "/.bash_history"; histfilename = cfg.readEntry("ShellHistoryPath",histfilename); QFile histfile(histfilename); // note: compiler barfed on: // QFile histfile(QString(getenv("HOME")) + "/.bash_history"); |