-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 | |||
@@ -2,48 +2,51 @@ | |||
2 | /* ---------------------------------------------------------------------- */ | 2 | /* ---------------------------------------------------------------------- */ |
3 | /* */ | 3 | /* */ |
4 | /* [main.C] Konsole */ | 4 | /* [main.C] Konsole */ |
5 | /* */ | 5 | /* */ |
6 | /* ---------------------------------------------------------------------- */ | 6 | /* ---------------------------------------------------------------------- */ |
7 | /* */ | 7 | /* */ |
8 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ | 8 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ |
9 | /* */ | 9 | /* */ |
10 | /* This file is part of Konsole, an X terminal. */ | 10 | /* This file is part of Konsole, an X terminal. */ |
11 | /* */ | 11 | /* */ |
12 | /* The material contained in here more or less directly orginates from */ | 12 | /* The material contained in here more or less directly orginates from */ |
13 | /* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */ | 13 | /* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */ |
14 | /* */ | 14 | /* */ |
15 | /* ---------------------------------------------------------------------- */ | 15 | /* ---------------------------------------------------------------------- */ |
16 | /* */ | 16 | /* */ |
17 | /* Ported Konsole to Qt/Embedded */ | 17 | /* Ported Konsole to Qt/Embedded */ |
18 | /* */ | 18 | /* */ |
19 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ | 19 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ |
20 | /* */ | 20 | /* */ |
21 | /* -------------------------------------------------------------------------- */ | 21 | /* -------------------------------------------------------------------------- */ |
22 | // enhancements added by L.J. Potter <ljp@llornkcor.com> | 22 | // enhancements added by L.J. Potter <ljp@llornkcor.com> |
23 | // enhancements added by Phillip Kuhn | 23 | // enhancements added by Phillip Kuhn |
24 | 24 | ||
25 | #include <stdlib.h> | 25 | #include <stdlib.h> |
26 | #include <sys/types.h> | ||
27 | #include <pwd.h> | ||
28 | #include <unistd.h> | ||
26 | 29 | ||
27 | #ifdef QT_QWS_OPIE | 30 | #ifdef QT_QWS_OPIE |
28 | #include <opie2/ocolorpopupmenu.h> | 31 | #include <opie2/ocolorpopupmenu.h> |
29 | #endif | 32 | #endif |
30 | 33 | ||
31 | #include <qpe/resource.h> | 34 | #include <qpe/resource.h> |
32 | 35 | ||
33 | #include <qdir.h> | 36 | #include <qdir.h> |
34 | #include <qevent.h> | 37 | #include <qevent.h> |
35 | #include <qdragobject.h> | 38 | #include <qdragobject.h> |
36 | #include <qobjectlist.h> | 39 | #include <qobjectlist.h> |
37 | #include <qtoolbutton.h> | 40 | #include <qtoolbutton.h> |
38 | #include <qtoolbar.h> | 41 | #include <qtoolbar.h> |
39 | #include <qpushbutton.h> | 42 | #include <qpushbutton.h> |
40 | #include <qfontdialog.h> | 43 | #include <qfontdialog.h> |
41 | #include <qglobal.h> | 44 | #include <qglobal.h> |
42 | #include <qpainter.h> | 45 | #include <qpainter.h> |
43 | #include <qmenubar.h> | 46 | #include <qmenubar.h> |
44 | #include <qmessagebox.h> | 47 | #include <qmessagebox.h> |
45 | #include <qaction.h> | 48 | #include <qaction.h> |
46 | #include <qapplication.h> | 49 | #include <qapplication.h> |
47 | #include <qfontmetrics.h> | 50 | #include <qfontmetrics.h> |
48 | #include <qcombobox.h> | 51 | #include <qcombobox.h> |
49 | #include <qevent.h> | 52 | #include <qevent.h> |
@@ -199,53 +202,91 @@ static const char *commonCmds[] = | |||
199 | "date", | 202 | "date", |
200 | "dd", | 203 | "dd", |
201 | "df", | 204 | "df", |
202 | "dmesg", | 205 | "dmesg", |
203 | "fuser", | 206 | "fuser", |
204 | "hostname", | 207 | "hostname", |
205 | "kill", | 208 | "kill", |
206 | "killall", | 209 | "killall", |
207 | "ln", | 210 | "ln", |
208 | "ping", | 211 | "ping", |
209 | "mount", | 212 | "mount", |
210 | "more", | 213 | "more", |
211 | "sort", | 214 | "sort", |
212 | "touch", | 215 | "touch", |
213 | "umount", | 216 | "umount", |
214 | "mknod", | 217 | "mknod", |
215 | "netstat", | 218 | "netstat", |
216 | */ | 219 | */ |
217 | 220 | ||
218 | "exit", | 221 | "exit", |
219 | NULL | 222 | NULL |
220 | }; | 223 | }; |
221 | 224 | ||
222 | 225 | ||
226 | static void konsoleInit(const char** shell) { | ||
227 | if(setuid(getuid()) !=0) qDebug("setuid failed"); | ||
228 | if(setgid(getgid()) != 0) qDebug("setgid failed"); // drop privileges | ||
229 | |||
230 | |||
231 | // QPEApplication::grabKeyboard(); // for CTRL and ALT | ||
232 | |||
233 | qDebug("keyboard grabbed"); | ||
234 | #ifdef FAKE_CTRL_AND_ALT | ||
235 | qDebug("Fake Ctrl and Alt defined"); | ||
236 | QPEApplication::grabKeyboard(); // for CTRL and ALT | ||
237 | #endif | ||
238 | |||
239 | *shell = getenv("SHELL"); | ||
240 | qWarning("SHell initially is %s", *shell ); | ||
241 | |||
242 | if (shell == NULL || *shell == '\0') { | ||
243 | struct passwd *ent = 0; | ||
244 | uid_t me = getuid(); | ||
245 | *shell = "/bin/sh"; | ||
246 | |||
247 | while ( (ent = getpwent()) != 0 ) { | ||
248 | if (ent->pw_uid == me) { | ||
249 | if (ent->pw_shell != "") | ||
250 | *shell = ent->pw_shell; | ||
251 | break; | ||
252 | } | ||
253 | } | ||
254 | endpwent(); | ||
255 | } | ||
256 | |||
257 | if( putenv((char*)"COLORTERM=") !=0) | ||
258 | qDebug("putenv failed"); // to trigger mc's color detection | ||
259 | } | ||
260 | |||
261 | |||
223 | Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) : | 262 | Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) : |
224 | QMainWindow(parent, name, fl) | 263 | QMainWindow(parent, name, fl) |
225 | { | 264 | { |
226 | QStrList args; | 265 | QStrList tmp; const char* shell; |
227 | init("/bin/bash",args); | 266 | |
267 | konsoleInit( &shell); | ||
268 | init(shell,tmp); | ||
228 | } | 269 | } |
229 | 270 | ||
230 | Konsole::Konsole(const char* name, const char* _pgm, QStrList & _args, int) | 271 | Konsole::Konsole(const char* name, const char* _pgm, QStrList & _args, int) |
231 | : QMainWindow(0, name) | 272 | : QMainWindow(0, name) |
232 | { | 273 | { |
233 | init(_pgm,_args); | 274 | init(_pgm,_args); |
234 | } | 275 | } |
235 | 276 | ||
236 | struct HistoryItem | 277 | struct HistoryItem |
237 | { | 278 | { |
238 | HistoryItem(int c, const QString &l) | 279 | HistoryItem(int c, const QString &l) |
239 | { | 280 | { |
240 | count = c; | 281 | count = c; |
241 | line = l; | 282 | line = l; |
242 | } | 283 | } |
243 | int count; | 284 | int count; |
244 | QString line; | 285 | QString line; |
245 | }; | 286 | }; |
246 | 287 | ||
247 | class HistoryList : public QList<HistoryItem> | 288 | class HistoryList : public QList<HistoryItem> |
248 | { | 289 | { |
249 | virtual int compareItems( QCollection::Item item1, QCollection::Item item2) | 290 | virtual int compareItems( QCollection::Item item1, QCollection::Item item2) |
250 | { | 291 | { |
251 | int c1 = ((HistoryItem*)item1)->count; | 292 | int c1 = ((HistoryItem*)item1)->count; |